Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / arch / metag / include / asm / cmpxchg.h
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
14 extern 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(). */
41 extern void __cmpxchg_called_with_bad_pointer(void);
42
43 static 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
54 #define __HAVE_ARCH_CMPXCHG 1
55
56 #define cmpxchg(ptr, o, n)                                              \
57         ({                                                              \
58                 __typeof__(*(ptr)) _o_ = (o);                           \
59                 __typeof__(*(ptr)) _n_ = (n);                           \
60                 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
61                                                (unsigned long)_n_,      \
62                                                sizeof(*(ptr)));         \
63         })
64
65 #endif /* __ASM_METAG_CMPXCHG_H */