From nobody Sun Apr 28 16:04:34 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; dkim=fail spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1490773836003783.2212932374246; Wed, 29 Mar 2017 00:50:36 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C6E9B21DFA7BE; Wed, 29 Mar 2017 00:50:34 -0700 (PDT) Received: from mail-pg0-x243.google.com (mail-pg0-x243.google.com [IPv6:2607:f8b0:400e:c05::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2CF42208F7A03 for ; Wed, 29 Mar 2017 00:50:34 -0700 (PDT) Received: by mail-pg0-x243.google.com with SMTP id 79so1680686pgf.0 for ; Wed, 29 Mar 2017 00:50:34 -0700 (PDT) Received: from localhost.localdomain ([118.82.182.58]) by smtp.gmail.com with ESMTPSA id q23sm11629946pfg.63.2017.03.29.00.50.29 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 29 Mar 2017 00:50:33 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philjordan-eu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jqcT2uI0HPi3g0jvuJ/ZdE1vZ7lFQ42R30aqnBhVOKw=; b=sOBzj8AE9Tmqq2bNlu+gnDTyR8Pcvu3m+SrrU+HdOABwDWDvJyflVLO9ZPbkV7b2z3 hBjwmoGmi6LS3QxtdRf8nFaC4/UoRtYGHKCv9Tx6LGI44fgJUr2r92ZExisKJ+TgcLga j5AxgrDP26ZblrBjj4Qs/w2gbSbF9B8Fhy070qlPdoDTAKiEh+y2lJNn6Mfp0bg3u21Q 4tcGRKaFo83D/vfAzbIOwEbE8GHDuUlHS52m/ZWqHhqGClPUTyYTKjFHXLLmtHHEwl1p Hf1PRzSgOuXpDOxfjmElCc/vOnCuGaUc7AW4nnqyedIRTHYHRJNjfsxFtvJcHO6xYDwn e3bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jqcT2uI0HPi3g0jvuJ/ZdE1vZ7lFQ42R30aqnBhVOKw=; b=b7vvRAPnxPTsGMlE9z4xMNsyPLxp7CpUyOWwBYA+/q5riv5hBDX54clrCEfjNe2Bot MvHx72NMs6QDFkT+eORAeBE9nvfNNkLyPDQ4O4ZVcJxfqPj1Cn8KmHh9a8r/qjPf2yu1 +0nsx0yXxCXI+wnjXPf1M8E5BrN9Wd+5pecytAsQ8s9+d/DQaJl7vDm/JLO70TnooJ5E u5S6wadnxi/UesCjSedAstWxTeXSZrQZE5j8w+L9uRumm9Wg+RzrS+L+Mw6guSVm7Dex GxUZFH762xO4U6jjvqGodM/CJhDSh25BPDv6O3xEZT0Llupz/3uUgDOS6KBd+CXVIqgF yAew== X-Gm-Message-State: AFeK/H0s8V/ozNuU4ez9i2z6shezPmMay6/fK4KqfQhGXqY+I5HNqs7746iBl0kn1sUTBQ== X-Received: by 10.99.224.69 with SMTP id n5mr33778807pgj.113.1490773833711; Wed, 29 Mar 2017 00:50:33 -0700 (PDT) From: Phil Dennis-Jordan To: edk2-devel@lists.01.org Date: Wed, 29 Mar 2017 20:50:12 +1300 Message-Id: <1490773812-23839-2-git-send-email-lists@philjordan.eu> X-Mailer: git-send-email 2.3.2 (Apple Git-55) In-Reply-To: <1490773812-23839-1-git-send-email-lists@philjordan.eu> References: <1490773812-23839-1-git-send-email-lists@philjordan.eu> Subject: [edk2] [PATCH v1 1/1] OvmfPkg: Allow multiple add-pointer linker commands to same ACPI table X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Phil Dennis-Jordan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Phil Dennis-Jordan ACPI tables may contain multiple pointer fields to the same destination table. For example, in some revisions, the FADT contains both DSDT and X_DSDT fields, and they may both point to the DSDT. Indeed, some operating systems demand this to be the case. Previously, if Qemu created "add pointer" linker commands for both fields, the linking process would fail, as AcpiProtocol->InstallAcpiTable() may only be called once for each destination table and otherwise returns an error. This change adds a memoisation data structure which tracks the table pointers that have already been installed; even if the same pointer is encountered multiple times, it is only installed once. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Phil Dennis-Jordan --- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c | 109 ++++++++++++++++---- 1 file changed, 89 insertions(+), 20 deletions(-) diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c b/OvmfPkg/AcpiPlatform= Dxe/QemuFwCfgAcpi.c index 7bb2e3f21821..cffa838623cc 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c @@ -100,6 +100,39 @@ BlobCompare ( =20 =20 /** + Comparator function for two opaque pointers, ordering on pointer value + itself. + Can be used as both Key and UserStruct comparator. + + @param[in] Pointer1 First pointer. + + @param[in] Pointer2 Second pointer. + + @retval <0 If Pointer1 compares less than Pointer2. + + @retval 0 If Pointer1 compares equal to Pointer2. + + @retval >0 If Pointer1 compares greater than Pointer2. +**/ +STATIC +INTN +EFIAPI +PointerCompare ( + IN CONST VOID *Pointer1, + IN CONST VOID *Pointer2 + ) +{ + if (Pointer1 =3D=3D Pointer2) { + return 0; + } else if ((INTN)Pointer1 < (INTN)Pointer2) { + return -1; + } else { + return 1; + } +} + + +/** Process a QEMU_LOADER_ALLOCATE command. =20 @param[in] Allocate The QEMU_LOADER_ALLOCATE command to process. @@ -535,27 +568,32 @@ UndoCmdWritePointer ( This function assumes that the entire QEMU linker/loader command file has been processed successfully in a prior first pass. =20 - @param[in] AddPointer The QEMU_LOADER_ADD_POINTER command to proc= ess. + @param[in] AddPointer The QEMU_LOADER_ADD_POINTER command to pr= ocess. =20 - @param[in] Tracker The ORDERED_COLLECTION tracking the BLOB us= er - structures. + @param[in] Tracker The ORDERED_COLLECTION tracking the BLOB = user + structures. =20 - @param[in] AcpiProtocol The ACPI table protocol used to install tab= les. + @param[in] AcpiProtocol The ACPI table protocol used to install t= ables. =20 - @param[in,out] InstalledKey On input, an array of INSTALLED_TABLES_MAX = UINTN - elements, allocated by the caller. On outpu= t, - the function will have stored (appended) the - AcpiProtocol-internal key of the ACPI table= that - the function has installed, if the AddPoint= er - command identified an ACPI table that is - different from RSDT and XSDT. + @param[in,out] InstalledKey On input, an array of INSTALLED_TABLES_MA= X UINTN + elements, allocated by the caller. On out= put, + the function will have stored (appended) = the + AcpiProtocol-internal key of the ACPI tab= le that + the function has installed, if the AddPoi= nter + command identified an ACPI table that is + different from RSDT and XSDT. =20 - @param[in,out] NumInstalled On input, the number of entries already use= d in - InstalledKey; it must be in [0, - INSTALLED_TABLES_MAX] inclusive. On output,= the - parameter is incremented if the AddPointer - command identified an ACPI table that is - different from RSDT and XSDT. + @param[in,out] NumInstalled On input, the number of entries already u= sed in + InstalledKey; it must be in [0, + INSTALLED_TABLES_MAX] inclusive. On outpu= t, the + parameter is incremented if the AddPointer + command identified an ACPI table that is + different from RSDT and XSDT. + + @param[in,out] InstalledTables The ORDERED_COLLECTION tracking the ACPI = tables + which have already been installed. If a n= ew + table is encountered by the function, it = is + added; existing ones will not be installe= d again. =20 @retval EFI_INVALID_PARAMETER NumInstalled was outside the allowed rang= e on input. @@ -584,7 +622,8 @@ Process2ndPassCmdAddPointer ( IN CONST ORDERED_COLLECTION *Tracker, IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, IN OUT UINTN InstalledKey[INSTALLED_TABLES_MAX], - IN OUT INT32 *NumInstalled + IN OUT INT32 *NumInstalled, + IN OUT ORDERED_COLLECTION *InstalledTables ) { CONST ORDERED_COLLECTION_ENTRY *TrackerEntry; @@ -679,6 +718,21 @@ Process2ndPassCmdAddPointer ( return EFI_SUCCESS; } =20 + Status =3D OrderedCollectionInsert ( + InstalledTables, NULL, (VOID *)(UINTN)PointerValue); + if (EFI_ERROR (Status)) { + if (Status =3D=3D RETURN_ALREADY_STARTED) { + // + // Already installed this table, don't try to do so again. + // + DEBUG ((DEBUG_VERBOSE, "%a: AcpiProtocol->InstallAcpiTable reports t= able " + "already installed, skipping. PointerValue=3D0x%Lx\n", + __FUNCTION__, PointerValue)); + Status =3D EFI_SUCCESS; + } + return Status; + } + if (*NumInstalled =3D=3D INSTALLED_TABLES_MAX) { DEBUG ((EFI_D_ERROR, "%a: can't install more than %d tables\n", __FUNCTION__, INSTALLED_TABLES_MAX)); @@ -739,6 +793,8 @@ InstallQemuFwCfgTables ( UINTN *InstalledKey; INT32 Installed; ORDERED_COLLECTION_ENTRY *TrackerEntry, *TrackerEntry2; + ORDERED_COLLECTION *InstalledTables; + ORDERED_COLLECTION_ENTRY *InstalledTableEntry; =20 Status =3D QemuFwCfgFindFile ("etc/table-loader", &FwCfgItem, &FwCfgSize= ); if (EFI_ERROR (Status)) { @@ -827,14 +883,21 @@ InstallQemuFwCfgTables ( goto RollbackWritePointersAndFreeTracker; } =20 + InstalledTables =3D OrderedCollectionInit (PointerCompare, PointerCompar= e); + if (InstalledTables =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto FreeKeys; + } + // // second pass: identify and install ACPI tables // Installed =3D 0; for (LoaderEntry =3D LoaderStart; LoaderEntry < LoaderEnd; ++LoaderEntry= ) { if (LoaderEntry->Type =3D=3D QemuLoaderCmdAddPointer) { - Status =3D Process2ndPassCmdAddPointer (&LoaderEntry->Command.AddPoi= nter, - Tracker, AcpiProtocol, InstalledKey, &Installed); + Status =3D Process2ndPassCmdAddPointer ( + &LoaderEntry->Command.AddPointer, Tracker, AcpiProtocol, + InstalledKey, &Installed, InstalledTables); if (EFI_ERROR (Status)) { goto UninstallAcpiTables; } @@ -870,6 +933,12 @@ UninstallAcpiTables: DEBUG ((EFI_D_INFO, "%a: installed %d tables\n", __FUNCTION__, Install= ed)); } =20 + while (((InstalledTableEntry =3D OrderedCollectionMax(InstalledTables)))= !=3D NULL) { + OrderedCollectionDelete (InstalledTables, InstalledTableEntry, NULL); + } + OrderedCollectionUninit (InstalledTables); + +FreeKeys: FreePool (InstalledKey); =20 RollbackWritePointersAndFreeTracker: --=20 2.3.2 (Apple Git-55) _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel