xref: /openbmc/linux/arch/arm64/include/asm/atomic.h (revision b830f94f)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Based on arch/arm/include/asm/atomic.h
4  *
5  * Copyright (C) 1996 Russell King.
6  * Copyright (C) 2002 Deep Blue Solutions Ltd.
7  * Copyright (C) 2012 ARM Ltd.
8  */
9 #ifndef __ASM_ATOMIC_H
10 #define __ASM_ATOMIC_H
11 
12 #include <linux/compiler.h>
13 #include <linux/types.h>
14 
15 #include <asm/barrier.h>
16 #include <asm/lse.h>
17 
18 #ifdef __KERNEL__
19 
20 #define __ARM64_IN_ATOMIC_IMPL
21 
22 #if defined(CONFIG_ARM64_LSE_ATOMICS) && defined(CONFIG_AS_LSE)
23 #include <asm/atomic_lse.h>
24 #else
25 #include <asm/atomic_ll_sc.h>
26 #endif
27 
28 #undef __ARM64_IN_ATOMIC_IMPL
29 
30 #include <asm/cmpxchg.h>
31 
32 #define ATOMIC_INIT(i)	{ (i) }
33 
34 #define arch_atomic_read(v)			READ_ONCE((v)->counter)
35 #define arch_atomic_set(v, i)			WRITE_ONCE(((v)->counter), (i))
36 
37 #define arch_atomic_add_return_relaxed		arch_atomic_add_return_relaxed
38 #define arch_atomic_add_return_acquire		arch_atomic_add_return_acquire
39 #define arch_atomic_add_return_release		arch_atomic_add_return_release
40 #define arch_atomic_add_return			arch_atomic_add_return
41 
42 #define arch_atomic_sub_return_relaxed		arch_atomic_sub_return_relaxed
43 #define arch_atomic_sub_return_acquire		arch_atomic_sub_return_acquire
44 #define arch_atomic_sub_return_release		arch_atomic_sub_return_release
45 #define arch_atomic_sub_return			arch_atomic_sub_return
46 
47 #define arch_atomic_fetch_add_relaxed		arch_atomic_fetch_add_relaxed
48 #define arch_atomic_fetch_add_acquire		arch_atomic_fetch_add_acquire
49 #define arch_atomic_fetch_add_release		arch_atomic_fetch_add_release
50 #define arch_atomic_fetch_add			arch_atomic_fetch_add
51 
52 #define arch_atomic_fetch_sub_relaxed		arch_atomic_fetch_sub_relaxed
53 #define arch_atomic_fetch_sub_acquire		arch_atomic_fetch_sub_acquire
54 #define arch_atomic_fetch_sub_release		arch_atomic_fetch_sub_release
55 #define arch_atomic_fetch_sub			arch_atomic_fetch_sub
56 
57 #define arch_atomic_fetch_and_relaxed		arch_atomic_fetch_and_relaxed
58 #define arch_atomic_fetch_and_acquire		arch_atomic_fetch_and_acquire
59 #define arch_atomic_fetch_and_release		arch_atomic_fetch_and_release
60 #define arch_atomic_fetch_and			arch_atomic_fetch_and
61 
62 #define arch_atomic_fetch_andnot_relaxed	arch_atomic_fetch_andnot_relaxed
63 #define arch_atomic_fetch_andnot_acquire	arch_atomic_fetch_andnot_acquire
64 #define arch_atomic_fetch_andnot_release	arch_atomic_fetch_andnot_release
65 #define arch_atomic_fetch_andnot		arch_atomic_fetch_andnot
66 
67 #define arch_atomic_fetch_or_relaxed		arch_atomic_fetch_or_relaxed
68 #define arch_atomic_fetch_or_acquire		arch_atomic_fetch_or_acquire
69 #define arch_atomic_fetch_or_release		arch_atomic_fetch_or_release
70 #define arch_atomic_fetch_or			arch_atomic_fetch_or
71 
72 #define arch_atomic_fetch_xor_relaxed		arch_atomic_fetch_xor_relaxed
73 #define arch_atomic_fetch_xor_acquire		arch_atomic_fetch_xor_acquire
74 #define arch_atomic_fetch_xor_release		arch_atomic_fetch_xor_release
75 #define arch_atomic_fetch_xor			arch_atomic_fetch_xor
76 
77 #define arch_atomic_xchg_relaxed(v, new) \
78 	arch_xchg_relaxed(&((v)->counter), (new))
79 #define arch_atomic_xchg_acquire(v, new) \
80 	arch_xchg_acquire(&((v)->counter), (new))
81 #define arch_atomic_xchg_release(v, new) \
82 	arch_xchg_release(&((v)->counter), (new))
83 #define arch_atomic_xchg(v, new) \
84 	arch_xchg(&((v)->counter), (new))
85 
86 #define arch_atomic_cmpxchg_relaxed(v, old, new) \
87 	arch_cmpxchg_relaxed(&((v)->counter), (old), (new))
88 #define arch_atomic_cmpxchg_acquire(v, old, new) \
89 	arch_cmpxchg_acquire(&((v)->counter), (old), (new))
90 #define arch_atomic_cmpxchg_release(v, old, new) \
91 	arch_cmpxchg_release(&((v)->counter), (old), (new))
92 #define arch_atomic_cmpxchg(v, old, new) \
93 	arch_cmpxchg(&((v)->counter), (old), (new))
94 
95 #define arch_atomic_andnot			arch_atomic_andnot
96 
97 /*
98  * 64-bit arch_atomic operations.
99  */
100 #define ATOMIC64_INIT				ATOMIC_INIT
101 #define arch_atomic64_read			arch_atomic_read
102 #define arch_atomic64_set			arch_atomic_set
103 
104 #define arch_atomic64_add_return_relaxed	arch_atomic64_add_return_relaxed
105 #define arch_atomic64_add_return_acquire	arch_atomic64_add_return_acquire
106 #define arch_atomic64_add_return_release	arch_atomic64_add_return_release
107 #define arch_atomic64_add_return		arch_atomic64_add_return
108 
109 #define arch_atomic64_sub_return_relaxed	arch_atomic64_sub_return_relaxed
110 #define arch_atomic64_sub_return_acquire	arch_atomic64_sub_return_acquire
111 #define arch_atomic64_sub_return_release	arch_atomic64_sub_return_release
112 #define arch_atomic64_sub_return		arch_atomic64_sub_return
113 
114 #define arch_atomic64_fetch_add_relaxed		arch_atomic64_fetch_add_relaxed
115 #define arch_atomic64_fetch_add_acquire		arch_atomic64_fetch_add_acquire
116 #define arch_atomic64_fetch_add_release		arch_atomic64_fetch_add_release
117 #define arch_atomic64_fetch_add			arch_atomic64_fetch_add
118 
119 #define arch_atomic64_fetch_sub_relaxed		arch_atomic64_fetch_sub_relaxed
120 #define arch_atomic64_fetch_sub_acquire		arch_atomic64_fetch_sub_acquire
121 #define arch_atomic64_fetch_sub_release		arch_atomic64_fetch_sub_release
122 #define arch_atomic64_fetch_sub			arch_atomic64_fetch_sub
123 
124 #define arch_atomic64_fetch_and_relaxed		arch_atomic64_fetch_and_relaxed
125 #define arch_atomic64_fetch_and_acquire		arch_atomic64_fetch_and_acquire
126 #define arch_atomic64_fetch_and_release		arch_atomic64_fetch_and_release
127 #define arch_atomic64_fetch_and			arch_atomic64_fetch_and
128 
129 #define arch_atomic64_fetch_andnot_relaxed	arch_atomic64_fetch_andnot_relaxed
130 #define arch_atomic64_fetch_andnot_acquire	arch_atomic64_fetch_andnot_acquire
131 #define arch_atomic64_fetch_andnot_release	arch_atomic64_fetch_andnot_release
132 #define arch_atomic64_fetch_andnot		arch_atomic64_fetch_andnot
133 
134 #define arch_atomic64_fetch_or_relaxed		arch_atomic64_fetch_or_relaxed
135 #define arch_atomic64_fetch_or_acquire		arch_atomic64_fetch_or_acquire
136 #define arch_atomic64_fetch_or_release		arch_atomic64_fetch_or_release
137 #define arch_atomic64_fetch_or			arch_atomic64_fetch_or
138 
139 #define arch_atomic64_fetch_xor_relaxed		arch_atomic64_fetch_xor_relaxed
140 #define arch_atomic64_fetch_xor_acquire		arch_atomic64_fetch_xor_acquire
141 #define arch_atomic64_fetch_xor_release		arch_atomic64_fetch_xor_release
142 #define arch_atomic64_fetch_xor			arch_atomic64_fetch_xor
143 
144 #define arch_atomic64_xchg_relaxed		arch_atomic_xchg_relaxed
145 #define arch_atomic64_xchg_acquire		arch_atomic_xchg_acquire
146 #define arch_atomic64_xchg_release		arch_atomic_xchg_release
147 #define arch_atomic64_xchg			arch_atomic_xchg
148 
149 #define arch_atomic64_cmpxchg_relaxed		arch_atomic_cmpxchg_relaxed
150 #define arch_atomic64_cmpxchg_acquire		arch_atomic_cmpxchg_acquire
151 #define arch_atomic64_cmpxchg_release		arch_atomic_cmpxchg_release
152 #define arch_atomic64_cmpxchg			arch_atomic_cmpxchg
153 
154 #define arch_atomic64_andnot			arch_atomic64_andnot
155 
156 #define arch_atomic64_dec_if_positive		arch_atomic64_dec_if_positive
157 
158 #include <asm-generic/atomic-instrumented.h>
159 
160 #endif
161 #endif
162