2 * Atomics xchg/cmpxchg for PKUnity SoC and UniCore ISA
4 * Copyright (C) 2001-2012 GUAN Xue-tao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 #ifndef __UNICORE_CMPXCHG_H__
11 #define __UNICORE_CMPXCHG_H__
14 * Generate a link failure on undefined symbol if the pointer points to a value
15 * of unsupported size.
17 extern void __xchg_bad_pointer(void);
19 static inline unsigned long __xchg(unsigned long x
, volatile void *ptr
,
26 asm volatile("swapb %0, %1, [%2]"
32 asm volatile("swapw %0, %1, [%2]"
44 #define xchg(ptr, x) \
45 ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
47 #include <asm-generic/cmpxchg-local.h>
50 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
53 #define cmpxchg_local(ptr, o, n) \
54 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \
55 (unsigned long)(o), (unsigned long)(n), sizeof(*(ptr))))
56 #define cmpxchg64_local(ptr, o, n) \
57 __cmpxchg64_local_generic((ptr), (o), (n))
59 #include <asm-generic/cmpxchg.h>
61 #endif /* __UNICORE_CMPXCHG_H__ */