[PATCH v2 19/21] ppc: qemu: Create a virtual memory mapping of the platform bus

Bin Meng bmeng.cn at gmail.com
Fri Mar 12 14:36:00 CET 2021


QEMU ppce500 target can dynamically instantiate an eTSEC device on
a platform bus if "-device eTSEC" is given to QEMU. It is presented
as a "simple-bus" in the device tree, with an additional compatible
string "qemu,platform".

Let's create a virtual memory mapping for it in misc_init_r(), in
preparation to adding eTSEC support.

Signed-off-by: Bin Meng <bmeng.cn at gmail.com>

---

Changes in v2:
- turn on CONFIG_SIMPLE_BUS_CORRECT_RANGE in qemu-ppce500_defconfig

 board/emulation/qemu-ppce500/Kconfig        |  6 ++++++
 board/emulation/qemu-ppce500/qemu-ppce500.c | 18 ++++++++++++++++++
 configs/qemu-ppce500_defconfig              |  1 +
 3 files changed, 25 insertions(+)

diff --git a/board/emulation/qemu-ppce500/Kconfig b/board/emulation/qemu-ppce500/Kconfig
index 4312d986d8..1c5aa18aa9 100644
--- a/board/emulation/qemu-ppce500/Kconfig
+++ b/board/emulation/qemu-ppce500/Kconfig
@@ -9,4 +9,10 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
 	default "qemu-ppce500"
 
+config PLATFORM_BUS_MAP_ADDR
+	hex
+	default 0xf0000000
+	help
+	  The QEMU platform bus base mapped address in the virtual memory space.
+
 endif
diff --git a/board/emulation/qemu-ppce500/qemu-ppce500.c b/board/emulation/qemu-ppce500/qemu-ppce500.c
index daa103c564..0960dd1f97 100644
--- a/board/emulation/qemu-ppce500/qemu-ppce500.c
+++ b/board/emulation/qemu-ppce500/qemu-ppce500.c
@@ -14,6 +14,8 @@
 #include <net.h>
 #include <pci.h>
 #include <time.h>
+#include <dm/simple_bus.h>
+#include <dm/uclass-internal.h>
 #include <asm/global_data.h>
 #include <asm/processor.h>
 #include <asm/mmu.h>
@@ -148,6 +150,22 @@ int misc_init_r(void)
 	 */
 	disable_tlb(find_tlb_idx((void *)CONFIG_SYS_TMPVIRT, 1));
 
+	/*
+	 * Detect the presence of the platform bus node, and
+	 * create a virtual memory mapping for it.
+	 */
+	for (ret = uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev);
+	     dev;
+	     ret = uclass_find_next_device(&dev)) {
+		if (device_is_compatible(dev, "qemu,platform")) {
+			struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
+
+			assert(!tlb_map_range(CONFIG_PLATFORM_BUS_MAP_ADDR,
+					      plat->target, plat->size,
+					      TLB_MAP_IO));
+		}
+	}
+
 	return 0;
 }
 
diff --git a/configs/qemu-ppce500_defconfig b/configs/qemu-ppce500_defconfig
index 536fe7d6e1..151834b4cf 100644
--- a/configs/qemu-ppce500_defconfig
+++ b/configs/qemu-ppce500_defconfig
@@ -28,6 +28,7 @@ CONFIG_OF_BOARD=y
 CONFIG_ENV_OVERWRITE=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_DM=y
+CONFIG_SIMPLE_BUS_CORRECT_RANGE=y
 CONFIG_BLK=y
 CONFIG_HAVE_BLOCK_DEVICE=y
 CONFIG_MPC8XXX_GPIO=y
-- 
2.25.1



More information about the U-Boot mailing list