From nobody Sun May 5 12:52:55 2024 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543498050466178.06603601345807; Thu, 29 Nov 2018 05:27:30 -0800 (PST) Received: from localhost ([::1]:54138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMLo-0001XO-QP for importer@patchew.org; Thu, 29 Nov 2018 08:27:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMJf-0000Ba-95 for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSMJb-0001bd-7q for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:15 -0500 Received: from mga09.intel.com ([134.134.136.24]:31202) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSMJa-00019W-Rt; Thu, 29 Nov 2018 08:25:11 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:25:10 -0800 Received: from hharjula-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.29.114]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2018 05:25:05 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="97547175" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 14:24:21 +0100 Message-Id: <20181129132428.333-2-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129132428.333-1-sameo@linux.intel.com> References: <20181129132428.333-1-sameo@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.24 Subject: [Qemu-devel] [PATCH v2 1/8] hw: acpi: The RSDP build API can return void 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: Laurent Vivier , Peter Maydell , Thomas Huth , Eduardo Habkost , Ben Warren , "Michael S. Tsirkin" , Shannon Zhao , qemu-arm@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" For both x86 and ARM architectures, the internal RSDP build API can return void as the current return value is unused. Signed-off-by: Samuel Ortiz Reviewed-by: Igor Mammedov Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Thomas Huth Reviewed-by: Andrew Jones --- hw/arm/virt-acpi-build.c | 4 +--- hw/i386/acpi-build.c | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 5785fb697c..fcaa350892 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -367,7 +367,7 @@ static void acpi_dsdt_add_power_button(Aml *scope) } =20 /* RSDP */ -static GArray * +static void build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offse= t) { AcpiRsdpDescriptor *rsdp =3D acpi_data_push(rsdp_table, sizeof *rsdp); @@ -392,8 +392,6 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsi= gned xsdt_tbl_offset) bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, (char *)rsdp - rsdp_table->data, sizeof *rsdp, (char *)&rsdp->checksum - rsdp_table->data); - - return rsdp_table; } =20 static void diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 236a20eaa8..35f17d0d91 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2547,7 +2547,7 @@ build_amd_iommu(GArray *table_data, BIOSLinker *linke= r) "IVRS", table_data->len - iommu_start, 1, NULL, NULL); } =20 -static GArray * +static void build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offse= t) { AcpiRsdpDescriptor *rsdp =3D acpi_data_push(rsdp_table, sizeof *rsdp); @@ -2569,8 +2569,6 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, un= signed rsdt_tbl_offset) bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, (char *)rsdp - rsdp_table->data, sizeof *rsdp, (char *)&rsdp->checksum - rsdp_table->data); - - return rsdp_table; } =20 typedef --=20 2.19.2 From nobody Sun May 5 12:52:55 2024 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543498052857707.5097908430137; Thu, 29 Nov 2018 05:27:32 -0800 (PST) Received: from localhost ([::1]:54139 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMLr-0001ZD-62 for importer@patchew.org; Thu, 29 Nov 2018 08:27:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMJo-0000Fu-1M for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSMJj-0001oG-Ga for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:23 -0500 Received: from mga03.intel.com ([134.134.136.65]:30951) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSMJj-0001hj-6S; Thu, 29 Nov 2018 08:25:19 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:25:16 -0800 Received: from hharjula-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.29.114]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2018 05:25:10 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="97547186" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 14:24:22 +0100 Message-Id: <20181129132428.333-3-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129132428.333-1-sameo@linux.intel.com> References: <20181129132428.333-1-sameo@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v2 2/8] hw: arm: acpi: Fix incorrect checksums in RSDP 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: Laurent Vivier , Peter Maydell , Thomas Huth , Eduardo Habkost , Ben Warren , "Michael S. Tsirkin" , Ard Biesheuvel , Shannon Zhao , qemu-arm@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Igor Mammedov When RSDP table was introduced (d4bec5d87), we calculated only legacy checksum, and that was incorrect as it - specified rev=3D2 and forgot about extended checksum. - legacy checksum calculated on full table instead of the 1st 20 bytes Fix it by adding extended checksum calculation and using correct size for legacy checksum. While at it use explicit constants to specify sub/full tables sizes instead of relying on AcpiRsdpDescriptor size and fields offsets. The follow up commits will convert this table to build_append_int_noprefix(= ) API, will use constants anyway and remove unused AcpiRsdpDescriptor structure. Based on "[PATCH v5 05/24] hw: acpi: Implement XSDT support for RSDP" by Samuel Ortiz, who did it right in his impl. Fixes: d4bec5d87 (hw/arm/virt-acpi-build: Generate RSDP table) Signed-off-by: Igor Mammedov CC: Ard Biesheuvel CC: Shannon Zhao Reviewed-by: Samuel Ortiz Signed-off-by: Samuel Ortiz Reviewed-by: Andrew Jones --- hw/arm/virt-acpi-build.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index fcaa350892..0835900052 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -390,8 +390,13 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, uns= igned xsdt_tbl_offset) =20 /* Checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, - (char *)rsdp - rsdp_table->data, sizeof *rsdp, + (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */, (char *)&rsdp->checksum - rsdp_table->data); + + /* Extended checksum to be filled by Guest linker */ + bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, + (char *)rsdp - rsdp_table->data, 36 /* ACPI rev 2.0 RSDP size */, + (char *)&rsdp->extended_checksum - rsdp_table->data); } =20 static void --=20 2.19.2 From nobody Sun May 5 12:52:55 2024 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543498057906772.0081376831207; Thu, 29 Nov 2018 05:27:37 -0800 (PST) Received: from localhost ([::1]:54140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMLv-0001bo-Un for importer@patchew.org; Thu, 29 Nov 2018 08:27:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMJo-0000GL-Jp for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSMJl-0001pS-MN for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:24 -0500 Received: from mga03.intel.com ([134.134.136.65]:30951) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSMJl-0001hj-B3; Thu, 29 Nov 2018 08:25:21 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:25:20 -0800 Received: from hharjula-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.29.114]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2018 05:25:16 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="97547195" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 14:24:23 +0100 Message-Id: <20181129132428.333-4-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129132428.333-1-sameo@linux.intel.com> References: <20181129132428.333-1-sameo@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v2 3/8] hw: i386: Use correct RSDT length for checksum 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: Laurent Vivier , Peter Maydell , Thomas Huth , Eduardo Habkost , Ben Warren , "Michael S. Tsirkin" , Shannon Zhao , qemu-arm@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Igor Mammedov AcpiRsdpDescriptor describes revision 2 RSDP table so using sizeof(*rsdp) for checksum calculation isn't correct since we are adding extra 16 bytes. But acpi_data_push() zeroes out table, so just by luck we are summing up exta zeros which still yelds correct checksum. Fix it up by explicitly stating table size instead of using pointer arithmetics on stucture. PS: Extra 16 bytes are still wasted, but droping them will break migration for machines older than 2.3 due to size mismatch, for 2.3 and older it's not an issue since they are using resizable memory regions (a1666142d) for ACPI blobs. So keep wasting memory to avoid breaking old machines. Fixes: 72c194f7e (i386: ACPI table generation code from seabios) Signed-off-by: Igor Mammedov Reviewed-by: Samuel Ortiz Signed-off-by: Samuel Ortiz --- hw/i386/acpi-build.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 35f17d0d91..fb877648ac 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2550,6 +2550,11 @@ build_amd_iommu(GArray *table_data, BIOSLinker *link= er) static void build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offse= t) { + /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we + * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16= bytes + * wasted to make sure we won't breake migration for machine types old= er + * than 2.3 due to size mismatch. + */ AcpiRsdpDescriptor *rsdp =3D acpi_data_push(rsdp_table, sizeof *rsdp); unsigned rsdt_pa_size =3D sizeof(rsdp->rsdt_physical_address); unsigned rsdt_pa_offset =3D @@ -2567,7 +2572,7 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, un= signed rsdt_tbl_offset) =20 /* Checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, - (char *)rsdp - rsdp_table->data, sizeof *rsdp, + (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */, (char *)&rsdp->checksum - rsdp_table->data); } =20 --=20 2.19.2 From nobody Sun May 5 12:52:55 2024 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543498249195661.2712059024702; Thu, 29 Nov 2018 05:30:49 -0800 (PST) Received: from localhost ([::1]:54162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMOw-00048B-CM for importer@patchew.org; Thu, 29 Nov 2018 08:30:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMJr-0000KK-Kc for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSMJq-0001yk-Mo for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:27 -0500 Received: from mga03.intel.com ([134.134.136.65]:30951) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSMJq-0001hj-BG; Thu, 29 Nov 2018 08:25:26 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:25:25 -0800 Received: from hharjula-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.29.114]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2018 05:25:21 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="97547207" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 14:24:24 +0100 Message-Id: <20181129132428.333-5-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129132428.333-1-sameo@linux.intel.com> References: <20181129132428.333-1-sameo@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v2 4/8] hw: arm: Carry RSDP specific data through AcpiRsdpData 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: Laurent Vivier , Peter Maydell , Thomas Huth , Eduardo Habkost , Ben Warren , "Michael S. Tsirkin" , Shannon Zhao , qemu-arm@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" That will allow us to generalize the ARM build_rsdp() routine to support both legacy RSDP (The current i386 implementation) and extended RSDP (The ARM implementation). Signed-off-by: Samuel Ortiz Reviewed-by: Igor Mammedov --- include/hw/acpi/acpi-defs.h | 8 ++++++++ hw/arm/virt-acpi-build.c | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index af8e023968..8425ecb8c6 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -53,6 +53,14 @@ struct AcpiRsdpDescriptor { /* Root System Descri= ptor Pointer */ } QEMU_PACKED; typedef struct AcpiRsdpDescriptor AcpiRsdpDescriptor; =20 +typedef struct AcpiRsdpData { + uint8_t oem_id[6]; /* OEM identification */ + uint8_t revision; /* Must be 0 for 1.0, 2 for 2.0 */ + + unsigned *rsdt_tbl_offset; + unsigned *xsdt_tbl_offset; +} AcpiRsdpData; + /* Table structure from Linux kernel (the ACPI tables are under the BSD license) */ =20 diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 0835900052..ce8bfa5a37 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -368,7 +368,7 @@ static void acpi_dsdt_add_power_button(Aml *scope) =20 /* RSDP */ static void -build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offse= t) +build_rsdp(GArray *rsdp_table, BIOSLinker *linker, AcpiRsdpData *rsdp_data) { AcpiRsdpDescriptor *rsdp =3D acpi_data_push(rsdp_table, sizeof *rsdp); unsigned xsdt_pa_size =3D sizeof(rsdp->xsdt_physical_address); @@ -379,14 +379,14 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, un= signed xsdt_tbl_offset) true /* fseg memory */); =20 memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature)); - memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, sizeof(rsdp->oem_id)); + memcpy(rsdp->oem_id, rsdp_data->oem_id, sizeof(rsdp->oem_id)); rsdp->length =3D cpu_to_le32(sizeof(*rsdp)); - rsdp->revision =3D 0x02; + rsdp->revision =3D rsdp_data->revision; =20 /* Address to be filled by Guest linker */ bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, xsdt_pa_offset, xsdt_pa_size, - ACPI_BUILD_TABLE_FILE, xsdt_tbl_offset); + ACPI_BUILD_TABLE_FILE, *rsdp_data->xsdt_tbl_offset); =20 /* Checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, @@ -857,7 +857,15 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildT= ables *tables) build_xsdt(tables_blob, tables->linker, table_offsets, NULL, NULL); =20 /* RSDP is in FSEG memory, so allocate it separately */ - build_rsdp(tables->rsdp, tables->linker, xsdt); + { + AcpiRsdpData rsdp_data =3D { + .revision =3D 2, + .oem_id =3D ACPI_BUILD_APPNAME6, + .xsdt_tbl_offset =3D &xsdt, + .rsdt_tbl_offset =3D NULL, + }; + build_rsdp(tables->rsdp, tables->linker, &rsdp_data); + } =20 /* Cleanup memory that's no longer used. */ g_array_free(table_offsets, true); --=20 2.19.2 From nobody Sun May 5 12:52:55 2024 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154349832590936.626729436804; Thu, 29 Nov 2018 05:32:05 -0800 (PST) Received: from localhost ([::1]:54171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMQG-00054l-ND for importer@patchew.org; Thu, 29 Nov 2018 08:32:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58814) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMK0-0000Yt-B7 for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSMJv-000260-Ew for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:36 -0500 Received: from mga03.intel.com ([134.134.136.65]:30951) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSMJv-0001hj-1C; Thu, 29 Nov 2018 08:25:31 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:25:30 -0800 Received: from hharjula-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.29.114]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2018 05:25:26 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="97547215" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 14:24:25 +0100 Message-Id: <20181129132428.333-6-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129132428.333-1-sameo@linux.intel.com> References: <20181129132428.333-1-sameo@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v2 5/8] hw: arm: Convert the RSDP build to the buid_append_foo() API 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: Laurent Vivier , Peter Maydell , Thomas Huth , Eduardo Habkost , Ben Warren , "Michael S. Tsirkin" , Shannon Zhao , qemu-arm@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of filling a mapped and packed C structure field in random order and being careful about endianness and sizes, build_rsdp() now uses build_append_int_noprefix() to compose RSDP table. This makes for an easier to review and maintain code that is almost matching 1:1 the ACPI spec itself. Signed-off-by: Samuel Ortiz Reviewed-by: Andrew Jones --- hw/arm/virt-acpi-build.c | 42 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index ce8bfa5a37..4782aea4fe 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -368,35 +368,37 @@ static void acpi_dsdt_add_power_button(Aml *scope) =20 /* RSDP */ static void -build_rsdp(GArray *rsdp_table, BIOSLinker *linker, AcpiRsdpData *rsdp_data) +build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data) { - AcpiRsdpDescriptor *rsdp =3D acpi_data_push(rsdp_table, sizeof *rsdp); - unsigned xsdt_pa_size =3D sizeof(rsdp->xsdt_physical_address); - unsigned xsdt_pa_offset =3D - (char *)&rsdp->xsdt_physical_address - rsdp_table->data; - - bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16, + bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16, true /* fseg memory */); =20 - memcpy(&rsdp->signature, "RSD PTR ", sizeof(rsdp->signature)); - memcpy(rsdp->oem_id, rsdp_data->oem_id, sizeof(rsdp->oem_id)); - rsdp->length =3D cpu_to_le32(sizeof(*rsdp)); - rsdp->revision =3D rsdp_data->revision; + g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */ + build_append_int_noprefix(tbl, 0, 1); /* Checksum */ + g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */ + build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */ + build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */ + build_append_int_noprefix(tbl, 36, 4); /* Length */ =20 - /* Address to be filled by Guest linker */ - bios_linker_loader_add_pointer(linker, - ACPI_BUILD_RSDP_FILE, xsdt_pa_offset, xsdt_pa_size, - ACPI_BUILD_TABLE_FILE, *rsdp_data->xsdt_tbl_offset); + /* XSDT address to be filled by guest linker */ + build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */ + bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, + 24, 8, + ACPI_BUILD_TABLE_FILE, + *rsdp_data->xsdt_tbl_offset); =20 - /* Checksum to be filled by Guest linker */ + build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */ + build_append_int_noprefix(tbl, 0, 3); /* Reserved */ + + /* Checksum to be filled by guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, - (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */, - (char *)&rsdp->checksum - rsdp_table->data); + 0, 20, /* ACPI rev 1.0 RSDP size */ + 8); =20 /* Extended checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, - (char *)rsdp - rsdp_table->data, 36 /* ACPI rev 2.0 RSDP size */, - (char *)&rsdp->extended_checksum - rsdp_table->data); + 0, 36, /* ACPI rev 2.0 RSDP size */ + 32); } =20 static void --=20 2.19.2 From nobody Sun May 5 12:52:55 2024 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543498487850615.1399350458328; Thu, 29 Nov 2018 05:34:47 -0800 (PST) Received: from localhost ([::1]:54185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMSs-0007Ym-1B for importer@patchew.org; Thu, 29 Nov 2018 08:34:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMK1-0000a7-U3 for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSMK0-0002OQ-FH for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:37 -0500 Received: from mga03.intel.com ([134.134.136.65]:30951) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSMK0-0001hj-2P; Thu, 29 Nov 2018 08:25:36 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:25:35 -0800 Received: from hharjula-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.29.114]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2018 05:25:30 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="97547217" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 14:24:26 +0100 Message-Id: <20181129132428.333-7-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129132428.333-1-sameo@linux.intel.com> References: <20181129132428.333-1-sameo@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v2 6/8] hw: arm: Support both legacy and current RSDP build 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: Laurent Vivier , Peter Maydell , Thomas Huth , Eduardo Habkost , Ben Warren , "Michael S. Tsirkin" , Shannon Zhao , qemu-arm@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We add the ability to build legacy or current RSDP tables, based on the AcpiRsdpData revision field passed to build_rsdp(). Although arm/virt only uses RSDP v2, adding that capability to build_rsdp will allow us to share the RSDP build code between ARM and x86. Signed-off-by: Samuel Ortiz Reviewed-by: Igor Mammedov --- hw/arm/virt-acpi-build.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index 4782aea4fe..e1338b6f5a 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -378,23 +378,38 @@ build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpD= ata *rsdp_data) g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */ build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */ build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */ - build_append_int_noprefix(tbl, 36, 4); /* Length */ - - /* XSDT address to be filled by guest linker */ - build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */ - bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, - 24, 8, - ACPI_BUILD_TABLE_FILE, - *rsdp_data->xsdt_tbl_offset); - - build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */ - build_append_int_noprefix(tbl, 0, 3); /* Reserved */ + if (rsdp_data->rsdt_tbl_offset) { + /* RSDT address to be filled by guest linker */ + bios_linker_loader_add_pointer(linker, + ACPI_BUILD_RSDP_FILE, 16, 4, + ACPI_BUILD_TABLE_FILE, + *rsdp_data->rsdt_tbl_offset); + } =20 /* Checksum to be filled by guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, 0, 20, /* ACPI rev 1.0 RSDP size */ 8); =20 + if (rsdp_data->revision =3D=3D 0) { + /* ACPI 1.0 RSDP, we're done */ + return; + } + + /* The RSDP revision is 2 and later, we must have an XSDT pointer */ + g_assert(rsdp_data->xsdt_tbl_offset !=3D NULL); + + build_append_int_noprefix(tbl, 36, 4); /* Length */ + + /* XSDT address to be filled by guest linker */ + build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */ + bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, 24, 8, + ACPI_BUILD_TABLE_FILE, + *rsdp_data->xsdt_tbl_offset); + + build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */ + build_append_int_noprefix(tbl, 0, 3); /* Reserved */ + /* Extended checksum to be filled by Guest linker */ bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, 0, 36, /* ACPI rev 2.0 RSDP size */ --=20 2.19.2 From nobody Sun May 5 12:52:55 2024 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 154349821632013.640402673649078; Thu, 29 Nov 2018 05:30:16 -0800 (PST) Received: from localhost ([::1]:54158 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMOU-0003ow-C7 for importer@patchew.org; Thu, 29 Nov 2018 08:30:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMKA-0000gl-O2 for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSMK5-0002Rn-F5 for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:44 -0500 Received: from mga03.intel.com ([134.134.136.65]:30951) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSMK4-0001hj-KZ; Thu, 29 Nov 2018 08:25:41 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:25:40 -0800 Received: from hharjula-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.29.114]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2018 05:25:35 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="97547231" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 14:24:27 +0100 Message-Id: <20181129132428.333-8-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129132428.333-1-sameo@linux.intel.com> References: <20181129132428.333-1-sameo@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v2 7/8] hw: acpi: Export and share the ARM RSDP build 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: Laurent Vivier , Peter Maydell , Thomas Huth , Eduardo Habkost , Ben Warren , "Michael S. Tsirkin" , Shannon Zhao , qemu-arm@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Now that build_rsdp() supports building both legacy and current RSDP tables, we can move it to a generic folder (hw/acpi) and have the i386 ACPI code reuse it in order to reduce code duplication. Signed-off-by: Samuel Ortiz Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Andrew Jones Reviewed-by: Igor Mammedov --- include/hw/acpi/aml-build.h | 2 ++ hw/acpi/aml-build.c | 50 +++++++++++++++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 50 ------------------------------------- hw/i386/acpi-build.c | 39 +++++++---------------------- 4 files changed, 61 insertions(+), 80 deletions(-) diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 6c36903c0a..1a563ad756 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -388,6 +388,8 @@ void acpi_add_table(GArray *table_offsets, GArray *tabl= e_data); void acpi_build_tables_init(AcpiBuildTables *tables); void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre); void +build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data); +void build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, const char *oem_id, const char *oem_table_id); void diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 1e43cd736d..3d5f77e02b 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1589,6 +1589,56 @@ void acpi_build_tables_cleanup(AcpiBuildTables *tabl= es, bool mfre) g_array_free(tables->vmgenid, mfre); } =20 +/* RSDP */ +void +build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data) +{ + bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16, + true /* fseg memory */); + + g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */ + build_append_int_noprefix(tbl, 0, 1); /* Checksum */ + g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */ + build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */ + build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */ + if (rsdp_data->rsdt_tbl_offset) { + /* RSDT address to be filled by guest linker */ + bios_linker_loader_add_pointer(linker, + ACPI_BUILD_RSDP_FILE, 16, 4, + ACPI_BUILD_TABLE_FILE, + *rsdp_data->rsdt_tbl_offset); + } + + /* Checksum to be filled by guest linker */ + bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, + 0, 20, /* ACPI rev 1.0 RSDP size */ + 8); + + if (rsdp_data->revision =3D=3D 0) { + /* ACPI 1.0 RSDP, we're done */ + return; + } + + /* The RSDP revision is 2 and later, we must have an XSDT pointer */ + g_assert(rsdp_data->xsdt_tbl_offset !=3D NULL); + + build_append_int_noprefix(tbl, 36, 4); /* Length */ + + /* XSDT address to be filled by guest linker */ + build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */ + bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, 24, 8, + ACPI_BUILD_TABLE_FILE, + *rsdp_data->xsdt_tbl_offset); + + build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */ + build_append_int_noprefix(tbl, 0, 3); /* Reserved */ + + /* Extended checksum to be filled by Guest linker */ + bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, + 0, 36, /* ACPI rev 2.0 RSDP size */ + 32); +} + /* Build rsdt table */ void build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets, diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c index e1338b6f5a..95fad6f0ce 100644 --- a/hw/arm/virt-acpi-build.c +++ b/hw/arm/virt-acpi-build.c @@ -366,56 +366,6 @@ static void acpi_dsdt_add_power_button(Aml *scope) aml_append(scope, dev); } =20 -/* RSDP */ -static void -build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data) -{ - bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, tbl, 16, - true /* fseg memory */); - - g_array_append_vals(tbl, "RSD PTR ", 8); /* Signature */ - build_append_int_noprefix(tbl, 0, 1); /* Checksum */ - g_array_append_vals(tbl, rsdp_data->oem_id, 6); /* OEMID */ - build_append_int_noprefix(tbl, rsdp_data->revision, 1); /* Revision */ - build_append_int_noprefix(tbl, 0, 4); /* RsdtAddress */ - if (rsdp_data->rsdt_tbl_offset) { - /* RSDT address to be filled by guest linker */ - bios_linker_loader_add_pointer(linker, - ACPI_BUILD_RSDP_FILE, 16, 4, - ACPI_BUILD_TABLE_FILE, - *rsdp_data->rsdt_tbl_offset); - } - - /* Checksum to be filled by guest linker */ - bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, - 0, 20, /* ACPI rev 1.0 RSDP size */ - 8); - - if (rsdp_data->revision =3D=3D 0) { - /* ACPI 1.0 RSDP, we're done */ - return; - } - - /* The RSDP revision is 2 and later, we must have an XSDT pointer */ - g_assert(rsdp_data->xsdt_tbl_offset !=3D NULL); - - build_append_int_noprefix(tbl, 36, 4); /* Length */ - - /* XSDT address to be filled by guest linker */ - build_append_int_noprefix(tbl, 0, 8); /* XsdtAddress */ - bios_linker_loader_add_pointer(linker, ACPI_BUILD_RSDP_FILE, 24, 8, - ACPI_BUILD_TABLE_FILE, - *rsdp_data->xsdt_tbl_offset); - - build_append_int_noprefix(tbl, 0, 1); /* Extended Checksum */ - build_append_int_noprefix(tbl, 0, 3); /* Reserved */ - - /* Extended checksum to be filled by Guest linker */ - bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, - 0, 36, /* ACPI rev 2.0 RSDP size */ - 32); -} - static void build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) { diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index fb877648ac..528a5fd4ed 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2547,35 +2547,6 @@ build_amd_iommu(GArray *table_data, BIOSLinker *link= er) "IVRS", table_data->len - iommu_start, 1, NULL, NULL); } =20 -static void -build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned rsdt_tbl_offse= t) -{ - /* AcpiRsdpDescriptor describes revision 2 RSDP table and as result we - * allocate extra 16 bytes for pc/q35 RSDP rev1 as well. Keep extra 16= bytes - * wasted to make sure we won't breake migration for machine types old= er - * than 2.3 due to size mismatch. - */ - AcpiRsdpDescriptor *rsdp =3D acpi_data_push(rsdp_table, sizeof *rsdp); - unsigned rsdt_pa_size =3D sizeof(rsdp->rsdt_physical_address); - unsigned rsdt_pa_offset =3D - (char *)&rsdp->rsdt_physical_address - rsdp_table->data; - - bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, rsdp_table, 16, - true /* fseg memory */); - - memcpy(&rsdp->signature, "RSD PTR ", 8); - memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6); - /* Address to be filled by Guest linker */ - bios_linker_loader_add_pointer(linker, - ACPI_BUILD_RSDP_FILE, rsdt_pa_offset, rsdt_pa_size, - ACPI_BUILD_TABLE_FILE, rsdt_tbl_offset); - - /* Checksum to be filled by Guest linker */ - bios_linker_loader_add_checksum(linker, ACPI_BUILD_RSDP_FILE, - (char *)rsdp - rsdp_table->data, 20 /* ACPI rev 1.0 RSDP size */, - (char *)&rsdp->checksum - rsdp_table->data); -} - typedef struct AcpiBuildState { /* Copy of table in RAM (for patching). */ @@ -2732,7 +2703,15 @@ void acpi_build(AcpiBuildTables *tables, MachineStat= e *machine) slic_oem.id, slic_oem.table_id); =20 /* RSDP is in FSEG memory, so allocate it separately */ - build_rsdp(tables->rsdp, tables->linker, rsdt); + { + AcpiRsdpData rsdp_data =3D { + .revision =3D 0, + .oem_id =3D ACPI_BUILD_APPNAME6, + .xsdt_tbl_offset =3D NULL, + .rsdt_tbl_offset =3D &rsdt, + }; + build_rsdp(tables->rsdp, tables->linker, &rsdp_data); + } =20 /* We'll expose it all to Guest so we want to reduce * chance of size changes. --=20 2.19.2 From nobody Sun May 5 12:52:55 2024 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=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1543498486054167.72176006888571; Thu, 29 Nov 2018 05:34:46 -0800 (PST) Received: from localhost ([::1]:54184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMSq-0007XJ-Qw for importer@patchew.org; Thu, 29 Nov 2018 08:34:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59002) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSMKG-0000li-Jk for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSMKC-0002q2-Qp for qemu-devel@nongnu.org; Thu, 29 Nov 2018 08:25:52 -0500 Received: from mga03.intel.com ([134.134.136.65]:30951) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gSMKB-0001hj-0d; Thu, 29 Nov 2018 08:25:48 -0500 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 05:25:44 -0800 Received: from hharjula-mobl.ger.corp.intel.com (HELO localhost.localdomain) ([10.252.29.114]) by fmsmga008.fm.intel.com with ESMTP; 29 Nov 2018 05:25:40 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,294,1539673200"; d="scan'208";a="97547241" From: Samuel Ortiz To: qemu-devel@nongnu.org Date: Thu, 29 Nov 2018 14:24:28 +0100 Message-Id: <20181129132428.333-9-sameo@linux.intel.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181129132428.333-1-sameo@linux.intel.com> References: <20181129132428.333-1-sameo@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v2 8/8] hw: acpi: Remove AcpiRsdpDescriptor and fix tests 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: Laurent Vivier , Peter Maydell , Thomas Huth , Eduardo Habkost , Ben Warren , "Michael S. Tsirkin" , Shannon Zhao , qemu-arm@nongnu.org, Igor Mammedov , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The only remaining AcpiRsdpDescriptor users are the ACPI utils for the BIOS table tests. We remove that dependency and can thus remove the structure itself. Signed-off-by: Samuel Ortiz --- include/hw/acpi/acpi-defs.h | 13 ----------- tests/acpi-utils.h | 5 +++- tests/acpi-utils.c | 46 ++++++++++++++++++++++++++++++------- tests/bios-tables-test.c | 27 +++++++++++++++------- tests/vmgenid-test.c | 8 ++++--- 5 files changed, 66 insertions(+), 33 deletions(-) diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h index 8425ecb8c6..5021cb9e79 100644 --- a/include/hw/acpi/acpi-defs.h +++ b/include/hw/acpi/acpi-defs.h @@ -40,19 +40,6 @@ enum { ACPI_FADT_F_LOW_POWER_S0_IDLE_CAPABLE, }; =20 -struct AcpiRsdpDescriptor { /* Root System Descriptor Pointer */ - uint64_t signature; /* ACPI signature, contains "RSD PTR = " */ - uint8_t checksum; /* To make sum of struct =3D=3D 0 */ - uint8_t oem_id [6]; /* OEM identification */ - uint8_t revision; /* Must be 0 for 1.0, 2 for 2.0 */ - uint32_t rsdt_physical_address; /* 32-bit physical address of RSDT */ - uint32_t length; /* XSDT Length in bytes including hdr= */ - uint64_t xsdt_physical_address; /* 64-bit physical address of XSDT */ - uint8_t extended_checksum; /* Checksum of entire table */ - uint8_t reserved [3]; /* Reserved field must be 0 */ -} QEMU_PACKED; -typedef struct AcpiRsdpDescriptor AcpiRsdpDescriptor; - typedef struct AcpiRsdpData { uint8_t oem_id[6]; /* OEM identification */ uint8_t revision; /* Must be 0 for 1.0, 2 for 2.0 */ diff --git a/tests/acpi-utils.h b/tests/acpi-utils.h index ac52abd0dd..c26c8976a6 100644 --- a/tests/acpi-utils.h +++ b/tests/acpi-utils.h @@ -82,6 +82,9 @@ typedef struct { =20 uint8_t acpi_calc_checksum(const uint8_t *data, int len); uint32_t acpi_find_rsdp_address(void); -void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table); +uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table); +uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table); +void acpi_parse_rsdp_table(uint32_t addr, uint8_t *rsdp_table, + uint8_t revision); =20 #endif /* TEST_ACPI_UTILS_H */ diff --git a/tests/acpi-utils.c b/tests/acpi-utils.c index 41dc1ea9b4..b1113bda8b 100644 --- a/tests/acpi-utils.c +++ b/tests/acpi-utils.c @@ -52,14 +52,44 @@ uint32_t acpi_find_rsdp_address(void) return off; } =20 -void acpi_parse_rsdp_table(uint32_t addr, AcpiRsdpDescriptor *rsdp_table) +uint32_t acpi_get_rsdt_address(uint8_t *rsdp_table) { - ACPI_READ_FIELD(rsdp_table->signature, addr); - ACPI_ASSERT_CMP64(rsdp_table->signature, "RSD PTR "); + uint32_t rsdt_physical_address; + uint8_t revision =3D rsdp_table[15 /* Revision offset */]; =20 - ACPI_READ_FIELD(rsdp_table->checksum, addr); - ACPI_READ_ARRAY(rsdp_table->oem_id, addr); - ACPI_READ_FIELD(rsdp_table->revision, addr); - ACPI_READ_FIELD(rsdp_table->rsdt_physical_address, addr); - ACPI_READ_FIELD(rsdp_table->length, addr); + if (revision !=3D 0) { /* ACPI 1.0 RSDP */ + return 0; + } + + memcpy(&rsdt_physical_address, &rsdp_table[16 /* RsdtAddress offset */= ], 4); + return le32_to_cpu(rsdt_physical_address); +} + +uint64_t acpi_get_xsdt_address(uint8_t *rsdp_table) +{ + uint64_t xsdt_physical_address; + uint8_t revision =3D rsdp_table[15 /* Revision offset */]; + + if (revision !=3D 2) { /* ACPI 2.0+ RSDP */ + return 0; + } + + memcpy(&xsdt_physical_address, &rsdp_table[24 /* XsdtAddress offset */= ], 8); + return le64_to_cpu(xsdt_physical_address); +} + +void acpi_parse_rsdp_table(uint32_t addr, uint8_t *rsdp_table, uint8_t rev= ision) +{ + switch (revision) { + case 0: /* ACPI 1.0 RSDP */ + memread(addr, rsdp_table, 20); + break; + case 2: /* ACPI 2.0+ RSDP */ + memread(addr, rsdp_table, 36); + break; + default: + g_assert_not_reached(); + } + + ACPI_ASSERT_CMP64(*((uint64_t *)(rsdp_table)), "RSD PTR "); } diff --git a/tests/bios-tables-test.c b/tests/bios-tables-test.c index d661d9be62..84f1500920 100644 --- a/tests/bios-tables-test.c +++ b/tests/bios-tables-test.c @@ -27,7 +27,8 @@ typedef struct { const char *machine; const char *variant; uint32_t rsdp_addr; - AcpiRsdpDescriptor rsdp_table; + uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */]; + uint32_t rsdt_physical_address; AcpiRsdtDescriptorRev1 rsdt_table; uint32_t dsdt_addr; uint32_t facs_addr; @@ -83,21 +84,31 @@ static void test_acpi_rsdp_address(test_data *data) data->rsdp_addr =3D off; } =20 -static void test_acpi_rsdp_table(test_data *data) +static void test_acpi_rsdp_table(test_data *data, uint8_t revision) { - AcpiRsdpDescriptor *rsdp_table =3D &data->rsdp_table; + uint8_t *rsdp_table =3D data->rsdp_table; uint32_t addr =3D data->rsdp_addr; =20 - acpi_parse_rsdp_table(addr, rsdp_table); + acpi_parse_rsdp_table(addr, rsdp_table, revision); =20 - /* rsdp checksum is not for the whole table, but for the first 20 byte= s */ - g_assert(!acpi_calc_checksum((uint8_t *)rsdp_table, 20)); + switch (revision) { + case 0: /* ACPI 1.0 RSDP */ + /* With rev 1, checksum is only for the first 20 bytes */ + g_assert(!acpi_calc_checksum(rsdp_table, 20)); + break; + case 2: /* ACPI 2.0+ RSDP */ + /* With revision 2, we have 2 checksums */ + g_assert(!acpi_calc_checksum(rsdp_table, 20)); + g_assert(!acpi_calc_checksum(rsdp_table, 36)); + default: + g_assert_not_reached(); + } } =20 static void test_acpi_rsdt_table(test_data *data) { AcpiRsdtDescriptorRev1 *rsdt_table =3D &data->rsdt_table; - uint32_t addr =3D le32_to_cpu(data->rsdp_table.rsdt_physical_address); + uint32_t addr =3D acpi_get_rsdt_address(data->rsdp_table); uint32_t *tables; int tables_nr; uint8_t checksum; @@ -626,7 +637,7 @@ static void test_acpi_one(const char *params, test_data= *data) =20 data->tables =3D g_array_new(false, true, sizeof(AcpiSdtTable)); test_acpi_rsdp_address(data); - test_acpi_rsdp_table(data); + test_acpi_rsdp_table(data, 0); /* ACPI 1.0 RSDP */ test_acpi_rsdt_table(data); fadt_fetch_facs_and_dsdt_ptrs(data); test_acpi_facs_table(data); diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c index 0a6fb55f2e..5f30dee059 100644 --- a/tests/vmgenid-test.c +++ b/tests/vmgenid-test.c @@ -35,7 +35,7 @@ static uint32_t acpi_find_vgia(void) { uint32_t rsdp_offset; uint32_t guid_offset =3D 0; - AcpiRsdpDescriptor rsdp_table; + uint8_t rsdp_table[36 /* ACPI 2.0+ RSDP size */]; uint32_t rsdt, rsdt_table_length; AcpiRsdtDescriptorRev1 rsdt_table; size_t tables_nr; @@ -52,9 +52,11 @@ static uint32_t acpi_find_vgia(void) =20 g_assert_cmphex(rsdp_offset, <, RSDP_ADDR_INVALID); =20 - acpi_parse_rsdp_table(rsdp_offset, &rsdp_table); + acpi_parse_rsdp_table(rsdp_offset, rsdp_table, 0); + + rsdt =3D acpi_get_rsdt_address(rsdp_table); + g_assert(rsdt); =20 - rsdt =3D le32_to_cpu(rsdp_table.rsdt_physical_address); /* read the header */ ACPI_READ_TABLE_HEADER(&rsdt_table, rsdt); ACPI_ASSERT_CMP(rsdt_table.signature, "RSDT"); --=20 2.19.2