From nobody Mon Feb 9 21:36:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+92316+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+92316+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1660170541; cv=none; d=zohomail.com; s=zohoarc; b=GNGgImZP+uINvjVxIdtqOQNIDZd6e/EyD/Jzopf953bl14d5F0Pj59q4Xvu0JyCyp8vI17jx2RLBFdjZoK3TN9dsGfDGS3Z1odh52vkZUQTBbzqVnx5G+39HMo8lHCrqxA7xvwlSs3OGG8bBZ5tTL4vPoDfdNwjb9k5RYSc7IUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660170541; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=jsy4uZtjVDa6HwiuhAY/pSd2KIIR4VuSaGNjCj73QBk=; b=LkDVbdrHyl5yRB+6wHui3rNpknRQoSv3F7WYRa8tUySDFazcry9EDdLl/VH5E8+ZIamDJCyFSkupkTMzXvIHqXVHWAeDr4n7l1YEMEHsPjZJL1y2R3albZ4vDUNN+8NsYIe629x7WAPXN0xNT6ka+jS7XViwLgGzOS0X1ZOIgsc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+92316+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1660170541717588.566068868181; Wed, 10 Aug 2022 15:29:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MeSpYY1788612xDqOcKHpBIY; Wed, 10 Aug 2022 15:29:01 -0700 X-Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mx.groups.io with SMTP id smtpd.web11.944.1660170540626412034 for ; Wed, 10 Aug 2022 15:29:00 -0700 X-Received: by mail-pg1-f178.google.com with SMTP id q16so15572145pgq.6 for ; Wed, 10 Aug 2022 15:29:00 -0700 (PDT) X-Gm-Message-State: zOFLfg7CFJYroHpCY3D26wP6x1787277AA= X-Google-Smtp-Source: AA6agR67yjgV5DHZefwf2e+L+hehOO/KPhAo+4cWFnIJnaqlN0GqMVxZpdO7VHvk2l6c7+lTV5ziqg== X-Received: by 2002:a63:4081:0:b0:405:4f9:e802 with SMTP id n123-20020a634081000000b0040504f9e802mr24697116pga.211.1660170539809; Wed, 10 Aug 2022 15:28:59 -0700 (PDT) X-Received: from MININT-0U7P5GU.redmond.corp.microsoft.com ([2001:4898:80e8:38:b518:f1a8:aef2:7dc4]) by smtp.gmail.com with ESMTPSA id h11-20020a170902f70b00b0016d66d49b85sm13309701plo.239.2022.08.10.15.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Aug 2022 15:28:59 -0700 (PDT) From: "Kun Qin" To: devel@edk2.groups.io Cc: Sami Mujawar , Alexei Fedorov , Joe Lopez , Pierre Gondois Subject: [edk2-devel] [PATCH v4 4/6] DynamicTablesPkg: DynamicTableManagerDxe: Added check for installed tables Date: Wed, 10 Aug 2022 15:28:51 -0700 Message-Id: <20220810222853.1916-5-kuqin12@gmail.com> In-Reply-To: <20220810222853.1916-1-kuqin12@gmail.com> References: <20220810222853.1916-1-kuqin12@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,kuqin12@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1660170541; bh=BbyjQvdOZu+uLF/Njpimhjy4FTxXYc2o6NYYzxCvx/g=; h=Cc:Date:From:Reply-To:Subject:To; b=Bj/FHAJjUqYEiB8FH0lGvk8EHevOl1tTC/nDUw3mZVAGWqcdoxfYiTE09f/82BiAxdA pZ91PzZH8vOS4E/FkkSug0vEPwEyPts8w2QxyU6zWT13ehwWtncMp2EM7vkFdy/WnbhTG D1TGSB/xoCHxtlj38Y828n3Pq15r7UUBA0c= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1660170542881100015 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3997 This change added an extra step to allow check for installed ACPI tables. For FADT, MADT, GTDT, DSDT, DBG2 and SPCR tables, either pre-installed or supplied through AcpiTableInfo can be accepted. An extra check for FADT ACPI table existence during installation step is also added. Cc: Sami Mujawar Cc: Alexei Fedorov Co-authored-by: Joe Lopez Signed-off-by: Kun Qin Reviewed-by: Pierre Gondois --- Notes: v2: - Function description updates [Sami] - Refactorized the table verification [Pierre] =20 v3: - Added descriptions for new structures [Pierre] - Added check for SDT protocol PCD before using it [Pierre] =20 v4: - Reset return status before inspecting the table presence [Sami] DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c = | 216 ++++++++++++-------- DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf= | 4 + 2 files changed, 140 insertions(+), 80 deletions(-) diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableMa= nagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableMa= nagerDxe.c index ed62299f9bbd..1e9b811c4017 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDx= e.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDx= e.c @@ -10,6 +10,7 @@ #include #include #include +#include #include =20 // Module specific include files. @@ -22,6 +23,58 @@ #include #include =20 +/// +/// Bit definitions for acceptable ACPI table presence formats. +/// Currently only ACPI tables present in the ACPI info list and +/// already installed will count towards "Table Present" during +/// verification routine. +/// +#define ACPI_TABLE_PRESENT_INFO_LIST BIT0 +#define ACPI_TABLE_PRESENT_INSTALLED BIT1 + +/// +/// Order of ACPI table being verified during presence inspection. +/// +#define ACPI_TABLE_VERIFY_FADT 0 +#define ACPI_TABLE_VERIFY_MADT 1 +#define ACPI_TABLE_VERIFY_GTDT 2 +#define ACPI_TABLE_VERIFY_DSDT 3 +#define ACPI_TABLE_VERIFY_DBG2 4 +#define ACPI_TABLE_VERIFY_SPCR 5 +#define ACPI_TABLE_VERIFY_COUNT 6 + +/// +/// Private data structure to verify the presence of mandatory +/// or optional ACPI tables. +/// +typedef struct { + /// ESTD ID for the ACPI table of interest. + ESTD_ACPI_TABLE_ID EstdTableId; + /// Standard UINT32 ACPI signature. + UINT32 AcpiTableSignature; + /// 4 character ACPI table name (the 5th char8 is for null terminator). + CHAR8 AcpiTableName[sizeof (UINT32) + 1]; + /// Indicator on whether the ACPI table is required. + BOOLEAN IsMandatory; + /// Formats of verified presences, as defined by ACPI_TABLE_PRESENT_* + /// This field should be initialized to 0 and will be populated during + /// verification routine. + UINT16 Presence; +} ACPI_TABLE_PRESENCE_INFO; + +/// +/// We require the FADT, MADT, GTDT and the DSDT tables to boot. +/// This list also include optional ACPI tables: DBG2, SPCR. +/// +ACPI_TABLE_PRESENCE_INFO mAcpiVerifyTables[ACPI_TABLE_VERIFY_COUNT] =3D { + { EStdAcpiTableIdFadt, EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATU= RE, "FADT", TRUE, 0 }, + { EStdAcpiTableIdMadt, EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGN= ATURE, "MADT", TRUE, 0 }, + { EStdAcpiTableIdGtdt, EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGN= ATURE, "GTDT", TRUE, 0 }, + { EStdAcpiTableIdDsdt, EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TA= BLE_SIGNATURE, "DSDT", TRUE, 0 }, + { EStdAcpiTableIdDbg2, EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE, = "DBG2", FALSE, 0 }, + { EStdAcpiTableIdSpcr, EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABL= E_SIGNATURE, "SPCR", FALSE, 0 }, +}; + /** This macro expands to a function that retrieves the ACPI Table List from the Configuration Manager. */ @@ -395,6 +448,7 @@ BuildAndInstallAcpiTable ( =20 @retval EFI_SUCCESS Success. @retval EFI_NOT_FOUND If mandatory table is not found. + @retval EFI_ALREADY_STARTED If mandatory table found in AcpiTableInfo = is already installed. **/ STATIC EFI_STATUS @@ -404,75 +458,73 @@ VerifyMandatoryTablesArePresent ( IN UINT32 AcpiTableCount ) { - EFI_STATUS Status; - BOOLEAN FadtFound; - BOOLEAN MadtFound; - BOOLEAN GtdtFound; - BOOLEAN DsdtFound; - BOOLEAN Dbg2Found; - BOOLEAN SpcrFound; + EFI_STATUS Status; + UINTN Handle; + UINTN Index; + UINTN InstalledTableIndex; + EFI_ACPI_DESCRIPTION_HEADER *DescHeader; + EFI_ACPI_TABLE_VERSION Version; + EFI_ACPI_SDT_PROTOCOL *AcpiSdt; =20 - Status =3D EFI_SUCCESS; - FadtFound =3D FALSE; - MadtFound =3D FALSE; - GtdtFound =3D FALSE; - DsdtFound =3D FALSE; - Dbg2Found =3D FALSE; - SpcrFound =3D FALSE; ASSERT (AcpiTableInfo !=3D NULL); =20 + Status =3D EFI_SUCCESS; + + // Check against the statically initialized ACPI tables to see if they a= re in ACPI info list while (AcpiTableCount-- !=3D 0) { - switch (AcpiTableInfo[AcpiTableCount].AcpiTableSignature) { - case EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE: - FadtFound =3D TRUE; - break; - case EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE: - MadtFound =3D TRUE; - break; - case EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE: - GtdtFound =3D TRUE; - break; - case EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE: - DsdtFound =3D TRUE; - break; - case EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE: - Dbg2Found =3D TRUE; - break; - case EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE: - SpcrFound =3D TRUE; - break; - default: + for (Index =3D 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { + if (AcpiTableInfo[AcpiTableCount].AcpiTableSignature =3D=3D mAcpiVer= ifyTables[Index].AcpiTableSignature) { + mAcpiVerifyTables[Index].Presence |=3D ACPI_TABLE_PRESENT_INFO_LIS= T; + // Found this table, skip the rest. break; + } } } =20 - // We need at least the FADT, MADT, GTDT and the DSDT tables to boot - if (!FadtFound) { - DEBUG ((DEBUG_ERROR, "ERROR: FADT Table not found\n")); - Status =3D EFI_NOT_FOUND; - } + // They also might be published already, so we can search from there + if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) { + AcpiSdt =3D NULL; + Status =3D gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID= **)&AcpiSdt); =20 - if (!MadtFound) { - DEBUG ((DEBUG_ERROR, "ERROR: MADT Table not found.\n")); - Status =3D EFI_NOT_FOUND; - } + if (EFI_ERROR (Status) || (AcpiSdt =3D=3D NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Failed to locate ACPI SDT protocol (0x%= p) - %r\n", AcpiSdt, Status)); + return Status; + } =20 - if (!GtdtFound) { - DEBUG ((DEBUG_ERROR, "ERROR: GTDT Table not found.\n")); - Status =3D EFI_NOT_FOUND; - } + for (Index =3D 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { + Handle =3D 0; + InstalledTableIndex =3D 0; + do { + Status =3D AcpiSdt->GetAcpiTable (InstalledTableIndex, (EFI_ACPI_S= DT_HEADER **)&DescHeader, &Version, &Handle); + if (EFI_ERROR (Status)) { + break; + } =20 - if (!DsdtFound) { - DEBUG ((DEBUG_ERROR, "ERROR: DSDT Table not found.\n")); - Status =3D EFI_NOT_FOUND; - } + InstalledTableIndex++; + } while (DescHeader->Signature !=3D mAcpiVerifyTables[Index].AcpiTab= leSignature); =20 - if (!Dbg2Found) { - DEBUG ((DEBUG_WARN, "WARNING: DBG2 Table not found.\n")); + if (!EFI_ERROR (Status)) { + mAcpiVerifyTables[Index].Presence |=3D ACPI_TABLE_PRESENT_INSTALLE= D; + } + } } =20 - if (!SpcrFound) { - DEBUG ((DEBUG_WARN, "WARNING: SPCR Table not found.\n")); + // Reset the return Status value to EFI_SUCCESS. We do not fully care if= the table look up has failed. + Status =3D EFI_SUCCESS; + for (Index =3D 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { + if (mAcpiVerifyTables[Index].Presence =3D=3D 0) { + if (mAcpiVerifyTables[Index].IsMandatory) { + DEBUG ((DEBUG_ERROR, "ERROR: %a Table not found.\n", mAcpiVerifyTa= bles[Index].AcpiTableName)); + Status =3D EFI_NOT_FOUND; + } else { + DEBUG ((DEBUG_WARN, "WARNING: %a Table not found.\n", mAcpiVerifyT= ables[Index].AcpiTableName)); + } + } else if (mAcpiVerifyTables[Index].Presence =3D=3D + (ACPI_TABLE_PRESENT_INFO_LIST | ACPI_TABLE_PRESENT_INSTALLE= D)) + { + DEBUG ((DEBUG_ERROR, "ERROR: %a Table found while already published.= \n", mAcpiVerifyTables[Index].AcpiTableName)); + Status =3D EFI_ALREADY_STARTED; + } } =20 return Status; @@ -489,8 +541,9 @@ VerifyMandatoryTablesArePresent ( @param [in] CfgMgrProtocol Pointer to the Configuration Manager Protocol Interface. =20 - @retval EFI_SUCCESS Success. - @retval EFI_NOT_FOUND If a mandatory table or a generator is not found. + @retval EFI_SUCCESS Success. + @retval EFI_NOT_FOUND If a mandatory table or a generator is not= found. + @retval EFI_ALREADY_STARTED If mandatory table found in AcpiTableInfo = is already installed. **/ STATIC EFI_STATUS @@ -562,7 +615,7 @@ ProcessAcpiTables ( if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, - "ERROR: Failed to find mandatory ACPI Table(s)." + "ERROR: Failed to verify mandatory ACPI Table(s) presence." " Status =3D %r\n", Status )); @@ -570,29 +623,32 @@ ProcessAcpiTables ( } =20 // Add the FADT Table first. - for (Idx =3D 0; Idx < AcpiTableCount; Idx++) { - if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) =3D=3D - AcpiTableInfo[Idx].TableGeneratorId) - { - Status =3D BuildAndInstallAcpiTable ( - TableFactoryProtocol, - CfgMgrProtocol, - AcpiTableProtocol, - &AcpiTableInfo[Idx] - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: Failed to find build and install ACPI FADT Table." \ - " Status =3D %r\n", - Status - )); - return Status; - } + if ((mAcpiVerifyTables[ACPI_TABLE_VERIFY_FADT].Presence & ACPI_TABLE_PRE= SENT_INSTALLED) =3D=3D 0) { + // FADT is not yet installed + for (Idx =3D 0; Idx < AcpiTableCount; Idx++) { + if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) =3D=3D + AcpiTableInfo[Idx].TableGeneratorId) + { + Status =3D BuildAndInstallAcpiTable ( + TableFactoryProtocol, + CfgMgrProtocol, + AcpiTableProtocol, + &AcpiTableInfo[Idx] + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: Failed to find build and install ACPI FADT Table." \ + " Status =3D %r\n", + Status + )); + return Status; + } =20 - break; - } - } // for + break; + } + } // for + } =20 // Add remaining ACPI Tables for (Idx =3D 0; Idx < AcpiTableCount; Idx++) { diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableMa= nagerDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTable= ManagerDxe.inf index 028c3d413cf8..ad8b3d037c16 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDx= e.inf +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDx= e.inf @@ -34,8 +34,12 @@ [LibraryClasses] UefiBootServicesTableLib UefiDriverEntryPoint =20 +[FeaturePcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol ## CONSUMES + [Protocols] gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED + gEfiAcpiSdtProtocolGuid # PROTOCOL ALWAYS_CONSUMED =20 gEdkiiConfigurationManagerProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEdkiiDynamicTableFactoryProtocolGuid # PROTOCOL ALWAYS_CONSUMED --=20 2.37.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#92316): https://edk2.groups.io/g/devel/message/92316 Mute This Topic: https://groups.io/mt/92947267/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-