blob: 37b570d01202e4ee62d5dcc11af345f1805e81a0 [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>
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007/*
8 * Simple spin lock operations. There are two variants, one clears IRQ's
9 * on the local processor, one does not.
10 *
11 * We make no fairness assumptions. They have a cost.
12 */
13
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010014#define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
15#define arch_spin_is_locked(x) ((x)->lock != 0)
16#define arch_spin_unlock_wait(x) \
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070017 do { cpu_relax(); } while ((x)->lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010019static inline void arch_spin_unlock(arch_spinlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
21 mb();
22 lock->lock = 0;
23}
24
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010025static inline void arch_spin_lock(arch_spinlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026{
27 long tmp;
28
29 __asm__ __volatile__(
30 "1: ldl_l %0,%1\n"
31 " bne %0,2f\n"
32 " lda %0,1\n"
33 " stl_c %0,%1\n"
34 " beq %0,2f\n"
35 " mb\n"
36 ".subsection 2\n"
37 "2: ldl %0,%1\n"
38 " bne %0,2b\n"
39 " br 1b\n"
40 ".previous"
41 : "=&r" (tmp), "=m" (lock->lock)
42 : "m"(lock->lock) : "memory");
43}
44
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010045static inline int arch_spin_trylock(arch_spinlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
47 return !test_and_set_bit(0, &lock->lock);
48}
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50/***********************************************************/
51
Thomas Gleixnere5931942009-12-03 20:08:46 +010052static inline int arch_read_can_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
54 return (lock->lock & 1) == 0;
55}
56
Thomas Gleixnere5931942009-12-03 20:08:46 +010057static inline int arch_write_can_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058{
59 return lock->lock == 0;
60}
61
Thomas Gleixnere5931942009-12-03 20:08:46 +010062static inline void arch_read_lock(arch_rwlock_t *lock)
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070063{
64 long regx;
65
66 __asm__ __volatile__(
67 "1: ldl_l %1,%0\n"
68 " blbs %1,6f\n"
69 " subl %1,2,%1\n"
70 " stl_c %1,%0\n"
71 " beq %1,6f\n"
72 " mb\n"
73 ".subsection 2\n"
74 "6: ldl %1,%0\n"
75 " blbs %1,6b\n"
76 " br 1b\n"
77 ".previous"
78 : "=m" (*lock), "=&r" (regx)
79 : "m" (*lock) : "memory");
80}
81
Thomas Gleixnere5931942009-12-03 20:08:46 +010082static inline void arch_write_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
84 long regx;
85
86 __asm__ __volatile__(
87 "1: ldl_l %1,%0\n"
88 " bne %1,6f\n"
89 " lda %1,1\n"
90 " stl_c %1,%0\n"
91 " beq %1,6f\n"
92 " mb\n"
93 ".subsection 2\n"
94 "6: ldl %1,%0\n"
95 " bne %1,6b\n"
96 " br 1b\n"
97 ".previous"
98 : "=m" (*lock), "=&r" (regx)
99 : "m" (*lock) : "memory");
100}
101
Thomas Gleixnere5931942009-12-03 20:08:46 +0100102static inline int arch_read_trylock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
104 long regx;
105 int success;
106
107 __asm__ __volatile__(
108 "1: ldl_l %1,%0\n"
109 " lda %2,0\n"
110 " blbs %1,2f\n"
111 " subl %1,2,%2\n"
112 " stl_c %2,%0\n"
113 " beq %2,6f\n"
114 "2: mb\n"
115 ".subsection 2\n"
116 "6: br 1b\n"
117 ".previous"
118 : "=m" (*lock), "=&r" (regx), "=&r" (success)
119 : "m" (*lock) : "memory");
120
121 return success;
122}
123
Thomas Gleixnere5931942009-12-03 20:08:46 +0100124static inline int arch_write_trylock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125{
126 long regx;
127 int success;
128
129 __asm__ __volatile__(
130 "1: ldl_l %1,%0\n"
131 " lda %2,0\n"
132 " bne %1,2f\n"
133 " lda %2,1\n"
134 " stl_c %2,%0\n"
135 " beq %2,6f\n"
136 "2: mb\n"
137 ".subsection 2\n"
138 "6: br 1b\n"
139 ".previous"
140 : "=m" (*lock), "=&r" (regx), "=&r" (success)
141 : "m" (*lock) : "memory");
142
143 return success;
144}
145
Thomas Gleixnere5931942009-12-03 20:08:46 +0100146static inline void arch_read_unlock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 long regx;
149 __asm__ __volatile__(
150 " mb\n"
151 "1: ldl_l %1,%0\n"
152 " addl %1,2,%1\n"
153 " stl_c %1,%0\n"
154 " beq %1,6f\n"
155 ".subsection 2\n"
156 "6: br 1b\n"
157 ".previous"
158 : "=m" (*lock), "=&r" (regx)
159 : "m" (*lock) : "memory");
160}
161
Thomas Gleixnere5931942009-12-03 20:08:46 +0100162static inline void arch_write_unlock(arch_rwlock_t * lock)
Ingo Molnarfb1c8f92005-09-10 00:25:56 -0700163{
164 mb();
165 lock->lock = 0;
166}
167
Thomas Gleixnere5931942009-12-03 20:08:46 +0100168#define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
169#define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
Robin Holtf5f7eac2009-04-02 16:59:46 -0700170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#endif /* _ALPHA_SPINLOCK_H */