52,16 → 52,13 |
* bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) |
* bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap |
* bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz |
* bitmap_scnprintf(buf, len, src, nbits) Print bitmap src to buf |
* bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf |
* bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf |
* bitmap_scnlistprintf(buf, len, src, nbits) Print bitmap src as list to buf |
* bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf |
* bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf |
* bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region |
* bitmap_release_region(bitmap, pos, order) Free specified bit region |
* bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region |
* bitmap_print_to_pagebuf(list, buf, mask, nbits) Print bitmap src as list/hex |
*/ |
|
/* |
96,10 → 93,10 |
const unsigned long *bitmap2, unsigned int nbits); |
extern void __bitmap_complement(unsigned long *dst, const unsigned long *src, |
unsigned int nbits); |
extern void __bitmap_shift_right(unsigned long *dst, |
const unsigned long *src, int shift, int bits); |
extern void __bitmap_shift_left(unsigned long *dst, |
const unsigned long *src, int shift, int bits); |
extern void __bitmap_shift_right(unsigned long *dst, const unsigned long *src, |
unsigned int shift, unsigned int nbits); |
extern void __bitmap_shift_left(unsigned long *dst, const unsigned long *src, |
unsigned int shift, unsigned int nbits); |
extern int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1, |
const unsigned long *bitmap2, unsigned int nbits); |
extern void __bitmap_or(unsigned long *dst, const unsigned long *bitmap1, |
147,59 → 144,55 |
align_mask, 0); |
} |
|
extern int bitmap_scnprintf(char *buf, unsigned int len, |
const unsigned long *src, int nbits); |
extern int __bitmap_parse(const char *buf, unsigned int buflen, int is_user, |
unsigned long *dst, int nbits); |
extern int bitmap_parse_user(const char __user *ubuf, unsigned int ulen, |
unsigned long *dst, int nbits); |
extern int bitmap_scnlistprintf(char *buf, unsigned int len, |
const unsigned long *src, int nbits); |
extern int bitmap_parselist(const char *buf, unsigned long *maskp, |
int nmaskbits); |
extern int bitmap_parselist_user(const char __user *ubuf, unsigned int ulen, |
unsigned long *dst, int nbits); |
extern void bitmap_remap(unsigned long *dst, const unsigned long *src, |
const unsigned long *old, const unsigned long *new, int bits); |
const unsigned long *old, const unsigned long *new, unsigned int nbits); |
extern int bitmap_bitremap(int oldbit, |
const unsigned long *old, const unsigned long *new, int bits); |
extern void bitmap_onto(unsigned long *dst, const unsigned long *orig, |
const unsigned long *relmap, int bits); |
const unsigned long *relmap, unsigned int bits); |
extern void bitmap_fold(unsigned long *dst, const unsigned long *orig, |
int sz, int bits); |
unsigned int sz, unsigned int nbits); |
extern int bitmap_find_free_region(unsigned long *bitmap, unsigned int bits, int order); |
extern void bitmap_release_region(unsigned long *bitmap, unsigned int pos, int order); |
extern int bitmap_allocate_region(unsigned long *bitmap, unsigned int pos, int order); |
extern void bitmap_copy_le(void *dst, const unsigned long *src, int nbits); |
extern int bitmap_ord_to_pos(const unsigned long *bitmap, int n, int bits); |
#ifdef __BIG_ENDIAN |
extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, unsigned int nbits); |
#else |
#define bitmap_copy_le bitmap_copy |
#endif |
extern unsigned int bitmap_ord_to_pos(const unsigned long *bitmap, unsigned int ord, unsigned int nbits); |
extern int bitmap_print_to_pagebuf(bool list, char *buf, |
const unsigned long *maskp, int nmaskbits); |
|
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) % BITS_PER_LONG)) |
#define BITMAP_LAST_WORD_MASK(nbits) \ |
( \ |
((nbits) % BITS_PER_LONG) ? \ |
(1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL \ |
) |
#define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) |
#define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) |
|
#define small_const_nbits(nbits) \ |
(__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) |
|
static inline void bitmap_zero(unsigned long *dst, int nbits) |
static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) |
{ |
if (small_const_nbits(nbits)) |
*dst = 0UL; |
else { |
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
memset(dst, 0, len); |
} |
} |
|
static inline void bitmap_fill(unsigned long *dst, int nbits) |
static inline void bitmap_fill(unsigned long *dst, unsigned int nbits) |
{ |
size_t nlongs = BITS_TO_LONGS(nbits); |
unsigned int nlongs = BITS_TO_LONGS(nbits); |
if (!small_const_nbits(nbits)) { |
int len = (nlongs - 1) * sizeof(unsigned long); |
unsigned int len = (nlongs - 1) * sizeof(unsigned long); |
memset(dst, 0xff, len); |
} |
dst[nlongs - 1] = BITMAP_LAST_WORD_MASK(nbits); |
206,12 → 199,12 |
} |
|
static inline void bitmap_copy(unsigned long *dst, const unsigned long *src, |
int nbits) |
unsigned int nbits) |
{ |
if (small_const_nbits(nbits)) |
*dst = *src; |
else { |
int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); |
memcpy(dst, src, len); |
} |
} |
290,8 → 283,8 |
{ |
if (small_const_nbits(nbits)) |
return ! (*src & BITMAP_LAST_WORD_MASK(nbits)); |
else |
return __bitmap_empty(src, nbits); |
|
return find_first_bit(src, nbits) == nbits; |
} |
|
static inline int bitmap_full(const unsigned long *src, unsigned int nbits) |
298,11 → 291,11 |
{ |
if (small_const_nbits(nbits)) |
return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); |
else |
return __bitmap_full(src, nbits); |
|
return find_first_zero_bit(src, nbits) == nbits; |
} |
|
static inline int bitmap_weight(const unsigned long *src, unsigned int nbits) |
static __always_inline int bitmap_weight(const unsigned long *src, unsigned int nbits) |
{ |
if (small_const_nbits(nbits)) |
return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits)); |
309,22 → 302,22 |
return __bitmap_weight(src, nbits); |
} |
|
static inline void bitmap_shift_right(unsigned long *dst, |
const unsigned long *src, int n, int nbits) |
static inline void bitmap_shift_right(unsigned long *dst, const unsigned long *src, |
unsigned int shift, int nbits) |
{ |
if (small_const_nbits(nbits)) |
*dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> n; |
*dst = (*src & BITMAP_LAST_WORD_MASK(nbits)) >> shift; |
else |
__bitmap_shift_right(dst, src, n, nbits); |
__bitmap_shift_right(dst, src, shift, nbits); |
} |
|
static inline void bitmap_shift_left(unsigned long *dst, |
const unsigned long *src, int n, int nbits) |
static inline void bitmap_shift_left(unsigned long *dst, const unsigned long *src, |
unsigned int shift, unsigned int nbits) |
{ |
if (small_const_nbits(nbits)) |
*dst = (*src << n) & BITMAP_LAST_WORD_MASK(nbits); |
*dst = (*src << shift) & BITMAP_LAST_WORD_MASK(nbits); |
else |
__bitmap_shift_left(dst, src, n, nbits); |
__bitmap_shift_left(dst, src, shift, nbits); |
} |
|
static inline int bitmap_parse(const char *buf, unsigned int buflen, |