2 * Based on arch/arm/include/asm/atomic.h
4 * Copyright (C) 1996 Russell King.
5 * Copyright (C) 2002 Deep Blue Solutions Ltd.
6 * Copyright (C) 2012 ARM Ltd.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef __ASM_ATOMIC_LL_SC_H
22 #define __ASM_ATOMIC_LL_SC_H
25 * AArch64 UP and SMP safe atomic ops. We use load exclusive and
26 * store exclusive to ensure that these are atomic. We may loop
27 * to ensure that the update happens.
29 * NOTE: these functions do *not* follow the PCS and must explicitly
30 * save any clobbered registers other than x0 (regardless of return
31 * value). This is achieved through -fcall-saved-* compiler flags for
32 * this file, which unfortunately don't work on a per-function basis
33 * (the optimize attribute silently ignores these options).
36 #ifndef __LL_SC_INLINE
37 #define __LL_SC_INLINE static inline
40 #ifndef __LL_SC_PREFIX
41 #define __LL_SC_PREFIX(x) x
44 #define ATOMIC_OP(op, asm_op) \
46 __LL_SC_PREFIX(atomic_##op(int i, atomic_t *v)) \
51 asm volatile("// atomic_" #op "\n" \
53 " " #asm_op " %w0, %w0, %w3\n" \
54 " stxr %w1, %w0, %2\n" \
56 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \
60 #define ATOMIC_OP_RETURN(op, asm_op) \
62 __LL_SC_PREFIX(atomic_##op##_return(int i, atomic_t *v)) \
67 asm volatile("// atomic_" #op "_return\n" \
69 " " #asm_op " %w0, %w0, %w3\n" \
70 " stlxr %w1, %w0, %2\n" \
72 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \
80 #define ATOMIC_OPS(op, asm_op) \
81 ATOMIC_OP(op, asm_op) \
82 ATOMIC_OP_RETURN(op, asm_op)
88 ATOMIC_OP(andnot
, bic
)
93 #undef ATOMIC_OP_RETURN
97 __LL_SC_PREFIX(atomic_cmpxchg(atomic_t
*ptr
, int old
, int new))
104 asm volatile("// atomic_cmpxchg\n"
108 " stxr %w0, %w4, %2\n"
111 : "=&r" (tmp
), "=&r" (oldval
), "+Q" (ptr
->counter
)
112 : "Ir" (old
), "r" (new)
119 #define ATOMIC64_OP(op, asm_op) \
120 __LL_SC_INLINE void \
121 __LL_SC_PREFIX(atomic64_##op(long i, atomic64_t *v)) \
126 asm volatile("// atomic64_" #op "\n" \
128 " " #asm_op " %0, %0, %3\n" \
129 " stxr %w1, %0, %2\n" \
131 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \
135 #define ATOMIC64_OP_RETURN(op, asm_op) \
136 __LL_SC_INLINE long \
137 __LL_SC_PREFIX(atomic64_##op##_return(long i, atomic64_t *v)) \
142 asm volatile("// atomic64_" #op "_return\n" \
144 " " #asm_op " %0, %0, %3\n" \
145 " stlxr %w1, %0, %2\n" \
147 : "=&r" (result), "=&r" (tmp), "+Q" (v->counter) \
155 #define ATOMIC64_OPS(op, asm_op) \
156 ATOMIC64_OP(op, asm_op) \
157 ATOMIC64_OP_RETURN(op, asm_op)
159 ATOMIC64_OPS(add
, add
)
160 ATOMIC64_OPS(sub
, sub
)
162 ATOMIC64_OP(and, and)
163 ATOMIC64_OP(andnot
, bic
)
165 ATOMIC64_OP(xor, eor
)
168 #undef ATOMIC64_OP_RETURN
172 __LL_SC_PREFIX(atomic64_cmpxchg(atomic64_t
*ptr
, long old
, long new))
179 asm volatile("// atomic64_cmpxchg\n"
183 " stxr %w0, %4, %2\n"
186 : "=&r" (res
), "=&r" (oldval
), "+Q" (ptr
->counter
)
187 : "Ir" (old
), "r" (new)
195 __LL_SC_PREFIX(atomic64_dec_if_positive(atomic64_t
*v
))
200 asm volatile("// atomic64_dec_if_positive\n"
204 " stlxr %w1, %0, %2\n"
208 : "=&r" (result
), "=&r" (tmp
), "+Q" (v
->counter
)
215 #endif /* __ASM_ATOMIC_LL_SC_H */
This page took 0.039812 seconds and 5 git commands to generate.