[PATCH 4/6] csky: Emulate two-byte cmpxchg
From: Bradley Morgan
Date: Fri Sep 11 2026 - 15:34:57 EST
csky has no byte or halfword atomic memory operations, so the
__cmpxchg_relaxed(), __cmpxchg_acquire() and __cmpxchg() switches
each route case 1 through cmpxchg_emu_u8() and leave case 2 to
fall into the BUILD_BUG() default. Route case 2 in all three
through the new cmpxchg_emu_u16().
arch_cmpxchg_local() maps to __cmpxchg_relaxed() and so picks up
case 2 automatically.
Signed-off-by: Bradley Morgan <brads@xxxxxxxxxxxxxx>
---
arch/csky/include/asm/cmpxchg.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/arch/csky/include/asm/cmpxchg.h b/arch/csky/include/asm/cmpxchg.h
index db6dda47184e..a6a4805064a4 100644
--- a/arch/csky/include/asm/cmpxchg.h
+++ b/arch/csky/include/asm/cmpxchg.h
@@ -65,6 +65,9 @@
case 1: \
__ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
break; \
+ case 2: \
+ __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
+ break; \
case 4: \
asm volatile ( \
"1: ldex.w %0, (%3) \n" \
@@ -98,6 +101,9 @@
case 1: \
__ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
break; \
+ case 2: \
+ __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
+ break; \
case 4: \
asm volatile ( \
"1: ldex.w %0, (%3) \n" \
@@ -132,6 +138,9 @@
case 1: \
__ret = (__typeof__(*(ptr)))cmpxchg_emu_u8((volatile u8 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
break; \
+ case 2: \
+ __ret = (__typeof__(*(ptr)))cmpxchg_emu_u16((volatile u16 *)__ptr, (uintptr_t)__old, (uintptr_t)__new); \
+ break; \
case 4: \
asm volatile ( \
RELEASE_FENCE \
--
2.47.3