Skip to content

Commit

Permalink
bitmap: add bitmap_copy_le()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
David Vrabel authored and David Vrabel committed Sep 17, 2008
1 parent 45e9c0d commit ccbe329
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/bitmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ extern void bitmap_fold(unsigned long *dst, const unsigned long *orig,
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(void *dst, const unsigned long *src, int nbits);

#define BITMAP_LAST_WORD_MASK(nbits) \
( \
Expand Down
22 changes: 22 additions & 0 deletions lib/bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,3 +1007,25 @@ 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 buffer
* @src: bitmap to copy
* @nbits: number of bits in the bitmap
*
* Require nbits % BITS_PER_LONG == 0.
*/
void bitmap_copy_le(void *dst, const unsigned long *src, int nbits)
{
unsigned long *d = dst;
int i;

for (i = 0; i < nbits/BITS_PER_LONG; i++) {
if (BITS_PER_LONG == 64)
d[i] = cpu_to_le64(src[i]);
else
d[i] = cpu_to_le32(src[i]);
}
}
EXPORT_SYMBOL(bitmap_copy_le);

0 comments on commit ccbe329

Please sign in to comment.