]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. | |
27 | * | |
28 | * HISTORY | |
29 | * | |
30 | */ | |
31 | ||
32 | /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. | |
33 | * | |
34 | * EventShmemLock.h - Shared memory area locks for use between the | |
35 | * WindowServer and the Event Driver. | |
36 | * | |
37 | * HISTORY | |
38 | * 30 Nov 1992 Ben Fathi (benf@next.com) | |
39 | * Ported to m98k. | |
40 | * | |
41 | * 29 April 1992 Mike Paquette at NeXT | |
42 | * Created. | |
43 | * | |
44 | * Multiprocessor locks used within the shared memory area between the | |
45 | * kernel and event system. These must work in both user and kernel mode. | |
46 | * The locks are defined in an include file so they get exported to the local | |
47 | * include file area. | |
48 | */ | |
49 | ||
50 | ||
51 | #ifndef _IOKIT_IOSHAREDLOCKIMP_H | |
52 | #define _IOKIT_IOSHAREDLOCKIMP_H | |
53 | ||
54 | #include <architecture/ppc/asm_help.h> | |
7b1edb79 A |
55 | #ifdef KERNEL |
56 | #undef END | |
57 | #include <mach/ppc/asm.h> | |
58 | #endif | |
1c79356b | 59 | |
1c79356b A |
60 | .macro DISABLE_PREEMPTION |
61 | #ifdef KERNEL | |
7b1edb79 A |
62 | stwu r1,-(FM_SIZE)(r1) |
63 | mflr r0 | |
64 | stw r3,FM_ARG0(r1) | |
65 | stw r0,(FM_SIZE+FM_LR_SAVE)(r1) | |
66 | bl EXT(_disable_preemption) | |
67 | lwz r3,FM_ARG0(r1) | |
68 | lwz r1,0(r1) | |
69 | lwz r0,FM_LR_SAVE(r1) | |
70 | mtlr r0 | |
1c79356b A |
71 | #endif |
72 | .endmacro | |
73 | .macro ENABLE_PREEMPTION | |
74 | #ifdef KERNEL | |
7b1edb79 A |
75 | stwu r1,-(FM_SIZE)(r1) |
76 | mflr r0 | |
77 | stw r3,FM_ARG0(r1) | |
78 | stw r0,(FM_SIZE+FM_LR_SAVE)(r1) | |
79 | bl EXT(_enable_preemption) | |
80 | lwz r3,FM_ARG0(r1) | |
81 | lwz r1,0(r1) | |
82 | lwz r0,FM_LR_SAVE(r1) | |
83 | mtlr r0 | |
1c79356b A |
84 | #endif |
85 | .endmacro | |
86 | ||
87 | /* | |
88 | * void | |
89 | * ev_lock(p) | |
90 | * register int *p; | |
91 | * | |
92 | * Lock the lock pointed to by p. Spin (possibly forever) until | |
93 | * the lock is available. Test and test and set logic used. | |
94 | */ | |
95 | TEXT | |
96 | ||
97 | #ifndef KERNEL | |
98 | LEAF(_ev_lock) | |
55e303ae A |
99 | |
100 | li a6,1 // lock value | |
101 | ||
102 | 8: lwz a7,0(a0) // Get lock word | |
103 | mr. a7,a7 // Is it held? | |
104 | bne-- 8b // Yup... | |
105 | ||
106 | 9: lwarx a7,0,a0 // read the lock | |
107 | mr. a7,a7 // Is it held? | |
108 | bne-- 7f // yes, kill reservation | |
109 | stwcx. a6,0,a0 // try to get the lock | |
110 | bne-- 9b // failed, try again | |
111 | isync | |
112 | blr // got it, return | |
113 | ||
114 | 7: li a7,-4 // Point to a spot in the red zone | |
115 | stwcx. a7,a7,r1 // Kill reservation | |
116 | b 8b // Go wait some more... | |
117 | ||
118 | ||
1c79356b | 119 | END(_ev_lock) |
0b4e3aa0 A |
120 | |
121 | LEAF(_IOSpinLock) | |
55e303ae A |
122 | |
123 | li a6,1 // lock value | |
124 | ||
125 | 8: lwz a7,0(a0) // Get lock word | |
126 | mr. a7,a7 // Is it held? | |
127 | bne-- 8b // Yup... | |
128 | ||
129 | 9: lwarx a7,0,a0 // read the lock | |
130 | mr. a7,a7 // Is it held? | |
131 | bne-- 7f // yes, kill reservation | |
132 | stwcx. a6,0,a0 // try to get the lock | |
133 | bne-- 9b // failed, try again | |
134 | isync | |
135 | blr // got it, return | |
136 | ||
137 | 7: li a7,-4 // Point to a spot in the red zone | |
138 | stwcx. a7,a7,r1 // Kill reservation | |
139 | b 8b // Go wait some more... | |
0b4e3aa0 | 140 | END(_IOSpinLock) |
1c79356b A |
141 | #endif |
142 | ||
143 | /* | |
144 | * void | |
145 | * spin_unlock(p) | |
146 | * int *p; | |
147 | * | |
148 | * Unlock the lock pointed to by p. | |
149 | */ | |
150 | ||
151 | LEAF(_ev_unlock) | |
1c79356b A |
152 | sync |
153 | li a7,0 | |
154 | stw a7,0(a0) | |
155 | ENABLE_PREEMPTION() | |
156 | blr | |
157 | END(_ev_unlock) | |
158 | ||
0b4e3aa0 A |
159 | LEAF(_IOSpinUnlock) |
160 | sync | |
161 | li a7,0 | |
162 | stw a7,0(a0) | |
163 | ENABLE_PREEMPTION() | |
164 | blr | |
165 | END(_IOSpinUnlock) | |
166 | ||
1c79356b A |
167 | |
168 | /* | |
169 | * ev_try_lock(p) | |
170 | * int *p; | |
171 | * | |
172 | * Try to lock p. Return TRUE if successful in obtaining lock. | |
173 | */ | |
174 | ||
175 | LEAF(_ev_try_lock) | |
55e303ae A |
176 | |
177 | DISABLE_PREEMPTION() | |
178 | ||
179 | li a6,1 // lock value | |
180 | ||
181 | lwz a7,0(a0) // Get lock word | |
182 | mr. a7,a7 // Is it held? | |
183 | bne-- 6f // Yup... | |
184 | ||
185 | 9: lwarx a7,0,a0 // read the lock | |
186 | mr. a7,a7 // Is it held? | |
187 | bne-- 7f // yes, kill reservation | |
188 | stwcx. a6,0,a0 // try to get the lock | |
189 | bne-- 9b // failed, try again | |
190 | li a0,1 // return TRUE | |
191 | isync | |
192 | blr // got it, return | |
193 | ||
194 | 7: li a7,-4 // Point to a spot in the red zone | |
195 | stwcx. a7,a7,r1 // Kill reservation | |
196 | ||
197 | 6: | |
198 | ENABLE_PREEMPTION() | |
199 | li a0,0 // return FALSE | |
200 | blr | |
201 | ||
1c79356b A |
202 | END(_ev_try_lock) |
203 | ||
0b4e3aa0 | 204 | LEAF(_IOTrySpinLock) |
55e303ae A |
205 | |
206 | DISABLE_PREEMPTION() | |
207 | ||
208 | li a6,1 // lock value | |
209 | ||
210 | lwz a7,0(a0) // Get lock word | |
211 | mr. a7,a7 // Is it held? | |
212 | bne-- 6f // Yup... | |
213 | ||
214 | 9: lwarx a7,0,a0 // read the lock | |
215 | mr. a7,a7 // Is it held? | |
216 | bne-- 7f // yes, kill reservation | |
217 | stwcx. a6,0,a0 // try to get the lock | |
218 | bne-- 9b // failed, try again | |
219 | li a0,1 // return TRUE | |
220 | isync | |
221 | blr // got it, return | |
222 | ||
223 | 7: li a7,-4 // Point to a spot in the red zone | |
224 | stwcx. a7,a7,r1 // Kill reservation | |
225 | ||
226 | 6: | |
227 | ENABLE_PREEMPTION() | |
228 | li a0,0 // return FALSE | |
229 | blr | |
230 | ||
0b4e3aa0 A |
231 | END(_IOTrySpinLock) |
232 | ||
1c79356b | 233 | #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */ |