]>
git.ipfire.org Git - thirdparty/linux.git/blob - arch/metag/include/asm/atomic_lnkget.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_METAG_ATOMIC_LNKGET_H
3 #define __ASM_METAG_ATOMIC_LNKGET_H
5 #define ATOMIC_INIT(i) { (i) }
7 #define atomic_set(v, i) WRITE_ONCE((v)->counter, (i))
9 #include <linux/compiler.h>
11 #include <asm/barrier.h>
14 * None of these asm statements clobber memory as LNKSET writes around
15 * the cache so the memory it modifies cannot safely be read by any means
16 * other than these accessors.
19 static inline int atomic_read(const atomic_t
*v
)
26 : "da" (&v
->counter
));
31 #define ATOMIC_OP(op) \
32 static inline void atomic_##op(int i, atomic_t *v) \
37 "1: LNKGETD %0, [%1]\n" \
38 " " #op " %0, %0, %2\n" \
39 " LNKSETD [%1], %0\n" \
40 " DEFR %0, TXSTAT\n" \
41 " ANDT %0, %0, #HI(0x3f000000)\n" \
42 " CMPT %0, #HI(0x02000000)\n" \
45 : "da" (&v->counter), "bd" (i) \
49 #define ATOMIC_OP_RETURN(op) \
50 static inline int atomic_##op##_return(int i, atomic_t *v) \
57 "1: LNKGETD %1, [%2]\n" \
58 " " #op " %1, %1, %3\n" \
59 " LNKSETD [%2], %1\n" \
60 " DEFR %0, TXSTAT\n" \
61 " ANDT %0, %0, #HI(0x3f000000)\n" \
62 " CMPT %0, #HI(0x02000000)\n" \
64 : "=&d" (temp), "=&da" (result) \
65 : "da" (&v->counter), "br" (i) \
73 #define ATOMIC_FETCH_OP(op) \
74 static inline int atomic_fetch_##op(int i, atomic_t *v) \
81 "1: LNKGETD %1, [%2]\n" \
82 " " #op " %0, %1, %3\n" \
83 " LNKSETD [%2], %0\n" \
84 " DEFR %0, TXSTAT\n" \
85 " ANDT %0, %0, #HI(0x3f000000)\n" \
86 " CMPT %0, #HI(0x02000000)\n" \
88 : "=&d" (temp), "=&d" (result) \
89 : "da" (&v->counter), "bd" (i) \
97 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op) ATOMIC_FETCH_OP(op)
103 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_FETCH_OP(op)
110 #undef ATOMIC_FETCH_OP
111 #undef ATOMIC_OP_RETURN
114 static inline int atomic_cmpxchg(atomic_t
*v
, int old
, int new)
121 "1: LNKGETD %1, [%2]\n"
123 " LNKSETDEQ [%2], %4\n"
126 " ANDT %0, %0, #HI(0x3f000000)\n"
127 " CMPT %0, #HI(0x02000000)\n"
130 : "=&d" (temp
), "=&d" (result
)
131 : "da" (&v
->counter
), "bd" (old
), "da" (new)
139 static inline int atomic_xchg(atomic_t
*v
, int new)
144 "1: LNKGETD %1, [%2]\n"
145 " LNKSETD [%2], %3\n"
147 " ANDT %0, %0, #HI(0x3f000000)\n"
148 " CMPT %0, #HI(0x02000000)\n"
150 : "=&d" (temp
), "=&d" (old
)
151 : "da" (&v
->counter
), "da" (new)
157 static inline int __atomic_add_unless(atomic_t
*v
, int a
, int u
)
164 "1: LNKGETD %1, [%2]\n"
167 " LNKSETDNE [%2], %0\n"
170 " ANDT %0, %0, #HI(0x3f000000)\n"
171 " CMPT %0, #HI(0x02000000)\n"
174 : "=&d" (temp
), "=&d" (result
)
175 : "da" (&v
->counter
), "bd" (u
), "bd" (a
)
183 static inline int atomic_sub_if_positive(int i
, atomic_t
*v
)
188 "1: LNKGETD %1, [%2]\n"
190 " LNKSETDGE [%2], %1\n"
193 " ANDT %0, %0, #HI(0x3f000000)\n"
194 " CMPT %0, #HI(0x02000000)\n"
197 : "=&d" (temp
), "=&da" (result
)
198 : "da" (&v
->counter
), "bd" (i
)
204 #endif /* __ASM_METAG_ATOMIC_LNKGET_H */