[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [RFC v8 15/18] hw/arm/virt: Add virtio-iommu to the virt boar
From: |
Eric Auger |
Subject: |
[Qemu-arm] [RFC v8 15/18] hw/arm/virt: Add virtio-iommu to the virt board |
Date: |
Fri, 9 Nov 2018 12:29:54 +0100 |
Both the virtio-iommu device and its dedicated mmio
transport get instantiated when requested.
Signed-off-by: Eric Auger <address@hidden>
---
v6 -> v7:
- align to the smmu instantiation code
v4 -> v5:
- VirtMachineClass no_iommu added in this patch
- Use object_resolve_path_type
---
hw/arm/virt.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 3 deletions(-)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index a2b8d8f7c2..f2994c4359 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -29,6 +29,7 @@
*/
#include "qemu/osdep.h"
+#include "monitor/qdev.h"
#include "qapi/error.h"
#include "hw/sysbus.h"
#include "hw/arm/arm.h"
@@ -49,6 +50,7 @@
#include "qemu/bitops.h"
#include "qemu/error-report.h"
#include "hw/pci-host/gpex.h"
+#include "hw/virtio/virtio-pci.h"
#include "hw/arm/sysbus-fdt.h"
#include "hw/platform-bus.h"
#include "hw/arm/fdt.h"
@@ -59,6 +61,7 @@
#include "qapi/visitor.h"
#include "standard-headers/linux/input.h"
#include "hw/arm/smmuv3.h"
+#include "hw/virtio/virtio-iommu.h"
#define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
@@ -1085,6 +1088,33 @@ static void create_smmu(const VirtMachineState *vms,
qemu_irq *pic,
g_free(node);
}
+static void create_virtio_iommu(VirtMachineState *vms,
+ const char *pciehb_nodename, PCIBus *bus)
+{
+ const char compat[] = "virtio,pci-iommu";
+ uint16_t bdf = 0x8; /* 00:01.0 */
+ DeviceState *dev;
+ char *node;
+
+ dev = qdev_create(BUS(bus), TYPE_VIRTIO_IOMMU_PCI);
+ object_property_set_bool(OBJECT(dev), true, "realized", &error_fatal);
+
+ node = g_strdup_printf("%s/address@hidden", pciehb_nodename, bdf);
+ qemu_fdt_add_subnode(vms->fdt, node);
+ qemu_fdt_setprop(vms->fdt, node, "compatible", compat, sizeof(compat));
+ qemu_fdt_setprop_sized_cells(vms->fdt, node, "reg",
+ 1, bdf << 8 /* phys.hi */,
+ 1, 0 /* phys.mid */,
+ 1, 0 /* phys.lo */,
+ 1, 0 /* size.hi */,
+ 1, 0 /* size.low */);
+
+ qemu_fdt_setprop_cell(vms->fdt, node, "#iommu-cells", 1);
+ qemu_fdt_setprop_cell(vms->fdt, node, "phandle", vms->iommu_phandle);
+ g_free(node);
+}
+
+
static void create_pcie(VirtMachineState *vms, qemu_irq *pic)
{
hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO].base;
@@ -1205,10 +1235,22 @@ static void create_pcie(VirtMachineState *vms, qemu_irq
*pic)
if (vms->iommu) {
vms->iommu_phandle = qemu_fdt_alloc_phandle(vms->fdt);
- create_smmu(vms, pic, pci->bus);
+ switch (vms->iommu) {
+ case VIRT_IOMMU_SMMUV3:
+ create_smmu(vms, pic, pci->bus);
+ qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map",
+ 0x0, vms->iommu_phandle, 0x0, 0x10000);
+ break;
+ case VIRT_IOMMU_VIRTIO:
+ create_virtio_iommu(vms, nodename, pci->bus);
+ qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map",
+ 0x0, vms->iommu_phandle, 0x0, 0x8,
+ 0x9, vms->iommu_phandle, 0x9, 0xfff7);
+ break;
+ default:
+ g_assert_not_reached();
+ }
- qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map",
- 0x0, vms->iommu_phandle, 0x0, 0x10000);
}
g_free(nodename);
--
2.17.2
- [Qemu-arm] [RFC v8 08/18] virtio-iommu: Implement map/unmap, (continued)
- [Qemu-arm] [RFC v8 08/18] virtio-iommu: Implement map/unmap, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 06/18] virtio-iommu: Endpoint and domains structs and helpers, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 09/18] virtio-iommu: Implement translate, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 10/18] virtio-iommu: Implement probe request, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 11/18] virtio-iommu: Add an msi_bypass property, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 12/18] virtio-iommu: Implement fault reporting, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 13/18] virtio_iommu: Handle reserved regions in translation process, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 14/18] virtio-iommu-pci: Add virtio iommu pci support, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 15/18] hw/arm/virt: Add virtio-iommu to the virt board,
Eric Auger <=
- Re: [Qemu-arm] [RFC v8 15/18] hw/arm/virt: Add virtio-iommu to the virt board, Bharat Bhushan, 2018/11/22
- [Qemu-arm] [RFC v8 16/18] hw/arm/virt-acpi-build: Introduce fill_iort_idmap helper, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 17/18] hw/arm/virt-acpi-build: Add virtio-iommu node in IORT table, Eric Auger, 2018/11/09
- [Qemu-arm] [RFC v8 18/18] hw/arm/virt: Allow virtio-iommu instantiation, Eric Auger, 2018/11/09