From e69e1eea2c30d986297e59c208474da11c8629da Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Mon, 10 Jun 2024 14:00:00 +0200 Subject: DynamicTablesPkg: AcpiFadtLib: Prepare to support other archs Allow other architectures to reuse the AcpiFadtLib by extracting the Arm specific part of the table generation. Suggested-by: Sunil V L Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar --- .../Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf | 7 ++ .../Acpi/Common/AcpiFadtLib/Arm/ArmFadtGenerator.c | 126 +++++++++++++++++++++ .../Acpi/Common/AcpiFadtLib/FadtGenerator.c | 86 ++------------ .../Acpi/Common/AcpiFadtLib/FadtGenerator.h | 35 ++++++ .../Acpi/Common/AcpiFadtLib/FadtGeneratorNull.c | 47 ++++++++ 5 files changed, 225 insertions(+), 76 deletions(-) create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/Arm/ArmFadtGenerator.c create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.h create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGeneratorNull.c (limited to 'DynamicTablesPkg') diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf index c9cd850faa..67c7fdbd23 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf @@ -18,6 +18,13 @@ [Sources] FadtGenerator.c + FadtGenerator.h + +[Sources.ARM, Sources.AARCH64] + Arm/ArmFadtGenerator.c + +[Sources.IA32, Sources.X64] + FadtGeneratorNull.c [Packages] MdePkg/MdePkg.dec diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/Arm/ArmFadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/Arm/ArmFadtGenerator.c new file mode 100644 index 0000000000..2d2afe98ab --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/Arm/ArmFadtGenerator.c @@ -0,0 +1,126 @@ +/** @file + ARM FADT Table Helpers + + Copyright (c) 2017 - 2023, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - ACPI 6.5 Specification, Aug 29, 2022 + +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include +#include "FadtGenerator.h" + +/** ARM Standard FADT Generator + +Requirements: + The following Configuration Manager Object(s) are required by + this Generator: + - EArmObjBootArchInfo +*/ + +/** This macro expands to a function that retrieves the Boot + Architecture Information from the Configuration Manager. +*/ +GET_OBJECT_LIST ( + EObjNameSpaceArm, + EArmObjBootArchInfo, + CM_ARM_BOOT_ARCH_INFO + ); + +/** This macro defines the FADT flag options for ARM Platforms. +*/ +#define FADT_FLAGS (EFI_ACPI_6_5_HW_REDUCED_ACPI | \ + EFI_ACPI_6_5_LOW_POWER_S0_IDLE_CAPABLE) + +/** Updates the Architecture specific information in the FADT Table. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in, out] Fadt Pointer to the constructed ACPI Table. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object was not found. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for the + requested object. +**/ +STATIC +EFI_STATUS +EFIAPI +ArmFadtBootArchInfoUpdate ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN OUT EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *Fadt + ) +{ + EFI_STATUS Status; + CM_ARM_BOOT_ARCH_INFO *BootArchInfo; + + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Fadt != NULL); + + // Get the Boot Architecture flags from the Platform Configuration Manager + Status = GetEArmObjBootArchInfo ( + CfgMgrProtocol, + CM_NULL_TOKEN, + &BootArchInfo, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "ERROR: FADT: Failed to get Boot Architecture flags. Status = %r\n", + Status + )); + return Status; + } + + DEBUG (( + DEBUG_INFO, + "FADT BootArchFlag = 0x%x\n", + BootArchInfo->BootArchFlags + )); + + Fadt->ArmBootArch = BootArchInfo->BootArchFlags; + + return Status; +} + +/** Updates the Architecture specific information in the FADT Table. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in, out] Fadt Pointer to the constructed ACPI Table. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object was not found. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for the + requested object. +**/ +EFI_STATUS +EFIAPI +FadtArchUpdate ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN OUT EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *Fadt + ) +{ + ASSERT (CfgMgrProtocol != NULL); + ASSERT (Fadt != NULL); + + Fadt->Flags = FADT_FLAGS; + + return ArmFadtBootArchInfoUpdate (CfgMgrProtocol, Fadt); +} diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c index 470f1acfd1..c2140ef414 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c @@ -19,22 +19,17 @@ #include #include #include +#include "FadtGenerator.h" -/** ARM standard FADT Generator +/** Standard FADT Generator Requirements: The following Configuration Manager Object(s) are required by this Generator: - EArchCommonObjPowerManagementProfileInfo - - EArmObjBootArchInfo - EArchCommonObjHypervisorVendorIdentity (OPTIONAL) */ -/** This macro defines the FADT flag options for ARM Platforms. -*/ -#define FADT_FLAGS (EFI_ACPI_6_5_HW_REDUCED_ACPI | \ - EFI_ACPI_6_5_LOW_POWER_S0_IDLE_CAPABLE) - /** This macro defines the valid mask for the FADT flag option if HW_REDUCED_ACPI flag in the table is set. @@ -159,13 +154,13 @@ EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE AcpiFadt = { // UINT8 Reserved1 0, // UINT32 Flags - FADT_FLAGS, + 0, // EFI_ACPI_6_5_GENERIC_ADDRESS_STRUCTURE ResetReg NULL_GAS, // UINT8 ResetValue 0, // UINT16 ArmBootArch - EFI_ACPI_6_5_ARM_PSCI_COMPLIANT, // {Template}: ARM Boot Architecture Flags + 0, // {Template}: ARM Boot Architecture Flags // UINT8 MinorRevision EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE_MINOR_REVISION, // {Template} // UINT64 XFirmwareCtrl @@ -207,15 +202,6 @@ GET_OBJECT_LIST ( CM_ARCH_COMMON_POWER_MANAGEMENT_PROFILE_INFO ); -/** This macro expands to a function that retrieves the Boot - Architecture Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjBootArchInfo, - CM_ARM_BOOT_ARCH_INFO - ); - /** This macro expands to a function that retrieves the Hypervisor Vendor ID from the Configuration Manager. */ @@ -287,58 +273,6 @@ error_handler: return Status; } -/** Updates the Boot Architecture information in the FADT Table. - - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. - - @retval EFI_SUCCESS Success. - @retval EFI_INVALID_PARAMETER A parameter is invalid. - @retval EFI_NOT_FOUND The required object was not found. - @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration - Manager is less than the Object size for the - requested object. -**/ -STATIC -EFI_STATUS -EFIAPI -FadtAddBootArchInfo ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol - ) -{ - EFI_STATUS Status; - CM_ARM_BOOT_ARCH_INFO *BootArchInfo; - - ASSERT (CfgMgrProtocol != NULL); - - // Get the Boot Architecture flags from the Platform Configuration Manager - Status = GetEArmObjBootArchInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &BootArchInfo, - NULL - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: FADT: Failed to get Boot Architecture flags. Status = %r\n", - Status - )); - goto error_handler; - } - - DEBUG (( - DEBUG_INFO, - "FADT BootArchFlag = 0x%x\n", - BootArchInfo->BootArchFlags - )); - - AcpiFadt.ArmBootArch = BootArchInfo->BootArchFlags; - -error_handler: - return Status; -} - /** Update the Hypervisor Vendor ID in the FADT Table. @param [in] CfgMgrProtocol Pointer to the Configuration Manager @@ -577,12 +511,6 @@ BuildFadtTable ( goto error_handler; } - // Update BootArch Info - Status = FadtAddBootArchInfo (CfgMgrProtocol); - if (EFI_ERROR (Status)) { - goto error_handler; - } - // Add the Hypervisor Vendor Id if present // Note if no hypervisor is present the zero bytes // will be placed in this field. @@ -623,6 +551,12 @@ BuildFadtTable ( } } + // Update Arch specific Info + Status = FadtArchUpdate (CfgMgrProtocol, &AcpiFadt); + if (EFI_ERROR (Status)) { + goto error_handler; + } + *Table = (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiFadt; error_handler: return Status; diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.h b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.h new file mode 100644 index 0000000000..08ac59e006 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.h @@ -0,0 +1,35 @@ +/** @file + FADT Table Generator + + Copyright (c) 2017 - 2023, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - ACPI 6.5 Specification, Aug 29, 2022 + +**/ + +#ifndef FADT_GENERATOR_H_ +#define FADT_GENERATOR_H_ + +/** Updates the Architecture specific information in the FADT Table. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in, out] Fadt Pointer to the constructed ACPI Table. + + @retval EFI_SUCCESS Success. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object was not found. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for the + requested object. +**/ +EFI_STATUS +EFIAPI +FadtArchUpdate ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN OUT EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *Fadt + ); + +#endif // FADT_GENERATOR_H_ diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGeneratorNull.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGeneratorNull.c new file mode 100644 index 0000000000..7868aae742 --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGeneratorNull.c @@ -0,0 +1,47 @@ +/** @file + Common FADT Table Helpers + + Copyright (c) 2017 - 2023, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - ACPI 6.5 Specification, Aug 29, 2022 + +**/ + +#include +#include +#include + +// Module specific include files. +#include +#include +#include +#include +#include +#include "FadtGenerator.h" + +/** Updates the Architecture specific information in the FADT Table. + + @param [in] CfgMgrProtocol Pointer to the Configuration Manager + Protocol Interface. + @param [in, out] Fadt Pointer to the constructed ACPI Table. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Unsupported. + @retval EFI_INVALID_PARAMETER A parameter is invalid. + @retval EFI_NOT_FOUND The required object was not found. + @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration + Manager is less than the Object size for the + requested object. +**/ +EFI_STATUS +EFIAPI +FadtArchUpdate ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, + IN OUT EFI_ACPI_6_5_FIXED_ACPI_DESCRIPTION_TABLE *Fadt + ) +{ + // Not implemented. + return EFI_UNSUPPORTED; +} -- cgit v1.2.3