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