diff options
Diffstat (limited to 'lib/bitmap.c')
| -rw-r--r-- | lib/bitmap.c | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c index cd250a2e14cb..324ea9eab8c1 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c | |||
| @@ -12,6 +12,8 @@ | |||
| 12 | #include <linux/bitmap.h> | 12 | #include <linux/bitmap.h> |
| 13 | #include <linux/bitops.h> | 13 | #include <linux/bitops.h> |
| 14 | #include <linux/bug.h> | 14 | #include <linux/bug.h> |
| 15 | |||
| 16 | #include <asm/page.h> | ||
| 15 | #include <asm/uaccess.h> | 17 | #include <asm/uaccess.h> |
| 16 | 18 | ||
| 17 | /* | 19 | /* |
| @@ -131,7 +133,9 @@ void __bitmap_shift_right(unsigned long *dst, | |||
| 131 | lower = src[off + k]; | 133 | lower = src[off + k]; |
| 132 | if (left && off + k == lim - 1) | 134 | if (left && off + k == lim - 1) |
| 133 | lower &= mask; | 135 | lower &= mask; |
| 134 | dst[k] = upper << (BITS_PER_LONG - rem) | lower >> rem; | 136 | dst[k] = lower >> rem; |
| 137 | if (rem) | ||
| 138 | dst[k] |= upper << (BITS_PER_LONG - rem); | ||
| 135 | if (left && k == lim - 1) | 139 | if (left && k == lim - 1) |
| 136 | dst[k] &= mask; | 140 | dst[k] &= mask; |
| 137 | } | 141 | } |
| @@ -172,7 +176,9 @@ void __bitmap_shift_left(unsigned long *dst, | |||
| 172 | upper = src[k]; | 176 | upper = src[k]; |
| 173 | if (left && k == lim - 1) | 177 | if (left && k == lim - 1) |
| 174 | upper &= (1UL << left) - 1; | 178 | upper &= (1UL << left) - 1; |
| 175 | dst[k + off] = lower >> (BITS_PER_LONG - rem) | upper << rem; | 179 | dst[k + off] = upper << rem; |
| 180 | if (rem) | ||
| 181 | dst[k + off] |= lower >> (BITS_PER_LONG - rem); | ||
| 176 | if (left && k + off == lim - 1) | 182 | if (left && k + off == lim - 1) |
| 177 | dst[k + off] &= (1UL << left) - 1; | 183 | dst[k + off] &= (1UL << left) - 1; |
| 178 | } | 184 | } |
| @@ -322,30 +328,32 @@ void bitmap_clear(unsigned long *map, unsigned int start, int len) | |||
| 322 | } | 328 | } |
| 323 | EXPORT_SYMBOL(bitmap_clear); | 329 | EXPORT_SYMBOL(bitmap_clear); |
| 324 | 330 | ||
| 325 | /* | 331 | /** |
| 326 | * bitmap_find_next_zero_area - find a contiguous aligned zero area | 332 | * bitmap_find_next_zero_area_off - find a contiguous aligned zero area |
| 327 | * @map: The address to base the search on | 333 | * @map: The address to base the search on |
| 328 | * @size: The bitmap size in bits | 334 | * @size: The bitmap size in bits |
| 329 | * @start: The bitnumber to start searching at | 335 | * @start: The bitnumber to start searching at |
| 330 | * @nr: The number of zeroed bits we're looking for | 336 | * @nr: The number of zeroed bits we're looking for |
| 331 | * @align_mask: Alignment mask for zero area | 337 | * @align_mask: Alignment mask for zero area |
| 338 | * @align_offset: Alignment offset for zero area. | ||
| 332 | * | 339 | * |
| 333 | * The @align_mask should be one less than a power of 2; the effect is that | 340 | * The @align_mask should be one less than a power of 2; the effect is that |
| 334 | * the bit offset of all zero areas this function finds is multiples of that | 341 | * the bit offset of all zero areas this function finds plus @align_offset |
| 335 | * power of 2. A @align_mask of 0 means no alignment is required. | 342 | * is multiple of that power of 2. |
| 336 | */ | 343 | */ |
| 337 | unsigned long bitmap_find_next_zero_area(unsigned long *map, | 344 | unsigned long bitmap_find_next_zero_area_off(unsigned long *map, |
| 338 | unsigned long size, | 345 | unsigned long size, |
| 339 | unsigned long start, | 346 | unsigned long start, |
| 340 | unsigned int nr, | 347 | unsigned int nr, |
| 341 | unsigned long align_mask) | 348 | unsigned long align_mask, |
| 349 | unsigned long align_offset) | ||
| 342 | { | 350 | { |
| 343 | unsigned long index, end, i; | 351 | unsigned long index, end, i; |
| 344 | again: | 352 | again: |
| 345 | index = find_next_zero_bit(map, size, start); | 353 | index = find_next_zero_bit(map, size, start); |
| 346 | 354 | ||
| 347 | /* Align allocation */ | 355 | /* Align allocation */ |
| 348 | index = __ALIGN_MASK(index, align_mask); | 356 | index = __ALIGN_MASK(index + align_offset, align_mask) - align_offset; |
| 349 | 357 | ||
| 350 | end = index + nr; | 358 | end = index + nr; |
| 351 | if (end > size) | 359 | if (end > size) |
| @@ -357,7 +365,7 @@ again: | |||
| 357 | } | 365 | } |
| 358 | return index; | 366 | return index; |
| 359 | } | 367 | } |
| 360 | EXPORT_SYMBOL(bitmap_find_next_zero_area); | 368 | EXPORT_SYMBOL(bitmap_find_next_zero_area_off); |
| 361 | 369 | ||
| 362 | /* | 370 | /* |
| 363 | * Bitmap printing & parsing functions: first version by Nadia Yvette Chambers, | 371 | * Bitmap printing & parsing functions: first version by Nadia Yvette Chambers, |
| @@ -580,6 +588,33 @@ int bitmap_scnlistprintf(char *buf, unsigned int buflen, | |||
| 580 | EXPORT_SYMBOL(bitmap_scnlistprintf); | 588 | EXPORT_SYMBOL(bitmap_scnlistprintf); |
| 581 | 589 | ||
| 582 | /** | 590 | /** |
| 591 | * bitmap_print_to_pagebuf - convert bitmap to list or hex format ASCII string | ||
| 592 | * @list: indicates whether the bitmap must be list | ||
| 593 | * @buf: page aligned buffer into which string is placed | ||
| 594 | * @maskp: pointer to bitmap to convert | ||
| 595 | * @nmaskbits: size of bitmap, in bits | ||
| 596 | * | ||
| 597 | * Output format is a comma-separated list of decimal numbers and | ||
| 598 | * ranges if list is specified or hex digits grouped into comma-separated | ||
| 599 | * sets of 8 digits/set. Returns the number of characters written to buf. | ||
| 600 | */ | ||
| 601 | int bitmap_print_to_pagebuf(bool list, char *buf, const unsigned long *maskp, | ||
| 602 | int nmaskbits) | ||
| 603 | { | ||
| 604 | ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf - 2; | ||
| 605 | int n = 0; | ||
| 606 | |||
| 607 | if (len > 1) { | ||
| 608 | n = list ? bitmap_scnlistprintf(buf, len, maskp, nmaskbits) : | ||
| 609 | bitmap_scnprintf(buf, len, maskp, nmaskbits); | ||
| 610 | buf[n++] = '\n'; | ||
| 611 | buf[n] = '\0'; | ||
| 612 | } | ||
| 613 | return n; | ||
| 614 | } | ||
| 615 | EXPORT_SYMBOL(bitmap_print_to_pagebuf); | ||
| 616 | |||
| 617 | /** | ||
| 583 | * __bitmap_parselist - convert list format ASCII string to bitmap | 618 | * __bitmap_parselist - convert list format ASCII string to bitmap |
| 584 | * @buf: read nul-terminated user string from this buffer | 619 | * @buf: read nul-terminated user string from this buffer |
| 585 | * @buflen: buffer size in bytes. If string is smaller than this | 620 | * @buflen: buffer size in bytes. If string is smaller than this |
