1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Atomics xchg/cmpxchg for PKUnity SoC and UniCore ISA
5 * Copyright (C) 2001-2012 GUAN Xue-tao
7 #ifndef __UNICORE_CMPXCHG_H__
8 #define __UNICORE_CMPXCHG_H__
11 * Generate a link failure on undefined symbol if the pointer points to a value
12 * of unsupported size.
14 extern void __xchg_bad_pointer(void);
16 static inline unsigned long __xchg(unsigned long x
, volatile void *ptr
,
23 asm volatile("swapb %0, %1, [%2]"
29 asm volatile("swapw %0, %1, [%2]"
41 #define xchg(ptr, x) \
42 ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
44 #include <asm-generic/cmpxchg-local.h>
47 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
50 #define cmpxchg_local(ptr, o, n) \
51 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \
52 (unsigned long)(o), (unsigned long)(n), sizeof(*(ptr))))
53 #define cmpxchg64_local(ptr, o, n) \
54 __cmpxchg64_local_generic((ptr), (o), (n))
56 #include <asm-generic/cmpxchg.h>
58 #endif /* __UNICORE_CMPXCHG_H__ */