]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb 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 | |
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@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * Copyright (c) 1998 Apple Computer, Inc. All rights reserved. | |
32 | * | |
33 | * HISTORY | |
34 | * | |
35 | */ | |
36 | ||
37 | /* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. | |
38 | * | |
39 | * EventShmemLock.h - Shared memory area locks for use between the | |
40 | * WindowServer and the Event Driver. | |
41 | * | |
42 | * HISTORY | |
43 | * 30 Nov 1992 Ben Fathi (benf@next.com) | |
44 | * Ported to m98k. | |
45 | * | |
46 | * 29 April 1992 Mike Paquette at NeXT | |
47 | * Created. | |
48 | * | |
49 | * Multiprocessor locks used within the shared memory area between the | |
50 | * kernel and event system. These must work in both user and kernel mode. | |
51 | * The locks are defined in an include file so they get exported to the local | |
52 | * include file area. | |
53 | */ | |
54 | ||
55 | ||
56 | #ifndef _IOKIT_IOSHAREDLOCKIMP_H | |
57 | #define _IOKIT_IOSHAREDLOCKIMP_H | |
58 | ||
59 | #include <architecture/ppc/asm_help.h> | |
7b1edb79 A |
60 | #ifdef KERNEL |
61 | #undef END | |
62 | #include <mach/ppc/asm.h> | |
63 | #endif | |
1c79356b | 64 | |
1c79356b A |
65 | /* |
66 | * void | |
67 | * ev_lock(p) | |
68 | * register int *p; | |
69 | * | |
70 | * Lock the lock pointed to by p. Spin (possibly forever) until | |
71 | * the lock is available. Test and test and set logic used. | |
72 | */ | |
73 | TEXT | |
74 | ||
75 | #ifndef KERNEL | |
76 | LEAF(_ev_lock) | |
55e303ae A |
77 | |
78 | li a6,1 // lock value | |
79 | ||
80 | 8: lwz a7,0(a0) // Get lock word | |
81 | mr. a7,a7 // Is it held? | |
82 | bne-- 8b // Yup... | |
83 | ||
84 | 9: lwarx a7,0,a0 // read the lock | |
85 | mr. a7,a7 // Is it held? | |
86 | bne-- 7f // yes, kill reservation | |
87 | stwcx. a6,0,a0 // try to get the lock | |
88 | bne-- 9b // failed, try again | |
89 | isync | |
90 | blr // got it, return | |
91 | ||
92 | 7: li a7,-4 // Point to a spot in the red zone | |
93 | stwcx. a7,a7,r1 // Kill reservation | |
94 | b 8b // Go wait some more... | |
95 | ||
96 | ||
1c79356b | 97 | END(_ev_lock) |
0b4e3aa0 A |
98 | |
99 | LEAF(_IOSpinLock) | |
55e303ae A |
100 | |
101 | li a6,1 // lock value | |
102 | ||
103 | 8: lwz a7,0(a0) // Get lock word | |
104 | mr. a7,a7 // Is it held? | |
105 | bne-- 8b // Yup... | |
106 | ||
107 | 9: lwarx a7,0,a0 // read the lock | |
108 | mr. a7,a7 // Is it held? | |
109 | bne-- 7f // yes, kill reservation | |
110 | stwcx. a6,0,a0 // try to get the lock | |
111 | bne-- 9b // failed, try again | |
112 | isync | |
113 | blr // got it, return | |
114 | ||
115 | 7: li a7,-4 // Point to a spot in the red zone | |
116 | stwcx. a7,a7,r1 // Kill reservation | |
117 | b 8b // Go wait some more... | |
0b4e3aa0 | 118 | END(_IOSpinLock) |
1c79356b A |
119 | #endif |
120 | ||
121 | /* | |
122 | * void | |
123 | * spin_unlock(p) | |
124 | * int *p; | |
125 | * | |
126 | * Unlock the lock pointed to by p. | |
127 | */ | |
128 | ||
129 | LEAF(_ev_unlock) | |
1c79356b A |
130 | sync |
131 | li a7,0 | |
132 | stw a7,0(a0) | |
1c79356b A |
133 | blr |
134 | END(_ev_unlock) | |
135 | ||
0b4e3aa0 A |
136 | LEAF(_IOSpinUnlock) |
137 | sync | |
138 | li a7,0 | |
139 | stw a7,0(a0) | |
0b4e3aa0 A |
140 | blr |
141 | END(_IOSpinUnlock) | |
142 | ||
1c79356b A |
143 | |
144 | /* | |
145 | * ev_try_lock(p) | |
146 | * int *p; | |
147 | * | |
148 | * Try to lock p. Return TRUE if successful in obtaining lock. | |
149 | */ | |
150 | ||
151 | LEAF(_ev_try_lock) | |
55e303ae A |
152 | li a6,1 // lock value |
153 | ||
154 | lwz a7,0(a0) // Get lock word | |
155 | mr. a7,a7 // Is it held? | |
156 | bne-- 6f // Yup... | |
157 | ||
158 | 9: lwarx a7,0,a0 // read the lock | |
159 | mr. a7,a7 // Is it held? | |
160 | bne-- 7f // yes, kill reservation | |
161 | stwcx. a6,0,a0 // try to get the lock | |
162 | bne-- 9b // failed, try again | |
163 | li a0,1 // return TRUE | |
164 | isync | |
165 | blr // got it, return | |
166 | ||
167 | 7: li a7,-4 // Point to a spot in the red zone | |
168 | stwcx. a7,a7,r1 // Kill reservation | |
169 | ||
170 | 6: | |
55e303ae A |
171 | li a0,0 // return FALSE |
172 | blr | |
173 | ||
1c79356b A |
174 | END(_ev_try_lock) |
175 | ||
0b4e3aa0 | 176 | LEAF(_IOTrySpinLock) |
55e303ae A |
177 | li a6,1 // lock value |
178 | ||
179 | lwz a7,0(a0) // Get lock word | |
180 | mr. a7,a7 // Is it held? | |
181 | bne-- 6f // Yup... | |
182 | ||
183 | 9: lwarx a7,0,a0 // read the lock | |
184 | mr. a7,a7 // Is it held? | |
185 | bne-- 7f // yes, kill reservation | |
186 | stwcx. a6,0,a0 // try to get the lock | |
187 | bne-- 9b // failed, try again | |
188 | li a0,1 // return TRUE | |
189 | isync | |
190 | blr // got it, return | |
191 | ||
192 | 7: li a7,-4 // Point to a spot in the red zone | |
193 | stwcx. a7,a7,r1 // Kill reservation | |
194 | ||
195 | 6: | |
55e303ae A |
196 | li a0,0 // return FALSE |
197 | blr | |
198 | ||
0b4e3aa0 A |
199 | END(_IOTrySpinLock) |
200 | ||
1c79356b | 201 | #endif /* ! _IOKIT_IOSHAREDLOCKIMP_H */ |