1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __ASM_ARM_BITOPS_H
19#define __ASM_ARM_BITOPS_H
20
21#ifdef __KERNEL__
22
23#ifndef _LINUX_BITOPS_H
24#error only <linux/bitops.h> can be included directly
25#endif
26
27#include <linux/compiler.h>
28#include <linux/irqflags.h>
29#include <asm/barrier.h>
30
31
32
33
34
35
36static inline void ____atomic_set_bit(unsigned int bit, volatile unsigned long *p)
37{
38 unsigned long flags;
39 unsigned long mask = BIT_MASK(bit);
40
41 p += BIT_WORD(bit);
42
43 raw_local_irq_save(flags);
44 *p |= mask;
45 raw_local_irq_restore(flags);
46}
47
48static inline void ____atomic_clear_bit(unsigned int bit, volatile unsigned long *p)
49{
50 unsigned long flags;
51 unsigned long mask = BIT_MASK(bit);
52
53 p += BIT_WORD(bit);
54
55 raw_local_irq_save(flags);
56 *p &= ~mask;
57 raw_local_irq_restore(flags);
58}
59
60static inline void ____atomic_change_bit(unsigned int bit, volatile unsigned long *p)
61{
62 unsigned long flags;
63 unsigned long mask = BIT_MASK(bit);
64
65 p += BIT_WORD(bit);
66
67 raw_local_irq_save(flags);
68 *p ^= mask;
69 raw_local_irq_restore(flags);
70}
71
72static inline int
73____atomic_test_and_set_bit(unsigned int bit, volatile unsigned long *p)
74{
75 unsigned long flags;
76 unsigned int res;
77 unsigned long mask = BIT_MASK(bit);
78
79 p += BIT_WORD(bit);
80
81 raw_local_irq_save(flags);
82 res = *p;
83 *p = res | mask;
84 raw_local_irq_restore(flags);
85
86 return (res & mask) != 0;
87}
88
89static inline int
90____atomic_test_and_clear_bit(unsigned int bit, volatile unsigned long *p)
91{
92 unsigned long flags;
93 unsigned int res;
94 unsigned long mask = BIT_MASK(bit);
95
96 p += BIT_WORD(bit);
97
98 raw_local_irq_save(flags);
99 res = *p;
100 *p = res & ~mask;
101 raw_local_irq_restore(flags);
102
103 return (res & mask) != 0;
104}
105
106static inline int
107____atomic_test_and_change_bit(unsigned int bit, volatile unsigned long *p)
108{
109 unsigned long flags;
110 unsigned int res;
111 unsigned long mask = BIT_MASK(bit);
112
113 p += BIT_WORD(bit);
114
115 raw_local_irq_save(flags);
116 res = *p;
117 *p = res ^ mask;
118 raw_local_irq_restore(flags);
119
120 return (res & mask) != 0;
121}
122
123#include <asm-generic/bitops/non-atomic.h>
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153extern void _set_bit(int nr, volatile unsigned long * p);
154extern void _clear_bit(int nr, volatile unsigned long * p);
155extern void _change_bit(int nr, volatile unsigned long * p);
156extern int _test_and_set_bit(int nr, volatile unsigned long * p);
157extern int _test_and_clear_bit(int nr, volatile unsigned long * p);
158extern int _test_and_change_bit(int nr, volatile unsigned long * p);
159
160
161
162
163extern int _find_first_zero_bit_le(const unsigned long *p, unsigned size);
164extern int _find_next_zero_bit_le(const unsigned long *p, int size, int offset);
165extern int _find_first_bit_le(const unsigned long *p, unsigned size);
166extern int _find_next_bit_le(const unsigned long *p, int size, int offset);
167
168
169
170
171extern int _find_first_zero_bit_be(const unsigned long *p, unsigned size);
172extern int _find_next_zero_bit_be(const unsigned long *p, int size, int offset);
173extern int _find_first_bit_be(const unsigned long *p, unsigned size);
174extern int _find_next_bit_be(const unsigned long *p, int size, int offset);
175
176#ifndef CONFIG_SMP
177
178
179
180#define ATOMIC_BITOP(name,nr,p) \
181 (__builtin_constant_p(nr) ? ____atomic_##name(nr, p) : _##name(nr,p))
182#else
183#define ATOMIC_BITOP(name,nr,p) _##name(nr,p)
184#endif
185
186
187
188
189#define set_bit(nr,p) ATOMIC_BITOP(set_bit,nr,p)
190#define clear_bit(nr,p) ATOMIC_BITOP(clear_bit,nr,p)
191#define change_bit(nr,p) ATOMIC_BITOP(change_bit,nr,p)
192#define test_and_set_bit(nr,p) ATOMIC_BITOP(test_and_set_bit,nr,p)
193#define test_and_clear_bit(nr,p) ATOMIC_BITOP(test_and_clear_bit,nr,p)
194#define test_and_change_bit(nr,p) ATOMIC_BITOP(test_and_change_bit,nr,p)
195
196#ifndef __ARMEB__
197
198
199
200#define find_first_zero_bit(p,sz) _find_first_zero_bit_le(p,sz)
201#define find_next_zero_bit(p,sz,off) _find_next_zero_bit_le(p,sz,off)
202#define find_first_bit(p,sz) _find_first_bit_le(p,sz)
203#define find_next_bit(p,sz,off) _find_next_bit_le(p,sz,off)
204
205#else
206
207
208
209#define find_first_zero_bit(p,sz) _find_first_zero_bit_be(p,sz)
210#define find_next_zero_bit(p,sz,off) _find_next_zero_bit_be(p,sz,off)
211#define find_first_bit(p,sz) _find_first_bit_be(p,sz)
212#define find_next_bit(p,sz,off) _find_next_bit_be(p,sz,off)
213
214#endif
215
216#if __LINUX_ARM_ARCH__ < 5
217
218#include <asm-generic/bitops/ffz.h>
219#include <asm-generic/bitops/__fls.h>
220#include <asm-generic/bitops/__ffs.h>
221#include <asm-generic/bitops/fls.h>
222#include <asm-generic/bitops/ffs.h>
223
224#else
225
226static inline int constant_fls(int x)
227{
228 int r = 32;
229
230 if (!x)
231 return 0;
232 if (!(x & 0xffff0000u)) {
233 x <<= 16;
234 r -= 16;
235 }
236 if (!(x & 0xff000000u)) {
237 x <<= 8;
238 r -= 8;
239 }
240 if (!(x & 0xf0000000u)) {
241 x <<= 4;
242 r -= 4;
243 }
244 if (!(x & 0xc0000000u)) {
245 x <<= 2;
246 r -= 2;
247 }
248 if (!(x & 0x80000000u)) {
249 x <<= 1;
250 r -= 1;
251 }
252 return r;
253}
254
255
256
257
258
259
260
261static inline unsigned int __clz(unsigned int x)
262{
263 unsigned int ret;
264
265 asm("clz\t%0, %1" : "=r" (ret) : "r" (x));
266
267 return ret;
268}
269
270
271
272
273
274static inline int fls(int x)
275{
276 if (__builtin_constant_p(x))
277 return constant_fls(x);
278
279 return 32 - __clz(x);
280}
281
282
283
284
285
286static inline unsigned long __fls(unsigned long x)
287{
288 return fls(x) - 1;
289}
290
291
292
293
294
295static inline int ffs(int x)
296{
297 return fls(x & -x);
298}
299
300
301
302
303
304static inline unsigned long __ffs(unsigned long x)
305{
306 return ffs(x) - 1;
307}
308
309#define ffz(x) __ffs( ~(x) )
310
311#endif
312
313#include <asm-generic/bitops/fls64.h>
314
315#include <asm-generic/bitops/sched.h>
316#include <asm-generic/bitops/hweight.h>
317#include <asm-generic/bitops/lock.h>
318
319#ifdef __ARMEB__
320
321static inline int find_first_zero_bit_le(const void *p, unsigned size)
322{
323 return _find_first_zero_bit_le(p, size);
324}
325#define find_first_zero_bit_le find_first_zero_bit_le
326
327static inline int find_next_zero_bit_le(const void *p, int size, int offset)
328{
329 return _find_next_zero_bit_le(p, size, offset);
330}
331#define find_next_zero_bit_le find_next_zero_bit_le
332
333static inline int find_next_bit_le(const void *p, int size, int offset)
334{
335 return _find_next_bit_le(p, size, offset);
336}
337#define find_next_bit_le find_next_bit_le
338
339#endif
340
341#include <asm-generic/bitops/le.h>
342
343
344
345
346#include <asm-generic/bitops/ext2-atomic-setbit.h>
347
348#endif
349
350#endif
351