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
20 volatile unsigned int lock;
22 unsigned int break_lock;
26 #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
28 #define spin_lock_init(x) do { (x)->lock = 0; } while(0)
30 #define spin_is_locked(x) ((x)->lock != 0)
31 #define spin_unlock_wait(x) do { barrier(); } while ((x)->lock)
32 #define _raw_spin_lock_flags(lock, flags) _raw_spin_lock(lock)
35 * Simple spin lock operations. There are two variants, one clears IRQ's
36 * on the local processor, one does not.
38 * We make no fairness assumptions. They have a cost.
41 static inline void _raw_spin_lock(spinlock_t *lock)
45 if (R10000_LLSC_WAR) {
47 " .set noreorder # _raw_spin_lock \n"
56 : "=m" (lock->lock), "=&r" (tmp)
61 " .set noreorder # _raw_spin_lock \n"
69 : "=m" (lock->lock), "=&r" (tmp)
75 static inline void _raw_spin_unlock(spinlock_t *lock)
78 " .set noreorder # _raw_spin_unlock \n"
87 static inline unsigned int _raw_spin_trylock(spinlock_t *lock)
89 unsigned int temp, res;
91 if (R10000_LLSC_WAR) {
93 " .set noreorder # _raw_spin_trylock \n"
102 : "=&r" (temp), "=m" (lock->lock), "=&r" (res)
106 __asm__ __volatile__(
107 " .set noreorder # _raw_spin_trylock \n"
115 : "=&r" (temp), "=m" (lock->lock), "=&r" (res)
124 * Read-write spinlocks, allowing multiple readers but only one writer.
126 * NOTE! it is quite common to have readers in interrupts but no interrupt
127 * writers. For those circumstances we can "mix" irq-safe locks - any writer
128 * needs to get a irq-safe write-lock, but readers can get non-irqsafe
133 volatile unsigned int lock;
134 #ifdef CONFIG_PREEMPT
135 unsigned int break_lock;
139 #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
141 #define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
143 static inline void _raw_read_lock(rwlock_t *rw)
147 if (R10000_LLSC_WAR) {
148 __asm__ __volatile__(
149 " .set noreorder # _raw_read_lock \n"
158 : "=m" (rw->lock), "=&r" (tmp)
162 __asm__ __volatile__(
163 " .set noreorder # _raw_read_lock \n"
171 : "=m" (rw->lock), "=&r" (tmp)
177 /* Note the use of sub, not subu which will make the kernel die with an
178 overflow exception if we ever try to unlock an rwlock that is already
179 unlocked or is being held by a writer. */
180 static inline void _raw_read_unlock(rwlock_t *rw)
184 if (R10000_LLSC_WAR) {
185 __asm__ __volatile__(
186 "1: ll %1, %2 # _raw_read_unlock \n"
191 : "=m" (rw->lock), "=&r" (tmp)
195 __asm__ __volatile__(
196 " .set noreorder # _raw_read_unlock \n"
203 : "=m" (rw->lock), "=&r" (tmp)
209 static inline void _raw_write_lock(rwlock_t *rw)
213 if (R10000_LLSC_WAR) {
214 __asm__ __volatile__(
215 " .set noreorder # _raw_write_lock \n"
224 : "=m" (rw->lock), "=&r" (tmp)
228 __asm__ __volatile__(
229 " .set noreorder # _raw_write_lock \n"
238 : "=m" (rw->lock), "=&r" (tmp)
244 static inline void _raw_write_unlock(rwlock_t *rw)
246 __asm__ __volatile__(
247 " sync # _raw_write_unlock \n"
254 #define _raw_read_trylock(lock) generic_raw_read_trylock(lock)
256 static inline int _raw_write_trylock(rwlock_t *rw)
261 if (R10000_LLSC_WAR) {
262 __asm__ __volatile__(
263 " .set noreorder # _raw_write_trylock \n"
275 : "=m" (rw->lock), "=&r" (tmp), "=&r" (ret)
279 __asm__ __volatile__(
280 " .set noreorder # _raw_write_trylock \n"
291 : "=m" (rw->lock), "=&r" (tmp), "=&r" (ret)
299 #endif /* _ASM_SPINLOCK_H */