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