1 /* spinlock.h: 64-bit Sparc spinlock support.
3 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu)
6 #ifndef __SPARC64_SPINLOCK_H
7 #define __SPARC64_SPINLOCK_H
11 #include <asm/processor.h>
12 #include <asm/barrier.h>
14 /* To get debugging spinlocks which detect and catch
15 * deadlock situations, set CONFIG_DEBUG_SPINLOCK
16 * and rebuild your kernel.
19 /* Because we play games to save cycles in the non-contention case, we
20 * need to be extra careful about branch targets into the "spinning"
21 * code. They live in their own section, but the newer V9 branches
22 * have a shorter range than the traditional 32-bit sparc branch
23 * variants. The rule is that the branches that go into and out of
24 * the spinner sections must be pre-V9 branches.
27 #define arch_spin_is_locked(lp) ((lp)->lock != 0)
29 static inline void arch_spin_unlock_wait(arch_spinlock_t
*lock
)
31 smp_cond_load_acquire(&lock
->lock
, !VAL
);
34 static inline void arch_spin_lock(arch_spinlock_t
*lock
)
39 "1: ldstub [%1], %0\n"
46 " ba,a,pt %%xcc, 1b\n"
53 static inline int arch_spin_trylock(arch_spinlock_t
*lock
)
63 return (result
== 0UL);
66 static inline void arch_spin_unlock(arch_spinlock_t
*lock
)
75 static inline void arch_spin_lock_flags(arch_spinlock_t
*lock
, unsigned long flags
)
77 unsigned long tmp1
, tmp2
;
80 "1: ldstub [%2], %0\n"
92 : "=&r" (tmp1
), "=&r" (tmp2
)
93 : "r"(lock
), "r"(flags
)
97 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
99 static void inline arch_read_lock(arch_rwlock_t
*lock
)
101 unsigned long tmp1
, tmp2
;
103 __asm__
__volatile__ (
107 " cas [%2], %0, %1\n"
109 " bne,pn %%icc, 1b\n"
115 " ba,a,pt %%xcc, 4b\n"
117 : "=&r" (tmp1
), "=&r" (tmp2
)
122 static int inline arch_read_trylock(arch_rwlock_t
*lock
)
126 __asm__
__volatile__ (
128 " brlz,a,pn %0, 2f\n"
131 " cas [%2], %0, %1\n"
133 " bne,pn %%icc, 1b\n"
136 : "=&r" (tmp1
), "=&r" (tmp2
)
143 static void inline arch_read_unlock(arch_rwlock_t
*lock
)
145 unsigned long tmp1
, tmp2
;
147 __asm__
__volatile__(
150 " cas [%2], %0, %1\n"
152 " bne,pn %%xcc, 1b\n"
154 : "=&r" (tmp1
), "=&r" (tmp2
)
159 static void inline arch_write_lock(arch_rwlock_t
*lock
)
161 unsigned long mask
, tmp1
, tmp2
;
165 __asm__
__volatile__(
169 " cas [%2], %0, %1\n"
171 " bne,pn %%icc, 1b\n"
177 " ba,a,pt %%xcc, 4b\n"
179 : "=&r" (tmp1
), "=&r" (tmp2
)
180 : "r" (lock
), "r" (mask
)
184 static void inline arch_write_unlock(arch_rwlock_t
*lock
)
186 __asm__
__volatile__(
193 static int inline arch_write_trylock(arch_rwlock_t
*lock
)
195 unsigned long mask
, tmp1
, tmp2
, result
;
199 __asm__
__volatile__(
204 " cas [%3], %0, %1\n"
206 " bne,pn %%icc, 1b\n"
210 : "=&r" (tmp1
), "=&r" (tmp2
), "=&r" (result
)
211 : "r" (lock
), "r" (mask
)
217 #define arch_read_lock_flags(p, f) arch_read_lock(p)
218 #define arch_write_lock_flags(p, f) arch_write_lock(p)
220 #define arch_read_can_lock(rw) (!((rw)->lock & 0x80000000UL))
221 #define arch_write_can_lock(rw) (!(rw)->lock)
223 #define arch_spin_relax(lock) cpu_relax()
224 #define arch_read_relax(lock) cpu_relax()
225 #define arch_write_relax(lock) cpu_relax()
227 #endif /* !(__ASSEMBLY__) */
229 #endif /* !(__SPARC64_SPINLOCK_H) */