2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 1999, 2000, 06 Ralf Baechle (ralf@linux-mips.org)
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 #ifndef _ASM_SPINLOCK_H
10 #define _ASM_SPINLOCK_H
12 #include <asm/barrier.h>
16 * Your basic SMP spinlocks, allowing only a single CPU anywhere
19 #define __raw_spin_is_locked(x) ((x)->lock != 0)
20 #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
21 #define __raw_spin_unlock_wait(x) \
22 do { cpu_relax(); } while ((x)->lock)
25 * Simple spin lock operations. There are two variants, one clears IRQ's
26 * on the local processor, one does not.
28 * We make no fairness assumptions. They have a cost.
31 static inline void __raw_spin_lock(raw_spinlock_t
*lock
)
35 if (R10000_LLSC_WAR
) {
37 " .set noreorder # __raw_spin_lock \n"
45 : "=m" (lock
->lock
), "=&r" (tmp
)
50 " .set noreorder # __raw_spin_lock \n"
65 : "=m" (lock
->lock
), "=&r" (tmp
)
73 static inline void __raw_spin_unlock(raw_spinlock_t
*lock
)
78 " .set noreorder # __raw_spin_unlock \n"
86 static inline unsigned int __raw_spin_trylock(raw_spinlock_t
*lock
)
88 unsigned int temp
, res
;
90 if (R10000_LLSC_WAR
) {
92 " .set noreorder # __raw_spin_trylock \n"
100 : "=&r" (temp
), "=m" (lock
->lock
), "=&r" (res
)
104 __asm__
__volatile__(
105 " .set noreorder # __raw_spin_trylock \n"
116 : "=&r" (temp
), "=m" (lock
->lock
), "=&r" (res
)
127 * Read-write spinlocks, allowing multiple readers but only one writer.
129 * NOTE! it is quite common to have readers in interrupts but no interrupt
130 * writers. For those circumstances we can "mix" irq-safe locks - any writer
131 * needs to get a irq-safe write-lock, but readers can get non-irqsafe
136 * read_can_lock - would read_trylock() succeed?
137 * @lock: the rwlock in question.
139 #define __raw_read_can_lock(rw) ((rw)->lock >= 0)
142 * write_can_lock - would write_trylock() succeed?
143 * @lock: the rwlock in question.
145 #define __raw_write_can_lock(rw) (!(rw)->lock)
147 static inline void __raw_read_lock(raw_rwlock_t
*rw
)
151 if (R10000_LLSC_WAR
) {
152 __asm__
__volatile__(
153 " .set noreorder # __raw_read_lock \n"
161 : "=m" (rw
->lock
), "=&r" (tmp
)
165 __asm__
__volatile__(
166 " .set noreorder # __raw_read_lock \n"
181 : "=m" (rw
->lock
), "=&r" (tmp
)
189 /* Note the use of sub, not subu which will make the kernel die with an
190 overflow exception if we ever try to unlock an rwlock that is already
191 unlocked or is being held by a writer. */
192 static inline void __raw_read_unlock(raw_rwlock_t
*rw
)
198 if (R10000_LLSC_WAR
) {
199 __asm__
__volatile__(
200 "1: ll %1, %2 # __raw_read_unlock \n"
204 : "=m" (rw
->lock
), "=&r" (tmp
)
208 __asm__
__volatile__(
209 " .set noreorder # __raw_read_unlock \n"
220 : "=m" (rw
->lock
), "=&r" (tmp
)
226 static inline void __raw_write_lock(raw_rwlock_t
*rw
)
230 if (R10000_LLSC_WAR
) {
231 __asm__
__volatile__(
232 " .set noreorder # __raw_write_lock \n"
240 : "=m" (rw
->lock
), "=&r" (tmp
)
244 __asm__
__volatile__(
245 " .set noreorder # __raw_write_lock \n"
260 : "=m" (rw
->lock
), "=&r" (tmp
)
268 static inline void __raw_write_unlock(raw_rwlock_t
*rw
)
272 __asm__
__volatile__(
273 " # __raw_write_unlock \n"
280 static inline int __raw_read_trylock(raw_rwlock_t
*rw
)
285 if (R10000_LLSC_WAR
) {
286 __asm__
__volatile__(
287 " .set noreorder # __raw_read_trylock \n"
299 : "=m" (rw
->lock
), "=&r" (tmp
), "=&r" (ret
)
303 __asm__
__volatile__(
304 " .set noreorder # __raw_read_trylock \n"
316 : "=m" (rw
->lock
), "=&r" (tmp
), "=&r" (ret
)
324 static inline int __raw_write_trylock(raw_rwlock_t
*rw
)
329 if (R10000_LLSC_WAR
) {
330 __asm__
__volatile__(
331 " .set noreorder # __raw_write_trylock \n"
343 : "=m" (rw
->lock
), "=&r" (tmp
), "=&r" (ret
)
347 __asm__
__volatile__(
348 " .set noreorder # __raw_write_trylock \n"
363 : "=m" (rw
->lock
), "=&r" (tmp
), "=&r" (ret
)
372 #define _raw_spin_relax(lock) cpu_relax()
373 #define _raw_read_relax(lock) cpu_relax()
374 #define _raw_write_relax(lock) cpu_relax()
376 #endif /* _ASM_SPINLOCK_H */