1 /* $NetBSD: lock.h,v 1.28 2008/02/23 05:48:13 matt Exp $ */
4 * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed at Ludd, University of Lule}.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/param.h>
40 #include "opt_multiprocessor.h"
41 #include <machine/intr.h>
43 #include <machine/cpu.h>
47 __SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t
*__ptr
)
49 return *__ptr
== __SIMPLELOCK_LOCKED
;
53 __SIMPLELOCK_UNLOCKED_P(__cpu_simple_lock_t
*__ptr
)
55 return *__ptr
== __SIMPLELOCK_UNLOCKED
;
59 __cpu_simple_lock_clear(__cpu_simple_lock_t
*__ptr
)
61 *__ptr
= __SIMPLELOCK_UNLOCKED
;
65 __cpu_simple_lock_set(__cpu_simple_lock_t
*__ptr
)
67 *__ptr
= __SIMPLELOCK_LOCKED
;
70 static __inline
void __cpu_simple_lock_init(__cpu_simple_lock_t
*);
72 __cpu_simple_lock_init(__cpu_simple_lock_t
*__alp
)
75 __asm
__volatile ("movl %0,%%r1;jsb Sunlock"
78 : "r1","cc","memory");
80 __asm
__volatile ("bbcci $0,%0,1f;1:"
87 static __inline
int __cpu_simple_lock_try(__cpu_simple_lock_t
*);
89 __cpu_simple_lock_try(__cpu_simple_lock_t
*__alp
)
94 __asm
__volatile ("movl %1,%%r1;jsb Slocktry;movl %%r0,%0"
97 : "r0","r1","cc","memory");
99 __asm
__volatile ("clrl %0;bbssi $0,%1,1f;incl %0;1:"
108 static __inline
void __cpu_simple_lock(__cpu_simple_lock_t
*);
110 __cpu_simple_lock(__cpu_simple_lock_t
*__alp
)
112 #if defined(_HARDKERNEL) && defined(MULTIPROCESSOR)
113 struct cpu_info
* const __ci
= curcpu();
115 while (__cpu_simple_lock_try(__alp
) == 0) {
116 #define VAX_LOCK_CHECKS ((1 << IPI_SEND_CNCHAR) | (1 << IPI_DDB))
117 if (__ci
->ci_ipimsgs
& VAX_LOCK_CHECKS
) {
121 #else /* _HARDKERNEL && MULTIPROCESSOR */
122 __asm
__volatile ("1:bbssi $0,%0,1b"
126 #endif /* _HARDKERNEL && MULTIPROCESSOR */
129 static __inline
void __cpu_simple_unlock(__cpu_simple_lock_t
*);
131 __cpu_simple_unlock(__cpu_simple_lock_t
*__alp
)
134 __asm
__volatile ("movl %0,%%r1;jsb Sunlock"
137 : "r1","cc","memory");
139 __asm
__volatile ("bbcci $0,%0,1f;1:"
146 #if defined(MULTIPROCESSOR)
148 * On the Vax, interprocessor interrupts can come in at device priority
149 * level or lower. This can cause some problems while waiting for r/w
150 * spinlocks from a high'ish priority level: IPIs that come in will not
151 * be processed. This can lead to deadlock.
153 * This hook allows IPIs to be processed while a spinlock's interlock
156 #define SPINLOCK_SPIN_HOOK \
158 struct cpu_info * const __ci = curcpu(); \
160 if (__ci->ci_ipimsgs != 0) { \
161 /* printf("CPU %lu has IPIs pending\n", \
162 __ci->ci_cpuid); */ \
165 } while (/*CONSTCOND*/0)
166 #endif /* MULTIPROCESSOR */
168 static __inline
void mb_read(void);
174 static __inline
void mb_write(void);
179 #endif /* _VAX_LOCK_H_ */