Andrew Geissler | 80d4184 | 2023-09-11 08:36:15 -0400 | [diff] [blame] | 1 | From 30405f59881c73946b6b0ffdbf25804f9fbf1585 Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Peter Hoyes <Peter.Hoyes@arm.com> |
| 3 | Date: Wed, 14 Jul 2021 12:44:27 +0100 |
Andrew Geissler | 80d4184 | 2023-09-11 08:36:15 -0400 | [diff] [blame] | 4 | Subject: [PATCH 4/9] armv8: ARMV8_SWITCH_TO_EL1 improvements |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 5 | |
| 6 | Convert CONFIG_ARMV8_SWITCH_TO_EL1 to a Kconfig variable. |
| 7 | |
| 8 | Add support for switching to EL1 to bootefi. |
| 9 | |
| 10 | Add the environment variable armv8_switch_to_el1 to allow configuring |
| 11 | whether to switch to EL1 at runtime. This overrides the compile-time |
| 12 | option. |
| 13 | |
| 14 | Issue-Id: SCM-3728 |
| 15 | Upstream-Status: Inappropriate [other] |
| 16 | Implementation pending further discussion |
| 17 | Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com> |
| 18 | Change-Id: If98478148d6d8d1f732acac5439276700614815f |
| 19 | --- |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 20 | arch/arm/cpu/armv8/exception_level.c | 21 ++++++++++++++-- |
| 21 | arch/arm/lib/bootm.c | 36 ++++++++++++++++------------ |
| 22 | configs/vexpress_aemv8r_defconfig | 1 + |
Andrew Geissler | ea144b03 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 23 | 3 files changed, 41 insertions(+), 17 deletions(-) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 24 | |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 25 | diff --git a/arch/arm/cpu/armv8/exception_level.c b/arch/arm/cpu/armv8/exception_level.c |
| 26 | index b11936548f..4aad1550f4 100644 |
| 27 | --- a/arch/arm/cpu/armv8/exception_level.c |
| 28 | +++ b/arch/arm/cpu/armv8/exception_level.c |
| 29 | @@ -40,19 +40,36 @@ static void entry_non_secure(struct jmp_buf_data *non_secure_jmp) |
| 30 | * trusted firmware being one embodiment). The operating system shall be |
| 31 | * started at exception level EL2. So here we check the exception level |
| 32 | * and switch it if necessary. |
| 33 | + * |
| 34 | + * If armv8_switch_to_el1 (config or env var) is enabled, also switch to EL1 |
| 35 | + * before booting the operating system. |
| 36 | */ |
| 37 | void switch_to_non_secure_mode(void) |
| 38 | { |
| 39 | struct jmp_buf_data non_secure_jmp; |
| 40 | |
| 41 | /* On AArch64 we need to make sure we call our payload in < EL3 */ |
| 42 | - if (current_el() == 3) { |
| 43 | + |
| 44 | + int switch_to_el1 = env_get_yesno("armv8_switch_to_el1"); |
| 45 | +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 |
| 46 | + if (switch_to_el1 == -1) { |
| 47 | + switch_to_el1 = 1; |
| 48 | + } |
| 49 | +#endif |
| 50 | + |
| 51 | + if (current_el() > 2) { |
| 52 | if (setjmp(&non_secure_jmp)) |
| 53 | return; |
| 54 | dcache_disable(); /* flush cache before switch to EL2 */ |
| 55 | - |
| 56 | /* Move into EL2 and keep running there */ |
| 57 | armv8_switch_to_el2((uintptr_t)&non_secure_jmp, 0, 0, 0, |
| 58 | (uintptr_t)entry_non_secure, ES_TO_AARCH64); |
| 59 | + } else if (switch_to_el1 == 1 && current_el() > 1) { |
| 60 | + if (setjmp(&non_secure_jmp)) |
| 61 | + return; |
| 62 | + dcache_disable(); /* flush cache before switch to EL1 */ |
| 63 | + /* Move into EL1 and keep running there */ |
| 64 | + armv8_switch_to_el1((uintptr_t)&non_secure_jmp, 0, 0, 0, |
| 65 | + (uintptr_t)entry_non_secure, ES_TO_AARCH64); |
| 66 | } |
| 67 | } |
| 68 | diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c |
Andrew Geissler | 80d4184 | 2023-09-11 08:36:15 -0400 | [diff] [blame] | 69 | index 9f086f3b90..b044aeca88 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 70 | --- a/arch/arm/lib/bootm.c |
| 71 | +++ b/arch/arm/lib/bootm.c |
Andrew Geissler | ea144b03 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 72 | @@ -270,7 +270,6 @@ __weak void update_os_arch_secondary_cores(uint8_t os_arch) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 73 | { |
| 74 | } |
| 75 | |
| 76 | -#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 |
| 77 | static void switch_to_el1(void) |
| 78 | { |
| 79 | if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && |
Andrew Geissler | ea144b03 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 80 | @@ -285,7 +284,6 @@ static void switch_to_el1(void) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 81 | ES_TO_AARCH64); |
| 82 | } |
| 83 | #endif |
| 84 | -#endif |
| 85 | |
| 86 | /* Subcommand: GO */ |
Andrew Geissler | 80d4184 | 2023-09-11 08:36:15 -0400 | [diff] [blame] | 87 | static void boot_jump_linux(bootm_headers_t *images, int flag) |
| 88 | @@ -312,21 +310,29 @@ static void boot_jump_linux(bootm_headers_t *images, int flag) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 89 | |
| 90 | update_os_arch_secondary_cores(images->os.arch); |
| 91 | |
| 92 | + int armv8_switch_to_el1 = env_get_yesno("armv8_switch_to_el1"); |
| 93 | #ifdef CONFIG_ARMV8_SWITCH_TO_EL1 |
| 94 | - armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, |
| 95 | - (u64)switch_to_el1, ES_TO_AARCH64); |
| 96 | -#else |
| 97 | - if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && |
| 98 | - (images->os.arch == IH_ARCH_ARM)) |
| 99 | - armv8_switch_to_el2(0, (u64)gd->bd->bi_arch_number, |
| 100 | - (u64)images->ft_addr, 0, |
| 101 | - (u64)images->ep, |
| 102 | - ES_TO_AARCH32); |
| 103 | - else |
| 104 | - armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, |
| 105 | - images->ep, |
| 106 | - ES_TO_AARCH64); |
| 107 | + if (armv8_switch_to_el1 == -1) { |
| 108 | + armv8_switch_to_el1 = 1; |
| 109 | + } |
| 110 | #endif |
| 111 | + if (armv8_switch_to_el1 == 1) { |
| 112 | + armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, |
| 113 | + (u64)switch_to_el1, ES_TO_AARCH64); |
| 114 | + } else { |
| 115 | + if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && |
| 116 | + (images->os.arch == IH_ARCH_ARM)) |
| 117 | + armv8_switch_to_el2(0, |
| 118 | + (u64)gd->bd->bi_arch_number, |
| 119 | + (u64)images->ft_addr, 0, |
| 120 | + (u64)images->ep, |
| 121 | + ES_TO_AARCH32); |
| 122 | + else |
| 123 | + armv8_switch_to_el2((u64)images->ft_addr, |
| 124 | + 0, 0, 0, |
| 125 | + images->ep, |
| 126 | + ES_TO_AARCH64); |
| 127 | + } |
| 128 | } |
| 129 | #else |
| 130 | unsigned long machid = gd->bd->bi_arch_number; |
| 131 | diff --git a/configs/vexpress_aemv8r_defconfig b/configs/vexpress_aemv8r_defconfig |
Andrew Geissler | ea144b03 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 132 | index 683d983c36..6044f82b00 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 133 | --- a/configs/vexpress_aemv8r_defconfig |
| 134 | +++ b/configs/vexpress_aemv8r_defconfig |
Andrew Geissler | ea144b03 | 2023-01-27 16:03:57 -0600 | [diff] [blame] | 135 | @@ -17,3 +17,4 @@ CONFIG_SYS_PBSIZE=541 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 136 | # CONFIG_MMC is not set |
| 137 | CONFIG_VIRTIO_MMIO=y |
| 138 | CONFIG_ARMV8_EXCEPTION_VECTORS=n |
| 139 | +CONFIG_ARMV8_SWITCH_TO_EL1=y |
Andrew Geissler | 80d4184 | 2023-09-11 08:36:15 -0400 | [diff] [blame] | 140 | -- |
| 141 | 2.25.1 |
| 142 | |