1 /* spinlock.h: 64-bit Sparc spinlock support.
3 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
6 #ifndef __SPARC64_SPINLOCK_H
7 #define __SPARC64_SPINLOCK_H
9 #include <linux/config.h>
10 #include <linux/threads.h> /* For NR_CPUS */
14 /* To get debugging spinlocks which detect and catch
15 * deadlock situations, set CONFIG_DEBUG_SPINLOCK
16 * and rebuild your kernel.
19 /* All of these locking primitives are expected to work properly
20 * even in an RMO memory model, which currently is what the kernel
23 * There is another issue. Because we play games to save cycles
24 * in the non-contention case, we need to be extra careful about
25 * branch targets into the "spinning" code. They live in their
26 * own section, but the newer V9 branches have a shorter range
27 * than the traditional 32-bit sparc branch variants. The rule
28 * is that the branches that go into and out of the spinner sections
29 * must be pre-V9 branches.
32 #define __raw_spin_is_locked(lp) ((lp)->lock != 0)
34 #define __raw_spin_unlock_wait(lp) \
38 static inline void __raw_spin_lock(raw_spinlock_t
*lock
)
43 "1: ldstub [%1], %0\n"
44 " membar #StoreLoad | #StoreStore\n"
52 " ba,a,pt %%xcc, 1b\n"
59 static inline int __raw_spin_trylock(raw_spinlock_t
*lock
)
65 " membar #StoreLoad | #StoreStore"
70 return (result
== 0UL);
73 static inline void __raw_spin_unlock(raw_spinlock_t
*lock
)
76 " membar #StoreStore | #LoadStore\n"
83 static inline void __raw_spin_lock_flags(raw_spinlock_t
*lock
, unsigned long flags
)
85 unsigned long tmp1
, tmp2
;
88 "1: ldstub [%2], %0\n"
89 " membar #StoreLoad | #StoreStore\n"
102 : "=&r" (tmp1
), "=&r" (tmp2
)
103 : "r"(lock
), "r"(flags
)
107 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
109 static void inline __read_lock(raw_rwlock_t
*lock
)
111 unsigned long tmp1
, tmp2
;
113 __asm__
__volatile__ (
117 " cas [%2], %0, %1\n"
119 " membar #StoreLoad | #StoreStore\n"
120 " bne,pn %%icc, 1b\n"
124 " membar #LoadLoad\n"
127 " ba,a,pt %%xcc, 4b\n"
129 : "=&r" (tmp1
), "=&r" (tmp2
)
134 static int inline __read_trylock(raw_rwlock_t
*lock
)
138 __asm__
__volatile__ (
140 " brlz,a,pn %0, 2f\n"
143 " cas [%2], %0, %1\n"
145 " membar #StoreLoad | #StoreStore\n"
146 " bne,pn %%icc, 1b\n"
149 : "=&r" (tmp1
), "=&r" (tmp2
)
156 static void inline __read_unlock(raw_rwlock_t
*lock
)
158 unsigned long tmp1
, tmp2
;
160 __asm__
__volatile__(
161 " membar #StoreLoad | #LoadLoad\n"
164 " cas [%2], %0, %1\n"
166 " bne,pn %%xcc, 1b\n"
168 : "=&r" (tmp1
), "=&r" (tmp2
)
173 static void inline __write_lock(raw_rwlock_t
*lock
)
175 unsigned long mask
, tmp1
, tmp2
;
179 __asm__
__volatile__(
183 " cas [%2], %0, %1\n"
185 " membar #StoreLoad | #StoreStore\n"
186 " bne,pn %%icc, 1b\n"
190 " membar #LoadLoad\n"
193 " ba,a,pt %%xcc, 4b\n"
195 : "=&r" (tmp1
), "=&r" (tmp2
)
196 : "r" (lock
), "r" (mask
)
200 static void inline __write_unlock(raw_rwlock_t
*lock
)
202 __asm__
__volatile__(
203 " membar #LoadStore | #StoreStore\n"
210 static int inline __write_trylock(raw_rwlock_t
*lock
)
212 unsigned long mask
, tmp1
, tmp2
, result
;
216 __asm__
__volatile__(
221 " cas [%3], %0, %1\n"
223 " membar #StoreLoad | #StoreStore\n"
224 " bne,pn %%icc, 1b\n"
228 : "=&r" (tmp1
), "=&r" (tmp2
), "=&r" (result
)
229 : "r" (lock
), "r" (mask
)
235 #define __raw_read_lock(p) __read_lock(p)
236 #define __raw_read_trylock(p) __read_trylock(p)
237 #define __raw_read_unlock(p) __read_unlock(p)
238 #define __raw_write_lock(p) __write_lock(p)
239 #define __raw_write_unlock(p) __write_unlock(p)
240 #define __raw_write_trylock(p) __write_trylock(p)
242 #define __raw_read_can_lock(rw) (!((rw)->lock & 0x80000000UL))
243 #define __raw_write_can_lock(rw) (!(rw)->lock)
245 #endif /* !(__ASSEMBLY__) */
247 #endif /* !(__SPARC64_SPINLOCK_H) */