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
11 * We exclusively read the old value. If it is zero, we may have
12 * won the lock, so we try exclusively storing it. A memory barrier
13 * is required after we get a lock, and before we release it, because
14 * V6 CPUs are assumed to have weakly ordered memory.
20 #define __raw_spin_is_locked(x) ((x)->lock != 0)
21 #define __raw_spin_unlock_wait(lock) \
22 do { while (__raw_spin_is_locked(lock)) cpu_relax(); } while (0)
24 #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
26 static inline void __raw_spin_lock(raw_spinlock_t
*lock
)
33 " strexeq %0, %2, [%1]\n"
37 : "r" (&lock
->lock
), "r" (1)
43 static inline int __raw_spin_trylock(raw_spinlock_t
*lock
)
50 " strexeq %0, %2, [%1]"
52 : "r" (&lock
->lock
), "r" (1)
63 static inline void __raw_spin_unlock(raw_spinlock_t
*lock
)
70 : "r" (&lock
->lock
), "r" (0)
78 * Write locks are easy - we just set bit 31. When unlocking, we can
79 * just write zero since the lock is exclusively held.
81 #define rwlock_is_locked(x) (*((volatile unsigned int *)(x)) != 0)
83 static inline void __raw_write_lock(rwlock_t
*rw
)
90 " strexeq %0, %2, [%1]\n"
94 : "r" (&rw
->lock
), "r" (0x80000000)
100 static inline int __raw_write_trylock(rwlock_t
*rw
)
104 __asm__
__volatile__(
105 "1: ldrex %0, [%1]\n"
107 " strexeq %0, %2, [%1]"
109 : "r" (&rw
->lock
), "r" (0x80000000)
120 static inline void __raw_write_unlock(raw_rwlock_t
*rw
)
124 __asm__
__volatile__(
127 : "r" (&rw
->lock
), "r" (0)
132 * Read locks are a bit more hairy:
133 * - Exclusively load the lock value.
135 * - Store new lock value if positive, and we still own this location.
136 * If the value is negative, we've already failed.
137 * - If we failed to store the value, we want a negative result.
138 * - If we failed, try again.
139 * Unlocking is similarly hairy. We may have multiple read locks
140 * currently active. However, we know we won't have any write
143 static inline void __raw_read_lock(raw_rwlock_t
*rw
)
145 unsigned long tmp
, tmp2
;
147 __asm__
__volatile__(
148 "1: ldrex %0, [%2]\n"
150 " strexpl %1, %0, [%2]\n"
151 " rsbpls %0, %1, #0\n"
153 : "=&r" (tmp
), "=&r" (tmp2
)
160 static inline void __raw_read_unlock(rwlock_t
*rw
)
162 unsigned long tmp
, tmp2
;
166 __asm__
__volatile__(
167 "1: ldrex %0, [%2]\n"
169 " strex %1, %0, [%2]\n"
172 : "=&r" (tmp
), "=&r" (tmp2
)
177 #define __raw_read_trylock(lock) generic__raw_read_trylock(lock)
179 #endif /* __ASM_SPINLOCK_H */