Exit Gunyah hypervisor and switch to EL2 during early boot on Qualcomm Dragonwing family platforms. This must happen before EL register configuration in start.S so that U-Boot can run properly at EL2 to support hypervisors requiring EL2 privilege level.
Signed-off-by: Aswin Murugan <[email protected]> --- arch/arm/mach-snapdragon/Kconfig | 8 +++++ arch/arm/mach-snapdragon/include/mach/boot0.h | 2 ++ .../include/mach/gunyah_exit_boot0.h | 36 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 arch/arm/mach-snapdragon/include/mach/gunyah_exit_boot0.h diff --git a/arch/arm/mach-snapdragon/Kconfig b/arch/arm/mach-snapdragon/Kconfig index ddded0029ef..2c182c7b974 100644 --- a/arch/arm/mach-snapdragon/Kconfig +++ b/arch/arm/mach-snapdragon/Kconfig @@ -80,6 +80,14 @@ config BOOT0_SDM845_WORKAROUND help Select this if you are building U-Boot SPL for sdm845. +config QCOM_EL2_GUNYAH_EXIT_SUPPORT + bool "Enable early EL2 switch by exiting Gunyah" + help + Exit Gunyah hypervisor and switch to EL2 during early boot on + Qualcomm Dragonwing family platforms. This must happen before EL + register configuration in start.S so that U-Boot can run properly + at EL2 to support hypervisors requiring EL2 privilege level. + endchoice endif diff --git a/arch/arm/mach-snapdragon/include/mach/boot0.h b/arch/arm/mach-snapdragon/include/mach/boot0.h index b71aab37f44..c34627cf62c 100644 --- a/arch/arm/mach-snapdragon/include/mach/boot0.h +++ b/arch/arm/mach-snapdragon/include/mach/boot0.h @@ -8,6 +8,8 @@ #else #if defined(CONFIG_BOOT0_MSM8916_PSCI_WORKAROUND) #include "msm8916_boot0.h" +#elif defined(CONFIG_QCOM_EL2_GUNYAH_EXIT_SUPPORT) +#include "gunyah_exit_boot0.h" #else b reset #endif diff --git a/arch/arm/mach-snapdragon/include/mach/gunyah_exit_boot0.h b/arch/arm/mach-snapdragon/include/mach/gunyah_exit_boot0.h new file mode 100644 index 00000000000..80b9f7effa5 --- /dev/null +++ b/arch/arm/mach-snapdragon/include/mach/gunyah_exit_boot0.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Early Gunyah Hypervisor Exit for Dragonwing Family Platforms + * + * Exit Gunyah hypervisor and switch to EL2 during early boot on Qualcomm + * Dragonwing family platforms. This must happen before EL register + * configuration in start.S so that U-Boot can run properly at EL2 to + * support hypervisors requiring EL2 privilege level. + */ + +#include <asm/macro.h> +#include <linux/arm-smccc.h> + +/* TrustZone SMC IDs for hypervisor configuration */ +#define TZ_EL2_SWITCH_SMC_ID 0x02000121 +#define TZ_EL2_SWITCH_PARAM_ID 0x00000023 +#define TZ_EL2_SWITCH_PARAM2_EXIT_GUNYAH 0x1 + + /* Only perform hypervisor switch if we're at EL1 */ + switch_el x9, 3f, 2f, 1f + + /* Save FDT address before we modify x0 */ +1: mov x9, x0 + + /* Switch to EL2 (exit Gunyah) */ + ldr w0, =TZ_EL2_SWITCH_SMC_ID + ldr w1, =TZ_EL2_SWITCH_PARAM_ID + mov w2, wzr + mov w3, wzr + ldr w4, =TZ_EL2_SWITCH_PARAM2_EXIT_GUNYAH + smc #0 + + /* Restore FDT address */ + mov x0, x9 +2: +3: b reset -- 2.34.1
