1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2024b246eSLinus Torvalds #ifndef _ALPHA_SPINLOCK_H
3024b246eSLinus Torvalds #define _ALPHA_SPINLOCK_H
4024b246eSLinus Torvalds
5024b246eSLinus Torvalds #include <linux/kernel.h>
6024b246eSLinus Torvalds #include <asm/current.h>
7726328d9SPeter Zijlstra #include <asm/barrier.h>
8726328d9SPeter Zijlstra #include <asm/processor.h>
9024b246eSLinus Torvalds
10024b246eSLinus Torvalds /*
11024b246eSLinus Torvalds * Simple spin lock operations. There are two variants, one clears IRQ's
12024b246eSLinus Torvalds * on the local processor, one does not.
13024b246eSLinus Torvalds *
14024b246eSLinus Torvalds * We make no fairness assumptions. They have a cost.
15024b246eSLinus Torvalds */
16024b246eSLinus Torvalds
170199c4e6SThomas Gleixner #define arch_spin_is_locked(x) ((x)->lock != 0)
18726328d9SPeter Zijlstra
arch_spin_value_unlocked(arch_spinlock_t lock)198f8dcb3fSMatt Turner static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
208f8dcb3fSMatt Turner {
218f8dcb3fSMatt Turner return lock.lock == 0;
228f8dcb3fSMatt Turner }
238f8dcb3fSMatt Turner
arch_spin_unlock(arch_spinlock_t * lock)240199c4e6SThomas Gleixner static inline void arch_spin_unlock(arch_spinlock_t * lock)
25024b246eSLinus Torvalds {
26024b246eSLinus Torvalds mb();
27024b246eSLinus Torvalds lock->lock = 0;
28024b246eSLinus Torvalds }
29024b246eSLinus Torvalds
arch_spin_lock(arch_spinlock_t * lock)300199c4e6SThomas Gleixner static inline void arch_spin_lock(arch_spinlock_t * lock)
31024b246eSLinus Torvalds {
32024b246eSLinus Torvalds long tmp;
33024b246eSLinus Torvalds
34024b246eSLinus Torvalds __asm__ __volatile__(
35024b246eSLinus Torvalds "1: ldl_l %0,%1\n"
36024b246eSLinus Torvalds " bne %0,2f\n"
37024b246eSLinus Torvalds " lda %0,1\n"
38024b246eSLinus Torvalds " stl_c %0,%1\n"
39024b246eSLinus Torvalds " beq %0,2f\n"
40024b246eSLinus Torvalds " mb\n"
41024b246eSLinus Torvalds ".subsection 2\n"
42024b246eSLinus Torvalds "2: ldl %0,%1\n"
43024b246eSLinus Torvalds " bne %0,2b\n"
44024b246eSLinus Torvalds " br 1b\n"
45024b246eSLinus Torvalds ".previous"
46024b246eSLinus Torvalds : "=&r" (tmp), "=m" (lock->lock)
47024b246eSLinus Torvalds : "m"(lock->lock) : "memory");
48024b246eSLinus Torvalds }
49024b246eSLinus Torvalds
arch_spin_trylock(arch_spinlock_t * lock)500199c4e6SThomas Gleixner static inline int arch_spin_trylock(arch_spinlock_t *lock)
51024b246eSLinus Torvalds {
52024b246eSLinus Torvalds return !test_and_set_bit(0, &lock->lock);
53024b246eSLinus Torvalds }
54024b246eSLinus Torvalds
55024b246eSLinus Torvalds /***********************************************************/
56024b246eSLinus Torvalds
arch_read_lock(arch_rwlock_t * lock)57e5931943SThomas Gleixner static inline void arch_read_lock(arch_rwlock_t *lock)
58024b246eSLinus Torvalds {
59024b246eSLinus Torvalds long regx;
60024b246eSLinus Torvalds
61024b246eSLinus Torvalds __asm__ __volatile__(
62024b246eSLinus Torvalds "1: ldl_l %1,%0\n"
63024b246eSLinus Torvalds " blbs %1,6f\n"
64024b246eSLinus Torvalds " subl %1,2,%1\n"
65024b246eSLinus Torvalds " stl_c %1,%0\n"
66024b246eSLinus Torvalds " beq %1,6f\n"
67024b246eSLinus Torvalds " mb\n"
68024b246eSLinus Torvalds ".subsection 2\n"
69024b246eSLinus Torvalds "6: ldl %1,%0\n"
70024b246eSLinus Torvalds " blbs %1,6b\n"
71024b246eSLinus Torvalds " br 1b\n"
72024b246eSLinus Torvalds ".previous"
73024b246eSLinus Torvalds : "=m" (*lock), "=&r" (regx)
74024b246eSLinus Torvalds : "m" (*lock) : "memory");
75024b246eSLinus Torvalds }
76024b246eSLinus Torvalds
arch_write_lock(arch_rwlock_t * lock)77e5931943SThomas Gleixner static inline void arch_write_lock(arch_rwlock_t *lock)
78024b246eSLinus Torvalds {
79024b246eSLinus Torvalds long regx;
80024b246eSLinus Torvalds
81024b246eSLinus Torvalds __asm__ __volatile__(
82024b246eSLinus Torvalds "1: ldl_l %1,%0\n"
83024b246eSLinus Torvalds " bne %1,6f\n"
84024b246eSLinus Torvalds " lda %1,1\n"
85024b246eSLinus Torvalds " stl_c %1,%0\n"
86024b246eSLinus Torvalds " beq %1,6f\n"
87024b246eSLinus Torvalds " mb\n"
88024b246eSLinus Torvalds ".subsection 2\n"
89024b246eSLinus Torvalds "6: ldl %1,%0\n"
90024b246eSLinus Torvalds " bne %1,6b\n"
91024b246eSLinus Torvalds " br 1b\n"
92024b246eSLinus Torvalds ".previous"
93024b246eSLinus Torvalds : "=m" (*lock), "=&r" (regx)
94024b246eSLinus Torvalds : "m" (*lock) : "memory");
95024b246eSLinus Torvalds }
96024b246eSLinus Torvalds
arch_read_trylock(arch_rwlock_t * lock)97e5931943SThomas Gleixner static inline int arch_read_trylock(arch_rwlock_t * lock)
98024b246eSLinus Torvalds {
99024b246eSLinus Torvalds long regx;
100024b246eSLinus Torvalds int success;
101024b246eSLinus Torvalds
102024b246eSLinus Torvalds __asm__ __volatile__(
103024b246eSLinus Torvalds "1: ldl_l %1,%0\n"
104024b246eSLinus Torvalds " lda %2,0\n"
105024b246eSLinus Torvalds " blbs %1,2f\n"
106024b246eSLinus Torvalds " subl %1,2,%2\n"
107024b246eSLinus Torvalds " stl_c %2,%0\n"
108024b246eSLinus Torvalds " beq %2,6f\n"
109024b246eSLinus Torvalds "2: mb\n"
110024b246eSLinus Torvalds ".subsection 2\n"
111024b246eSLinus Torvalds "6: br 1b\n"
112024b246eSLinus Torvalds ".previous"
113024b246eSLinus Torvalds : "=m" (*lock), "=&r" (regx), "=&r" (success)
114024b246eSLinus Torvalds : "m" (*lock) : "memory");
115024b246eSLinus Torvalds
116024b246eSLinus Torvalds return success;
117024b246eSLinus Torvalds }
118024b246eSLinus Torvalds
arch_write_trylock(arch_rwlock_t * lock)119e5931943SThomas Gleixner static inline int arch_write_trylock(arch_rwlock_t * lock)
120024b246eSLinus Torvalds {
121024b246eSLinus Torvalds long regx;
122024b246eSLinus Torvalds int success;
123024b246eSLinus Torvalds
124024b246eSLinus Torvalds __asm__ __volatile__(
125024b246eSLinus Torvalds "1: ldl_l %1,%0\n"
126024b246eSLinus Torvalds " lda %2,0\n"
127024b246eSLinus Torvalds " bne %1,2f\n"
128024b246eSLinus Torvalds " lda %2,1\n"
129024b246eSLinus Torvalds " stl_c %2,%0\n"
130024b246eSLinus Torvalds " beq %2,6f\n"
131024b246eSLinus Torvalds "2: mb\n"
132024b246eSLinus Torvalds ".subsection 2\n"
133024b246eSLinus Torvalds "6: br 1b\n"
134024b246eSLinus Torvalds ".previous"
135024b246eSLinus Torvalds : "=m" (*lock), "=&r" (regx), "=&r" (success)
136024b246eSLinus Torvalds : "m" (*lock) : "memory");
137024b246eSLinus Torvalds
138024b246eSLinus Torvalds return success;
139024b246eSLinus Torvalds }
140024b246eSLinus Torvalds
arch_read_unlock(arch_rwlock_t * lock)141e5931943SThomas Gleixner static inline void arch_read_unlock(arch_rwlock_t * lock)
142024b246eSLinus Torvalds {
143024b246eSLinus Torvalds long regx;
144024b246eSLinus Torvalds __asm__ __volatile__(
145024b246eSLinus Torvalds " mb\n"
146024b246eSLinus Torvalds "1: ldl_l %1,%0\n"
147024b246eSLinus Torvalds " addl %1,2,%1\n"
148024b246eSLinus Torvalds " stl_c %1,%0\n"
149024b246eSLinus Torvalds " beq %1,6f\n"
150024b246eSLinus Torvalds ".subsection 2\n"
151024b246eSLinus Torvalds "6: br 1b\n"
152024b246eSLinus Torvalds ".previous"
153024b246eSLinus Torvalds : "=m" (*lock), "=&r" (regx)
154024b246eSLinus Torvalds : "m" (*lock) : "memory");
155024b246eSLinus Torvalds }
156024b246eSLinus Torvalds
arch_write_unlock(arch_rwlock_t * lock)157e5931943SThomas Gleixner static inline void arch_write_unlock(arch_rwlock_t * lock)
158024b246eSLinus Torvalds {
159024b246eSLinus Torvalds mb();
160024b246eSLinus Torvalds lock->lock = 0;
161024b246eSLinus Torvalds }
162024b246eSLinus Torvalds
163024b246eSLinus Torvalds #endif /* _ALPHA_SPINLOCK_H */
164