Received: by 2002:a05:6512:3aa:0:0:0:0 with SMTP id v10csp362634lfp; Fri, 7 Feb 2020 01:36:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxVyzNB/CzQHlKgR8GTkIS2vQlUwgo8ZOV1sS7JJT4U0EroHevgStTeQ6dJugjSZj1XiC+S X-Received: by 2002:ac8:4e43:: with SMTP id e3mr6669816qtw.129.1581068168881; Fri, 07 Feb 2020 01:36:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581068168; cv=none; d=google.com; s=arc-20160816; b=lU9eWpPtBo3l9JDVxGjnbEL3CrXwlsnVVTbnGhtpfUmLNZ5QEWn9JsK2yNspMCQFQv dvmw3atYJ1+Sq8ctCzoCt+Pg3AKmoRKRUkVG2Y0GUZow+CW5MYRUW2gJ8Iy1dsoeUQxB OSi6R0GccDB2ly+F5SdDxwoO/QZJMoncZwF+layO6KVZbypm4Qfi2S+ul3Y4XGMuIwVF 28hVaRQ8YMwM4yTUVogIN6jj9e7ctiaZXTX1iJreD3qKYjhdbesM04xnJceZTslSdByJ m4a76XDiPHysilmTJRO8vn0K8dtk7nCbBJO0qKzP248jsSZM+GYBpzEmSgQeu8KTZWPe 86NQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=bTwQOlqxoVwpnfegHRn2b9Emri8g+ClUmBQXK/hi3uA=; b=FgFtj0wx6gGO6YUH7l4MhNa5DyzcI8Ugalm0U/ERggL7jCHrNmSlhkc5IfJC6ko3Pn pn0Wnr4Gc3a+U2/0OzfGigWofRrHAsNfc3WeByNGDiA9Ehvwgvqjb5e+wNDc/orHgQBk 71MPxRWA07PO08apP9ky7EdS+5CijXjRmJdnwi8/nXNsqNAnZd7TCGOSZVBaVaQEt1cO 22wZTuCMLHca2wt+lKF6MBdcq+SXFyqJArSZ1fOanuv4wcRioxsrH+4iu+GBVNb9lG7p NAAW3W9jmVjegK6j8pPbo0kz66cZfxtL1lVLIjJKvT+Lu6S8KxjRkbWenNWAOWFlrLa4 FrCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=f2HXovBL; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id o12si933575qvr.30.2020.02.07.01.36.08 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Feb 2020 01:36:08 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=f2HXovBL; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:52840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j003U-0002ty-AK for alex.bennee@linaro.org; Fri, 07 Feb 2020 04:36:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36782) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j001H-0008Rx-4i for qemu-devel@nongnu.org; Fri, 07 Feb 2020 04:33:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j001F-00051J-Bd for qemu-devel@nongnu.org; Fri, 07 Feb 2020 04:33:50 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:58047 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j001F-00051C-7M for qemu-devel@nongnu.org; Fri, 07 Feb 2020 04:33:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581068028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bTwQOlqxoVwpnfegHRn2b9Emri8g+ClUmBQXK/hi3uA=; b=f2HXovBLUjBNY/OKjGEIqbX+wLyDKgroqcGNxCXDUHcNnjn/CGTt5JbvTh69B6R8vlYhAa Cl4q1ZTulz5PXJWZXkxY2+uivwBr8FrmkcKAmnuVAByL8UZG/iZ1ajNFVEVx3iHMhrwa9L hoAV2hfNJUY2kfLjqxloSaZD5NIj6/c= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-413-2ll_mc46MHaXXvZ7o96xlg-1; Fri, 07 Feb 2020 04:33:47 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3907101FC65; Fri, 7 Feb 2020 09:33:45 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD65D790CF; Fri, 7 Feb 2020 09:33:40 +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, jean-philippe@linaro.org, dgilbert@redhat.com, quintela@redhat.com, mst@redhat.com, peterx@redhat.com Subject: [PATCH v14 09/11] hw/arm/virt: Add the virtio-iommu device tree mappings Date: Fri, 7 Feb 2020 10:32:01 +0100 Message-Id: <20200207093203.3788-10-eric.auger@redhat.com> In-Reply-To: <20200207093203.3788-1-eric.auger@redhat.com> References: <20200207093203.3788-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-MC-Unique: 2ll_mc46MHaXXvZ7o96xlg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevin.tian@intel.com, bharatb.linux@gmail.com, tnowicki@marvell.com Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-devel" X-TUID: Eq5KqCr8NlRU Adds the "virtio,pci-iommu" node in the host bridge node and the RID mapping, excluding the IOMMU RID. Signed-off-by: Eric Auger Reviewed-by: Jean-Philippe Brucker --- v11 -> v12: - Added Jean's R-b v10 -> v11: - remove msi_bypass v8 -> v9: - disable msi-bypass property - addition of the subnode is handled is the hotplug handler and IOMMU RID is notimposed anymore 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 | 54 ++++++++++++++++++++++++++++++++++++------- include/hw/arm/virt.h | 2 ++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index f788fe27d6..274abc10c0 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -32,6 +32,7 @@ #include "qemu-common.h" #include "qemu/units.h" #include "qemu/option.h" +#include "monitor/qdev.h" #include "qapi/error.h" #include "hw/sysbus.h" #include "hw/boards.h" @@ -54,6 +55,7 @@ #include "qemu/error-report.h" #include "qemu/module.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/qdev-properties.h" @@ -71,6 +73,7 @@ #include "hw/mem/pc-dimm.h" #include "hw/mem/nvdimm.h" #include "hw/acpi/generic_event_device.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, \ @@ -1180,6 +1183,30 @@ static void create_smmu(const VirtMachineState *vms, g_free(node); } =20 +static void create_virtio_iommu(VirtMachineState *vms, Error **errp) +{ + const char compat[] =3D "virtio,pci-iommu"; + uint16_t bdf =3D vms->virtio_iommu_bdf; + char *node; + + vms->iommu_phandle =3D qemu_fdt_alloc_phandle(vms->fdt); + + node =3D g_strdup_printf("%s/virtio_iommu@%d", vms->pciehb_nodename, b= df); + 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, 1, 0, 1, 0, + 1, 0, 1, 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); + + qemu_fdt_setprop_cells(vms->fdt, vms->pciehb_nodename, "iommu-map", + 0x0, vms->iommu_phandle, 0x0, bdf, + bdf + 1, vms->iommu_phandle, bdf + 1, 0xffff - = bdf); +} + static void create_pcie(VirtMachineState *vms) { hwaddr base_mmio =3D vms->memmap[VIRT_PCIE_MMIO].base; @@ -1258,7 +1285,7 @@ static void create_pcie(VirtMachineState *vms) } } =20 - nodename =3D g_strdup_printf("/pcie@%" PRIx64, base); + nodename =3D vms->pciehb_nodename =3D g_strdup_printf("/pcie@%" PRIx64= , base); qemu_fdt_add_subnode(vms->fdt, nodename); qemu_fdt_setprop_string(vms->fdt, nodename, "compatible", "pci-host-ecam-generic"); @@ -1301,13 +1328,16 @@ static void create_pcie(VirtMachineState *vms) if (vms->iommu) { vms->iommu_phandle =3D qemu_fdt_alloc_phandle(vms->fdt); =20 - create_smmu(vms, pci->bus); - - qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map", - 0x0, vms->iommu_phandle, 0x0, 0x10000); + switch (vms->iommu) { + case VIRT_IOMMU_SMMUV3: + create_smmu(vms, pci->bus); + qemu_fdt_setprop_cells(vms->fdt, nodename, "iommu-map", + 0x0, vms->iommu_phandle, 0x0, 0x10000); + break; + default: + g_assert_not_reached(); + } } - - g_free(nodename); } =20 static void create_platform_bus(VirtMachineState *vms) @@ -1976,6 +2006,13 @@ static void virt_machine_device_plug_cb(HotplugHandl= er *hotplug_dev, if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) { virt_memory_plug(hotplug_dev, dev, errp); } + if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) { + PCIDevice *pdev =3D PCI_DEVICE(dev); + + vms->iommu =3D VIRT_IOMMU_VIRTIO; + vms->virtio_iommu_bdf =3D pci_get_bdf(pdev); + create_virtio_iommu(vms, errp); + } } =20 static void virt_machine_device_unplug_request_cb(HotplugHandler *hotplug_= dev, @@ -1989,7 +2026,8 @@ static HotplugHandler *virt_machine_get_hotplug_handl= er(MachineState *machine, DeviceState *dev) { if (object_dynamic_cast(OBJECT(dev), TYPE_SYS_BUS_DEVICE) || - (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM))) { + (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM)) || + (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI))) { return HOTPLUG_HANDLER(machine); } =20 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index 71508bf40c..02f500cb8e 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -125,8 +125,10 @@ typedef struct { bool virt; int32_t gic_version; VirtIOMMUType iommu; + uint16_t virtio_iommu_bdf; struct arm_boot_info bootinfo; MemMapEntry *memmap; + char *pciehb_nodename; const int *irqmap; int smp_cpus; void *fdt; --=20 2.20.1