This allows us to boot secondary CPUs.

Signed-off-by: Ralf Ramsauer <[email protected]>
---
 inmates/lib/arm-common/include/psci.h     |  1 +
 inmates/lib/arm-common/psci.c             | 24 ++++++++++++++++++++++++
 inmates/lib/arm/header.S                  | 22 ++++++++++++++++++++--
 inmates/lib/arm/include/asm/psci_call.h   |  4 ++++
 inmates/lib/arm64/header.S                | 24 +++++++++++++++++++++---
 inmates/lib/arm64/include/asm/psci_call.h |  4 ++++
 6 files changed, 74 insertions(+), 5 deletions(-)

diff --git a/inmates/lib/arm-common/include/psci.h 
b/inmates/lib/arm-common/include/psci.h
index a367beb4..b7cf3dab 100644
--- a/inmates/lib/arm-common/include/psci.h
+++ b/inmates/lib/arm-common/include/psci.h
@@ -37,3 +37,4 @@
  */
 
 unsigned int psci_version(void);
+int psci_cpu_on(unsigned int cpu_id, void (*c_entry)(void *));
diff --git a/inmates/lib/arm-common/psci.c b/inmates/lib/arm-common/psci.c
index 3470bdf7..306ff037 100644
--- a/inmates/lib/arm-common/psci.c
+++ b/inmates/lib/arm-common/psci.c
@@ -38,6 +38,11 @@
 
 #include <psci.h>
 #include <asm/psci_call.h>
+#include <asm/processor.h>
+
+void (* volatile __c_entry)(void *);
+
+extern void secondary_startup(void);
 
 volatile unsigned int cpus_online;
 
@@ -45,3 +50,22 @@ unsigned int psci_version(void)
 {
        return (unsigned int)psci_call(PSCI_VERSION, 0, 0, 0);
 }
+
+int psci_cpu_on(unsigned int cpu_id, void (*c_entry)(void *))
+{
+       int err;
+       unsigned int cpus = cpus_online + 1;
+
+       __c_entry = c_entry;
+       memory_barrier();
+
+       err = psci_call(PSCI_CPU_ON, cpu_id, (uintptr_t)secondary_startup, 0);
+       if (err)
+               return err;
+
+       /* spin while CPU is not up */
+       while (cpus != cpus_online)
+               cpu_relax();
+
+       return 0;
+}
diff --git a/inmates/lib/arm/header.S b/inmates/lib/arm/header.S
index 13700f02..4c28ad63 100644
--- a/inmates/lib/arm/header.S
+++ b/inmates/lib/arm/header.S
@@ -2,10 +2,12 @@
  * Jailhouse, a Linux-based partitioning hypervisor
  *
  * Copyright (c) ARM Limited, 2014
+ * Copyright (c) OTH Regensburg, 2017
  * Copyright (c) Siemens AG, 2016
  *
  * Authors:
  *  Jean-Philippe Brucker <[email protected]>
+ *  Ralf Ramsauer <[email protected]>
  *  Jan Kiszka <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2.  See
@@ -42,6 +44,7 @@
 #include <asm/sysregs.h>
 
        .arm
+       .arch_extension virt
 
        .section ".boot", "ax"
        .align 5
@@ -114,10 +117,14 @@ vectors:
        add     r0, r0, r2
 .endm
 
+.macro load_vectors, reg
+       ldr     \reg, =vectors
+       arm_write_sysreg(VBAR, \reg)
+.endm
+
        .globl __reset_entry
 __reset_entry:
-       ldr     r0, =vectors
-       arm_write_sysreg(VBAR, r0)
+       load_vectors r0
 
        mov     r0, #0
        ldr     r1, =bss_start
@@ -137,4 +144,15 @@ __reset_entry:
 stack_size:
        .word STACK_SIZE
 
+       .globl secondary_startup
+secondary_startup:
+       /* prepare vector base address */
+       load_vectors r0
+
+       /* prepare stack */
+       setup_cpu_stack
+
+       ldr     r1, =__c_entry
+       ldr     pc, [r1]
+
        .ltorg
diff --git a/inmates/lib/arm/include/asm/psci_call.h 
b/inmates/lib/arm/include/asm/psci_call.h
index 0cf6651d..6b12ecb9 100644
--- a/inmates/lib/arm/include/asm/psci_call.h
+++ b/inmates/lib/arm/include/asm/psci_call.h
@@ -38,6 +38,10 @@
 
 #include <asm/psci_generic.h>
 
+#define PSCI_CPU_ON PSCI_CPU_ON_32
+
+typedef unsigned long uintptr_t;
+
 static inline int psci_call(unsigned int function_id, unsigned int arg0,
                            unsigned int arg1, unsigned int arg2)
 {
diff --git a/inmates/lib/arm64/header.S b/inmates/lib/arm64/header.S
index 2c1f6a20..a3d295ef 100644
--- a/inmates/lib/arm64/header.S
+++ b/inmates/lib/arm64/header.S
@@ -2,9 +2,11 @@
  * Jailhouse AArch64 support
  *
  * Copyright (C) 2015 Huawei Technologies Duesseldorf GmbH
+ * Copyright (C) 2017 OTH Regensburg
  *
  * Authors:
  *  Antonios Motakis <[email protected]>
+ *  Ralf Ramsauer <[email protected]>
  *
  * This work is licensed under the terms of the GNU GPL, version 2.  See
  * the COPYING file in the top-level directory.
@@ -37,6 +39,7 @@
  */
 
 #include <mach.h>
+#include <asm/sysregs.h>
 
 .macro ventry  label
        .align  7
@@ -83,9 +86,7 @@
        mov     x0, #0
 .endm
 
-       .section ".boot", "ax"
-       .globl __reset_entry
-__reset_entry:
+.macro prepare_cpu
        ldr     x0, =vectors
        msr     vbar_el1, x0
 
@@ -96,6 +97,12 @@ __reset_entry:
        msr     daif, xzr
 
        isb
+.endm
+
+       .section ".boot", "ax"
+       .globl __reset_entry
+__reset_entry:
+       prepare_cpu
 
        b       inmate_main
 
@@ -106,6 +113,17 @@ handle_irq:
        bl      vector_irq
        eret
 
+
+       .globl secondary_startup
+secondary_startup:
+       prepare_cpu
+
+       ldr     x1, =__c_entry
+       ldr     x2, [x1]
+       br      x2
+
+       .ltorg
+
 .weak vector_irq
        b       .
 
diff --git a/inmates/lib/arm64/include/asm/psci_call.h 
b/inmates/lib/arm64/include/asm/psci_call.h
index ae71da4c..0406a6d5 100644
--- a/inmates/lib/arm64/include/asm/psci_call.h
+++ b/inmates/lib/arm64/include/asm/psci_call.h
@@ -38,6 +38,10 @@
 
 #include <asm/psci_generic.h>
 
+#define PSCI_CPU_ON PSCI_CPU_ON_64
+
+typedef unsigned long long uintptr_t;
+
 static inline int psci_call(unsigned long function_id, unsigned long arg0,
                            unsigned long arg1, unsigned long arg2)
 {
-- 
2.14.1

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to