Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Paul Mackerras | 09d4e0e | 2009-06-12 21:10:05 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Generic implementation of 64-bit atomics using spinlocks, |
| 4 | * useful on processors that don't have 64-bit atomic instructions. |
| 5 | * |
| 6 | * Copyright © 2009 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com> |
Paul Mackerras | 09d4e0e | 2009-06-12 21:10:05 +0000 | [diff] [blame] | 7 | */ |
| 8 | #ifndef _ASM_GENERIC_ATOMIC64_H |
| 9 | #define _ASM_GENERIC_ATOMIC64_H |
Mark Rutland | ade5ef9 | 2018-06-21 13:13:07 +0100 | [diff] [blame] | 10 | #include <linux/types.h> |
Paul Mackerras | 09d4e0e | 2009-06-12 21:10:05 +0000 | [diff] [blame] | 11 | |
| 12 | typedef struct { |
Mark Rutland | 9255813 | 2019-05-22 14:22:35 +0100 | [diff] [blame] | 13 | s64 counter; |
Paul Mackerras | 09d4e0e | 2009-06-12 21:10:05 +0000 | [diff] [blame] | 14 | } atomic64_t; |
| 15 | |
| 16 | #define ATOMIC64_INIT(i) { (i) } |
| 17 | |
Mark Rutland | 9255813 | 2019-05-22 14:22:35 +0100 | [diff] [blame] | 18 | extern s64 atomic64_read(const atomic64_t *v); |
| 19 | extern void atomic64_set(atomic64_t *v, s64 i); |
Peter Zijlstra | 560cb12 | 2014-04-23 16:12:30 +0200 | [diff] [blame] | 20 | |
Peter Zijlstra | 9d664c0 | 2017-06-09 13:05:06 +0200 | [diff] [blame] | 21 | #define atomic64_set_release(v, i) atomic64_set((v), (i)) |
| 22 | |
Peter Zijlstra | 560cb12 | 2014-04-23 16:12:30 +0200 | [diff] [blame] | 23 | #define ATOMIC64_OP(op) \ |
Mark Rutland | 9255813 | 2019-05-22 14:22:35 +0100 | [diff] [blame] | 24 | extern void atomic64_##op(s64 a, atomic64_t *v); |
Peter Zijlstra | 560cb12 | 2014-04-23 16:12:30 +0200 | [diff] [blame] | 25 | |
| 26 | #define ATOMIC64_OP_RETURN(op) \ |
Mark Rutland | 9255813 | 2019-05-22 14:22:35 +0100 | [diff] [blame] | 27 | extern s64 atomic64_##op##_return(s64 a, atomic64_t *v); |
Peter Zijlstra | 560cb12 | 2014-04-23 16:12:30 +0200 | [diff] [blame] | 28 | |
Peter Zijlstra | 28aa2bd | 2016-04-18 00:54:38 +0200 | [diff] [blame] | 29 | #define ATOMIC64_FETCH_OP(op) \ |
Mark Rutland | 9255813 | 2019-05-22 14:22:35 +0100 | [diff] [blame] | 30 | extern s64 atomic64_fetch_##op(s64 a, atomic64_t *v); |
Peter Zijlstra | 28aa2bd | 2016-04-18 00:54:38 +0200 | [diff] [blame] | 31 | |
| 32 | #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op) ATOMIC64_FETCH_OP(op) |
Peter Zijlstra | 560cb12 | 2014-04-23 16:12:30 +0200 | [diff] [blame] | 33 | |
| 34 | ATOMIC64_OPS(add) |
| 35 | ATOMIC64_OPS(sub) |
| 36 | |
Peter Zijlstra | 28aa2bd | 2016-04-18 00:54:38 +0200 | [diff] [blame] | 37 | #undef ATOMIC64_OPS |
| 38 | #define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_FETCH_OP(op) |
| 39 | |
| 40 | ATOMIC64_OPS(and) |
| 41 | ATOMIC64_OPS(or) |
| 42 | ATOMIC64_OPS(xor) |
Peter Zijlstra | e6942b7 | 2014-04-23 19:32:50 +0200 | [diff] [blame] | 43 | |
Peter Zijlstra | 560cb12 | 2014-04-23 16:12:30 +0200 | [diff] [blame] | 44 | #undef ATOMIC64_OPS |
Peter Zijlstra | 28aa2bd | 2016-04-18 00:54:38 +0200 | [diff] [blame] | 45 | #undef ATOMIC64_FETCH_OP |
Peter Zijlstra | 560cb12 | 2014-04-23 16:12:30 +0200 | [diff] [blame] | 46 | #undef ATOMIC64_OP_RETURN |
| 47 | #undef ATOMIC64_OP |
| 48 | |
Mark Rutland | 9255813 | 2019-05-22 14:22:35 +0100 | [diff] [blame] | 49 | extern s64 atomic64_dec_if_positive(atomic64_t *v); |
Mark Rutland | b3a2a05 | 2018-06-21 13:13:20 +0100 | [diff] [blame] | 50 | #define atomic64_dec_if_positive atomic64_dec_if_positive |
Mark Rutland | 9255813 | 2019-05-22 14:22:35 +0100 | [diff] [blame] | 51 | extern s64 atomic64_cmpxchg(atomic64_t *v, s64 o, s64 n); |
| 52 | extern s64 atomic64_xchg(atomic64_t *v, s64 new); |
| 53 | extern s64 atomic64_fetch_add_unless(atomic64_t *v, s64 a, s64 u); |
Mark Rutland | 00b808a | 2018-06-21 13:13:11 +0100 | [diff] [blame] | 54 | #define atomic64_fetch_add_unless atomic64_fetch_add_unless |
Paul Mackerras | 09d4e0e | 2009-06-12 21:10:05 +0000 | [diff] [blame] | 55 | |
Paul Mackerras | 09d4e0e | 2009-06-12 21:10:05 +0000 | [diff] [blame] | 56 | #endif /* _ASM_GENERIC_ATOMIC64_H */ |