[PATCH 7/8] DynamicTablesPkg: Simplify AddAcpiHeader, CfgMgrGetInfo


Tomas Pilar (tpilar)
 

Simplify the methods to use the other object getter methods.
The methods no longer need CfgMgr context parameter, the getter
helpers retrieve the singleton platform protocol.

The CfgMgrGetInfo always allocates the memory that is passed to the caller.

Cc: Sami Mujawar <Sami.Mujawar@...>
Cc: Alexei Fedorov <Alexei.Fedorov@...>
Signed-off-by: Tomas Pilar <tomas@...>
---
.../DynamicTableManagerDxe.c | 20 ++--
.../Include/Library/TableHelperLib.h | 23 ++---
.../Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c | 10 +-
.../Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c | 12 +--
.../Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c | 8 +-
.../Acpi/Arm/AcpiIortLibArm/IortGenerator.c | 8 +-
.../Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c | 8 +-
.../Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c | 8 +-
.../Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c | 8 +-
.../Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c | 10 +-
.../Acpi/Arm/AcpiSratLibArm/SratGenerator.c | 8 +-
.../Common/TableHelperLib/TableHelper.c | 97 ++++---------------
.../Common/TableHelperLib/TableHelperLib.inf | 3 +-
13 files changed, 56 insertions(+), 167 deletions(-)

diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
index e27dcaf374..b194a38659 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
+++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
@@ -661,7 +661,7 @@ DynamicTableManagerDxeInitialize (
{
EFI_STATUS Status;
EDKII_CONFIGURATION_MANAGER_PROTOCOL * CfgMgrProtocol;
- CM_STD_OBJ_CONFIGURATION_MANAGER_INFO * CfgMfrInfo;
+ CM_STD_OBJ_CONFIGURATION_MANAGER_INFO * CfgMgrInfo;
EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * TableFactoryProtocol;

// Locate the Dynamic Table Factory
@@ -695,7 +695,7 @@ DynamicTableManagerDxeInitialize (
return Status;
}

- Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
+ Status = CfgMgrGetInfo (&CfgMgrInfo);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
@@ -708,15 +708,17 @@ DynamicTableManagerDxeInitialize (
DEBUG ((
DEBUG_INFO,
"INFO: Configuration Manager Version = 0x%x, OemID = %c%c%c%c%c%c\n",
- CfgMfrInfo->Revision,
- CfgMfrInfo->OemId[0],
- CfgMfrInfo->OemId[1],
- CfgMfrInfo->OemId[2],
- CfgMfrInfo->OemId[3],
- CfgMfrInfo->OemId[4],
- CfgMfrInfo->OemId[5]
+ CfgMgrInfo->Revision,
+ CfgMgrInfo->OemId[0],
+ CfgMgrInfo->OemId[1],
+ CfgMgrInfo->OemId[2],
+ CfgMgrInfo->OemId[3],
+ CfgMgrInfo->OemId[4],
+ CfgMgrInfo->OemId[5]
));

+ FreePool(CfgMgrInfo);
+
Status = ProcessAcpiTables (TableFactoryProtocol, CfgMgrProtocol);
if (EFI_ERROR (Status)) {
DEBUG ((
diff --git a/DynamicTablesPkg/Include/Library/TableHelperLib.h b/DynamicTablesPkg/Include/Library/TableHelperLib.h
index 9269e77377..0dce81827b 100644
--- a/DynamicTablesPkg/Include/Library/TableHelperLib.h
+++ b/DynamicTablesPkg/Include/Library/TableHelperLib.h
@@ -194,33 +194,26 @@ CfgMgrGetObjects (
OUT UINT32 * ItemCount OPTIONAL
);

-/** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO
+/** The CfgMgrGetInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO
object from the Configuration Manager.

- @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol
- interface.
@param [out] CfgMfrInfo Pointer to the Configuration Manager Info
object structure.

@retval EFI_SUCCESS The object is returned.
- @retval EFI_INVALID_PARAMETER The Object ID is invalid.
@retval EFI_NOT_FOUND The requested Object is not found.
- @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
- Manager is less than the Object size.
**/
EFI_STATUS
EFIAPI
-GetCgfMgrInfo (
- IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
+CfgMgrGetInfo (
OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMfrInfo
);

-/** The AddAcpiHeader function updates the ACPI header structure. It uses the
- ACPI table Generator and the Configuration Manager protocol to obtain the
- information required for constructing the header.
+/** The AddAcpiHeader function updates the ACPI header structure pointed by
+ the AcpiHeader. It utilizes the ACPI table Generator and the Configuration
+ Manager protocol to obtain any information required for constructing the
+ header.

- @param [in] CfgMgrProtocol Pointer to the Configuration Manager
- protocol interface.
@param [in] Generator Pointer to the ACPI table Generator.
@param [in,out] AcpiHeader Pointer to the ACPI table header to be
updated.
@@ -230,14 +223,10 @@ GetCgfMgrInfo (
@retval EFI_SUCCESS The ACPI table is updated successfully.
@retval EFI_INVALID_PARAMETER A parameter is invalid.
@retval EFI_NOT_FOUND The required object information is 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
AddAcpiHeader (
- IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
IN CONST ACPI_TABLE_GENERATOR * CONST Generator,
IN OUT EFI_ACPI_DESCRIPTION_HEADER * CONST AcpiHeader,
IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c
index 51c843d25f..21a7f9bf64 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c
@@ -330,12 +330,10 @@ BuildDbg2Table (
}

Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiDbg2,
- AcpiTableInfo,
- sizeof (DBG2_TABLE)
- );
+ This,
+ (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiDbg2,
+ AcpiTableInfo,
+ sizeof (DBG2_TABLE));
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c
index b748c982b2..febaca3dae 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c
@@ -528,19 +528,17 @@ BuildFadtTable (
*Table = NULL;

Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiFadt,
- AcpiTableInfo,
- sizeof (EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE)
- );
+ This,
+ (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiFadt,
+ AcpiTableInfo,
+ sizeof (EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE));
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
"ERROR: FADT: Failed to add ACPI header. Status = %r\n",
Status
));
- goto error_handler;
+ return Status;
}

// Update PmProfile Info
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c
index c109f2ac20..4af410fb5b 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c
@@ -593,13 +593,7 @@ BuildGtdtTable (
TableSize
));

- Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- &Gtdt->Header,
- AcpiTableInfo,
- TableSize
- );
+ Status = AddAcpiHeader (This, &Gtdt->Header, AcpiTableInfo, TableSize);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c
index 65d006c89e..97f86ddb30 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c
@@ -1942,13 +1942,7 @@ BuildIortTable (
TableSize
));

- Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- &Iort->Header,
- AcpiTableInfo,
- (UINT32)TableSize
- );
+ Status = AddAcpiHeader (This, &Iort->Header, AcpiTableInfo, (UINT32) TableSize);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c
index 2651ca1541..ab42c96b06 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c
@@ -641,13 +641,7 @@ BuildMadtTable (
TableSize
));

- Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- &Madt->Header,
- AcpiTableInfo,
- TableSize
- );
+ Status = AddAcpiHeader (This, &Madt->Header, AcpiTableInfo, TableSize);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c
index 1293ac8e43..a486e2297a 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c
@@ -210,13 +210,7 @@ BuildMcfgTable (
TableSize
));

- Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- &Mcfg->Header,
- AcpiTableInfo,
- TableSize
- );
+ Status = AddAcpiHeader (This, &Mcfg->Header, AcpiTableInfo, TableSize);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c
index d70fc59e75..99eb6e0929 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c
@@ -1291,13 +1291,7 @@ BuildPpttTable (
));

// Add ACPI header
- Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- &Pptt->Header,
- AcpiTableInfo,
- TableSize
- );
+ Status = AddAcpiHeader (This, &Pptt->Header, AcpiTableInfo, TableSize);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c
index 4b2580da7d..46f53f819a 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c
@@ -202,12 +202,10 @@ BuildSpcrTable (
DEBUG ((DEBUG_INFO, " Interrupt = %d\n", SerialPortInfo->Interrupt));

Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiSpcr,
- AcpiTableInfo,
- sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE)
- );
+ This,
+ (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiSpcr,
+ AcpiTableInfo,
+ sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE));
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c
index 620e2929ef..fda0837f32 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c
@@ -610,13 +610,7 @@ BuildSratTable (
TableSize
));

- Status = AddAcpiHeader (
- CfgMgrProtocol,
- This,
- &Srat->Header,
- AcpiTableInfo,
- TableSize
- );
+ Status = AddAcpiHeader (This, &Srat->Header, AcpiTableInfo, TableSize);
if (EFI_ERROR (Status)) {
DEBUG ((
DEBUG_ERROR,
diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c
index 18c0e95e0d..2f266feb9c 100644
--- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c
+++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c
@@ -392,74 +392,30 @@ CfgMgrRemoveObject (
}


-/** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO
- object from the Configuration Manager.
+/** The CfgMgrGetInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO
+ object from the Configuration Manager. The caller is responsible for freeing
+ the memory allocated by this function.

- @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol
- interface.
- @param [out] CfgMfrInfo Pointer to the Configuration Manager Info
+ @param [out] CfgMgrInfo Pointer to the Configuration Manager Info
object structure.

@retval EFI_SUCCESS The object is returned.
- @retval EFI_INVALID_PARAMETER The Object ID is invalid.
@retval EFI_NOT_FOUND The requested Object is not found.
- @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration
- Manager is less than the Object size.
+ @retval EFI_INVALID_PARAMETER CfgMgrInfo is NULL.
**/
EFI_STATUS
EFIAPI
-GetCgfMgrInfo (
- IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
- OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMfrInfo
+CfgMgrGetInfo (
+ OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMgrInfo
)
{
- EFI_STATUS Status;
- CM_OBJ_DESCRIPTOR CmObjectDesc;
-
- ASSERT (CfgMgrProtocol != NULL);
- ASSERT (CfgMfrInfo != NULL);
-
- *CfgMfrInfo = NULL;
-
- Status = CfgMgrProtocol->GetObject (
- CfgMgrProtocol,
- CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo),
- CM_NULL_TOKEN,
- &CmObjectDesc
- );
- if (EFI_ERROR (Status)) {
- DEBUG ((
- DEBUG_ERROR,
- "ERROR: Failed to Get Configuration Manager Info. Status = %r\n",
- Status
- ));
- return Status;
- }
-
- if (CmObjectDesc.ObjectId != CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo)) {
- DEBUG ((
- DEBUG_ERROR,
- "ERROR: EStdObjCfgMgrInfo: Invalid ObjectId = 0x%x, expected Id = 0x%x\n",
- CmObjectDesc.ObjectId,
- CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo)
- ));
- ASSERT (FALSE);
+ if (CfgMgrInfo == NULL) {
return EFI_INVALID_PARAMETER;
}

- if (CmObjectDesc.Size <
- (sizeof (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO) * CmObjectDesc.Count)) {
- DEBUG ((
- DEBUG_ERROR,
- "ERROR: EStdObjCfgMgrInfo: Buffer too small, size = 0x%x\n",
- CmObjectDesc.Size
- ));
- ASSERT (FALSE);
- return EFI_BAD_BUFFER_SIZE;
- }
+ *CfgMgrInfo = NULL;

- *CfgMfrInfo = (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO*)CmObjectDesc.Data;
- return Status;
+ return CfgMgrGetSimpleObject (EStdObjCfgMgrInfo, (VOID **)CfgMgrInfo);
}

/** The AddAcpiHeader function updates the ACPI header structure pointed by
@@ -467,8 +423,6 @@ GetCgfMgrInfo (
Manager protocol to obtain any information required for constructing the
header.

- @param [in] CfgMgrProtocol Pointer to the Configuration Manager
- protocol interface.
@param [in] Generator Pointer to the ACPI table Generator.
@param [in,out] AcpiHeader Pointer to the ACPI table header to be
updated.
@@ -478,14 +432,10 @@ GetCgfMgrInfo (
@retval EFI_SUCCESS The ACPI table is updated successfully.
@retval EFI_INVALID_PARAMETER A parameter is invalid.
@retval EFI_NOT_FOUND The required object information is 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
AddAcpiHeader (
- IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol,
IN CONST ACPI_TABLE_GENERATOR * CONST Generator,
IN OUT EFI_ACPI_DESCRIPTION_HEADER * CONST AcpiHeader,
IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo,
@@ -495,27 +445,17 @@ AddAcpiHeader (
EFI_STATUS Status;
CM_STD_OBJ_CONFIGURATION_MANAGER_INFO * CfgMfrInfo;

- ASSERT (CfgMgrProtocol != NULL);
- ASSERT (Generator != NULL);
- ASSERT (AcpiHeader != NULL);
- ASSERT (Length >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));
-
- if ((CfgMgrProtocol == NULL) ||
- (Generator == NULL) ||
+ if ((Generator == NULL) ||
(AcpiHeader == NULL) ||
- (Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER))
- ) {
+ (Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER))) {
+ DEBUG ((DEBUG_ERROR,
+ "ERROR: Cannot add ACPI header [Invalid Pamrameter].\n"));
return EFI_INVALID_PARAMETER;
}

- Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
+ Status = CfgMgrGetInfo (&CfgMfrInfo);
if (EFI_ERROR (Status)) {
- DEBUG ((
- DEBUG_ERROR,
- "ERROR: Failed to get Configuration Manager info. Status = %r\n",
- Status
- ));
- goto error_handler;
+ return Status;
}

// UINT32 Signature
@@ -555,8 +495,9 @@ AddAcpiHeader (
// UINT32 CreatorRevision
AcpiHeader->CreatorRevision = Generator->CreatorRevision;

-error_handler:
- return Status;
+ FreePool (CfgMfrInfo);
+
+ return EFI_SUCCESS;
}

/**
diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf
index 0fbc1fe5b2..4ee478dab9 100644
--- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf
+++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf
@@ -32,6 +32,5 @@

[Protocols]
gEfiSerialIoProtocolGuid
-
-[Guids]
+ gEdkiiConfigurationManagerProtocolGuid

--
2.25.1

Join devel@edk2.groups.io to automatically receive all group messages.