Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 6 | * Copyright (C) 1999, 2000, 06 Ralf Baechle (ralf@linux-mips.org) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Copyright (C) 1999, 2000 Silicon Graphics, Inc. |
| 8 | */ |
| 9 | #ifndef _ASM_SPINLOCK_H |
| 10 | #define _ASM_SPINLOCK_H |
| 11 | |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 12 | #include <asm/barrier.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/war.h> |
| 14 | |
| 15 | /* |
| 16 | * Your basic SMP spinlocks, allowing only a single CPU anywhere |
| 17 | */ |
| 18 | |
Ralf Baechle | beb3ca8 | 2005-10-29 19:32:40 +0100 | [diff] [blame] | 19 | #define __raw_spin_is_locked(x) ((x)->lock != 0) |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 20 | #define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock) |
| 21 | #define __raw_spin_unlock_wait(x) \ |
Ralf Baechle | beb3ca8 | 2005-10-29 19:32:40 +0100 | [diff] [blame] | 22 | do { cpu_relax(); } while ((x)->lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Simple spin lock operations. There are two variants, one clears IRQ's |
| 26 | * on the local processor, one does not. |
| 27 | * |
| 28 | * We make no fairness assumptions. They have a cost. |
| 29 | */ |
| 30 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 31 | static inline void __raw_spin_lock(raw_spinlock_t *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | { |
| 33 | unsigned int tmp; |
| 34 | |
| 35 | if (R10000_LLSC_WAR) { |
| 36 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 37 | " .set noreorder # __raw_spin_lock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | "1: ll %1, %2 \n" |
| 39 | " bnez %1, 1b \n" |
| 40 | " li %1, 1 \n" |
| 41 | " sc %1, %0 \n" |
| 42 | " beqzl %1, 1b \n" |
| 43 | " nop \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | " .set reorder \n" |
| 45 | : "=m" (lock->lock), "=&r" (tmp) |
| 46 | : "m" (lock->lock) |
| 47 | : "memory"); |
| 48 | } else { |
| 49 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 50 | " .set noreorder # __raw_spin_lock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | "1: ll %1, %2 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 52 | " bnez %1, 2f \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | " li %1, 1 \n" |
| 54 | " sc %1, %0 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 55 | " beqz %1, 2f \n" |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 56 | " nop \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 57 | " .subsection 2 \n" |
| 58 | "2: ll %1, %2 \n" |
| 59 | " bnez %1, 2b \n" |
| 60 | " li %1, 1 \n" |
| 61 | " b 1b \n" |
| 62 | " nop \n" |
| 63 | " .previous \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | " .set reorder \n" |
| 65 | : "=m" (lock->lock), "=&r" (tmp) |
| 66 | : "m" (lock->lock) |
| 67 | : "memory"); |
| 68 | } |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 69 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 70 | smp_llsc_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 73 | static inline void __raw_spin_unlock(raw_spinlock_t *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 75 | smp_mb(); |
| 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 78 | " .set noreorder # __raw_spin_unlock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | " sw $0, %0 \n" |
| 80 | " .set\treorder \n" |
| 81 | : "=m" (lock->lock) |
| 82 | : "m" (lock->lock) |
| 83 | : "memory"); |
| 84 | } |
| 85 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 86 | static inline unsigned int __raw_spin_trylock(raw_spinlock_t *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | unsigned int temp, res; |
| 89 | |
| 90 | if (R10000_LLSC_WAR) { |
| 91 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 92 | " .set noreorder # __raw_spin_trylock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | "1: ll %0, %3 \n" |
| 94 | " ori %2, %0, 1 \n" |
| 95 | " sc %2, %1 \n" |
| 96 | " beqzl %2, 1b \n" |
| 97 | " nop \n" |
| 98 | " andi %2, %0, 1 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | " .set reorder" |
| 100 | : "=&r" (temp), "=m" (lock->lock), "=&r" (res) |
| 101 | : "m" (lock->lock) |
| 102 | : "memory"); |
| 103 | } else { |
| 104 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 105 | " .set noreorder # __raw_spin_trylock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | "1: ll %0, %3 \n" |
| 107 | " ori %2, %0, 1 \n" |
| 108 | " sc %2, %1 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 109 | " beqz %2, 2f \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | " andi %2, %0, 1 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 111 | " .subsection 2 \n" |
| 112 | "2: b 1b \n" |
| 113 | " nop \n" |
| 114 | " .previous \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | " .set reorder" |
| 116 | : "=&r" (temp), "=m" (lock->lock), "=&r" (res) |
| 117 | : "m" (lock->lock) |
| 118 | : "memory"); |
| 119 | } |
| 120 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 121 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | return res == 0; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Read-write spinlocks, allowing multiple readers but only one writer. |
| 128 | * |
| 129 | * NOTE! it is quite common to have readers in interrupts but no interrupt |
| 130 | * writers. For those circumstances we can "mix" irq-safe locks - any writer |
| 131 | * needs to get a irq-safe write-lock, but readers can get non-irqsafe |
| 132 | * read-locks. |
| 133 | */ |
| 134 | |
Ralf Baechle | e3c4807 | 2005-02-03 13:34:45 +0000 | [diff] [blame] | 135 | /* |
| 136 | * read_can_lock - would read_trylock() succeed? |
| 137 | * @lock: the rwlock in question. |
| 138 | */ |
| 139 | #define __raw_read_can_lock(rw) ((rw)->lock >= 0) |
| 140 | |
| 141 | /* |
| 142 | * write_can_lock - would write_trylock() succeed? |
| 143 | * @lock: the rwlock in question. |
| 144 | */ |
| 145 | #define __raw_write_can_lock(rw) (!(rw)->lock) |
| 146 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 147 | static inline void __raw_read_lock(raw_rwlock_t *rw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
| 149 | unsigned int tmp; |
| 150 | |
| 151 | if (R10000_LLSC_WAR) { |
| 152 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 153 | " .set noreorder # __raw_read_lock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | "1: ll %1, %2 \n" |
| 155 | " bltz %1, 1b \n" |
| 156 | " addu %1, 1 \n" |
| 157 | " sc %1, %0 \n" |
| 158 | " beqzl %1, 1b \n" |
| 159 | " nop \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | " .set reorder \n" |
| 161 | : "=m" (rw->lock), "=&r" (tmp) |
| 162 | : "m" (rw->lock) |
| 163 | : "memory"); |
| 164 | } else { |
| 165 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 166 | " .set noreorder # __raw_read_lock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | "1: ll %1, %2 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 168 | " bltz %1, 2f \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | " addu %1, 1 \n" |
| 170 | " sc %1, %0 \n" |
| 171 | " beqz %1, 1b \n" |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 172 | " nop \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 173 | " .subsection 2 \n" |
| 174 | "2: ll %1, %2 \n" |
| 175 | " bltz %1, 2b \n" |
| 176 | " addu %1, 1 \n" |
| 177 | " b 1b \n" |
| 178 | " nop \n" |
| 179 | " .previous \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | " .set reorder \n" |
| 181 | : "=m" (rw->lock), "=&r" (tmp) |
| 182 | : "m" (rw->lock) |
| 183 | : "memory"); |
| 184 | } |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 185 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 186 | smp_llsc_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* Note the use of sub, not subu which will make the kernel die with an |
| 190 | overflow exception if we ever try to unlock an rwlock that is already |
| 191 | unlocked or is being held by a writer. */ |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 192 | static inline void __raw_read_unlock(raw_rwlock_t *rw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
| 194 | unsigned int tmp; |
| 195 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 196 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | if (R10000_LLSC_WAR) { |
| 199 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 200 | "1: ll %1, %2 # __raw_read_unlock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | " sub %1, 1 \n" |
| 202 | " sc %1, %0 \n" |
| 203 | " beqzl %1, 1b \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | : "=m" (rw->lock), "=&r" (tmp) |
| 205 | : "m" (rw->lock) |
| 206 | : "memory"); |
| 207 | } else { |
| 208 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 209 | " .set noreorder # __raw_read_unlock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | "1: ll %1, %2 \n" |
| 211 | " sub %1, 1 \n" |
| 212 | " sc %1, %0 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 213 | " beqz %1, 2f \n" |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 214 | " nop \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 215 | " .subsection 2 \n" |
| 216 | "2: b 1b \n" |
| 217 | " nop \n" |
| 218 | " .previous \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | " .set reorder \n" |
| 220 | : "=m" (rw->lock), "=&r" (tmp) |
| 221 | : "m" (rw->lock) |
| 222 | : "memory"); |
| 223 | } |
| 224 | } |
| 225 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 226 | static inline void __raw_write_lock(raw_rwlock_t *rw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | unsigned int tmp; |
| 229 | |
| 230 | if (R10000_LLSC_WAR) { |
| 231 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 232 | " .set noreorder # __raw_write_lock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | "1: ll %1, %2 \n" |
| 234 | " bnez %1, 1b \n" |
| 235 | " lui %1, 0x8000 \n" |
| 236 | " sc %1, %0 \n" |
| 237 | " beqzl %1, 1b \n" |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 238 | " nop \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | " .set reorder \n" |
| 240 | : "=m" (rw->lock), "=&r" (tmp) |
| 241 | : "m" (rw->lock) |
| 242 | : "memory"); |
| 243 | } else { |
| 244 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 245 | " .set noreorder # __raw_write_lock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | "1: ll %1, %2 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 247 | " bnez %1, 2f \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | " lui %1, 0x8000 \n" |
| 249 | " sc %1, %0 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 250 | " beqz %1, 2f \n" |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 251 | " nop \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 252 | " .subsection 2 \n" |
| 253 | "2: ll %1, %2 \n" |
| 254 | " bnez %1, 2b \n" |
| 255 | " lui %1, 0x8000 \n" |
| 256 | " b 1b \n" |
| 257 | " nop \n" |
| 258 | " .previous \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | " .set reorder \n" |
| 260 | : "=m" (rw->lock), "=&r" (tmp) |
| 261 | : "m" (rw->lock) |
| 262 | : "memory"); |
| 263 | } |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 264 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 265 | smp_llsc_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 268 | static inline void __raw_write_unlock(raw_rwlock_t *rw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 270 | smp_mb(); |
| 271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | __asm__ __volatile__( |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 273 | " # __raw_write_unlock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | " sw $0, %0 \n" |
| 275 | : "=m" (rw->lock) |
| 276 | : "m" (rw->lock) |
| 277 | : "memory"); |
| 278 | } |
| 279 | |
Ralf Baechle | 65316fd | 2006-08-31 14:16:06 +0100 | [diff] [blame] | 280 | static inline int __raw_read_trylock(raw_rwlock_t *rw) |
| 281 | { |
| 282 | unsigned int tmp; |
| 283 | int ret; |
| 284 | |
| 285 | if (R10000_LLSC_WAR) { |
| 286 | __asm__ __volatile__( |
| 287 | " .set noreorder # __raw_read_trylock \n" |
| 288 | " li %2, 0 \n" |
| 289 | "1: ll %1, %3 \n" |
Dave Johnson | d52c2d5 | 2007-03-05 20:50:27 -0500 | [diff] [blame] | 290 | " bltz %1, 2f \n" |
Ralf Baechle | 65316fd | 2006-08-31 14:16:06 +0100 | [diff] [blame] | 291 | " addu %1, 1 \n" |
| 292 | " sc %1, %0 \n" |
Ralf Baechle | 65316fd | 2006-08-31 14:16:06 +0100 | [diff] [blame] | 293 | " .set reorder \n" |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 294 | " beqzl %1, 1b \n" |
| 295 | " nop \n" |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 296 | __WEAK_LLSC_MB |
Ralf Baechle | 65316fd | 2006-08-31 14:16:06 +0100 | [diff] [blame] | 297 | " li %2, 1 \n" |
| 298 | "2: \n" |
| 299 | : "=m" (rw->lock), "=&r" (tmp), "=&r" (ret) |
| 300 | : "m" (rw->lock) |
| 301 | : "memory"); |
| 302 | } else { |
| 303 | __asm__ __volatile__( |
| 304 | " .set noreorder # __raw_read_trylock \n" |
| 305 | " li %2, 0 \n" |
| 306 | "1: ll %1, %3 \n" |
Dave Johnson | d52c2d5 | 2007-03-05 20:50:27 -0500 | [diff] [blame] | 307 | " bltz %1, 2f \n" |
Ralf Baechle | 65316fd | 2006-08-31 14:16:06 +0100 | [diff] [blame] | 308 | " addu %1, 1 \n" |
| 309 | " sc %1, %0 \n" |
| 310 | " beqz %1, 1b \n" |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 311 | " nop \n" |
Ralf Baechle | 65316fd | 2006-08-31 14:16:06 +0100 | [diff] [blame] | 312 | " .set reorder \n" |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 313 | __WEAK_LLSC_MB |
Ralf Baechle | 65316fd | 2006-08-31 14:16:06 +0100 | [diff] [blame] | 314 | " li %2, 1 \n" |
| 315 | "2: \n" |
| 316 | : "=m" (rw->lock), "=&r" (tmp), "=&r" (ret) |
| 317 | : "m" (rw->lock) |
| 318 | : "memory"); |
| 319 | } |
| 320 | |
| 321 | return ret; |
| 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 324 | static inline int __raw_write_trylock(raw_rwlock_t *rw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | { |
| 326 | unsigned int tmp; |
| 327 | int ret; |
| 328 | |
| 329 | if (R10000_LLSC_WAR) { |
| 330 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 331 | " .set noreorder # __raw_write_trylock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | " li %2, 0 \n" |
| 333 | "1: ll %1, %3 \n" |
| 334 | " bnez %1, 2f \n" |
| 335 | " lui %1, 0x8000 \n" |
| 336 | " sc %1, %0 \n" |
| 337 | " beqzl %1, 1b \n" |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 338 | " nop \n" |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 339 | __WEAK_LLSC_MB |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | " li %2, 1 \n" |
| 341 | " .set reorder \n" |
| 342 | "2: \n" |
| 343 | : "=m" (rw->lock), "=&r" (tmp), "=&r" (ret) |
| 344 | : "m" (rw->lock) |
| 345 | : "memory"); |
| 346 | } else { |
| 347 | __asm__ __volatile__( |
Ingo Molnar | fb1c8f9 | 2005-09-10 00:25:56 -0700 | [diff] [blame] | 348 | " .set noreorder # __raw_write_trylock \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | " li %2, 0 \n" |
| 350 | "1: ll %1, %3 \n" |
| 351 | " bnez %1, 2f \n" |
| 352 | " lui %1, 0x8000 \n" |
| 353 | " sc %1, %0 \n" |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 354 | " beqz %1, 3f \n" |
| 355 | " li %2, 1 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | "2: \n" |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame^] | 357 | __WEAK_LLSC_MB |
Ralf Baechle | f65e4fa | 2006-09-28 01:45:21 +0100 | [diff] [blame] | 358 | " .subsection 2 \n" |
| 359 | "3: b 1b \n" |
| 360 | " li %2, 0 \n" |
| 361 | " .previous \n" |
| 362 | " .set reorder \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | : "=m" (rw->lock), "=&r" (tmp), "=&r" (ret) |
| 364 | : "m" (rw->lock) |
| 365 | : "memory"); |
| 366 | } |
| 367 | |
| 368 | return ret; |
| 369 | } |
| 370 | |
Ralf Baechle | 65316fd | 2006-08-31 14:16:06 +0100 | [diff] [blame] | 371 | |
Martin Schwidefsky | ef6edc9 | 2006-09-30 23:27:43 -0700 | [diff] [blame] | 372 | #define _raw_spin_relax(lock) cpu_relax() |
| 373 | #define _raw_read_relax(lock) cpu_relax() |
| 374 | #define _raw_write_relax(lock) cpu_relax() |
| 375 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | #endif /* _ASM_SPINLOCK_H */ |