1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ARCH_M68K_CMPXCHG__
3 #define __ARCH_M68K_CMPXCHG__
5 #include <linux/irqflags.h>
7 struct __xchg_dummy
{ unsigned long a
[100]; };
8 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
10 extern unsigned long __invalid_xchg_size(unsigned long, volatile void *, int);
12 #ifndef CONFIG_RMW_INSNS
13 static inline unsigned long __xchg(unsigned long x
, volatile void * ptr
, int size
)
15 unsigned long flags
, tmp
;
17 local_irq_save(flags
);
36 tmp
= __invalid_xchg_size(x
, ptr
, size
);
40 local_irq_restore(flags
);
44 static inline unsigned long __xchg(unsigned long x
, volatile void * ptr
, int size
)
53 : "=&d" (x
) : "d" (x
), "m" (*__xg(ptr
)) : "memory");
61 : "=&d" (x
) : "d" (x
), "m" (*__xg(ptr
)) : "memory");
69 : "=&d" (x
) : "d" (x
), "m" (*__xg(ptr
)) : "memory");
72 x
= __invalid_xchg_size(x
, ptr
, size
);
79 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
81 #include <asm-generic/cmpxchg-local.h>
83 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
85 extern unsigned long __invalid_cmpxchg_size(volatile void *,
86 unsigned long, unsigned long, int);
89 * Atomic compare and exchange. Compare OLD with MEM, if identical,
90 * store NEW in MEM. Return the initial value in MEM. Success is
91 * indicated by comparing RETURN with OLD.
93 #ifdef CONFIG_RMW_INSNS
95 static inline unsigned long __cmpxchg(volatile void *p
, unsigned long old
,
96 unsigned long new, int size
)
100 __asm__
__volatile__ ("casb %0,%2,%1"
101 : "=d" (old
), "=m" (*(char *)p
)
102 : "d" (new), "0" (old
), "m" (*(char *)p
));
105 __asm__
__volatile__ ("casw %0,%2,%1"
106 : "=d" (old
), "=m" (*(short *)p
)
107 : "d" (new), "0" (old
), "m" (*(short *)p
));
110 __asm__
__volatile__ ("casl %0,%2,%1"
111 : "=d" (old
), "=m" (*(int *)p
)
112 : "d" (new), "0" (old
), "m" (*(int *)p
));
115 old
= __invalid_cmpxchg_size(p
, old
, new, size
);
121 #define cmpxchg(ptr, o, n) \
122 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
123 (unsigned long)(n), sizeof(*(ptr))))
124 #define cmpxchg_local(ptr, o, n) \
125 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
126 (unsigned long)(n), sizeof(*(ptr))))
128 #define cmpxchg64(ptr, o, n) cmpxchg64_local((ptr), (o), (n))
133 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
136 #define cmpxchg_local(ptr, o, n) \
137 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
138 (unsigned long)(n), sizeof(*(ptr))))
140 #include <asm-generic/cmpxchg.h>
144 #endif /* __ARCH_M68K_CMPXCHG__ */