[patch 7/7] bitmap: add bitmap_copy_le()
Inaky Perez-Gonzalez <inaky-VuQAYsv1563Yd54FQh9/[email protected]>
| Newsgroups | gmane.linux.drivers.uwb,gmane.linux.usb.devel |
|---|---|
| Message-ID | <[email protected]> |
lib-bitmap_copy_le.patch
(text/plain, 1.9 KB)
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 <[email protected]> Index: linux-2.6-upstream/include/linux/bitmap.h =================================================================== --- linux-2.6-upstream.orig/include/linux/bitmap.h 2007-08-02 16:57:40.000000000 +0100 +++ linux-2.6-upstream/include/linux/bitmap.h 2007-08-02 17:00:25.000000000 +0100 @@ -122,6 +122,7 @@ 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) \ ( \ Index: linux-2.6-upstream/lib/bitmap.c =================================================================== --- linux-2.6-upstream.orig/lib/bitmap.c 2007-08-02 16:56:00.000000000 +0100 +++ linux-2.6-upstream/lib/bitmap.c 2007-08-02 17:32:02.000000000 +0100 @@ -834,3 +834,23 @@ 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); -- Inaky