]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
arm64: versal: Move bootmode decoding out of board code
authorMichal Simek <michal.simek@amd.com>
Tue, 23 Jun 2026 12:53:30 +0000 (14:53 +0200)
committerMichal Simek <michal.simek@amd.com>
Wed, 8 Jul 2026 06:55:51 +0000 (08:55 +0200)
versal_get_bootmode() lived in board code and open-coded the
IS_ENABLED(CONFIG_ZYNQMP_FIRMWARE) selection between the firmware call
zynqmp_pm_get_bootmode_reg() and a direct readl(). To keep generic board
code free of firmware specifics and SoC register details and ready for
SCMI, move the whole function, including the alt-shift and mask decoding,
behind an overridable hook.

The weak versal_get_bootmode() in arch/arm/mach-versal does the plain
MMIO read via versal_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@amd.com>
Link: https://patch.msgid.link/d60073feed8da8d3aff9eabee6ab132e0bbd0f8e.1782219202.git.michal.simek@amd.com
arch/arm/mach-versal/cpu.c
arch/arm/mach-versal/include/mach/sys_proto.h
board/xilinx/versal/board.c
drivers/firmware/firmware-zynqmp.c

index 7ad93982e8d45aff4383aa3f0e46f81e56af2cf8..5cb013d5f2e7fd33af9a7586d9408f3227f06094 100644 (file)
@@ -120,6 +120,21 @@ u32 __weak versal_pmc_multi_boot(void)
        return versal_multi_boot_reg();
 }
 
+u32 versal_bootmode_reg(void)
+{
+       return readl(&crp_base->boot_mode_usr);
+}
+
+u8 __weak versal_get_bootmode(void)
+{
+       u32 reg = versal_bootmode_reg();
+
+       if (reg >> BOOT_MODE_ALT_SHIFT)
+               reg >>= BOOT_MODE_ALT_SHIFT;
+
+       return reg & BOOT_MODES_MASK;
+}
+
 U_BOOT_DRVINFO(soc_xilinx_versal) = {
        .name = "soc_xilinx_versal",
 };
index d7ab2549658304d80f30be401d715bcd0df4d57e..f8836db5ef05727ff6fc7324a2483f4cf3bc64a1 100644 (file)
@@ -21,5 +21,9 @@ void mem_map_fill(void);
 u32 versal_pmc_multi_boot(void);
 /* Direct MMIO read of the multiboot register (EL3 / no-firmware path) */
 u32 versal_multi_boot_reg(void);
+/* Overridable bootmode decode: weak MMIO default, firmware override */
+u8 versal_get_bootmode(void);
+/* Direct MMIO read of the bootmode register (EL3 / no-firmware path) */
+u32 versal_bootmode_reg(void);
 
 #endif /* _ASM_ARCH_SYS_PROTO_H */
index 110490b96729821430bc0d290b03adeafcdbbd90..d0c15fed1e93c7fc74a5a09fec74d1595506f518 100644 (file)
@@ -28,7 +28,6 @@
 #include <dm/device.h>
 #include <dm/uclass.h>
 #include <versalpl.h>
-#include <zynqmp_firmware.h>
 #include "../common/board.h"
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -40,25 +39,6 @@ static xilinx_desc versalpl = {
 };
 #endif
 
-static u8 versal_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;
-}
-
 static u32 versal_multi_boot(void)
 {
        u8 bootmode = versal_get_bootmode();
index c8943b8d23a34b9b07d4edf6eb6ab80b4d172a75..f3ca0b08762c3f4dece4a3bb29364c76465e8b23 100644 (file)
@@ -337,6 +337,22 @@ u32 versal_pmc_multi_boot(void)
 
        return zynqmp_pm_get_pmc_multi_boot_reg() & PMC_MULTI_BOOT_MASK;
 }
+
+u8 versal_get_bootmode(void)
+{
+       u32 reg;
+
+       /* At EL3 the SMC path to firmware is unavailable, read directly */
+       if (current_el() == 3)
+               reg = versal_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)