2 * forked from parisc asm/atomic.h which was:
7 #ifndef _ASM_PARISC_CMPXCHG_H_
8 #define _ASM_PARISC_CMPXCHG_H_
10 /* This should get optimized out since it's never called.
11 ** Or get a link error if xchg is used "wrong".
13 extern void __xchg_called_with_bad_pointer(void);
15 /* __xchg32/64 defined in arch/parisc/lib/bitops.c */
16 extern unsigned long __xchg8(char, char *);
17 extern unsigned long __xchg32(int, int *);
19 extern unsigned long __xchg64(unsigned long, unsigned long *);
22 /* optimizer better get rid of switch since size is a constant */
23 static inline unsigned long
24 __xchg(unsigned long x, __volatile__ void *ptr, int size)
28 case 8: return __xchg64(x, (unsigned long *) ptr);
30 case 4: return __xchg32((int) x, (int *) ptr);
31 case 1: return __xchg8((char) x, (char *) ptr);
33 __xchg_called_with_bad_pointer();
38 ** REVISIT - Abandoned use of LDCW in xchg() for now:
39 ** o need to test sizeof(*ptr) to avoid clearing adjacent bytes
40 ** o and while we are at it, could CONFIG_64BIT code use LDCD too?
42 ** if (__builtin_constant_p(x) && (x == NULL))
43 ** if (((unsigned long)p & 0xf) == 0)
46 #define xchg(ptr, x) \
47 ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
49 #define __HAVE_ARCH_CMPXCHG 1
51 /* bug catcher for when unsupported size is used - won't link */
52 extern void __cmpxchg_called_with_bad_pointer(void);
54 /* __cmpxchg_u32/u64 defined in arch/parisc/lib/bitops.c */
55 extern unsigned long __cmpxchg_u32(volatile unsigned int *m, unsigned int old,
57 extern unsigned long __cmpxchg_u64(volatile unsigned long *ptr,
58 unsigned long old, unsigned long new_);
60 /* don't worry...optimizer will get rid of most of this */
61 static inline unsigned long
62 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
66 case 8: return __cmpxchg_u64((unsigned long *)ptr, old, new_);
68 case 4: return __cmpxchg_u32((unsigned int *)ptr,
69 (unsigned int)old, (unsigned int)new_);
71 __cmpxchg_called_with_bad_pointer();
75 #define cmpxchg(ptr, o, n) \
77 __typeof__(*(ptr)) _o_ = (o); \
78 __typeof__(*(ptr)) _n_ = (n); \
79 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
80 (unsigned long)_n_, sizeof(*(ptr))); \
83 #include <asm-generic/cmpxchg-local.h>
85 static inline unsigned long __cmpxchg_local(volatile void *ptr,
87 unsigned long new_, int size)
91 case 8: return __cmpxchg_u64((unsigned long *)ptr, old, new_);
93 case 4: return __cmpxchg_u32(ptr, old, new_);
95 return __cmpxchg_local_generic(ptr, old, new_, size);
100 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
103 #define cmpxchg_local(ptr, o, n) \
104 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
105 (unsigned long)(n), sizeof(*(ptr))))
107 #define cmpxchg64_local(ptr, o, n) \
109 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
110 cmpxchg_local((ptr), (o), (n)); \
113 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
116 #endif /* _ASM_PARISC_CMPXCHG_H_ */