1 /* $NetBSD: lock.h,v 1.27 2008/04/28 20:23:11 martin Exp $ */
4 * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Machine-dependent spin lock operations.
37 #ifndef _ALPHA_LOCK_H_
38 #define _ALPHA_LOCK_H_
41 #include "opt_multiprocessor.h"
45 __SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t
*__ptr
)
47 return *__ptr
== __SIMPLELOCK_LOCKED
;
51 __SIMPLELOCK_UNLOCKED_P(__cpu_simple_lock_t
*__ptr
)
53 return *__ptr
== __SIMPLELOCK_UNLOCKED
;
57 __cpu_simple_lock_clear(__cpu_simple_lock_t
*__ptr
)
59 *__ptr
= __SIMPLELOCK_UNLOCKED
;
63 __cpu_simple_lock_set(__cpu_simple_lock_t
*__ptr
)
65 *__ptr
= __SIMPLELOCK_LOCKED
;
69 __cpu_simple_lock_init(__cpu_simple_lock_t
*alp
)
73 "# BEGIN __cpu_simple_lock_init\n"
76 " # END __cpu_simple_lock_init"
81 __cpu_simple_lock(__cpu_simple_lock_t
*alp
)
86 * Note, if we detect that the lock is held when
87 * we do the initial load-locked, we spin using
88 * a non-locked load to save the coherency logic
93 "# BEGIN __cpu_simple_lock\n"
106 " # END __cpu_simple_lock\n"
107 : "=&r" (t0
), "=m" (*alp
)
108 : "i" (__SIMPLELOCK_LOCKED
), "m" (*alp
)
113 __cpu_simple_lock_try(__cpu_simple_lock_t
*alp
)
115 unsigned long t0
, v0
;
118 "# BEGIN __cpu_simple_lock_try\n"
121 " bis $31, %3, %0 \n"
127 "2: bis $31, $31, %1 \n"
131 " # END __cpu_simple_lock_try"
132 : "=&r" (t0
), "=r" (v0
), "=m" (*alp
)
133 : "i" (__SIMPLELOCK_LOCKED
), "m" (*alp
)
140 __cpu_simple_unlock(__cpu_simple_lock_t
*alp
)
144 "# BEGIN __cpu_simple_unlock\n"
147 " # END __cpu_simple_unlock"
151 #if defined(MULTIPROCESSOR)
153 * On the Alpha, interprocessor interrupts come in at device priority
154 * level. This can cause some problems while waiting for r/w spinlocks
155 * from a high'ish priority level: IPIs that come in will not be processed.
156 * This can lead to deadlock.
158 * This hook allows IPIs to be processed while a spinlock's interlock
161 #define SPINLOCK_SPIN_HOOK \
163 struct cpu_info *__ci = curcpu(); \
166 if (__ci->ci_ipis != 0) { \
167 /* printf("CPU %lu has IPIs pending\n", \
168 __ci->ci_cpuid); */ \
170 alpha_ipi_process(__ci, NULL); \
174 #define SPINLOCK_BACKOFF_HOOK (void)nullop((void *)0)
175 #endif /* MULTIPROCESSOR */
180 __asm
__volatile("mb" : : : "memory");
187 __asm
__volatile("mb" : : : "memory");
193 __asm
__volatile("mb" : : : "memory");
196 #endif /* _ALPHA_LOCK_H_ */