1
#ifndef _ASM_X86_ATOMIC64_32_H
2
#define _ASM_X86_ATOMIC64_32_H
4
#include <linux/compiler.h>
5
#include <linux/types.h>
6
#include <asm/processor.h>
7
//#include <asm/cmpxchg.h>
9
/* An 64bit atomic type */
12
u64 __aligned(8) counter;
15
#define ATOMIC64_INIT(val) { (val) }
17
#ifdef CONFIG_X86_CMPXCHG64
18
#define ATOMIC64_ALTERNATIVE_(f, g) "call atomic64_" #g "_cx8"
20
#define ATOMIC64_ALTERNATIVE_(f, g) ALTERNATIVE("call atomic64_" #f "_386", "call atomic64_" #g "_cx8", X86_FEATURE_CX8)
23
#define ATOMIC64_ALTERNATIVE(f) ATOMIC64_ALTERNATIVE_(f, f)
26
* atomic64_cmpxchg - cmpxchg atomic64 variable
27
* @p: pointer to type atomic64_t
31
* Atomically sets @v to @n if it was equal to @o and returns
35
static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n)
37
return cmpxchg64(&v->counter, o, n);
41
* atomic64_xchg - xchg atomic64 variable
42
* @v: pointer to type atomic64_t
45
* Atomically xchgs the value of @v to @n and returns
48
static inline long long atomic64_xchg(atomic64_t *v, long long n)
51
unsigned high = (unsigned)(n >> 32);
52
unsigned low = (unsigned)n;
53
asm volatile(ATOMIC64_ALTERNATIVE(xchg)
54
: "=A" (o), "+b" (low), "+c" (high)
62
* atomic64_set - set atomic64 variable
63
* @v: pointer to type atomic64_t
66
* Atomically sets the value of @v to @n.
68
static inline void atomic64_set(atomic64_t *v, long long i)
70
unsigned high = (unsigned)(i >> 32);
71
unsigned low = (unsigned)i;
72
asm volatile(ATOMIC64_ALTERNATIVE(set)
73
: "+b" (low), "+c" (high)
75
: "eax", "edx", "memory"
80
* atomic64_read - read atomic64 variable
81
* @v: pointer to type atomic64_t
83
* Atomically reads the value of @v and returns it.
85
static inline long long atomic64_read(atomic64_t *v)
88
asm volatile(ATOMIC64_ALTERNATIVE(read)
96
* atomic64_add_return - add and return
97
* @i: integer value to add
98
* @v: pointer to type atomic64_t
100
* Atomically adds @i to @v and returns @i + *@v
102
static inline long long atomic64_add_return(long long i, atomic64_t *v)
104
asm volatile(ATOMIC64_ALTERNATIVE(add_return)
112
* Other variants with different arithmetic operators:
114
static inline long long atomic64_sub_return(long long i, atomic64_t *v)
116
asm volatile(ATOMIC64_ALTERNATIVE(sub_return)
123
static inline long long atomic64_inc_return(atomic64_t *v)
126
asm volatile(ATOMIC64_ALTERNATIVE(inc_return)
134
static inline long long atomic64_dec_return(atomic64_t *v)
137
asm volatile(ATOMIC64_ALTERNATIVE(dec_return)
146
* atomic64_add - add integer to atomic64 variable
147
* @i: integer value to add
148
* @v: pointer to type atomic64_t
150
* Atomically adds @i to @v.
152
static inline long long atomic64_add(long long i, atomic64_t *v)
154
asm volatile(ATOMIC64_ALTERNATIVE_(add, add_return)
162
* atomic64_sub - subtract the atomic64 variable
163
* @i: integer value to subtract
164
* @v: pointer to type atomic64_t
166
* Atomically subtracts @i from @v.
168
static inline long long atomic64_sub(long long i, atomic64_t *v)
170
asm volatile(ATOMIC64_ALTERNATIVE_(sub, sub_return)
178
* atomic64_sub_and_test - subtract value from variable and test result
179
* @i: integer value to subtract
180
* @v: pointer to type atomic64_t
182
* Atomically subtracts @i from @v and returns
183
* true if the result is zero, or false for all
186
static inline int atomic64_sub_and_test(long long i, atomic64_t *v)
188
return atomic64_sub_return(i, v) == 0;
192
* atomic64_inc - increment atomic64 variable
193
* @v: pointer to type atomic64_t
195
* Atomically increments @v by 1.
197
static inline void atomic64_inc(atomic64_t *v)
199
asm volatile(ATOMIC64_ALTERNATIVE_(inc, inc_return)
201
: "memory", "eax", "ecx", "edx"
206
* atomic64_dec - decrement atomic64 variable
207
* @ptr: pointer to type atomic64_t
209
* Atomically decrements @ptr by 1.
211
static inline void atomic64_dec(atomic64_t *v)
213
asm volatile(ATOMIC64_ALTERNATIVE_(dec, dec_return)
215
: "memory", "eax", "ecx", "edx"
220
* atomic64_dec_and_test - decrement and test
221
* @v: pointer to type atomic64_t
223
* Atomically decrements @v by 1 and
224
* returns true if the result is 0, or false for all other
227
static inline int atomic64_dec_and_test(atomic64_t *v)
229
return atomic64_dec_return(v) == 0;
233
* atomic64_inc_and_test - increment and test
234
* @v: pointer to type atomic64_t
236
* Atomically increments @v by 1
237
* and returns true if the result is zero, or false for all
240
static inline int atomic64_inc_and_test(atomic64_t *v)
242
return atomic64_inc_return(v) == 0;
246
* atomic64_add_negative - add and test if negative
247
* @i: integer value to add
248
* @v: pointer to type atomic64_t
250
* Atomically adds @i to @v and returns true
251
* if the result is negative, or false when
252
* result is greater than or equal to zero.
254
static inline int atomic64_add_negative(long long i, atomic64_t *v)
256
return atomic64_add_return(i, v) < 0;
260
* atomic64_add_unless - add unless the number is a given value
261
* @v: pointer of type atomic64_t
262
* @a: the amount to add to v...
263
* @u: ...unless v is equal to u.
265
* Atomically adds @a to @v, so long as it was not @u.
266
* Returns the old value of @v.
268
static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
270
unsigned low = (unsigned)u;
271
unsigned high = (unsigned)(u >> 32);
272
asm volatile(ATOMIC64_ALTERNATIVE(add_unless) "\n\t"
273
: "+A" (a), "+c" (v), "+S" (low), "+D" (high)
279
static inline int atomic64_inc_not_zero(atomic64_t *v)
282
asm volatile(ATOMIC64_ALTERNATIVE(inc_not_zero)
285
: "ecx", "edx", "memory"
290
static inline long long atomic64_dec_if_positive(atomic64_t *v)
293
asm volatile(ATOMIC64_ALTERNATIVE(dec_if_positive)
301
#undef ATOMIC64_ALTERNATIVE
302
#undef ATOMIC64_ALTERNATIVE_
304
#endif /* _ASM_X86_ATOMIC64_32_H */