From nobody Sun May 19 14:40:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1614329517; cv=none; d=zohomail.com; s=zohoarc; b=LZssjpiAHzmwYpatjCNW50B2C73fWBCBh6dailx9NVnQWH03CKG6nye7TTAAm0r2KJIxAEMNNXgKWNnZKmPs8yHohNjG1O774UE52zjKZOpKP51g/Kqfsq84ZFAgdMwf98vFpPLv4+xIhGCK0gJgBJaeiAkIhs83dq+5WwvjQu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614329517; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FylAKnGbTJlfVFVZqEQSO3LAKrD/JuyF9BY5MPgF2IQ=; b=UDvQHv8vfeebgO9cKJsHXMyH4szSWlon5vlXMI9j89LNGuihIX6yVtYn+IF9gMt5mR7WBfqYAfb+mveiNGz+AvD1g4C5r8wes0qi5jOAVt9xSHyHQ4bwBDrYauk2zgai8zthQSDpxginnXtKOodmE/veWWbx6glsHMP5pIKssWk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614329517596965.9447774814915; Fri, 26 Feb 2021 00:51:57 -0800 (PST) Received: from localhost ([::1]:60236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lFYqo-0006Eh-JY for importer@patchew.org; Fri, 26 Feb 2021 03:51:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFYol-0004rN-G2; Fri, 26 Feb 2021 03:49:47 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:3373) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFYoj-0003Yr-Aj; Fri, 26 Feb 2021 03:49:47 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Dn3Fl0XCCz164BW; Fri, 26 Feb 2021 16:47:55 +0800 (CST) Received: from huawei.com (10.174.185.226) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Fri, 26 Feb 2021 16:49:25 +0800 From: Wang Xingang To: Subject: [RFC PATCH 1/4] pci: Add PCI_BUS_IOMMU property Date: Fri, 26 Feb 2021 08:49:10 +0000 Message-ID: <1614329353-2124-2-git-send-email-wangxingang5@huawei.com> X-Mailer: git-send-email 2.6.4.windows.1 In-Reply-To: <1614329353-2124-1-git-send-email-wangxingang5@huawei.com> References: <1614329353-2124-1-git-send-email-wangxingang5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.185.226] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.190; envelope-from=wangxingang5@huawei.com; helo=szxga04-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: xieyingtai@huawei.com, peter.maydell@linaro.org, cenjiahui@huawei.com, wangxingang5@huawei.com, mst@redhat.com, shannon.zhaosl@gmail.com, qemu-arm@nongnu.org, imammedo@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang This property can be useful to check whether this bus is attached to iommu. Signed-off-by: Xingang Wang Signed-off-by: Jiahui Cen --- include/hw/pci/pci_bus.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h index 347440d42c..42109e8a06 100644 --- a/include/hw/pci/pci_bus.h +++ b/include/hw/pci/pci_bus.h @@ -24,6 +24,8 @@ enum PCIBusFlags { PCI_BUS_IS_ROOT =3D 0x0001, /* PCIe extended configuration space is accessible on this bus */ PCI_BUS_EXTENDED_CONFIG_SPACE =3D 0x0002, + /* Iommu is enabled on this bus */ + PCI_BUS_IOMMU =3D 0x0004, }; =20 struct PCIBus { @@ -63,4 +65,15 @@ static inline bool pci_bus_allows_extended_config_space(= PCIBus *bus) return !!(bus->flags & PCI_BUS_EXTENDED_CONFIG_SPACE); } =20 +static inline bool pci_bus_has_iommu(PCIBus *bus) +{ + PCIBus *root_bus =3D bus; + + while (root_bus && !pci_bus_is_root(root_bus)) { + root_bus =3D pci_get_bus(root_bus->parent_dev); + } + + return !!(root_bus->flags & PCI_BUS_IOMMU); +} + #endif /* QEMU_PCI_BUS_H */ --=20 2.19.1 From nobody Sun May 19 14:40:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1614329637; cv=none; d=zohomail.com; s=zohoarc; b=IhG2EzD0vfThsbJin1pkfQ0M8xHU0WNgDdgGz2LpGnaiQNZUyi3qnxy8bj02e6FhCUUWg4g4NvkogF2dquKWyoHgyWFIj2wT+e33MjKFd7VXmZrRQu9mX4X3Yfu7dXBPhsRfZ17JhAhrJyouuMZcmvy6CeC0fUaXZpP16BEXWVo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614329637; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sbzFPJ2QO5cK2sB8vdASmmbQR/662gbSXtEVTD0npWA=; b=h4fcsPXHHGfxzK7/OzyVSg3L4Ff8CSjPzwpqZjKqSh+EonCeHQQ/QeVNO+sfHEbn3fmLTEQT4pFpc3+BjyKEPLA4j3FWTq/2T52/hDeUMY2sU0dxQfXY0xrGwr46TmnrpZv7167e5NT1VPruxcX9xJcMruiEwaSjn126X+r1xwA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614329637796617.4822324768161; Fri, 26 Feb 2021 00:53:57 -0800 (PST) Received: from localhost ([::1]:38332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lFYsm-0000Nf-Kw for importer@patchew.org; Fri, 26 Feb 2021 03:53:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFYol-0004rb-RK; Fri, 26 Feb 2021 03:49:47 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2657) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFYoj-0003Yq-Ae; Fri, 26 Feb 2021 03:49:47 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Dn3Fl1mc8z7qQg; Fri, 26 Feb 2021 16:47:55 +0800 (CST) Received: from huawei.com (10.174.185.226) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Fri, 26 Feb 2021 16:49:26 +0800 From: Wang Xingang To: Subject: [RFC PATCH 2/4] hw/pci: Add iommu option for pci root bus Date: Fri, 26 Feb 2021 08:49:11 +0000 Message-ID: <1614329353-2124-3-git-send-email-wangxingang5@huawei.com> X-Mailer: git-send-email 2.6.4.windows.1 In-Reply-To: <1614329353-2124-1-git-send-email-wangxingang5@huawei.com> References: <1614329353-2124-1-git-send-email-wangxingang5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.185.226] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.35; envelope-from=wangxingang5@huawei.com; helo=szxga07-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: xieyingtai@huawei.com, peter.maydell@linaro.org, cenjiahui@huawei.com, wangxingang5@huawei.com, mst@redhat.com, shannon.zhaosl@gmail.com, qemu-arm@nongnu.org, imammedo@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang This add iommu option for pci root bus, including primary bus and pxb root bus. Default option is set to true, and the option is valid only if the iommu option for machine is properly set. Signed-off-by: Xingang Wang Signed-off-by: Jiahui Cen --- hw/arm/virt.c | 29 +++++++++++++++++++++++++++++ hw/pci-bridge/pci_expander_bridge.c | 6 ++++++ hw/pci/pci.c | 2 +- include/hw/arm/virt.h | 1 + 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 371147f3ae..0c9e549759 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -79,6 +79,7 @@ #include "hw/virtio/virtio-iommu.h" #include "hw/char/pl011.h" #include "qemu/guest-random.h" +#include "include/hw/pci/pci_bus.h" =20 #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ @@ -1232,6 +1233,10 @@ static void create_smmu(const VirtMachineState *vms, =20 dev =3D qdev_new("arm-smmuv3"); =20 + if (vms->primary_bus_iommu) { + bus->flags |=3D PCI_BUS_IOMMU; + } + object_property_set_link(OBJECT(dev), "primary-bus", OBJECT(bus), &error_abort); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); @@ -2305,6 +2310,20 @@ static void virt_set_iommu(Object *obj, const char *= value, Error **errp) } } =20 +static bool virt_get_primary_bus_iommu(Object *obj, Error **errp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + return vms->primary_bus_iommu; +} + +static void virt_set_primary_bus_iommu(Object *obj, bool value, Error **er= rp) +{ + VirtMachineState *vms =3D VIRT_MACHINE(obj); + + vms->primary_bus_iommu =3D value; +} + static CpuInstanceProperties virt_cpu_index_to_props(MachineState *ms, unsigned cpu_index) { @@ -2629,6 +2648,13 @@ static void virt_machine_class_init(ObjectClass *oc,= void *data) "Set the IOMMU type. " "Valid values are none and smmuv= 3"); =20 + object_class_property_add_bool(oc, "primary_bus_iommu", + virt_get_primary_bus_iommu, + virt_set_primary_bus_iommu); + object_class_property_set_description(oc, "primary_bus_iommu", + "Set on/off to enable/disable " + "iommu for primary bus"); + object_class_property_add_bool(oc, "ras", virt_get_ras, virt_set_ras); object_class_property_set_description(oc, "ras", @@ -2696,6 +2722,9 @@ static void virt_instance_init(Object *obj) /* Default disallows iommu instantiation */ vms->iommu =3D VIRT_IOMMU_NONE; =20 + /* Iommu is enabled by default for primary bus */ + vms->primary_bus_iommu =3D true; + /* Default disallows RAS instantiation */ vms->ras =3D false; =20 diff --git a/hw/pci-bridge/pci_expander_bridge.c b/hw/pci-bridge/pci_expand= er_bridge.c index aedded1064..7971ce9bd9 100644 --- a/hw/pci-bridge/pci_expander_bridge.c +++ b/hw/pci-bridge/pci_expander_bridge.c @@ -57,6 +57,7 @@ struct PXBDev { =20 uint8_t bus_nr; uint16_t numa_node; + bool iommu; }; =20 static PXBDev *convert_to_pxb(PCIDevice *dev) @@ -254,6 +255,10 @@ static void pxb_dev_realize_common(PCIDevice *dev, boo= l pcie, Error **errp) bus->address_space_io =3D pci_get_bus(dev)->address_space_io; bus->map_irq =3D pxb_map_irq_fn; =20 + if (pxb->iommu) { + bus->flags |=3D PCI_BUS_IOMMU; + } + PCI_HOST_BRIDGE(ds)->bus =3D bus; =20 pxb_register_bus(dev, bus, &local_err); @@ -301,6 +306,7 @@ static Property pxb_dev_properties[] =3D { /* Note: 0 is not a legal PXB bus number. */ DEFINE_PROP_UINT8("bus_nr", PXBDev, bus_nr, 0), DEFINE_PROP_UINT16("numa_node", PXBDev, numa_node, NUMA_NODE_UNASSIGNE= D), + DEFINE_PROP_BOOL("iommu", PXBDev, iommu, true), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/pci/pci.c b/hw/pci/pci.c index a9ebef8a35..dc969989c9 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2712,7 +2712,7 @@ AddressSpace *pci_device_iommu_address_space(PCIDevic= e *dev) =20 iommu_bus =3D parent_bus; } - if (iommu_bus && iommu_bus->iommu_fn) { + if (pci_bus_has_iommu(bus) && iommu_bus && iommu_bus->iommu_fn) { return iommu_bus->iommu_fn(bus, iommu_bus->iommu_opaque, devfn); } return &address_space_memory; diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index ee9a93101e..babe829486 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -147,6 +147,7 @@ struct VirtMachineState { OnOffAuto acpi; VirtGICType gic_version; VirtIOMMUType iommu; + bool primary_bus_iommu; VirtMSIControllerType msi_controller; uint16_t virtio_iommu_bdf; struct arm_boot_info bootinfo; --=20 2.19.1 From nobody Sun May 19 14:40:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1614329636; cv=none; d=zohomail.com; s=zohoarc; b=cIFaC4tGfehe1W+318idmUUuhTZoF3rgjDCrOyOW99mzND/FJiqNcPQQJ069SwDa9BOr2j5RZpQLZF5pXV/OPlDJ+jxqAE43mJFn/OABLMvFIT4B+TSY08ZK0QacfkVmCBFVdOQ/8YwYeqt4hgaHlcdy7yMMwYHEfGNtuGKw2hE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614329636; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NQ/yIixLZVbKC4+Wi9PZ2LRq2vSgMrtFwIAgtPaSzdU=; b=Gw6TIlDD2ekxWbuapGQQpCTpHDaZbIa571W0IMKmPl3aF3qkI54eDtY8JLSnTyRMU71Q4mM79JYqmHEbF6eIMP8ZiV6XLZgXwpedaXLwH+xJDOdLidbz9hPvju4hArrpP5af16qYlhwMf+2RfG9hRPJZNWcA/kNDtOqxYgMGVpI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614329636541302.7046797098204; Fri, 26 Feb 2021 00:53:56 -0800 (PST) Received: from localhost ([::1]:38126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lFYsk-0000IB-Fc for importer@patchew.org; Fri, 26 Feb 2021 03:53:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFYoo-0004uV-Pj; Fri, 26 Feb 2021 03:49:50 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2942) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFYoj-0003b6-K7; Fri, 26 Feb 2021 03:49:50 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Dn3FL0vpBzMfBM; Fri, 26 Feb 2021 16:47:34 +0800 (CST) Received: from huawei.com (10.174.185.226) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Fri, 26 Feb 2021 16:49:27 +0800 From: Wang Xingang To: Subject: [RFC PATCH 3/4] hw/pci: Add pci_root_bus_max_bus Date: Fri, 26 Feb 2021 08:49:12 +0000 Message-ID: <1614329353-2124-4-git-send-email-wangxingang5@huawei.com> X-Mailer: git-send-email 2.6.4.windows.1 In-Reply-To: <1614329353-2124-1-git-send-email-wangxingang5@huawei.com> References: <1614329353-2124-1-git-send-email-wangxingang5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.185.226] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.191; envelope-from=wangxingang5@huawei.com; helo=szxga05-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: xieyingtai@huawei.com, peter.maydell@linaro.org, cenjiahui@huawei.com, wangxingang5@huawei.com, mst@redhat.com, shannon.zhaosl@gmail.com, qemu-arm@nongnu.org, imammedo@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang This helps to find max bus number of a root bus. Signed-off-by: Xingang Wang Signed-off-by: Jiahui Cen --- hw/pci/pci.c | 33 +++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + 2 files changed, 34 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index dc969989c9..ed92ce0971 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -516,6 +516,39 @@ int pci_bus_num(PCIBus *s) return PCI_BUS_GET_CLASS(s)->bus_num(s); } =20 +int pci_root_bus_max_bus(PCIBus *bus) +{ + PCIHostState *host; + int max_bus =3D 0; + int type; + int devfn; + + if (!pci_bus_is_root(bus)) { + return 0; + } + + host =3D PCI_HOST_BRIDGE(BUS(bus)->parent); + max_bus =3D pci_bus_num(host->bus); + + for (devfn =3D 0; devfn < ARRAY_SIZE(host->bus->devices); devfn++) { + PCIDevice *dev =3D host->bus->devices[devfn]; + + if (!dev) { + continue; + } + + type =3D dev->config[PCI_HEADER_TYPE] & ~PCI_HEADER_TYPE_MULTI_FUN= CTION; + if (type =3D=3D PCI_HEADER_TYPE_BRIDGE) { + uint8_t subordinate =3D dev->config[PCI_SUBORDINATE_BUS]; + if (subordinate > max_bus) { + max_bus =3D subordinate; + } + } + } + + return max_bus; +} + int pci_bus_numa_node(PCIBus *bus) { return PCI_BUS_GET_CLASS(bus)->numa_node(bus); diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 1bc231480f..238b91817a 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -449,6 +449,7 @@ static inline PCIBus *pci_get_bus(const PCIDevice *dev) return PCI_BUS(qdev_get_parent_bus(DEVICE(dev))); } int pci_bus_num(PCIBus *s); +int pci_root_bus_max_bus(PCIBus *bus); static inline int pci_dev_bus_num(const PCIDevice *dev) { return pci_bus_num(pci_get_bus(dev)); --=20 2.19.1 From nobody Sun May 19 14:40:14 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1614330039; cv=none; d=zohomail.com; s=zohoarc; b=ayjtbs9URvUo8P3wEf6jVC3u4UUwIAO6SQ9EUisO6MqQ3WFebJN6/I9SD51y1RpepRt23QuYGUorx78I0Bp+7vIn3Y6KFY+lz/cxd+7uwJk09V6BRMmjcFUdITRpcxt9+EQiMroury0xrVKWAHMaNRkJZXfiwKuVUdfSmey8EUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614330039; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MF0uEgNQ10dhatV3rdIpuiQ2V60leOMvU634U9c42WE=; b=OcP31+4mCIge4UaVbvS6oqOhmDBTS2dyNwmgaLAh3T3nv1RXZShDCOhjgH2fNrBjAPWIIyYZOz1T+EpLsru947MZlWdR+xizhMUPMjwmr/tVnWWuKJq2BhfrdIHogohKWh/3sDOIG/3CBvbINX0T5k2Mj+8iuJfeHCnnhpT9qCQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1614330039378433.21368935455655; Fri, 26 Feb 2021 01:00:39 -0800 (PST) Received: from localhost ([::1]:57436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lFYzG-0008Er-0y for importer@patchew.org; Fri, 26 Feb 2021 04:00:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFYom-0004sj-N0; Fri, 26 Feb 2021 03:49:48 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lFYoj-0003b7-Jk; Fri, 26 Feb 2021 03:49:48 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4Dn3FL19PbzMfG7; Fri, 26 Feb 2021 16:47:34 +0800 (CST) Received: from huawei.com (10.174.185.226) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Fri, 26 Feb 2021 16:49:27 +0800 From: Wang Xingang To: Subject: [RFC PATCH 4/4] hw/arm/virt-acpi-build: Add explicit idmap info in IORT table Date: Fri, 26 Feb 2021 08:49:13 +0000 Message-ID: <1614329353-2124-5-git-send-email-wangxingang5@huawei.com> X-Mailer: git-send-email 2.6.4.windows.1 In-Reply-To: <1614329353-2124-1-git-send-email-wangxingang5@huawei.com> References: <1614329353-2124-1-git-send-email-wangxingang5@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.185.226] X-CFilter-Loop: Reflected Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=45.249.212.191; envelope-from=wangxingang5@huawei.com; helo=szxga05-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: xieyingtai@huawei.com, peter.maydell@linaro.org, cenjiahui@huawei.com, wangxingang5@huawei.com, mst@redhat.com, shannon.zhaosl@gmail.com, qemu-arm@nongnu.org, imammedo@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Xingang Wang The idmap of smmuv3 and root complex covers the whole RID space for now, this patch add explicit idmap info according to root bus number range. This add smmuv3 idmap for certain bus which has enabled the iommu property. Signed-off-by: Xingang Wang Signed-off-by: Jiahui Cen --- hw/arm/virt-acpi-build.c | 88 +++++++++++++++++++++++++++++----------- 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index f9c9df916c..8bb8b251d0 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -54,6 +54,7 @@ #include "kvm_arm.h" #include "migration/vmstate.h" #include "hw/acpi/ghes.h" +#include "hw/pci/pci_bus.h" =20 #define ARM_SPI_BASE 32 =20 @@ -247,9 +248,34 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vir= tMachineState *vms) AcpiIortSmmu3 *smmu; size_t node_size, iort_node_offset, iort_length, smmu_offset =3D 0; AcpiIortRC *rc; + PCIBus *bus =3D vms->bus; + GArray *root_bus_array; + size_t root_bus_count =3D 0; + size_t root_bus_smmu_count =3D 0; + int bus_num, max_bus, index; + + root_bus_array =3D g_array_new(false, true, sizeof(PCIBus *)); =20 iort =3D acpi_data_push(table_data, sizeof(*iort)); =20 + g_array_append_val(root_bus_array, bus); + root_bus_count++; + if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3 && pci_bus_has_iommu(bus)) { + root_bus_smmu_count++; + } + + QLIST_FOREACH(bus, &bus->child, sibling) { + + if (!pci_bus_is_root(bus)) continue; + + g_array_append_val(root_bus_array, bus); + root_bus_count++; + + if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3 && pci_bus_has_iommu(bus))= { + root_bus_smmu_count++; + } + } + if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3) { nb_nodes =3D 3; /* RC, ITS, SMMUv3 */ } else { @@ -280,13 +306,13 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vi= rtMachineState *vms) =20 /* SMMUv3 node */ smmu_offset =3D iort_node_offset + node_size; - node_size =3D sizeof(*smmu) + sizeof(*idmap); + node_size =3D sizeof(*smmu) + sizeof(*idmap) * root_bus_smmu_count; iort_length +=3D node_size; smmu =3D acpi_data_push(table_data, node_size); =20 smmu->type =3D ACPI_IORT_NODE_SMMU_V3; smmu->length =3D cpu_to_le16(node_size); - smmu->mapping_count =3D cpu_to_le32(1); + smmu->mapping_count =3D cpu_to_le32(root_bus_smmu_count); smmu->mapping_offset =3D cpu_to_le32(sizeof(*smmu)); smmu->base_address =3D cpu_to_le64(vms->memmap[VIRT_SMMU].base); smmu->flags =3D cpu_to_le32(ACPI_IORT_SMMU_V3_COHACC_OVERRIDE); @@ -295,23 +321,32 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vi= rtMachineState *vms) smmu->gerr_gsiv =3D cpu_to_le32(irq + 2); smmu->sync_gsiv =3D cpu_to_le32(irq + 3); =20 - /* Identity RID mapping covering the whole input RID range */ - idmap =3D &smmu->id_mapping_array[0]; - idmap->input_base =3D 0; - idmap->id_count =3D cpu_to_le32(0xFFFF); - idmap->output_base =3D 0; - /* output IORT node is the ITS group node (the first node) */ - idmap->output_reference =3D cpu_to_le32(iort_node_offset); + index =3D 0; + for (int i =3D 0; i < root_bus_count; i++) { + bus =3D g_array_index(root_bus_array, PCIBus *, i); + + if (!pci_bus_has_iommu(bus)) continue; + + bus_num =3D pci_bus_num(bus); + max_bus =3D pci_root_bus_max_bus(bus); + + idmap =3D &smmu->id_mapping_array[index++]; + idmap->input_base =3D cpu_to_le32(bus_num << 8); + idmap->id_count =3D cpu_to_le32((max_bus - bus_num + 1) << 8); + idmap->output_base =3D cpu_to_le32(bus_num << 8); + /* output IORT node is the ITS group node (the first node) */ + idmap->output_reference =3D cpu_to_le32(iort_node_offset); + } } =20 /* Root Complex Node */ - node_size =3D sizeof(*rc) + sizeof(*idmap); + node_size =3D sizeof(*rc) + sizeof(*idmap) * root_bus_count; iort_length +=3D node_size; rc =3D acpi_data_push(table_data, node_size); =20 rc->type =3D ACPI_IORT_NODE_PCI_ROOT_COMPLEX; rc->length =3D cpu_to_le16(node_size); - rc->mapping_count =3D cpu_to_le32(1); + rc->mapping_count =3D cpu_to_le32(root_bus_count); rc->mapping_offset =3D cpu_to_le32(sizeof(*rc)); =20 /* fully coherent device */ @@ -319,18 +354,23 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vi= rtMachineState *vms) rc->memory_properties.memory_flags =3D 0x3; /* CCA =3D CPM =3D DCAS = =3D 1 */ rc->pci_segment_number =3D 0; /* MCFG pci_segment */ =20 - /* Identity RID mapping covering the whole input RID range */ - idmap =3D &rc->id_mapping_array[0]; - idmap->input_base =3D 0; - idmap->id_count =3D cpu_to_le32(0xFFFF); - idmap->output_base =3D 0; - - if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3) { - /* output IORT node is the smmuv3 node */ - idmap->output_reference =3D cpu_to_le32(smmu_offset); - } else { - /* output IORT node is the ITS group node (the first node) */ - idmap->output_reference =3D cpu_to_le32(iort_node_offset); + for (int i =3D 0; i < root_bus_count; i++) { + bus =3D g_array_index(root_bus_array, PCIBus *, i); + bus_num =3D pci_bus_num(bus); + max_bus =3D pci_root_bus_max_bus(bus); + + idmap =3D &rc->id_mapping_array[i]; + idmap->input_base =3D cpu_to_le32(bus_num << 8); + idmap->id_count =3D cpu_to_le32((max_bus - bus_num + 1) << 8); + idmap->output_base =3D cpu_to_le32(bus_num << 8); + + if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3 && pci_bus_has_iommu(bus))= { + /* output IORT node is the smmuv3 node */ + idmap->output_reference =3D cpu_to_le32(smmu_offset); + } else { + /* output IORT node is the ITS group node (the first node) */ + idmap->output_reference =3D cpu_to_le32(iort_node_offset); + } } =20 /* @@ -343,6 +383,8 @@ build_iort(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) build_header(linker, table_data, (void *)(table_data->data + iort_star= t), "IORT", table_data->len - iort_start, 0, vms->oem_id, vms->oem_table_id); + + g_array_free(root_bus_array, true); } =20 static void --=20 2.19.1