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