[PATCH 11/18] arm64: versal-net: Move SoC detection out of board code

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


soc_detection() and soc_name_decode() read the PMC_TAP version/idcode
registers and decode the platform. This is SoC information rather than
board policy, and a firmware interface could provide it instead, so it
does not belong in board code.

Move both functions, together with the shared platform_id and
platform_version state, into arch/arm/mach-versal-net where they still
override the weak stubs in the Xilinx common board code. The board file
drops the now unused linux/bitfield.h include.

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

 arch/arm/mach-versal-net/cpu.c  | 91 +++++++++++++++++++++++++++++++++
 board/xilinx/versal-net/board.c | 87 -------------------------------
 2 files changed, 91 insertions(+), 87 deletions(-)

diff --git a/arch/arm/mach-versal-net/cpu.c b/arch/arm/mach-versal-net/cpu.c
index 5e7c1bebf2cc..4cbcb119ccb8 100644
--- a/arch/arm/mach-versal-net/cpu.c
+++ b/arch/arm/mach-versal-net/cpu.c
@@ -8,7 +8,9 @@
 
 #include <init.h>
 #include <log.h>
+#include <malloc.h>
 #include <time.h>
+#include <vsprintf.h>
 #include <asm/armv8/mmu.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
@@ -17,6 +19,9 @@
 #include <asm/arch/sys_proto.h>
 #include <asm/cache.h>
 #include <dm/platdata.h>
+#include <linux/bitfield.h>
+#include <linux/string.h>
+#include "../../../board/xilinx/common/board.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -131,6 +136,92 @@ void versal_net_timer_setup(void)
 	debug("timer 0x%llx\n", get_ticks());
 }
 
+static u32 platform_id, platform_version;
+
+char *soc_name_decode(void)
+{
+	char *name, *platform_name;
+
+	switch (platform_id) {
+	case VERSAL_NET_SPP:
+		platform_name = "ipp";
+		break;
+	case VERSAL_NET_EMU:
+		platform_name = "emu";
+		break;
+	case VERSAL_NET_QEMU:
+		platform_name = "qemu";
+		break;
+	default:
+		return NULL;
+	}
+
+	/*
+	 * --rev. are 6 chars
+	 * max platform name is qemu which is 4 chars
+	 * platform version number are 1+1
+	 * Plus 1 char for \n
+	 */
+	name = calloc(1, strlen(CONFIG_SYS_BOARD) + 13);
+	if (!name)
+		return NULL;
+
+	sprintf(name, "%s-%s-rev%d.%d", CONFIG_SYS_BOARD,
+		platform_name, platform_version / 10,
+		platform_version % 10);
+
+	return name;
+}
+
+bool soc_detection(void)
+{
+	u32 version, ps_version;
+
+	version = readl(PMC_TAP_VERSION);
+	platform_id = FIELD_GET(PLATFORM_MASK, version);
+	ps_version = FIELD_GET(PS_VERSION_MASK, version);
+
+	debug("idcode %x, version %x, usercode %x\n",
+	      readl(PMC_TAP_IDCODE), version,
+	      readl(PMC_TAP_USERCODE));
+
+	debug("pmc_ver %lx, ps version %x, rtl version %lx\n",
+	      FIELD_GET(PMC_VERSION_MASK, version),
+	      ps_version,
+	      FIELD_GET(RTL_VERSION_MASK, version));
+
+	platform_version = FIELD_GET(PLATFORM_VERSION_MASK, version);
+
+	if (platform_id == VERSAL_NET_SPP ||
+	    platform_id == VERSAL_NET_EMU) {
+		if (ps_version == PS_VERSION_PRODUCTION) {
+			/*
+			 * ES1 version ends at 1.9 version where there was +9
+			 * used because of IPP/SPP conversion. Production
+			 * version have platform_version started from 0 again
+			 * that's why adding +20 to continue with the same line.
+			 * It means the last ES1 version ends at 1.9 version and
+			 * new PRODUCTION line starts at 2.0.
+			 */
+			platform_version += 20;
+		} else {
+			/*
+			 * 9 is diff for
+			 * 0 means 0.9 version
+			 * 1 means 1.0 version
+			 * 2 means 1.1 version
+			 * etc,
+			 */
+			platform_version += 9;
+		}
+	}
+
+	debug("Platform id: %d version: %d.%d\n", platform_id,
+	      platform_version / 10, platform_version % 10);
+
+	return true;
+}
+
 U_BOOT_DRVINFO(soc_xilinx_versal_net) = {
 	.name = "soc_xilinx_versal_net",
 };
diff --git a/board/xilinx/versal-net/board.c b/board/xilinx/versal-net/board.c
index a40039a1dc8e..3c69edc22606 100644
--- a/board/xilinx/versal-net/board.c
+++ b/board/xilinx/versal-net/board.c
@@ -25,7 +25,6 @@
 #include <versalpl.h>
 #include "../common/board.h"
 
-#include <linux/bitfield.h>
 #include <debug_uart.h>
 #include <generated/dt.h>
 
@@ -49,92 +48,6 @@ int board_init(void)
 	return 0;
 }
 
-static u32 platform_id, platform_version;
-
-char *soc_name_decode(void)
-{
-	char *name, *platform_name;
-
-	switch (platform_id) {
-	case VERSAL_NET_SPP:
-		platform_name = "ipp";
-		break;
-	case VERSAL_NET_EMU:
-		platform_name = "emu";
-		break;
-	case VERSAL_NET_QEMU:
-		platform_name = "qemu";
-		break;
-	default:
-		return NULL;
-	}
-
-	/*
-	 * --rev. are 6 chars
-	 * max platform name is qemu which is 4 chars
-	 * platform version number are 1+1
-	 * Plus 1 char for \n
-	 */
-	name = calloc(1, strlen(CONFIG_SYS_BOARD) + 13);
-	if (!name)
-		return NULL;
-
-	sprintf(name, "%s-%s-rev%d.%d", CONFIG_SYS_BOARD,
-		platform_name, platform_version / 10,
-		platform_version % 10);
-
-	return name;
-}
-
-bool soc_detection(void)
-{
-	u32 version, ps_version;
-
-	version = readl(PMC_TAP_VERSION);
-	platform_id = FIELD_GET(PLATFORM_MASK, version);
-	ps_version = FIELD_GET(PS_VERSION_MASK, version);
-
-	debug("idcode %x, version %x, usercode %x\n",
-	      readl(PMC_TAP_IDCODE), version,
-	      readl(PMC_TAP_USERCODE));
-
-	debug("pmc_ver %lx, ps version %x, rtl version %lx\n",
-	      FIELD_GET(PMC_VERSION_MASK, version),
-	      ps_version,
-	      FIELD_GET(RTL_VERSION_MASK, version));
-
-	platform_version = FIELD_GET(PLATFORM_VERSION_MASK, version);
-
-	if (platform_id == VERSAL_NET_SPP ||
-	    platform_id == VERSAL_NET_EMU) {
-		if (ps_version == PS_VERSION_PRODUCTION) {
-			/*
-			 * ES1 version ends at 1.9 version where there was +9
-			 * used because of IPP/SPP conversion. Production
-			 * version have platform_version started from 0 again
-			 * that's why adding +20 to continue with the same line.
-			 * It means the last ES1 version ends at 1.9 version and
-			 * new PRODUCTION line starts at 2.0.
-			 */
-			platform_version += 20;
-		} else {
-			/*
-			 * 9 is diff for
-			 * 0 means 0.9 version
-			 * 1 means 1.0 version
-			 * 2 means 1.1 version
-			 * etc,
-			 */
-			platform_version += 9;
-		}
-	}
-
-	debug("Platform id: %d version: %d.%d\n", platform_id,
-	      platform_version / 10, platform_version % 10);
-
-	return true;
-}
-
 int board_early_init_f(void)
 {
 	if (IS_ENABLED(CONFIG_DEBUG_UART)) {
-- 
2.43.0



More information about the U-Boot mailing list