From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 1DD4B7803D7 for ; Tue, 9 Jan 2024 16:30:47 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=eBBHyw7lIjzqjT6MFnuwFaKMDDuC2fXc2Ule2uOk780=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1704817846; v=1; b=VuDnl9/rHG87VSG5MKk7eXbcHyp6z/qXBUDZu1RclVyeBbkkjodmKtVdaDP3jhNTEj+vCBhq VLpovLHswYt62CiO/61Lx9H9bUdWEb2bx2Z3T0r1kM3Fjahs0UJiIu+SmxUPxQ18JkbAAfHTrSC zf+1h4kmDDVKYZz/5cf14lW8= X-Received: by 127.0.0.2 with SMTP id AbKBYY7687511xOmclXewPZF; Tue, 09 Jan 2024 08:30:46 -0800 X-Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mx.groups.io with SMTP id smtpd.web11.21079.1704817846298741677 for ; Tue, 09 Jan 2024 08:30:46 -0800 X-Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1d3eb299e2eso17942025ad.2 for ; Tue, 09 Jan 2024 08:30:46 -0800 (PST) X-Gm-Message-State: 4H40hW6XiulDorw7d0xxnXmYx7686176AA= X-Google-Smtp-Source: AGHT+IHZiK/QQimUfo6LVZ2Hl+4sm2hbDs7MQld6SU31eFiycyV67P0j8l/dVl1g4iX5TX8srsPe1g== X-Received: by 2002:a17:902:b113:b0:1d4:4e13:6b59 with SMTP id q19-20020a170902b11300b001d44e136b59mr2533798plr.45.1704817844888; Tue, 09 Jan 2024 08:30:44 -0800 (PST) X-Received: from localhost.localdomain ([106.51.188.200]) by smtp.gmail.com with ESMTPSA id c12-20020a170902b68c00b001d457090851sm1983596pls.289.2024.01.09.08.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 08:30:44 -0800 (PST) From: "Sunil V L" To: devel@edk2.groups.io Cc: Sunil V L , Ard Biesheuvel , Leif Lindholm , Pierre Gondois , Sami Mujawar Subject: [edk2-devel] [RFC PATCH v1 17/20] DynamicTablesPkg: DynamicTableManagerDxe: Refactor to allow other archs Date: Tue, 9 Jan 2024 21:59:41 +0530 Message-Id: <20240109162944.528006-18-sunilvl@ventanamicro.com> In-Reply-To: <20240109162944.528006-1-sunilvl@ventanamicro.com> References: <20240109162944.528006-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Precedence: Bulk 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,sunilvl@ventanamicro.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="VuDnl9/r"; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io mAcpiVerifyTables is an arch specific structure. So, move the structure and the function which refers this structure to ARM specific file. Cc: Ard Biesheuvel Cc: Leif Lindholm Cc: Pierre Gondois Cc: Sami Mujawar Signed-off-by: Sunil V L --- .../DynamicTableManagerDxe.inf | 4 + .../DynamicTableManagerDxe.h | 65 ++++++++ .../ArmDynamicTableManagerDxe.c | 154 ++++++++++++++++++ .../DynamicTableManagerDxe.c | 145 +---------------- 4 files changed, 225 insertions(+), 143 deletions(-) create mode 100644 DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.h create mode 100644 DynamicTablesPkg/Drivers/DynamicTableManagerDxe/ArmDynamicTableManagerDxe.c diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf index ad8b3d037c16..b49f6b811691 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf @@ -22,6 +22,10 @@ [Defines] [Sources] DynamicTableManagerDxe.c + DynamicTableManagerDxe.h + +[Sources.ARM, Sources.AARCH64] + ArmDynamicTableManagerDxe.c [Packages] MdePkg/MdePkg.dec diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.h b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.h new file mode 100644 index 000000000000..0149d9de1bdc --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.h @@ -0,0 +1,65 @@ +/** @file + + Copyright (c) 2017 - 2023, Arm Limited. All rights reserved.
+ Copyright (c) 2024, Ventana Micro Systems Inc. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef DYNAMIC_TABLE_MANAGER_DXE_H_ +#define DYNAMIC_TABLE_MANAGER_DXE_H_ + +#include + +/// +/// 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 + +/// +/// 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; + +BOOLEAN +IsFadtPresentInstalled ( + VOID + ); + +/** The function checks if the Configuration Manager has provided the + mandatory ACPI tables for installation. + + @param [in] AcpiTableInfo Pointer to the ACPI Table Info list. + @param [in] AcpiTableCount Count of ACPI Table Info. + + @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. +**/ +EFI_STATUS +EFIAPI +VerifyMandatoryTablesArePresent ( + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, + IN UINT32 AcpiTableCount + ); + +#endif // DYNAMIC_TABLE_MANAGER_DXE_H_ diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/ArmDynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/ArmDynamicTableManagerDxe.c new file mode 100644 index 000000000000..19ba501752b9 --- /dev/null +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/ArmDynamicTableManagerDxe.c @@ -0,0 +1,154 @@ +/** @file + ARM Dynamic Table Manager Dxe + + Copyright (c) 2017 - 2019, ARM Limited. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include +#include +#include +#include "DynamicTableManagerDxe.h" + +/// +/// 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 + +/// +/// 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] = { + { EStdAcpiTableIdFadt, EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, "FADT", TRUE, 0 }, + { EStdAcpiTableIdMadt, EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE, "MADT", TRUE, 0 }, + { EStdAcpiTableIdGtdt, EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE, "GTDT", TRUE, 0 }, + { EStdAcpiTableIdDsdt, EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_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_TABLE_SIGNATURE, "SPCR", FALSE, 0 }, +}; + +/** The function checks if the Configuration Manager has provided the + mandatory ACPI tables for installation. + + @param [in] AcpiTableInfo Pointer to the ACPI Table Info list. + @param [in] AcpiTableCount Count of ACPI Table Info. + + @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. +**/ +EFI_STATUS +EFIAPI +VerifyMandatoryTablesArePresent ( + IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, + IN UINT32 AcpiTableCount + ) +{ + EFI_STATUS Status; + UINTN Handle; + UINTN Index; + UINTN InstalledTableIndex; + EFI_ACPI_DESCRIPTION_HEADER *DescHeader; + EFI_ACPI_TABLE_VERSION Version; + EFI_ACPI_SDT_PROTOCOL *AcpiSdt; + + ASSERT (AcpiTableInfo != NULL); + + Status = EFI_SUCCESS; + + // Check against the statically initialized ACPI tables to see if they are in ACPI info list + while (AcpiTableCount-- != 0) { + for (Index = 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { + if (AcpiTableInfo[AcpiTableCount].AcpiTableSignature == mAcpiVerifyTables[Index].AcpiTableSignature) { + mAcpiVerifyTables[Index].Presence |= ACPI_TABLE_PRESENT_INFO_LIST; + // Found this table, skip the rest. + break; + } + } + } + + // They also might be published already, so we can search from there + if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) { + AcpiSdt = NULL; + Status = gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID **)&AcpiSdt); + + if (EFI_ERROR (Status) || (AcpiSdt == NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Failed to locate ACPI SDT protocol (0x%p) - %r\n", AcpiSdt, Status)); + return Status; + } + + for (Index = 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { + Handle = 0; + InstalledTableIndex = 0; + do { + Status = AcpiSdt->GetAcpiTable (InstalledTableIndex, (EFI_ACPI_SDT_HEADER **)&DescHeader, &Version, &Handle); + if (EFI_ERROR (Status)) { + break; + } + + InstalledTableIndex++; + } while (DescHeader->Signature != mAcpiVerifyTables[Index].AcpiTableSignature); + + if (!EFI_ERROR (Status)) { + mAcpiVerifyTables[Index].Presence |= ACPI_TABLE_PRESENT_INSTALLED; + } + } + } + + // Reset the return Status value to EFI_SUCCESS. We do not fully care if the table look up has failed. + Status = EFI_SUCCESS; + for (Index = 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { + if (mAcpiVerifyTables[Index].Presence == 0) { + if (mAcpiVerifyTables[Index].IsMandatory) { + DEBUG ((DEBUG_ERROR, "ERROR: %a Table not found.\n", mAcpiVerifyTables[Index].AcpiTableName)); + Status = EFI_NOT_FOUND; + } else { + DEBUG ((DEBUG_WARN, "WARNING: %a Table not found.\n", mAcpiVerifyTables[Index].AcpiTableName)); + } + } else if (mAcpiVerifyTables[Index].Presence == + (ACPI_TABLE_PRESENT_INFO_LIST | ACPI_TABLE_PRESENT_INSTALLED)) + { + DEBUG ((DEBUG_ERROR, "ERROR: %a Table found while already published.\n", mAcpiVerifyTables[Index].AcpiTableName)); + Status = EFI_ALREADY_STARTED; + } + } + + return Status; +} + +/** The function checks if the FADT table is present and installed + + @retval TRUE FADT is present and installed. + @retval FALSE FADT is not present and installed. +**/ +BOOLEAN +IsFadtPresentInstalled ( + VOID + ) +{ + if ((mAcpiVerifyTables[ACPI_TABLE_VERIFY_FADT].Presence & ACPI_TABLE_PRESENT_INSTALLED) == 0) { + return FALSE; + } + + return TRUE; +} diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c index 1e9b811c4017..4f0e238636bc 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c @@ -22,58 +22,7 @@ #include #include #include - -/// -/// 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] = { - { EStdAcpiTableIdFadt, EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, "FADT", TRUE, 0 }, - { EStdAcpiTableIdMadt, EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE, "MADT", TRUE, 0 }, - { EStdAcpiTableIdGtdt, EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE, "GTDT", TRUE, 0 }, - { EStdAcpiTableIdDsdt, EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_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_TABLE_SIGNATURE, "SPCR", FALSE, 0 }, -}; +#include "DynamicTableManagerDxe.h" /** This macro expands to a function that retrieves the ACPI Table List from the Configuration Manager. @@ -440,96 +389,6 @@ BuildAndInstallAcpiTable ( return Status; } -/** The function checks if the Configuration Manager has provided the - mandatory ACPI tables for installation. - - @param [in] AcpiTableInfo Pointer to the ACPI Table Info list. - @param [in] AcpiTableCount Count of ACPI Table Info. - - @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 -EFIAPI -VerifyMandatoryTablesArePresent ( - IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, - IN UINT32 AcpiTableCount - ) -{ - EFI_STATUS Status; - UINTN Handle; - UINTN Index; - UINTN InstalledTableIndex; - EFI_ACPI_DESCRIPTION_HEADER *DescHeader; - EFI_ACPI_TABLE_VERSION Version; - EFI_ACPI_SDT_PROTOCOL *AcpiSdt; - - ASSERT (AcpiTableInfo != NULL); - - Status = EFI_SUCCESS; - - // Check against the statically initialized ACPI tables to see if they are in ACPI info list - while (AcpiTableCount-- != 0) { - for (Index = 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { - if (AcpiTableInfo[AcpiTableCount].AcpiTableSignature == mAcpiVerifyTables[Index].AcpiTableSignature) { - mAcpiVerifyTables[Index].Presence |= ACPI_TABLE_PRESENT_INFO_LIST; - // Found this table, skip the rest. - break; - } - } - } - - // They also might be published already, so we can search from there - if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) { - AcpiSdt = NULL; - Status = gBS->LocateProtocol (&gEfiAcpiSdtProtocolGuid, NULL, (VOID **)&AcpiSdt); - - if (EFI_ERROR (Status) || (AcpiSdt == NULL)) { - DEBUG ((DEBUG_ERROR, "ERROR: Failed to locate ACPI SDT protocol (0x%p) - %r\n", AcpiSdt, Status)); - return Status; - } - - for (Index = 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { - Handle = 0; - InstalledTableIndex = 0; - do { - Status = AcpiSdt->GetAcpiTable (InstalledTableIndex, (EFI_ACPI_SDT_HEADER **)&DescHeader, &Version, &Handle); - if (EFI_ERROR (Status)) { - break; - } - - InstalledTableIndex++; - } while (DescHeader->Signature != mAcpiVerifyTables[Index].AcpiTableSignature); - - if (!EFI_ERROR (Status)) { - mAcpiVerifyTables[Index].Presence |= ACPI_TABLE_PRESENT_INSTALLED; - } - } - } - - // Reset the return Status value to EFI_SUCCESS. We do not fully care if the table look up has failed. - Status = EFI_SUCCESS; - for (Index = 0; Index < ACPI_TABLE_VERIFY_COUNT; Index++) { - if (mAcpiVerifyTables[Index].Presence == 0) { - if (mAcpiVerifyTables[Index].IsMandatory) { - DEBUG ((DEBUG_ERROR, "ERROR: %a Table not found.\n", mAcpiVerifyTables[Index].AcpiTableName)); - Status = EFI_NOT_FOUND; - } else { - DEBUG ((DEBUG_WARN, "WARNING: %a Table not found.\n", mAcpiVerifyTables[Index].AcpiTableName)); - } - } else if (mAcpiVerifyTables[Index].Presence == - (ACPI_TABLE_PRESENT_INFO_LIST | ACPI_TABLE_PRESENT_INSTALLED)) - { - DEBUG ((DEBUG_ERROR, "ERROR: %a Table found while already published.\n", mAcpiVerifyTables[Index].AcpiTableName)); - Status = EFI_ALREADY_STARTED; - } - } - - return Status; -} - /** Generate and install ACPI tables. The function gathers the information necessary for installing the @@ -623,7 +482,7 @@ ProcessAcpiTables ( } // Add the FADT Table first. - if ((mAcpiVerifyTables[ACPI_TABLE_VERIFY_FADT].Presence & ACPI_TABLE_PRESENT_INSTALLED) == 0) { + if (IsFadtPresentInstalled () == FALSE) { // FADT is not yet installed for (Idx = 0; Idx < AcpiTableCount; Idx++) { if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) == -- 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113479): https://edk2.groups.io/g/devel/message/113479 Mute This Topic: https://groups.io/mt/103622743/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-