Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / sh / include / asm / spinlock-llsc.h
blob715595de286a8348f05ac5470db369d130febcdd
1 /*
2 * include/asm-sh/spinlock-llsc.h
4 * Copyright (C) 2002, 2003 Paul Mundt
5 * Copyright (C) 2006, 2007 Akio Idehara
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
11 #ifndef __ASM_SH_SPINLOCK_LLSC_H
12 #define __ASM_SH_SPINLOCK_LLSC_H
14 #include <asm/barrier.h>
15 #include <asm/processor.h>
18 * Your basic SMP spinlocks, allowing only a single CPU anywhere
21 #define arch_spin_is_locked(x) ((x)->lock <= 0)
24 * Simple spin lock operations. There are two variants, one clears IRQ's
25 * on the local processor, one does not.
27 * We make no fairness assumptions. They have a cost.
29 static inline void arch_spin_lock(arch_spinlock_t *lock)
31 unsigned long tmp;
32 unsigned long oldval;
34 __asm__ __volatile__ (
35 "1: \n\t"
36 "movli.l @%2, %0 ! arch_spin_lock \n\t"
37 "mov %0, %1 \n\t"
38 "mov #0, %0 \n\t"
39 "movco.l %0, @%2 \n\t"
40 "bf 1b \n\t"
41 "cmp/pl %1 \n\t"
42 "bf 1b \n\t"
43 : "=&z" (tmp), "=&r" (oldval)
44 : "r" (&lock->lock)
45 : "t", "memory"
49 static inline void arch_spin_unlock(arch_spinlock_t *lock)
51 unsigned long tmp;
53 __asm__ __volatile__ (
54 "mov #1, %0 ! arch_spin_unlock \n\t"
55 "mov.l %0, @%1 \n\t"
56 : "=&z" (tmp)
57 : "r" (&lock->lock)
58 : "t", "memory"
62 static inline int arch_spin_trylock(arch_spinlock_t *lock)
64 unsigned long tmp, oldval;
66 __asm__ __volatile__ (
67 "1: \n\t"
68 "movli.l @%2, %0 ! arch_spin_trylock \n\t"
69 "mov %0, %1 \n\t"
70 "mov #0, %0 \n\t"
71 "movco.l %0, @%2 \n\t"
72 "bf 1b \n\t"
73 "synco \n\t"
74 : "=&z" (tmp), "=&r" (oldval)
75 : "r" (&lock->lock)
76 : "t", "memory"
79 return oldval;
83 * Read-write spinlocks, allowing multiple readers but only one writer.
85 * NOTE! it is quite common to have readers in interrupts but no interrupt
86 * writers. For those circumstances we can "mix" irq-safe locks - any writer
87 * needs to get a irq-safe write-lock, but readers can get non-irqsafe
88 * read-locks.
91 static inline void arch_read_lock(arch_rwlock_t *rw)
93 unsigned long tmp;
95 __asm__ __volatile__ (
96 "1: \n\t"
97 "movli.l @%1, %0 ! arch_read_lock \n\t"
98 "cmp/pl %0 \n\t"
99 "bf 1b \n\t"
100 "add #-1, %0 \n\t"
101 "movco.l %0, @%1 \n\t"
102 "bf 1b \n\t"
103 : "=&z" (tmp)
104 : "r" (&rw->lock)
105 : "t", "memory"
109 static inline void arch_read_unlock(arch_rwlock_t *rw)
111 unsigned long tmp;
113 __asm__ __volatile__ (
114 "1: \n\t"
115 "movli.l @%1, %0 ! arch_read_unlock \n\t"
116 "add #1, %0 \n\t"
117 "movco.l %0, @%1 \n\t"
118 "bf 1b \n\t"
119 : "=&z" (tmp)
120 : "r" (&rw->lock)
121 : "t", "memory"
125 static inline void arch_write_lock(arch_rwlock_t *rw)
127 unsigned long tmp;
129 __asm__ __volatile__ (
130 "1: \n\t"
131 "movli.l @%1, %0 ! arch_write_lock \n\t"
132 "cmp/hs %2, %0 \n\t"
133 "bf 1b \n\t"
134 "sub %2, %0 \n\t"
135 "movco.l %0, @%1 \n\t"
136 "bf 1b \n\t"
137 : "=&z" (tmp)
138 : "r" (&rw->lock), "r" (RW_LOCK_BIAS)
139 : "t", "memory"
143 static inline void arch_write_unlock(arch_rwlock_t *rw)
145 __asm__ __volatile__ (
146 "mov.l %1, @%0 ! arch_write_unlock \n\t"
148 : "r" (&rw->lock), "r" (RW_LOCK_BIAS)
149 : "t", "memory"
153 static inline int arch_read_trylock(arch_rwlock_t *rw)
155 unsigned long tmp, oldval;
157 __asm__ __volatile__ (
158 "1: \n\t"
159 "movli.l @%2, %0 ! arch_read_trylock \n\t"
160 "mov %0, %1 \n\t"
161 "cmp/pl %0 \n\t"
162 "bf 2f \n\t"
163 "add #-1, %0 \n\t"
164 "movco.l %0, @%2 \n\t"
165 "bf 1b \n\t"
166 "2: \n\t"
167 "synco \n\t"
168 : "=&z" (tmp), "=&r" (oldval)
169 : "r" (&rw->lock)
170 : "t", "memory"
173 return (oldval > 0);
176 static inline int arch_write_trylock(arch_rwlock_t *rw)
178 unsigned long tmp, oldval;
180 __asm__ __volatile__ (
181 "1: \n\t"
182 "movli.l @%2, %0 ! arch_write_trylock \n\t"
183 "mov %0, %1 \n\t"
184 "cmp/hs %3, %0 \n\t"
185 "bf 2f \n\t"
186 "sub %3, %0 \n\t"
187 "2: \n\t"
188 "movco.l %0, @%2 \n\t"
189 "bf 1b \n\t"
190 "synco \n\t"
191 : "=&z" (tmp), "=&r" (oldval)
192 : "r" (&rw->lock), "r" (RW_LOCK_BIAS)
193 : "t", "memory"
196 return (oldval > (RW_LOCK_BIAS - 1));
199 #endif /* __ASM_SH_SPINLOCK_LLSC_H */