1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef __ASM_CSKY_CMPXCHG_H
4 #define __ASM_CSKY_CMPXCHG_H
6 #ifdef CONFIG_CPU_HAS_LDSTEX
7 #include <asm/barrier.h>
9 extern void __bad_xchg(void);
11 #define __xchg(new, ptr, size) \
13 __typeof__(ptr) __ptr = (ptr); \
14 __typeof__(new) __new = (new); \
15 __typeof__(*(ptr)) __ret; \
21 "1: ldex.w %0, (%3) \n" \
23 " stex.w %1, (%3) \n" \
25 : "=&r" (__ret), "=&r" (tmp) \
26 : "r" (__new), "r"(__ptr) \
36 #define xchg(ptr, x) (__xchg((x), (ptr), sizeof(*(ptr))))
38 #define __cmpxchg(ptr, old, new, size) \
40 __typeof__(ptr) __ptr = (ptr); \
41 __typeof__(new) __new = (new); \
42 __typeof__(new) __tmp; \
43 __typeof__(old) __old = (old); \
44 __typeof__(*(ptr)) __ret; \
49 "1: ldex.w %0, (%3) \n" \
53 " stex.w %1, (%3) \n" \
56 : "=&r" (__ret), "=&r" (__tmp) \
57 : "r" (__new), "r"(__ptr), "r"(__old) \
67 #define cmpxchg(ptr, o, n) \
68 (__cmpxchg((ptr), (o), (n), sizeof(*(ptr))))
70 #include <asm-generic/cmpxchg.h>
73 #endif /* __ASM_CSKY_CMPXCHG_H */