1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_GENERIC_BITOPS_LE_H_
3 #define _ASM_GENERIC_BITOPS_LE_H_
5 #include <asm-generic/bitops/find.h>
7 #include <asm/byteorder.h>
8 #include <linux/swab.h>
10 #if defined(__LITTLE_ENDIAN)
12 #define BITOP_LE_SWIZZLE 0
14 static inline unsigned long find_next_zero_bit_le(const void *addr,
15 unsigned long size, unsigned long offset)
17 return find_next_zero_bit(addr, size, offset);
20 static inline unsigned long find_next_bit_le(const void *addr,
21 unsigned long size, unsigned long offset)
23 return find_next_bit(addr, size, offset);
26 static inline unsigned long find_first_zero_bit_le(const void *addr,
29 return find_first_zero_bit(addr, size);
32 #elif defined(__BIG_ENDIAN)
34 #define BITOP_LE_SWIZZLE ((BITS_PER_LONG-1) & ~0x7)
36 #ifndef find_next_zero_bit_le
38 unsigned long find_next_zero_bit_le(const void *addr, unsigned
39 long size, unsigned long offset)
41 if (small_const_nbits(size)) {
42 unsigned long val = *(const unsigned long *)addr;
44 if (unlikely(offset >= size))
47 val = swab(val) | ~GENMASK(size - 1, offset);
48 return val == ~0UL ? size : ffz(val);
51 return _find_next_bit(addr, NULL, size, offset, ~0UL, 1);
55 #ifndef find_next_bit_le
57 unsigned long find_next_bit_le(const void *addr, unsigned
58 long size, unsigned long offset)
60 if (small_const_nbits(size)) {
61 unsigned long val = *(const unsigned long *)addr;
63 if (unlikely(offset >= size))
66 val = swab(val) & GENMASK(size - 1, offset);
67 return val ? __ffs(val) : size;
70 return _find_next_bit(addr, NULL, size, offset, 0UL, 1);
74 #ifndef find_first_zero_bit_le
75 #define find_first_zero_bit_le(addr, size) \
76 find_next_zero_bit_le((addr), (size), 0)
80 #error "Please fix <asm/byteorder.h>"
83 static inline int test_bit_le(int nr, const void *addr)
85 return test_bit(nr ^ BITOP_LE_SWIZZLE, addr);
88 static inline void set_bit_le(int nr, void *addr)
90 set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
93 static inline void clear_bit_le(int nr, void *addr)
95 clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
98 static inline void __set_bit_le(int nr, void *addr)
100 __set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
103 static inline void __clear_bit_le(int nr, void *addr)
105 __clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
108 static inline int test_and_set_bit_le(int nr, void *addr)
110 return test_and_set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
113 static inline int test_and_clear_bit_le(int nr, void *addr)
115 return test_and_clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
118 static inline int __test_and_set_bit_le(int nr, void *addr)
120 return __test_and_set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
123 static inline int __test_and_clear_bit_le(int nr, void *addr)
125 return __test_and_clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
128 #endif /* _ASM_GENERIC_BITOPS_LE_H_ */