From: Eric Auger <eric.auger@redhat.com>
To: eric.auger.pro@gmail.com, eric.auger@redhat.com,
peter.maydell@linaro.org, alex.williamson@redhat.com,
mst@redhat.com, qemu-arm@nongnu.org, qemu-devel@nongnu.org,
jean-philippe.brucker@arm.com
Cc: will.deacon@arm.com, kevin.tian@intel.com, marc.zyngier@arm.com,
christoffer.dall@linaro.org, drjones@redhat.com, wei@redhat.com,
tn@semihalf.com, bharat.bhushan@nxp.com, peterx@redhat.com,
linuc.decode@gmail.com
Subject: [Qemu-devel] [RFC v6 17/22] hw/arm/virt: Add virtio-iommu to the virt board
Date: Mon, 12 Feb 2018 18:58:19 +0000 [thread overview]
Message-ID: <1518461904-5305-18-git-send-email-eric.auger@redhat.com> (raw)
In-Reply-To: <1518461904-5305-1-git-send-email-eric.auger@redhat.com>
The specific virtio-mmio node is inconditionally added on
machine init while the binding between this latter and the
PCIe host bridge is done on machine init done notifier, only
if -device virtio-iommu-device was added to the qemu command
line.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v4 -> v5:
- VirtMachineClass no_iommu added in this patch
- Use object_resolve_path_type
---
hw/arm/virt.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++----
include/hw/arm/virt.h | 5 ++++
2 files changed, 82 insertions(+), 6 deletions(-)
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 08ac411..cf81716 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -54,6 +54,7 @@
#include "hw/arm/fdt.h"
#include "hw/intc/arm_gic.h"
#include "hw/intc/arm_gicv3_common.h"
+#include "hw/virtio/virtio-iommu.h"
#include "kvm_arm.h"
#include "hw/smbios/smbios.h"
#include "qapi/visitor.h"
@@ -141,6 +142,7 @@ static const MemMapEntry a15memmap[] = {
[VIRT_FW_CFG] = { 0x09020000, 0x00000018 },
[VIRT_GPIO] = { 0x09030000, 0x00001000 },
[VIRT_SECURE_UART] = { 0x09040000, 0x00001000 },
+ [VIRT_IOMMU] = { 0x09050000, 0x00000200 },
[VIRT_MMIO] = { 0x0a000000, 0x00000200 },
/* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */
[VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 },
@@ -161,6 +163,7 @@ static const int a15irqmap[] = {
[VIRT_SECURE_UART] = 8,
[VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */
[VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */
+ [VIRT_IOMMU] = 74,
[VIRT_PLATFORM_BUS] = 112, /* ...to 112 + PLATFORM_BUS_NUM_IRQS -1 */
};
@@ -941,6 +944,69 @@ static void create_pcie_irq_map(const VirtMachineState *vms,
0x7 /* PCI irq */);
}
+static void virtio_iommu_notifier(Notifier *notifier, void *data)
+{
+ VirtMachineState *vms = container_of(notifier, VirtMachineState,
+ virtio_iommu_done);
+ VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
+ struct arm_boot_info *info = &vms->bootinfo;
+ bool ambiguous;
+ Object *obj = object_resolve_path_type("", TYPE_VIRTIO_IOMMU, &ambiguous);
+ int dtb_size;
+ void *fdt = info->get_dtb(info, &dtb_size);
+
+ if (!obj) {
+ return;
+ }
+
+ if (vmc->no_iommu) {
+ error_setg(&error_fatal, "this machine version does not support iommu");
+ }
+
+ if (ambiguous) {
+ error_setg(&error_fatal, "a single virtio-iommu device is supported!");
+ }
+
+ object_property_set_bool(obj, false, "msi_bypass", &error_fatal);
+
+ qemu_fdt_setprop_cells(fdt, vms->pcie_host_nodename, "iommu-map",
+ 0x0, vms->iommu_phandle, 0x0, 0x10000);
+}
+
+static void create_virtio_iommu(VirtMachineState *vms, qemu_irq *pic)
+{
+ char *node;
+ const char compat[] = "virtio,mmio";
+ int irq = vms->irqmap[VIRT_IOMMU];
+ hwaddr base = vms->memmap[VIRT_IOMMU].base;
+ hwaddr size = vms->memmap[VIRT_IOMMU].size;
+ VirtMachineClass *vmc = VIRT_MACHINE_GET_CLASS(vms);
+
+ if (vmc->no_iommu) {
+ return;
+ }
+
+ vms->iommu_phandle = qemu_fdt_alloc_phandle(vms->fdt);
+
+ sysbus_create_simple("virtio-mmio", base, pic[irq]);
+
+ node = g_strdup_printf("/virtio_mmio@%" PRIx64, base);
+ 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", 2, base, 2, size);
+
+ qemu_fdt_setprop_cells(vms->fdt, node, "interrupts",
+ GIC_FDT_IRQ_TYPE_SPI, irq, GIC_FDT_IRQ_FLAGS_EDGE_LO_HI);
+
+ qemu_fdt_setprop(vms->fdt, node, "dma-coherent", NULL, 0);
+ qemu_fdt_setprop_cell(vms->fdt, node, "#iommu-cells", 1);
+ qemu_fdt_setprop_cell(vms->fdt, node, "phandle", vms->iommu_phandle);
+ g_free(node);
+
+ vms->virtio_iommu_done.notify = virtio_iommu_notifier;
+ qemu_add_machine_init_done_notifier(&vms->virtio_iommu_done);
+}
+
static void create_pcie(VirtMachineState *vms, qemu_irq *pic)
{
hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO].base;
@@ -1016,7 +1082,8 @@ static void create_pcie(VirtMachineState *vms, qemu_irq *pic)
}
}
- nodename = g_strdup_printf("/pcie@%" PRIx64, base);
+ vms->pcie_host_nodename = g_strdup_printf("/pcie@%" PRIx64, base);
+ nodename = vms->pcie_host_nodename;
qemu_fdt_add_subnode(vms->fdt, nodename);
qemu_fdt_setprop_string(vms->fdt, nodename,
"compatible", "pci-host-ecam-generic");
@@ -1055,7 +1122,6 @@ static void create_pcie(VirtMachineState *vms, qemu_irq *pic)
qemu_fdt_setprop_cell(vms->fdt, nodename, "#interrupt-cells", 1);
create_pcie_irq_map(vms, vms->gic_phandle, irq, nodename);
- g_free(nodename);
}
static void create_platform_bus(VirtMachineState *vms, qemu_irq *pic)
@@ -1370,16 +1436,16 @@ static void machvirt_init(MachineState *machine)
create_rtc(vms, pic);
- create_pcie(vms, pic);
-
- create_gpio(vms, pic);
-
/* Create mmio transports, so the user can create virtio backends
* (which will be automatically plugged in to the transports). If
* no backend is created the transport will just sit harmlessly idle.
*/
create_virtio_devices(vms, pic);
+ create_pcie(vms, pic);
+
+ create_gpio(vms, pic);
+
vms->fw_cfg = create_fw_cfg(vms, &address_space_memory);
rom_set_fw(vms->fw_cfg);
@@ -1404,6 +1470,7 @@ static void machvirt_init(MachineState *machine)
* Notifiers are executed in registration reverse order.
*/
create_platform_bus(vms, pic);
+ create_virtio_iommu(vms, pic);
}
static bool virt_get_secure(Object *obj, Error **errp)
@@ -1645,8 +1712,12 @@ static void virt_2_11_instance_init(Object *obj)
static void virt_machine_2_11_options(MachineClass *mc)
{
+ VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc));
+
virt_machine_2_12_options(mc);
SET_MACHINE_COMPAT(mc, VIRT_COMPAT_2_11);
+
+ vmc->no_iommu = true;
}
DEFINE_VIRT_MACHINE(2, 11)
diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h
index 7e31e99..a13b895 100644
--- a/include/hw/arm/virt.h
+++ b/include/hw/arm/virt.h
@@ -59,6 +59,7 @@ enum {
VIRT_GIC_V2M,
VIRT_GIC_ITS,
VIRT_GIC_REDIST,
+ VIRT_IOMMU,
VIRT_UART,
VIRT_MMIO,
VIRT_RTC,
@@ -84,12 +85,14 @@ typedef struct {
bool disallow_affinity_adjustment;
bool no_its;
bool no_pmu;
+ bool no_iommu;
bool claim_edge_triggered_timers;
} VirtMachineClass;
typedef struct {
MachineState parent;
Notifier machine_done;
+ Notifier virtio_iommu_done;
FWCfgState *fw_cfg;
bool secure;
bool highmem;
@@ -105,6 +108,8 @@ typedef struct {
uint32_t clock_phandle;
uint32_t gic_phandle;
uint32_t msi_phandle;
+ uint32_t iommu_phandle;
+ char *pcie_host_nodename;
int psci_conduit;
PCIBus *pci_bus;
} VirtMachineState;
--
1.9.1
next prev parent reply other threads:[~2018-02-12 19:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-12 18:58 [Qemu-devel] [RFC v6 00/22] VIRTIO-IOMMU device Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 01/22] machine: Add a get_primary_pci_bus callback Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 02/22] hw/arm/virt: Implement get_primary_pci_bus Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 03/22] pc: " Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 04/22] update-linux-headers: Import virtio_iommu.h Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 05/22] linux-headers: Partial update for virtio-iommu v0.6 Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 06/22] virtio-iommu: Add skeleton Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 07/22] virtio-iommu: Decode the command payload Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 08/22] virtio-iommu: Add the iommu regions Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 09/22] virtio-iommu: Register attached endpoints Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 10/22] virtio-iommu: Implement attach/detach command Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 11/22] virtio-iommu: Implement map/unmap Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 12/22] virtio-iommu: Implement translate Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 13/22] virtio-iommu: Implement probe request Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 14/22] virtio-iommu: Add an msi_bypass property Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 15/22] virtio-iommu: Implement fault reporting Eric Auger
2018-03-21 13:15 ` Jean-Philippe Brucker
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 16/22] virtio_iommu: Handle reserved regions in translation process Eric Auger
2018-02-12 18:58 ` Eric Auger [this message]
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 18/22] hw/arm/virt-acpi-build: Add virtio-iommu node in IORT table Eric Auger
2018-02-13 12:24 ` Andrew Jones
2018-02-13 13:22 ` Auger Eric
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 19/22] memory.h: Add set_page_size_mask IOMMUMemoryRegion callback Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 20/22] hw/vfio/common: Set the IOMMUMemoryRegion supported page sizes Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 21/22] virtio-iommu: Implement set_page_size_mask Eric Auger
2018-02-12 18:58 ` [Qemu-devel] [RFC v6 22/22] hw/vfio/common: Do not print error when viommu translates into an mmio region Eric Auger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1518461904-5305-18-git-send-email-eric.auger@redhat.com \
--to=eric.auger@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=bharat.bhushan@nxp.com \
--cc=christoffer.dall@linaro.org \
--cc=drjones@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=jean-philippe.brucker@arm.com \
--cc=kevin.tian@intel.com \
--cc=linuc.decode@gmail.com \
--cc=marc.zyngier@arm.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=tn@semihalf.com \
--cc=wei@redhat.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).