2 * include/asm-sh/spinlock-llsc.h
4 * Copyright (C) 2002, 2003 Paul Mundt
5 * Copyright (C) 2006, 2007 Akio Idehara
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
11 #ifndef __ASM_SH_SPINLOCK_LLSC_H
12 #define __ASM_SH_SPINLOCK_LLSC_H
14 #include <asm/barrier.h>
15 #include <asm/processor.h>
18 * Your basic SMP spinlocks, allowing only a single CPU anywhere
21 #define arch_spin_is_locked(x) ((x)->lock <= 0)
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.
29 static inline void arch_spin_lock(arch_spinlock_t
*lock
)
34 __asm__
__volatile__ (
36 "movli.l @%2, %0 ! arch_spin_lock \n\t"
39 "movco.l %0, @%2 \n\t"
43 : "=&z" (tmp
), "=&r" (oldval
)
49 static inline void arch_spin_unlock(arch_spinlock_t
*lock
)
53 __asm__
__volatile__ (
54 "mov #1, %0 ! arch_spin_unlock \n\t"
62 static inline int arch_spin_trylock(arch_spinlock_t
*lock
)
64 unsigned long tmp
, oldval
;
66 __asm__
__volatile__ (
68 "movli.l @%2, %0 ! arch_spin_trylock \n\t"
71 "movco.l %0, @%2 \n\t"
74 : "=&z" (tmp
), "=&r" (oldval
)
83 * Read-write spinlocks, allowing multiple readers but only one writer.
85 * NOTE! it is quite common to have readers in interrupts but no interrupt
86 * writers. For those circumstances we can "mix" irq-safe locks - any writer
87 * needs to get a irq-safe write-lock, but readers can get non-irqsafe
91 static inline void arch_read_lock(arch_rwlock_t
*rw
)
95 __asm__
__volatile__ (
97 "movli.l @%1, %0 ! arch_read_lock \n\t"
101 "movco.l %0, @%1 \n\t"
109 static inline void arch_read_unlock(arch_rwlock_t
*rw
)
113 __asm__
__volatile__ (
115 "movli.l @%1, %0 ! arch_read_unlock \n\t"
117 "movco.l %0, @%1 \n\t"
125 static inline void arch_write_lock(arch_rwlock_t
*rw
)
129 __asm__
__volatile__ (
131 "movli.l @%1, %0 ! arch_write_lock \n\t"
135 "movco.l %0, @%1 \n\t"
138 : "r" (&rw
->lock
), "r" (RW_LOCK_BIAS
)
143 static inline void arch_write_unlock(arch_rwlock_t
*rw
)
145 __asm__
__volatile__ (
146 "mov.l %1, @%0 ! arch_write_unlock \n\t"
148 : "r" (&rw
->lock
), "r" (RW_LOCK_BIAS
)
153 static inline int arch_read_trylock(arch_rwlock_t
*rw
)
155 unsigned long tmp
, oldval
;
157 __asm__
__volatile__ (
159 "movli.l @%2, %0 ! arch_read_trylock \n\t"
164 "movco.l %0, @%2 \n\t"
168 : "=&z" (tmp
), "=&r" (oldval
)
176 static inline int arch_write_trylock(arch_rwlock_t
*rw
)
178 unsigned long tmp
, oldval
;
180 __asm__
__volatile__ (
182 "movli.l @%2, %0 ! arch_write_trylock \n\t"
188 "movco.l %0, @%2 \n\t"
191 : "=&z" (tmp
), "=&r" (oldval
)
192 : "r" (&rw
->lock
), "r" (RW_LOCK_BIAS
)
196 return (oldval
> (RW_LOCK_BIAS
- 1));
199 #endif /* __ASM_SH_SPINLOCK_LLSC_H */