Skip to contentSkip to conversation

cmd: cpu: migrate cpu command to U_BOOT_CMD_WITH_SUBCMDS()

PATCH In review Ovidiu Panait 3 participants 17 messages May 31, 2022 – Jun 7, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/14 cmd: cpu: migrate cpu command to U_BOOT_CMD_WITH_SUBCMDS()

Migrate cpu command to use U_BOOT_CMD_WITH_SUBCMDS() helper macro, to reduce duplicated code. This also fixes the cpu command on boards that enable CONFIG_NEEDS_MANUAL_RELOC.

---
NOTE: this series depends on the following "events" patch:
https://lore.kernel.org/u-boot/[email protected]/

Changes in v2:
- New patch.

 cmd/cpu.c | 39 ++++++++-------------------------------
 1 file changed, 8 insertions(+), 31 deletions(-)
cmd/cpu.c +8 -31
index 67dbb044b5..2ca4d05ae8 100644
@@ -82,36 +82,13 @@ static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static struct cmd_tbl cmd_cpu_sub[] = {
-	U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
-	U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
-};
-
-/*
- * Process a cpu sub-command
- */
-static int do_cpu(struct cmd_tbl *cmdtp, int flag, int argc,
-		  char *const argv[])
-{
-	struct cmd_tbl *c = NULL;
-
-	/* Strip off leading 'cpu' command argument */
-	argc--;
-	argv++;
-
-	if (argc)
-		c = find_cmd_tbl(argv[0], cmd_cpu_sub,
-				 ARRAY_SIZE(cmd_cpu_sub));
-
-	if (c)
-		return c->cmd(cmdtp, flag, argc, argv);
-	else
-		return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-	cpu, 2, 1, do_cpu,
-	"display information about CPUs",
+#if CONFIG_IS_ENABLED(SYS_LONGHELP)
+static char cpu_help_text[] =
 	"list	- list available CPUs\n"
 	"cpu detail	- show CPU detail"
-);
+	;
+#endif
+
+U_BOOT_CMD_WITH_SUBCMDS(cpu, "display information about CPUs", cpu_help_text,
+	U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cpu_list),
+	U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail));
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 2/14 cpu-uclass: relocate ops pointers for CONFIG_NEEDS_MANUAL_RELOC

Relocate cpu_ops pointers when CONFIG_NEEDS_MANUAL_RELOC is enabled.

The (gd->flags & GD_FLG_RELOC) check was added to make sure the reloc_done logic works for drivers that use DM_FLAG_PRE_RELOC.

---

Changes in v2:
- New patch.

 drivers/cpu/cpu-uclass.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
drivers/cpu/cpu-uclass.c +30 -0
index a5cda6a62c..71e5900d70 100644
@@ -14,6 +14,9 @@
 #include <dm/lists.h>
 #include <dm/root.h>
 #include <linux/err.h>
+#include <relocate.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 int cpu_probe_all(void)
 {
@@ -136,9 +139,36 @@ static int uclass_cpu_init(struct uclass *uc)
 	return ret;
 }
 
+static int uclass_cpu_post_bind(struct udevice *dev)
+{
+	if (IS_ENABLED(CONFIG_NEEDS_MANUAL_RELOC) &&
+	    (gd->flags & GD_FLG_RELOC)) {
+		struct cpu_ops *ops = cpu_get_ops(dev);
+		static int reloc_done;
+
+		if (!reloc_done) {
+			if (ops->get_desc)
+				MANUAL_RELOC(ops->get_desc);
+			if (ops->get_info)
+				MANUAL_RELOC(ops->get_info);
+			if (ops->get_count)
+				MANUAL_RELOC(ops->get_count);
+			if (ops->get_vendor)
+				MANUAL_RELOC(ops->get_vendor);
+			if (ops->is_current)
+				MANUAL_RELOC(ops->is_current);
+
+			reloc_done++;
+		}
+	}
+
+	return 0;
+}
+
 UCLASS_DRIVER(cpu) = {
 	.id		= UCLASS_CPU,
 	.name		= "cpu",
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
 	.init		= uclass_cpu_init,
+	.post_bind	= uclass_cpu_post_bind,
 };
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 3/14 microblaze: start.S: remove unused code

In reply to Ovidiu Panait

in16/out16 routines seem to not be used anywhere in microblaze code, so remove them.

---

(no changes since v1)

 arch/microblaze/cpu/start.S | 33 ---------------------------------
 1 file changed, 33 deletions(-)
arch/microblaze/cpu/start.S +0 -33
index 645f7cb038..d1b0453caf 100644
@@ -220,39 +220,6 @@ __setup_exceptions:
 	or	r0, r0, r0
 	.end	__setup_exceptions
 
-/*
- * Read 16bit little endian
- */
-	.text
-	.global	in16
-	.ent	in16
-	.align	2
-in16:	lhu	r3, r0, r5
-	bslli	r4, r3, 8
-	bsrli	r3, r3, 8
-	andi	r4, r4, 0xffff
-	or	r3, r3, r4
-	rtsd	r15, 8
-	sext16	r3, r3
-	.end	in16
-
-/*
- * Write 16bit little endian
- * first parameter(r5) - address, second(r6) - short value
- */
-	.text
-	.global	out16
-	.ent	out16
-	.align	2
-out16:	bslli	r3, r6, 8
-	bsrli	r6, r6, 8
-	andi	r3, r3, 0xffff
-	or	r3, r3, r6
-	sh	r3, r0, r5
-	rtsd	r15, 8
-	or	r0, r0, r0
-	.end	out16
-
 /*
  * Relocate u-boot
  */
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 4/14 microblaze: cache: replace XILINX_USE_DCACHE -> CONFIG_DCACHE

In reply to Ovidiu Panait

XILINX_USE_DCACHE macro was removed in 7556fa09e0e ("microblaze: Simplify cache handling"), but it was still used in a couple of places.

Replace those occurences with CONFIG_DCACHE.

---

(no changes since v1)

 arch/microblaze/cpu/cache.c | 2 +-
 arch/microblaze/lib/bootm.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
arch/microblaze/cpu/cache.c +1 -1
index aa832d6be6..b6126de194 100644
@@ -49,7 +49,7 @@ void dcache_enable(void)
 
 void dcache_disable(void)
 {
-#ifdef XILINX_USE_DCACHE
+#ifdef CONFIG_DCACHE
 	flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
 #endif
 	MSRCLR(0x80);
arch/microblaze/lib/bootm.c +1 -1
index 12ea32488e..b652d2767a 100644
@@ -57,7 +57,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
 	       "(fake run for tracing)" : "");
 	bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
 
-#ifdef XILINX_USE_DCACHE
+#ifdef CONFIG_DCACHE
 	flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
 #endif
 
Signature · 1 line
2.25.1
#4 lore raw

PATCH v2 5/14 microblaze: cache: improve dcache Kconfig options

In reply to Ovidiu Panait

Replace CONFIG_DCACHE with a Kconfig option more limited in scope - XILINX_MICROBLAZE0_USE_WDC. It should be enabled if the processor supports the "wdc" (Write to Data Cache) instruction. It will be used to guard "wdc" invocations in microblaze cache code.

Also, drop all ifdefs around flush_cache() calls and only keep one CONFIG_IS_ENABLED() guard within flush_cache() itself.

---

Changes in v2:
- added CONFIG_SPL_XILINX_MICROBLAZE0_USE_WDC symbol

 arch/microblaze/Kconfig                 |  4 ----
 arch/microblaze/cpu/cache.c             | 15 ++++++++++-----
 arch/microblaze/lib/bootm.c             |  2 --
 board/xilinx/microblaze-generic/Kconfig | 11 +++++++++++
 4 files changed, 21 insertions(+), 11 deletions(-)
arch/microblaze/Kconfig +0 -4
index d7d1b21970..5a2e91104f 100644
@@ -25,10 +25,6 @@ config TARGET_MICROBLAZE_GENERIC
 
 endchoice
 
-config DCACHE
-	bool "Enable dcache support"
-	default y
-
 config ICACHE
 	bool "Enable icache support"
 	default y
arch/microblaze/cpu/cache.c +10 -5
index b6126de194..4e8e228a22 100644
@@ -49,26 +49,31 @@ void dcache_enable(void)
 
 void dcache_disable(void)
 {
-#ifdef CONFIG_DCACHE
 	flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
-#endif
+
 	MSRCLR(0x80);
 }
 
 void flush_cache(ulong addr, ulong size)
 {
 	int i;
-	for (i = 0; i < size; i += 4)
+	for (i = 0; i < size; i += 4) {
 		asm volatile (
 #ifdef CONFIG_ICACHE
 				"wic	%0, r0;"
 #endif
 				"nop;"
-#ifdef CONFIG_DCACHE
+				:
+				: "r" (addr + i)
+				: "memory");
+
+		if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
+			asm volatile (
 				"wdc.flush	%0, r0;"
-#endif
 				"nop;"
 				:
 				: "r" (addr + i)
 				: "memory");
+		}
+	}
 }
arch/microblaze/lib/bootm.c +0 -2
index b652d2767a..dba6226ce5 100644
@@ -57,9 +57,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
 	       "(fake run for tracing)" : "");
 	bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
 
-#ifdef CONFIG_DCACHE
 	flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
-#endif
 
 	if (!fake) {
 		/*
board/xilinx/microblaze-generic/Kconfig +11 -0
index 117b476f3f..b00ce6f59a 100644
@@ -63,4 +63,15 @@ config XILINX_MICROBLAZE0_VECTOR_BASE_ADDR
 	  Memory address location of the exception vector table. It is
 	  configurable via the C_BASE_VECTORS hdl parameter.
 
+config XILINX_MICROBLAZE0_USE_WDC
+	bool "MicroBlaze wdc instruction support"
+	default y
+	help
+	  Enable this option if the MicroBlaze processor is configured with
+	  support for the "wdc" (Write to Data Cache) instruction.
+
+config SPL_XILINX_MICROBLAZE0_USE_WDC
+	bool
+	default XILINX_MICROBLAZE0_USE_WDC
+
 endif
Signature · 1 line
2.25.1
#5 lore raw

PATCH v2 6/14 microblaze: cache: improve icache Kconfig options

In reply to Ovidiu Panait

Replace CONFIG_ICACHE with a Kconfig option more limited in scope - XILINX_MICROBLAZE0_USE_WIC. It should be enabled if the processor supports the "wic" (Write to Instruction Cache) instruction. It will be used to guard "wic" invocations in microblaze cache code.

---

Changes in v2:
- added CONFIG_SPL_XILINX_MICROBLAZE0_USE_WIC symbol

 arch/microblaze/Kconfig                 |  4 ----
 arch/microblaze/cpu/cache.c             |  6 +++---
 board/xilinx/microblaze-generic/Kconfig | 11 +++++++++++
 3 files changed, 14 insertions(+), 7 deletions(-)
arch/microblaze/Kconfig +0 -4
index 5a2e91104f..a25a95a013 100644
@@ -25,10 +25,6 @@ config TARGET_MICROBLAZE_GENERIC
 
 endchoice
 
-config ICACHE
-	bool "Enable icache support"
-	default y
-
 source "board/xilinx/Kconfig"
 source "board/xilinx/microblaze-generic/Kconfig"
 
arch/microblaze/cpu/cache.c +3 -3
index 4e8e228a22..b6bbc215b3 100644
@@ -58,14 +58,14 @@ void flush_cache(ulong addr, ulong size)
 {
 	int i;
 	for (i = 0; i < size; i += 4) {
-		asm volatile (
-#ifdef CONFIG_ICACHE
+		if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) {
+			asm volatile (
 				"wic	%0, r0;"
-#endif
 				"nop;"
 				:
 				: "r" (addr + i)
 				: "memory");
+		}
 
 		if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
 			asm volatile (
board/xilinx/microblaze-generic/Kconfig +11 -0
index b00ce6f59a..98b4814b95 100644
@@ -74,4 +74,15 @@ config SPL_XILINX_MICROBLAZE0_USE_WDC
 	bool
 	default XILINX_MICROBLAZE0_USE_WDC
 
+config XILINX_MICROBLAZE0_USE_WIC
+	bool "MicroBlaze wic instruction support"
+	default y
+	help
+	  Enable this option if the MicroBlaze processor is configured with
+	  support for the "wic" (Write to Instruction Cache) instruction.
+
+config SPL_XILINX_MICROBLAZE0_USE_WIC
+	bool
+	default XILINX_MICROBLAZE0_USE_WIC
+
 endif
Signature · 1 line
2.25.1
#6 lore raw

PATCH v2 7/14 microblaze: cache: split flush_cache() function

In reply to Ovidiu Panait

Factor out icache/dcache components from flush_cache() function. Call the newly added __flush_icache()/__flush_dcache() functions inside icache_disable() and dcache_disable(), respectively. There is no need to flush both caches when disabling a particular cache type.

---

(no changes since v1)

 arch/microblaze/cpu/cache.c | 55 ++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 22 deletions(-)
arch/microblaze/cpu/cache.c +33 -22
index b6bbc215b3..e362a34a79 100644
@@ -10,6 +10,34 @@
 #include <asm/asm.h>
 #include <asm/cache.h>
 
+static void __invalidate_icache(ulong addr, ulong size)
+{
+	if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) {
+		for (int i = 0; i < size; i += 4) {
+			asm volatile (
+				"wic	%0, r0;"
+				"nop;"
+				:
+				: "r" (addr + i)
+				: "memory");
+		}
+	}
+}
+
+static void __flush_dcache(ulong addr, ulong size)
+{
+	if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
+		for (int i = 0; i < size; i += 4) {
+			asm volatile (
+				"wdc.flush	%0, r0;"
+				"nop;"
+				:
+				: "r" (addr + i)
+				: "memory");
+		}
+	}
+}
+
 int dcache_status(void)
 {
 	int i = 0;
@@ -38,7 +66,8 @@ void icache_enable(void)
 void icache_disable(void)
 {
 	/* we are not generate ICACHE size -> flush whole cache */
-	flush_cache(0, 32768);
+	__invalidate_icache(0, 32768);
+
 	MSRCLR(0x20);
 }
 
@@ -49,31 +78,13 @@ void dcache_enable(void)
 
 void dcache_disable(void)
 {
-	flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
+	__flush_dcache(0, XILINX_DCACHE_BYTE_SIZE);
 
 	MSRCLR(0x80);
 }
 
 void flush_cache(ulong addr, ulong size)
 {
-	int i;
-	for (i = 0; i < size; i += 4) {
-		if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) {
-			asm volatile (
-				"wic	%0, r0;"
-				"nop;"
-				:
-				: "r" (addr + i)
-				: "memory");
-		}
-
-		if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
-			asm volatile (
-				"wdc.flush	%0, r0;"
-				"nop;"
-				:
-				: "r" (addr + i)
-				: "memory");
-		}
-	}
+	__invalidate_icache(addr, size);
+	__flush_dcache(addr, size);
 }
Signature · 1 line
2.25.1
#7 lore raw

PATCH v2 8/14 microblaze: cache: introduce Kconfig options for icache/dcache sizes

In reply to Ovidiu Panait

Replace XILINX_DCACHE_BYTE_SIZE macro with two Kconfig symbols for instruction and data caches sizes, respectively:
CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE

Also, get rid of the hardcoded value in icache_disable().

---

Changes in v2:
- added separate Kconfig symbols for icache/dcache

 arch/microblaze/cpu/cache.c             |  5 ++---
 arch/microblaze/cpu/start.S             |  4 ++--
 arch/microblaze/lib/bootm.c             |  2 +-
 board/xilinx/microblaze-generic/Kconfig | 16 ++++++++++++++++
 include/configs/microblaze-generic.h    |  4 ----
 5 files changed, 21 insertions(+), 10 deletions(-)
arch/microblaze/cpu/cache.c +2 -3
index e362a34a79..d5c0afd935 100644
@@ -65,8 +65,7 @@ void icache_enable(void)
 
 void icache_disable(void)
 {
-	/* we are not generate ICACHE size -> flush whole cache */
-	__invalidate_icache(0, 32768);
+	__invalidate_icache(0, CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE);
 
 	MSRCLR(0x20);
 }
@@ -78,7 +77,7 @@ void dcache_enable(void)
 
 void dcache_disable(void)
 {
-	__flush_dcache(0, XILINX_DCACHE_BYTE_SIZE);
+	__flush_dcache(0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE);
 
 	MSRCLR(0x80);
 }
arch/microblaze/cpu/start.S +2 -2
index d1b0453caf..356ca05392 100644
@@ -53,7 +53,7 @@ _start:
 
 	/* Flush cache before enable cache */
 	addik	r5, r0, 0
-	addik	r6, r0, XILINX_DCACHE_BYTE_SIZE
+	addik	r6, r0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE
 	bralid	r15, flush_cache
 	nop
 
@@ -284,7 +284,7 @@ relocate_code:
 
 	/* Flush caches to ensure consistency */
 	addik	r5, r0, 0
-	addik	r6, r0, XILINX_DCACHE_BYTE_SIZE
+	addik	r6, r0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE
 	bralid	r15, flush_cache
 	nop
 
arch/microblaze/lib/bootm.c +1 -1
index dba6226ce5..48e05333a6 100644
@@ -57,7 +57,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
 	       "(fake run for tracing)" : "");
 	bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
 
-	flush_cache(0, XILINX_DCACHE_BYTE_SIZE);
+	flush_cache(0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE);
 
 	if (!fake) {
 		/*
board/xilinx/microblaze-generic/Kconfig +16 -0
index 98b4814b95..a6743cadf4 100644
@@ -85,4 +85,20 @@ config SPL_XILINX_MICROBLAZE0_USE_WIC
 	bool
 	default XILINX_MICROBLAZE0_USE_WIC
 
+config XILINX_MICROBLAZE0_DCACHE_SIZE
+	int "Default data cache size"
+	default 32768
+	help
+	  This fallback size will be used when no dcache info can be found in
+	  the device tree, or when the data cache is flushed very early in the
+	  boot process, before device tree is available.
+
+config XILINX_MICROBLAZE0_ICACHE_SIZE
+	int "Default instruction cache size"
+	default 32768
+	help
+	  This fallback size will be used when no icache info can be found in
+	  the device tree, or when the instruction cache is flushed very early
+	  in the boot process, before device tree is available.
+
 endif
include/configs/microblaze-generic.h +0 -4
index 663837f33d..7b064eacb2 100644
@@ -30,10 +30,6 @@
 # define CONFIG_SYS_MAX_FLASH_SECT	2048
 #endif
 
-#ifndef XILINX_DCACHE_BYTE_SIZE
-#define XILINX_DCACHE_BYTE_SIZE	32768
-#endif
-
 /* size of console buffer */
 #define	CONFIG_SYS_CBSIZE	512
 /* max number of command args */
Signature · 1 line
2.25.1
#8 lore raw

PATCH v2 9/14 microblaze: cache: introduce flush_cache_all()

In reply to Ovidiu Panait

All flush_cache() calls in microblaze code are supposed to flush the entire instruction and data caches, so introduce flush_cache_all() helper to handle this.

Also, provide implementations for flush_dcache_all() and invalidate_icache_all() so that icache and dcache u-boot commands can work.

---

Changes in v2:
- adjusted for newly added CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE and CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE Kconfig symbols

 arch/microblaze/cpu/cache.c         | 20 ++++++++++++++++++--
 arch/microblaze/cpu/start.S         |  8 ++------
 arch/microblaze/include/asm/cache.h |  5 +++++
 arch/microblaze/lib/bootm.c         |  2 +-
 4 files changed, 26 insertions(+), 9 deletions(-)
arch/microblaze/cpu/cache.c +18 -2
index d5c0afd935..b99b8c1706 100644
@@ -24,6 +24,11 @@ static void __invalidate_icache(ulong addr, ulong size)
 	}
 }
 
+void invalidate_icache_all(void)
+{
+	__invalidate_icache(0, CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE);
+}
+
 static void __flush_dcache(ulong addr, ulong size)
 {
 	if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
@@ -38,6 +43,11 @@ static void __flush_dcache(ulong addr, ulong size)
 	}
 }
 
+void flush_dcache_all(void)
+{
+	__flush_dcache(0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE);
+}
+
 int dcache_status(void)
 {
 	int i = 0;
@@ -65,7 +75,7 @@ void icache_enable(void)
 
 void icache_disable(void)
 {
-	__invalidate_icache(0, CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE);
+	invalidate_icache_all();
 
 	MSRCLR(0x20);
 }
@@ -77,7 +87,7 @@ void dcache_enable(void)
 
 void dcache_disable(void)
 {
-	__flush_dcache(0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE);
+	flush_dcache_all();
 
 	MSRCLR(0x80);
 }
@@ -87,3 +97,9 @@ void flush_cache(ulong addr, ulong size)
 	__invalidate_icache(addr, size);
 	__flush_dcache(addr, size);
 }
+
+void flush_cache_all(void)
+{
+	invalidate_icache_all();
+	flush_dcache_all();
+}
arch/microblaze/cpu/start.S +2 -6
index 356ca05392..7f7b5f5cb5 100644
@@ -52,9 +52,7 @@ _start:
 #endif
 
 	/* Flush cache before enable cache */
-	addik	r5, r0, 0
-	addik	r6, r0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE
-	bralid	r15, flush_cache
+	bralid	r15, flush_cache_all
 	nop
 
 	/* enable instruction and data cache */
@@ -283,9 +281,7 @@ relocate_code:
 	addk	r20, r20, r23
 
 	/* Flush caches to ensure consistency */
-	addik	r5, r0, 0
-	addik	r6, r0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE
-	bralid	r15, flush_cache
+	bralid	r15, flush_cache_all
 	nop
 
 2:	addi	r5, r31, 0 /* gd is initialized in board_r.c */
arch/microblaze/include/asm/cache.h +5 -0
index baee01a0e2..c39b66dd7d 100644
@@ -18,4 +18,9 @@
 #define ARCH_DMA_MINALIGN	16
 #endif
 
+/**
+ * flush_cache_all - flush the entire instruction/data caches
+ */
+void flush_cache_all(void);
+
 #endif /* __MICROBLAZE_CACHE_H__ */
arch/microblaze/lib/bootm.c +1 -1
index 48e05333a6..af946b8642 100644
@@ -57,7 +57,7 @@ static void boot_jump_linux(bootm_headers_t *images, int flag)
 	       "(fake run for tracing)" : "");
 	bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
 
-	flush_cache(0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE);
+	flush_cache_all();
 
 	if (!fake) {
 		/*
Signature · 1 line
2.25.1
#9 lore raw

PATCH v2 10/14 microblaze: cache: introduce cpuinfo structure

In reply to Ovidiu Panait

Introduce a minimal cpuinfo structure to hold cache related info. The instruction/data cache size and cache line size are initialized early in the boot to default Kconfig values. They will be overwritten with data from PVR/dtb if the microblaze UCLASS_CPU driver is enabled.

The cpuinfo struct was placed in global_data to allow the microblaze UCLASS_CPU driver to also run before relocation (initialized global data should be read-only before relocation).

gd_cpuinfo() helper macro was added to avoid volatile "-Wdiscarded-qualifiers" warnings when using the pointer directly.

---

Changes in v2:
- New patch.

 arch/microblaze/cpu/Makefile              |  2 +-
 arch/microblaze/cpu/cache.c               | 14 ++++++---
 arch/microblaze/cpu/cpuinfo.c             | 20 +++++++++++++
 arch/microblaze/cpu/start.S               |  7 +++++
 arch/microblaze/include/asm/cpuinfo.h     | 35 +++++++++++++++++++++++
 arch/microblaze/include/asm/global_data.h |  5 ++++
 6 files changed, 78 insertions(+), 5 deletions(-)
 create mode 100644 arch/microblaze/cpu/cpuinfo.c
 create mode 100644 arch/microblaze/include/asm/cpuinfo.h
arch/microblaze/cpu/Makefile +1 -1
index f7a83d07b6..5388a21550 100644
@@ -5,5 +5,5 @@
 
 extra-y	= start.o
 obj-y	= irq.o
-obj-y	+= interrupts.o cache.o exception.o timer.o
+obj-y	+= interrupts.o cache.o exception.o timer.o cpuinfo.o
 obj-$(CONFIG_SPL_BUILD)	+= spl.o
arch/microblaze/cpu/cache.c +10 -4
index b99b8c1706..cd8507901d 100644
@@ -9,11 +9,16 @@
 #include <cpu_func.h>
 #include <asm/asm.h>
 #include <asm/cache.h>
+#include <asm/cpuinfo.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 static void __invalidate_icache(ulong addr, ulong size)
 {
 	if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) {
-		for (int i = 0; i < size; i += 4) {
+		for (int i = 0; i < size;
+		     i += gd_cpuinfo()->icache_line_length) {
 			asm volatile (
 				"wic	%0, r0;"
 				"nop;"
@@ -26,13 +31,14 @@ static void __invalidate_icache(ulong addr, ulong size)
 
 void invalidate_icache_all(void)
 {
-	__invalidate_icache(0, CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE);
+	__invalidate_icache(0, gd_cpuinfo()->icache_size);
 }
 
 static void __flush_dcache(ulong addr, ulong size)
 {
 	if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
-		for (int i = 0; i < size; i += 4) {
+		for (int i = 0; i < size;
+		     i += gd_cpuinfo()->dcache_line_length) {
 			asm volatile (
 				"wdc.flush	%0, r0;"
 				"nop;"
@@ -45,7 +51,7 @@ static void __flush_dcache(ulong addr, ulong size)
 
 void flush_dcache_all(void)
 {
-	__flush_dcache(0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE);
+	__flush_dcache(0, gd_cpuinfo()->dcache_size);
 }
 
 int dcache_status(void)
arch/microblaze/cpu/cpuinfo.c new file +20 -0
new file mode 100644
index 0000000000..3f0b1d2c04
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022, Ovidiu Panait <[email protected]>
+ */
+#include <common.h>
+#include <asm/cpuinfo.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+void microblaze_early_cpuinfo_init(void)
+{
+	struct microblaze_cpuinfo *ci = gd_cpuinfo();
+
+	ci->icache_size = CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE;
+	ci->icache_line_length = 4;
+
+	ci->dcache_size = CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE;
+	ci->dcache_line_length = 4;
+}
arch/microblaze/cpu/start.S +7 -0
index 7f7b5f5cb5..ad400a4be5 100644
@@ -51,6 +51,13 @@ _start:
 	nop
 #endif
 
+	/*
+	 * Initialize global data cpuinfo with default values (cache
+	 * size, cache line size, etc).
+	 */
+	bralid	r15, microblaze_early_cpuinfo_init
+	nop
+
 	/* Flush cache before enable cache */
 	bralid	r15, flush_cache_all
 	nop
arch/microblaze/include/asm/cpuinfo.h new file +35 -0
new file mode 100644
index 0000000000..c27dd40af7
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2022, Ovidiu Panait <[email protected]>
+ */
+
+#ifndef __ASM_MICROBLAZE_CPUINFO_H
+#define __ASM_MICROBLAZE_CPUINFO_H
+
+/**
+ * struct microblaze_cpuinfo - CPU info for microblaze processor core.
+ *
+ * @icache_size: Size of instruction cache memory in bytes.
+ * @icache_line_length: Instruction cache line length in bytes.
+ * @dcache_size: Size of data cache memory in bytes.
+ * @dcache_line_length: Data cache line length in bytes.
+ */
+struct microblaze_cpuinfo {
+	u32 icache_size;
+	u32 icache_line_length;
+
+	u32 dcache_size;
+	u32 dcache_line_length;
+};
+
+/**
+ * microblaze_early_cpuinfo_init() - Initialize cpuinfo with default values.
+ *
+ * Initializes the global data cpuinfo structure with default values (cache
+ * size, cache line size, etc.). It is called very early in the boot process
+ * (start.S codepath right before the first cache flush call) to ensure that
+ * cache related operations are properly handled.
+ */
+void microblaze_early_cpuinfo_init(void);
+
+#endif	/* __ASM_MICROBLAZE_CPUINFO_H */
arch/microblaze/include/asm/global_data.h +5 -0
index 05868ac4f5..93506dec89 100644
@@ -8,12 +8,17 @@
 #ifndef	__ASM_GBL_DATA_H
 #define __ASM_GBL_DATA_H
 
+#include <asm/cpuinfo.h>
+
 /* Architecture-specific global data */
 struct arch_global_data {
+	struct microblaze_cpuinfo cpuinfo;
 };
 
 #include <asm-generic/global_data.h>
 
 #define DECLARE_GLOBAL_DATA_PTR     register volatile gd_t *gd asm ("r31")
 
+#define gd_cpuinfo()	((struct microblaze_cpuinfo *)&gd->arch.cpuinfo)
+
 #endif /* __ASM_GBL_DATA_H */
Signature · 1 line
2.25.1
maintainer
#10 lore raw

Re: [PATCH v2 10/14] microblaze: cache: introduce cpuinfo structure

út 31. 5. 2022 v 20:15 odesílatel Ovidiu Panait <[email protected]> napsal:

Quoted 150 lines

Introduce a minimal cpuinfo structure to hold cache related info. The instruction/data cache size and cache line size are initialized early in the boot to default Kconfig values. They will be overwritten with data from PVR/dtb if the microblaze UCLASS_CPU driver is enabled.

The cpuinfo struct was placed in global_data to allow the microblaze UCLASS_CPU driver to also run before relocation (initialized global data should be read-only before relocation).

gd_cpuinfo() helper macro was added to avoid volatile "-Wdiscarded-qualifiers" warnings when using the pointer directly.

---

Changes in v2:
- New patch.

 arch/microblaze/cpu/Makefile              |  2 +-
 arch/microblaze/cpu/cache.c               | 14 ++++++---
 arch/microblaze/cpu/cpuinfo.c             | 20 +++++++++++++
 arch/microblaze/cpu/start.S               |  7 +++++
 arch/microblaze/include/asm/cpuinfo.h     | 35 +++++++++++++++++++++++
 arch/microblaze/include/asm/global_data.h |  5 ++++
 6 files changed, 78 insertions(+), 5 deletions(-)
 create mode 100644 arch/microblaze/cpu/cpuinfo.c
 create mode 100644 arch/microblaze/include/asm/cpuinfo.h
arch/microblaze/cpu/Makefile +1 -1
index f7a83d07b6..5388a21550 100644
@@ -5,5 +5,5 @@
 
 extra-y        = start.o
 obj-y  = irq.o
-obj-y  += interrupts.o cache.o exception.o timer.o
+obj-y  += interrupts.o cache.o exception.o timer.o cpuinfo.o
 obj-$(CONFIG_SPL_BUILD)        += spl.o
arch/microblaze/cpu/cache.c +10 -4
index b99b8c1706..cd8507901d 100644
@@ -9,11 +9,16 @@
 #include <cpu_func.h>
 #include <asm/asm.h>
 #include <asm/cache.h>
+#include <asm/cpuinfo.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 static void __invalidate_icache(ulong addr, ulong size)
 {
        if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WIC)) {
-               for (int i = 0; i < size; i += 4) {
+               for (int i = 0; i < size;
+                    i += gd_cpuinfo()->icache_line_length) {
                        asm volatile (
                                "wic    %0, r0;"
                                "nop;"
@@ -26,13 +31,14 @@ static void __invalidate_icache(ulong addr, ulong size)
 
 void invalidate_icache_all(void)
 {
-       __invalidate_icache(0, CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE);
+       __invalidate_icache(0, gd_cpuinfo()->icache_size);
 }
 
 static void __flush_dcache(ulong addr, ulong size)
 {
        if (CONFIG_IS_ENABLED(XILINX_MICROBLAZE0_USE_WDC)) {
-               for (int i = 0; i < size; i += 4) {
+               for (int i = 0; i < size;
+                    i += gd_cpuinfo()->dcache_line_length) {
                        asm volatile (
                                "wdc.flush      %0, r0;"
                                "nop;"
@@ -45,7 +51,7 @@ static void __flush_dcache(ulong addr, ulong size)
 
 void flush_dcache_all(void)
 {
-       __flush_dcache(0, CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE);
+       __flush_dcache(0, gd_cpuinfo()->dcache_size);
 }
 
 int dcache_status(void)
arch/microblaze/cpu/cpuinfo.c new file +20 -0
new file mode 100644
index 0000000000..3f0b1d2c04
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2022, Ovidiu Panait <[email protected]>
+ */
+#include <common.h>
+#include <asm/cpuinfo.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+void microblaze_early_cpuinfo_init(void)
+{
+       struct microblaze_cpuinfo *ci = gd_cpuinfo();
+
+       ci->icache_size = CONFIG_XILINX_MICROBLAZE0_ICACHE_SIZE;
+       ci->icache_line_length = 4;
+
+       ci->dcache_size = CONFIG_XILINX_MICROBLAZE0_DCACHE_SIZE;
+       ci->dcache_line_length = 4;
+}
arch/microblaze/cpu/start.S +7 -0
index 7f7b5f5cb5..ad400a4be5 100644
@@ -51,6 +51,13 @@ _start:
        nop
 #endif
 
+       /*
+        * Initialize global data cpuinfo with default values (cache
+        * size, cache line size, etc).
+        */
+       bralid  r15, microblaze_early_cpuinfo_init
+       nop
+
        /* Flush cache before enable cache */
        bralid  r15, flush_cache_all
        nop
arch/microblaze/include/asm/cpuinfo.h new file +12 -0
new file mode 100644
index 0000000000..c27dd40af7
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2022, Ovidiu Panait <[email protected]>
+ */
+
+#ifndef __ASM_MICROBLAZE_CPUINFO_H
+#define __ASM_MICROBLAZE_CPUINFO_H
+
+/**
+ * struct microblaze_cpuinfo - CPU info for microblaze processor core.
+ *
+ * @icache_size: Size of instruction cache memory in bytes.

arch/microblaze/include/asm/cpuinfo.h line 22

Quoted 10 lines
arch/microblaze/include/asm/cpuinfo.h new file +10 -0
+ * @icache_line_length: Instruction cache line length in bytes.
+ * @dcache_size: Size of data cache memory in bytes.
+ * @dcache_line_length: Data cache line length in bytes.
+ */
+struct microblaze_cpuinfo {
+       u32 icache_size;
+       u32 icache_line_length;
+
+       u32 dcache_size;
+       u32 dcache_line_length;

Feel free to create a separate patch on the top of this series which introduces arch_print_bdinfo() to also print it out or use your cpu driver to have a way to get information about caches.

Thanks,
Michal

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs
#11 lore raw

PATCH v2 11/14 microblaze: cache: introduce flush_dcache_range()

In reply to Ovidiu Panait

Align microblaze with the other architectures and provide an implementation for flush_dcache_range(). Also, remove the microblaze exception in drivers/core/device.c.

---

Changes in v2:
- Added debug message for invalid range.

 arch/microblaze/cpu/cache.c | 11 +++++++++++
 drivers/core/device.c       |  5 -----
 2 files changed, 11 insertions(+), 5 deletions(-)
arch/microblaze/cpu/cache.c +11 -0
index cd8507901d..829e6c7ae6 100644
@@ -49,6 +49,17 @@ static void __flush_dcache(ulong addr, ulong size)
 	}
 }
 
+void flush_dcache_range(unsigned long start, unsigned long end)
+{
+	if (start >= end) {
+		debug("Invalid dcache range - start: 0x%08lx end: 0x%08lx\n",
+		      start, end);
+		return;
+	}
+
+	__flush_dcache(start, end - start);
+}
+
 void flush_dcache_all(void)
 {
 	__flush_dcache(0, gd_cpuinfo()->dcache_size);
drivers/core/device.c +0 -5
index 3ab2583df3..03155e9867 100644
@@ -328,13 +328,8 @@ static void *alloc_priv(int size, uint flags)
 			 * within this range at the start. The driver can then
 			 * use normal flush-after-write, invalidate-before-read
 			 * procedures.
-			 *
-			 * TODO([email protected]): Drop this microblaze
-			 * exception.
 			 */
-#ifndef CONFIG_MICROBLAZE
 			flush_dcache_range((ulong)priv, (ulong)priv + size);
-#endif
 		}
 	} else {
 		priv = calloc(1, size);
Signature · 1 line
2.25.1
#12 lore raw

PATCH v2 12/14 microblaze: Kconfig: introduce XILINX_MICROBLAZE0_FPGA_FAMILY option

In reply to Ovidiu Panait

Provide a static Kconfig value for the target FPGA archtitecture, as it is done in Linux. The cpu-uclass driver will cross-check it with the value read from PVR10 register.

---

Changes in v2:
- New patch.

 board/xilinx/microblaze-generic/Kconfig | 8 ++++++++
 1 file changed, 8 insertions(+)
board/xilinx/microblaze-generic/Kconfig +8 -0
index a6743cadf4..90f79cfb94 100644
@@ -38,6 +38,14 @@ config XILINX_MICROBLAZE0_HW_VER
 	string "Core version number"
 	default "7.10.d"
 
+config XILINX_MICROBLAZE0_FPGA_FAMILY
+	string "Targeted FPGA family"
+	default "virtex5"
+	help
+	  This option contains info about the target FPGA architecture
+	  (Zynq-7000, UltraScale+ Kintex, etc) that the MicroBlaze soft core is
+	  implemented on. It corresponds to the C_FAMILY hdl parameter.
+
 config XILINX_MICROBLAZE0_USR_EXCEP
 	bool "MicroBlaze user exception support"
 	default y
Signature · 1 line
2.25.1
#13 lore raw

PATCH v2 13/14 microblaze: add support for handling PVR data

In reply to Ovidiu Panait

Add helper code for PVR (Processor Version Register) data handling. It will be used by the UCLASS_CPU driver to populate cpuinfo fields at runtime.

---

Changes in v2:
- New patch.

 arch/microblaze/cpu/Makefile            |  1 +
 arch/microblaze/cpu/pvr.c               | 41 ++++++++++++++
 arch/microblaze/include/asm/pvr.h       | 75 +++++++++++++++++++++++++
 board/xilinx/microblaze-generic/Kconfig |  8 +++
 4 files changed, 125 insertions(+)
 create mode 100644 arch/microblaze/cpu/pvr.c
 create mode 100644 arch/microblaze/include/asm/pvr.h
arch/microblaze/cpu/Makefile +1 -0
index 5388a21550..96eb40f6f2 100644
@@ -6,4 +6,5 @@
 extra-y	= start.o
 obj-y	= irq.o
 obj-y	+= interrupts.o cache.o exception.o timer.o cpuinfo.o
+obj-$(CONFIG_XILINX_MICROBLAZE0_PVR) += pvr.o
 obj-$(CONFIG_SPL_BUILD)	+= spl.o
arch/microblaze/cpu/pvr.c new file +41 -0

41 lines not on this page · raw message

arch/microblaze/include/asm/pvr.h new file +75 -0

75 lines not on this page · raw message

board/xilinx/microblaze-generic/Kconfig +8 -0
index 90f79cfb94..dd5eacef52 100644
@@ -109,4 +109,12 @@ config XILINX_MICROBLAZE0_ICACHE_SIZE
 	  the device tree, or when the instruction cache is flushed very early
 	  in the boot process, before device tree is available.
 
+config XILINX_MICROBLAZE0_PVR
+	bool "MicroBlaze PVR support"
+	help
+	  Enables helper functions and macros needed to manipulate PVR
+	  (Processor Version Register) data. Currently, only the microblaze
+	  UCLASS_CPU driver makes use of this feature to retrieve CPU info at
+	  runtime.
+
 endif
Signature · 1 line
2.25.1
#14 lore raw

PATCH v2 14/14 cpu: add CPU driver for microblaze

In reply to Ovidiu Panait

Add a basic CPU driver that retrieves information about the microblaze CPU core. cpu_ops handlers are implemented so that the "cpu" command can work properly:

U-Boot-mONStR> cpu list
0: cpu@0 MicroBlaze @ 50MHz, Rev: 11.0, FPGA family: zynq7000
U-Boot-mONStR> cpu detail
0: cpu@0 MicroBlaze @ 50MHz, Rev: 11.0, FPGA family: zynq7000
ID = 0, freq = 50 MHz: L1 cache, MMU

Note: cpu_ver_lookup[] and family_string_lookup[] arrays were imported from linux.

---

Changes in v2:
- Refactored completely.
- Fixed v9.X version codes.
- Added support for cross-checking PVR and static data.
- Added support for "cpu" command.

 arch/microblaze/cpu/cpuinfo.c         | 111 ++++++++++++++++
 arch/microblaze/include/asm/cpuinfo.h |  79 +++++++++++
 drivers/cpu/Kconfig                   |   9 ++
 drivers/cpu/Makefile                  |   1 +
 drivers/cpu/microblaze_cpu.c          | 180 ++++++++++++++++++++++++++
 5 files changed, 380 insertions(+)
 create mode 100644 drivers/cpu/microblaze_cpu.c
arch/microblaze/cpu/cpuinfo.c +111 -0
index 3f0b1d2c04..f021f4e5e2 100644
@@ -8,6 +8,117 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#if CONFIG_IS_ENABLED(CPU_MICROBLAZE)
+/* These key value are as per MBV field in PVR0 */
+static const struct microblaze_version_map cpu_ver_lookup[] = {
+	{"5.00.a", 0x01},
+	{"5.00.b", 0x02},
+	{"5.00.c", 0x03},
+	{"6.00.a", 0x04},
+	{"6.00.b", 0x06},
+	{"7.00.a", 0x05},
+	{"7.00.b", 0x07},
+	{"7.10.a", 0x08},
+	{"7.10.b", 0x09},
+	{"7.10.c", 0x0a},
+	{"7.10.d", 0x0b},
+	{"7.20.a", 0x0c},
+	{"7.20.b", 0x0d},
+	{"7.20.c", 0x0e},
+	{"7.20.d", 0x0f},
+	{"7.30.a", 0x10},
+	{"7.30.b", 0x11},
+	{"8.00.a", 0x12},
+	{"8.00.b", 0x13},
+	{"8.10.a", 0x14},
+	{"8.20.a", 0x15},
+	{"8.20.b", 0x16},
+	{"8.30.a", 0x17},
+	{"8.40.a", 0x18},
+	{"8.40.b", 0x19},
+	{"8.50.a", 0x1a},
+	{"8.50.b", 0x1c},
+	{"8.50.c", 0x1e},
+	{"9.0", 0x1b},
+	{"9.1", 0x1d},
+	{"9.2", 0x1f},
+	{"9.3", 0x20},
+	{"9.4", 0x21},
+	{"9.5", 0x22},
+	{"9.6", 0x23},
+	{"10.0", 0x24},
+	{"11.0", 0x25},
+	{NULL, 0},
+};
+
+static const struct microblaze_version_map family_string_lookup[] = {
+	{"virtex2", 0x4},
+	{"virtex2pro", 0x5},
+	{"spartan3", 0x6},
+	{"virtex4", 0x7},
+	{"virtex5", 0x8},
+	{"spartan3e", 0x9},
+	{"spartan3a", 0xa},
+	{"spartan3an", 0xb},
+	{"spartan3adsp", 0xc},
+	{"spartan6", 0xd},
+	{"virtex6", 0xe},
+	{"virtex7", 0xf},
+	/* FIXME There is no key code defined for spartan2 */
+	{"spartan2", 0xf0},
+	{"kintex7", 0x10},
+	{"artix7", 0x11},
+	{"zynq7000", 0x12},
+	{"UltraScale Virtex", 0x13},
+	{"UltraScale Kintex", 0x14},
+	{"UltraScale+ Zynq", 0x15},
+	{"UltraScale+ Virtex", 0x16},
+	{"UltraScale+ Kintex", 0x17},
+	{"Spartan7", 0x18},
+	{NULL, 0},
+};
+
+static const char *lookup_string(u32 code,
+				 const struct microblaze_version_map *entry)
+{
+	for (; entry->string; ++entry)
+		if (entry->code == code)
+			return entry->string;
+
+	return "(unknown)";
+}
+
+static const u32 lookup_code(const char *string,
+			     const struct microblaze_version_map *entry)
+{
+	for (; entry->string; ++entry)
+		if (!strcmp(entry->string, string))
+			return entry->code;
+
+	return 0;
+}
+
+const char *microblaze_lookup_fpga_family_string(const u32 code)
+{
+	return lookup_string(code, family_string_lookup);
+}
+
+const char *microblaze_lookup_cpu_version_string(const u32 code)
+{
+	return lookup_string(code, cpu_ver_lookup);
+}
+
+const u32 microblaze_lookup_fpga_family_code(const char *string)
+{
+	return lookup_code(string, family_string_lookup);
+}
+
+const u32 microblaze_lookup_cpu_version_code(const char *string)
+{
+	return lookup_code(string, cpu_ver_lookup);
+}
+#endif /* CONFIG_CPU_MICROBLAZE */
+
 void microblaze_early_cpuinfo_init(void)
 {
 	struct microblaze_cpuinfo *ci = gd_cpuinfo();
arch/microblaze/include/asm/cpuinfo.h +79 -0

93 lines not on this page · raw message

drivers/cpu/Kconfig +9 -0
index 789728167c..21874335c8 100644
@@ -19,3 +19,12 @@ config CPU_RISCV
 	depends on CPU && RISCV
 	help
 	  Support CPU cores for RISC-V architecture.
+
+config CPU_MICROBLAZE
+	bool "Enable Microblaze CPU driver"
+	depends on CPU && MICROBLAZE
+	select EVENT
+	select DM_EVENT
+	select XILINX_MICROBLAZE0_PVR
+	help
+	  Support CPU cores for Microblaze architecture.
drivers/cpu/Makefile +1 -0
index c8532637ca..20884b1795 100644
@@ -11,4 +11,5 @@ obj-$(CONFIG_ARCH_IMX8) += imx8_cpu.o
 obj-$(CONFIG_ARCH_AT91) += at91_cpu.o
 obj-$(CONFIG_CPU_MPC83XX) += mpc83xx_cpu.o
 obj-$(CONFIG_CPU_RISCV) += riscv_cpu.o
+obj-$(CONFIG_CPU_MICROBLAZE) += microblaze_cpu.o
 obj-$(CONFIG_SANDBOX) += cpu_sandbox.o
drivers/cpu/microblaze_cpu.c new file +180 -0

180 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#15 lore raw
In reply to Ovidiu Panait

út 31. 5. 2022 v 20:14 odesílatel Ovidiu Panait <[email protected]> napsal:

Quoted 66 lines

Migrate cpu command to use U_BOOT_CMD_WITH_SUBCMDS() helper macro, to reduce duplicated code. This also fixes the cpu command on boards that enable CONFIG_NEEDS_MANUAL_RELOC.

---
NOTE: this series depends on the following "events" patch:
https://lore.kernel.org/u-boot/[email protected]/

Changes in v2:
- New patch.

 cmd/cpu.c | 39 ++++++++-------------------------------
 1 file changed, 8 insertions(+), 31 deletions(-)
cmd/cpu.c +8 -32
index 67dbb044b5..2ca4d05ae8 100644
@@ -82,36 +82,13 @@ static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
        return 0;
 }
 
-static struct cmd_tbl cmd_cpu_sub[] = {
-       U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
-       U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
-};
-
-/*
- * Process a cpu sub-command
- */
-static int do_cpu(struct cmd_tbl *cmdtp, int flag, int argc,
-                 char *const argv[])
-{
-       struct cmd_tbl *c = NULL;
-
-       /* Strip off leading 'cpu' command argument */
-       argc--;
-       argv++;
-
-       if (argc)
-               c = find_cmd_tbl(argv[0], cmd_cpu_sub,
-                                ARRAY_SIZE(cmd_cpu_sub));
-
-       if (c)
-               return c->cmd(cmdtp, flag, argc, argv);
-       else
-               return CMD_RET_USAGE;
-}
-
-U_BOOT_CMD(
-       cpu, 2, 1, do_cpu,
-       "display information about CPUs",
+#if CONFIG_IS_ENABLED(SYS_LONGHELP)
+static char cpu_help_text[] =
        "list   - list available CPUs\n"
        "cpu detail     - show CPU detail"
-);
+       ;
+#endif
+
+U_BOOT_CMD_WITH_SUBCMDS(cpu, "display information about CPUs", cpu_help_text,
+       U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cpu_list),
+       U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail));
--
Quoted 2 lines

2.25.1

From my point of view this series looks good. I have sent v2 of mb conversion rela and I prefer to apply this on the top. There is actually one change needed bralid/brlid in one patch but I have already did it and test it on the HW.
Will queue for the next u-boot version.

Thanks,
Michal

Signature · 5 lines
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze
Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs
U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs
#16 lore raw

Hi Michal,

Quoted 12 lines · Michal Simek

[Please note: This e-mail is from an EXTERNAL e-mail address]

út 31. 5. 2022 v 20:14 odesílatel Ovidiu Panait <[email protected]> napsal:

Migrate cpu command to use U_BOOT_CMD_WITH_SUBCMDS() helper macro, to reduce duplicated code. This also fixes the cpu command on boards that enable CONFIG_NEEDS_MANUAL_RELOC.

---
NOTE: this series depends on the following "events" patch:
https://lore.kernel.org/u-boot/[email protected]/

[...]

Quoted 5 lines
Quoted 5 lines

From my point of view this series looks good. I have sent v2 of mb
conversion rela and I prefer to apply this on the top. There is actually one change needed bralid/brlid in one patch but I have already did it and test it on the HW.
Will queue for the next u-boot version.

Thanks for the feedback! Could you also take in the following event patch that fixes the pointers after relocation (the cpu driver makes use of the events feature)? Without this, in my testing the event handlers are not called at all after relocation:

https://lore.kernel.org/u-boot/[email protected]/

It seems it is not currently applied to the 20220607-cache branch of u-boot-microblaze repo.

Thanks!

Ovidiu

Quoted 9 lines
Quoted 9 lines

Thanks,
Michal

--
Michal Simek, Ing. (M.Eng), OpenPGP -> KeyID: FE3D1F91
w: www.monstr.eu p: +42-0-721842854
Maintainer of Linux kernel - Xilinx Microblaze Maintainer of Linux kernel - Xilinx Zynq ARM and ZynqMP ARM64 SoCs U-Boot custodian - Xilinx Microblaze/Zynq/ZynqMP/Versal SoCs