]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
xen/arm: add coloring basic initialization
authorLuca Miccio <206497@studenti.unimore.it>
Wed, 21 Aug 2019 14:05:56 +0000 (16:05 +0200)
committerLuca Miccio <206497@studenti.unimore.it>
Mon, 6 Jan 2020 13:46:31 +0000 (14:46 +0100)
Introduce a first and simple initialization function for the cache
coloring support. A helper function computes 'addr_col_mask', the
platform-dependent bitmask asserting the bits in memory addresses that
can be used for the coloring mechanism. This, in turn is used to
determine the total amount of available colors.

Signed-off-by: Luca Miccio <206497@studenti.unimore.it>
Signed-off-by: Marco Solieri <marco.solieri@unimore.it>
xen/arch/arm/coloring.c
xen/arch/arm/setup.c
xen/include/asm-arm/coloring.h

index ae1f37070348d00731851914fb432206724435d5..eb9426d6962d95c8410234cba58a2ac699d7a7a0 100644 (file)
@@ -37,8 +37,13 @@ static uint64_t xen_col_mask;
 static uint64_t dom0_colors_num;
 /* Coloring configuration of Dom0 as bitmask */
 static uint64_t dom0_colors_mask;
+/* Maximum number of available color(s) */
+static uint64_t col_num_max;
+/* Maximum available coloring configuration as bitmask */
+static uint64_t col_val_max;
 
 static uint64_t way_size;
+static uint64_t addr_col_mask;
 
 #define CTR_LINESIZE_MASK 0x7
 #define CTR_SIZE_SHIFT 13
@@ -113,6 +118,67 @@ static uint64_t get_llc_way_size(void)
     return (cache_line_size * cache_set_num);
 }
 
+/*
+ * Return the coloring mask based on the value of @param llc_way_size.
+ * This mask represents the bits in the address that can be used
+ * for defining available colors.
+ *
+ * @param llc_way_size         Last level cache way size.
+ * @return unsigned long       The coloring bitmask.
+ */
+static __init unsigned long calculate_addr_col_mask(unsigned int llc_way_size)
+{
+    unsigned long addr_col_mask = 0;
+    unsigned int i;
+    unsigned int low_idx, high_idx;
+
+    low_idx = PAGE_SHIFT;
+    high_idx = get_count_order(llc_way_size) - 1;
+
+    for ( i = low_idx; i <= high_idx; i++ )
+        addr_col_mask |= (1 << i);
+
+    return addr_col_mask;
+}
+
+bool __init coloring_init(void)
+{
+    int i;
+
+    C_DEBUG("Initialize XEN coloring: \n");
+    /*
+     * If the way size is not provided by the configuration, try to get
+     * this information from hardware.
+     */
+    if ( !way_size )
+    {
+        way_size = get_llc_way_size();
+
+        if ( !way_size )
+        {
+            C_DEBUG("ERROR: way size is null\n");
+            return false;
+        }
+    }
+
+    addr_col_mask = calculate_addr_col_mask(way_size);
+    if ( !addr_col_mask )
+    {
+        C_DEBUG("ERROR: addr_col_mask is null\n");
+        return false;
+    }
+
+    col_num_max = ((addr_col_mask >> PAGE_SHIFT) + 1);
+    for ( i = 0; i < col_num_max; i++ )
+        col_val_max |= (1 << i);
+
+    C_DEBUG("Way size: 0x%lx\n", way_size);
+    C_DEBUG("Color bits in address: 0x%lx\n", addr_col_mask);
+    C_DEBUG("Max number of colors: %lu (0x%lx)\n", col_num_max, col_val_max);
+
+    return true;
+}
+
 /*************************
  * PARSING COLORING BOOTARGS
  */
index 9c89c7d8febea596cc2cf68b5daefdc4e83dee6a..c504ec6a0eda81725d44ef0ebfc3073dbdeb73e8 100644 (file)
@@ -53,6 +53,7 @@
 #include <asm/tee/tee.h>
 #include <xsm/xsm.h>
 #include <asm/acpi.h>
+#include <asm/coloring.h>
 
 struct bootinfo __initdata bootinfo;
 
@@ -818,6 +819,12 @@ void __init start_xen(unsigned long boot_phys_offset,
 
     fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr);
 
+    if ( !coloring_init() )
+        panic("Xen Coloring support: setup failed\n");
+
+    xen_paddr = get_xen_paddr();
+    setup_pagetables(boot_phys_offset, xen_paddr);
+
     cmdline = boot_fdt_cmdline(device_tree_flattened);
     printk("Command line: %s\n", cmdline);
     cmdline_parse(cmdline);
index 97d8550680a5c580f787de6559b6722898f90974..3b84dc3fb5e371fdaee7423bad53e03f96e7a440 100644 (file)
 #else
 #define C_DEBUG(fmt, args...) { }
 #endif
-
+#ifdef CONFIG_COLORING
+bool __init coloring_init(void);
+#else
+static bool inline __init coloring_init(void)
+{
+    return true;
+}
 #endif /* !__ASM_ARM_COLORING_H__ */