aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bitmap.c
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2015-02-10 14:35:36 -0500
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2015-02-10 14:35:36 -0500
commit4ba24fef3eb3b142197135223b90ced2f319cd53 (patch)
treea20c125b27740ec7b4c761b11d801108e1b316b2 /lib/bitmap.c
parent47c1ffb2b6b630894e9a16442611c056ab21c057 (diff)
parent98a4a59ee31a12105a2b84f5b8b515ac2cb208ef (diff)
Merge branch 'next' into for-linus
Prepare first round of input updates for 3.20.
Diffstat (limited to 'lib/bitmap.c')
-rw-r--r--lib/bitmap.c65
1 files changed, 50 insertions, 15 deletions
diff --git a/lib/bitmap.c b/lib/bitmap.c
index 1e031f2c9aba..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}
323EXPORT_SYMBOL(bitmap_clear); 329EXPORT_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 */
337unsigned long bitmap_find_next_zero_area(unsigned long *map, 344unsigned 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;
344again: 352again:
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}
360EXPORT_SYMBOL(bitmap_find_next_zero_area); 368EXPORT_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,
580EXPORT_SYMBOL(bitmap_scnlistprintf); 588EXPORT_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 */
601int 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}
615EXPORT_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
@@ -884,7 +919,7 @@ EXPORT_SYMBOL(bitmap_bitremap);
884 * read it, you're overqualified for your current job.) 919 * read it, you're overqualified for your current job.)
885 * 920 *
886 * In other words, @orig is mapped onto (surjectively) @dst, 921 * In other words, @orig is mapped onto (surjectively) @dst,
887 * using the the map { <n, m> | the n-th bit of @relmap is the 922 * using the map { <n, m> | the n-th bit of @relmap is the
888 * m-th set bit of @relmap }. 923 * m-th set bit of @relmap }.
889 * 924 *
890 * Any set bits in @orig above bit number W, where W is the 925 * Any set bits in @orig above bit number W, where W is the
@@ -932,7 +967,7 @@ EXPORT_SYMBOL(bitmap_bitremap);
932 * 967 *
933 * Further lets say we use the following code, invoking 968 * Further lets say we use the following code, invoking
934 * bitmap_fold() then bitmap_onto, as suggested above to 969 * bitmap_fold() then bitmap_onto, as suggested above to
935 * avoid the possitility of an empty @dst result: 970 * avoid the possibility of an empty @dst result:
936 * 971 *
937 * unsigned long *tmp; // a temporary bitmap's bits 972 * unsigned long *tmp; // a temporary bitmap's bits
938 * 973 *