This source file includes following definitions.
- __xchg
- __cmpxchg
- __cmpxchg_local
1
2
3
4
5
6
7
8 #ifndef _ASM_PARISC_CMPXCHG_H_
9 #define _ASM_PARISC_CMPXCHG_H_
10
11
12
13
14 extern void __xchg_called_with_bad_pointer(void);
15
16
17 extern unsigned long __xchg8(char, char *);
18 extern unsigned long __xchg32(int, int *);
19 #ifdef CONFIG_64BIT
20 extern unsigned long __xchg64(unsigned long, unsigned long *);
21 #endif
22
23
24 static inline unsigned long
25 __xchg(unsigned long x, __volatile__ void *ptr, int size)
26 {
27 switch (size) {
28 #ifdef CONFIG_64BIT
29 case 8: return __xchg64(x, (unsigned long *) ptr);
30 #endif
31 case 4: return __xchg32((int) x, (int *) ptr);
32 case 1: return __xchg8((char) x, (char *) ptr);
33 }
34 __xchg_called_with_bad_pointer();
35 return x;
36 }
37
38
39
40
41
42
43
44
45
46
47 #define xchg(ptr, x) \
48 ({ \
49 __typeof__(*(ptr)) __ret; \
50 __typeof__(*(ptr)) _x_ = (x); \
51 __ret = (__typeof__(*(ptr))) \
52 __xchg((unsigned long)_x_, (ptr), sizeof(*(ptr))); \
53 __ret; \
54 })
55
56
57 extern void __cmpxchg_called_with_bad_pointer(void);
58
59
60 extern unsigned long __cmpxchg_u32(volatile unsigned int *m, unsigned int old,
61 unsigned int new_);
62 extern u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new_);
63
64
65 static inline unsigned long
66 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
67 {
68 switch (size) {
69 #ifdef CONFIG_64BIT
70 case 8: return __cmpxchg_u64((u64 *)ptr, old, new_);
71 #endif
72 case 4: return __cmpxchg_u32((unsigned int *)ptr,
73 (unsigned int)old, (unsigned int)new_);
74 }
75 __cmpxchg_called_with_bad_pointer();
76 return old;
77 }
78
79 #define cmpxchg(ptr, o, n) \
80 ({ \
81 __typeof__(*(ptr)) _o_ = (o); \
82 __typeof__(*(ptr)) _n_ = (n); \
83 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
84 (unsigned long)_n_, sizeof(*(ptr))); \
85 })
86
87 #include <asm-generic/cmpxchg-local.h>
88
89 static inline unsigned long __cmpxchg_local(volatile void *ptr,
90 unsigned long old,
91 unsigned long new_, int size)
92 {
93 switch (size) {
94 #ifdef CONFIG_64BIT
95 case 8: return __cmpxchg_u64((u64 *)ptr, old, new_);
96 #endif
97 case 4: return __cmpxchg_u32(ptr, old, new_);
98 default:
99 return __cmpxchg_local_generic(ptr, old, new_, size);
100 }
101 }
102
103
104
105
106
107 #define cmpxchg_local(ptr, o, n) \
108 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
109 (unsigned long)(n), sizeof(*(ptr))))
110 #ifdef CONFIG_64BIT
111 #define cmpxchg64_local(ptr, o, n) \
112 ({ \
113 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
114 cmpxchg_local((ptr), (o), (n)); \
115 })
116 #else
117 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
118 #endif
119
120 #define cmpxchg64(ptr, o, n) __cmpxchg_u64(ptr, o, n)
121
122 #endif