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