Skip to content

Commit 7d7363e

Browse files
rddunlapJonathan Corbet
authored andcommitted
documentation: kernel-api: add more info on bitmap functions
There are some good comments about bitmap operations in lib/bitmap.c and include/linux/bitmap.h, so format them for document generation and pull them into core-api/kernel-api.rst. I converted the "tables" of functions from using tabs to using spaces so that they are more readable in the source file and in the generated output. Signed-off-by: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent 718d50e commit 7d7363e

3 files changed

Lines changed: 72 additions & 49 deletions

File tree

‎Documentation/core-api/kernel-api.rst‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ The Linux kernel provides more basic utility functions.
5353
Bitmap Operations
5454
-----------------
5555

56+
.. kernel-doc:: lib/bitmap.c
57+
:doc: bitmap introduction
58+
59+
.. kernel-doc:: include/linux/bitmap.h
60+
:doc: declare bitmap
61+
62+
.. kernel-doc:: include/linux/bitmap.h
63+
:doc: bitmap overview
64+
65+
.. kernel-doc:: include/linux/bitmap.h
66+
:doc: bitmap bitops
67+
5668
.. kernel-doc:: lib/bitmap.c
5769
:export:
5870

‎include/linux/bitmap.h‎

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -21,65 +21,74 @@
2121
* See lib/bitmap.c for more details.
2222
*/
2323

24-
/*
24+
/**
25+
* DOC: bitmap overview
26+
*
2527
* The available bitmap operations and their rough meaning in the
2628
* case that the bitmap is a single unsigned long are thus:
2729
*
2830
* Note that nbits should be always a compile time evaluable constant.
2931
* Otherwise many inlines will generate horrible code.
3032
*
31-
* bitmap_zero(dst, nbits) *dst = 0UL
32-
* bitmap_fill(dst, nbits) *dst = ~0UL
33-
* bitmap_copy(dst, src, nbits) *dst = *src
34-
* bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2
35-
* bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2
36-
* bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2
37-
* bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2)
38-
* bitmap_complement(dst, src, nbits) *dst = ~(*src)
39-
* bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal?
40-
* bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
41-
* bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2?
42-
* bitmap_empty(src, nbits) Are all bits zero in *src?
43-
* bitmap_full(src, nbits) Are all bits set in *src?
44-
* bitmap_weight(src, nbits) Hamming Weight: number set bits
45-
* bitmap_set(dst, pos, nbits) Set specified bit area
46-
* bitmap_clear(dst, pos, nbits) Clear specified bit area
47-
* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
48-
* bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above
49-
* bitmap_shift_right(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)
52-
* bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit)
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
55-
* bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf
56-
* bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf
57-
* bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf
58-
* bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf
59-
* bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region
60-
* bitmap_release_region(bitmap, pos, order) Free specified bit region
61-
* bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region
62-
* bitmap_from_u32array(dst, nbits, buf, nwords) *dst = *buf (nwords 32b words)
63-
* bitmap_to_u32array(buf, nwords, src, nbits) *buf = *dst (nwords 32b words)
33+
* ::
34+
*
35+
* bitmap_zero(dst, nbits) *dst = 0UL
36+
* bitmap_fill(dst, nbits) *dst = ~0UL
37+
* bitmap_copy(dst, src, nbits) *dst = *src
38+
* bitmap_and(dst, src1, src2, nbits) *dst = *src1 & *src2
39+
* bitmap_or(dst, src1, src2, nbits) *dst = *src1 | *src2
40+
* bitmap_xor(dst, src1, src2, nbits) *dst = *src1 ^ *src2
41+
* bitmap_andnot(dst, src1, src2, nbits) *dst = *src1 & ~(*src2)
42+
* bitmap_complement(dst, src, nbits) *dst = ~(*src)
43+
* bitmap_equal(src1, src2, nbits) Are *src1 and *src2 equal?
44+
* bitmap_intersects(src1, src2, nbits) Do *src1 and *src2 overlap?
45+
* bitmap_subset(src1, src2, nbits) Is *src1 a subset of *src2?
46+
* bitmap_empty(src, nbits) Are all bits zero in *src?
47+
* bitmap_full(src, nbits) Are all bits set in *src?
48+
* bitmap_weight(src, nbits) Hamming Weight: number set bits
49+
* bitmap_set(dst, pos, nbits) Set specified bit area
50+
* bitmap_clear(dst, pos, nbits) Clear specified bit area
51+
* bitmap_find_next_zero_area(buf, len, pos, n, mask) Find bit free area
52+
* bitmap_find_next_zero_area_off(buf, len, pos, n, mask) as above
53+
* bitmap_shift_right(dst, src, n, nbits) *dst = *src >> n
54+
* bitmap_shift_left(dst, src, n, nbits) *dst = *src << n
55+
* bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src)
56+
* bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit)
57+
* bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap
58+
* bitmap_fold(dst, orig, sz, nbits) dst bits = orig bits mod sz
59+
* bitmap_parse(buf, buflen, dst, nbits) Parse bitmap dst from kernel buf
60+
* bitmap_parse_user(ubuf, ulen, dst, nbits) Parse bitmap dst from user buf
61+
* bitmap_parselist(buf, dst, nbits) Parse bitmap dst from kernel buf
62+
* bitmap_parselist_user(buf, dst, nbits) Parse bitmap dst from user buf
63+
* bitmap_find_free_region(bitmap, bits, order) Find and allocate bit region
64+
* bitmap_release_region(bitmap, pos, order) Free specified bit region
65+
* bitmap_allocate_region(bitmap, pos, order) Allocate specified bit region
66+
* bitmap_from_u32array(dst, nbits, buf, nwords) *dst = *buf (nwords 32b words)
67+
* bitmap_to_u32array(buf, nwords, src, nbits) *buf = *dst (nwords 32b words)
68+
*
6469
*/
6570

66-
/*
67-
* Also the following operations in asm/bitops.h apply to bitmaps.
71+
/**
72+
* DOC: bitmap bitops
73+
*
74+
* Also the following operations in asm/bitops.h apply to bitmaps.::
75+
*
76+
* set_bit(bit, addr) *addr |= bit
77+
* clear_bit(bit, addr) *addr &= ~bit
78+
* change_bit(bit, addr) *addr ^= bit
79+
* test_bit(bit, addr) Is bit set in *addr?
80+
* test_and_set_bit(bit, addr) Set bit and return old value
81+
* test_and_clear_bit(bit, addr) Clear bit and return old value
82+
* test_and_change_bit(bit, addr) Change bit and return old value
83+
* find_first_zero_bit(addr, nbits) Position first zero bit in *addr
84+
* find_first_bit(addr, nbits) Position first set bit in *addr
85+
* find_next_zero_bit(addr, nbits, bit) Position next zero bit in *addr >= bit
86+
* find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
6887
*
69-
* set_bit(bit, addr) *addr |= bit
70-
* clear_bit(bit, addr) *addr &= ~bit
71-
* change_bit(bit, addr) *addr ^= bit
72-
* test_bit(bit, addr) Is bit set in *addr?
73-
* test_and_set_bit(bit, addr) Set bit and return old value
74-
* test_and_clear_bit(bit, addr) Clear bit and return old value
75-
* test_and_change_bit(bit, addr) Change bit and return old value
76-
* find_first_zero_bit(addr, nbits) Position first zero bit in *addr
77-
* find_first_bit(addr, nbits) Position first set bit in *addr
78-
* find_next_zero_bit(addr, nbits, bit) Position next zero bit in *addr >= bit
79-
* find_next_bit(addr, nbits, bit) Position next set bit in *addr >= bit
8088
*/
8189

82-
/*
90+
/**
91+
* DOC: declare bitmap
8392
* The DECLARE_BITMAP(name,bits) macro, in linux/types.h, can be used
8493
* to declare an array named 'name' of just enough unsigned longs to
8594
* contain all bit positions from 0 to 'bits' - 1.

‎lib/bitmap.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
#include <asm/page.h>
2020

21-
/*
21+
/**
22+
* DOC: bitmap introduction
23+
*
2224
* bitmaps provide an array of bits, implemented using an an
2325
* array of unsigned longs. The number of valid bits in a
2426
* given bitmap does _not_ need to be an exact multiple of

0 commit comments

Comments
 (0)