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 | |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 44 | #ifndef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define RWSEM_UNLOCKED_VALUE 0x00000000 |
| 46 | #define RWSEM_ACTIVE_BIAS 0x00000001 |
| 47 | #define RWSEM_ACTIVE_MASK 0x0000ffff |
| 48 | #define RWSEM_WAITING_BIAS (-0x00010000) |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 49 | #else /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define RWSEM_UNLOCKED_VALUE 0x0000000000000000L |
| 51 | #define RWSEM_ACTIVE_BIAS 0x0000000000000001L |
| 52 | #define RWSEM_ACTIVE_MASK 0x00000000ffffffffL |
| 53 | #define RWSEM_WAITING_BIAS (-0x0000000100000000L) |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 54 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS |
| 56 | #define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS) |
| 57 | |
| 58 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | * lock for reading |
| 60 | */ |
| 61 | static inline void __down_read(struct rw_semaphore *sem) |
| 62 | { |
| 63 | signed long old, new; |
| 64 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 65 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 66 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 67 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 68 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 69 | " ahi %1,%4\n" |
| 70 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 71 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 72 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 73 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 74 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 75 | " aghi %1,%4\n" |
| 76 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 77 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 78 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 79 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 80 | : "Q" (sem->count), "i" (RWSEM_ACTIVE_READ_BIAS) |
| 81 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | if (old < 0) |
| 83 | rwsem_down_read_failed(sem); |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * trylock for reading -- returns 1 if successful, 0 if contention |
| 88 | */ |
| 89 | static inline int __down_read_trylock(struct rw_semaphore *sem) |
| 90 | { |
| 91 | signed long old, new; |
| 92 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 93 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 94 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 95 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 96 | "0: ltr %1,%0\n" |
| 97 | " jm 1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 98 | " ahi %1,%4\n" |
| 99 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 100 | " jl 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | "1:" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 102 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 103 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 104 | "0: ltgr %1,%0\n" |
| 105 | " jm 1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 106 | " aghi %1,%4\n" |
| 107 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 108 | " jl 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | "1:" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 110 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 111 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 112 | : "Q" (sem->count), "i" (RWSEM_ACTIVE_READ_BIAS) |
| 113 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return old >= 0 ? 1 : 0; |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * lock for writing |
| 119 | */ |
Ingo Molnar | 4ea2176 | 2006-07-03 00:24:53 -0700 | [diff] [blame] | 120 | static inline void __down_write_nested(struct rw_semaphore *sem, int subclass) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
| 122 | signed long old, new, tmp; |
| 123 | |
| 124 | tmp = RWSEM_ACTIVE_WRITE_BIAS; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 125 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 126 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 127 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 128 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 129 | " a %1,%4\n" |
| 130 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 131 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 132 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 133 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 134 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 135 | " ag %1,%4\n" |
| 136 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 137 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 138 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 139 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 140 | : "Q" (sem->count), "m" (tmp) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 141 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | if (old != 0) |
| 143 | rwsem_down_write_failed(sem); |
| 144 | } |
| 145 | |
Ingo Molnar | 4ea2176 | 2006-07-03 00:24:53 -0700 | [diff] [blame] | 146 | static inline void __down_write(struct rw_semaphore *sem) |
| 147 | { |
| 148 | __down_write_nested(sem, 0); |
| 149 | } |
| 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* |
| 152 | * trylock for writing -- returns 1 if successful, 0 if contention |
| 153 | */ |
| 154 | static inline int __down_write_trylock(struct rw_semaphore *sem) |
| 155 | { |
| 156 | signed long old; |
| 157 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 158 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 159 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 160 | " l %0,%1\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 161 | "0: ltr %0,%0\n" |
| 162 | " jnz 1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 163 | " cs %0,%3,%1\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 164 | " jl 0b\n" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 165 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 166 | " lg %0,%1\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 167 | "0: ltgr %0,%0\n" |
| 168 | " jnz 1f\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 169 | " csg %0,%3,%1\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 170 | " jl 0b\n" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 171 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | "1:" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 173 | : "=&d" (old), "=Q" (sem->count) |
| 174 | : "Q" (sem->count), "d" (RWSEM_ACTIVE_WRITE_BIAS) |
| 175 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | return (old == RWSEM_UNLOCKED_VALUE) ? 1 : 0; |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * unlock after reading |
| 181 | */ |
| 182 | static inline void __up_read(struct rw_semaphore *sem) |
| 183 | { |
| 184 | signed long old, new; |
| 185 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 186 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 187 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 188 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 189 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 190 | " ahi %1,%4\n" |
| 191 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 192 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 193 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 194 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 195 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 196 | " aghi %1,%4\n" |
| 197 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 198 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 199 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 200 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 201 | : "Q" (sem->count), "i" (-RWSEM_ACTIVE_READ_BIAS) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 202 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | if (new < 0) |
| 204 | if ((new & RWSEM_ACTIVE_MASK) == 0) |
| 205 | rwsem_wake(sem); |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * unlock after writing |
| 210 | */ |
| 211 | static inline void __up_write(struct rw_semaphore *sem) |
| 212 | { |
| 213 | signed long old, new, tmp; |
| 214 | |
| 215 | tmp = -RWSEM_ACTIVE_WRITE_BIAS; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 216 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 217 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 218 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 219 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 220 | " a %1,%4\n" |
| 221 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 222 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 223 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 224 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 225 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 226 | " ag %1,%4\n" |
| 227 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 228 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 229 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 230 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 231 | : "Q" (sem->count), "m" (tmp) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 232 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (new < 0) |
| 234 | if ((new & RWSEM_ACTIVE_MASK) == 0) |
| 235 | rwsem_wake(sem); |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * downgrade write lock to read lock |
| 240 | */ |
| 241 | static inline void __downgrade_write(struct rw_semaphore *sem) |
| 242 | { |
| 243 | signed long old, new, tmp; |
| 244 | |
| 245 | tmp = -RWSEM_WAITING_BIAS; |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 246 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 247 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 248 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 249 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 250 | " a %1,%4\n" |
| 251 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 252 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 253 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 254 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 255 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 256 | " ag %1,%4\n" |
| 257 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 258 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 259 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 260 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 261 | : "Q" (sem->count), "m" (tmp) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 262 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | if (new > 1) |
| 264 | rwsem_downgrade_wake(sem); |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * implement atomic add functionality |
| 269 | */ |
| 270 | static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem) |
| 271 | { |
| 272 | signed long old, new; |
| 273 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 274 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 275 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 276 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 277 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 278 | " ar %1,%4\n" |
| 279 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 280 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 281 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 282 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 283 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 284 | " agr %1,%4\n" |
| 285 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 286 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 287 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 288 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 289 | : "Q" (sem->count), "d" (delta) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 290 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* |
| 294 | * implement exchange and add functionality |
| 295 | */ |
| 296 | static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem) |
| 297 | { |
| 298 | signed long old, new; |
| 299 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 300 | asm volatile( |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 301 | #ifndef CONFIG_64BIT |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 302 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 303 | "0: lr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 304 | " ar %1,%4\n" |
| 305 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 306 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 307 | #else /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 308 | " lg %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 309 | "0: lgr %1,%0\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 310 | " agr %1,%4\n" |
| 311 | " csg %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 312 | " jl 0b" |
Heiko Carstens | f4815ac | 2012-05-23 16:24:51 +0200 | [diff] [blame^] | 313 | #endif /* CONFIG_64BIT */ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 314 | : "=&d" (old), "=&d" (new), "=Q" (sem->count) |
| 315 | : "Q" (sem->count), "d" (delta) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 316 | : "cc", "memory"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return new; |
| 318 | } |
| 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | #endif /* _S390_RWSEM_H */ |