Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
72099ed2 AB |
2 | #ifndef _ASM_GENERIC_ATOMIC_LONG_H |
3 | #define _ASM_GENERIC_ATOMIC_LONG_H | |
d3cb4871 CL |
4 | /* |
5 | * Copyright (C) 2005 Silicon Graphics, Inc. | |
cde53535 | 6 | * Christoph Lameter |
d3cb4871 CL |
7 | * |
8 | * Allows to provide arch independent atomic definitions without the need to | |
9 | * edit all arch specific atomic.h files. | |
10 | */ | |
11 | ||
5998bf1d | 12 | #include <asm/types.h> |
d3cb4871 CL |
13 | |
14 | /* | |
15 | * Suppport for atomic_long_t | |
16 | * | |
17 | * Casts for parameters are avoided for existing atomic functions in order to | |
18 | * avoid issues with cast-as-lval under gcc 4.x and other limitations that the | |
19 | * macros of a platform may have. | |
20 | */ | |
21 | ||
22 | #if BITS_PER_LONG == 64 | |
23 | ||
24 | typedef atomic64_t atomic_long_t; | |
25 | ||
26 | #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i) | |
586b610e | 27 | #define ATOMIC_LONG_PFX(x) atomic64 ## x |
d3cb4871 | 28 | |
586b610e | 29 | #else |
d3cb4871 CL |
30 | |
31 | typedef atomic_t atomic_long_t; | |
32 | ||
33 | #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i) | |
586b610e WD |
34 | #define ATOMIC_LONG_PFX(x) atomic ## x |
35 | ||
36 | #endif | |
37 | ||
6d79ef2d | 38 | #define ATOMIC_LONG_READ_OP(mo) \ |
e3e72ab8 | 39 | static inline long atomic_long_read##mo(const atomic_long_t *l) \ |
6d79ef2d WD |
40 | { \ |
41 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ | |
42 | \ | |
43 | return (long)ATOMIC_LONG_PFX(_read##mo)(v); \ | |
d3cb4871 | 44 | } |
6d79ef2d WD |
45 | ATOMIC_LONG_READ_OP() |
46 | ATOMIC_LONG_READ_OP(_acquire) | |
d3cb4871 | 47 | |
6d79ef2d | 48 | #undef ATOMIC_LONG_READ_OP |
d3cb4871 | 49 | |
6d79ef2d WD |
50 | #define ATOMIC_LONG_SET_OP(mo) \ |
51 | static inline void atomic_long_set##mo(atomic_long_t *l, long i) \ | |
52 | { \ | |
53 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ | |
54 | \ | |
55 | ATOMIC_LONG_PFX(_set##mo)(v, i); \ | |
56 | } | |
57 | ATOMIC_LONG_SET_OP() | |
58 | ATOMIC_LONG_SET_OP(_release) | |
59 | ||
60 | #undef ATOMIC_LONG_SET_OP | |
61 | ||
62 | #define ATOMIC_LONG_ADD_SUB_OP(op, mo) \ | |
63 | static inline long \ | |
64 | atomic_long_##op##_return##mo(long i, atomic_long_t *l) \ | |
65 | { \ | |
66 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ | |
67 | \ | |
68 | return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(i, v); \ | |
d3cb4871 | 69 | } |
6d79ef2d WD |
70 | ATOMIC_LONG_ADD_SUB_OP(add,) |
71 | ATOMIC_LONG_ADD_SUB_OP(add, _relaxed) | |
72 | ATOMIC_LONG_ADD_SUB_OP(add, _acquire) | |
73 | ATOMIC_LONG_ADD_SUB_OP(add, _release) | |
74 | ATOMIC_LONG_ADD_SUB_OP(sub,) | |
75 | ATOMIC_LONG_ADD_SUB_OP(sub, _relaxed) | |
76 | ATOMIC_LONG_ADD_SUB_OP(sub, _acquire) | |
77 | ATOMIC_LONG_ADD_SUB_OP(sub, _release) | |
78 | ||
79 | #undef ATOMIC_LONG_ADD_SUB_OP | |
80 | ||
81 | #define atomic_long_cmpxchg_relaxed(l, old, new) \ | |
82 | (ATOMIC_LONG_PFX(_cmpxchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(l), \ | |
83 | (old), (new))) | |
84 | #define atomic_long_cmpxchg_acquire(l, old, new) \ | |
85 | (ATOMIC_LONG_PFX(_cmpxchg_acquire)((ATOMIC_LONG_PFX(_t) *)(l), \ | |
86 | (old), (new))) | |
87 | #define atomic_long_cmpxchg_release(l, old, new) \ | |
88 | (ATOMIC_LONG_PFX(_cmpxchg_release)((ATOMIC_LONG_PFX(_t) *)(l), \ | |
89 | (old), (new))) | |
90 | #define atomic_long_cmpxchg(l, old, new) \ | |
91 | (ATOMIC_LONG_PFX(_cmpxchg)((ATOMIC_LONG_PFX(_t) *)(l), (old), (new))) | |
92 | ||
93 | #define atomic_long_xchg_relaxed(v, new) \ | |
94 | (ATOMIC_LONG_PFX(_xchg_relaxed)((ATOMIC_LONG_PFX(_t) *)(v), (new))) | |
95 | #define atomic_long_xchg_acquire(v, new) \ | |
96 | (ATOMIC_LONG_PFX(_xchg_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (new))) | |
97 | #define atomic_long_xchg_release(v, new) \ | |
98 | (ATOMIC_LONG_PFX(_xchg_release)((ATOMIC_LONG_PFX(_t) *)(v), (new))) | |
99 | #define atomic_long_xchg(v, new) \ | |
100 | (ATOMIC_LONG_PFX(_xchg)((ATOMIC_LONG_PFX(_t) *)(v), (new))) | |
d3cb4871 | 101 | |
a644fdf0 | 102 | static __always_inline void atomic_long_inc(atomic_long_t *l) |
d3cb4871 | 103 | { |
586b610e | 104 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; |
d3cb4871 | 105 | |
586b610e | 106 | ATOMIC_LONG_PFX(_inc)(v); |
d3cb4871 CL |
107 | } |
108 | ||
a644fdf0 | 109 | static __always_inline void atomic_long_dec(atomic_long_t *l) |
d3cb4871 | 110 | { |
586b610e | 111 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; |
d3cb4871 | 112 | |
586b610e | 113 | ATOMIC_LONG_PFX(_dec)(v); |
d3cb4871 CL |
114 | } |
115 | ||
28aa2bda PZ |
116 | #define ATOMIC_LONG_FETCH_OP(op, mo) \ |
117 | static inline long \ | |
118 | atomic_long_fetch_##op##mo(long i, atomic_long_t *l) \ | |
119 | { \ | |
120 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ | |
121 | \ | |
122 | return (long)ATOMIC_LONG_PFX(_fetch_##op##mo)(i, v); \ | |
123 | } | |
124 | ||
125 | ATOMIC_LONG_FETCH_OP(add, ) | |
126 | ATOMIC_LONG_FETCH_OP(add, _relaxed) | |
127 | ATOMIC_LONG_FETCH_OP(add, _acquire) | |
128 | ATOMIC_LONG_FETCH_OP(add, _release) | |
129 | ATOMIC_LONG_FETCH_OP(sub, ) | |
130 | ATOMIC_LONG_FETCH_OP(sub, _relaxed) | |
131 | ATOMIC_LONG_FETCH_OP(sub, _acquire) | |
132 | ATOMIC_LONG_FETCH_OP(sub, _release) | |
133 | ATOMIC_LONG_FETCH_OP(and, ) | |
134 | ATOMIC_LONG_FETCH_OP(and, _relaxed) | |
135 | ATOMIC_LONG_FETCH_OP(and, _acquire) | |
136 | ATOMIC_LONG_FETCH_OP(and, _release) | |
137 | ATOMIC_LONG_FETCH_OP(andnot, ) | |
138 | ATOMIC_LONG_FETCH_OP(andnot, _relaxed) | |
139 | ATOMIC_LONG_FETCH_OP(andnot, _acquire) | |
140 | ATOMIC_LONG_FETCH_OP(andnot, _release) | |
141 | ATOMIC_LONG_FETCH_OP(or, ) | |
142 | ATOMIC_LONG_FETCH_OP(or, _relaxed) | |
143 | ATOMIC_LONG_FETCH_OP(or, _acquire) | |
144 | ATOMIC_LONG_FETCH_OP(or, _release) | |
145 | ATOMIC_LONG_FETCH_OP(xor, ) | |
146 | ATOMIC_LONG_FETCH_OP(xor, _relaxed) | |
147 | ATOMIC_LONG_FETCH_OP(xor, _acquire) | |
148 | ATOMIC_LONG_FETCH_OP(xor, _release) | |
149 | ||
f0662863 DB |
150 | #undef ATOMIC_LONG_FETCH_OP |
151 | ||
152 | #define ATOMIC_LONG_FETCH_INC_DEC_OP(op, mo) \ | |
153 | static inline long \ | |
154 | atomic_long_fetch_##op##mo(atomic_long_t *l) \ | |
155 | { \ | |
156 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ | |
157 | \ | |
158 | return (long)ATOMIC_LONG_PFX(_fetch_##op##mo)(v); \ | |
159 | } | |
160 | ||
161 | ATOMIC_LONG_FETCH_INC_DEC_OP(inc,) | |
162 | ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _relaxed) | |
163 | ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _acquire) | |
164 | ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _release) | |
165 | ATOMIC_LONG_FETCH_INC_DEC_OP(dec,) | |
166 | ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _relaxed) | |
167 | ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _acquire) | |
168 | ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _release) | |
169 | ||
170 | #undef ATOMIC_LONG_FETCH_INC_DEC_OP | |
171 | ||
90fe6514 | 172 | #define ATOMIC_LONG_OP(op) \ |
a644fdf0 | 173 | static __always_inline void \ |
90fe6514 PZ |
174 | atomic_long_##op(long i, atomic_long_t *l) \ |
175 | { \ | |
176 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ | |
177 | \ | |
178 | ATOMIC_LONG_PFX(_##op)(i, v); \ | |
d3cb4871 CL |
179 | } |
180 | ||
90fe6514 PZ |
181 | ATOMIC_LONG_OP(add) |
182 | ATOMIC_LONG_OP(sub) | |
183 | ATOMIC_LONG_OP(and) | |
28aa2bda | 184 | ATOMIC_LONG_OP(andnot) |
90fe6514 PZ |
185 | ATOMIC_LONG_OP(or) |
186 | ATOMIC_LONG_OP(xor) | |
d3cb4871 | 187 | |
90fe6514 | 188 | #undef ATOMIC_LONG_OP |
d3cb4871 | 189 | |
bb2382c3 MD |
190 | static inline int atomic_long_sub_and_test(long i, atomic_long_t *l) |
191 | { | |
586b610e | 192 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; |
bb2382c3 | 193 | |
586b610e | 194 | return ATOMIC_LONG_PFX(_sub_and_test)(i, v); |
bb2382c3 MD |
195 | } |
196 | ||
197 | static inline int atomic_long_dec_and_test(atomic_long_t *l) | |
198 | { | |
586b610e | 199 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; |
bb2382c3 | 200 | |
586b610e | 201 | return ATOMIC_LONG_PFX(_dec_and_test)(v); |
bb2382c3 MD |
202 | } |
203 | ||
204 | static inline int atomic_long_inc_and_test(atomic_long_t *l) | |
205 | { | |
586b610e | 206 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; |
bb2382c3 | 207 | |
586b610e | 208 | return ATOMIC_LONG_PFX(_inc_and_test)(v); |
bb2382c3 MD |
209 | } |
210 | ||
211 | static inline int atomic_long_add_negative(long i, atomic_long_t *l) | |
212 | { | |
586b610e | 213 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; |
bb2382c3 | 214 | |
586b610e | 215 | return ATOMIC_LONG_PFX(_add_negative)(i, v); |
bb2382c3 MD |
216 | } |
217 | ||
63ab7bd0 DB |
218 | #define ATOMIC_LONG_INC_DEC_OP(op, mo) \ |
219 | static inline long \ | |
220 | atomic_long_##op##_return##mo(atomic_long_t *l) \ | |
221 | { \ | |
222 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; \ | |
223 | \ | |
224 | return (long)ATOMIC_LONG_PFX(_##op##_return##mo)(v); \ | |
bb2382c3 | 225 | } |
63ab7bd0 DB |
226 | ATOMIC_LONG_INC_DEC_OP(inc,) |
227 | ATOMIC_LONG_INC_DEC_OP(inc, _relaxed) | |
228 | ATOMIC_LONG_INC_DEC_OP(inc, _acquire) | |
229 | ATOMIC_LONG_INC_DEC_OP(inc, _release) | |
230 | ATOMIC_LONG_INC_DEC_OP(dec,) | |
231 | ATOMIC_LONG_INC_DEC_OP(dec, _relaxed) | |
232 | ATOMIC_LONG_INC_DEC_OP(dec, _acquire) | |
233 | ATOMIC_LONG_INC_DEC_OP(dec, _release) | |
234 | ||
235 | #undef ATOMIC_LONG_INC_DEC_OP | |
bb2382c3 | 236 | |
2856f5e3 MD |
237 | static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u) |
238 | { | |
586b610e | 239 | ATOMIC_LONG_PFX(_t) *v = (ATOMIC_LONG_PFX(_t) *)l; |
2856f5e3 | 240 | |
586b610e | 241 | return (long)ATOMIC_LONG_PFX(_add_unless)(v, a, u); |
2856f5e3 | 242 | } |
bb2382c3 | 243 | |
586b610e WD |
244 | #define atomic_long_inc_not_zero(l) \ |
245 | ATOMIC_LONG_PFX(_inc_not_zero)((ATOMIC_LONG_PFX(_t) *)(l)) | |
4b358e22 | 246 | |
4df714be WD |
247 | #define atomic_long_cond_read_acquire(v, c) \ |
248 | ATOMIC_LONG_PFX(_cond_read_acquire)((ATOMIC_LONG_PFX(_t) *)(v), (c)) | |
249 | ||
72099ed2 | 250 | #endif /* _ASM_GENERIC_ATOMIC_LONG_H */ |