blob: 718ac0b64adf78ce770e1e1e56f82694550e24c9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _ALPHA_SPINLOCK_H
2#define _ALPHA_SPINLOCK_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/kernel.h>
5#include <asm/current.h>
Peter Zijlstra726328d2016-05-26 10:35:03 +02006#include <asm/barrier.h>
7#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Linus Torvalds1da177e2005-04-16 15:20:36 -07009/*
10 * Simple spin lock operations. There are two variants, one clears IRQ's
11 * on the local processor, one does not.
12 *
13 * We make no fairness assumptions. They have a cost.
14 */
15
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010016#define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
17#define arch_spin_is_locked(x) ((x)->lock != 0)
Peter Zijlstra726328d2016-05-26 10:35:03 +020018
Matt Turner8f8dcb32015-08-04 14:35:05 -070019static inline int arch_spin_value_unlocked(arch_spinlock_t lock)
20{
21 return lock.lock == 0;
22}
23
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010024static inline void arch_spin_unlock(arch_spinlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
26 mb();
27 lock->lock = 0;
28}
29
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010030static inline void arch_spin_lock(arch_spinlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 long tmp;
33
34 __asm__ __volatile__(
35 "1: ldl_l %0,%1\n"
36 " bne %0,2f\n"
37 " lda %0,1\n"
38 " stl_c %0,%1\n"
39 " beq %0,2f\n"
40 " mb\n"
41 ".subsection 2\n"
42 "2: ldl %0,%1\n"
43 " bne %0,2b\n"
44 " br 1b\n"
45 ".previous"
46 : "=&r" (tmp), "=m" (lock->lock)
47 : "m"(lock->lock) : "memory");
48}
49
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010050static inline int arch_spin_trylock(arch_spinlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
52 return !test_and_set_bit(0, &lock->lock);
53}
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/***********************************************************/
56
Thomas Gleixnere5931942009-12-03 20:08:46 +010057static inline int arch_read_can_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 return (lock->lock & 1) == 0;
60}
61
Thomas Gleixnere5931942009-12-03 20:08:46 +010062static inline int arch_write_can_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
64 return lock->lock == 0;
65}
66
Thomas Gleixnere5931942009-12-03 20:08:46 +010067static inline void arch_read_lock(arch_rwlock_t *lock)
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070068{
69 long regx;
70
71 __asm__ __volatile__(
72 "1: ldl_l %1,%0\n"
73 " blbs %1,6f\n"
74 " subl %1,2,%1\n"
75 " stl_c %1,%0\n"
76 " beq %1,6f\n"
77 " mb\n"
78 ".subsection 2\n"
79 "6: ldl %1,%0\n"
80 " blbs %1,6b\n"
81 " br 1b\n"
82 ".previous"
83 : "=m" (*lock), "=&r" (regx)
84 : "m" (*lock) : "memory");
85}
86
Thomas Gleixnere5931942009-12-03 20:08:46 +010087static inline void arch_write_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
89 long regx;
90
91 __asm__ __volatile__(
92 "1: ldl_l %1,%0\n"
93 " bne %1,6f\n"
94 " lda %1,1\n"
95 " stl_c %1,%0\n"
96 " beq %1,6f\n"
97 " mb\n"
98 ".subsection 2\n"
99 "6: ldl %1,%0\n"
100 " bne %1,6b\n"
101 " br 1b\n"
102 ".previous"
103 : "=m" (*lock), "=&r" (regx)
104 : "m" (*lock) : "memory");
105}
106
Thomas Gleixnere5931942009-12-03 20:08:46 +0100107static inline int arch_read_trylock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109 long regx;
110 int success;
111
112 __asm__ __volatile__(
113 "1: ldl_l %1,%0\n"
114 " lda %2,0\n"
115 " blbs %1,2f\n"
116 " subl %1,2,%2\n"
117 " stl_c %2,%0\n"
118 " beq %2,6f\n"
119 "2: mb\n"
120 ".subsection 2\n"
121 "6: br 1b\n"
122 ".previous"
123 : "=m" (*lock), "=&r" (regx), "=&r" (success)
124 : "m" (*lock) : "memory");
125
126 return success;
127}
128
Thomas Gleixnere5931942009-12-03 20:08:46 +0100129static inline int arch_write_trylock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
131 long regx;
132 int success;
133
134 __asm__ __volatile__(
135 "1: ldl_l %1,%0\n"
136 " lda %2,0\n"
137 " bne %1,2f\n"
138 " lda %2,1\n"
139 " stl_c %2,%0\n"
140 " beq %2,6f\n"
141 "2: mb\n"
142 ".subsection 2\n"
143 "6: br 1b\n"
144 ".previous"
145 : "=m" (*lock), "=&r" (regx), "=&r" (success)
146 : "m" (*lock) : "memory");
147
148 return success;
149}
150
Thomas Gleixnere5931942009-12-03 20:08:46 +0100151static inline void arch_read_unlock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
153 long regx;
154 __asm__ __volatile__(
155 " mb\n"
156 "1: ldl_l %1,%0\n"
157 " addl %1,2,%1\n"
158 " stl_c %1,%0\n"
159 " beq %1,6f\n"
160 ".subsection 2\n"
161 "6: br 1b\n"
162 ".previous"
163 : "=m" (*lock), "=&r" (regx)
164 : "m" (*lock) : "memory");
165}
166
Thomas Gleixnere5931942009-12-03 20:08:46 +0100167static inline void arch_write_unlock(arch_rwlock_t * lock)
Ingo Molnarfb1c8f92005-09-10 00:25:56 -0700168{
169 mb();
170 lock->lock = 0;
171}
172
Thomas Gleixnere5931942009-12-03 20:08:46 +0100173#define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
174#define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
Robin Holtf5f7eac2009-04-02 16:59:46 -0700175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#endif /* _ALPHA_SPINLOCK_H */