1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_SH_CMPXCHG_H
3 #define __ASM_SH_CMPXCHG_H
6 * Atomic operations that C can't guarantee us. Useful for
7 * resource counting etc..
10 #include <linux/compiler.h>
11 #include <linux/types.h>
12 #include <linux/cmpxchg-emu.h>
14 #if defined(CONFIG_GUSA_RB)
15 #include <asm/cmpxchg-grb.h>
16 #elif defined(CONFIG_CPU_SH4A)
17 #include <asm/cmpxchg-llsc.h>
18 #elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP)
19 #include <asm/cmpxchg-cas.h>
21 #include <asm/cmpxchg-irq.h>
24 extern void __xchg_called_with_bad_pointer(void);
26 #define __arch_xchg(ptr, x, size) \
28 unsigned long __xchg__res; \
29 volatile void *__xchg_ptr = (ptr); \
32 __xchg__res = xchg_u32(__xchg_ptr, x); \
35 __xchg__res = xchg_u16(__xchg_ptr, x); \
38 __xchg__res = xchg_u8(__xchg_ptr, x); \
41 __xchg_called_with_bad_pointer(); \
49 #define arch_xchg(ptr,x) \
50 ((__typeof__(*(ptr)))__arch_xchg((ptr),(unsigned long)(x), sizeof(*(ptr))))
52 /* This function doesn't exist, so you'll get a linker error
53 * if something tries to do an invalid cmpxchg(). */
54 extern void __cmpxchg_called_with_bad_pointer(void);
56 static inline unsigned long __cmpxchg(volatile void * ptr
, unsigned long old
,
57 unsigned long new, int size
)
61 return cmpxchg_emu_u8(ptr
, old
, new);
63 return __cmpxchg_u32(ptr
, old
, new);
65 __cmpxchg_called_with_bad_pointer();
69 #define arch_cmpxchg(ptr,o,n) \
71 __typeof__(*(ptr)) _o_ = (o); \
72 __typeof__(*(ptr)) _n_ = (n); \
73 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
74 (unsigned long)_n_, sizeof(*(ptr))); \
77 #include <asm-generic/cmpxchg-local.h>
79 #define arch_cmpxchg_local(ptr, o, n) ({ \
80 (__typeof__(*ptr))__generic_cmpxchg_local((ptr), \
86 #endif /* __ASM_SH_CMPXCHG_H */