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 by Ralf Baechle
7 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 #ifndef _ASM_SPINLOCK_H
10 #define _ASM_SPINLOCK_H
12 #include <linux/config.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"
46 : "=m" (lock
->lock
), "=&r" (tmp
)
51 " .set noreorder # __raw_spin_lock \n"
59 : "=m" (lock
->lock
), "=&r" (tmp
)
65 static inline void __raw_spin_unlock(raw_spinlock_t
*lock
)
68 " .set noreorder # __raw_spin_unlock \n"
77 static inline unsigned int __raw_spin_trylock(raw_spinlock_t
*lock
)
79 unsigned int temp
, res
;
81 if (R10000_LLSC_WAR
) {
83 " .set noreorder # __raw_spin_trylock \n"
92 : "=&r" (temp
), "=m" (lock
->lock
), "=&r" (res
)
97 " .set noreorder # __raw_spin_trylock \n"
105 : "=&r" (temp
), "=m" (lock
->lock
), "=&r" (res
)
114 * Read-write spinlocks, allowing multiple readers but only one writer.
116 * NOTE! it is quite common to have readers in interrupts but no interrupt
117 * writers. For those circumstances we can "mix" irq-safe locks - any writer
118 * needs to get a irq-safe write-lock, but readers can get non-irqsafe
122 static inline void __raw_read_lock(raw_rwlock_t
*rw
)
126 if (R10000_LLSC_WAR
) {
127 __asm__
__volatile__(
128 " .set noreorder # __raw_read_lock \n"
137 : "=m" (rw
->lock
), "=&r" (tmp
)
141 __asm__
__volatile__(
142 " .set noreorder # __raw_read_lock \n"
150 : "=m" (rw
->lock
), "=&r" (tmp
)
156 /* Note the use of sub, not subu which will make the kernel die with an
157 overflow exception if we ever try to unlock an rwlock that is already
158 unlocked or is being held by a writer. */
159 static inline void __raw_read_unlock(raw_rwlock_t
*rw
)
163 if (R10000_LLSC_WAR
) {
164 __asm__
__volatile__(
165 "1: ll %1, %2 # __raw_read_unlock \n"
170 : "=m" (rw
->lock
), "=&r" (tmp
)
174 __asm__
__volatile__(
175 " .set noreorder # __raw_read_unlock \n"
182 : "=m" (rw
->lock
), "=&r" (tmp
)
188 static inline void __raw_write_lock(raw_rwlock_t
*rw
)
192 if (R10000_LLSC_WAR
) {
193 __asm__
__volatile__(
194 " .set noreorder # __raw_write_lock \n"
203 : "=m" (rw
->lock
), "=&r" (tmp
)
207 __asm__
__volatile__(
208 " .set noreorder # __raw_write_lock \n"
217 : "=m" (rw
->lock
), "=&r" (tmp
)
223 static inline void __raw_write_unlock(raw_rwlock_t
*rw
)
225 __asm__
__volatile__(
226 " sync # __raw_write_unlock \n"
233 #define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
235 static inline int __raw_write_trylock(raw_rwlock_t
*rw
)
240 if (R10000_LLSC_WAR
) {
241 __asm__
__volatile__(
242 " .set noreorder # __raw_write_trylock \n"
254 : "=m" (rw
->lock
), "=&r" (tmp
), "=&r" (ret
)
258 __asm__
__volatile__(
259 " .set noreorder # __raw_write_trylock \n"
270 : "=m" (rw
->lock
), "=&r" (tmp
), "=&r" (ret
)
278 #endif /* _ASM_SPINLOCK_H */