Signed-off-by: Andrea Bastoni <andrea.bast...@tum.de>
---
 hypervisor/arch/arm64/coloring.c | 40 +--------------------------
 include/jailhouse/coloring.h     | 46 ++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 39 deletions(-)
 create mode 100644 include/jailhouse/coloring.h

diff --git a/hypervisor/arch/arm64/coloring.c b/hypervisor/arch/arm64/coloring.c
index ff3b5a78..c066ae24 100644
--- a/hypervisor/arch/arm64/coloring.c
+++ b/hypervisor/arch/arm64/coloring.c
@@ -21,6 +21,7 @@
 #include <jailhouse/cell.h>
 #include <jailhouse/mmio.h>
 #include <jailhouse/assert.h>
+#include <jailhouse/coloring.h>
 #include <asm/control.h>
 #include <asm/coloring.h>
 
@@ -54,21 +55,11 @@ static inline int coloring_mem_destroy(struct cell *cell,
 
 static inline int coloring_mem_start(struct jailhouse_memory *mr)
 {
-       assert(mr->flags & JAILHOUSE_MEM_LOADABLE);
-
-       /* Match the address specified during load */
-       mr->virt_start += coloring_root_map_offset;
-
        return arch_unmap_memory_region(&root_cell, mr);
 }
 
 static inline int coloring_mem_load(struct jailhouse_memory *mr)
 {
-       assert(mr->flags & JAILHOUSE_MEM_LOADABLE);
-
-       /* Fix addr to match the driver's IPA ioremap */
-       mr->virt_start += coloring_root_map_offset;
-
        /* Create an ad-hoc mapping just to load this image */
        return arch_map_memory_region(&root_cell, mr);
 }
@@ -104,35 +95,6 @@ static int dispatch_op(struct cell *cell, struct 
jailhouse_memory *mr,
        return 0;
 }
 
-/**
- *  Get range of contiguous bits in a bitmask.
- *
- *  The function returns:
- *  - bitmask without the extracted bit range.
- *  - low: original bit position of range start.
- *  - size: size of the range
- *
- *  The function assumes bitmask is not 0.
- */
-static inline void get_bit_range(
-       u64 *bitmask,
-       unsigned int *low,
-       unsigned int *size)
-{
-       unsigned int _range;
-
-       //col_print("mask: 0x%lx ", *bitmask);
-
-       *low = ffsl(*bitmask);
-       _range = *bitmask >> *low;
-       *bitmask = _range & (_range + 1UL);
-
-       _range = _range ^ *bitmask;
-       *size = msbl(_range) + 1;
-
-       //col_print("range: 0x%x, low: %u, size %u\n", _range, *low, *size);
-}
-
 int color_cell_op(struct cell *cell,
                  const struct jailhouse_memory *col_mem,
                  unsigned int op, unsigned int flags)
diff --git a/include/jailhouse/coloring.h b/include/jailhouse/coloring.h
new file mode 100644
index 00000000..3def05d9
--- /dev/null
+++ b/include/jailhouse/coloring.h
@@ -0,0 +1,46 @@
+/*
+ * Jailhouse Cache Coloring Support
+ *
+ * Copyright (C) Technical University of Munich, 2020
+ *
+ * Authors:
+ *  Andrea Bastoni <andrea.bast...@tum.de>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See the
+ * COPYING file in the top-level directory.
+ */
+
+/** MSB/LSB function names differs between Jailhouse and Linux */
+#ifdef LINUX_VERSION_CODE
+/* NOTE: use [0-63] variants */
+#define _lsb(x)        __ffs(x)
+#define _msb(x)        __fls(x)
+#else
+#define _lsb(x)        ffsl(x)
+#define _msb(x)        msbl(x)
+#endif
+
+/**
+ *  Get range of contiguous bits in a bitmask.
+ *
+ *  The function returns:
+ *  - bitmask without the extracted bit range.
+ *  - low: original bit position of range start.
+ *  - size: size of the range
+ *
+ *  The function assumes bitmask is not 0.
+ */
+static inline void get_bit_range(
+       u64 *bitmask,
+       unsigned int *low,
+       unsigned int *size)
+{
+       unsigned int _range;
+
+       *low = _lsb(*bitmask);
+       _range = *bitmask >> *low;
+       *bitmask = _range & (_range + 1UL);
+
+       _range = _range ^ *bitmask;
+       *size = _msb(_range) + 1;
+}
-- 
2.29.2

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jailhouse-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/20210125120044.56794-21-andrea.bastoni%40tum.de.

Reply via email to