[PATCH v5 10/18] hw/hexagon/virt: instantiate virtio-mmio transports

Brian Cain <[email protected]>
Newsgroups gmane.comp.emulators.qemu
Message-ID <[email protected]>
Add a VIRT_MMIO region and virtio-mmio transports, wired into l2vic.

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Brian Cain <[email protected]>
---
 include/hw/hexagon/virt.h |  3 +++
 hw/hexagon/virt.c         | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/include/hw/hexagon/virt.h b/include/hw/hexagon/virt.h
index cf0cd2f8f22..4ca2f1ef859 100644
--- a/include/hw/hexagon/virt.h
+++ b/include/hw/hexagon/virt.h
@@ -11,6 +11,8 @@
 #include "hw/hexagon/hexagon.h"
 #include "target/hexagon/cpu.h"
 
+#define VIRTIO_DEV_COUNT 8
+
 struct HexagonVirtMachineState {
     HexagonCommonMachineState parent_obj;
 
@@ -19,6 +21,7 @@ struct HexagonVirtMachineState {
     MemoryRegion tcm;
     MemoryRegion bios;
     Clock *apb_clk;
+    DeviceState *virtio_mmio[VIRTIO_DEV_COUNT];
 };
 
 void hexagon_load_fdt(const struct HexagonVirtMachineState *vms);
diff --git a/hw/hexagon/virt.c b/hw/hexagon/virt.c
index 9a680852c3c..ff0770cfc46 100644
--- a/hw/hexagon/virt.c
+++ b/hw/hexagon/virt.c
@@ -30,11 +30,19 @@
 
 enum {
     VIRT_UART0,
+    VIRT_MMIO,
     VIRT_FDT,
 };
 
+/*
+ * Virtio IRQs run from VIRTIO_IRQ_BASE to
+ * VIRTIO_IRQ_BASE + VIRTIO_DEV_COUNT - 1
+ */
+static const int VIRTIO_IRQ_BASE = 16;
+
 static const MemMapEntry base_memmap[] = {
     [VIRT_UART0] = { 0x10000000, 0x00000200 },
+    [VIRT_MMIO] = { 0x11000000, 0x00001000 },
     [VIRT_FDT] = { 0x99800000, 0x00400000 },
 };
 
@@ -167,7 +175,25 @@ static void fdt_add_cpu_nodes(const HexagonVirtMachineState *vms)
     }
 }
 
+static void create_virtio_devices(HexagonVirtMachineState *vms)
+{
+    hwaddr size = base_memmap[VIRT_MMIO].size;
 
+    for (int i = 0; i < VIRTIO_DEV_COUNT; i++) {
+        int irq = VIRTIO_IRQ_BASE + i;
+        hwaddr base = base_memmap[VIRT_MMIO].base + i * size;
+        DeviceState *dev = qdev_new("virtio-mmio");
+        SysBusDevice *s = SYS_BUS_DEVICE(dev);
+
+        object_property_add_child(OBJECT(MACHINE(vms)), "virtio-mmio[*]",
+                                  OBJECT(dev));
+        sysbus_realize_and_unref(s, &error_fatal);
+        sysbus_mmio_map(s, 0, base);
+        sysbus_connect_irq(s, 0,
+                           qdev_get_gpio_in(vms->parent_obj.l2vic, irq));
+        vms->virtio_mmio[i] = dev;
+    }
+}
 
 void hexagon_load_fdt(const HexagonVirtMachineState *vms)
 {
@@ -246,6 +272,8 @@ static void virt_init(MachineState *ms)
 
     fdt_add_hvx(vms, m_cfg);
 
+    create_virtio_devices(vms);
+
     g_autofree HexagonCPU **cpus = g_new(HexagonCPU *, ms->smp.cpus);
 
     for (int i = 0; i < ms->smp.cpus; i++) {
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.