blob: 2bf80afb7841916439cee502881fbf6ee0273ddd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Russell King4baa9922008-08-02 10:55:55 +01002 * arch/arm/include/asm/atomic.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1996 Russell King.
5 * Copyright (C) 2002 Deep Blue Solutions Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef __ASM_ARM_ATOMIC_H
12#define __ASM_ARM_ATOMIC_H
13
Russell King8dc39b82005-11-16 17:23:57 +000014#include <linux/compiler.h>
Will Deaconf38d9992013-07-04 11:43:18 +010015#include <linux/prefetch.h>
Matthew Wilcoxea4354672009-01-06 14:40:39 -080016#include <linux/types.h>
David Howells9f97da72012-03-28 18:30:01 +010017#include <linux/irqflags.h>
18#include <asm/barrier.h>
19#include <asm/cmpxchg.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#define ATOMIC_INIT(i) { (i) }
22
23#ifdef __KERNEL__
24
Catalin Marinas200b8122009-09-18 23:27:05 +010025/*
26 * On ARM, ordinary assignment (str instruction) doesn't clear the local
27 * strex/ldrex monitor on some implementations. The reason we can use it for
28 * atomic_set() is the clrex or dummy strex done on every exception return.
29 */
Peter Zijlstra62e8a322015-09-18 11:13:10 +020030#define atomic_read(v) READ_ONCE((v)->counter)
31#define atomic_set(v,i) WRITE_ONCE(((v)->counter), (i))
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#if __LINUX_ARM_ARCH__ >= 6
34
35/*
36 * ARMv6 UP and SMP safe atomic ops. We use load exclusive and
37 * store exclusive to ensure that these are atomic. We may loop
Catalin Marinas200b8122009-09-18 23:27:05 +010038 * to ensure that the update happens.
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 */
Russell Kingbac4e962009-05-25 20:58:00 +010040
Peter Zijlstraaee9a552014-03-23 16:38:18 +010041#define ATOMIC_OP(op, c_op, asm_op) \
42static inline void atomic_##op(int i, atomic_t *v) \
43{ \
44 unsigned long tmp; \
45 int result; \
46 \
47 prefetchw(&v->counter); \
48 __asm__ __volatile__("@ atomic_" #op "\n" \
49"1: ldrex %0, [%3]\n" \
50" " #asm_op " %0, %0, %4\n" \
51" strex %1, %0, [%3]\n" \
52" teq %1, #0\n" \
53" bne 1b" \
54 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
55 : "r" (&v->counter), "Ir" (i) \
56 : "cc"); \
57} \
Russell Kingbac4e962009-05-25 20:58:00 +010058
Peter Zijlstraaee9a552014-03-23 16:38:18 +010059#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
Will Deacon0ca326d2015-08-06 17:54:44 +010060static inline int atomic_##op##_return_relaxed(int i, atomic_t *v) \
Peter Zijlstraaee9a552014-03-23 16:38:18 +010061{ \
62 unsigned long tmp; \
63 int result; \
64 \
Peter Zijlstraaee9a552014-03-23 16:38:18 +010065 prefetchw(&v->counter); \
66 \
67 __asm__ __volatile__("@ atomic_" #op "_return\n" \
68"1: ldrex %0, [%3]\n" \
69" " #asm_op " %0, %0, %4\n" \
70" strex %1, %0, [%3]\n" \
71" teq %1, #0\n" \
72" bne 1b" \
73 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
74 : "r" (&v->counter), "Ir" (i) \
75 : "cc"); \
76 \
Peter Zijlstraaee9a552014-03-23 16:38:18 +010077 return result; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070078}
79
Will Deacon0ca326d2015-08-06 17:54:44 +010080#define atomic_add_return_relaxed atomic_add_return_relaxed
81#define atomic_sub_return_relaxed atomic_sub_return_relaxed
82
83static inline int atomic_cmpxchg_relaxed(atomic_t *ptr, int old, int new)
Nick Piggin4a6dae62005-11-13 16:07:24 -080084{
Chen Gang4dcc1cf2013-10-26 15:07:25 +010085 int oldval;
86 unsigned long res;
Nick Piggin4a6dae62005-11-13 16:07:24 -080087
Will Deaconc32ffce2014-02-21 17:01:48 +010088 prefetchw(&ptr->counter);
Russell Kingbac4e962009-05-25 20:58:00 +010089
Nick Piggin4a6dae62005-11-13 16:07:24 -080090 do {
91 __asm__ __volatile__("@ atomic_cmpxchg\n"
Will Deacon398aa662010-07-08 10:59:16 +010092 "ldrex %1, [%3]\n"
Nicolas Pitrea7d06832005-11-16 15:05:11 +000093 "mov %0, #0\n"
Will Deacon398aa662010-07-08 10:59:16 +010094 "teq %1, %4\n"
95 "strexeq %0, %5, [%3]\n"
96 : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
Nick Piggin4a6dae62005-11-13 16:07:24 -080097 : "r" (&ptr->counter), "Ir" (old), "r" (new)
98 : "cc");
99 } while (res);
100
101 return oldval;
102}
Will Deacon0ca326d2015-08-06 17:54:44 +0100103#define atomic_cmpxchg_relaxed atomic_cmpxchg_relaxed
Nick Piggin4a6dae62005-11-13 16:07:24 -0800104
Will Deacondb38ee82014-02-21 17:01:48 +0100105static inline int __atomic_add_unless(atomic_t *v, int a, int u)
106{
107 int oldval, newval;
108 unsigned long tmp;
109
110 smp_mb();
111 prefetchw(&v->counter);
112
113 __asm__ __volatile__ ("@ atomic_add_unless\n"
114"1: ldrex %0, [%4]\n"
115" teq %0, %5\n"
116" beq 2f\n"
117" add %1, %0, %6\n"
118" strex %2, %1, [%4]\n"
119" teq %2, #0\n"
120" bne 1b\n"
121"2:"
122 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
123 : "r" (&v->counter), "r" (u), "r" (a)
124 : "cc");
125
126 if (oldval != u)
127 smp_mb();
128
129 return oldval;
130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#else /* ARM_ARCH_6 */
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#ifdef CONFIG_SMP
135#error SMP not supported on pre-ARMv6 CPUs
136#endif
137
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100138#define ATOMIC_OP(op, c_op, asm_op) \
139static inline void atomic_##op(int i, atomic_t *v) \
140{ \
141 unsigned long flags; \
142 \
143 raw_local_irq_save(flags); \
144 v->counter c_op i; \
145 raw_local_irq_restore(flags); \
146} \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100148#define ATOMIC_OP_RETURN(op, c_op, asm_op) \
149static inline int atomic_##op##_return(int i, atomic_t *v) \
150{ \
151 unsigned long flags; \
152 int val; \
153 \
154 raw_local_irq_save(flags); \
155 v->counter c_op i; \
156 val = v->counter; \
157 raw_local_irq_restore(flags); \
158 \
159 return val; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Nick Piggin4a6dae62005-11-13 16:07:24 -0800162static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
163{
164 int ret;
165 unsigned long flags;
166
Lennert Buytenhek8dd5c842006-09-16 10:47:18 +0100167 raw_local_irq_save(flags);
Nick Piggin4a6dae62005-11-13 16:07:24 -0800168 ret = v->counter;
169 if (likely(ret == old))
170 v->counter = new;
Lennert Buytenhek8dd5c842006-09-16 10:47:18 +0100171 raw_local_irq_restore(flags);
Nick Piggin4a6dae62005-11-13 16:07:24 -0800172
173 return ret;
174}
175
Arun Sharmaf24219b2011-07-26 16:09:07 -0700176static inline int __atomic_add_unless(atomic_t *v, int a, int u)
Nick Piggin8426e1f2005-11-13 16:07:25 -0800177{
178 int c, old;
179
180 c = atomic_read(v);
181 while (c != u && (old = atomic_cmpxchg((v), c, c + a)) != c)
182 c = old;
Arun Sharmaf24219b2011-07-26 16:09:07 -0700183 return c;
Nick Piggin8426e1f2005-11-13 16:07:25 -0800184}
Nick Piggin8426e1f2005-11-13 16:07:25 -0800185
Will Deacondb38ee82014-02-21 17:01:48 +0100186#endif /* __LINUX_ARM_ARCH__ */
187
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100188#define ATOMIC_OPS(op, c_op, asm_op) \
189 ATOMIC_OP(op, c_op, asm_op) \
190 ATOMIC_OP_RETURN(op, c_op, asm_op)
191
192ATOMIC_OPS(add, +=, add)
193ATOMIC_OPS(sub, -=, sub)
194
Peter Zijlstra12589792014-04-23 20:04:39 +0200195#define atomic_andnot atomic_andnot
196
197ATOMIC_OP(and, &=, and)
198ATOMIC_OP(andnot, &= ~, bic)
199ATOMIC_OP(or, |=, orr)
200ATOMIC_OP(xor, ^=, eor)
201
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100202#undef ATOMIC_OPS
203#undef ATOMIC_OP_RETURN
204#undef ATOMIC_OP
205
Will Deacondb38ee82014-02-21 17:01:48 +0100206#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
207
Russell Kingbac4e962009-05-25 20:58:00 +0100208#define atomic_inc(v) atomic_add(1, v)
209#define atomic_dec(v) atomic_sub(1, v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211#define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
212#define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
213#define atomic_inc_return(v) (atomic_add_return(1, v))
214#define atomic_dec_return(v) (atomic_sub_return(1, v))
215#define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
216
217#define atomic_add_negative(i,v) (atomic_add_return(i, v) < 0)
218
Will Deacon24b44a62010-01-20 19:05:07 +0100219#ifndef CONFIG_GENERIC_ATOMIC64
220typedef struct {
Chen Gang237f1232013-10-26 15:07:04 +0100221 long long counter;
Will Deacon24b44a62010-01-20 19:05:07 +0100222} atomic64_t;
223
224#define ATOMIC64_INIT(i) { (i) }
225
Will Deacon4fd75912013-03-28 11:25:03 +0100226#ifdef CONFIG_ARM_LPAE
Chen Gang237f1232013-10-26 15:07:04 +0100227static inline long long atomic64_read(const atomic64_t *v)
Will Deacon4fd75912013-03-28 11:25:03 +0100228{
Chen Gang237f1232013-10-26 15:07:04 +0100229 long long result;
Will Deacon4fd75912013-03-28 11:25:03 +0100230
231 __asm__ __volatile__("@ atomic64_read\n"
232" ldrd %0, %H0, [%1]"
233 : "=&r" (result)
234 : "r" (&v->counter), "Qo" (v->counter)
235 );
236
237 return result;
238}
239
Chen Gang237f1232013-10-26 15:07:04 +0100240static inline void atomic64_set(atomic64_t *v, long long i)
Will Deacon4fd75912013-03-28 11:25:03 +0100241{
242 __asm__ __volatile__("@ atomic64_set\n"
243" strd %2, %H2, [%1]"
244 : "=Qo" (v->counter)
245 : "r" (&v->counter), "r" (i)
246 );
247}
248#else
Chen Gang237f1232013-10-26 15:07:04 +0100249static inline long long atomic64_read(const atomic64_t *v)
Will Deacon24b44a62010-01-20 19:05:07 +0100250{
Chen Gang237f1232013-10-26 15:07:04 +0100251 long long result;
Will Deacon24b44a62010-01-20 19:05:07 +0100252
253 __asm__ __volatile__("@ atomic64_read\n"
254" ldrexd %0, %H0, [%1]"
255 : "=&r" (result)
Will Deacon398aa662010-07-08 10:59:16 +0100256 : "r" (&v->counter), "Qo" (v->counter)
Will Deacon24b44a62010-01-20 19:05:07 +0100257 );
258
259 return result;
260}
261
Chen Gang237f1232013-10-26 15:07:04 +0100262static inline void atomic64_set(atomic64_t *v, long long i)
Will Deacon24b44a62010-01-20 19:05:07 +0100263{
Chen Gang237f1232013-10-26 15:07:04 +0100264 long long tmp;
Will Deacon24b44a62010-01-20 19:05:07 +0100265
Will Deaconf38d9992013-07-04 11:43:18 +0100266 prefetchw(&v->counter);
Will Deacon24b44a62010-01-20 19:05:07 +0100267 __asm__ __volatile__("@ atomic64_set\n"
Will Deacon398aa662010-07-08 10:59:16 +0100268"1: ldrexd %0, %H0, [%2]\n"
269" strexd %0, %3, %H3, [%2]\n"
Will Deacon24b44a62010-01-20 19:05:07 +0100270" teq %0, #0\n"
271" bne 1b"
Will Deacon398aa662010-07-08 10:59:16 +0100272 : "=&r" (tmp), "=Qo" (v->counter)
Will Deacon24b44a62010-01-20 19:05:07 +0100273 : "r" (&v->counter), "r" (i)
274 : "cc");
275}
Will Deacon4fd75912013-03-28 11:25:03 +0100276#endif
Will Deacon24b44a62010-01-20 19:05:07 +0100277
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100278#define ATOMIC64_OP(op, op1, op2) \
279static inline void atomic64_##op(long long i, atomic64_t *v) \
280{ \
281 long long result; \
282 unsigned long tmp; \
283 \
284 prefetchw(&v->counter); \
285 __asm__ __volatile__("@ atomic64_" #op "\n" \
286"1: ldrexd %0, %H0, [%3]\n" \
287" " #op1 " %Q0, %Q0, %Q4\n" \
288" " #op2 " %R0, %R0, %R4\n" \
289" strexd %1, %0, %H0, [%3]\n" \
290" teq %1, #0\n" \
291" bne 1b" \
292 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
293 : "r" (&v->counter), "r" (i) \
294 : "cc"); \
295} \
Will Deacon24b44a62010-01-20 19:05:07 +0100296
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100297#define ATOMIC64_OP_RETURN(op, op1, op2) \
Will Deacon0ca326d2015-08-06 17:54:44 +0100298static inline long long \
299atomic64_##op##_return_relaxed(long long i, atomic64_t *v) \
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100300{ \
301 long long result; \
302 unsigned long tmp; \
303 \
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100304 prefetchw(&v->counter); \
305 \
306 __asm__ __volatile__("@ atomic64_" #op "_return\n" \
307"1: ldrexd %0, %H0, [%3]\n" \
308" " #op1 " %Q0, %Q0, %Q4\n" \
309" " #op2 " %R0, %R0, %R4\n" \
310" strexd %1, %0, %H0, [%3]\n" \
311" teq %1, #0\n" \
312" bne 1b" \
313 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter) \
314 : "r" (&v->counter), "r" (i) \
315 : "cc"); \
316 \
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100317 return result; \
Will Deacon24b44a62010-01-20 19:05:07 +0100318}
319
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100320#define ATOMIC64_OPS(op, op1, op2) \
321 ATOMIC64_OP(op, op1, op2) \
322 ATOMIC64_OP_RETURN(op, op1, op2)
Will Deacon24b44a62010-01-20 19:05:07 +0100323
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100324ATOMIC64_OPS(add, adds, adc)
325ATOMIC64_OPS(sub, subs, sbc)
Will Deacon24b44a62010-01-20 19:05:07 +0100326
Will Deacon0ca326d2015-08-06 17:54:44 +0100327#define atomic64_add_return_relaxed atomic64_add_return_relaxed
328#define atomic64_sub_return_relaxed atomic64_sub_return_relaxed
329
Peter Zijlstra12589792014-04-23 20:04:39 +0200330#define atomic64_andnot atomic64_andnot
331
332ATOMIC64_OP(and, and, and)
333ATOMIC64_OP(andnot, bic, bic)
334ATOMIC64_OP(or, orr, orr)
335ATOMIC64_OP(xor, eor, eor)
336
Peter Zijlstraaee9a552014-03-23 16:38:18 +0100337#undef ATOMIC64_OPS
338#undef ATOMIC64_OP_RETURN
339#undef ATOMIC64_OP
Will Deacon24b44a62010-01-20 19:05:07 +0100340
Will Deacon0ca326d2015-08-06 17:54:44 +0100341static inline long long
342atomic64_cmpxchg_relaxed(atomic64_t *ptr, long long old, long long new)
Will Deacon24b44a62010-01-20 19:05:07 +0100343{
Chen Gang237f1232013-10-26 15:07:04 +0100344 long long oldval;
Will Deacon24b44a62010-01-20 19:05:07 +0100345 unsigned long res;
346
Will Deaconc32ffce2014-02-21 17:01:48 +0100347 prefetchw(&ptr->counter);
Will Deacon24b44a62010-01-20 19:05:07 +0100348
349 do {
350 __asm__ __volatile__("@ atomic64_cmpxchg\n"
Will Deacon398aa662010-07-08 10:59:16 +0100351 "ldrexd %1, %H1, [%3]\n"
Will Deacon24b44a62010-01-20 19:05:07 +0100352 "mov %0, #0\n"
Will Deacon398aa662010-07-08 10:59:16 +0100353 "teq %1, %4\n"
354 "teqeq %H1, %H4\n"
355 "strexdeq %0, %5, %H5, [%3]"
356 : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
Will Deacon24b44a62010-01-20 19:05:07 +0100357 : "r" (&ptr->counter), "r" (old), "r" (new)
358 : "cc");
359 } while (res);
360
Will Deacon24b44a62010-01-20 19:05:07 +0100361 return oldval;
362}
Will Deacon0ca326d2015-08-06 17:54:44 +0100363#define atomic64_cmpxchg_relaxed atomic64_cmpxchg_relaxed
Will Deacon24b44a62010-01-20 19:05:07 +0100364
Will Deacon0ca326d2015-08-06 17:54:44 +0100365static inline long long atomic64_xchg_relaxed(atomic64_t *ptr, long long new)
Will Deacon24b44a62010-01-20 19:05:07 +0100366{
Chen Gang237f1232013-10-26 15:07:04 +0100367 long long result;
Will Deacon24b44a62010-01-20 19:05:07 +0100368 unsigned long tmp;
369
Will Deaconc32ffce2014-02-21 17:01:48 +0100370 prefetchw(&ptr->counter);
Will Deacon24b44a62010-01-20 19:05:07 +0100371
372 __asm__ __volatile__("@ atomic64_xchg\n"
Will Deacon398aa662010-07-08 10:59:16 +0100373"1: ldrexd %0, %H0, [%3]\n"
374" strexd %1, %4, %H4, [%3]\n"
Will Deacon24b44a62010-01-20 19:05:07 +0100375" teq %1, #0\n"
376" bne 1b"
Will Deacon398aa662010-07-08 10:59:16 +0100377 : "=&r" (result), "=&r" (tmp), "+Qo" (ptr->counter)
Will Deacon24b44a62010-01-20 19:05:07 +0100378 : "r" (&ptr->counter), "r" (new)
379 : "cc");
380
Will Deacon24b44a62010-01-20 19:05:07 +0100381 return result;
382}
Will Deacon0ca326d2015-08-06 17:54:44 +0100383#define atomic64_xchg_relaxed atomic64_xchg_relaxed
Will Deacon24b44a62010-01-20 19:05:07 +0100384
Chen Gang237f1232013-10-26 15:07:04 +0100385static inline long long atomic64_dec_if_positive(atomic64_t *v)
Will Deacon24b44a62010-01-20 19:05:07 +0100386{
Chen Gang237f1232013-10-26 15:07:04 +0100387 long long result;
Will Deacon24b44a62010-01-20 19:05:07 +0100388 unsigned long tmp;
389
390 smp_mb();
Will Deaconc32ffce2014-02-21 17:01:48 +0100391 prefetchw(&v->counter);
Will Deacon24b44a62010-01-20 19:05:07 +0100392
393 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
Will Deacon398aa662010-07-08 10:59:16 +0100394"1: ldrexd %0, %H0, [%3]\n"
Victor Kamensky2245f922013-07-26 09:28:53 -0700395" subs %Q0, %Q0, #1\n"
396" sbc %R0, %R0, #0\n"
397" teq %R0, #0\n"
Will Deacon24b44a62010-01-20 19:05:07 +0100398" bmi 2f\n"
Will Deacon398aa662010-07-08 10:59:16 +0100399" strexd %1, %0, %H0, [%3]\n"
Will Deacon24b44a62010-01-20 19:05:07 +0100400" teq %1, #0\n"
401" bne 1b\n"
402"2:"
Will Deacon398aa662010-07-08 10:59:16 +0100403 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
Will Deacon24b44a62010-01-20 19:05:07 +0100404 : "r" (&v->counter)
405 : "cc");
406
407 smp_mb();
408
409 return result;
410}
411
Chen Gang237f1232013-10-26 15:07:04 +0100412static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
Will Deacon24b44a62010-01-20 19:05:07 +0100413{
Chen Gang237f1232013-10-26 15:07:04 +0100414 long long val;
Will Deacon24b44a62010-01-20 19:05:07 +0100415 unsigned long tmp;
416 int ret = 1;
417
418 smp_mb();
Will Deaconc32ffce2014-02-21 17:01:48 +0100419 prefetchw(&v->counter);
Will Deacon24b44a62010-01-20 19:05:07 +0100420
421 __asm__ __volatile__("@ atomic64_add_unless\n"
Will Deacon398aa662010-07-08 10:59:16 +0100422"1: ldrexd %0, %H0, [%4]\n"
423" teq %0, %5\n"
424" teqeq %H0, %H5\n"
Will Deacon24b44a62010-01-20 19:05:07 +0100425" moveq %1, #0\n"
426" beq 2f\n"
Victor Kamensky2245f922013-07-26 09:28:53 -0700427" adds %Q0, %Q0, %Q6\n"
428" adc %R0, %R0, %R6\n"
Will Deacon398aa662010-07-08 10:59:16 +0100429" strexd %2, %0, %H0, [%4]\n"
Will Deacon24b44a62010-01-20 19:05:07 +0100430" teq %2, #0\n"
431" bne 1b\n"
432"2:"
Will Deacon398aa662010-07-08 10:59:16 +0100433 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
Will Deacon24b44a62010-01-20 19:05:07 +0100434 : "r" (&v->counter), "r" (u), "r" (a)
435 : "cc");
436
437 if (ret)
438 smp_mb();
439
440 return ret;
441}
442
443#define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
444#define atomic64_inc(v) atomic64_add(1LL, (v))
445#define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
446#define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
447#define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
448#define atomic64_dec(v) atomic64_sub(1LL, (v))
449#define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
450#define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
451#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
452
Arun Sharma78477772011-07-26 16:09:08 -0700453#endif /* !CONFIG_GENERIC_ATOMIC64 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454#endif
455#endif