blob: d0faca1e992df0ffc9ca0ed12408e132da9b798a [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 <asm/system.h>
5#include <linux/kernel.h>
6#include <asm/current.h>
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008/*
9 * Simple spin lock operations. There are two variants, one clears IRQ's
10 * on the local processor, one does not.
11 *
12 * We make no fairness assumptions. They have a cost.
13 */
14
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010015#define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
16#define arch_spin_is_locked(x) ((x)->lock != 0)
17#define arch_spin_unlock_wait(x) \
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070018 do { cpu_relax(); } while ((x)->lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010020static inline void arch_spin_unlock(arch_spinlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
22 mb();
23 lock->lock = 0;
24}
25
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010026static inline void arch_spin_lock(arch_spinlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070027{
28 long tmp;
29
30 __asm__ __volatile__(
31 "1: ldl_l %0,%1\n"
32 " bne %0,2f\n"
33 " lda %0,1\n"
34 " stl_c %0,%1\n"
35 " beq %0,2f\n"
36 " mb\n"
37 ".subsection 2\n"
38 "2: ldl %0,%1\n"
39 " bne %0,2b\n"
40 " br 1b\n"
41 ".previous"
42 : "=&r" (tmp), "=m" (lock->lock)
43 : "m"(lock->lock) : "memory");
44}
45
Thomas Gleixner0199c4e2009-12-02 20:01:25 +010046static inline int arch_spin_trylock(arch_spinlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
48 return !test_and_set_bit(0, &lock->lock);
49}
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/***********************************************************/
52
Thomas Gleixnere5931942009-12-03 20:08:46 +010053static inline int arch_read_can_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
55 return (lock->lock & 1) == 0;
56}
57
Thomas Gleixnere5931942009-12-03 20:08:46 +010058static inline int arch_write_can_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 return lock->lock == 0;
61}
62
Thomas Gleixnere5931942009-12-03 20:08:46 +010063static inline void arch_read_lock(arch_rwlock_t *lock)
Ingo Molnarfb1c8f92005-09-10 00:25:56 -070064{
65 long regx;
66
67 __asm__ __volatile__(
68 "1: ldl_l %1,%0\n"
69 " blbs %1,6f\n"
70 " subl %1,2,%1\n"
71 " stl_c %1,%0\n"
72 " beq %1,6f\n"
73 " mb\n"
74 ".subsection 2\n"
75 "6: ldl %1,%0\n"
76 " blbs %1,6b\n"
77 " br 1b\n"
78 ".previous"
79 : "=m" (*lock), "=&r" (regx)
80 : "m" (*lock) : "memory");
81}
82
Thomas Gleixnere5931942009-12-03 20:08:46 +010083static inline void arch_write_lock(arch_rwlock_t *lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 long regx;
86
87 __asm__ __volatile__(
88 "1: ldl_l %1,%0\n"
89 " bne %1,6f\n"
90 " lda %1,1\n"
91 " stl_c %1,%0\n"
92 " beq %1,6f\n"
93 " mb\n"
94 ".subsection 2\n"
95 "6: ldl %1,%0\n"
96 " bne %1,6b\n"
97 " br 1b\n"
98 ".previous"
99 : "=m" (*lock), "=&r" (regx)
100 : "m" (*lock) : "memory");
101}
102
Thomas Gleixnere5931942009-12-03 20:08:46 +0100103static inline int arch_read_trylock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 long regx;
106 int success;
107
108 __asm__ __volatile__(
109 "1: ldl_l %1,%0\n"
110 " lda %2,0\n"
111 " blbs %1,2f\n"
112 " subl %1,2,%2\n"
113 " stl_c %2,%0\n"
114 " beq %2,6f\n"
115 "2: mb\n"
116 ".subsection 2\n"
117 "6: br 1b\n"
118 ".previous"
119 : "=m" (*lock), "=&r" (regx), "=&r" (success)
120 : "m" (*lock) : "memory");
121
122 return success;
123}
124
Thomas Gleixnere5931942009-12-03 20:08:46 +0100125static inline int arch_write_trylock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 long regx;
128 int success;
129
130 __asm__ __volatile__(
131 "1: ldl_l %1,%0\n"
132 " lda %2,0\n"
133 " bne %1,2f\n"
134 " lda %2,1\n"
135 " stl_c %2,%0\n"
136 " beq %2,6f\n"
137 "2: mb\n"
138 ".subsection 2\n"
139 "6: br 1b\n"
140 ".previous"
141 : "=m" (*lock), "=&r" (regx), "=&r" (success)
142 : "m" (*lock) : "memory");
143
144 return success;
145}
146
Thomas Gleixnere5931942009-12-03 20:08:46 +0100147static inline void arch_read_unlock(arch_rwlock_t * lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148{
149 long regx;
150 __asm__ __volatile__(
151 " mb\n"
152 "1: ldl_l %1,%0\n"
153 " addl %1,2,%1\n"
154 " stl_c %1,%0\n"
155 " beq %1,6f\n"
156 ".subsection 2\n"
157 "6: br 1b\n"
158 ".previous"
159 : "=m" (*lock), "=&r" (regx)
160 : "m" (*lock) : "memory");
161}
162
Thomas Gleixnere5931942009-12-03 20:08:46 +0100163static inline void arch_write_unlock(arch_rwlock_t * lock)
Ingo Molnarfb1c8f92005-09-10 00:25:56 -0700164{
165 mb();
166 lock->lock = 0;
167}
168
Thomas Gleixnere5931942009-12-03 20:08:46 +0100169#define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
170#define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
Robin Holtf5f7eac2009-04-02 16:59:46 -0700171
Thomas Gleixner0199c4e2009-12-02 20:01:25 +0100172#define arch_spin_relax(lock) cpu_relax()
173#define arch_read_relax(lock) cpu_relax()
174#define arch_write_relax(lock) cpu_relax()
Martin Schwidefskyef6edc92006-09-30 23:27:43 -0700175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#endif /* _ALPHA_SPINLOCK_H */