From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WqGDwPpX; spf=pass (domain: gmail.com, ip: 209.85.215.178, mailfrom: kuqin12@gmail.com) Received: by mail-pg1-f178.google.com with SMTP id q16so15572145pgq.6 for ; Wed, 10 Aug 2022 15:29:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=FPGKW+0NOoz+2N+nDI1FO2NXRiBZFoZjIXwM7UZDpKw=; b=WqGDwPpXmcLkelpJ1r/fUqoc6ZTPXlTTAi7AhbSZWKVDvLCcaTNK+JrRJDtey1GFj6 EmKnOB8LWJINZDDI9zSKgx4KT8tz4kt7PHoCtLxhyt74koSSGE0QO9QPaj65nJV8wLMW uCSGplaBhwR3umn7a944WPCqN7Ae0PcX9G11GloJv3wM3l2Uk7hWcPPrjLnz1A91WuJG 5geebMBdfeFof8RPG9fXKFfx7YKQ2grd5D/PGCEgVw3ERk+r229HqtMP5lOD1uj27DpI m73dAkRF5IfcMh2+IqRiJIJP7hTvXSkxOEAZw9XpSVBSFqceH5A8xoODKoM0Il9SYdCf +Vrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=FPGKW+0NOoz+2N+nDI1FO2NXRiBZFoZjIXwM7UZDpKw=; b=Wlvc7CUGclsBEOy1BbvqGdz/e3SOJ1WFXXFhOpDSETS9bc5p7bQZH13OuS//cmWXwD 3FLEkGmg5J2DWsw5i3KImdhCcRQTOls7lNYf//O7c++h5jz3btIq9ahBsljL6SACj6TF nRFiXM/jE7VtMt1Mf9Y0vDyKQ3CQysymQt95pLDXyeuKAxqGKMTlrZl2k7+mMnMfDBCN zER89cog/riMZFtY+8NhRyOr/rCwlZd/qzEuFn+EnIfXcS0mAqmq4kBFKR+9Nm7NruxG O6EAhyC37lk3CwwfhfzKdaDWcTmv4bJu/Iki7TwV9M6UuulrqGzxB4WziUIFM55YMLHF sv7Q== X-Gm-Message-State: ACgBeo1hK/KtU4vmAm/iXpVqqjugQzSVqwTcsKelUPDDkAKZZUE2dK+a k70+S03L5+woFjG+ryzA5tz3vp309MU= 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20220810222853.1916-1-kuqin12@gmail.com> References: <20220810222853.1916-1-kuqin12@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=20=20=20 v3: - Added descriptions for new structures [Pierre] - Added check for SDT protocol PCD before using it [Pierre] =20=20=20=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 =0D #include =0D #include =0D +#include =0D #include =0D =0D // Module specific include files.=0D @@ -22,6 +23,58 @@ #include =0D #include =0D =0D +///=0D +/// Bit definitions for acceptable ACPI table presence formats.=0D +/// Currently only ACPI tables present in the ACPI info list and=0D +/// already installed will count towards "Table Present" during=0D +/// verification routine.=0D +///=0D +#define ACPI_TABLE_PRESENT_INFO_LIST BIT0=0D +#define ACPI_TABLE_PRESENT_INSTALLED BIT1=0D +=0D +///=0D +/// Order of ACPI table being verified during presence inspection.=0D +///=0D +#define ACPI_TABLE_VERIFY_FADT 0=0D +#define ACPI_TABLE_VERIFY_MADT 1=0D +#define ACPI_TABLE_VERIFY_GTDT 2=0D +#define ACPI_TABLE_VERIFY_DSDT 3=0D +#define ACPI_TABLE_VERIFY_DBG2 4=0D +#define ACPI_TABLE_VERIFY_SPCR 5=0D +#define ACPI_TABLE_VERIFY_COUNT 6=0D +=0D +///=0D +/// Private data structure to verify the presence of mandatory=0D +/// or optional ACPI tables.=0D +///=0D +typedef struct {=0D + /// ESTD ID for the ACPI table of interest.=0D + ESTD_ACPI_TABLE_ID EstdTableId;=0D + /// Standard UINT32 ACPI signature.=0D + UINT32 AcpiTableSignature;=0D + /// 4 character ACPI table name (the 5th char8 is for null terminator).= =0D + CHAR8 AcpiTableName[sizeof (UINT32) + 1];=0D + /// Indicator on whether the ACPI table is required.=0D + BOOLEAN IsMandatory;=0D + /// Formats of verified presences, as defined by ACPI_TABLE_PRESENT_*=0D + /// This field should be initialized to 0 and will be populated during=0D + /// verification routine.=0D + UINT16 Presence;=0D +} ACPI_TABLE_PRESENCE_INFO;=0D +=0D +///=0D +/// We require the FADT, MADT, GTDT and the DSDT tables to boot.=0D +/// This list also include optional ACPI tables: DBG2, SPCR.=0D +///=0D +ACPI_TABLE_PRESENCE_INFO mAcpiVerifyTables[ACPI_TABLE_VERIFY_COUNT] =3D {= =0D + { EStdAcpiTableIdFadt, EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATU= RE, "FADT", TRUE, 0 },=0D + { EStdAcpiTableIdMadt, EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGN= ATURE, "MADT", TRUE, 0 },=0D + { EStdAcpiTableIdGtdt, EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGN= ATURE, "GTDT", TRUE, 0 },=0D + { EStdAcpiTableIdDsdt, EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TA= BLE_SIGNATURE, "DSDT", TRUE, 0 },=0D + { EStdAcpiTableIdDbg2, EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE, = "DBG2", FALSE, 0 },=0D + { EStdAcpiTableIdSpcr, EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABL= E_SIGNATURE, "SPCR", FALSE, 0 },=0D +};=0D +=0D /** This macro expands to a function that retrieves the ACPI Table=0D List from the Configuration Manager.=0D */=0D @@ -395,6 +448,7 @@ BuildAndInstallAcpiTable ( =0D @retval EFI_SUCCESS Success.=0D @retval EFI_NOT_FOUND If mandatory table is not found.=0D + @retval EFI_ALREADY_STARTED If mandatory table found in AcpiTableInfo = is already installed.=0D **/=0D STATIC=0D EFI_STATUS=0D @@ -404,75 +458,73 @@ VerifyMandatoryTablesArePresent ( IN UINT32 AcpiTableCount=0D )=0D {=0D - EFI_STATUS Status;=0D - BOOLEAN FadtFound;=0D - BOOLEAN MadtFound;=0D - BOOLEAN GtdtFound;=0D - BOOLEAN DsdtFound;=0D - BOOLEAN Dbg2Found;=0D - BOOLEAN SpcrFound;=0D + EFI_STATUS Status;=0D + UINTN Handle;=0D + UINTN Index;=0D + UINTN InstalledTableIndex;=0D + EFI_ACPI_DESCRIPTION_HEADER *DescHeader;=0D + EFI_ACPI_TABLE_VERSION Version;=0D + EFI_ACPI_SDT_PROTOCOL *AcpiSdt;=0D =0D - Status =3D EFI_SUCCESS;=0D - FadtFound =3D FALSE;=0D - MadtFound =3D FALSE;=0D - GtdtFound =3D FALSE;=0D - DsdtFound =3D FALSE;=0D - Dbg2Found =3D FALSE;=0D - SpcrFound =3D FALSE;=0D ASSERT (AcpiTableInfo !=3D NULL);=0D =0D + Status =3D EFI_SUCCESS;=0D +=0D + // Check against the statically initialized ACPI tables to see if they a= re in ACPI info list=0D while (AcpiTableCount-- !=3D 0) {=0D - switch (AcpiTableInfo[AcpiTableCount].AcpiTableSignature) {=0D - case EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:=0D - FadtFound =3D TRUE;=0D - break;=0D - case EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE:=0D - MadtFound =3D TRUE;=0D - break;=0D - case EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE:=0D - GtdtFound =3D TRUE;=0D - break;=0D - case EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:= =0D - DsdtFound =3D TRUE;=0D - break;=0D - case EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE:=0D - Dbg2Found =3D TRUE;=0D - break;=0D - case EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE:=0D - SpcrFound =3D TRUE;=0D - break;=0D - default:=0D + for (Index =3D 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) {=0D + if (AcpiTableInfo[AcpiTableCount].AcpiTableSignature =3D=3D mAcpiVer= ifyTables[Index].AcpiTableSignature) {=0D + mAcpiVerifyTables[Index].Presence |=3D ACPI_TABLE_PRESENT_INFO_LIS= T;=0D + // Found this table, skip the rest.=0D break;=0D + }=0D }=0D }=0D =0D - // We need at least the FADT, MADT, GTDT and the DSDT tables to boot=0D - if (!FadtFound) {=0D - DEBUG ((DEBUG_ERROR, "ERROR: FADT Table not found\n"));=0D - Status =3D EFI_NOT_FOUND;=0D - }=0D + // They also might be published already, so we can search from there=0D + if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {=0D + AcpiSdt =3D NULL;=0D + Status =3D gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID= **)&AcpiSdt);=0D =0D - if (!MadtFound) {=0D - DEBUG ((DEBUG_ERROR, "ERROR: MADT Table not found.\n"));=0D - Status =3D EFI_NOT_FOUND;=0D - }=0D + if (EFI_ERROR (Status) || (AcpiSdt =3D=3D NULL)) {=0D + DEBUG ((DEBUG_ERROR, "ERROR: Failed to locate ACPI SDT protocol (0x%= p) - %r\n", AcpiSdt, Status));=0D + return Status;=0D + }=0D =0D - if (!GtdtFound) {=0D - DEBUG ((DEBUG_ERROR, "ERROR: GTDT Table not found.\n"));=0D - Status =3D EFI_NOT_FOUND;=0D - }=0D + for (Index =3D 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) {=0D + Handle =3D 0;=0D + InstalledTableIndex =3D 0;=0D + do {=0D + Status =3D AcpiSdt->GetAcpiTable (InstalledTableIndex, (EFI_ACPI_S= DT_HEADER **)&DescHeader, &Version, &Handle);=0D + if (EFI_ERROR (Status)) {=0D + break;=0D + }=0D =0D - if (!DsdtFound) {=0D - DEBUG ((DEBUG_ERROR, "ERROR: DSDT Table not found.\n"));=0D - Status =3D EFI_NOT_FOUND;=0D - }=0D + InstalledTableIndex++;=0D + } while (DescHeader->Signature !=3D mAcpiVerifyTables[Index].AcpiTab= leSignature);=0D =0D - if (!Dbg2Found) {=0D - DEBUG ((DEBUG_WARN, "WARNING: DBG2 Table not found.\n"));=0D + if (!EFI_ERROR (Status)) {=0D + mAcpiVerifyTables[Index].Presence |=3D ACPI_TABLE_PRESENT_INSTALLE= D;=0D + }=0D + }=0D }=0D =0D - if (!SpcrFound) {=0D - DEBUG ((DEBUG_WARN, "WARNING: SPCR Table not found.\n"));=0D + // Reset the return Status value to EFI_SUCCESS. We do not fully care if= the table look up has failed.=0D + Status =3D EFI_SUCCESS;=0D + for (Index =3D 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) {=0D + if (mAcpiVerifyTables[Index].Presence =3D=3D 0) {=0D + if (mAcpiVerifyTables[Index].IsMandatory) {=0D + DEBUG ((DEBUG_ERROR, "ERROR: %a Table not found.\n", mAcpiVerifyTa= bles[Index].AcpiTableName));=0D + Status =3D EFI_NOT_FOUND;=0D + } else {=0D + DEBUG ((DEBUG_WARN, "WARNING: %a Table not found.\n", mAcpiVerifyT= ables[Index].AcpiTableName));=0D + }=0D + } else if (mAcpiVerifyTables[Index].Presence =3D=3D=0D + (ACPI_TABLE_PRESENT_INFO_LIST | ACPI_TABLE_PRESENT_INSTALLE= D))=0D + {=0D + DEBUG ((DEBUG_ERROR, "ERROR: %a Table found while already published.= \n", mAcpiVerifyTables[Index].AcpiTableName));=0D + Status =3D EFI_ALREADY_STARTED;=0D + }=0D }=0D =0D return Status;=0D @@ -489,8 +541,9 @@ VerifyMandatoryTablesArePresent ( @param [in] CfgMgrProtocol Pointer to the Configuration Manager=0D Protocol Interface.=0D =0D - @retval EFI_SUCCESS Success.=0D - @retval EFI_NOT_FOUND If a mandatory table or a generator is not found.= =0D + @retval EFI_SUCCESS Success.=0D + @retval EFI_NOT_FOUND If a mandatory table or a generator is not= found.=0D + @retval EFI_ALREADY_STARTED If mandatory table found in AcpiTableInfo = is already installed.=0D **/=0D STATIC=0D EFI_STATUS=0D @@ -562,7 +615,7 @@ ProcessAcpiTables ( if (EFI_ERROR (Status)) {=0D DEBUG ((=0D DEBUG_ERROR,=0D - "ERROR: Failed to find mandatory ACPI Table(s)."=0D + "ERROR: Failed to verify mandatory ACPI Table(s) presence."=0D " Status =3D %r\n",=0D Status=0D ));=0D @@ -570,29 +623,32 @@ ProcessAcpiTables ( }=0D =0D // Add the FADT Table first.=0D - for (Idx =3D 0; Idx < AcpiTableCount; Idx++) {=0D - if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) =3D=3D=0D - AcpiTableInfo[Idx].TableGeneratorId)=0D - {=0D - Status =3D BuildAndInstallAcpiTable (=0D - TableFactoryProtocol,=0D - CfgMgrProtocol,=0D - AcpiTableProtocol,=0D - &AcpiTableInfo[Idx]=0D - );=0D - if (EFI_ERROR (Status)) {=0D - DEBUG ((=0D - DEBUG_ERROR,=0D - "ERROR: Failed to find build and install ACPI FADT Table." \=0D - " Status =3D %r\n",=0D - Status=0D - ));=0D - return Status;=0D - }=0D + if ((mAcpiVerifyTables[ACPI_TABLE_VERIFY_FADT].Presence & ACPI_TABLE_PRE= SENT_INSTALLED) =3D=3D 0) {=0D + // FADT is not yet installed=0D + for (Idx =3D 0; Idx < AcpiTableCount; Idx++) {=0D + if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) =3D=3D=0D + AcpiTableInfo[Idx].TableGeneratorId)=0D + {=0D + Status =3D BuildAndInstallAcpiTable (=0D + TableFactoryProtocol,=0D + CfgMgrProtocol,=0D + AcpiTableProtocol,=0D + &AcpiTableInfo[Idx]=0D + );=0D + if (EFI_ERROR (Status)) {=0D + DEBUG ((=0D + DEBUG_ERROR,=0D + "ERROR: Failed to find build and install ACPI FADT Table." \=0D + " Status =3D %r\n",=0D + Status=0D + ));=0D + return Status;=0D + }=0D =0D - break;=0D - }=0D - } // for=0D + break;=0D + }=0D + } // for=0D + }=0D =0D // Add remaining ACPI Tables=0D for (Idx =3D 0; Idx < AcpiTableCount; Idx++) {=0D 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=0D UefiDriverEntryPoint=0D =0D +[FeaturePcd]=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol ## CONSUMES=0D +=0D [Protocols]=0D gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED= =0D + gEfiAcpiSdtProtocolGuid # PROTOCOL ALWAYS_CONSUMED= =0D =0D gEdkiiConfigurationManagerProtocolGuid # PROTOCOL ALWAYS_CONSUMED= =0D gEdkiiDynamicTableFactoryProtocolGuid # PROTOCOL ALWAYS_CONSUMED= =0D --=20 2.37.1.windows.1