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