blob: 7d59e5fc3bcff43ef12efb029237bc8a00fc0dca [file] [log] [blame]
Andrew Geissler9347dd42023-03-03 12:38:41 -06001From 5995f83592aea874f5b423538e36675e2204582b Mon Sep 17 00:00:00 2001
Brad Bishopbec4ebc2022-08-03 09:55:16 -04002From: Jaxson Han <jaxson.han@arm.com>
3Date: Tue, 4 Jan 2022 17:01:55 +0800
4Subject: [PATCH] boot: Add the --enable-keep-el compile option
5
6Add --enable-keep-el compile option to enable boot-wrapper booting next
7stage at EL2.
8The Armv8R AArch64 boots at EL2. If the next stage requires EL2 booting,
9the boot-wrapper should not drop to EL1.
10Currently, this option only works for Armv8R AArch64. Also, to work with
11Linux PSCI, this option will cause secondary cores booting at EL1.
12
13Issue-Id: SCM-3813
14Upstream-Status: Inappropriate [other]
15 Implementation pending further discussion
16Signed-off-by: Jaxson Han <jaxson.han@arm.com>
17Change-Id: I3ba9c87cf0b59d163ca433f74c9e3a46e5ca2c63
18---
19 Makefile.am | 4 ++++
20 arch/aarch64/boot.S | 6 +++++-
21 common/psci.c | 6 ++++++
22 configure.ac | 5 +++++
23 4 files changed, 20 insertions(+), 1 deletion(-)
24
25diff --git a/Makefile.am b/Makefile.am
Andrew Geissler9347dd42023-03-03 12:38:41 -060026index e905602..6604baa 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040027--- a/Makefile.am
28+++ b/Makefile.am
29@@ -33,6 +33,10 @@ PSCI_CPU_ON := 0xc4000003
30 endif
31 PSCI_CPU_OFF := 0x84000002
32
33+if KEEP_EL
34+DEFINES += -DKEEP_EL
35+endif
36+
37 COMMON_SRC := common/
38 COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o device_tree.o
39
40diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S
Andrew Geissler9347dd42023-03-03 12:38:41 -060041index 27b1139..c079d22 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040042--- a/arch/aarch64/boot.S
43+++ b/arch/aarch64/boot.S
Andrew Geissler9347dd42023-03-03 12:38:41 -060044@@ -254,7 +254,11 @@ el2_init:
Brad Bishopbec4ebc2022-08-03 09:55:16 -040045 msr cnthctl_el2, x0
46 isb
47
48+#ifdef KEEP_EL
49+ mov w0, #SPSR_KERNEL
50+#else
51 mov w0, #SPSR_KERNEL_EL1
52+#endif
53 ldr x1, =spsr_to_elx
54 str w0, [x1]
55 // fall through
Andrew Geissler9347dd42023-03-03 12:38:41 -060056@@ -334,5 +338,5 @@ ASM_FUNC(jump_kernel)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040057 .align 3
58 flag_keep_el:
59 .long 0
60-spsr_to_elx:
61+ASM_DATA(spsr_to_elx)
62 .long 0
63diff --git a/common/psci.c b/common/psci.c
64index a0e8700..945780b 100644
65--- a/common/psci.c
66+++ b/common/psci.c
67@@ -18,6 +18,8 @@
68 #error "No MPIDRs provided"
69 #endif
70
71+extern unsigned int spsr_to_elx;
72+
73 static unsigned long branch_table[NR_CPUS];
74
75 bakery_ticket_t branch_table_lock[NR_CPUS];
76@@ -44,6 +46,10 @@ static int psci_cpu_on(unsigned long target_mpidr, unsigned long address)
77 ret = psci_store_address(cpu, address);
78 bakery_unlock(branch_table_lock, this_cpu);
79
80+#ifdef KEEP_EL
81+ spsr_to_elx = SPSR_KERNEL_EL1;
82+#endif
83+
84 return ret;
85 }
86
87diff --git a/configure.ac b/configure.ac
88index 53e51be..0e07db3 100644
89--- a/configure.ac
90+++ b/configure.ac
91@@ -25,6 +25,11 @@ AS_IF([test "x$BOOTWRAPPER_ES" = x32 -a "x$KERNEL_ES" != x32],
92 [AC_MSG_ERROR([a 32-bit boot-wrapper cannot launch a 64-bit kernel])]
93 )
94
95+AC_ARG_ENABLE([keep-el],
96+ AC_HELP_STRING([--enable-keep-el], [keep exception level when start kernel]),
97+ [KEEP_EL=yes], [KEEP_EL=no])
98+AM_CONDITIONAL([KEEP_EL], [test "x$KEEP_EL" = xyes])
99+
100 # Allow a user to pass --with-kernel-dir
101 AC_ARG_WITH([kernel-dir],
102 AS_HELP_STRING([--with-kernel-dir], [specify the root Linux kernel build directory (required)]),