1
2
3
4
5
6
7
8#ifndef _ASM_PARISC_CMPXCHG_H_
9#define _ASM_PARISC_CMPXCHG_H_
10
11
12
13
14extern void __xchg_called_with_bad_pointer(void);
15
16
17extern unsigned long __xchg8(char, char *);
18extern unsigned long __xchg32(int, int *);
19#ifdef CONFIG_64BIT
20extern unsigned long __xchg64(unsigned long, unsigned long *);
21#endif
22
23
24static 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 ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
49
50
51extern void __cmpxchg_called_with_bad_pointer(void);
52
53
54extern unsigned long __cmpxchg_u32(volatile unsigned int *m, unsigned int old,
55 unsigned int new_);
56extern u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new_);
57
58
59static inline unsigned long
60__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
61{
62 switch (size) {
63#ifdef CONFIG_64BIT
64 case 8: return __cmpxchg_u64((u64 *)ptr, old, new_);
65#endif
66 case 4: return __cmpxchg_u32((unsigned int *)ptr,
67 (unsigned int)old, (unsigned int)new_);
68 }
69 __cmpxchg_called_with_bad_pointer();
70 return old;
71}
72
73#define cmpxchg(ptr, o, n) \
74({ \
75 __typeof__(*(ptr)) _o_ = (o); \
76 __typeof__(*(ptr)) _n_ = (n); \
77 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
78 (unsigned long)_n_, sizeof(*(ptr))); \
79})
80
81#include <asm-generic/cmpxchg-local.h>
82
83static inline unsigned long __cmpxchg_local(volatile void *ptr,
84 unsigned long old,
85 unsigned long new_, int size)
86{
87 switch (size) {
88#ifdef CONFIG_64BIT
89 case 8: return __cmpxchg_u64((u64 *)ptr, old, new_);
90#endif
91 case 4: return __cmpxchg_u32(ptr, old, new_);
92 default:
93 return __cmpxchg_local_generic(ptr, old, new_, size);
94 }
95}
96
97
98
99
100
101#define cmpxchg_local(ptr, o, n) \
102 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
103 (unsigned long)(n), sizeof(*(ptr))))
104#ifdef CONFIG_64BIT
105#define cmpxchg64_local(ptr, o, n) \
106({ \
107 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
108 cmpxchg_local((ptr), (o), (n)); \
109})
110#else
111#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
112#endif
113
114#define cmpxchg64(ptr, o, n) __cmpxchg_u64(ptr, o, n)
115
116#endif
117