From nobody Mon Feb 9 07:55:26 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633452695711400.9786703554564; Tue, 5 Oct 2021 09:51:35 -0700 (PDT) Received: from localhost ([::1]:44298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mXnfC-00013q-Kb for importer@patchew.org; Tue, 05 Oct 2021 12:51:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47660) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXmuU-0001cp-DA for qemu-devel@nongnu.org; Tue, 05 Oct 2021 12:03:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mXmuS-0006LV-6W for qemu-devel@nongnu.org; Tue, 05 Oct 2021 12:03:18 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-505-t-xw3kU6NnehyYYEcBCdaA-1; Tue, 05 Oct 2021 12:03:14 -0400 Received: by mail-wm1-f69.google.com with SMTP id x23-20020a05600c21d700b0030d23749278so1502644wmj.2 for ; Tue, 05 Oct 2021 09:03:14 -0700 (PDT) Received: from redhat.com ([2.55.147.134]) by smtp.gmail.com with ESMTPSA id w5sm17949753wrq.86.2021.10.05.09.03.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Oct 2021 09:03:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633449795; 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=hLUEbIzvV2N7lkZsbc8CHTUdFKm2dW0+2UECt7Ns1Mg=; b=IvRFn+ab2w7QhgOwOOYQ3BU3wTCTqQKB9LFuPSfopXE4QoYCz3uzG06jDcd+SfU26LaInx LwOoMkz40Wp1lJTTXBH4uwNbr+BXuwk/9CKZuvGB01amFOfUoT+muXZoANgn4kdS0m1chN OLfbOb8VrNfDFGhb3cBR0fMlLrN6MqY= X-MC-Unique: t-xw3kU6NnehyYYEcBCdaA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=hLUEbIzvV2N7lkZsbc8CHTUdFKm2dW0+2UECt7Ns1Mg=; b=W5JayEaQFAhf2BX4vFHI9bi3By8kX+xN7moJ46sx0j3j1CHlWTw+LpvHfUGytmfSze P/FfVc7AyZEhMX88pYeecjFL0TvPexTRXKOwdvjVgvqilTxvLrWKCskp54mfIm1CWrxW 8bfeeWqoTmwiL+0ISlY4lhbM+CyBmwoGR7hi3+7BMaeXohvHbrYtEKQIrMV0FUZHnP7h MHmigmJy02xvBAsEgzFk0/CRCCy6eDxuRu/h5mCeu8Qm60VkBNOf54eWJfriMCP+AJE1 E+o2sA1pk2wi+VdfcF5f6fYdYJrThAQyDxNF929A++zahI6QA96ek9rKg4RuYIWXP/0k l5Yw== X-Gm-Message-State: AOAM531MueIJkVlHFuIrln0D6x2S+HkvoZ81IehWlxfGGwCOGNWnG4Zj bIkI9knYILLvNXtN//sYKaVqTA6+oGlIuCEas0pfrxKQrlHaUnRPMpEBldlmSg4fgfQBRswYPvv o7jt6x/wqjLM+N32ztN6vEYTtCnLJeICE3AQJ8rZNPGGwiOaACwgZlqgBe7Re X-Received: by 2002:a1c:ac03:: with SMTP id v3mr4304856wme.13.1633449791606; Tue, 05 Oct 2021 09:03:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5bB2qWqsinJXb5hSwh/qRQe85pV2uTw86JRI+TVr5jDKueiWM0ppy8BE0Q1Z40eICCqY07g== X-Received: by 2002:a1c:ac03:: with SMTP id v3mr4304590wme.13.1633449789282; Tue, 05 Oct 2021 09:03:09 -0700 (PDT) Date: Tue, 5 Oct 2021 12:03:02 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL 32/57] acpi: build_dmar_q35: use acpi_table_begin()/acpi_table_end() instead of build_header() Message-ID: <20211005155946.513818-33-mst@redhat.com> References: <20211005155946.513818-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20211005155946.513818-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.066, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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: Peter Maydell , Eduardo Habkost , Richard Henderson , Eric Auger , Igor Mammedov , Ani Sinha , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633452697867100001 From: Igor Mammedov it replaces error-prone pointer arithmetic for build_header() API, with 2 calls to start and finish table creation, which hides offsets magic from API user. While at it switch to build_append_int_noprefix() to build table entries tables. Signed-off-by: Igor Mammedov Reviewed-by: Eric Auger Message-Id: <20210924122802.1455362-19-imammedo@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/acpi/acpi-defs.h | 68 ----------------------------- hw/i386/acpi-build.c | 85 ++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 106 deletions(-) diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index d293304f9c..c4f0a202e8 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -358,74 +358,6 @@ struct AcpiGenericTimerTable { } QEMU_PACKED; typedef struct AcpiGenericTimerTable AcpiGenericTimerTable; =20 -/* DMAR - DMA Remapping table r2.2 */ -struct AcpiTableDmar { - ACPI_TABLE_HEADER_DEF - uint8_t host_address_width; /* Maximum DMA physical addressability */ - uint8_t flags; - uint8_t reserved[10]; -} QEMU_PACKED; -typedef struct AcpiTableDmar AcpiTableDmar; - -/* Masks for Flags field above */ -#define ACPI_DMAR_INTR_REMAP 1 -#define ACPI_DMAR_X2APIC_OPT_OUT (1 << 1) - -/* Values for sub-structure type for DMAR */ -enum { - ACPI_DMAR_TYPE_HARDWARE_UNIT =3D 0, /* DRHD */ - ACPI_DMAR_TYPE_RESERVED_MEMORY =3D 1, /* RMRR */ - ACPI_DMAR_TYPE_ATSR =3D 2, /* ATSR */ - ACPI_DMAR_TYPE_HARDWARE_AFFINITY =3D 3, /* RHSR */ - ACPI_DMAR_TYPE_ANDD =3D 4, /* ANDD */ - ACPI_DMAR_TYPE_RESERVED =3D 5 /* Reserved for furture use = */ -}; - -/* - * Sub-structures for DMAR - */ - -/* Device scope structure for DRHD. */ -struct AcpiDmarDeviceScope { - uint8_t entry_type; - uint8_t length; - uint16_t reserved; - uint8_t enumeration_id; - uint8_t bus; - struct { - uint8_t device; - uint8_t function; - } path[]; -} QEMU_PACKED; -typedef struct AcpiDmarDeviceScope AcpiDmarDeviceScope; - -/* Type 0: Hardware Unit Definition */ -struct AcpiDmarHardwareUnit { - uint16_t type; - uint16_t length; - uint8_t flags; - uint8_t reserved; - uint16_t pci_segment; /* The PCI Segment associated with this unit */ - uint64_t address; /* Base address of remapping hardware register-set= */ - AcpiDmarDeviceScope scope[]; -} QEMU_PACKED; -typedef struct AcpiDmarHardwareUnit AcpiDmarHardwareUnit; - -/* Type 2: Root Port ATS Capability Reporting Structure */ -struct AcpiDmarRootPortATS { - uint16_t type; - uint16_t length; - uint8_t flags; - uint8_t reserved; - uint16_t pci_segment; - AcpiDmarDeviceScope scope[]; -} QEMU_PACKED; -typedef struct AcpiDmarRootPortATS AcpiDmarRootPortATS; - -/* Masks for Flags field above */ -#define ACPI_DMAR_INCLUDE_PCI_ALL 1 -#define ACPI_DMAR_ATSR_ALL_PORTS 1 - /* * Input Output Remapping Table (IORT) * Conforms to "IO Remapping Table System Software on ARM Platforms", diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 078097a060..c65ab1d6a5 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2086,8 +2086,9 @@ build_srat(GArray *table_data, BIOSLinker *linker, Ma= chineState *machine) static void insert_scope(PCIBus *bus, PCIDevice *dev, void *opaque) { + const size_t device_scope_size =3D 6 /* device scope structure */ + + 2 /* 1 path entry */; GArray *scope_blob =3D opaque; - AcpiDmarDeviceScope *scope =3D NULL; =20 if (object_dynamic_cast(OBJECT(dev), TYPE_PCI_BRIDGE)) { /* Dmar Scope Type: 0x02 for PCI Bridge */ @@ -2098,8 +2099,7 @@ insert_scope(PCIBus *bus, PCIDevice *dev, void *opaqu= e) } =20 /* length */ - build_append_int_noprefix(scope_blob, - sizeof(*scope) + sizeof(scope->path[0]), 1); + build_append_int_noprefix(scope_blob, device_scope_size, 1); /* reserved */ build_append_int_noprefix(scope_blob, 0, 2); /* enumeration_id */ @@ -2131,26 +2131,26 @@ dmar_host_bridges(Object *obj, void *opaque) } =20 /* - * VT-d spec 8.1 DMA Remapping Reporting Structure - * (version Oct. 2014 or later) + * Intel =C2=AE Virtualization Technology for Directed I/O + * Architecture Specification. Revision 3.3 + * 8.1 DMA Remapping Reporting Structure */ static void build_dmar_q35(GArray *table_data, BIOSLinker *linker, const char *oem_id, const char *oem_table_id) { - int dmar_start =3D table_data->len; - - AcpiTableDmar *dmar; - AcpiDmarHardwareUnit *drhd; - AcpiDmarRootPortATS *atsr; uint8_t dmar_flags =3D 0; + uint8_t rsvd10[10] =3D {}; + /* Root complex IOAPIC uses one path only */ + const size_t ioapic_scope_size =3D 6 /* device scope structure */ + + 2 /* 1 path entry */; X86IOMMUState *iommu =3D x86_iommu_get_default(); - AcpiDmarDeviceScope *scope =3D NULL; - /* Root complex IOAPIC use one path[0] only */ - size_t ioapic_scope_size =3D sizeof(*scope) + sizeof(scope->path[0]); IntelIOMMUState *intel_iommu =3D INTEL_IOMMU_DEVICE(iommu); GArray *scope_blob =3D g_array_new(false, true, 1); =20 + AcpiTable table =3D { .sig =3D "DMAR", .rev =3D 1, .oem_id =3D oem_id, + .oem_table_id =3D oem_table_id }; + /* * A PCI bus walk, for each PCI host bridge. * Insert scope for each PCI bridge and endpoint device which @@ -2164,43 +2164,52 @@ build_dmar_q35(GArray *table_data, BIOSLinker *link= er, const char *oem_id, dmar_flags |=3D 0x1; /* Flags: 0x1: INT_REMAP */ } =20 - dmar =3D acpi_data_push(table_data, sizeof(*dmar)); - dmar->host_address_width =3D intel_iommu->aw_bits - 1; - dmar->flags =3D dmar_flags; + acpi_table_begin(&table, table_data); + /* Host Address Width */ + build_append_int_noprefix(table_data, intel_iommu->aw_bits - 1, 1); + build_append_int_noprefix(table_data, dmar_flags, 1); /* Flags */ + g_array_append_vals(table_data, rsvd10, sizeof(rsvd10)); /* Reserved */ =20 - /* DMAR Remapping Hardware Unit Definition structure */ - drhd =3D acpi_data_push(table_data, sizeof(*drhd) + ioapic_scope_size); - drhd->type =3D cpu_to_le16(ACPI_DMAR_TYPE_HARDWARE_UNIT); - drhd->length =3D - cpu_to_le16(sizeof(*drhd) + ioapic_scope_size + scope_blob->len); - drhd->flags =3D 0; /* Don't include all pci device */ - drhd->pci_segment =3D cpu_to_le16(0); - drhd->address =3D cpu_to_le64(Q35_HOST_BRIDGE_IOMMU_ADDR); + /* 8.3 DMAR Remapping Hardware Unit Definition structure */ + build_append_int_noprefix(table_data, 0, 2); /* Type */ + /* Length */ + build_append_int_noprefix(table_data, + 16 + ioapic_scope_size + scope_blob->len, 2); + /* Flags */ + build_append_int_noprefix(table_data, 0 /* Don't include all pci devic= e */ , + 1); + build_append_int_noprefix(table_data, 0 , 1); /* Reserved */ + build_append_int_noprefix(table_data, 0 , 2); /* Segment Number */ + /* Register Base Address */ + build_append_int_noprefix(table_data, Q35_HOST_BRIDGE_IOMMU_ADDR , 8); =20 /* Scope definition for the root-complex IOAPIC. See VT-d spec * 8.3.1 (version Oct. 2014 or later). */ - scope =3D &drhd->scope[0]; - scope->entry_type =3D 0x03; /* Type: 0x03 for IOAPIC */ - scope->length =3D ioapic_scope_size; - scope->enumeration_id =3D ACPI_BUILD_IOAPIC_ID; - scope->bus =3D Q35_PSEUDO_BUS_PLATFORM; - scope->path[0].device =3D PCI_SLOT(Q35_PSEUDO_DEVFN_IOAPIC); - scope->path[0].function =3D PCI_FUNC(Q35_PSEUDO_DEVFN_IOAPIC); + build_append_int_noprefix(table_data, 0x03 /* IOAPIC */, 1); /* Type */ + build_append_int_noprefix(table_data, ioapic_scope_size, 1); /* Length= */ + build_append_int_noprefix(table_data, 0, 2); /* Reserved */ + /* Enumeration ID */ + build_append_int_noprefix(table_data, ACPI_BUILD_IOAPIC_ID, 1); + /* Start Bus Number */ + build_append_int_noprefix(table_data, Q35_PSEUDO_BUS_PLATFORM, 1); + /* Path, {Device, Function} pair */ + build_append_int_noprefix(table_data, PCI_SLOT(Q35_PSEUDO_DEVFN_IOAPIC= ), 1); + build_append_int_noprefix(table_data, PCI_FUNC(Q35_PSEUDO_DEVFN_IOAPIC= ), 1); =20 /* Add scope found above */ g_array_append_vals(table_data, scope_blob->data, scope_blob->len); g_array_free(scope_blob, true); =20 if (iommu->dt_supported) { - atsr =3D acpi_data_push(table_data, sizeof(*atsr)); - atsr->type =3D cpu_to_le16(ACPI_DMAR_TYPE_ATSR); - atsr->length =3D cpu_to_le16(sizeof(*atsr)); - atsr->flags =3D ACPI_DMAR_ATSR_ALL_PORTS; - atsr->pci_segment =3D cpu_to_le16(0); + /* 8.5 Root Port ATS Capability Reporting Structure */ + build_append_int_noprefix(table_data, 2, 2); /* Type */ + build_append_int_noprefix(table_data, 8, 2); /* Length */ + build_append_int_noprefix(table_data, 1 /* ALL_PORTS */, 1); /* Fl= ags */ + build_append_int_noprefix(table_data, 0, 1); /* Reserved */ + build_append_int_noprefix(table_data, 0, 2); /* Segment Number */ } =20 - build_header(linker, table_data, (void *)(table_data->data + dmar_star= t), - "DMAR", table_data->len - dmar_start, 1, oem_id, oem_tabl= e_id); + acpi_table_end(linker, &table); } =20 /* --=20 MST