1 #ifndef __ASM_SPINLOCK_H
2 #define __ASM_SPINLOCK_H
4 #if __LINUX_ARM_ARCH__ < 6
5 #error SMP not supported on pre-ARMv6 CPUs
8 static inline void dsb_sev(void)
10 #if __LINUX_ARM_ARCH__ >= 7
11 __asm__
__volatile__ (
15 #elif defined(CONFIG_CPU_32v6K)
16 __asm__
__volatile__ (
17 "mcr p15, 0, %0, c7, c10, 4\n"
27 * We exclusively read the old value. If it is zero, we may have
28 * won the lock, so we try exclusively storing it. A memory barrier
29 * is required after we get a lock, and before we release it, because
30 * V6 CPUs are assumed to have weakly ordered memory.
36 #define arch_spin_is_locked(x) ((x)->lock != 0)
37 #define arch_spin_unlock_wait(lock) \
38 do { while (arch_spin_is_locked(lock)) cpu_relax(); } while (0)
40 #define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
42 static inline void arch_spin_lock(arch_spinlock_t
*lock
)
49 #ifdef CONFIG_CPU_32v6K
52 " strexeq %0, %2, [%1]\n"
56 : "r" (&lock
->lock
), "r" (1)
62 static inline int arch_spin_trylock(arch_spinlock_t
*lock
)
69 " strexeq %0, %2, [%1]"
71 : "r" (&lock
->lock
), "r" (1)
82 static inline void arch_spin_unlock(arch_spinlock_t
*lock
)
89 : "r" (&lock
->lock
), "r" (0)
99 * Write locks are easy - we just set bit 31. When unlocking, we can
100 * just write zero since the lock is exclusively held.
103 static inline void arch_write_lock(arch_rwlock_t
*rw
)
107 __asm__
__volatile__(
108 "1: ldrex %0, [%1]\n"
110 #ifdef CONFIG_CPU_32v6K
113 " strexeq %0, %2, [%1]\n"
117 : "r" (&rw
->lock
), "r" (0x80000000)
123 static inline int arch_write_trylock(arch_rwlock_t
*rw
)
127 __asm__
__volatile__(
128 "1: ldrex %0, [%1]\n"
130 " strexeq %0, %2, [%1]"
132 : "r" (&rw
->lock
), "r" (0x80000000)
143 static inline void arch_write_unlock(arch_rwlock_t
*rw
)
147 __asm__
__volatile__(
150 : "r" (&rw
->lock
), "r" (0)
156 /* write_can_lock - would write_trylock() succeed? */
157 #define arch_write_can_lock(x) ((x)->lock == 0)
160 * Read locks are a bit more hairy:
161 * - Exclusively load the lock value.
163 * - Store new lock value if positive, and we still own this location.
164 * If the value is negative, we've already failed.
165 * - If we failed to store the value, we want a negative result.
166 * - If we failed, try again.
167 * Unlocking is similarly hairy. We may have multiple read locks
168 * currently active. However, we know we won't have any write
171 static inline void arch_read_lock(arch_rwlock_t
*rw
)
173 unsigned long tmp
, tmp2
;
175 __asm__
__volatile__(
176 "1: ldrex %0, [%2]\n"
178 " strexpl %1, %0, [%2]\n"
179 #ifdef CONFIG_CPU_32v6K
182 " rsbpls %0, %1, #0\n"
184 : "=&r" (tmp
), "=&r" (tmp2
)
191 static inline void arch_read_unlock(arch_rwlock_t
*rw
)
193 unsigned long tmp
, tmp2
;
197 __asm__
__volatile__(
198 "1: ldrex %0, [%2]\n"
200 " strex %1, %0, [%2]\n"
203 : "=&r" (tmp
), "=&r" (tmp2
)
211 static inline int arch_read_trylock(arch_rwlock_t
*rw
)
213 unsigned long tmp
, tmp2
= 1;
215 __asm__
__volatile__(
216 "1: ldrex %0, [%2]\n"
218 " strexpl %1, %0, [%2]\n"
219 : "=&r" (tmp
), "+r" (tmp2
)
227 /* read_can_lock - would read_trylock() succeed? */
228 #define arch_read_can_lock(x) ((x)->lock < 0x80000000)
230 #define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
231 #define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
233 #define arch_spin_relax(lock) cpu_relax()
234 #define arch_read_relax(lock) cpu_relax()
235 #define arch_write_relax(lock) cpu_relax()
237 #endif /* __ASM_SPINLOCK_H */