]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - arch/metag/include/asm/cmpxchg.h
Merge tag 'for-4.2' of git://git.infradead.org/battery-2.6
[mirror_ubuntu-focal-kernel.git] / arch / metag / include / asm / cmpxchg.h
CommitLineData
6006c0d8
JH
1#ifndef __ASM_METAG_CMPXCHG_H
2#define __ASM_METAG_CMPXCHG_H
3
4#include <asm/barrier.h>
5
6#if defined(CONFIG_METAG_ATOMICITY_IRQSOFF)
7#include <asm/cmpxchg_irq.h>
8#elif defined(CONFIG_METAG_ATOMICITY_LOCK1)
9#include <asm/cmpxchg_lock1.h>
10#elif defined(CONFIG_METAG_ATOMICITY_LNKGET)
11#include <asm/cmpxchg_lnkget.h>
12#endif
13
14extern void __xchg_called_with_bad_pointer(void);
15
16#define __xchg(ptr, x, size) \
17({ \
18 unsigned long __xchg__res; \
19 volatile void *__xchg_ptr = (ptr); \
20 switch (size) { \
21 case 4: \
22 __xchg__res = xchg_u32(__xchg_ptr, x); \
23 break; \
24 case 1: \
25 __xchg__res = xchg_u8(__xchg_ptr, x); \
26 break; \
27 default: \
28 __xchg_called_with_bad_pointer(); \
29 __xchg__res = x; \
30 break; \
31 } \
32 \
33 __xchg__res; \
34})
35
36#define xchg(ptr, x) \
37 ((__typeof__(*(ptr)))__xchg((ptr), (unsigned long)(x), sizeof(*(ptr))))
38
39/* This function doesn't exist, so you'll get a linker error
40 * if something tries to do an invalid cmpxchg(). */
41extern void __cmpxchg_called_with_bad_pointer(void);
42
43static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
44 unsigned long new, int size)
45{
46 switch (size) {
47 case 4:
48 return __cmpxchg_u32(ptr, old, new);
49 }
50 __cmpxchg_called_with_bad_pointer();
51 return old;
52}
53
6006c0d8
JH
54#define cmpxchg(ptr, o, n) \
55 ({ \
56 __typeof__(*(ptr)) _o_ = (o); \
57 __typeof__(*(ptr)) _n_ = (n); \
58 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
59 (unsigned long)_n_, \
60 sizeof(*(ptr))); \
61 })
62
63#endif /* __ASM_METAG_CMPXCHG_H */