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
15 * Your basic SMP spinlocks, allowing only a single CPU anywhere
18 #define __raw_spin_is_locked(x) ((x)->lock != 0)
19 #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
20 #define __raw_spin_unlock_wait(x) \
21 do { cpu_relax(); } while ((x)->lock)
24 * Simple spin lock operations. There are two variants, one clears IRQ's
25 * on the local processor, one does not.
27 * We make no fairness assumptions. They have a cost.
30 static inline void __raw_spin_lock(raw_spinlock_t
*lock
)
34 if (R10000_LLSC_WAR
) {
36 " .set noreorder # __raw_spin_lock \n"
45 : "=m" (lock
->lock
), "=&r" (tmp
)
50 " .set noreorder # __raw_spin_lock \n"
58 : "=m" (lock
->lock
), "=&r" (tmp
)
64 static inline void __raw_spin_unlock(raw_spinlock_t
*lock
)
67 " .set noreorder # __raw_spin_unlock \n"
76 static inline unsigned int __raw_spin_trylock(raw_spinlock_t
*lock
)
78 unsigned int temp
, res
;
80 if (R10000_LLSC_WAR
) {
82 " .set noreorder # __raw_spin_trylock \n"
91 : "=&r" (temp
), "=m" (lock
->lock
), "=&r" (res
)
96 " .set noreorder # __raw_spin_trylock \n"
104 : "=&r" (temp
), "=m" (lock
->lock
), "=&r" (res
)
113 * Read-write spinlocks, allowing multiple readers but only one writer.
115 * NOTE! it is quite common to have readers in interrupts but no interrupt
116 * writers. For those circumstances we can "mix" irq-safe locks - any writer
117 * needs to get a irq-safe write-lock, but readers can get non-irqsafe
122 * read_can_lock - would read_trylock() succeed?
123 * @lock: the rwlock in question.
125 #define __raw_read_can_lock(rw) ((rw)->lock >= 0)
128 * write_can_lock - would write_trylock() succeed?
129 * @lock: the rwlock in question.
131 #define __raw_write_can_lock(rw) (!(rw)->lock)
133 static inline void __raw_read_lock(raw_rwlock_t
*rw
)
137 if (R10000_LLSC_WAR
) {
138 __asm__
__volatile__(
139 " .set noreorder # __raw_read_lock \n"
148 : "=m" (rw
->lock
), "=&r" (tmp
)
152 __asm__
__volatile__(
153 " .set noreorder # __raw_read_lock \n"
161 : "=m" (rw
->lock
), "=&r" (tmp
)
167 /* Note the use of sub, not subu which will make the kernel die with an
168 overflow exception if we ever try to unlock an rwlock that is already
169 unlocked or is being held by a writer. */
170 static inline void __raw_read_unlock(raw_rwlock_t
*rw
)
174 if (R10000_LLSC_WAR
) {
175 __asm__
__volatile__(
176 "1: ll %1, %2 # __raw_read_unlock \n"
181 : "=m" (rw
->lock
), "=&r" (tmp
)
185 __asm__
__volatile__(
186 " .set noreorder # __raw_read_unlock \n"
193 : "=m" (rw
->lock
), "=&r" (tmp
)
199 static inline void __raw_write_lock(raw_rwlock_t
*rw
)
203 if (R10000_LLSC_WAR
) {
204 __asm__
__volatile__(
205 " .set noreorder # __raw_write_lock \n"
213 : "=m" (rw
->lock
), "=&r" (tmp
)
217 __asm__
__volatile__(
218 " .set noreorder # __raw_write_lock \n"
226 : "=m" (rw
->lock
), "=&r" (tmp
)
232 static inline void __raw_write_unlock(raw_rwlock_t
*rw
)
234 __asm__
__volatile__(
235 " sync # __raw_write_unlock \n"
242 #define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
244 static inline int __raw_write_trylock(raw_rwlock_t
*rw
)
249 if (R10000_LLSC_WAR
) {
250 __asm__
__volatile__(
251 " .set noreorder # __raw_write_trylock \n"
262 : "=m" (rw
->lock
), "=&r" (tmp
), "=&r" (ret
)
266 __asm__
__volatile__(
267 " .set noreorder # __raw_write_trylock \n"
278 : "=m" (rw
->lock
), "=&r" (tmp
), "=&r" (ret
)
286 #endif /* _ASM_SPINLOCK_H */