Merge tag 'trace-v6.13-rc7-2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[linux.git] / drivers / firmware / efi / libstub / bitmap.c
blob5c9bba0d549be20e984d3ed3906aa9f8dd459d62
1 #include <linux/bitmap.h>
3 void __bitmap_set(unsigned long *map, unsigned int start, int len)
5 unsigned long *p = map + BIT_WORD(start);
6 const unsigned int size = start + len;
7 int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);
8 unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);
10 while (len - bits_to_set >= 0) {
11 *p |= mask_to_set;
12 len -= bits_to_set;
13 bits_to_set = BITS_PER_LONG;
14 mask_to_set = ~0UL;
15 p++;
17 if (len) {
18 mask_to_set &= BITMAP_LAST_WORD_MASK(size);
19 *p |= mask_to_set;
23 void __bitmap_clear(unsigned long *map, unsigned int start, int len)
25 unsigned long *p = map + BIT_WORD(start);
26 const unsigned int size = start + len;
27 int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
28 unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
30 while (len - bits_to_clear >= 0) {
31 *p &= ~mask_to_clear;
32 len -= bits_to_clear;
33 bits_to_clear = BITS_PER_LONG;
34 mask_to_clear = ~0UL;
35 p++;
37 if (len) {
38 mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
39 *p &= ~mask_to_clear;