Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _S390_RWSEM_H |
| 2 | #define _S390_RWSEM_H |
| 3 | |
| 4 | /* |
| 5 | * include/asm-s390/rwsem.h |
| 6 | * |
| 7 | * S390 version |
| 8 | * Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 9 | * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 10 | * |
| 11 | * Based on asm-alpha/semaphore.h and asm-i386/rwsem.h |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * |
| 16 | * The MSW of the count is the negated number of active writers and waiting |
| 17 | * lockers, and the LSW is the total number of active locks |
| 18 | * |
| 19 | * The lock count is initialized to 0 (no active and no waiting lockers). |
| 20 | * |
| 21 | * When a writer subtracts WRITE_BIAS, it'll get 0xffff0001 for the case of an |
| 22 | * uncontended lock. This can be determined because XADD returns the old value. |
| 23 | * Readers increment by 1 and see a positive value when uncontended, negative |
| 24 | * if there are writers (and maybe) readers waiting (in which case it goes to |
| 25 | * sleep). |
| 26 | * |
| 27 | * The value of WAITING_BIAS supports up to 32766 waiting processes. This can |
| 28 | * be extended to 65534 by manually checking the whole MSW rather than relying |
| 29 | * on the S flag. |
| 30 | * |
| 31 | * The value of ACTIVE_BIAS supports up to 65535 active processes. |
| 32 | * |
| 33 | * This should be totally fair - if anything is waiting, a process that wants a |
| 34 | * lock will go to the back of the queue. When the currently active lock is |
| 35 | * released, if there's a writer at the front of the queue, then that and only |
| 36 | * that will be woken up; if there's a bunch of consequtive readers at the |
| 37 | * front, then they'll all be woken up, but no other readers will be. |
| 38 | */ |
| 39 | |
| 40 | #ifndef _LINUX_RWSEM_H |
| 41 | #error "please don't include asm/rwsem.h directly, use linux/rwsem.h instead" |
| 42 | #endif |
| 43 | |
| 44 | #ifdef __KERNEL__ |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #ifndef __s390x__ |
| 47 | #define RWSEM_UNLOCKED_VALUE 0x00000000 |
| 48 | #define RWSEM_ACTIVE_BIAS 0x00000001 |
| 49 | #define RWSEM_ACTIVE_MASK 0x0000ffff |
| 50 | #define RWSEM_WAITING_BIAS (-0x00010000) |
| 51 | #else /* __s390x__ */ |
| 52 | #define RWSEM_UNLOCKED_VALUE 0x0000000000000000L |
| 53 | #define RWSEM_ACTIVE_BIAS 0x0000000000000001L |
| 54 | #define RWSEM_ACTIVE_MASK 0x00000000ffffffffL |
| 55 | #define RWSEM_WAITING_BIAS (-0x0000000100000000L) |
| 56 | #endif /* __s390x__ */ |
| 57 | #define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS |
| 58 | #define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS) |
| 59 | |
| 60 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | * lock for reading |
| 62 | */ |
| 63 | static inline void __down_read(struct rw_semaphore *sem) |
| 64 | { |
| 65 | signed long old, new; |
| 66 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 67 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 69 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 70 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 71 | " ahi %1,%4\n" |
| 72 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 73 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 75 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 76 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 77 | " aghi %1,%4\n" |
| 78 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 79 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #endif /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 81 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 82 | : "Q" (sem->count), "i" (RWSEM_ACTIVE_READ_BIAS) |
| 83 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | if (old < 0) |
| 85 | rwsem_down_read_failed(sem); |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * trylock for reading -- returns 1 if successful, 0 if contention |
| 90 | */ |
| 91 | static inline int __down_read_trylock(struct rw_semaphore *sem) |
| 92 | { |
| 93 | signed long old, new; |
| 94 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 95 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 97 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 98 | "0: ltr %1,%0\n" |
| 99 | " jm 1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 100 | " ahi %1,%4\n" |
| 101 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 102 | " jl 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | "1:" |
| 104 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 105 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 106 | "0: ltgr %1,%0\n" |
| 107 | " jm 1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 108 | " aghi %1,%4\n" |
| 109 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 110 | " jl 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | "1:" |
| 112 | #endif /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 113 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 114 | : "Q" (sem->count), "i" (RWSEM_ACTIVE_READ_BIAS) |
| 115 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return old >= 0 ? 1 : 0; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * lock for writing |
| 121 | */ |
Ingo Molnar | 4ea2176 | 2006-07-03 00:24:53 -0700 | [diff] [blame] | 122 | static inline void __down_write_nested(struct rw_semaphore *sem, int subclass) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | signed long old, new, tmp; |
| 125 | |
| 126 | tmp = RWSEM_ACTIVE_WRITE_BIAS; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 127 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 129 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 130 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 131 | " a %1,%4\n" |
| 132 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 133 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 135 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 136 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 137 | " ag %1,%4\n" |
| 138 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 139 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | #endif /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 141 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 142 | : "Q" (sem->count), "m" (tmp) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 143 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (old != 0) |
| 145 | rwsem_down_write_failed(sem); |
| 146 | } |
| 147 | |
Ingo Molnar | 4ea2176 | 2006-07-03 00:24:53 -0700 | [diff] [blame] | 148 | static inline void __down_write(struct rw_semaphore *sem) |
| 149 | { |
| 150 | __down_write_nested(sem, 0); |
| 151 | } |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* |
| 154 | * trylock for writing -- returns 1 if successful, 0 if contention |
| 155 | */ |
| 156 | static inline int __down_write_trylock(struct rw_semaphore *sem) |
| 157 | { |
| 158 | signed long old; |
| 159 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 160 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 162 | " l %0,%1\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 163 | "0: ltr %0,%0\n" |
| 164 | " jnz 1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 165 | " cs %0,%3,%1\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 166 | " jl 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 168 | " lg %0,%1\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 169 | "0: ltgr %0,%0\n" |
| 170 | " jnz 1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 171 | " csg %0,%3,%1\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 172 | " jl 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | #endif /* __s390x__ */ |
| 174 | "1:" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 175 | : "=&d" (old), "=Q" (sem->count) |
| 176 | : "Q" (sem->count), "d" (RWSEM_ACTIVE_WRITE_BIAS) |
| 177 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | return (old == RWSEM_UNLOCKED_VALUE) ? 1 : 0; |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * unlock after reading |
| 183 | */ |
| 184 | static inline void __up_read(struct rw_semaphore *sem) |
| 185 | { |
| 186 | signed long old, new; |
| 187 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 188 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 190 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 191 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 192 | " ahi %1,%4\n" |
| 193 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 194 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 196 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 197 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 198 | " aghi %1,%4\n" |
| 199 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 200 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | #endif /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 202 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 203 | : "Q" (sem->count), "i" (-RWSEM_ACTIVE_READ_BIAS) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 204 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | if (new < 0) |
| 206 | if ((new & RWSEM_ACTIVE_MASK) == 0) |
| 207 | rwsem_wake(sem); |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * unlock after writing |
| 212 | */ |
| 213 | static inline void __up_write(struct rw_semaphore *sem) |
| 214 | { |
| 215 | signed long old, new, tmp; |
| 216 | |
| 217 | tmp = -RWSEM_ACTIVE_WRITE_BIAS; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 218 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 220 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 221 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 222 | " a %1,%4\n" |
| 223 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 224 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 226 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 227 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 228 | " ag %1,%4\n" |
| 229 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 230 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | #endif /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 232 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 233 | : "Q" (sem->count), "m" (tmp) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 234 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | if (new < 0) |
| 236 | if ((new & RWSEM_ACTIVE_MASK) == 0) |
| 237 | rwsem_wake(sem); |
| 238 | } |
| 239 | |
| 240 | /* |
| 241 | * downgrade write lock to read lock |
| 242 | */ |
| 243 | static inline void __downgrade_write(struct rw_semaphore *sem) |
| 244 | { |
| 245 | signed long old, new, tmp; |
| 246 | |
| 247 | tmp = -RWSEM_WAITING_BIAS; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 248 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 250 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 251 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 252 | " a %1,%4\n" |
| 253 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 254 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 256 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 257 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 258 | " ag %1,%4\n" |
| 259 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 260 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | #endif /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 262 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 263 | : "Q" (sem->count), "m" (tmp) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 264 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | if (new > 1) |
| 266 | rwsem_downgrade_wake(sem); |
| 267 | } |
| 268 | |
| 269 | /* |
| 270 | * implement atomic add functionality |
| 271 | */ |
| 272 | static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem) |
| 273 | { |
| 274 | signed long old, new; |
| 275 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 276 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 278 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 279 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 280 | " ar %1,%4\n" |
| 281 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 282 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 284 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 285 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 286 | " agr %1,%4\n" |
| 287 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 288 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | #endif /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 290 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 291 | : "Q" (sem->count), "d" (delta) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 292 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* |
| 296 | * implement exchange and add functionality |
| 297 | */ |
| 298 | static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem) |
| 299 | { |
| 300 | signed long old, new; |
| 301 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 302 | asm volatile( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | #ifndef __s390x__ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 304 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 305 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 306 | " ar %1,%4\n" |
| 307 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 308 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | #else /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 310 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 311 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 312 | " agr %1,%4\n" |
| 313 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 314 | " jl 0b" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | #endif /* __s390x__ */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 316 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 317 | : "Q" (sem->count), "d" (delta) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 318 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | return new; |
| 320 | } |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | #endif /* __KERNEL__ */ |
| 323 | #endif /* _S390_RWSEM_H */ |