Skip to contentSkip to conversation

mach-snapdragon: Add early EL2 hypervisor switch support

PATCH Superseded Aswin Murugan 1 participant 4 messages Jul 3

Subsystems (2)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover mach-snapdragon: Add early EL2 hypervisor switch support

This series adds support for exiting Gunyah hypervisor and switching to EL2 during early boot on Qualcomm Dragonwing family platforms. This enables U-Boot to run at EL2, which is required for supporting hypervisors that need EL2 privilege level.

- Adds early boot0.h infrastructure to exit Gunyah via TrustZone SMC
- Creates a reusable config fragment for easy platform enablement
- Enables the feature on QCS9100 platform

This series is based on the boot0.h infrastructure from:
[1] https://lore.kernel.org/all/[email protected]/

Changes in v4:
- Updated Kconfig and gunyah_exit_boot0.h header comments for better clarity on platform support
- Split config changes into reusable fragment and qcs9100 platform enablement
Link to v3: https://lore.kernel.org/u-boot/[email protected]/

Change in v3:
- Corrected the logic to accurately detect the current Exception Level (EL)
and fuction properly when U-Boot enters either EL2 or EL1.
Link to v2: https://lore.kernel.org/u-boot/[email protected]/

Change in v2:
- EL2 switch is made at early stage instead of doing at the very last stage in
the previous version
- This change is based on the patch [1]
Link to v1: https://lore.kernel.org/u-boot/[email protected]/

Aswin Murugan (3):
mach-snapdragon: Add early EL2 hypervisor switch support
configs: qualcomm: Add Gunyah exit config fragment
configs: qcom_qcs9100: Enable Gunyah exit support

 arch/arm/mach-snapdragon/Kconfig              |  8 +++++
 arch/arm/mach-snapdragon/include/mach/boot0.h |  3 ++
 .../include/mach/gunyah_exit_boot0.h          | 36 +++++++++++++++++++
 board/qualcomm/exit-gunyah.config             |  4 +++
 configs/qcom_qcs9100_defconfig                |  1 +
 5 files changed, 52 insertions(+)
 create mode 100644 arch/arm/mach-snapdragon/include/mach/gunyah_exit_boot0.h
 create mode 100644 board/qualcomm/exit-gunyah.config
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 1/3 mach-snapdragon: Add early EL2 hypervisor switch support

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.

---
 arch/arm/mach-snapdragon/Kconfig              |  8 +++++
 arch/arm/mach-snapdragon/include/mach/boot0.h |  3 ++
 .../include/mach/gunyah_exit_boot0.h          | 36 +++++++++++++++++++
 3 files changed, 47 insertions(+)
 create mode 100644 arch/arm/mach-snapdragon/include/mach/gunyah_exit_boot0.h
arch/arm/mach-snapdragon/Kconfig +8 -0
index f863daf6bb9..3a95d7141f9 100644
@@ -56,6 +56,14 @@ config BOOT0_MSM8916_PSCI_WORKAROUND
 	help
 	  Select this if you are building U-Boot proper for an msm8916 board that
 	  uses the buggy PSCI implementation.
+
+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
arch/arm/mach-snapdragon/include/mach/boot0.h +3 -0
index b3c76d6d97d..032a9fbdb12 100644
@@ -1,9 +1,12 @@
 /* SPDX-License-Identifier: GPL-2.0+ */
+
 #if defined(CONFIG_SPL_BUILD)
 	b	reset
 #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
arch/arm/mach-snapdragon/include/mach/gunyah_exit_boot0.h new file +36 -0
new file mode 100644
index 00000000000..80b9f7effa5
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * 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
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 2/3 configs: qualcomm: Add Gunyah exit config fragment

In reply to Aswin Murugan

Add reusable config fragment for exiting Gunyah hypervisor and switching to EL2 on Dragonwing family platforms.

---
 board/qualcomm/exit-gunyah.config | 4 ++++
 1 file changed, 4 insertions(+)
 create mode 100644 board/qualcomm/exit-gunyah.config
board/qualcomm/exit-gunyah.config new file +4 -0
new file mode 100644
index 00000000000..b9b99184960
@@ -0,0 +1,4 @@
+# Exit Gunyah hypervisor and switch to
+# EL2 for Dragonwing platforms
+CONFIG_ENABLE_ARM_SOC_BOOT0_HOOK=y
+CONFIG_QCOM_EL2_GUNYAH_EXIT_SUPPORT=y
Signature · 1 line
2.34.1
#3 lore raw

PATCH v4 3/3 configs: qcom_qcs9100: Enable Gunyah exit support

In reply to Aswin Murugan

Include exit-gunyah.config fragment to enable early hypervisor exit on QCS9100 platform, allowing U-Boot to run at EL2.

---
 configs/qcom_qcs9100_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/qcom_qcs9100_defconfig +1 -0
index efd6c63f212..fb7addb5276 100644
@@ -4,6 +4,7 @@
 # a dedicated "uefi" partition for edk2/U-Boot)
 
 #include "qcom_defconfig"
+#include "board/qualcomm/exit-gunyah.config"
 
 # Address where U-Boot will be loaded
 CONFIG_TEXT_BASE=0xaf000000
Signature · 1 line
2.34.1