Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Maciej W. Rozycki | edf7b93 | 2013-11-01 23:47:05 +0000 | [diff] [blame] | 2 | * Atomic operations that C can't guarantee us. Useful for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * resource counting etc.. |
| 4 | * |
| 5 | * But use these as seldom as possible since they are much more slower |
| 6 | * than regular operations. |
| 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License. See the file "COPYING" in the main directory of this archive |
| 10 | * for more details. |
| 11 | * |
Ralf Baechle | e303e08 | 2006-11-30 01:14:50 +0000 | [diff] [blame] | 12 | * Copyright (C) 1996, 97, 99, 2000, 03, 04, 06 by Ralf Baechle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #ifndef _ASM_ATOMIC_H |
| 15 | #define _ASM_ATOMIC_H |
| 16 | |
Ralf Baechle | 192ef36 | 2006-07-07 14:07:18 +0100 | [diff] [blame] | 17 | #include <linux/irqflags.h> |
Matthew Wilcox | ea435467 | 2009-01-06 14:40:39 -0800 | [diff] [blame] | 18 | #include <linux/types.h> |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 19 | #include <asm/barrier.h> |
Maciej W. Rozycki | b0984c4 | 2014-11-15 22:08:48 +0000 | [diff] [blame] | 20 | #include <asm/compiler.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/cpu-features.h> |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 22 | #include <asm/cmpxchg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <asm/war.h> |
| 24 | |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 25 | /* |
| 26 | * Using a branch-likely instruction to check the result of an sc instruction |
| 27 | * works around a bug present in R10000 CPUs prior to revision 3.0 that could |
| 28 | * cause ll-sc sequences to execute non-atomically. |
| 29 | */ |
| 30 | #if R10000_LLSC_WAR |
| 31 | # define __scbeqz "beqzl" |
| 32 | #else |
| 33 | # define __scbeqz "beqz" |
| 34 | #endif |
| 35 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 36 | #define ATOMIC_INIT(i) { (i) } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * atomic_read - read atomic variable |
| 40 | * @v: pointer of type atomic_t |
| 41 | * |
| 42 | * Atomically reads the value of @v. |
| 43 | */ |
Peter Zijlstra | 62e8a32 | 2015-09-18 11:13:10 +0200 | [diff] [blame] | 44 | #define atomic_read(v) READ_ONCE((v)->counter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
| 47 | * atomic_set - set atomic variable |
| 48 | * @v: pointer of type atomic_t |
| 49 | * @i: required value |
| 50 | * |
| 51 | * Atomically sets the value of @v to @i. |
| 52 | */ |
Peter Zijlstra | 62e8a32 | 2015-09-18 11:13:10 +0200 | [diff] [blame] | 53 | #define atomic_set(v, i) WRITE_ONCE((v)->counter, (i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 55 | #define ATOMIC_OP(op, c_op, asm_op) \ |
| 56 | static __inline__ void atomic_##op(int i, atomic_t * v) \ |
| 57 | { \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 58 | if (kernel_uses_llsc) { \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 59 | int temp; \ |
| 60 | \ |
| 61 | __asm__ __volatile__( \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 62 | " .set "MIPS_ISA_LEVEL" \n" \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 63 | "1: ll %0, %1 # atomic_" #op " \n" \ |
| 64 | " " #asm_op " %0, %2 \n" \ |
| 65 | " sc %0, %1 \n" \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 66 | "\t" __scbeqz " %0, 1b \n" \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 67 | " .set mips0 \n" \ |
Markos Chandras | 94bfb75 | 2015-01-26 12:44:11 +0000 | [diff] [blame] | 68 | : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 69 | : "Ir" (i)); \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 70 | } else { \ |
| 71 | unsigned long flags; \ |
| 72 | \ |
| 73 | raw_local_irq_save(flags); \ |
| 74 | v->counter c_op i; \ |
| 75 | raw_local_irq_restore(flags); \ |
| 76 | } \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 79 | #define ATOMIC_OP_RETURN(op, c_op, asm_op) \ |
Peter Zijlstra | 4ec4585 | 2016-04-18 01:15:25 +0200 | [diff] [blame] | 80 | static __inline__ int atomic_##op##_return_relaxed(int i, atomic_t * v) \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 81 | { \ |
| 82 | int result; \ |
| 83 | \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 84 | if (kernel_uses_llsc) { \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 85 | int temp; \ |
| 86 | \ |
| 87 | __asm__ __volatile__( \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 88 | " .set "MIPS_ISA_LEVEL" \n" \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 89 | "1: ll %1, %2 # atomic_" #op "_return \n" \ |
| 90 | " " #asm_op " %0, %1, %3 \n" \ |
| 91 | " sc %0, %2 \n" \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 92 | "\t" __scbeqz " %0, 1b \n" \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 93 | " " #asm_op " %0, %1, %3 \n" \ |
| 94 | " .set mips0 \n" \ |
| 95 | : "=&r" (result), "=&r" (temp), \ |
Markos Chandras | 94bfb75 | 2015-01-26 12:44:11 +0000 | [diff] [blame] | 96 | "+" GCC_OFF_SMALL_ASM() (v->counter) \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 97 | : "Ir" (i)); \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 98 | } else { \ |
| 99 | unsigned long flags; \ |
| 100 | \ |
| 101 | raw_local_irq_save(flags); \ |
| 102 | result = v->counter; \ |
| 103 | result c_op i; \ |
| 104 | v->counter = result; \ |
| 105 | raw_local_irq_restore(flags); \ |
| 106 | } \ |
| 107 | \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 108 | return result; \ |
| 109 | } |
| 110 | |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 111 | #define ATOMIC_FETCH_OP(op, c_op, asm_op) \ |
Peter Zijlstra | 4ec4585 | 2016-04-18 01:15:25 +0200 | [diff] [blame] | 112 | static __inline__ int atomic_fetch_##op##_relaxed(int i, atomic_t * v) \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 113 | { \ |
| 114 | int result; \ |
| 115 | \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 116 | if (kernel_uses_llsc) { \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 117 | int temp; \ |
| 118 | \ |
| 119 | __asm__ __volatile__( \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 120 | " .set "MIPS_ISA_LEVEL" \n" \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 121 | "1: ll %1, %2 # atomic_fetch_" #op " \n" \ |
| 122 | " " #asm_op " %0, %1, %3 \n" \ |
| 123 | " sc %0, %2 \n" \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 124 | "\t" __scbeqz " %0, 1b \n" \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 125 | " move %0, %1 \n" \ |
| 126 | " .set mips0 \n" \ |
| 127 | : "=&r" (result), "=&r" (temp), \ |
| 128 | "+" GCC_OFF_SMALL_ASM() (v->counter) \ |
| 129 | : "Ir" (i)); \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 130 | } else { \ |
| 131 | unsigned long flags; \ |
| 132 | \ |
| 133 | raw_local_irq_save(flags); \ |
| 134 | result = v->counter; \ |
| 135 | v->counter c_op i; \ |
| 136 | raw_local_irq_restore(flags); \ |
| 137 | } \ |
| 138 | \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 139 | return result; \ |
| 140 | } |
| 141 | |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 142 | #define ATOMIC_OPS(op, c_op, asm_op) \ |
| 143 | ATOMIC_OP(op, c_op, asm_op) \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 144 | ATOMIC_OP_RETURN(op, c_op, asm_op) \ |
| 145 | ATOMIC_FETCH_OP(op, c_op, asm_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Peter Zijlstra | ef31563 | 2014-03-26 17:56:43 +0100 | [diff] [blame] | 147 | ATOMIC_OPS(add, +=, addu) |
| 148 | ATOMIC_OPS(sub, -=, subu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Peter Zijlstra | 4ec4585 | 2016-04-18 01:15:25 +0200 | [diff] [blame] | 150 | #define atomic_add_return_relaxed atomic_add_return_relaxed |
| 151 | #define atomic_sub_return_relaxed atomic_sub_return_relaxed |
| 152 | #define atomic_fetch_add_relaxed atomic_fetch_add_relaxed |
| 153 | #define atomic_fetch_sub_relaxed atomic_fetch_sub_relaxed |
| 154 | |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 155 | #undef ATOMIC_OPS |
| 156 | #define ATOMIC_OPS(op, c_op, asm_op) \ |
| 157 | ATOMIC_OP(op, c_op, asm_op) \ |
| 158 | ATOMIC_FETCH_OP(op, c_op, asm_op) |
| 159 | |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 160 | ATOMIC_OPS(and, &=, and) |
| 161 | ATOMIC_OPS(or, |=, or) |
| 162 | ATOMIC_OPS(xor, ^=, xor) |
Peter Zijlstra | 27782f2 | 2014-04-23 19:51:36 +0200 | [diff] [blame] | 163 | |
Peter Zijlstra | 4ec4585 | 2016-04-18 01:15:25 +0200 | [diff] [blame] | 164 | #define atomic_fetch_and_relaxed atomic_fetch_and_relaxed |
| 165 | #define atomic_fetch_or_relaxed atomic_fetch_or_relaxed |
| 166 | #define atomic_fetch_xor_relaxed atomic_fetch_xor_relaxed |
| 167 | |
Peter Zijlstra | ef31563 | 2014-03-26 17:56:43 +0100 | [diff] [blame] | 168 | #undef ATOMIC_OPS |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 169 | #undef ATOMIC_FETCH_OP |
Peter Zijlstra | ef31563 | 2014-03-26 17:56:43 +0100 | [diff] [blame] | 170 | #undef ATOMIC_OP_RETURN |
| 171 | #undef ATOMIC_OP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | /* |
Arnaud Giersch | f10d14d | 2005-11-13 00:38:18 +0100 | [diff] [blame] | 174 | * atomic_sub_if_positive - conditionally subtract integer from atomic variable |
| 175 | * @i: integer value to subtract |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | * @v: pointer of type atomic_t |
| 177 | * |
Arnaud Giersch | f10d14d | 2005-11-13 00:38:18 +0100 | [diff] [blame] | 178 | * Atomically test @v and subtract @i if @v is greater or equal than @i. |
| 179 | * The function returns the old value of @v minus @i. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | */ |
| 181 | static __inline__ int atomic_sub_if_positive(int i, atomic_t * v) |
| 182 | { |
Ralf Baechle | 915ec1e | 2009-01-12 00:52:18 +0000 | [diff] [blame] | 183 | int result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
David Daney | f252ffd | 2010-01-08 17:17:43 -0800 | [diff] [blame] | 185 | smp_mb__before_llsc(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 186 | |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 187 | if (kernel_uses_llsc) { |
Ralf Baechle | 915ec1e | 2009-01-12 00:52:18 +0000 | [diff] [blame] | 188 | int temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | |
| 190 | __asm__ __volatile__( |
Markos Chandras | 0038df2 | 2015-01-06 11:09:24 +0000 | [diff] [blame] | 191 | " .set "MIPS_ISA_LEVEL" \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | "1: ll %1, %2 # atomic_sub_if_positive\n" |
| 193 | " subu %0, %1, %3 \n" |
Joshua Kinard | a0a5ac3 | 2017-11-18 22:29:56 -0500 | [diff] [blame] | 194 | " move %1, %0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | " bltz %0, 1f \n" |
Joshua Kinard | a0a5ac3 | 2017-11-18 22:29:56 -0500 | [diff] [blame] | 196 | " sc %1, %2 \n" |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 197 | "\t" __scbeqz " %1, 1b \n" |
Ralf Baechle | 5095202 | 2008-07-03 23:28:35 +0100 | [diff] [blame] | 198 | "1: \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 199 | " .set mips0 \n" |
Maciej W. Rozycki | b0984c4 | 2014-11-15 22:08:48 +0000 | [diff] [blame] | 200 | : "=&r" (result), "=&r" (temp), |
Markos Chandras | 94bfb75 | 2015-01-26 12:44:11 +0000 | [diff] [blame] | 201 | "+" GCC_OFF_SMALL_ASM() (v->counter) |
Joshua Kinard | b4f2a17 | 2012-06-24 21:01:34 -0400 | [diff] [blame] | 202 | : "Ir" (i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } else { |
| 204 | unsigned long flags; |
| 205 | |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 206 | raw_local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | result = v->counter; |
| 208 | result -= i; |
| 209 | if (result >= 0) |
| 210 | v->counter = result; |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 211 | raw_local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame] | 214 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | return result; |
| 217 | } |
| 218 | |
Mathieu Desnoyers | e12f644 | 2007-05-08 00:34:24 -0700 | [diff] [blame] | 219 | #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n))) |
| 220 | #define atomic_xchg(v, new) (xchg(&((v)->counter), (new))) |
Nick Piggin | 4a6dae6 | 2005-11-13 16:07:24 -0800 | [diff] [blame] | 221 | |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 222 | /** |
Arun Sharma | f24219b | 2011-07-26 16:09:07 -0700 | [diff] [blame] | 223 | * __atomic_add_unless - add unless the number is a given value |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 224 | * @v: pointer of type atomic_t |
| 225 | * @a: the amount to add to v... |
| 226 | * @u: ...unless v is equal to u. |
| 227 | * |
| 228 | * Atomically adds @a to @v, so long as it was not @u. |
Arun Sharma | f24219b | 2011-07-26 16:09:07 -0700 | [diff] [blame] | 229 | * Returns the old value of @v. |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 230 | */ |
Arun Sharma | f24219b | 2011-07-26 16:09:07 -0700 | [diff] [blame] | 231 | static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u) |
Mathieu Desnoyers | 2856f5e | 2007-05-08 00:34:38 -0700 | [diff] [blame] | 232 | { |
| 233 | int c, old; |
| 234 | c = atomic_read(v); |
| 235 | for (;;) { |
| 236 | if (unlikely(c == (u))) |
| 237 | break; |
| 238 | old = atomic_cmpxchg((v), c, c + (a)); |
| 239 | if (likely(old == c)) |
| 240 | break; |
| 241 | c = old; |
| 242 | } |
Arun Sharma | f24219b | 2011-07-26 16:09:07 -0700 | [diff] [blame] | 243 | return c; |
Mathieu Desnoyers | 2856f5e | 2007-05-08 00:34:38 -0700 | [diff] [blame] | 244 | } |
Nick Piggin | 8426e1f | 2005-11-13 16:07:25 -0800 | [diff] [blame] | 245 | |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 246 | #define atomic_dec_return(v) atomic_sub_return(1, (v)) |
| 247 | #define atomic_inc_return(v) atomic_add_return(1, (v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | /* |
| 250 | * atomic_sub_and_test - subtract value from variable and test result |
| 251 | * @i: integer value to subtract |
| 252 | * @v: pointer of type atomic_t |
| 253 | * |
| 254 | * Atomically subtracts @i from @v and returns |
| 255 | * true if the result is zero, or false for all |
| 256 | * other cases. |
| 257 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 258 | #define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
| 260 | /* |
| 261 | * atomic_inc_and_test - increment and test |
| 262 | * @v: pointer of type atomic_t |
| 263 | * |
| 264 | * Atomically increments @v by 1 |
| 265 | * and returns true if the result is zero, or false for all |
| 266 | * other cases. |
| 267 | */ |
| 268 | #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0) |
| 269 | |
| 270 | /* |
| 271 | * atomic_dec_and_test - decrement by 1 and test |
| 272 | * @v: pointer of type atomic_t |
| 273 | * |
| 274 | * Atomically decrements @v by 1 and |
| 275 | * returns true if the result is 0, or false for all other |
| 276 | * cases. |
| 277 | */ |
| 278 | #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0) |
| 279 | |
| 280 | /* |
| 281 | * atomic_dec_if_positive - decrement by 1 if old value positive |
| 282 | * @v: pointer of type atomic_t |
| 283 | */ |
| 284 | #define atomic_dec_if_positive(v) atomic_sub_if_positive(1, v) |
| 285 | |
| 286 | /* |
| 287 | * atomic_inc - increment atomic variable |
| 288 | * @v: pointer of type atomic_t |
| 289 | * |
| 290 | * Atomically increments @v by 1. |
| 291 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 292 | #define atomic_inc(v) atomic_add(1, (v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * atomic_dec - decrement and test |
| 296 | * @v: pointer of type atomic_t |
| 297 | * |
| 298 | * Atomically decrements @v by 1. |
| 299 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 300 | #define atomic_dec(v) atomic_sub(1, (v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * atomic_add_negative - add and test if negative |
| 304 | * @v: pointer of type atomic_t |
| 305 | * @i: integer value to add |
| 306 | * |
| 307 | * Atomically adds @i to @v and returns true |
| 308 | * if the result is negative, or false when |
| 309 | * result is greater than or equal to zero. |
| 310 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 311 | #define atomic_add_negative(i, v) (atomic_add_return(i, (v)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 313 | #ifdef CONFIG_64BIT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | #define ATOMIC64_INIT(i) { (i) } |
| 316 | |
| 317 | /* |
| 318 | * atomic64_read - read atomic variable |
| 319 | * @v: pointer of type atomic64_t |
| 320 | * |
| 321 | */ |
Peter Zijlstra | 62e8a32 | 2015-09-18 11:13:10 +0200 | [diff] [blame] | 322 | #define atomic64_read(v) READ_ONCE((v)->counter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * atomic64_set - set atomic variable |
| 326 | * @v: pointer of type atomic64_t |
| 327 | * @i: required value |
| 328 | */ |
Peter Zijlstra | 62e8a32 | 2015-09-18 11:13:10 +0200 | [diff] [blame] | 329 | #define atomic64_set(v, i) WRITE_ONCE((v)->counter, (i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 331 | #define ATOMIC64_OP(op, c_op, asm_op) \ |
| 332 | static __inline__ void atomic64_##op(long i, atomic64_t * v) \ |
| 333 | { \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 334 | if (kernel_uses_llsc) { \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 335 | long temp; \ |
| 336 | \ |
| 337 | __asm__ __volatile__( \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 338 | " .set "MIPS_ISA_LEVEL" \n" \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 339 | "1: lld %0, %1 # atomic64_" #op " \n" \ |
| 340 | " " #asm_op " %0, %2 \n" \ |
| 341 | " scd %0, %1 \n" \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 342 | "\t" __scbeqz " %0, 1b \n" \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 343 | " .set mips0 \n" \ |
Markos Chandras | 94bfb75 | 2015-01-26 12:44:11 +0000 | [diff] [blame] | 344 | : "=&r" (temp), "+" GCC_OFF_SMALL_ASM() (v->counter) \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 345 | : "Ir" (i)); \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 346 | } else { \ |
| 347 | unsigned long flags; \ |
| 348 | \ |
| 349 | raw_local_irq_save(flags); \ |
| 350 | v->counter c_op i; \ |
| 351 | raw_local_irq_restore(flags); \ |
| 352 | } \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 355 | #define ATOMIC64_OP_RETURN(op, c_op, asm_op) \ |
Peter Zijlstra | 4ec4585 | 2016-04-18 01:15:25 +0200 | [diff] [blame] | 356 | static __inline__ long atomic64_##op##_return_relaxed(long i, atomic64_t * v) \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 357 | { \ |
| 358 | long result; \ |
| 359 | \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 360 | if (kernel_uses_llsc) { \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 361 | long temp; \ |
| 362 | \ |
| 363 | __asm__ __volatile__( \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 364 | " .set "MIPS_ISA_LEVEL" \n" \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 365 | "1: lld %1, %2 # atomic64_" #op "_return\n" \ |
| 366 | " " #asm_op " %0, %1, %3 \n" \ |
| 367 | " scd %0, %2 \n" \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 368 | "\t" __scbeqz " %0, 1b \n" \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 369 | " " #asm_op " %0, %1, %3 \n" \ |
| 370 | " .set mips0 \n" \ |
| 371 | : "=&r" (result), "=&r" (temp), \ |
Markos Chandras | 94bfb75 | 2015-01-26 12:44:11 +0000 | [diff] [blame] | 372 | "+" GCC_OFF_SMALL_ASM() (v->counter) \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 373 | : "Ir" (i)); \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 374 | } else { \ |
| 375 | unsigned long flags; \ |
| 376 | \ |
| 377 | raw_local_irq_save(flags); \ |
| 378 | result = v->counter; \ |
| 379 | result c_op i; \ |
| 380 | v->counter = result; \ |
| 381 | raw_local_irq_restore(flags); \ |
| 382 | } \ |
| 383 | \ |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 384 | return result; \ |
| 385 | } |
| 386 | |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 387 | #define ATOMIC64_FETCH_OP(op, c_op, asm_op) \ |
Peter Zijlstra | 4ec4585 | 2016-04-18 01:15:25 +0200 | [diff] [blame] | 388 | static __inline__ long atomic64_fetch_##op##_relaxed(long i, atomic64_t * v) \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 389 | { \ |
| 390 | long result; \ |
| 391 | \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 392 | if (kernel_uses_llsc && R10000_LLSC_WAR) { \ |
| 393 | long temp; \ |
| 394 | \ |
| 395 | __asm__ __volatile__( \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 396 | " .set "MIPS_ISA_LEVEL" \n" \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 397 | "1: lld %1, %2 # atomic64_fetch_" #op "\n" \ |
| 398 | " " #asm_op " %0, %1, %3 \n" \ |
| 399 | " scd %0, %2 \n" \ |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 400 | "\t" __scbeqz " %0, 1b \n" \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 401 | " move %0, %1 \n" \ |
| 402 | " .set mips0 \n" \ |
| 403 | : "=&r" (result), "=&r" (temp), \ |
| 404 | "+" GCC_OFF_SMALL_ASM() (v->counter) \ |
| 405 | : "Ir" (i)); \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 406 | } else { \ |
| 407 | unsigned long flags; \ |
| 408 | \ |
| 409 | raw_local_irq_save(flags); \ |
| 410 | result = v->counter; \ |
| 411 | v->counter c_op i; \ |
| 412 | raw_local_irq_restore(flags); \ |
| 413 | } \ |
| 414 | \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 415 | return result; \ |
| 416 | } |
| 417 | |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 418 | #define ATOMIC64_OPS(op, c_op, asm_op) \ |
| 419 | ATOMIC64_OP(op, c_op, asm_op) \ |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 420 | ATOMIC64_OP_RETURN(op, c_op, asm_op) \ |
| 421 | ATOMIC64_FETCH_OP(op, c_op, asm_op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Peter Zijlstra | ef31563 | 2014-03-26 17:56:43 +0100 | [diff] [blame] | 423 | ATOMIC64_OPS(add, +=, daddu) |
| 424 | ATOMIC64_OPS(sub, -=, dsubu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Peter Zijlstra | 4ec4585 | 2016-04-18 01:15:25 +0200 | [diff] [blame] | 426 | #define atomic64_add_return_relaxed atomic64_add_return_relaxed |
| 427 | #define atomic64_sub_return_relaxed atomic64_sub_return_relaxed |
| 428 | #define atomic64_fetch_add_relaxed atomic64_fetch_add_relaxed |
| 429 | #define atomic64_fetch_sub_relaxed atomic64_fetch_sub_relaxed |
| 430 | |
Peter Zijlstra | ef31563 | 2014-03-26 17:56:43 +0100 | [diff] [blame] | 431 | #undef ATOMIC64_OPS |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 432 | #define ATOMIC64_OPS(op, c_op, asm_op) \ |
| 433 | ATOMIC64_OP(op, c_op, asm_op) \ |
| 434 | ATOMIC64_FETCH_OP(op, c_op, asm_op) |
| 435 | |
| 436 | ATOMIC64_OPS(and, &=, and) |
| 437 | ATOMIC64_OPS(or, |=, or) |
| 438 | ATOMIC64_OPS(xor, ^=, xor) |
| 439 | |
Peter Zijlstra | 4ec4585 | 2016-04-18 01:15:25 +0200 | [diff] [blame] | 440 | #define atomic64_fetch_and_relaxed atomic64_fetch_and_relaxed |
| 441 | #define atomic64_fetch_or_relaxed atomic64_fetch_or_relaxed |
| 442 | #define atomic64_fetch_xor_relaxed atomic64_fetch_xor_relaxed |
| 443 | |
Peter Zijlstra | 4edac52 | 2016-04-18 01:16:06 +0200 | [diff] [blame] | 444 | #undef ATOMIC64_OPS |
| 445 | #undef ATOMIC64_FETCH_OP |
Peter Zijlstra | ef31563 | 2014-03-26 17:56:43 +0100 | [diff] [blame] | 446 | #undef ATOMIC64_OP_RETURN |
| 447 | #undef ATOMIC64_OP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | /* |
Maciej W. Rozycki | ddb3108 | 2014-11-15 22:09:54 +0000 | [diff] [blame] | 450 | * atomic64_sub_if_positive - conditionally subtract integer from atomic |
| 451 | * variable |
Arnaud Giersch | f10d14d | 2005-11-13 00:38:18 +0100 | [diff] [blame] | 452 | * @i: integer value to subtract |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | * @v: pointer of type atomic64_t |
| 454 | * |
Arnaud Giersch | f10d14d | 2005-11-13 00:38:18 +0100 | [diff] [blame] | 455 | * Atomically test @v and subtract @i if @v is greater or equal than @i. |
| 456 | * The function returns the old value of @v minus @i. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | */ |
| 458 | static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v) |
| 459 | { |
Ralf Baechle | 915ec1e | 2009-01-12 00:52:18 +0000 | [diff] [blame] | 460 | long result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | |
David Daney | f252ffd | 2010-01-08 17:17:43 -0800 | [diff] [blame] | 462 | smp_mb__before_llsc(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 463 | |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 464 | if (kernel_uses_llsc) { |
Ralf Baechle | 915ec1e | 2009-01-12 00:52:18 +0000 | [diff] [blame] | 465 | long temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | __asm__ __volatile__( |
Markos Chandras | 0038df2 | 2015-01-06 11:09:24 +0000 | [diff] [blame] | 468 | " .set "MIPS_ISA_LEVEL" \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | "1: lld %1, %2 # atomic64_sub_if_positive\n" |
| 470 | " dsubu %0, %1, %3 \n" |
Joshua Kinard | a0a5ac3 | 2017-11-18 22:29:56 -0500 | [diff] [blame] | 471 | " move %1, %0 \n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | " bltz %0, 1f \n" |
Joshua Kinard | a0a5ac3 | 2017-11-18 22:29:56 -0500 | [diff] [blame] | 473 | " scd %1, %2 \n" |
Joshua Kinard | 4936084 | 2017-11-18 23:00:51 -0500 | [diff] [blame^] | 474 | "\t" __scbeqz " %1, 1b \n" |
Ralf Baechle | 5095202 | 2008-07-03 23:28:35 +0100 | [diff] [blame] | 475 | "1: \n" |
Maciej W. Rozycki | aac8aa7 | 2005-06-14 17:35:03 +0000 | [diff] [blame] | 476 | " .set mips0 \n" |
Maciej W. Rozycki | b0984c4 | 2014-11-15 22:08:48 +0000 | [diff] [blame] | 477 | : "=&r" (result), "=&r" (temp), |
Markos Chandras | 94bfb75 | 2015-01-26 12:44:11 +0000 | [diff] [blame] | 478 | "+" GCC_OFF_SMALL_ASM() (v->counter) |
Joshua Kinard | b4f2a17 | 2012-06-24 21:01:34 -0400 | [diff] [blame] | 479 | : "Ir" (i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } else { |
| 481 | unsigned long flags; |
| 482 | |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 483 | raw_local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | result = v->counter; |
| 485 | result -= i; |
| 486 | if (result >= 0) |
| 487 | v->counter = result; |
Ralf Baechle | 49edd09 | 2007-03-16 16:10:36 +0000 | [diff] [blame] | 488 | raw_local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Ralf Baechle | 17099b1 | 2007-07-14 13:24:05 +0100 | [diff] [blame] | 491 | smp_llsc_mb(); |
Ralf Baechle | 0004a9d | 2006-10-31 03:45:07 +0000 | [diff] [blame] | 492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | return result; |
| 494 | } |
| 495 | |
Mathieu Desnoyers | e12f644 | 2007-05-08 00:34:24 -0700 | [diff] [blame] | 496 | #define atomic64_cmpxchg(v, o, n) \ |
Atsushi Nemoto | 7b239bb | 2007-05-10 23:47:45 +0900 | [diff] [blame] | 497 | ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n))) |
Mathieu Desnoyers | e12f644 | 2007-05-08 00:34:24 -0700 | [diff] [blame] | 498 | #define atomic64_xchg(v, new) (xchg(&((v)->counter), (new))) |
| 499 | |
| 500 | /** |
| 501 | * atomic64_add_unless - add unless the number is a given value |
| 502 | * @v: pointer of type atomic64_t |
| 503 | * @a: the amount to add to v... |
| 504 | * @u: ...unless v is equal to u. |
| 505 | * |
| 506 | * Atomically adds @a to @v, so long as it was not @u. |
Ralf Baechle | f25319d | 2015-10-16 23:09:57 +0200 | [diff] [blame] | 507 | * Returns true iff @v was not @u. |
Mathieu Desnoyers | e12f644 | 2007-05-08 00:34:24 -0700 | [diff] [blame] | 508 | */ |
Mathieu Desnoyers | 2856f5e | 2007-05-08 00:34:38 -0700 | [diff] [blame] | 509 | static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u) |
| 510 | { |
| 511 | long c, old; |
| 512 | c = atomic64_read(v); |
| 513 | for (;;) { |
| 514 | if (unlikely(c == (u))) |
| 515 | break; |
| 516 | old = atomic64_cmpxchg((v), c, c + (a)); |
| 517 | if (likely(old == c)) |
| 518 | break; |
| 519 | c = old; |
| 520 | } |
| 521 | return c != (u); |
| 522 | } |
| 523 | |
Mathieu Desnoyers | e12f644 | 2007-05-08 00:34:24 -0700 | [diff] [blame] | 524 | #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0) |
| 525 | |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 526 | #define atomic64_dec_return(v) atomic64_sub_return(1, (v)) |
| 527 | #define atomic64_inc_return(v) atomic64_add_return(1, (v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | /* |
| 530 | * atomic64_sub_and_test - subtract value from variable and test result |
| 531 | * @i: integer value to subtract |
| 532 | * @v: pointer of type atomic64_t |
| 533 | * |
| 534 | * Atomically subtracts @i from @v and returns |
| 535 | * true if the result is zero, or false for all |
| 536 | * other cases. |
| 537 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 538 | #define atomic64_sub_and_test(i, v) (atomic64_sub_return((i), (v)) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
| 540 | /* |
| 541 | * atomic64_inc_and_test - increment and test |
| 542 | * @v: pointer of type atomic64_t |
| 543 | * |
| 544 | * Atomically increments @v by 1 |
| 545 | * and returns true if the result is zero, or false for all |
| 546 | * other cases. |
| 547 | */ |
| 548 | #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0) |
| 549 | |
| 550 | /* |
| 551 | * atomic64_dec_and_test - decrement by 1 and test |
| 552 | * @v: pointer of type atomic64_t |
| 553 | * |
| 554 | * Atomically decrements @v by 1 and |
| 555 | * returns true if the result is 0, or false for all other |
| 556 | * cases. |
| 557 | */ |
| 558 | #define atomic64_dec_and_test(v) (atomic64_sub_return(1, (v)) == 0) |
| 559 | |
| 560 | /* |
| 561 | * atomic64_dec_if_positive - decrement by 1 if old value positive |
| 562 | * @v: pointer of type atomic64_t |
| 563 | */ |
| 564 | #define atomic64_dec_if_positive(v) atomic64_sub_if_positive(1, v) |
| 565 | |
| 566 | /* |
| 567 | * atomic64_inc - increment atomic variable |
| 568 | * @v: pointer of type atomic64_t |
| 569 | * |
| 570 | * Atomically increments @v by 1. |
| 571 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 572 | #define atomic64_inc(v) atomic64_add(1, (v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
| 574 | /* |
| 575 | * atomic64_dec - decrement and test |
| 576 | * @v: pointer of type atomic64_t |
| 577 | * |
| 578 | * Atomically decrements @v by 1. |
| 579 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 580 | #define atomic64_dec(v) atomic64_sub(1, (v)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | /* |
| 583 | * atomic64_add_negative - add and test if negative |
| 584 | * @v: pointer of type atomic64_t |
| 585 | * @i: integer value to add |
| 586 | * |
| 587 | * Atomically adds @i to @v and returns true |
| 588 | * if the result is negative, or false when |
| 589 | * result is greater than or equal to zero. |
| 590 | */ |
Ralf Baechle | 21a151d | 2007-10-11 23:46:15 +0100 | [diff] [blame] | 591 | #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Ralf Baechle | 875d43e | 2005-09-03 15:56:16 -0700 | [diff] [blame] | 593 | #endif /* CONFIG_64BIT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | #endif /* _ASM_ATOMIC_H */ |