|
12 | 12 | #include <asm/fence.h>
|
13 | 13 | #include <asm/hwcap.h>
|
14 | 14 | #include <asm/insn-def.h>
|
| 15 | +#include <asm/cpufeature-macros.h> |
15 | 16 |
|
16 | 17 | #define __arch_xchg_masked(sc_sfx, prepend, append, r, p, n) \
|
17 | 18 | ({ \
|
|
137 | 138 | r = (__typeof__(*(p)))((__retx & __mask) >> __s); \
|
138 | 139 | })
|
139 | 140 |
|
140 |
| -#define __arch_cmpxchg(lr_sfx, sc_sfx, prepend, append, r, p, co, o, n) \ |
| 141 | +#define __arch_cmpxchg(lr_sfx, sc_cas_sfx, prepend, append, r, p, co, o, n) \ |
141 | 142 | ({ \
|
142 |
| - register unsigned int __rc; \ |
| 143 | + if (IS_ENABLED(CONFIG_RISCV_ISA_ZACAS) && \ |
| 144 | + riscv_has_extension_unlikely(RISCV_ISA_EXT_ZACAS)) { \ |
| 145 | + r = o; \ |
143 | 146 | \
|
144 |
| - __asm__ __volatile__ ( \ |
145 |
| - prepend \ |
146 |
| - "0: lr" lr_sfx " %0, %2\n" \ |
147 |
| - " bne %0, %z3, 1f\n" \ |
148 |
| - " sc" sc_sfx " %1, %z4, %2\n" \ |
149 |
| - " bnez %1, 0b\n" \ |
150 |
| - append \ |
151 |
| - "1:\n" \ |
152 |
| - : "=&r" (r), "=&r" (__rc), "+A" (*(p)) \ |
153 |
| - : "rJ" (co o), "rJ" (n) \ |
154 |
| - : "memory"); \ |
| 147 | + __asm__ __volatile__ ( \ |
| 148 | + prepend \ |
| 149 | + " amocas" sc_cas_sfx " %0, %z2, %1\n" \ |
| 150 | + append \ |
| 151 | + : "+&r" (r), "+A" (*(p)) \ |
| 152 | + : "rJ" (n) \ |
| 153 | + : "memory"); \ |
| 154 | + } else { \ |
| 155 | + register unsigned int __rc; \ |
| 156 | + \ |
| 157 | + __asm__ __volatile__ ( \ |
| 158 | + prepend \ |
| 159 | + "0: lr" lr_sfx " %0, %2\n" \ |
| 160 | + " bne %0, %z3, 1f\n" \ |
| 161 | + " sc" sc_cas_sfx " %1, %z4, %2\n" \ |
| 162 | + " bnez %1, 0b\n" \ |
| 163 | + append \ |
| 164 | + "1:\n" \ |
| 165 | + : "=&r" (r), "=&r" (__rc), "+A" (*(p)) \ |
| 166 | + : "rJ" (co o), "rJ" (n) \ |
| 167 | + : "memory"); \ |
| 168 | + } \ |
155 | 169 | })
|
156 | 170 |
|
157 |
| -#define _arch_cmpxchg(ptr, old, new, sc_sfx, prepend, append) \ |
| 171 | +#define _arch_cmpxchg(ptr, old, new, sc_cas_sfx, prepend, append) \ |
158 | 172 | ({ \
|
159 | 173 | __typeof__(ptr) __ptr = (ptr); \
|
160 | 174 | __typeof__(*(__ptr)) __old = (old); \
|
|
164 | 178 | switch (sizeof(*__ptr)) { \
|
165 | 179 | case 1: \
|
166 | 180 | case 2: \
|
167 |
| - __arch_cmpxchg_masked(sc_sfx, prepend, append, \ |
| 181 | + __arch_cmpxchg_masked(sc_cas_sfx, prepend, append, \ |
168 | 182 | __ret, __ptr, __old, __new); \
|
169 | 183 | break; \
|
170 | 184 | case 4: \
|
171 |
| - __arch_cmpxchg(".w", ".w" sc_sfx, prepend, append, \ |
| 185 | + __arch_cmpxchg(".w", ".w" sc_cas_sfx, prepend, append, \ |
172 | 186 | __ret, __ptr, (long), __old, __new); \
|
173 | 187 | break; \
|
174 | 188 | case 8: \
|
175 |
| - __arch_cmpxchg(".d", ".d" sc_sfx, prepend, append, \ |
| 189 | + __arch_cmpxchg(".d", ".d" sc_cas_sfx, prepend, append, \ |
176 | 190 | __ret, __ptr, /**/, __old, __new); \
|
177 | 191 | break; \
|
178 | 192 | default: \
|
|
0 commit comments