1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __ASM_RISCV_BITOPS_H
19#define __ASM_RISCV_BITOPS_H
20
21#ifdef __KERNEL__
22
23#include <asm/system.h>
24#include <asm-generic/bitops/fls.h>
25#include <asm-generic/bitops/__fls.h>
26#include <asm-generic/bitops/fls64.h>
27#include <asm-generic/bitops/__ffs.h>
28
29#define smp_mb__before_clear_bit() do { } while (0)
30#define smp_mb__after_clear_bit() do { } while (0)
31
32
33
34
35static inline void __set_bit(int nr, void *addr)
36{
37 int *a = (int *)addr;
38 int mask;
39
40 a += nr >> 5;
41 mask = 1 << (nr & 0x1f);
42 *a |= mask;
43}
44
45static inline void __clear_bit(int nr, void *addr)
46{
47 int *a = (int *)addr;
48 int mask;
49
50 a += nr >> 5;
51 mask = 1 << (nr & 0x1f);
52 *a &= ~mask;
53}
54
55static inline void __change_bit(int nr, void *addr)
56{
57 int mask;
58 unsigned long *ADDR = (unsigned long *)addr;
59
60 ADDR += nr >> 5;
61 mask = 1 << (nr & 31);
62 *ADDR ^= mask;
63}
64
65static inline int __test_and_set_bit(int nr, void *addr)
66{
67 int mask, retval;
68 unsigned int *a = (unsigned int *)addr;
69
70 a += nr >> 5;
71 mask = 1 << (nr & 0x1f);
72 retval = (mask & *a) != 0;
73 *a |= mask;
74 return retval;
75}
76
77static inline int __test_and_clear_bit(int nr, void *addr)
78{
79 int mask, retval;
80 unsigned int *a = (unsigned int *)addr;
81
82 a += nr >> 5;
83 mask = 1 << (nr & 0x1f);
84 retval = (mask & *a) != 0;
85 *a &= ~mask;
86 return retval;
87}
88
89static inline int __test_and_change_bit(int nr, void *addr)
90{
91 int mask, retval;
92 unsigned int *a = (unsigned int *)addr;
93
94 a += nr >> 5;
95 mask = 1 << (nr & 0x1f);
96 retval = (mask & *a) != 0;
97 *a ^= mask;
98 return retval;
99}
100
101
102
103
104static inline int test_bit(int nr, const void *addr)
105{
106 return ((unsigned char *)addr)[nr >> 3] & (1U << (nr & 7));
107}
108
109
110
111
112
113static inline unsigned long ffz(unsigned long word)
114{
115 int k;
116
117 word = ~word;
118 k = 31;
119 if (word & 0x0000ffff) {
120 k -= 16; word <<= 16;
121 }
122 if (word & 0x00ff0000) {
123 k -= 8; word <<= 8;
124 }
125 if (word & 0x0f000000) {
126 k -= 4; word <<= 4;
127 }
128 if (word & 0x30000000) {
129 k -= 2; word <<= 2;
130 }
131 if (word & 0x40000000)
132 k -= 1;
133
134 return k;
135}
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153#define hweight32(x) generic_hweight32(x)
154#define hweight16(x) generic_hweight16(x)
155#define hweight8(x) generic_hweight8(x)
156
157#define ext2_set_bit test_and_set_bit
158#define ext2_clear_bit test_and_clear_bit
159#define ext2_test_bit test_bit
160#define ext2_find_first_zero_bit find_first_zero_bit
161#define ext2_find_next_zero_bit find_next_zero_bit
162
163
164#define minix_test_and_set_bit(nr, addr) test_and_set_bit(nr, addr)
165#define minix_set_bit(nr, addr) set_bit(nr, addr)
166#define minix_test_and_clear_bit(nr, addr) test_and_clear_bit(nr, addr)
167#define minix_test_bit(nr, addr) test_bit(nr, addr)
168#define minix_find_first_zero_bit(addr, size) find_first_zero_bit(addr, size)
169
170#endif
171
172#endif
173