aboutsummaryrefslogtreecommitdiffstats
path: root/xen/common/bitmap.c
diff options
context:
space:
mode:
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-01-19 14:24:28 +0000
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>2007-01-19 14:24:28 +0000
commit060fe1405f9717a6d83692504b0f704208d66dd8 (patch)
tree02e181bd61d90fc56e1fc812c366cfdd9c541b8e /xen/common/bitmap.c
parentbeb6098f214a6c227f0dce614f48cd0fc391da2d (diff)
downloadxen-060fe1405f9717a6d83692504b0f704208d66dd8.tar.gz
xen-060fe1405f9717a6d83692504b0f704208d66dd8.tar.bz2
xen-060fe1405f9717a6d83692504b0f704208d66dd8.zip
[XEN] Convert between long-based and byte-based bitmap arrays.
Use this for conversion of the domctl_cpumap type on big-endian systems. Original patch from Jimi Xenidis <jimix@watson.ibm.com> Signed-off-by: Keir Fraser <keir@xensource.com>
Diffstat (limited to 'xen/common/bitmap.c')
-rw-r--r--xen/common/bitmap.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/xen/common/bitmap.c b/xen/common/bitmap.c
index 9bdc3157d1..76f55d29e8 100644
--- a/xen/common/bitmap.c
+++ b/xen/common/bitmap.c
@@ -10,6 +10,7 @@
#include <xen/errno.h>
#include <xen/bitmap.h>
#include <xen/bitops.h>
+#include <asm/byteorder.h>
/*
* bitmaps provide an array of bits, implemented using an an
@@ -467,3 +468,53 @@ int bitmap_allocate_region(unsigned long *bitmap, int pos, int order)
return 0;
}
EXPORT_SYMBOL(bitmap_allocate_region);
+
+#ifdef __BIG_ENDIAN
+
+void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits)
+{
+ unsigned long l;
+ int i, j, b;
+
+ for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
+ l = lp[i];
+ for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
+ bp[b+j] = l;
+ l >>= 8;
+ nbits -= 8;
+ }
+ }
+}
+
+void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits)
+{
+ unsigned long l;
+ int i, j, b;
+
+ for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
+ l = 0;
+ for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
+ l <<= 8;
+ l |= bp[b+j];
+ nbits -= 8;
+ }
+ lp[i] = l;
+ }
+}
+
+#elif defined(__LITTLE_ENDIAN)
+
+void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits)
+{
+ memcpy(bp, lp, (nbits+7)/8);
+}
+
+void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits)
+{
+ /* We may need to pad the final longword with zeroes. */
+ if (nbits & (BITS_PER_LONG-1))
+ lp[BITS_TO_LONGS(nbits)-1] = 0;
+ memcpy(lp, bp, (nbits+7)/8);
+}
+
+#endif