From nobody Sun Feb 8 19:59:43 2026 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516374547336989.5327184647994; Fri, 19 Jan 2018 07:09:07 -0800 (PST) Received: from localhost ([::1]:54317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecYHq-0003B3-MG for importer@patchew.org; Fri, 19 Jan 2018 10:08:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49810) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecYFU-0001SM-3F for qemu-devel@nongnu.org; Fri, 19 Jan 2018 10:06:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecYFS-0002vv-F3 for qemu-devel@nongnu.org; Fri, 19 Jan 2018 10:06:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49580) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ecYFO-0002iC-DG; Fri, 19 Jan 2018 10:06:26 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C93E80478; Fri, 19 Jan 2018 15:06:25 +0000 (UTC) Received: from AMD.redhat.com (ovpn-116-129.ams2.redhat.com [10.36.116.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id F27635C1B7; Fri, 19 Jan 2018 15:06:00 +0000 (UTC) From: Eric Auger 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 Date: Fri, 19 Jan 2018 14:49:11 +0000 Message-Id: <1516373355-305-19-git-send-email-eric.auger@redhat.com> In-Reply-To: <1516373355-305-1-git-send-email-eric.auger@redhat.com> References: <1516373355-305-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 19 Jan 2018 15:06:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v5 18/22] hw/arm/virt-acpi-build: Add virtio-iommu node in IORT table 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, marc.zyngier@arm.com, tn@semihalf.com, will.deacon@arm.com, drjones@redhat.com, peterx@redhat.com, linuc.decode@gmail.com, bharat.bhushan@nxp.com, christoffer.dall@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch builds the virtio-iommu node in the ACPI IORT table. The dt node creation function fills the information used by the IORT table generation function (base address, base irq, type of the smmu). The RID space of the root complex, which spans 0x0-0x10000 maps to streamid space 0x0-0x10000 in smmuv3, which in turn maps to deviceid space 0x0-0x10000 in the ITS group. Signed-off-by: Eric Auger --- hw/arm/virt-acpi-build.c | 55 +++++++++++++++++++++++++++++++++++++++--= ---- hw/arm/virt.c | 5 +++++ include/hw/acpi/acpi-defs.h | 21 ++++++++++++++++- include/hw/arm/virt.h | 13 +++++++++++ 4 files changed, 86 insertions(+), 8 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index f7fa795..371edde 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -42,6 +42,7 @@ #include "hw/acpi/aml-build.h" #include "hw/pci/pcie_host.h" #include "hw/pci/pci.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/arm/virt.h" #include "sysemu/numa.h" #include "kvm_arm.h" @@ -393,18 +394,26 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, un= signed xsdt_tbl_offset) } =20 static void -build_iort(GArray *table_data, BIOSLinker *linker) +build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) { - int iort_start =3D table_data->len; + int nb_nodes, iort_start =3D table_data->len; AcpiIortIdMapping *idmap; AcpiIortItsGroup *its; AcpiIortTable *iort; - size_t node_size, iort_length; + AcpiIortPVIommu *iommu; + size_t node_size, iort_length, iommu_offset =3D 0; AcpiIortRC *rc; =20 iort =3D acpi_data_push(table_data, sizeof(*iort)); =20 + if (vms->iommu_info.type) { + nb_nodes =3D 3; /* RC, ITS, IOMMU */ + } else { + nb_nodes =3D 2; /* RC, ITS */ + } + iort_length =3D sizeof(*iort); + iort->node_count =3D cpu_to_le32(nb_nodes); iort->node_count =3D cpu_to_le32(2); /* RC and ITS nodes */ iort->node_offset =3D cpu_to_le32(sizeof(*iort)); =20 @@ -418,6 +427,32 @@ build_iort(GArray *table_data, BIOSLinker *linker) its->its_count =3D cpu_to_le32(1); its->identifiers[0] =3D 0; /* MADT translation_id */ =20 + if (vms->iommu_info.type =3D=3D VIRT_IOMMU_VIRTIO) { + + /* Para-virtualized IOMMU node */ + iommu_offset =3D cpu_to_le32(iort->node_offset + node_size); + node_size =3D sizeof(*iommu) + sizeof(*idmap); + iort_length +=3D node_size; + iommu =3D acpi_data_push(table_data, node_size); + + iommu->type =3D ACPI_IORT_NODE_PARAVIRT; + iommu->length =3D cpu_to_le16(node_size); + iommu->base_address =3D cpu_to_le64(vms->iommu_info.reg.base); + iommu->span =3D cpu_to_le64(vms->iommu_info.reg.size); + iommu->model =3D ACPI_IORT_NODE_PV_VIRTIO_IOMMU; + iommu->flags =3D ACPI_IORT_NODE_PV_CACHE_COHERENT; + iommu->interrupt_count =3D 1; + iommu->interrupts[0] =3D cpu_to_le64(vms->iommu_info.irq_base); + + /* Identity RID mapping covering the whole input RID range */ + idmap =3D &iommu->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); + } + /* Root Complex Node */ node_size =3D sizeof(*rc) + sizeof(*idmap); iort_length +=3D node_size; @@ -438,10 +473,16 @@ build_iort(GArray *table_data, BIOSLinker *linker) 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); =20 - iort->length =3D cpu_to_le32(iort_length); + if (vms->iommu_info.type) { + /* output IORT node is the smmuv3 node */ + idmap->output_reference =3D cpu_to_le32(iommu_offset); + } else { + /* output IORT node is the ITS group node (the first node) */ + idmap->output_reference =3D cpu_to_le32(iort->node_offset); + } + + iort->length =3D cpu_to_le32(iort_length); =20 build_header(linker, table_data, (void *)(table_data->data + iort_star= t), "IORT", table_data->len - iort_start, 0, NULL, NULL); @@ -786,7 +827,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTa= bles *tables) =20 if (its_class_name() && !vmc->no_its) { acpi_add_table(table_offsets, tables_blob); - build_iort(tables_blob, tables->linker); + build_iort(tables_blob, tables->linker, vms); } =20 /* XSDT is pointed to by RSDP */ diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 5584109..ad5d7ea 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1027,6 +1027,11 @@ static void virtio_iommu_notifier(Notifier *notifier= , void *data) =20 object_property_set_bool(obj, false, "msi_bypass", &error_fatal); =20 + vms->iommu_info.type =3D VIRT_IOMMU_VIRTIO; + vms->iommu_info.reg.base =3D vms->memmap[VIRT_IOMMU].base; + vms->iommu_info.reg.size =3D vms->memmap[VIRT_IOMMU].size; + vms->iommu_info.irq_base =3D vms->irqmap[VIRT_IOMMU]; + qemu_fdt_setprop_cells(fdt, vms->pcie_host_nodename, "iommu-map", 0x0, vms->iommu_phandle, 0x0, 0x10000); } diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index 80c8099..dd8f806 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -673,7 +673,8 @@ enum { ACPI_IORT_NODE_NAMED_COMPONENT =3D 0x01, ACPI_IORT_NODE_PCI_ROOT_COMPLEX =3D 0x02, ACPI_IORT_NODE_SMMU =3D 0x03, - ACPI_IORT_NODE_SMMU_V3 =3D 0x04 + ACPI_IORT_NODE_SMMU_V3 =3D 0x04, + ACPI_IORT_NODE_PARAVIRT =3D 0x05 }; =20 struct AcpiIortIdMapping { @@ -700,6 +701,24 @@ struct AcpiIortItsGroup { } QEMU_PACKED; typedef struct AcpiIortItsGroup AcpiIortItsGroup; =20 +struct AcpiIortPVIommu { + ACPI_IORT_NODE_HEADER_DEF + uint64_t base_address; + uint64_t span; + uint32_t model; + uint32_t flags; + uint32_t interrupt_count; + uint64_t interrupts[1]; + AcpiIortIdMapping id_mapping_array[0]; +} QEMU_PACKED; +typedef struct AcpiIortPVIommu AcpiIortPVIommu; + +enum { + ACPI_IORT_NODE_PV_VIRTIO_IOMMU =3D 0x00, +}; + +#define ACPI_IORT_NODE_PV_CACHE_COHERENT (1 << 0) + struct AcpiIortRC { ACPI_IORT_NODE_HEADER_DEF AcpiIortMemoryAccess memory_properties; diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index a13b895..2e1e907 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -89,6 +89,18 @@ typedef struct { bool claim_edge_triggered_timers; } VirtMachineClass; =20 +typedef enum VirtIOMMUType { + VIRT_IOMMU_NONE, + VIRT_IOMMU_SMMUV3, + VIRT_IOMMU_VIRTIO, +} VirtIOMMUType; + +typedef struct VirtIOMMUInfo { + VirtIOMMUType type; + MemMapEntry reg; + int irq_base; +} VirtIOMMUInfo; + typedef struct { MachineState parent; Notifier machine_done; @@ -98,6 +110,7 @@ typedef struct { bool highmem; bool its; bool virt; + VirtIOMMUInfo iommu_info; int32_t gic_version; struct arm_boot_info bootinfo; const MemMapEntry *memmap; --=20 1.9.1