]> git.saurik.com Git - apple/xnu.git/blame - osfmk/mach/i386/flipc_dep.h
xnu-344.tar.gz
[apple/xnu.git] / osfmk / mach / i386 / flipc_dep.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * @OSF_COPYRIGHT@
24 *
25 */
26/*
27 * HISTORY
28 *
29 * Revision 1.1.1.1 1998/09/22 21:05:31 wsanchez
30 * Import of Mac OS X kernel (~semeria)
31 *
32 * Revision 1.1.1.1 1998/03/07 02:25:47 wsanchez
33 * Import of OSF Mach kernel (~mburg)
34 *
35 * Revision 1.1.5.1 1995/06/13 18:20:42 sjs
36 * Merge from flipc_shared.
37 * [95/06/07 sjs]
38 *
39 * Revision 1.1.3.3 1995/02/21 17:23:16 randys
40 * Re-indented code to four space indentation
41 * [1995/02/21 16:26:50 randys]
42 *
43 * Revision 1.1.3.2 1994/12/20 19:02:12 randys
44 * Moved definition of flipc_simple_lock to flipc_cb.h
45 * [1994/12/20 17:35:15 randys]
46 *
47 * Moved the machine independent macros into mach/flipc_locks.h
48 * [1994/12/20 16:44:14 randys]
49 *
50 * Added filename in comment at top of file
51 * [1994/12/19 20:29:36 randys]
52 *
53 * Fixed incorrect return of lock_try
54 * [1994/12/13 00:36:46 randys]
55 *
56 * Revision 1.1.3.1 1994/12/12 17:46:29 randys
57 * Putting initial flipc implementation under flipc_shared
58 * [1994/12/12 16:27:51 randys]
59 *
60 * Revision 1.1.1.2 1994/12/11 23:08:36 randys
61 * Initial flipc code checkin.
62 *
63 * $EndLog$
64 */
65
66/*
67 * mach/i386/flipc_dep.h
68 *
69 * This file will have all of the FLIPC implementation machine dependent
70 * defines that need to be visible to both kernel and AIL (eg. bus locks
71 * and bus synchronization primitives).
72 */
73
74#ifndef _MACH_FLIPC_DEP_H_
75#define _MACH_FLIPC_DEP_H_
76
77/* For the 386, we don't need to wrap synchronization variable writes
78 at all. */
79#define SYNCVAR_WRITE(statement) statement
80
81/* And similarly (I believe; check on this), for the 386 there isn't any
82 requirement for write fences. */
83#define WRITE_FENCE()
84
85/*
86 * Flipc simple lock defines. These are almost completely for the use
87 * of the AIL; the reason they are in this file is that they need to
88 * be initialized properly in the communications buffer initialization
89 * routine. Sigh. Note in particular that the kernel has no defined
90 * "simple_lock_yield_function", so it had better never expand the
91 * macro simple_lock_acquire.
92 *
93 * These locks may be declared by "flipc_simple_lock lock;". If they
94 * are instead declared by FLIPC_DECL_SIMPLE_LOCK(class,lockname) they
95 * may be used without initialization.
96 */
97
98#define SIMPLE_LOCK_INITIALIZER 0
99#define FLIPC_DECL_SIMPLE_LOCK(class,lockname) \
100class flipc_simple_lock (lockname) = SIMPLE_LOCK_INITIALIZER
101
102/*
103 * Lower case because they may be macros or functions.
104 * I'll include the function prototypes just for examples here.
105 */
106
107#define flipc_simple_lock_init(lock) \
108do { \
109 *(lock) = SIMPLE_LOCK_INITIALIZER; \
110} while (0)
111
112/*
113 * Defines of the actual routines, for gcc.
114 */
115
116#define flipc_simple_lock_locked(lock) ((*lock) != SIMPLE_LOCK_INITIALIZER)
117
118#ifdef __GNUC__
119 extern __inline__ int flipc_simple_lock_try(flipc_simple_lock *lock)
120{
121 int r;
122 __asm__ volatile("movl $1, %0; xchgl %0, %1" : "=&r" (r), "=m" (*lock));
123 return !r;
124}
125
126/* I don't know why this requires an ASM, but I'll follow the leader. */
127extern __inline__ void flipc_simple_lock_release(flipc_simple_lock *lock)
128{
129 register int t;
130
131 __asm__ volatile("xorl %0, %0; xchgl %0, %1" : "=&r" (t), "=m" (*lock));
132}
133#else /* __GNUC__ */
134/* If we aren't compiling with gcc, the above need to be functions. */
135#endif /* __GNUC__ */
136
137#endif /* _MACH_FLIPC_DEP_H_ */