[RFC/DONOT MERGE PATCH] arm: mach-k3: Enable Serror exception trap at u-boot

Nishanth Menon nm at ti.com
Fri Jan 7 21:17:08 CET 2022


When TF-A hands over control to Armv8 SPL/U-boot in K3 architecture,
by default, the SERROR[1] is not trapped in EL2/1 - this allows
bootloaders and hypervisors to make specific choices as to what they
would like to do.

However the side effect of this design choice is that if TF-A does'nt
trap exceptions in EL3, exceptions created by SPL/U-boot is only trapped
when kernel gets started, and that too at a very late stage.

Instead, lets try and follow the model that layerscape and imx follows
and enable the same in u-boot itself.

NOTE: While, theoretically, it is possible to enable the exceptions very
early in the boot process (say, low_level_init) there is hardly any
interactions taking place until board_init_f, making the integration
relatively easier.

[1] https://developer.arm.com/documentation/100933/0100/Synchronous-and-asynchronous-exceptions

Inspired-by: Andre Przywara <andre.przywara at arm.com>
Link: https://patchwork.ozlabs.org/project/uboot/cover/20200117012047.31096-1-andre.przywara@arm.com/#2349054
Signed-off-by: Nishanth Menon <nm at ti.com>
---


This patch is RFC based on the discussion https://libera.irclog.whitequark.org/u-boot/2022-01-07
This is armv8 architecture implementation detail, that is better done in
arch/arm/cpu/armv8 in a generic manner - just a patch to indicate the
problem is wide spread and to support the efforts of Andre to fix this
up. In the meanwhile, for others in K3 community looking for an intermediate
fixup.

Thanks Andre for helping clean this up.

 arch/arm/mach-k3/Makefile                |  1 +
 arch/arm/mach-k3/am642_init.c            |  2 ++
 arch/arm/mach-k3/am6_init.c              |  2 ++
 arch/arm/mach-k3/arm64-misc.S            | 21 +++++++++++++++++++++
 arch/arm/mach-k3/common.h                |  1 +
 arch/arm/mach-k3/include/mach/hardware.h |  1 -
 arch/arm/mach-k3/j721e_init.c            |  2 ++
 7 files changed, 29 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/mach-k3/arm64-misc.S

diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
index b965848e2350..213bf684802b 100644
--- a/arch/arm/mach-k3/Makefile
+++ b/arch/arm/mach-k3/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_ARM64) += arm64-mmu.o
 obj-$(CONFIG_CPU_V7R) += r5_mpu.o lowlevel_init.o
 obj-$(CONFIG_TI_SECURE_DEVICE) += security.o
 obj-$(CONFIG_ARM64) += cache.o
+obj-$(CONFIG_ARM64) += arm64-misc.o
 ifeq ($(CONFIG_SPL_BUILD),y)
 obj-$(CONFIG_K3_LOAD_SYSFW) += sysfw-loader.o
 endif
diff --git a/arch/arm/mach-k3/am642_init.c b/arch/arm/mach-k3/am642_init.c
index 533905daeb41..402b4219e16e 100644
--- a/arch/arm/mach-k3/am642_init.c
+++ b/arch/arm/mach-k3/am642_init.c
@@ -148,6 +148,8 @@ void board_init_f(ulong dummy)
 
 #if defined(CONFIG_CPU_V7R)
 	setup_k3_mpu_regions();
+#else
+	__asm_k3_enable_serror();
 #endif
 
 	/*
diff --git a/arch/arm/mach-k3/am6_init.c b/arch/arm/mach-k3/am6_init.c
index ffb7aaded2e7..15b1fa4cc022 100644
--- a/arch/arm/mach-k3/am6_init.c
+++ b/arch/arm/mach-k3/am6_init.c
@@ -186,6 +186,8 @@ void board_init_f(ulong dummy)
 #ifdef CONFIG_CPU_V7R
 	disable_linefill_optimization();
 	setup_k3_mpu_regions();
+#else
+	__asm_k3_enable_serror();
 #endif
 
 	/* Init DM early in-order to invoke system controller */
diff --git a/arch/arm/mach-k3/arm64-misc.S b/arch/arm/mach-k3/arm64-misc.S
new file mode 100644
index 000000000000..86b9481fc0e4
--- /dev/null
+++ b/arch/arm/mach-k3/arm64-misc.S
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2022 Texas Instruments Incorporated - http://www.ti.com/
+ */
+
+#include <config.h>
+#include <linux/linkage.h>
+
+#if defined(CONFIG_SPL_BUILD)
+ENTRY(__asm_k3_enable_serror)
+	/* unmask SError and abort */
+	msr daifclr, #4
+
+	/* Set HCR_EL2[AMO] so SError @EL2 is taken */
+	mrs	x0, hcr_el2
+	orr	x0, x0, #0x20			/* AMO */
+	msr	hcr_el2, x0
+	isb
+	ret
+ENDPROC(__asm_k3_enable_serror)
+#endif
diff --git a/arch/arm/mach-k3/common.h b/arch/arm/mach-k3/common.h
index e81b70d7c368..2680a21af344 100644
--- a/arch/arm/mach-k3/common.h
+++ b/arch/arm/mach-k3/common.h
@@ -19,6 +19,7 @@ struct fwl_data {
 };
 
 void setup_k3_mpu_regions(void);
+void __asm_k3_enable_serror(void);
 int early_console_init(void);
 void disable_linefill_optimization(void);
 void remove_fwl_configs(struct fwl_data *fwl_data, size_t fwl_data_size);
diff --git a/arch/arm/mach-k3/include/mach/hardware.h b/arch/arm/mach-k3/include/mach/hardware.h
index e87a888465c1..bb874d4e0638 100644
--- a/arch/arm/mach-k3/include/mach/hardware.h
+++ b/arch/arm/mach-k3/include/mach/hardware.h
@@ -35,5 +35,4 @@ struct rom_extended_boot_data {
 	char header[8];
 	u32 num_components;
 };
-
 #endif /* _ASM_ARCH_HARDWARE_H_ */
diff --git a/arch/arm/mach-k3/j721e_init.c b/arch/arm/mach-k3/j721e_init.c
index 78d80be1758e..84513bca8869 100644
--- a/arch/arm/mach-k3/j721e_init.c
+++ b/arch/arm/mach-k3/j721e_init.c
@@ -153,6 +153,8 @@ void board_init_f(ulong dummy)
 #ifdef CONFIG_CPU_V7R
 	disable_linefill_optimization();
 	setup_k3_mpu_regions();
+#else
+	__asm_k3_enable_serror();
 #endif
 
 	/* Init DM early */
-- 
2.31.1



More information about the U-Boot mailing list