1 #ifndef _ARM_ARM64_BITOPS_H
2 #define _ARM_ARM64_BITOPS_H
3 
4 /*
5  * Little endian assembly atomic bitops.
6  */
7 extern void set_bit(int nr, volatile void *p);
8 extern void clear_bit(int nr, volatile void *p);
9 extern void change_bit(int nr, volatile void *p);
10 extern int test_and_set_bit(int nr, volatile void *p);
11 extern int test_and_clear_bit(int nr, volatile void *p);
12 extern int test_and_change_bit(int nr, volatile void *p);
13 
14 /* Based on linux/include/asm-generic/bitops/builtin-__ffs.h */
15 /**
16  * __ffs - find first bit in word.
17  * @word: The word to search
18  *
19  * Undefined if no bit exists, so code should check against 0 first.
20  */
__ffs(unsigned long word)21 static /*__*/always_inline unsigned long __ffs(unsigned long word)
22 {
23         return __builtin_ctzl(word);
24 }
25 
26 /* Based on linux/include/asm-generic/bitops/ffz.h */
27 /*
28  * ffz - find first zero in word.
29  * @word: The word to search
30  *
31  * Undefined if no zero exists, so code should check against ~0UL first.
32  */
33 #define ffz(x)  __ffs(~(x))
34 
flsl(unsigned long x)35 static inline int flsl(unsigned long x)
36 {
37         int ret;
38 
39         if (__builtin_constant_p(x))
40                return generic_flsl(x);
41 
42         asm("clz\t%0, %1" : "=r" (ret) : "r" (x));
43         return BITS_PER_LONG - ret;
44 }
45 
46 /* Based on linux/include/asm-generic/bitops/find.h */
47 
48 #ifndef find_next_bit
49 /**
50  * find_next_bit - find the next set bit in a memory region
51  * @addr: The address to base the search on
52  * @offset: The bitnumber to start searching at
53  * @size: The bitmap size in bits
54  */
55 extern unsigned long find_next_bit(const unsigned long *addr, unsigned long
56 		size, unsigned long offset);
57 #endif
58 
59 #ifndef find_next_zero_bit
60 /**
61  * find_next_zero_bit - find the next cleared bit in a memory region
62  * @addr: The address to base the search on
63  * @offset: The bitnumber to start searching at
64  * @size: The bitmap size in bits
65  */
66 extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned
67 		long size, unsigned long offset);
68 #endif
69 
70 #ifdef CONFIG_GENERIC_FIND_FIRST_BIT
71 
72 /**
73  * find_first_bit - find the first set bit in a memory region
74  * @addr: The address to start the search at
75  * @size: The maximum size to search
76  *
77  * Returns the bit number of the first set bit.
78  */
79 extern unsigned long find_first_bit(const unsigned long *addr,
80 				    unsigned long size);
81 
82 /**
83  * find_first_zero_bit - find the first cleared bit in a memory region
84  * @addr: The address to start the search at
85  * @size: The maximum size to search
86  *
87  * Returns the bit number of the first cleared bit.
88  */
89 extern unsigned long find_first_zero_bit(const unsigned long *addr,
90 					 unsigned long size);
91 #else /* CONFIG_GENERIC_FIND_FIRST_BIT */
92 
93 #define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
94 #define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
95 
96 #endif /* CONFIG_GENERIC_FIND_FIRST_BIT */
97 
98 
99 #endif /* _ARM_ARM64_BITOPS_H */
100 /*
101  * Local variables:
102  * mode: C
103  * c-file-style: "BSD"
104  * c-basic-offset: 4
105  * indent-tabs-mode: nil
106  * End:
107  */
108