|
10 | 10 |
|
11 | 11 | #include <asm/fence.h> |
12 | 12 |
|
13 | | -#define __arch_xchg_masked(prepend, append, r, p, n) \ |
| 13 | +#define __arch_xchg_masked(sc_sfx, prepend, append, r, p, n) \ |
14 | 14 | ({ \ |
15 | 15 | u32 *__ptr32b = (u32 *)((ulong)(p) & ~0x3); \ |
16 | 16 | ulong __s = ((ulong)(p) & (0x4 - sizeof(*p))) * BITS_PER_BYTE; \ |
|
25 | 25 | "0: lr.w %0, %2\n" \ |
26 | 26 | " and %1, %0, %z4\n" \ |
27 | 27 | " or %1, %1, %z3\n" \ |
28 | | - " sc.w %1, %1, %2\n" \ |
| 28 | + " sc.w" sc_sfx " %1, %1, %2\n" \ |
29 | 29 | " bnez %1, 0b\n" \ |
30 | 30 | append \ |
31 | 31 | : "=&r" (__retx), "=&r" (__rc), "+A" (*(__ptr32b)) \ |
|
46 | 46 | : "memory"); \ |
47 | 47 | }) |
48 | 48 |
|
49 | | -#define _arch_xchg(ptr, new, sfx, prepend, append) \ |
| 49 | +#define _arch_xchg(ptr, new, sc_sfx, swap_sfx, prepend, \ |
| 50 | + sc_append, swap_append) \ |
50 | 51 | ({ \ |
51 | 52 | __typeof__(ptr) __ptr = (ptr); \ |
52 | 53 | __typeof__(*(__ptr)) __new = (new); \ |
|
55 | 56 | switch (sizeof(*__ptr)) { \ |
56 | 57 | case 1: \ |
57 | 58 | case 2: \ |
58 | | - __arch_xchg_masked(prepend, append, \ |
| 59 | + __arch_xchg_masked(sc_sfx, prepend, sc_append, \ |
59 | 60 | __ret, __ptr, __new); \ |
60 | 61 | break; \ |
61 | 62 | case 4: \ |
62 | | - __arch_xchg(".w" sfx, prepend, append, \ |
| 63 | + __arch_xchg(".w" swap_sfx, prepend, swap_append, \ |
63 | 64 | __ret, __ptr, __new); \ |
64 | 65 | break; \ |
65 | 66 | case 8: \ |
66 | | - __arch_xchg(".d" sfx, prepend, append, \ |
| 67 | + __arch_xchg(".d" swap_sfx, prepend, swap_append, \ |
67 | 68 | __ret, __ptr, __new); \ |
68 | 69 | break; \ |
69 | 70 | default: \ |
|
73 | 74 | }) |
74 | 75 |
|
75 | 76 | #define arch_xchg_relaxed(ptr, x) \ |
76 | | - _arch_xchg(ptr, x, "", "", "") |
| 77 | + _arch_xchg(ptr, x, "", "", "", "", "") |
77 | 78 |
|
78 | 79 | #define arch_xchg_acquire(ptr, x) \ |
79 | | - _arch_xchg(ptr, x, "", "", RISCV_ACQUIRE_BARRIER) |
| 80 | + _arch_xchg(ptr, x, "", "", "", \ |
| 81 | + RISCV_ACQUIRE_BARRIER, RISCV_ACQUIRE_BARRIER) |
80 | 82 |
|
81 | 83 | #define arch_xchg_release(ptr, x) \ |
82 | | - _arch_xchg(ptr, x, "", RISCV_RELEASE_BARRIER, "") |
| 84 | + _arch_xchg(ptr, x, "", "", RISCV_RELEASE_BARRIER, "", "") |
83 | 85 |
|
84 | 86 | #define arch_xchg(ptr, x) \ |
85 | | - _arch_xchg(ptr, x, ".aqrl", "", "") |
| 87 | + _arch_xchg(ptr, x, ".rl", ".aqrl", "", RISCV_FULL_BARRIER, "") |
86 | 88 |
|
87 | 89 | #define xchg32(ptr, x) \ |
88 | 90 | ({ \ |
|
0 commit comments