2 * include/asm-sh/spinlock.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_H
12 #define __ASM_SH_SPINLOCK_H
15 * The only locking implemented here uses SH-4A opcodes. For others,
16 * split this out as per atomic-*.h.
18 #ifndef CONFIG_CPU_SH4A
19 #error "Need movli.l/movco.l for spinlocks"
22 #include <asm/barrier.h>
23 #include <asm/processor.h>
26 * Your basic SMP spinlocks, allowing only a single CPU anywhere
29 #define arch_spin_is_locked(x) ((x)->lock <= 0)
30 #define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
32 static inline void arch_spin_unlock_wait(arch_spinlock_t
*lock
)
34 smp_cond_load_acquire(&lock
->lock
, VAL
> 0);
38 * Simple spin lock operations. There are two variants, one clears IRQ's
39 * on the local processor, one does not.
41 * We make no fairness assumptions. They have a cost.
43 static inline void arch_spin_lock(arch_spinlock_t
*lock
)
48 __asm__
__volatile__ (
50 "movli.l @%2, %0 ! arch_spin_lock \n\t"
53 "movco.l %0, @%2 \n\t"
57 : "=&z" (tmp
), "=&r" (oldval
)
63 static inline void arch_spin_unlock(arch_spinlock_t
*lock
)
67 __asm__
__volatile__ (
68 "mov #1, %0 ! arch_spin_unlock \n\t"
76 static inline int arch_spin_trylock(arch_spinlock_t
*lock
)
78 unsigned long tmp
, oldval
;
80 __asm__
__volatile__ (
82 "movli.l @%2, %0 ! arch_spin_trylock \n\t"
85 "movco.l %0, @%2 \n\t"
88 : "=&z" (tmp
), "=&r" (oldval
)
97 * Read-write spinlocks, allowing multiple readers but only one writer.
99 * NOTE! it is quite common to have readers in interrupts but no interrupt
100 * writers. For those circumstances we can "mix" irq-safe locks - any writer
101 * needs to get a irq-safe write-lock, but readers can get non-irqsafe
106 * read_can_lock - would read_trylock() succeed?
107 * @lock: the rwlock in question.
109 #define arch_read_can_lock(x) ((x)->lock > 0)
112 * write_can_lock - would write_trylock() succeed?
113 * @lock: the rwlock in question.
115 #define arch_write_can_lock(x) ((x)->lock == RW_LOCK_BIAS)
117 static inline void arch_read_lock(arch_rwlock_t
*rw
)
121 __asm__
__volatile__ (
123 "movli.l @%1, %0 ! arch_read_lock \n\t"
127 "movco.l %0, @%1 \n\t"
135 static inline void arch_read_unlock(arch_rwlock_t
*rw
)
139 __asm__
__volatile__ (
141 "movli.l @%1, %0 ! arch_read_unlock \n\t"
143 "movco.l %0, @%1 \n\t"
151 static inline void arch_write_lock(arch_rwlock_t
*rw
)
155 __asm__
__volatile__ (
157 "movli.l @%1, %0 ! arch_write_lock \n\t"
161 "movco.l %0, @%1 \n\t"
164 : "r" (&rw
->lock
), "r" (RW_LOCK_BIAS
)
169 static inline void arch_write_unlock(arch_rwlock_t
*rw
)
171 __asm__
__volatile__ (
172 "mov.l %1, @%0 ! arch_write_unlock \n\t"
174 : "r" (&rw
->lock
), "r" (RW_LOCK_BIAS
)
179 static inline int arch_read_trylock(arch_rwlock_t
*rw
)
181 unsigned long tmp
, oldval
;
183 __asm__
__volatile__ (
185 "movli.l @%2, %0 ! arch_read_trylock \n\t"
190 "movco.l %0, @%2 \n\t"
194 : "=&z" (tmp
), "=&r" (oldval
)
202 static inline int arch_write_trylock(arch_rwlock_t
*rw
)
204 unsigned long tmp
, oldval
;
206 __asm__
__volatile__ (
208 "movli.l @%2, %0 ! arch_write_trylock \n\t"
214 "movco.l %0, @%2 \n\t"
217 : "=&z" (tmp
), "=&r" (oldval
)
218 : "r" (&rw
->lock
), "r" (RW_LOCK_BIAS
)
222 return (oldval
> (RW_LOCK_BIAS
- 1));
225 #define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
226 #define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
228 #define arch_spin_relax(lock) cpu_relax()
229 #define arch_read_relax(lock) cpu_relax()
230 #define arch_write_relax(lock) cpu_relax()
232 #endif /* __ASM_SH_SPINLOCK_H */
This page took 0.040114 seconds and 5 git commands to generate.