|
34 | 34 | * |
35 | 35 | * - Get an error at link-time due to the call to the missing function. |
36 | 36 | */ |
37 | | -extern void __cmpxchg_called_with_bad_pointer(void) |
| 37 | +extern unsigned long __cmpxchg_called_with_bad_pointer(void) |
38 | 38 | __compiletime_error("Bad argument size for cmpxchg"); |
39 | 39 | extern unsigned long __xchg_called_with_bad_pointer(void) |
40 | 40 | __compiletime_error("Bad argument size for xchg"); |
@@ -137,38 +137,43 @@ static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int siz |
137 | 137 | __ret; \ |
138 | 138 | }) |
139 | 139 |
|
140 | | -#define __cmpxchg(ptr, old, new, pre_barrier, post_barrier) \ |
| 140 | +static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, |
| 141 | + unsigned long new, unsigned int size) |
| 142 | +{ |
| 143 | + switch (size) { |
| 144 | + case 4: |
| 145 | + return __cmpxchg_asm("ll", "sc", (volatile u32 *)ptr, old, new); |
| 146 | + |
| 147 | + case 8: |
| 148 | + /* lld/scd are only available for MIPS64 */ |
| 149 | + if (!IS_ENABLED(CONFIG_64BIT)) |
| 150 | + return __cmpxchg_called_with_bad_pointer(); |
| 151 | + |
| 152 | + return __cmpxchg_asm("lld", "scd", (volatile u64 *)ptr, old, new); |
| 153 | + |
| 154 | + default: |
| 155 | + return __cmpxchg_called_with_bad_pointer(); |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | +#define cmpxchg_local(ptr, old, new) \ |
| 160 | + ((__typeof__(*(ptr))) \ |
| 161 | + __cmpxchg((ptr), \ |
| 162 | + (unsigned long)(__typeof__(*(ptr)))(old), \ |
| 163 | + (unsigned long)(__typeof__(*(ptr)))(new), \ |
| 164 | + sizeof(*(ptr)))) |
| 165 | + |
| 166 | +#define cmpxchg(ptr, old, new) \ |
141 | 167 | ({ \ |
142 | | - __typeof__(ptr) __ptr = (ptr); \ |
143 | | - __typeof__(*(ptr)) __old = (old); \ |
144 | | - __typeof__(*(ptr)) __new = (new); \ |
145 | | - __typeof__(*(ptr)) __res = 0; \ |
146 | | - \ |
147 | | - pre_barrier; \ |
148 | | - \ |
149 | | - switch (sizeof(*(__ptr))) { \ |
150 | | - case 4: \ |
151 | | - __res = __cmpxchg_asm("ll", "sc", __ptr, __old, __new); \ |
152 | | - break; \ |
153 | | - case 8: \ |
154 | | - if (sizeof(long) == 8) { \ |
155 | | - __res = __cmpxchg_asm("lld", "scd", __ptr, \ |
156 | | - __old, __new); \ |
157 | | - break; \ |
158 | | - } \ |
159 | | - default: \ |
160 | | - __cmpxchg_called_with_bad_pointer(); \ |
161 | | - break; \ |
162 | | - } \ |
| 168 | + __typeof__(*(ptr)) __res; \ |
163 | 169 | \ |
164 | | - post_barrier; \ |
| 170 | + smp_mb__before_llsc(); \ |
| 171 | + __res = cmpxchg_local((ptr), (old), (new)); \ |
| 172 | + smp_llsc_mb(); \ |
165 | 173 | \ |
166 | 174 | __res; \ |
167 | 175 | }) |
168 | 176 |
|
169 | | -#define cmpxchg(ptr, old, new) __cmpxchg(ptr, old, new, smp_mb__before_llsc(), smp_llsc_mb()) |
170 | | -#define cmpxchg_local(ptr, old, new) __cmpxchg(ptr, old, new, , ) |
171 | | - |
172 | 177 | #ifdef CONFIG_64BIT |
173 | 178 | #define cmpxchg64_local(ptr, o, n) \ |
174 | 179 | ({ \ |
|
0 commit comments