1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef _ASM_RISCV_BITOPS_H
15#define _ASM_RISCV_BITOPS_H
16
17#ifndef _LINUX_BITOPS_H
18#error "Only <linux/bitops.h> can be included directly"
19#endif
20
21#include <linux/compiler.h>
22#include <linux/irqflags.h>
23#include <asm/barrier.h>
24#include <asm/bitsperlong.h>
25
26#ifndef smp_mb__before_clear_bit
27#define smp_mb__before_clear_bit() smp_mb()
28#define smp_mb__after_clear_bit() smp_mb()
29#endif
30
31#include <asm-generic/bitops/__ffs.h>
32#include <asm-generic/bitops/ffz.h>
33#include <asm-generic/bitops/fls.h>
34#include <asm-generic/bitops/__fls.h>
35#include <asm-generic/bitops/fls64.h>
36#include <asm-generic/bitops/find.h>
37#include <asm-generic/bitops/sched.h>
38#include <asm-generic/bitops/ffs.h>
39
40#include <asm-generic/bitops/hweight.h>
41
42#if (BITS_PER_LONG == 64)
43#define __AMO(op) "amo" #op ".d"
44#elif (BITS_PER_LONG == 32)
45#define __AMO(op) "amo" #op ".w"
46#else
47#error "Unexpected BITS_PER_LONG"
48#endif
49
50#define __test_and_op_bit_ord(op, mod, nr, addr, ord) \
51({ \
52 unsigned long __res, __mask; \
53 __mask = BIT_MASK(nr); \
54 __asm__ __volatile__ ( \
55 __AMO(op) #ord " %0, %2, %1" \
56 : "=r" (__res), "+A" (addr[BIT_WORD(nr)]) \
57 : "r" (mod(__mask)) \
58 : "memory"); \
59 ((__res & __mask) != 0); \
60})
61
62#define __op_bit_ord(op, mod, nr, addr, ord) \
63 __asm__ __volatile__ ( \
64 __AMO(op) #ord " zero, %1, %0" \
65 : "+A" (addr[BIT_WORD(nr)]) \
66 : "r" (mod(BIT_MASK(nr))) \
67 : "memory");
68
69#define __test_and_op_bit(op, mod, nr, addr) \
70 __test_and_op_bit_ord(op, mod, nr, addr, .aqrl)
71#define __op_bit(op, mod, nr, addr) \
72 __op_bit_ord(op, mod, nr, addr, )
73
74
75#define __NOP(x) (x)
76#define __NOT(x) (~(x))
77
78
79
80
81
82
83
84
85static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
86{
87 return __test_and_op_bit(or, __NOP, nr, addr);
88}
89
90
91
92
93
94
95
96
97static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
98{
99 return __test_and_op_bit(and, __NOT, nr, addr);
100}
101
102
103
104
105
106
107
108
109
110static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
111{
112 return __test_and_op_bit(xor, __NOP, nr, addr);
113}
114
115
116
117
118
119
120
121
122
123
124
125
126
127static inline void set_bit(int nr, volatile unsigned long *addr)
128{
129 __op_bit(or, __NOP, nr, addr);
130}
131
132
133
134
135
136
137
138
139
140
141static inline void clear_bit(int nr, volatile unsigned long *addr)
142{
143 __op_bit(and, __NOT, nr, addr);
144}
145
146
147
148
149
150
151
152
153
154
155static inline void change_bit(int nr, volatile unsigned long *addr)
156{
157 __op_bit(xor, __NOP, nr, addr);
158}
159
160
161
162
163
164
165
166
167
168static inline int test_and_set_bit_lock(
169 unsigned long nr, volatile unsigned long *addr)
170{
171 return __test_and_op_bit_ord(or, __NOP, nr, addr, .aq);
172}
173
174
175
176
177
178
179
180
181static inline void clear_bit_unlock(
182 unsigned long nr, volatile unsigned long *addr)
183{
184 __op_bit_ord(and, __NOT, nr, addr, .rl);
185}
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202static inline void __clear_bit_unlock(
203 unsigned long nr, volatile unsigned long *addr)
204{
205 clear_bit_unlock(nr, addr);
206}
207
208#undef __test_and_op_bit
209#undef __op_bit
210#undef __NOP
211#undef __NOT
212#undef __AMO
213
214#include <asm-generic/bitops/non-atomic.h>
215#include <asm-generic/bitops/le.h>
216#include <asm-generic/bitops/ext2-atomic.h>
217
218#endif
219