No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / vax / include / lock.h
blob0618c9d4e0cd1ace9ed3de7a88368b6ea0c14327
1 /* $NetBSD: lock.h,v 1.28 2008/02/23 05:48:13 matt Exp $ */
3 /*
4 * Copyright (c) 2000 Ludd, University of Lule}, Sweden.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
33 #ifndef _VAX_LOCK_H_
34 #define _VAX_LOCK_H_
36 #include <sys/param.h>
38 #ifdef _KERNEL
39 #ifdef _KERNEL_OPT
40 #include "opt_multiprocessor.h"
41 #include <machine/intr.h>
42 #endif
43 #include <machine/cpu.h>
44 #endif
46 static __inline int
47 __SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t *__ptr)
49 return *__ptr == __SIMPLELOCK_LOCKED;
52 static __inline int
53 __SIMPLELOCK_UNLOCKED_P(__cpu_simple_lock_t *__ptr)
55 return *__ptr == __SIMPLELOCK_UNLOCKED;
58 static __inline void
59 __cpu_simple_lock_clear(__cpu_simple_lock_t *__ptr)
61 *__ptr = __SIMPLELOCK_UNLOCKED;
64 static __inline void
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 *);
71 static __inline void
72 __cpu_simple_lock_init(__cpu_simple_lock_t *__alp)
74 #ifdef _HARDKERNEL
75 __asm __volatile ("movl %0,%%r1;jsb Sunlock"
76 : /* No output */
77 : "g"(__alp)
78 : "r1","cc","memory");
79 #else
80 __asm __volatile ("bbcci $0,%0,1f;1:"
81 : /* No output */
82 : "m"(*__alp)
83 : "cc");
84 #endif
87 static __inline int __cpu_simple_lock_try(__cpu_simple_lock_t *);
88 static __inline int
89 __cpu_simple_lock_try(__cpu_simple_lock_t *__alp)
91 int ret;
93 #ifdef _HARDKERNEL
94 __asm __volatile ("movl %1,%%r1;jsb Slocktry;movl %%r0,%0"
95 : "=&r"(ret)
96 : "g"(__alp)
97 : "r0","r1","cc","memory");
98 #else
99 __asm __volatile ("clrl %0;bbssi $0,%1,1f;incl %0;1:"
100 : "=&r"(ret)
101 : "m"(*__alp)
102 : "cc");
103 #endif
105 return ret;
108 static __inline void __cpu_simple_lock(__cpu_simple_lock_t *);
109 static __inline void
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) {
118 cpu_handle_ipi();
121 #else /* _HARDKERNEL && MULTIPROCESSOR */
122 __asm __volatile ("1:bbssi $0,%0,1b"
123 : /* No outputs */
124 : "m"(*__alp)
125 : "cc");
126 #endif /* _HARDKERNEL && MULTIPROCESSOR */
129 static __inline void __cpu_simple_unlock(__cpu_simple_lock_t *);
130 static __inline void
131 __cpu_simple_unlock(__cpu_simple_lock_t *__alp)
133 #ifdef _HARDKERNEL
134 __asm __volatile ("movl %0,%%r1;jsb Sunlock"
135 : /* No output */
136 : "g"(__alp)
137 : "r1","cc","memory");
138 #else
139 __asm __volatile ("bbcci $0,%0,1f;1:"
140 : /* No output */
141 : "m"(*__alp)
142 : "cc");
143 #endif
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
154 * is released.
156 #define SPINLOCK_SPIN_HOOK \
157 do { \
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); */ \
163 cpu_handle_ipi(); \
165 } while (/*CONSTCOND*/0)
166 #endif /* MULTIPROCESSOR */
168 static __inline void mb_read(void);
169 static __inline void
170 mb_read(void)
174 static __inline void mb_write(void);
175 static __inline void
176 mb_write(void)
179 #endif /* _VAX_LOCK_H_ */