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 1533587311681653.154740798738; Mon, 6 Aug 2018 13:28:31 -0700 (PDT) Received: from localhost ([::1]:36173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmm7C-0000jS-6G for importer@patchew.org; Mon, 06 Aug 2018 16:28:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmlut-0006nS-67 for qemu-devel@nongnu.org; Mon, 06 Aug 2018 16:15:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmluo-00078F-W2 for qemu-devel@nongnu.org; Mon, 06 Aug 2018 16:15:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38200 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 1fmlum-00075h-1B; Mon, 06 Aug 2018 16:15:40 -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 8B6F540201A3; Mon, 6 Aug 2018 20:15:39 +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 0CA8E2156711; Mon, 6 Aug 2018 20:15:36 +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:43 +0200 Message-Id: <1533586484-5737-16-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.6]); Mon, 06 Aug 2018 20:15:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 06 Aug 2018 20:15:39 +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 15/16] 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, 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" This patch builds the virtio-iommu node in the ACPI IORT table. 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 | 39 ++++++++++++++++++++++++++++++++------- include/hw/acpi/acpi-defs.h | 21 ++++++++++++++++++++- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 6ea47e2..a856a31 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -403,14 +403,13 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vi= rtMachineState *vms) AcpiIortIdMapping *idmap; AcpiIortItsGroup *its; AcpiIortTable *iort; - AcpiIortSmmu3 *smmu; - size_t node_size, iort_node_offset, iort_length, smmu_offset =3D 0; + size_t node_size, iort_node_offset, iort_length, iommu_offset =3D 0; AcpiIortRC *rc; =20 iort =3D acpi_data_push(table_data, sizeof(*iort)); =20 - if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3) { - nb_nodes =3D 3; /* RC, ITS, SMMUv3 */ + if (vms->iommu) { + nb_nodes =3D 3; /* RC, ITS, IOMMU */ } else { nb_nodes =3D 2; /* RC, ITS */ } @@ -435,10 +434,11 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vi= rtMachineState *vms) its->identifiers[0] =3D 0; /* MADT translation_id */ =20 if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3) { + AcpiIortSmmu3 *smmu; int irq =3D vms->irqmap[VIRT_SMMU]; =20 /* SMMUv3 node */ - smmu_offset =3D iort_node_offset + node_size; + iommu_offset =3D iort_node_offset + node_size; node_size =3D sizeof(*smmu) + sizeof(*idmap); iort_length +=3D node_size; smmu =3D acpi_data_push(table_data, node_size); @@ -460,6 +460,31 @@ build_iort(GArray *table_data, BIOSLinker *linker, Vir= tMachineState *vms) 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); + } else if (vms->iommu =3D=3D VIRT_IOMMU_VIRTIO) { + AcpiIortPVIommu *iommu; + int irq =3D vms->irqmap[VIRT_VIRTIO_IOMMU]; + + /* Para-virtualized IOMMU node */ + iommu_offset =3D 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->memmap[VIRT_VIRTIO_IOMMU]= .base); + iommu->span =3D cpu_to_le64(vms->memmap[VIRT_VIRTIO_IOMMU].size); + iommu->model =3D ACPI_IORT_NODE_PV_VIRTIO_IOMMU; + iommu->flags =3D ACPI_IORT_NODE_PV_CACHE_COHERENT; + iommu->gsiv =3D cpu_to_le64(irq); + + /* 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); } =20 /* Root Complex Node */ @@ -483,9 +508,9 @@ build_iort(GArray *table_data, BIOSLinker *linker, Virt= MachineState *vms) idmap->id_count =3D cpu_to_le32(0xFFFF); idmap->output_base =3D 0; =20 - if (vms->iommu =3D=3D VIRT_IOMMU_SMMUV3) { + if (vms->iommu) { /* output IORT node is the smmuv3 node */ - idmap->output_reference =3D cpu_to_le32(smmu_offset); + 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); diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index af8e023..1046409 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -601,7 +601,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 0x80 }; =20 struct AcpiIortIdMapping { @@ -628,6 +629,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; + uint64_t gsiv; + uint64_t reserved2; + 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 AcpiIortSmmu3 { ACPI_IORT_NODE_HEADER_DEF uint64_t base_address; --=20 2.5.5