diff options
author | David Vrabel <david.vrabel@csr.com> | 2008-04-09 10:21:50 +1000 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2008-04-09 10:21:50 +1000 |
commit | 5d05fbb41b1de0bf9ab13675cf5ac51f1cc28ed0 (patch) | |
tree | 7122a5635a83f86e69c6b664b89a3d20ad781cc7 | |
parent | 0397250b6c3421691c3f6a07f08752967aa5de2b (diff) |
lib-bitmap_copy_le
[PATCH] bitmap: add bitmap_copy_le()
bitmap_copy_le() copies a bitmap, putting the bits into little-endian
order (i.e., each unsigned long word in the bitmap is put into
little-endian order).
The UWB stack used bitmaps to manage Medium Access Slot availability,
and these bitmaps need to be written to the hardware in LE order.
Signed-off-by: David Vrabel <david.vrabel@csr.com>
-rw-r--r-- | include/linux/bitmap.h | 1 | ||||
-rw-r--r-- | lib/bitmap.c | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index acad1105d942..893c32fc37c4 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -123,6 +123,7 @@ extern int bitmap_bitremap(int oldbit, extern int bitmap_find_free_region(unsigned long *bitmap, int bits, int order); extern void bitmap_release_region(unsigned long *bitmap, int pos, int order); extern int bitmap_allocate_region(unsigned long *bitmap, int pos, int order); +extern void bitmap_copy_le(unsigned long *dst, const unsigned long *src, int nbits); #define BITMAP_LAST_WORD_MASK(nbits) \ ( \ diff --git a/lib/bitmap.c b/lib/bitmap.c index 2c9242e3fed0..0e184e3cfd3c 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -838,3 +838,23 @@ int bitmap_allocate_region(unsigned long *bitmap, int pos, int order) return 0; } EXPORT_SYMBOL(bitmap_allocate_region); + +/** + * bitmap_copy_le - copy a bitmap, putting the bits into little-endian order. + * @dst: destination bitmap. + * @src: bitmap to copy. + * @nbits: number of bits in the bitmap. + * + * Require nbits % BITS_PER_LONG == 0. + */ +void bitmap_copy_le(unsigned long *dst, const unsigned long *src, int nbits) +{ + int i; + + for (i = 0; i < nbits/BITS_PER_LONG; i++) + if (BITS_PER_LONG == 64) + dst[i] = cpu_to_le64(src[i]); + else + dst[i] = cpu_to_le32(src[i]); +} +EXPORT_SYMBOL(bitmap_copy_le); |