From nobody Wed Nov 5 08:12:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153358734247010.929501361262965; Mon, 6 Aug 2018 13:29:02 -0700 (PDT) Received: from localhost ([::1]:36174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmm7X-00010Q-UV for importer@patchew.org; Mon, 06 Aug 2018 16:28:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmlun-0006fg-72 for qemu-devel@nongnu.org; Mon, 06 Aug 2018 16:15:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmlum-00075p-09 for qemu-devel@nongnu.org; Mon, 06 Aug 2018 16:15:41 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40576 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fmluj-00073n-8D; Mon, 06 Aug 2018 16:15:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6EB840214E2; Mon, 6 Aug 2018 20:15:36 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 584422156711; Mon, 6 Aug 2018 20:15:34 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, peter.maydell@linaro.org, alex.williamson@redhat.com, mst@redhat.com, jean-philippe.brucker@arm.com Date: Mon, 6 Aug 2018 22:14:42 +0200 Message-Id: <1533586484-5737-15-git-send-email-eric.auger@redhat.com> In-Reply-To: <1533586484-5737-1-git-send-email-eric.auger@redhat.com> References: <1533586484-5737-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 06 Aug 2018 20:15:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 06 Aug 2018 20:15:36 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eric.auger@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [RFC v7 14/16] hw/arm/virt: Add virtio-iommu to the virt board X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wei@redhat.com, kevin.tian@intel.com, tn@semihalf.com, will.deacon@arm.com, drjones@redhat.com, peterx@redhat.com, linuc.decode@gmail.com, bharat.bhushan@nxp.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Both the virtio-iommu device and its dedicated mmio transport get instantiated when requested. Signed-off-by: Eric Auger --- 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 | 51 +++++++++++++++++++++++++++++++++++++++++++++++= +++- include/hw/arm/virt.h | 1 + 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 281ddcd..dd3cc71 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -29,6 +29,7 @@ */ =20 #include "qemu/osdep.h" +#include "monitor/qdev.h" #include "qapi/error.h" #include "hw/sysbus.h" #include "hw/arm/arm.h" @@ -59,6 +60,7 @@ #include "qapi/visitor.h" #include "standard-headers/linux/input.h" #include "hw/arm/smmuv3.h" +#include "hw/virtio/virtio-iommu.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -141,6 +143,7 @@ static const MemMapEntry a15memmap[] =3D { [VIRT_GPIO] =3D { 0x09030000, 0x00001000 }, [VIRT_SECURE_UART] =3D { 0x09040000, 0x00001000 }, [VIRT_SMMU] =3D { 0x09050000, 0x00020000 }, + [VIRT_VIRTIO_IOMMU] =3D { 0x09070000, 0x00000200 }, [VIRT_MMIO] =3D { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that siz= e */ [VIRT_PLATFORM_BUS] =3D { 0x0c000000, 0x02000000 }, @@ -165,6 +168,7 @@ static const int a15irqmap[] =3D { [VIRT_MMIO] =3D 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] =3D 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ [VIRT_SMMU] =3D 74, /* ...to 74 + NUM_SMMU_IRQS - 1 */ + [VIRT_VIRTIO_IOMMU] =3D 75, [VIRT_PLATFORM_BUS] =3D 112, /* ...to 112 + PLATFORM_BUS_NUM_IRQS -1 */ }; =20 @@ -1047,6 +1051,42 @@ static void create_smmu(const VirtMachineState *vms,= qemu_irq *pic, g_free(node); } =20 +static void create_virtio_iommu(VirtMachineState *vms, qemu_irq *pic, + PCIBus *bus) +{ + const char compat[] =3D "virtio,mmio"; + int irq =3D vms->irqmap[VIRT_VIRTIO_IOMMU]; + hwaddr base =3D vms->memmap[VIRT_VIRTIO_IOMMU].base; + hwaddr size =3D vms->memmap[VIRT_VIRTIO_IOMMU].size; + DeviceState *dev; + BusState *virtio_bus; + char *node; + + sysbus_create_simple("virtio-mmio", base, pic[irq]); + + virtio_bus =3D qbus_find_recursive(sysbus_get_default(), NULL, "virtio= -bus"); + dev =3D DEVICE(object_new("virtio-iommu-device")); + qdev_set_parent_bus(dev, virtio_bus); + object_property_set_link(OBJECT(dev), OBJECT(bus), "primary-bus", + &error_abort); + object_property_set_bool(OBJECT(dev), false, "msi_bypass", &error_fata= l); + object_property_set_bool(OBJECT(dev), true, "realized", &error_abort); + + node =3D 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); +} + + static void create_pcie(VirtMachineState *vms, qemu_irq *pic) { hwaddr base_mmio =3D vms->memmap[VIRT_PCIE_MMIO].base; @@ -1167,7 +1207,16 @@ static void create_pcie(VirtMachineState *vms, qemu_= irq *pic) if (vms->iommu) { vms->iommu_phandle =3D qemu_fdt_alloc_phandle(vms->fdt); =20 - create_smmu(vms, pic, pci->bus); + switch (vms->iommu) { + case VIRT_IOMMU_SMMUV3: + create_smmu(vms, pic, pci->bus); + break; + case VIRT_IOMMU_VIRTIO: + create_virtio_iommu(vms, pic, pci->bus); + break; + default: + g_assert_not_reached(); + } =20 qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map", 0x0, vms->iommu_phandle, 0x0, 0x10000); diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 9a870cc..837c135 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -64,6 +64,7 @@ enum { VIRT_GIC_REDIST, VIRT_GIC_REDIST2, VIRT_SMMU, + VIRT_VIRTIO_IOMMU, VIRT_UART, VIRT_MMIO, VIRT_RTC, --=20 2.5.5