Linux 3.9-rc4
[linux-2.6/cjktty.git] / arch / alpha / include / asm / spinlock.h
blob3bba21e41b818e1ff8fb7f346721dc8e95f93950
1 #ifndef _ALPHA_SPINLOCK_H
2 #define _ALPHA_SPINLOCK_H
4 #include <linux/kernel.h>
5 #include <asm/current.h>
7 /*
8 * Simple spin lock operations. There are two variants, one clears IRQ's
9 * on the local processor, one does not.
11 * We make no fairness assumptions. They have a cost.
14 #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) \
17 do { cpu_relax(); } while ((x)->lock)
19 static inline void arch_spin_unlock(arch_spinlock_t * lock)
21 mb();
22 lock->lock = 0;
25 static inline void arch_spin_lock(arch_spinlock_t * lock)
27 long tmp;
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");
45 static inline int arch_spin_trylock(arch_spinlock_t *lock)
47 return !test_and_set_bit(0, &lock->lock);
50 /***********************************************************/
52 static inline int arch_read_can_lock(arch_rwlock_t *lock)
54 return (lock->lock & 1) == 0;
57 static inline int arch_write_can_lock(arch_rwlock_t *lock)
59 return lock->lock == 0;
62 static inline void arch_read_lock(arch_rwlock_t *lock)
64 long regx;
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");
82 static inline void arch_write_lock(arch_rwlock_t *lock)
84 long regx;
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");
102 static inline int arch_read_trylock(arch_rwlock_t * lock)
104 long regx;
105 int success;
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");
121 return success;
124 static inline int arch_write_trylock(arch_rwlock_t * lock)
126 long regx;
127 int success;
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");
143 return success;
146 static inline void arch_read_unlock(arch_rwlock_t * lock)
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");
162 static inline void arch_write_unlock(arch_rwlock_t * lock)
164 mb();
165 lock->lock = 0;
168 #define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
169 #define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
171 #define arch_spin_relax(lock) cpu_relax()
172 #define arch_read_relax(lock) cpu_relax()
173 #define arch_write_relax(lock) cpu_relax()
175 #endif /* _ALPHA_SPINLOCK_H */