[PATCH 12/18] arm64: versal-net: Move bootmode decoding out of board code

Michal Simek michal.simek at amd.com
Tue Jun 23 14:53:37 CEST 2026


versal_net_get_bootmode() open-coded the
IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE) selection between the firmware call
zynqmp_pm_get_bootmode_reg() and a direct readl() in board code. Like
the Versal change, move the whole function behind an overridable hook so
generic board code stays free of firmware specifics and is ready for
SCMI.

The weak versal_net_get_bootmode() in arch/arm/mach-versal-net does the
plain MMIO read via versal_net_bootmode_reg() and decodes it (used at EL3
and without firmware). When CONFIG_ZYNQMP_FIRMWARE is enabled,
firmware-zynqmp.c provides a strong definition that reads the register
through the firmware call, falling back to the direct read at EL3 where
the SMC path to firmware is unavailable. This preserves the existing
firmware-based bootmode behaviour while removing the firmware interface
from board code; the now unused zynqmp_firmware.h include is dropped.

Signed-off-by: Michal Simek <michal.simek at amd.com>
---

 arch/arm/mach-versal-net/cpu.c                | 15 ++++++++++++++
 .../mach-versal-net/include/mach/sys_proto.h  |  4 ++++
 board/xilinx/versal-net/board.c               | 20 -------------------
 drivers/firmware/firmware-zynqmp.c            | 18 +++++++++++++++++
 4 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/arch/arm/mach-versal-net/cpu.c b/arch/arm/mach-versal-net/cpu.c
index 4cbcb119ccb8..84fd8a67aa2f 100644
--- a/arch/arm/mach-versal-net/cpu.c
+++ b/arch/arm/mach-versal-net/cpu.c
@@ -136,6 +136,21 @@ void versal_net_timer_setup(void)
 	debug("timer 0x%llx\n", get_ticks());
 }
 
+u32 versal_net_bootmode_reg(void)
+{
+	return readl(&crp_base->boot_mode_usr);
+}
+
+u8 __weak versal_net_get_bootmode(void)
+{
+	u32 reg = versal_net_bootmode_reg();
+
+	if (reg >> BOOT_MODE_ALT_SHIFT)
+		reg >>= BOOT_MODE_ALT_SHIFT;
+
+	return reg & BOOT_MODES_MASK;
+}
+
 static u32 platform_id, platform_version;
 
 char *soc_name_decode(void)
diff --git a/arch/arm/mach-versal-net/include/mach/sys_proto.h b/arch/arm/mach-versal-net/include/mach/sys_proto.h
index 33253ca88bfe..4907dae1108f 100644
--- a/arch/arm/mach-versal-net/include/mach/sys_proto.h
+++ b/arch/arm/mach-versal-net/include/mach/sys_proto.h
@@ -9,3 +9,7 @@
 void mem_map_fill(void);
 /* EL3 clock/timer register setup, called from board_early_init_r() */
 void versal_net_timer_setup(void);
+/* Overridable bootmode decode: weak MMIO default, firmware override */
+u8 versal_net_get_bootmode(void);
+/* Direct MMIO read of the bootmode register (EL3 / no-firmware path) */
+u32 versal_net_bootmode_reg(void);
diff --git a/board/xilinx/versal-net/board.c b/board/xilinx/versal-net/board.c
index 3c69edc22606..bb099c1e7ca5 100644
--- a/board/xilinx/versal-net/board.c
+++ b/board/xilinx/versal-net/board.c
@@ -21,7 +21,6 @@
 #include <asm/arch/sys_proto.h>
 #include <dm/device.h>
 #include <dm/uclass.h>
-#include <zynqmp_firmware.h>
 #include <versalpl.h>
 #include "../common/board.h"
 
@@ -69,25 +68,6 @@ int board_early_init_r(void)
 	return 0;
 }
 
-static u8 versal_net_get_bootmode(void)
-{
-	u8 bootmode;
-	u32 reg = 0;
-
-	if (IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE) && current_el() != 3) {
-		reg = zynqmp_pm_get_bootmode_reg();
-	} else {
-		reg = readl(&crp_base->boot_mode_usr);
-	}
-
-	if (reg >> BOOT_MODE_ALT_SHIFT)
-		reg >>= BOOT_MODE_ALT_SHIFT;
-
-	bootmode = reg & BOOT_MODES_MASK;
-
-	return bootmode;
-}
-
 int spi_get_env_dev(void)
 {
 	struct udevice *dev;
diff --git a/drivers/firmware/firmware-zynqmp.c b/drivers/firmware/firmware-zynqmp.c
index f3ca0b08762c..4c4f4c19ae4b 100644
--- a/drivers/firmware/firmware-zynqmp.c
+++ b/drivers/firmware/firmware-zynqmp.c
@@ -355,6 +355,24 @@ u8 versal_get_bootmode(void)
 }
 #endif
 
+#if defined(CONFIG_ARCH_VERSAL_NET)
+u8 versal_net_get_bootmode(void)
+{
+	u32 reg;
+
+	/* At EL3 the SMC path to firmware is unavailable, read directly */
+	if (current_el() == 3)
+		reg = versal_net_bootmode_reg();
+	else
+		reg = zynqmp_pm_get_bootmode_reg();
+
+	if (reg >> BOOT_MODE_ALT_SHIFT)
+		reg >>= BOOT_MODE_ALT_SHIFT;
+
+	return reg & BOOT_MODES_MASK;
+}
+#endif
+
 #if defined(CONFIG_ARCH_VERSAL2)
 u32 versal2_pmc_multi_boot(void)
 {
-- 
2.43.0



More information about the U-Boot mailing list