Rev 5270 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5270 | Rev 6082 | ||
---|---|---|---|
Line 50... | Line 50... | ||
50 | * bitmap_shift_left(dst, src, n, nbits) *dst = *src << n |
50 | * bitmap_shift_left(dst, src, n, nbits) *dst = *src << n |
51 | * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) |
51 | * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) |
52 | * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) |
52 | * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) |
53 | * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap |
53 | * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap |
54 | * bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz |
54 | * bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz |
55 | * bitmap_scnprintf(buf, len, src, nbits) Print bitmap src to buf |
- | |
56 | * bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf |
55 | * bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf |
57 | * bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf |
56 | * bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf |
58 | * bitmap_scnlistprintf(buf, len, src, nbits) Print bitmap src as list to buf |
- | |
59 | * bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf |
57 | * bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf |
60 | * bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf |
58 | * bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf |
61 | * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region |
59 | * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region |
62 | * bitmap_release_region(bitmap, pos, order) Free specified bit region |
60 | * bitmap_release_region(bitmap, pos, order) Free specified bit region |
63 | * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region |
61 | * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region |
64 | * bitmap_print_to_pagebuf(list, buf, mask, nbits) Print bitmap src as list/hex |
- | |
65 | */ |
62 | */ |
Line 66... | Line 63... | ||
66 | 63 | ||
67 | /* |
64 | /* |
68 | * Also the following operations in asm/bitops.h apply to bitmaps. |
65 | * Also the following operations in asm/bitops.h apply to bitmaps. |
Line 94... | Line 91... | ||
94 | extern int __bitmap_full(const unsigned long *bitmap, unsigned int nbits); |
91 | extern int __bitmap_full(const unsigned long *bitmap, unsigned int nbits); |
95 | extern int __bitmap_equal(const unsigned long *bitmap1, |
92 | extern int __bitmap_equal(const unsigned long *bitmap1, |
96 | const unsigned long *bitmap2, unsigned int nbits); |
93 | const unsigned long *bitmap2, unsigned int nbits); |
97 | extern void __bitmap_complement(unsigned long *dst, const unsigned long *src, |
94 | extern void __bitmap_complement(unsigned long *dst, const unsigned long *src, |
98 | unsigned int nbits); |
95 | unsigned int nbits); |
99 | extern void __bitmap_shift_right(unsigned long *dst, |
96 | extern void __bitmap_shift_right(unsigned long *dst, const unsigned long *src, |
100 | const unsigned long *src, int shift, int bits); |
97 | unsigned int shift, unsigned int nbits); |
101 | extern void __bitmap_shift_left(unsigned long *dst, |
98 | extern void __bitmap_shift_left(unsigned long *dst, const unsigned long *src, |
102 | const unsigned long *src, int shift, int bits); |
99 | unsigned int shift, unsigned int nbits); |
103 | extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, |
100 | extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, |
104 | const unsigned long *bitmap2, unsigned int nbits); |
101 | const unsigned long *bitmap2, unsigned int nbits); |
105 | extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, |
102 | extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, |
106 | const unsigned long *bitmap2, unsigned int nbits); |
103 | const unsigned long *bitmap2, unsigned int nbits); |
107 | extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, |
104 | extern void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, |
Line 145... | Line 142... | ||
145 | { |
142 | { |
146 | return bitmap_find_next_zero_area_off(map, size, start, nr, |
143 | return bitmap_find_next_zero_area_off(map, size, start, nr, |
147 | align_mask, 0); |
144 | align_mask, 0); |
148 | } |
145 | } |
Line 149... | Line -... | ||
149 | - | ||
150 | extern int bitmap_scnprintf(char *buf, unsigned int len, |
- | |
151 | const unsigned long *src, int nbits); |
146 | |
152 | extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user, |
147 | extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user, |
153 | unsigned long *dst, int nbits); |
148 | unsigned long *dst, int nbits); |
154 | extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen, |
149 | extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen, |
155 | unsigned long *dst, int nbits); |
- | |
156 | extern int bitmap_scnlistprintf(char *buf, unsigned int len, |
- | |
157 | const unsigned long *src, int nbits); |
150 | unsigned long *dst, int nbits); |
158 | extern int bitmap_parselist(const char *buf, unsigned long *maskp, |
151 | extern int bitmap_parselist(const char *buf, unsigned long *maskp, |
159 | int nmaskbits); |
152 | int nmaskbits); |
160 | extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen, |
153 | extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen, |
161 | unsigned long *dst, int nbits); |
154 | unsigned long *dst, int nbits); |
162 | extern void bitmap_remap(unsigned long *dst, const unsigned long *src, |
155 | extern void bitmap_remap(unsigned long *dst, const unsigned long *src, |
163 | const unsigned long *old, const unsigned long *new, int bits); |
156 | const unsigned long *old, const unsigned long *new, unsigned int nbits); |
164 | extern int bitmap_bitremap(int oldbit, |
157 | extern int bitmap_bitremap(int oldbit, |
165 | const unsigned long *old, const unsigned long *new, int bits); |
158 | const unsigned long *old, const unsigned long *new, int bits); |
166 | extern void bitmap_onto(unsigned long *dst, const unsigned long *orig, |
159 | extern void bitmap_onto(unsigned long *dst, const unsigned long *orig, |
167 | const unsigned long *relmap, int bits); |
160 | const unsigned long *relmap, unsigned int bits); |
168 | extern void bitmap_fold(unsigned long *dst, const unsigned long *orig, |
161 | extern void bitmap_fold(unsigned long *dst, const unsigned long *orig, |
169 | int sz, int bits); |
162 | unsigned int sz, unsigned int nbits); |
170 | extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order); |
163 | extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order); |
171 | extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order); |
164 | extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order); |
- | 165 | extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order); |
|
172 | extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order); |
166 | #ifdef __BIG_ENDIAN |
- | 167 | extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits); |
|
- | 168 | #else |
|
- | 169 | #define bitmap_copy_le bitmap_copy |
|
173 | extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); |
170 | #endif |
174 | extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits); |
171 | extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int ord, unsigned int nbits); |
175 | extern int bitmap_print_to_pagebuf(bool list, char *buf, |
172 | extern int bitmap_print_to_pagebuf(bool list, char *buf, |
Line 176... | Line 173... | ||
176 | const unsigned long *maskp, int nmaskbits); |
173 | const unsigned long *maskp, int nmaskbits); |
177 | 174 | ||
178 | #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG)) |
- | |
179 | #define BITMAP_LAST_WORD_MASK(nbits) \ |
- | |
180 | ( \ |
- | |
181 | ((nbits) % BITS_PER_LONG) ? \ |
- | |
Line 182... | Line 175... | ||
182 | (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ |
175 | #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) |
183 | ) |
176 | #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) |
Line 184... | Line 177... | ||
184 | 177 | ||
185 | #define small_const_nbits(nbits) \ |
178 | #define small_const_nbits(nbits) \ |
186 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) |
179 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) |
187 | 180 | ||
188 | static inline void bitmap_zero(unsigned long *dst, int nbits) |
181 | static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) |
189 | { |
182 | { |
190 | if (small_const_nbits(nbits)) |
183 | if (small_const_nbits(nbits)) |
191 | *dst = 0UL; |
184 | *dst = 0UL; |
192 | else { |
185 | else { |
Line 193... | Line 186... | ||
193 | int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
186 | unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
194 | memset(dst, 0, len); |
187 | memset(dst, 0, len); |
195 | } |
188 | } |
196 | } |
189 | } |
197 | 190 | ||
198 | static inline void bitmap_fill(unsigned long *dst, int nbits) |
191 | static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) |
199 | { |
192 | { |
200 | size_t nlongs = BITS_TO_LONGS(nbits); |
193 | unsigned int nlongs = BITS_TO_LONGS(nbits); |
201 | if (!small_const_nbits(nbits)) { |
194 | if (!small_const_nbits(nbits)) { |
Line 202... | Line 195... | ||
202 | int len = (nlongs - 1) * sizeof(unsigned long); |
195 | unsigned int len = (nlongs - 1) * sizeof(unsigned long); |
203 | memset(dst, 0xff, len); |
196 | memset(dst, 0xff, len); |
204 | } |
197 | } |
205 | dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); |
198 | dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); |
206 | } |
199 | } |
207 | 200 | ||
208 | static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, |
201 | static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, |
209 | int nbits) |
202 | unsigned int nbits) |
210 | { |
203 | { |
211 | if (small_const_nbits(nbits)) |
204 | if (small_const_nbits(nbits)) |
Line 212... | Line 205... | ||
212 | *dst = *src; |
205 | *dst = *src; |
Line 288... | Line 281... | ||
288 | 281 | ||
289 | static inline int bitmap_empty(const unsigned long *src, unsigned nbits) |
282 | static inline int bitmap_empty(const unsigned long *src, unsigned nbits) |
290 | { |
283 | { |
291 | if (small_const_nbits(nbits)) |
284 | if (small_const_nbits(nbits)) |
292 | return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); |
285 | return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); |
293 | else |
286 | |
294 | return __bitmap_empty(src, nbits); |
287 | return find_first_bit(src, nbits) == nbits; |
Line 295... | Line 288... | ||
295 | } |
288 | } |
296 | 289 | ||
297 | static inline int bitmap_full(const unsigned long *src, unsigned int nbits) |
290 | static inline int bitmap_full(const unsigned long *src, unsigned int nbits) |
298 | { |
291 | { |
299 | if (small_const_nbits(nbits)) |
292 | if (small_const_nbits(nbits)) |
300 | return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); |
293 | return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); |
301 | else |
294 | |
Line 302... | Line 295... | ||
302 | return __bitmap_full(src, nbits); |
295 | return find_first_zero_bit(src, nbits) == nbits; |
303 | } |
296 | } |
304 | 297 | ||
305 | static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) |
298 | static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits) |
306 | { |
299 | { |
307 | if (small_const_nbits(nbits)) |
300 | if (small_const_nbits(nbits)) |
Line 308... | Line 301... | ||
308 | return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); |
301 | return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); |
309 | return __bitmap_weight(src, nbits); |
302 | return __bitmap_weight(src, nbits); |
310 | } |
303 | } |
311 | 304 | ||
312 | static inline void bitmap_shift_right(unsigned long *dst, |
305 | static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src, |
313 | const unsigned long *src, int n, int nbits) |
306 | unsigned int shift, int nbits) |
314 | { |
307 | { |
315 | if (small_const_nbits(nbits)) |
308 | if (small_const_nbits(nbits)) |
Line 316... | Line 309... | ||
316 | *dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> n; |
309 | *dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> shift; |
317 | else |
310 | else |
318 | __bitmap_shift_right(dst, src, n, nbits); |
311 | __bitmap_shift_right(dst, src, shift, nbits); |
319 | } |
312 | } |
320 | 313 | ||
321 | static inline void bitmap_shift_left(unsigned long *dst, |
314 | static inline void bitmap_shift_left(unsigned long *dst, const unsigned long *src, |
322 | const unsigned long *src, int n, int nbits) |
315 | unsigned int shift, unsigned int nbits) |
323 | { |
316 | { |
Line 324... | Line 317... | ||
324 | if (small_const_nbits(nbits)) |
317 | if (small_const_nbits(nbits)) |
325 | *dst = (*src << n) & BITMAP_LAST_WORD_MASK(nbits); |
318 | *dst = (*src << shift) & BITMAP_LAST_WORD_MASK(nbits); |
326 | else |
319 | else |