]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/i386/flipc_dep.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / osfmk / mach / i386 / flipc_dep.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 *
33 */
34
35 /*
36 * mach/i386/flipc_dep.h
37 *
38 * This file will have all of the FLIPC implementation machine dependent
39 * defines that need to be visible to both kernel and AIL (eg. bus locks
40 * and bus synchronization primitives).
41 */
42
43 #ifndef _MACH_FLIPC_DEP_H_
44 #define _MACH_FLIPC_DEP_H_
45
46 /* For the 386, we don't need to wrap synchronization variable writes
47 at all. */
48 #define SYNCVAR_WRITE(statement) statement
49
50 /* And similarly (I believe; check on this), for the 386 there isn't any
51 requirement for write fences. */
52 #define WRITE_FENCE()
53
54 /*
55 * Flipc simple lock defines. These are almost completely for the use
56 * of the AIL; the reason they are in this file is that they need to
57 * be initialized properly in the communications buffer initialization
58 * routine. Sigh. Note in particular that the kernel has no defined
59 * "simple_lock_yield_function", so it had better never expand the
60 * macro simple_lock_acquire.
61 *
62 * These locks may be declared by "flipc_simple_lock lock;". If they
63 * are instead declared by FLIPC_DECL_SIMPLE_LOCK(class,lockname) they
64 * may be used without initialization.
65 */
66
67 #define SIMPLE_LOCK_INITIALIZER 0
68 #define FLIPC_DECL_SIMPLE_LOCK(class,lockname) \
69 class flipc_simple_lock (lockname) = SIMPLE_LOCK_INITIALIZER
70
71 /*
72 * Lower case because they may be macros or functions.
73 * I'll include the function prototypes just for examples here.
74 */
75
76 #define flipc_simple_lock_init(lock) \
77 do { \
78 *(lock) = SIMPLE_LOCK_INITIALIZER; \
79 } while (0)
80
81 /*
82 * Defines of the actual routines, for gcc.
83 */
84
85 #define flipc_simple_lock_locked(lock) ((*lock) != SIMPLE_LOCK_INITIALIZER)
86
87 #ifdef __GNUC__
88 extern __inline__ int flipc_simple_lock_try(flipc_simple_lock *lock)
89 {
90 int r;
91 __asm__ volatile("movl $1, %0; xchgl %0, %1" : "=&r" (r), "=m" (*lock));
92 return !r;
93 }
94
95 /* I don't know why this requires an ASM, but I'll follow the leader. */
96 extern __inline__ void flipc_simple_lock_release(flipc_simple_lock *lock)
97 {
98 register int t;
99
100 __asm__ volatile("xorl %0, %0; xchgl %0, %1" : "=&r" (t), "=m" (*lock));
101 }
102 #else /* __GNUC__ */
103 /* If we aren't compiling with gcc, the above need to be functions. */
104 #endif /* __GNUC__ */
105
106 #endif /* _MACH_FLIPC_DEP_H_ */