]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/ppc/IOSharedLockImp.h
xnu-1228.0.2.tar.gz
[apple/xnu.git] / iokit / IOKit / ppc / IOSharedLockImp.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
30 *
31 * HISTORY
32 *
33 */
34
35 /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
36 *
37 * EventShmemLock.h - Shared memory area locks for use between the
38 * WindowServer and the Event Driver.
39 *
40 * HISTORY
41 * 30 Nov 1992 Ben Fathi (benf@next.com)
42 * Ported to m98k.
43 *
44 * 29 April 1992 Mike Paquette at NeXT
45 * Created.
46 *
47 * Multiprocessor locks used within the shared memory area between the
48 * kernel and event system. These must work in both user and kernel mode.
49 * The locks are defined in an include file so they get exported to the local
50 * include file area.
51 */
52
53
54 #ifndef _IOKIT_IOSHAREDLOCKIMP_H
55 #define _IOKIT_IOSHAREDLOCKIMP_H
56
57 #include <architecture/ppc/asm_help.h>
58 #ifdef KERNEL
59 #undef END
60 #include <mach/ppc/asm.h>
61 #endif
62
63 /*
64 * void
65 * ev_lock(p)
66 * register int *p;
67 *
68 * Lock the lock pointed to by p. Spin (possibly forever) until
69 * the lock is available. Test and test and set logic used.
70 */
71 TEXT
72
73 #ifndef KERNEL
74 LEAF(_ev_lock)
75
76 li a6,1 // lock value
77
78 8: lwz a7,0(a0) // Get lock word
79 mr. a7,a7 // Is it held?
80 bne-- 8b // Yup...
81
82 9: lwarx a7,0,a0 // read the lock
83 mr. a7,a7 // Is it held?
84 bne-- 7f // yes, kill reservation
85 stwcx. a6,0,a0 // try to get the lock
86 bne-- 9b // failed, try again
87 isync
88 blr // got it, return
89
90 7: li a7,-4 // Point to a spot in the red zone
91 stwcx. a7,a7,r1 // Kill reservation
92 b 8b // Go wait some more...
93
94
95 END(_ev_lock)
96
97 LEAF(_IOSpinLock)
98
99 li a6,1 // lock value
100
101 8: lwz a7,0(a0) // Get lock word
102 mr. a7,a7 // Is it held?
103 bne-- 8b // Yup...
104
105 9: lwarx a7,0,a0 // read the lock
106 mr. a7,a7 // Is it held?
107 bne-- 7f // yes, kill reservation
108 stwcx. a6,0,a0 // try to get the lock
109 bne-- 9b // failed, try again
110 isync
111 blr // got it, return
112
113 7: li a7,-4 // Point to a spot in the red zone
114 stwcx. a7,a7,r1 // Kill reservation
115 b 8b // Go wait some more...
116 END(_IOSpinLock)
117 #endif
118
119 /*
120 * void
121 * spin_unlock(p)
122 * int *p;
123 *
124 * Unlock the lock pointed to by p.
125 */
126
127 LEAF(_ev_unlock)
128 sync
129 li a7,0
130 stw a7,0(a0)
131 blr
132 END(_ev_unlock)
133
134 LEAF(_IOSpinUnlock)
135 sync
136 li a7,0
137 stw a7,0(a0)
138 blr
139 END(_IOSpinUnlock)
140
141
142 /*
143 * ev_try_lock(p)
144 * int *p;
145 *
146 * Try to lock p. Return TRUE if successful in obtaining lock.
147 */
148
149 LEAF(_ev_try_lock)
150 li a6,1 // lock value
151
152 lwz a7,0(a0) // Get lock word
153 mr. a7,a7 // Is it held?
154 bne-- 6f // Yup...
155
156 9: lwarx a7,0,a0 // read the lock
157 mr. a7,a7 // Is it held?
158 bne-- 7f // yes, kill reservation
159 stwcx. a6,0,a0 // try to get the lock
160 bne-- 9b // failed, try again
161 li a0,1 // return TRUE
162 isync
163 blr // got it, return
164
165 7: li a7,-4 // Point to a spot in the red zone
166 stwcx. a7,a7,r1 // Kill reservation
167
168 6:
169 li a0,0 // return FALSE
170 blr
171
172 END(_ev_try_lock)
173
174 LEAF(_IOTrySpinLock)
175 li a6,1 // lock value
176
177 lwz a7,0(a0) // Get lock word
178 mr. a7,a7 // Is it held?
179 bne-- 6f // Yup...
180
181 9: lwarx a7,0,a0 // read the lock
182 mr. a7,a7 // Is it held?
183 bne-- 7f // yes, kill reservation
184 stwcx. a6,0,a0 // try to get the lock
185 bne-- 9b // failed, try again
186 li a0,1 // return TRUE
187 isync
188 blr // got it, return
189
190 7: li a7,-4 // Point to a spot in the red zone
191 stwcx. a7,a7,r1 // Kill reservation
192
193 6:
194 li a0,0 // return FALSE
195 blr
196
197 END(_IOTrySpinLock)
198
199 #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */