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