]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/asm-generic/atomic-long.h
dmaengine: Fix access to uninitialized dma_slave_caps
[mirror_ubuntu-bionic-kernel.git] / include / asm-generic / atomic-long.h
CommitLineData
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
24typedef 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
31typedef 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 39static 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
45ATOMIC_LONG_READ_OP()
46ATOMIC_LONG_READ_OP(_acquire)
d3cb4871 47
6d79ef2d 48#undef ATOMIC_LONG_READ_OP
d3cb4871 49
6d79ef2d
WD
50#define ATOMIC_LONG_SET_OP(mo) \
51static 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}
57ATOMIC_LONG_SET_OP()
58ATOMIC_LONG_SET_OP(_release)
59
60#undef ATOMIC_LONG_SET_OP
61
62#define ATOMIC_LONG_ADD_SUB_OP(op, mo) \
63static inline long \
64atomic_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
70ATOMIC_LONG_ADD_SUB_OP(add,)
71ATOMIC_LONG_ADD_SUB_OP(add, _relaxed)
72ATOMIC_LONG_ADD_SUB_OP(add, _acquire)
73ATOMIC_LONG_ADD_SUB_OP(add, _release)
74ATOMIC_LONG_ADD_SUB_OP(sub,)
75ATOMIC_LONG_ADD_SUB_OP(sub, _relaxed)
76ATOMIC_LONG_ADD_SUB_OP(sub, _acquire)
77ATOMIC_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 102static __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 109static __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) \
117static inline long \
118atomic_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
125ATOMIC_LONG_FETCH_OP(add, )
126ATOMIC_LONG_FETCH_OP(add, _relaxed)
127ATOMIC_LONG_FETCH_OP(add, _acquire)
128ATOMIC_LONG_FETCH_OP(add, _release)
129ATOMIC_LONG_FETCH_OP(sub, )
130ATOMIC_LONG_FETCH_OP(sub, _relaxed)
131ATOMIC_LONG_FETCH_OP(sub, _acquire)
132ATOMIC_LONG_FETCH_OP(sub, _release)
133ATOMIC_LONG_FETCH_OP(and, )
134ATOMIC_LONG_FETCH_OP(and, _relaxed)
135ATOMIC_LONG_FETCH_OP(and, _acquire)
136ATOMIC_LONG_FETCH_OP(and, _release)
137ATOMIC_LONG_FETCH_OP(andnot, )
138ATOMIC_LONG_FETCH_OP(andnot, _relaxed)
139ATOMIC_LONG_FETCH_OP(andnot, _acquire)
140ATOMIC_LONG_FETCH_OP(andnot, _release)
141ATOMIC_LONG_FETCH_OP(or, )
142ATOMIC_LONG_FETCH_OP(or, _relaxed)
143ATOMIC_LONG_FETCH_OP(or, _acquire)
144ATOMIC_LONG_FETCH_OP(or, _release)
145ATOMIC_LONG_FETCH_OP(xor, )
146ATOMIC_LONG_FETCH_OP(xor, _relaxed)
147ATOMIC_LONG_FETCH_OP(xor, _acquire)
148ATOMIC_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) \
153static inline long \
154atomic_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
161ATOMIC_LONG_FETCH_INC_DEC_OP(inc,)
162ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _relaxed)
163ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _acquire)
164ATOMIC_LONG_FETCH_INC_DEC_OP(inc, _release)
165ATOMIC_LONG_FETCH_INC_DEC_OP(dec,)
166ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _relaxed)
167ATOMIC_LONG_FETCH_INC_DEC_OP(dec, _acquire)
168ATOMIC_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 173static __always_inline void \
90fe6514
PZ
174atomic_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
181ATOMIC_LONG_OP(add)
182ATOMIC_LONG_OP(sub)
183ATOMIC_LONG_OP(and)
28aa2bda 184ATOMIC_LONG_OP(andnot)
90fe6514
PZ
185ATOMIC_LONG_OP(or)
186ATOMIC_LONG_OP(xor)
d3cb4871 187
90fe6514 188#undef ATOMIC_LONG_OP
d3cb4871 189
bb2382c3
MD
190static 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
197static 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
204static 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
211static 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) \
219static inline long \
220atomic_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
226ATOMIC_LONG_INC_DEC_OP(inc,)
227ATOMIC_LONG_INC_DEC_OP(inc, _relaxed)
228ATOMIC_LONG_INC_DEC_OP(inc, _acquire)
229ATOMIC_LONG_INC_DEC_OP(inc, _release)
230ATOMIC_LONG_INC_DEC_OP(dec,)
231ATOMIC_LONG_INC_DEC_OP(dec, _relaxed)
232ATOMIC_LONG_INC_DEC_OP(dec, _acquire)
233ATOMIC_LONG_INC_DEC_OP(dec, _release)
234
235#undef ATOMIC_LONG_INC_DEC_OP
bb2382c3 236
2856f5e3
MD
237static 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 */