1 #ifndef __ASM_METAG_ATOMIC_LNKGET_H
2 #define __ASM_METAG_ATOMIC_LNKGET_H
4 #define ATOMIC_INIT(i) { (i) }
6 #define atomic_set(v, i) WRITE_ONCE((v)->counter, (i))
8 #include <linux/compiler.h>
10 #include <asm/barrier.h>
13 * None of these asm statements clobber memory as LNKSET writes around
14 * the cache so the memory it modifies cannot safely be read by any means
15 * other than these accessors.
18 static inline int atomic_read(const atomic_t *v)
25 : "da" (&v->counter));
30 #define ATOMIC_OP(op) \
31 static inline void atomic_##op(int i, atomic_t *v) \
36 "1: LNKGETD %0, [%1]\n" \
37 " " #op " %0, %0, %2\n" \
38 " LNKSETD [%1], %0\n" \
39 " DEFR %0, TXSTAT\n" \
40 " ANDT %0, %0, #HI(0x3f000000)\n" \
41 " CMPT %0, #HI(0x02000000)\n" \
44 : "da" (&v->counter), "bd" (i) \
48 #define ATOMIC_OP_RETURN(op) \
49 static inline int atomic_##op##_return(int i, atomic_t *v) \
56 "1: LNKGETD %1, [%2]\n" \
57 " " #op " %1, %1, %3\n" \
58 " LNKSETD [%2], %1\n" \
59 " DEFR %0, TXSTAT\n" \
60 " ANDT %0, %0, #HI(0x3f000000)\n" \
61 " CMPT %0, #HI(0x02000000)\n" \
63 : "=&d" (temp), "=&da" (result) \
64 : "da" (&v->counter), "br" (i) \
72 #define ATOMIC_FETCH_OP(op) \
73 static inline int atomic_fetch_##op(int i, atomic_t *v) \
80 "1: LNKGETD %1, [%2]\n" \
81 " " #op " %0, %1, %3\n" \
82 " LNKSETD [%2], %0\n" \
83 " DEFR %0, TXSTAT\n" \
84 " ANDT %0, %0, #HI(0x3f000000)\n" \
85 " CMPT %0, #HI(0x02000000)\n" \
87 : "=&d" (temp), "=&d" (result) \
88 : "da" (&v->counter), "bd" (i) \
96 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_OP_RETURN(op) ATOMIC_FETCH_OP(op)
102 #define ATOMIC_OPS(op) ATOMIC_OP(op) ATOMIC_FETCH_OP(op)
109 #undef ATOMIC_FETCH_OP
110 #undef ATOMIC_OP_RETURN
113 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
120 "1: LNKGETD %1, [%2]\n"
122 " LNKSETDEQ [%2], %4\n"
125 " ANDT %0, %0, #HI(0x3f000000)\n"
126 " CMPT %0, #HI(0x02000000)\n"
129 : "=&d" (temp), "=&d" (result)
130 : "da" (&v->counter), "bd" (old), "da" (new)
138 static inline int atomic_xchg(atomic_t *v, int new)
143 "1: LNKGETD %1, [%2]\n"
144 " LNKSETD [%2], %3\n"
146 " ANDT %0, %0, #HI(0x3f000000)\n"
147 " CMPT %0, #HI(0x02000000)\n"
149 : "=&d" (temp), "=&d" (old)
150 : "da" (&v->counter), "da" (new)
156 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
163 "1: LNKGETD %1, [%2]\n"
166 " LNKSETDNE [%2], %0\n"
169 " ANDT %0, %0, #HI(0x3f000000)\n"
170 " CMPT %0, #HI(0x02000000)\n"
173 : "=&d" (temp), "=&d" (result)
174 : "da" (&v->counter), "bd" (u), "bd" (a)
182 static inline int atomic_sub_if_positive(int i, atomic_t *v)
187 "1: LNKGETD %1, [%2]\n"
189 " LNKSETDGE [%2], %1\n"
192 " ANDT %0, %0, #HI(0x3f000000)\n"
193 " CMPT %0, #HI(0x02000000)\n"
196 : "=&d" (temp), "=&da" (result)
197 : "da" (&v->counter), "bd" (i)
203 #endif /* __ASM_METAG_ATOMIC_LNKGET_H */