8 #include <linux/export.h>
10 #include <linux/ctype.h>
11 #include <linux/errno.h>
12 #include <linux/bitmap.h>
13 #include <linux/bitops.h>
15 #include <asm/uaccess.h>
46 for (k = 0; k < lim; ++
k)
61 for (k = 0; k < lim; ++
k)
74 const unsigned long *bitmap2,
int bits)
77 for (k = 0; k < lim; ++
k)
78 if (bitmap1[k] != bitmap2[k])
92 for (k = 0; k < lim; ++
k)
112 const unsigned long *
src,
int shift,
int bits)
117 for (k = 0; off + k < lim; ++
k) {
118 unsigned long upper, lower;
124 if (!rem || off + k + 1 >= lim)
127 upper = src[off + k + 1];
128 if (off + k + 1 == lim - 1 &&
left)
131 lower = src[off +
k];
132 if (
left && off + k == lim - 1)
135 if (
left && k == lim - 1)
139 memset(&dst[lim - off], 0, off*
sizeof(
unsigned long));
157 const unsigned long *
src,
int shift,
int bits)
161 for (k = lim - off - 1; k >= 0; --
k) {
162 unsigned long upper, lower;
173 if (
left && k == lim - 1)
174 upper &= (1
UL <<
left) - 1;
175 dst[k + off] = lower >> (
BITS_PER_LONG - rem) | upper << rem;
176 if (
left && k + off == lim - 1)
177 dst[k + off] &= (1
UL <<
left) - 1;
180 memset(dst, 0, off*
sizeof(
unsigned long));
185 const unsigned long *bitmap2,
int bits)
191 for (k = 0; k <
nr; k++)
192 result |= (dst[k] = bitmap1[k] & bitmap2[k]);
198 const unsigned long *bitmap2,
int bits)
203 for (k = 0; k <
nr; k++)
204 dst[k] = bitmap1[k] | bitmap2[k];
209 const unsigned long *bitmap2,
int bits)
214 for (k = 0; k <
nr; k++)
215 dst[k] = bitmap1[k] ^ bitmap2[k];
220 const unsigned long *bitmap2,
int bits)
226 for (k = 0; k <
nr; k++)
227 result |= (dst[k] = bitmap1[k] & ~bitmap2[k]);
233 const unsigned long *bitmap2,
int bits)
236 for (k = 0; k < lim; ++
k)
237 if (bitmap1[k] & bitmap2[k])
248 const unsigned long *bitmap2,
int bits)
251 for (k = 0; k < lim; ++
k)
252 if (bitmap1[k] & ~bitmap2[k])
266 for (k = 0; k < lim; k++)
267 w += hweight_long(bitmap[k]);
278 unsigned long *
p = map +
BIT_WORD(start);
279 const int size = start +
nr;
283 while (nr - bits_to_set >= 0) {
299 unsigned long *
p = map +
BIT_WORD(start);
300 const int size = start +
nr;
304 while (nr - bits_to_clear >= 0) {
305 *p &= ~mask_to_clear;
308 mask_to_clear = ~0
UL;
313 *p &= ~mask_to_clear;
334 unsigned long align_mask)
361 #define nbits_to_hold_value(val) fls(val)
376 const unsigned long *maskp,
int nmaskbits)
380 const char *sep =
"";
384 chunksz = nmaskbits & (
CHUNKSZ - 1);
390 chunkmask = ((1ULL << chunksz) - 1);
393 val = (maskp[
word] >>
bit) & chunkmask;
394 len +=
scnprintf(buf+len, buflen-len,
"%s%0*lx", sep,
420 int is_user,
unsigned long *maskp,
423 int c, old_c, totaldigits, ndigits, nchunks, nbits;
427 bitmap_zero(maskp, nmaskbits);
429 nchunks = nbits = totaldigits = c = 0;
451 if (totaldigits && c &&
isspace(old_c))
455 if (c ==
'\0' || c ==
',')
466 if (chunk & ~((1
UL << (
CHUNKSZ - 4)) - 1))
470 ndigits++; totaldigits++;
474 if (nchunks == 0 && chunk == 0)
481 if (nbits > nmaskbits)
483 }
while (buflen && c ==
',');
505 unsigned int ulen,
unsigned long *maskp,
511 ulen, 1, maskp, nmaskbits);
524 static inline int bscnl_emit(
char *
buf,
int buflen,
int rbot,
int rtop,
int len)
527 len +=
scnprintf(buf + len, buflen - len,
",");
529 len +=
scnprintf(buf + len, buflen - len,
"%d", rbot);
531 len +=
scnprintf(buf + len, buflen - len,
"%d-%d", rbot, rtop);
552 const unsigned long *maskp,
int nmaskbits)
563 while (cur < nmaskbits) {
566 if (cur >= nmaskbits || cur > rtop + 1) {
567 len = bscnl_emit(buf, buflen, rbot, rtop, len);
595 static int __bitmap_parselist(
const char *buf,
unsigned int buflen,
596 int is_user,
unsigned long *maskp,
600 int c, old_c, totaldigits;
605 bitmap_zero(maskp, nmaskbits);
628 if (totaldigits && c &&
isspace(old_c))
632 if (c ==
'\0' || c ==
',')
636 if (exp_digit || in_range)
647 b = b * 10 + (c -
'0');
661 }
while (buflen && c ==
',');
667 char *nl =
strchr(bp,
'\n');
675 return __bitmap_parselist(bp, len, 0, maskp, nmaskbits);
696 unsigned int ulen,
unsigned long *maskp,
701 return __bitmap_parselist((
const char __force *)ubuf,
702 ulen, 1, maskp, nmaskbits);
725 static int bitmap_pos_to_ord(
const unsigned long *buf,
int pos,
int bits)
729 if (pos < 0 || pos >= bits || !
test_bit(pos, buf))
765 if (ord >= 0 && ord < bits) {
772 if (i < bits && ord == 0)
812 const unsigned long *old,
const unsigned long *
new,
819 bitmap_zero(dst, bits);
821 w = bitmap_weight(
new, bits);
823 int n = bitmap_pos_to_ord(old, oldbit, bits);
860 const unsigned long *
new,
int bits)
862 int w = bitmap_weight(
new, bits);
863 int n = bitmap_pos_to_ord(old, oldbit, bits);
972 const unsigned long *relmap,
int bits)
978 bitmap_zero(dst, bits);
1018 bitmap_zero(dst, bits);
1049 static int __reg_op(
unsigned long *
bitmap,
int pos,
int order,
int reg_op)
1064 nbits_reg = 1 <<
order;
1074 mask = (1
UL << (nbitsinlong - 1));
1080 for (i = 0; i < nlongs_reg; i++) {
1081 if (bitmap[index + i] & mask)
1088 for (i = 0; i < nlongs_reg; i++)
1089 bitmap[index + i] |= mask;
1093 for (i = 0; i < nlongs_reg; i++)
1094 bitmap[index + i] &= ~mask;
1119 for (pos = 0 ; (end = pos + (1 <<
order)) <=
bits; pos =
end) {
1176 unsigned long *
d =
dst;