blob: 370f01d4450f52d18ab1736fe6a7af7b1c6d691f [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Paul Mackerras09d4e0e2009-06-12 21:10:05 +00002/*
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 Mackerras09d4e0e2009-06-12 21:10:05 +00007 */
8#ifndef _ASM_GENERIC_ATOMIC64_H
9#define _ASM_GENERIC_ATOMIC64_H
Mark Rutlandade5ef92018-06-21 13:13:07 +010010#include <linux/types.h>
Paul Mackerras09d4e0e2009-06-12 21:10:05 +000011
12typedef struct {
Mark Rutland92558132019-05-22 14:22:35 +010013 s64 counter;
Paul Mackerras09d4e0e2009-06-12 21:10:05 +000014} atomic64_t;
15
16#define ATOMIC64_INIT(i) { (i) }
17
Mark Rutland92558132019-05-22 14:22:35 +010018extern s64 atomic64_read(const atomic64_t *v);
19extern void atomic64_set(atomic64_t *v, s64 i);
Peter Zijlstra560cb122014-04-23 16:12:30 +020020
Peter Zijlstra9d664c02017-06-09 13:05:06 +020021#define atomic64_set_release(v, i) atomic64_set((v), (i))
22
Peter Zijlstra560cb122014-04-23 16:12:30 +020023#define ATOMIC64_OP(op) \
Mark Rutland92558132019-05-22 14:22:35 +010024extern void atomic64_##op(s64 a, atomic64_t *v);
Peter Zijlstra560cb122014-04-23 16:12:30 +020025
26#define ATOMIC64_OP_RETURN(op) \
Mark Rutland92558132019-05-22 14:22:35 +010027extern s64 atomic64_##op##_return(s64 a, atomic64_t *v);
Peter Zijlstra560cb122014-04-23 16:12:30 +020028
Peter Zijlstra28aa2bd2016-04-18 00:54:38 +020029#define ATOMIC64_FETCH_OP(op) \
Mark Rutland92558132019-05-22 14:22:35 +010030extern s64 atomic64_fetch_##op(s64 a, atomic64_t *v);
Peter Zijlstra28aa2bd2016-04-18 00:54:38 +020031
32#define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_OP_RETURN(op) ATOMIC64_FETCH_OP(op)
Peter Zijlstra560cb122014-04-23 16:12:30 +020033
34ATOMIC64_OPS(add)
35ATOMIC64_OPS(sub)
36
Peter Zijlstra28aa2bd2016-04-18 00:54:38 +020037#undef ATOMIC64_OPS
38#define ATOMIC64_OPS(op) ATOMIC64_OP(op) ATOMIC64_FETCH_OP(op)
39
40ATOMIC64_OPS(and)
41ATOMIC64_OPS(or)
42ATOMIC64_OPS(xor)
Peter Zijlstrae6942b72014-04-23 19:32:50 +020043
Peter Zijlstra560cb122014-04-23 16:12:30 +020044#undef ATOMIC64_OPS
Peter Zijlstra28aa2bd2016-04-18 00:54:38 +020045#undef ATOMIC64_FETCH_OP
Peter Zijlstra560cb122014-04-23 16:12:30 +020046#undef ATOMIC64_OP_RETURN
47#undef ATOMIC64_OP
48
Mark Rutland92558132019-05-22 14:22:35 +010049extern s64 atomic64_dec_if_positive(atomic64_t *v);
Mark Rutlandb3a2a052018-06-21 13:13:20 +010050#define atomic64_dec_if_positive atomic64_dec_if_positive
Mark Rutland92558132019-05-22 14:22:35 +010051extern s64 atomic64_cmpxchg(atomic64_t *v, s64 o, s64 n);
52extern s64 atomic64_xchg(atomic64_t *v, s64 new);
53extern s64 atomic64_fetch_add_unless(atomic64_t *v, s64 a, s64 u);
Mark Rutland00b808a2018-06-21 13:13:11 +010054#define atomic64_fetch_add_unless atomic64_fetch_add_unless
Paul Mackerras09d4e0e2009-06-12 21:10:05 +000055
Paul Mackerras09d4e0e2009-06-12 21:10:05 +000056#endif /* _ASM_GENERIC_ATOMIC64_H */