Allow other architectures to reuse the AcpiFadtLib by extracting the Arm specific part of the table generation.
Suggested-by: Sunil V L <suni...@ventanamicro.com> Signed-off-by: Pierre Gondois <pierre.gond...@arm.com> --- .../Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf | 7 + .../Common/AcpiFadtLib/Arm/ArmFadtGenerator.c | 126 ++++++++++++++++++ .../AcpiFadtLib/Common/CommonFadtGenerator.c | 46 +++++++ .../Acpi/Common/AcpiFadtLib/FadtGenerator.c | 86 ++---------- .../Acpi/Common/AcpiFadtLib/FadtGenerator.h | 35 +++++ 5 files changed, 224 insertions(+), 76 deletions(-) create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/Arm/ArmFadtGenerator.c create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/Common/CommonFadtGenerator.c create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.h diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf index c9cd850faac0..be2af0cfd53a 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/AcpiFadtLib.inf @@ -18,6 +18,13 @@ [Defines] [Sources] FadtGenerator.c + FadtGenerator.h + +[Sources.ARM, Sources.AARCH64] + Arm/ArmFadtGenerator.c + +[Sources.IA32, Sources.X64] + Common/CommonFadtGenerator.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 000000000000..2d2afe98ab1f --- /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 <Library/AcpiLib.h> +#include <Library/DebugLib.h> +#include <Protocol/AcpiTable.h> + +// Module specific include files. +#include <AcpiTableGenerator.h> +#include <ConfigurationManagerObject.h> +#include <ConfigurationManagerHelper.h> +#include <Library/TableHelperLib.h> +#include <Protocol/ConfigurationManagerProtocol.h> +#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/Common/CommonFadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/Common/CommonFadtGenerator.c new file mode 100644 index 000000000000..d3e908358b7b --- /dev/null +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/Common/CommonFadtGenerator.c @@ -0,0 +1,46 @@ +/** @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 <Library/AcpiLib.h> +#include <Library/DebugLib.h> +#include <Protocol/AcpiTable.h> + +// Module specific include files. +#include <AcpiTableGenerator.h> +#include <ConfigurationManagerObject.h> +#include <ConfigurationManagerHelper.h> +#include <Library/TableHelperLib.h> +#include <Protocol/ConfigurationManagerProtocol.h> +#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_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 + ) +{ + // Nothing to do. + return EFI_SUCCESS; +} diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c index 470f1acfd11f..c2140ef414d2 100644 --- a/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiFadtLib/FadtGenerator.c @@ -19,22 +19,17 @@ #include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> +#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 000000000000..08ac59e00684 --- /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_ -- 2.25.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#119635): https://edk2.groups.io/g/devel/message/119635 Mute This Topic: https://groups.io/mt/106770154/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-