xref: /openbmc/linux/include/asm-generic/bitops/le.h (revision 6c33a6f4)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_GENERIC_BITOPS_LE_H_
3 #define _ASM_GENERIC_BITOPS_LE_H_
4 
5 #include <asm/types.h>
6 #include <asm/byteorder.h>
7 
8 #if defined(__LITTLE_ENDIAN)
9 
10 #define BITOP_LE_SWIZZLE	0
11 
12 static inline unsigned long find_next_zero_bit_le(const void *addr,
13 		unsigned long size, unsigned long offset)
14 {
15 	return find_next_zero_bit(addr, size, offset);
16 }
17 
18 static inline unsigned long find_next_bit_le(const void *addr,
19 		unsigned long size, unsigned long offset)
20 {
21 	return find_next_bit(addr, size, offset);
22 }
23 
24 static inline unsigned long find_first_zero_bit_le(const void *addr,
25 		unsigned long size)
26 {
27 	return find_first_zero_bit(addr, size);
28 }
29 
30 #elif defined(__BIG_ENDIAN)
31 
32 #define BITOP_LE_SWIZZLE	((BITS_PER_LONG-1) & ~0x7)
33 
34 #ifndef find_next_zero_bit_le
35 extern unsigned long find_next_zero_bit_le(const void *addr,
36 		unsigned long size, unsigned long offset);
37 #endif
38 
39 #ifndef find_next_bit_le
40 extern unsigned long find_next_bit_le(const void *addr,
41 		unsigned long size, unsigned long offset);
42 #endif
43 
44 #ifndef find_first_zero_bit_le
45 #define find_first_zero_bit_le(addr, size) \
46 	find_next_zero_bit_le((addr), (size), 0)
47 #endif
48 
49 #else
50 #error "Please fix <asm/byteorder.h>"
51 #endif
52 
53 static inline int test_bit_le(int nr, const void *addr)
54 {
55 	return test_bit(nr ^ BITOP_LE_SWIZZLE, addr);
56 }
57 
58 static inline void set_bit_le(int nr, void *addr)
59 {
60 	set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
61 }
62 
63 static inline void clear_bit_le(int nr, void *addr)
64 {
65 	clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
66 }
67 
68 static inline void __set_bit_le(int nr, void *addr)
69 {
70 	__set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
71 }
72 
73 static inline void __clear_bit_le(int nr, void *addr)
74 {
75 	__clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
76 }
77 
78 static inline int test_and_set_bit_le(int nr, void *addr)
79 {
80 	return test_and_set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
81 }
82 
83 static inline int test_and_clear_bit_le(int nr, void *addr)
84 {
85 	return test_and_clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
86 }
87 
88 static inline int __test_and_set_bit_le(int nr, void *addr)
89 {
90 	return __test_and_set_bit(nr ^ BITOP_LE_SWIZZLE, addr);
91 }
92 
93 static inline int __test_and_clear_bit_le(int nr, void *addr)
94 {
95 	return __test_and_clear_bit(nr ^ BITOP_LE_SWIZZLE, addr);
96 }
97 
98 #endif /* _ASM_GENERIC_BITOPS_LE_H_ */
99