aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bitmap.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/bitmap.h')
-rw-r--r--include/linux/bitmap.h114
1 files changed, 62 insertions, 52 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 19748a5b0e77..3489253e38fc 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -22,65 +22,74 @@
22 * See lib/bitmap.c for more details. 22 * See lib/bitmap.c for more details.
23 */ 23 */
24 24
25/* 25/**
26 * DOC: bitmap overview
27 *
26 * The available bitmap operations and their rough meaning in the 28 * The available bitmap operations and their rough meaning in the
27 * case that the bitmap is a single unsigned long are thus: 29 * case that the bitmap is a single unsigned long are thus:
28 * 30 *
29 * Note that nbits should be always a compile time evaluable constant. 31 * Note that nbits should be always a compile time evaluable constant.
30 * Otherwise many inlines will generate horrible code. 32 * Otherwise many inlines will generate horrible code.
31 * 33 *
32 * bitmap_zero(dst, nbits) *dst = 0UL 34 * ::
33 * bitmap_fill(dst, nbits) *dst = ~0UL 35 *
34 * bitmap_copy(dst, src, nbits) *dst = *src 36 * bitmap_zero(dst, nbits) *dst = 0UL
35 * bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2 37 * bitmap_fill(dst, nbits) *dst = ~0UL
36 * bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2 38 * bitmap_copy(dst, src, nbits) *dst = *src
37 * bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2 39 * bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2
38 * bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2) 40 * bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2
39 * bitmap_complement(dst, src, nbits) *dst = ~(*src) 41 * bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2
40 * bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal? 42 * bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2)
41 * bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap? 43 * bitmap_complement(dst, src, nbits) *dst = ~(*src)
42 * bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2? 44 * bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal?
43 * bitmap_empty(src, nbits) Are all bits zero in *src? 45 * bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
44 * bitmap_full(src, nbits) Are all bits set in *src? 46 * bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2?
45 * bitmap_weight(src, nbits) Hamming Weight: number set bits 47 * bitmap_empty(src, nbits) Are all bits zero in *src?
46 * bitmap_set(dst, pos, nbits) Set specified bit area 48 * bitmap_full(src, nbits) Are all bits set in *src?
47 * bitmap_clear(dst, pos, nbits) Clear specified bit area 49 * bitmap_weight(src, nbits) Hamming Weight: number set bits
48 * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area 50 * bitmap_set(dst, pos, nbits) Set specified bit area
49 * bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above 51 * bitmap_clear(dst, pos, nbits) Clear specified bit area
50 * bitmap_shift_right(dst, src, n, nbits) *dst = *src >> n 52 * bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
51 * bitmap_shift_left(dst, src, n, nbits) *dst = *src << n 53 * bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above
52 * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) 54 * bitmap_shift_right(dst, src, n, nbits) *dst = *src >> n
53 * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) 55 * bitmap_shift_left(dst, src, n, nbits) *dst = *src << n
54 * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap 56 * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src)
55 * bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz 57 * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit)
56 * bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf 58 * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap
57 * bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf 59 * bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz
58 * bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf 60 * bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf
59 * bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf 61 * bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf
60 * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region 62 * bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf
61 * bitmap_release_region(bitmap, pos, order) Free specified bit region 63 * bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf
62 * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region 64 * bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region
63 * bitmap_from_u32array(dst, nbits, buf, nwords) *dst = *buf (nwords 32b words) 65 * bitmap_release_region(bitmap, pos, order) Free specified bit region
64 * bitmap_to_u32array(buf, nwords, src, nbits) *buf = *dst (nwords 32b words) 66 * bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region
67 * bitmap_from_u32array(dst, nbits, buf, nwords) *dst = *buf (nwords 32b words)
68 * bitmap_to_u32array(buf, nwords, src, nbits) *buf = *dst (nwords 32b words)
69 *
65 */ 70 */
66 71
67/* 72/**
68 * Also the following operations in asm/bitops.h apply to bitmaps. 73 * DOC: bitmap bitops
74 *
75 * Also the following operations in asm/bitops.h apply to bitmaps.::
76 *
77 * set_bit(bit, addr) *addr |= bit
78 * clear_bit(bit, addr) *addr &= ~bit
79 * change_bit(bit, addr) *addr ^= bit
80 * test_bit(bit, addr) Is bit set in *addr?
81 * test_and_set_bit(bit, addr) Set bit and return old value
82 * test_and_clear_bit(bit, addr) Clear bit and return old value
83 * test_and_change_bit(bit, addr) Change bit and return old value
84 * find_first_zero_bit(addr, nbits) Position first zero bit in *addr
85 * find_first_bit(addr, nbits) Position first set bit in *addr
86 * find_next_zero_bit(addr, nbits, bit) Position next zero bit in *addr >= bit
87 * find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
69 * 88 *
70 * set_bit(bit, addr) *addr |= bit
71 * clear_bit(bit, addr) *addr &= ~bit
72 * change_bit(bit, addr) *addr ^= bit
73 * test_bit(bit, addr) Is bit set in *addr?
74 * test_and_set_bit(bit, addr) Set bit and return old value
75 * test_and_clear_bit(bit, addr) Clear bit and return old value
76 * test_and_change_bit(bit, addr) Change bit and return old value
77 * find_first_zero_bit(addr, nbits) Position first zero bit in *addr
78 * find_first_bit(addr, nbits) Position first set bit in *addr
79 * find_next_zero_bit(addr, nbits, bit) Position next zero bit in *addr >= bit
80 * find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
81 */ 89 */
82 90
83/* 91/**
92 * DOC: declare bitmap
84 * The DECLARE_BITMAP(name,bits) macro, in linux/types.h, can be used 93 * The DECLARE_BITMAP(name,bits) macro, in linux/types.h, can be used
85 * to declare an array named 'name' of just enough unsigned longs to 94 * to declare an array named 'name' of just enough unsigned longs to
86 * contain all bit positions from 0 to 'bits' - 1. 95 * contain all bit positions from 0 to 'bits' - 1.
@@ -361,8 +370,9 @@ static inline int bitmap_parse(const char *buf, unsigned int buflen,
361 return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits); 370 return __bitmap_parse(buf, buflen, 0, maskp, nmaskbits);
362} 371}
363 372
364/* 373/**
365 * BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap. 374 * BITMAP_FROM_U64() - Represent u64 value in the format suitable for bitmap.
375 * @n: u64 value
366 * 376 *
367 * Linux bitmaps are internally arrays of unsigned longs, i.e. 32-bit 377 * Linux bitmaps are internally arrays of unsigned longs, i.e. 32-bit
368 * integers in 32-bit environment, and 64-bit integers in 64-bit one. 378 * integers in 32-bit environment, and 64-bit integers in 64-bit one.
@@ -393,14 +403,14 @@ static inline int bitmap_parse(const char *buf, unsigned int buflen,
393 ((unsigned long) ((u64)(n) >> 32)) 403 ((unsigned long) ((u64)(n) >> 32))
394#endif 404#endif
395 405
396/* 406/**
397 * bitmap_from_u64 - Check and swap words within u64. 407 * bitmap_from_u64 - Check and swap words within u64.
398 * @mask: source bitmap 408 * @mask: source bitmap
399 * @dst: destination bitmap 409 * @dst: destination bitmap
400 * 410 *
401 * In 32-bit Big Endian kernel, when using (u32 *)(&val)[*] 411 * In 32-bit Big Endian kernel, when using ``(u32 *)(&val)[*]``
402 * to read u64 mask, we will get the wrong word. 412 * to read u64 mask, we will get the wrong word.
403 * That is "(u32 *)(&val)[0]" gets the upper 32 bits, 413 * That is ``(u32 *)(&val)[0]`` gets the upper 32 bits,
404 * but we expect the lower 32-bits of u64. 414 * but we expect the lower 32-bits of u64.
405 */ 415 */
406static inline void bitmap_from_u64(unsigned long *dst, u64 mask) 416static inline void bitmap_from_u64(unsigned long *dst, u64 mask)