[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 1/3] [XEN] Convert from bytestream to BITMAP_ARRAY and back




Signed-off-by: Jimi Xenidis <jimix@xxxxxxxxxxxxxx>

---

diff -r 58d6c9cb95c6 xen/common/bitmap.c
--- a/xen/common/bitmap.c       Wed Jan 17 14:57:04 2007 -0500
+++ b/xen/common/bitmap.c       Wed Jan 17 15:09:23 2007 -0500
@@ -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,77 @@ int bitmap_allocate_region(unsigned long
        return 0;
 }
 EXPORT_SYMBOL(bitmap_allocate_region);
+
+static inline ulong ulong_to_le(ulong l)
+{
+#if BITS_PER_LONG == 32
+    return cpu_to_le32(l);
+#else
+    return cpu_to_le64(l);
+#endif
+
+}
+
+static inline ulong le_to_ulong(ulong l)
+{
+#if BITS_PER_LONG == 32
+    return le32_to_cpu(l);
+#else
+    return le64_to_cpu(l);
+#endif
+}
+
+void *bitmap_long_to_byte(uint8_t *bp, const ulong *lp, size_t n)
+{
+#ifdef __BIG_ENDIAN
+    ulong l;
+    int i = 0;
+    int b = 0;
+
+    for (;;) {
+        l = ulong_to_le(lp[i]);
+
+        if (n < sizeof (l))
+            break;
+
+        ((ulong *)bp)[b] = l;
+        ++i;
+        n -= sizeof (l);
+        b += sizeof (l);
+    }
+    /* don't call memcpy for 0 */
+    if (n > 0)
+        memcpy(&bp[b], &l, n);
+#else
+    memcpy(bp, lp, n);
+#endif
+
+    return bp;
+}
+EXPORT_SYMBOL(bitmap_long_to_byte);
+
+void *bitmap_byte_to_long(ulong *lp, const uint8_t *bp, size_t n)
+{
+#ifdef __BIG_ENDIAN
+    ulong l;
+    int i = 0;
+    int b = 0;
+
+    while (n > sizeof (l)) {
+        l = ((ulong *)bp)[b];
+        lp[i] = le_to_ulong(l);
+        ++i;
+        n -= sizeof (l);
+        b += sizeof (l);
+    }
+    if (n > 0) {
+        l = 0;
+        memcpy(&l, &bp[b], n);
+        lp[i] = le_to_ulong(l);
+    }
+#else
+    memcpy(lp, bp, n);
+#endif
+    return lp;
+}
+EXPORT_SYMBOL(bitmap_byte_to_long);
diff -r 58d6c9cb95c6 xen/common/domctl.c
--- a/xen/common/domctl.c       Wed Jan 17 14:57:04 2007 -0500
+++ b/xen/common/domctl.c       Wed Jan 17 15:37:35 2007 -0500
@@ -18,6 +18,7 @@
 #include <xen/console.h>
 #include <xen/iocap.h>
 #include <xen/guest_access.h>
+#include <xen/bitmap.h>
 #ifdef CONFIG_COMPAT
 #include <xen/compat.h>
 #endif
@@ -40,6 +41,7 @@ void cpumask_to_xenctl_cpumap(
 {
     unsigned int guest_bytes, copy_bytes, i;
     uint8_t zero = 0;
+    uint8_t local[sizeof (*cpumask)];
 
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
@@ -47,9 +49,9 @@ void cpumask_to_xenctl_cpumap(
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
     copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
 
-    copy_to_guest(xenctl_cpumap->bitmap,
-                  (uint8_t *)cpus_addr(*cpumask),
-                  copy_bytes);
+    bitmap_long_to_byte(local, cpus_addr(*cpumask), copy_bytes);
+
+    copy_to_guest(xenctl_cpumap->bitmap, &local[0], copy_bytes);
 
     for ( i = copy_bytes; i < guest_bytes; i++ )
         copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1);
@@ -59,6 +61,7 @@ void xenctl_cpumap_to_cpumask(
     cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap)
 {
     unsigned int guest_bytes, copy_bytes;
+    uint8_t local[sizeof (*cpumask)];
 
     guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
     copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
@@ -68,9 +71,9 @@ void xenctl_cpumap_to_cpumask(
     if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
         return;
 
-    copy_from_guest((uint8_t *)cpus_addr(*cpumask),
-                    xenctl_cpumap->bitmap,
-                    copy_bytes);
+    copy_from_guest(&local[0], xenctl_cpumap->bitmap, copy_bytes);
+
+    bitmap_byte_to_long(cpus_addr(*cpumask), local, copy_bytes);
 }
 
 #endif /* COMPAT */
diff -r 58d6c9cb95c6 xen/include/xen/bitmap.h
--- a/xen/include/xen/bitmap.h  Wed Jan 17 14:57:04 2007 -0500
+++ b/xen/include/xen/bitmap.h  Wed Jan 17 15:06:33 2007 -0500
@@ -251,6 +251,9 @@ static inline void bitmap_shift_left(uns
                __bitmap_shift_left(dst, src, n, nbits);
 }
 
+extern void *bitmap_long_to_byte(uint8_t *bp, const ulong *lp, size_t n);
+extern void *bitmap_byte_to_long(ulong *lp, const uint8_t *bp, size_t n);
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* __XEN_BITMAP_H */

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.