[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 18/34] hw/riscv/virt.c: add virtio-iommu-pci hotplug support
From: |
Alistair Francis |
Subject: |
[PULL 18/34] hw/riscv/virt.c: add virtio-iommu-pci hotplug support |
Date: |
Fri, 8 Mar 2024 21:11:36 +1000 |
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
We want to add a RISC-V 'virt' libqos machine to increase our test
coverage. Some of the tests will try to plug a virtio-iommu-pci
device into the board and do some tests with it.
Enable virtio-iommu-pci in the 'virt' machine.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20240217192607.32565-5-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
---
hw/riscv/virt.c | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index b540f4d3da..54ad809b44 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -53,6 +53,7 @@
#include "hw/display/ramfb.h"
#include "hw/acpi/aml-build.h"
#include "qapi/qapi-visit-common.h"
+#include "hw/virtio/virtio-iommu.h"
/* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */
static bool virt_use_kvm_aia(RISCVVirtState *s)
@@ -971,6 +972,34 @@ static void create_fdt_fw_cfg(RISCVVirtState *s, const
MemMapEntry *memmap)
qemu_fdt_setprop(ms->fdt, nodename, "dma-coherent", NULL, 0);
}
+static void create_fdt_virtio_iommu(RISCVVirtState *s, uint16_t bdf)
+{
+ const char compat[] = "virtio,pci-iommu\0pci1af4,1057";
+ void *fdt = MACHINE(s)->fdt;
+ uint32_t iommu_phandle;
+ g_autofree char *iommu_node = NULL;
+ g_autofree char *pci_node = NULL;
+
+ pci_node = g_strdup_printf("/soc/pci@%lx",
+ (long) virt_memmap[VIRT_PCIE_ECAM].base);
+ iommu_node = g_strdup_printf("%s/virtio_iommu@%x,%x", pci_node,
+ PCI_SLOT(bdf), PCI_FUNC(bdf));
+ iommu_phandle = qemu_fdt_alloc_phandle(fdt);
+
+ qemu_fdt_add_subnode(fdt, iommu_node);
+
+ qemu_fdt_setprop(fdt, iommu_node, "compatible", compat, sizeof(compat));
+ qemu_fdt_setprop_sized_cells(fdt, iommu_node, "reg",
+ 1, bdf << 8, 1, 0, 1, 0,
+ 1, 0, 1, 0);
+ qemu_fdt_setprop_cell(fdt, iommu_node, "#iommu-cells", 1);
+ qemu_fdt_setprop_cell(fdt, iommu_node, "phandle", iommu_phandle);
+
+ qemu_fdt_setprop_cells(fdt, pci_node, "iommu-map",
+ 0, iommu_phandle, 0, bdf,
+ bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf);
+}
+
static void finalize_fdt(RISCVVirtState *s)
{
uint32_t phandle = 1, irq_mmio_phandle = 1, msi_pcie_phandle = 1;
@@ -1680,7 +1709,8 @@ static HotplugHandler
*virt_machine_get_hotplug_handler(MachineState *machine,
{
MachineClass *mc = MACHINE_GET_CLASS(machine);
- if (device_is_dynamic_sysbus(mc, dev)) {
+ if (device_is_dynamic_sysbus(mc, dev) ||
+ object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
return HOTPLUG_HANDLER(machine);
}
return NULL;
@@ -1699,6 +1729,10 @@ static void virt_machine_device_plug_cb(HotplugHandler
*hotplug_dev,
SYS_BUS_DEVICE(dev));
}
}
+
+ if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
+ create_fdt_virtio_iommu(s, pci_get_bdf(PCI_DEVICE(dev)));
+ }
}
static void virt_machine_class_init(ObjectClass *oc, void *data)
--
2.44.0
- Re: [PULL 09/34] target/riscv: add remaining named features, (continued)
[PULL 10/34] target/riscv: Reset henvcfg to zero, Alistair Francis, 2024/03/08
[PULL 11/34] target/riscv: Gate hardware A/D PTE bit updating, Alistair Francis, 2024/03/08
[PULL 12/34] target/riscv: Promote svade to a normal extension, Alistair Francis, 2024/03/08
[PULL 13/34] target/riscv: FIX xATP_MODE validation, Alistair Francis, 2024/03/08
[PULL 14/34] target/riscv: UPDATE xATP write CSR, Alistair Francis, 2024/03/08
[PULL 15/34] target/riscv: Add missing include guard in pmu.h, Alistair Francis, 2024/03/08
[PULL 17/34] hw/riscv/virt.c: create '/soc/pci@...' fdt node earlier, Alistair Francis, 2024/03/08
[PULL 16/34] hw/riscv/virt-acpi-build.c: Add SRAT and SLIT ACPI tables, Alistair Francis, 2024/03/08
[PULL 18/34] hw/riscv/virt.c: add virtio-iommu-pci hotplug support,
Alistair Francis <=
[PULL 19/34] hw/riscv/virt.c: make aclint compatible with 'qtest' accel, Alistair Francis, 2024/03/08
[PULL 20/34] tests/libqos: add riscv/virt machine nodes, Alistair Francis, 2024/03/08
[PULL 21/34] RISC-V: Add support for Ztso, Alistair Francis, 2024/03/08
[PULL 22/34] linux-user/riscv: Add Ztso extension to hwprobe, Alistair Francis, 2024/03/08
[PULL 23/34] tests: riscv64: Use 'zfa' instead of 'Zfa', Alistair Francis, 2024/03/08