xen: arm: implement arch/platform SMP and CPU initialisation framework
authorIan Campbell <ian.campbell@citrix.com>
Fri, 20 Sep 2013 22:29:44 +0000 (23:29 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Fri, 27 Sep 2013 15:39:03 +0000 (16:39 +0100)
Includes an implementation for vexpress using the sysflags interface and
support for the ARMv8 "spin-table" method.

Unused until "rewrite start of day page table and cpu bring up", split out to
simplify review.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Tim Deegan <tim@xen.org>
Acked-by: Julien Grall <julien.grall@linaro.org>
xen/arch/arm/arm32/Makefile
xen/arch/arm/arm32/head.S
xen/arch/arm/arm32/smpboot.c [new file with mode: 0644]
xen/arch/arm/arm64/Makefile
xen/arch/arm/arm64/head.S
xen/arch/arm/arm64/smpboot.c [new file with mode: 0644]
xen/arch/arm/platform.c
xen/arch/arm/platforms/vexpress.c
xen/include/asm-arm/platform.h
xen/include/asm-arm/smp.h

index 18522dca20fe1b976b5a9ff7393c048a7cc6827b..463b1f51ab8835aef16ccda88461ff4948a54832 100644 (file)
@@ -7,5 +7,6 @@ obj-y += proc-v7.o
 obj-y += traps.o
 obj-y += domain.o
 obj-y += vfp.o
+obj-y += smpboot.o
 
 obj-$(EARLY_PRINTK) += debug.o
index 2fcd38aa6eda3b9ffffeefcfa603f03bbd6cc752..bbcb3a0cada4c317be2136a13b0cb0e9cccee8d1 100644 (file)
@@ -59,7 +59,7 @@
          * or the initial pagetable code below will need adjustment. */
         .global start
 start:
-
+GLOBAL(init_secondary) /* currently unused */
         /* zImage magic header, see:
          * http://www.simtec.co.uk/products/SWLINUX/files/booting_article.html#d0e309
          */
diff --git a/xen/arch/arm/arm32/smpboot.c b/xen/arch/arm/arm32/smpboot.c
new file mode 100644 (file)
index 0000000..88fe8fb
--- /dev/null
@@ -0,0 +1,29 @@
+#include <xen/device_tree.h>
+#include <xen/init.h>
+#include <xen/smp.h>
+#include <asm/platform.h>
+
+int __init arch_smp_init(void)
+{
+    return platform_smp_init();
+}
+
+int __init arch_cpu_init(int cpu, struct dt_device_node *dn)
+{
+    /* TODO handle PSCI init */
+    return 0;
+}
+
+int __init arch_cpu_up(int cpu)
+{
+    return platform_cpu_up(cpu);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index e06a0a99776b6d019be92aef9765df6baf7680fb..30fb480d65cb83816aeeb6ba6e92950738bade4d 100644 (file)
@@ -6,5 +6,6 @@ obj-y += mode_switch.o
 obj-y += traps.o
 obj-y += domain.o
 obj-y += vfp.o
+obj-y += smpboot.o
 
 obj-$(EARLY_PRINTK) += debug.o
index bc95972a40b83e6ea37e6c83ad96ea05b49b53ab..ac1b75ab5f0a398459f8dc3b2e5ace0fa74b97f6 100644 (file)
@@ -65,6 +65,7 @@
 
         .global start
 start:
+GLOBAL(init_secondary) /* currently unused */
         /*
          * DO NOT MODIFY. Image header expected by Linux boot-loaders.
          */
diff --git a/xen/arch/arm/arm64/smpboot.c b/xen/arch/arm/arm64/smpboot.c
new file mode 100644 (file)
index 0000000..8239590
--- /dev/null
@@ -0,0 +1,89 @@
+#include <xen/cpu.h>
+#include <xen/lib.h>
+#include <xen/init.h>
+#include <xen/errno.h>
+#include <xen/mm.h>
+#include <xen/smp.h>
+
+struct smp_enable_ops {
+        int             (*prepare_cpu)(int);
+};
+
+static paddr_t cpu_release_addr[NR_CPUS];
+static struct smp_enable_ops smp_enable_ops[NR_CPUS];
+
+static int __init smp_spin_table_cpu_up(int cpu)
+{
+    paddr_t *release;
+
+    if (!cpu_release_addr[cpu])
+    {
+        printk("CPU%d: No release addr\n", cpu);
+        return -ENODEV;
+    }
+
+    release = __va(cpu_release_addr[cpu]);
+
+    release[0] = __pa(init_secondary);
+    flush_xen_data_tlb_range_va((vaddr_t)release, sizeof(*release));
+
+    sev();
+    return 0;
+}
+
+static void __init smp_spin_table_init(int cpu, struct dt_device_node *dn)
+{
+    if ( !dt_property_read_u64(dn, "cpu-release-addr", &cpu_release_addr[cpu]) )
+    {
+        printk("CPU%d has no cpu-release-addr\n", cpu);
+        return;
+    }
+
+    smp_enable_ops[cpu].prepare_cpu = smp_spin_table_cpu_up;
+}
+
+int __init arch_smp_init(void)
+{
+    /* Nothing */
+    return 0;
+}
+
+int __init arch_cpu_init(int cpu, struct dt_device_node *dn)
+{
+    const char *enable_method;
+
+    enable_method = dt_get_property(dn, "enable-method", NULL);
+    if (!enable_method)
+    {
+        printk("CPU%d has no enable method\n", cpu);
+        return -EINVAL;
+    }
+
+    if ( !strcmp(enable_method, "spin-table") )
+        smp_spin_table_init(cpu, dn);
+    /* TODO: method "psci" */
+    else
+    {
+        printk("CPU%d has unknown enable method \"%s\"\n", cpu, enable_method);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+int __init arch_cpu_up(int cpu)
+{
+    if ( !smp_enable_ops[cpu].prepare_cpu )
+        return -ENODEV;
+
+    return smp_enable_ops[cpu].prepare_cpu(cpu);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index db79368ce2c19cbb7f0bb071d91c1eaea18bd940..db135f84fbdea73291e424050bb957673682c63d 100644 (file)
@@ -105,6 +105,24 @@ int __init platform_specific_mapping(struct domain *d)
     return res;
 }
 
+#ifdef CONFIG_ARM_32
+int __init platform_cpu_up(int cpu)
+{
+    if ( platform && platform->cpu_up )
+        return platform->cpu_up(cpu);
+
+    return -EAGAIN;
+}
+
+int __init platform_smp_init(void)
+{
+    if ( platform && platform->smp_init )
+        return platform->smp_init();
+
+    return 0;
+}
+#endif
+
 void platform_reset(void)
 {
     if ( platform && platform->reset )
index 22c0c13e9842a2d8de1ef003eae9a416eb369b3d..b9d85af2abbf6c9b96ad025a21c811b2f9217111 100644 (file)
@@ -22,6 +22,7 @@
 #include <xen/mm.h>
 #include <xen/vmap.h>
 #include <asm/io.h>
+#include <asm/gic.h>
 
 #define DCC_SHIFT      26
 #define FUNCTION_SHIFT 20
@@ -120,6 +121,39 @@ static void vexpress_reset(void)
     iounmap(sp810);
 }
 
+#ifdef CONFIG_ARM_32
+
+static int __init vexpress_smp_init(void)
+{
+    void __iomem *sysflags;
+
+    sysflags = ioremap_nocache(V2M_SYS_MMIO_BASE, PAGE_SIZE);
+    if ( !sysflags )
+    {
+        dprintk(XENLOG_ERR, "Unable to map vexpress MMIO\n");
+        return -EFAULT;
+    }
+
+    printk("Set SYS_FLAGS to %"PRIpaddr" (%p)\n",
+           __pa(init_secondary), init_secondary);
+    writel(~0, sysflags + V2M_SYS_FLAGSCLR);
+    writel(__pa(init_secondary), sysflags + V2M_SYS_FLAGSSET);
+
+    iounmap(sysflags);
+
+    return 0;
+}
+
+static int __init vexpress_cpu_up(int cpu)
+{
+    /* Nothing to do here, the generic sev() will suffice to kick CPUs
+     * out of either the firmware or our own smp_up_cpu gate,
+     * depending on where they have ended up. */
+
+    return 0;
+}
+#endif
+
 static const char * const vexpress_dt_compat[] __initdata =
 {
     "arm,vexpress",
@@ -144,6 +178,10 @@ static const struct dt_device_match vexpress_blacklist_dev[] __initconst =
 
 PLATFORM_START(vexpress, "VERSATILE EXPRESS")
     .compatible = vexpress_dt_compat,
+#ifdef CONFIG_ARM_32
+    .smp_init = vexpress_smp_init,
+    .cpu_up = vexpress_cpu_up,
+#endif
     .reset = vexpress_reset,
     .blacklist_dev = vexpress_blacklist_dev,
 PLATFORM_END
index a19dbf732b24e6ffd66c9385033686a54daf9e2f..dbd2a15ed429cda56795776c76f7b01637b79cd9 100644 (file)
@@ -15,6 +15,11 @@ struct platform_desc {
     /* Platform initialization */
     int (*init)(void);
     int (*init_time)(void);
+#ifdef CONFIG_ARM_32
+    /* SMP */
+    int (*smp_init)(void);
+    int (*cpu_up)(int cpu);
+#endif
     /* Specific mapping for dom0 */
     int (*specific_mapping)(struct domain *d);
     /* Platform reset */
@@ -43,6 +48,10 @@ struct platform_desc {
 int __init platform_init(void);
 int __init platform_init_time(void);
 int __init platform_specific_mapping(struct domain *d);
+#ifdef CONFIG_ARM_32
+int platform_smp_init(void);
+int platform_cpu_up(int cpu);
+#endif
 void platform_reset(void);
 void platform_poweroff(void);
 bool_t platform_has_quirk(uint32_t quirk);
index 1c2746b763cf492e93289bd6f22ca68c569c27b2..1added5550b7b543a448a9b01496855536a268e6 100644 (file)
@@ -4,6 +4,7 @@
 #ifndef __ASSEMBLY__
 #include <xen/config.h>
 #include <xen/cpumask.h>
+#include <xen/device_tree.h>
 #include <asm/current.h>
 #endif
 
@@ -22,9 +23,17 @@ extern void stop_cpu(void);
 extern void
 make_cpus_ready(unsigned int max_cpus, unsigned long boot_phys_offset);
 
+extern int arch_smp_init(void);
+extern int arch_cpu_init(int cpu, struct dt_device_node *dn);
+extern int arch_cpu_up(int cpu);
+
+/* Secondary CPU entry point */
+extern void init_secondary(void);
+
 extern void smp_clear_cpu_maps (void);
 extern int smp_get_max_cpus (void);
 #endif
+
 /*
  * Local variables:
  * mode: C