]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
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> | |
7b1edb79 A |
58 | #ifdef KERNEL |
59 | #undef END | |
60 | #include <mach/ppc/asm.h> | |
61 | #endif | |
1c79356b | 62 | |
1c79356b A |
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) | |
55e303ae A |
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 | ||
1c79356b | 95 | END(_ev_lock) |
0b4e3aa0 A |
96 | |
97 | LEAF(_IOSpinLock) | |
55e303ae A |
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... | |
0b4e3aa0 | 116 | END(_IOSpinLock) |
1c79356b A |
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) | |
1c79356b A |
128 | sync |
129 | li a7,0 | |
130 | stw a7,0(a0) | |
1c79356b A |
131 | blr |
132 | END(_ev_unlock) | |
133 | ||
0b4e3aa0 A |
134 | LEAF(_IOSpinUnlock) |
135 | sync | |
136 | li a7,0 | |
137 | stw a7,0(a0) | |
0b4e3aa0 A |
138 | blr |
139 | END(_IOSpinUnlock) | |
140 | ||
1c79356b A |
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) | |
55e303ae A |
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: | |
55e303ae A |
169 | li a0,0 // return FALSE |
170 | blr | |
171 | ||
1c79356b A |
172 | END(_ev_try_lock) |
173 | ||
0b4e3aa0 | 174 | LEAF(_IOTrySpinLock) |
55e303ae A |
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: | |
55e303ae A |
194 | li a0,0 // return FALSE |
195 | blr | |
196 | ||
0b4e3aa0 A |
197 | END(_IOTrySpinLock) |
198 | ||
1c79356b | 199 | #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */ |