public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH v3 0/5] DynamicTablesPkg: Add SMBIOS Table Generation
@ 2023-07-25 23:38 Girish Mahadevan via groups.io
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table generation Girish Mahadevan via groups.io
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Girish Mahadevan via groups.io @ 2023-07-25 23:38 UTC (permalink / raw)
  To: devel, sami.mujawar
  Cc: gmahadevan, Alexei.Fedorov, Pierre.Gondois, jbrasen, ashishsingha,
	nramirez

Patch series to add SMBIOS Table generation using DynamicTablesPkg

This patch series builds on top of the SMBIOS table dispatcher work that
dispatches and installs SMBIOS tables in the correct order.

This patches series does the following:
- Modify the existing DynamicTableManagerDxe driver to remove the Depex on
  AcpiTableProtocolGuid , instead setup notify callbacks for the ACPI and
  SMBIOS protocols. This is because not all systems mandate ACPI tables be
  present in which case SMBIOS tables won't get installed.
- Add functions to build and install single and multiple SMBIOS tables similar
  to ACPI tables.
- Modify the Smbios Table Factory code to add a Handle map to go between the 
  SMBIOS handles and the CMObject Token that is used to generate the SMBIOS
  tables.
- After installing each SMBIOS table update the Handle map with the generated
  SMBIOS handle and the CMObject Token (usually the CM Object used to generate
  the table) or a generated Token.
- Split the ACPI and SMBIOS table manager code into their own files.
- Introduce a new namepsace for SMBIOS CM objects.
- Add new generator libraries for SMBIOS table type17 (Memory Device) and type16 
  (Physical Memory Array)

This patch series can be seen at
https://github.com/tianocore/edk2/compare/master...gmahadevan:RFC/smbios-dyntables-v2-genonly

The complete patch series which includes 18 Table Generators is available here:
https://github.com/tianocore/edk2/compare/master...gmahadevan:edk2-upstream:RFC/smbios-dyntables-v2

Girish Mahadevan (5):
  DynamicTablesPkg: Add SMBIOS table generation
  DynamicTablesPkg: Split the ACPI and SMBIOS table generators
  DynamicTablesPkg: Introduce new namespace for SMBIOS Objects
  DynamicTablesPkg: Smbios Memory Device (Type 17)
  DynamicTablesPkg: Smbios Physical Memory Array (Type 16)

 .../DynamicTableFactory.h                     |   5 +
 .../DynamicTableFactoryDxe.c                  |  10 +
 .../SmbiosTableFactory/SmbiosTableFactory.c   | 108 +++
 .../DynamicTableManagerDxe/AcpiTableBuilder.c | 798 ++++++++++++++++++
 .../DynamicTableManagerDxe.c                  | 781 +----------------
 .../DynamicTableManagerDxe.inf                |   5 +-
 .../SmbiosTableBuilder.c                      | 603 +++++++++++++
 .../Include/ConfigurationManagerObject.h      |  14 +-
 .../Protocol/DynamicTableFactoryProtocol.h    |  10 +
 .../Include/SmbiosNameSpaceObjects.h          | 131 +++
 .../Include/SmbiosTableGenerator.h            | 204 ++++-
 .../SmbiosType16Lib/SmbiosType16Generator.c   | 361 ++++++++
 .../SmbiosType16Lib/SmbiosType16Lib.inf       |  35 +
 .../SmbiosType17Lib/SmbiosType17Generator.c   | 445 ++++++++++
 .../SmbiosType17Lib/SmbiosType17Lib.inf       |  36 +
 MdePkg/Include/IndustryStandard/SmBios.h      |   8 +
 16 files changed, 2805 insertions(+), 749 deletions(-)
 create mode 100644 DynamicTablesPkg/Drivers/DynamicTableManagerDxe/AcpiTableBuilder.c
 create mode 100644 DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
 create mode 100644 DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
 create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c
 create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf
 create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c
 create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf

-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107254): https://edk2.groups.io/g/devel/message/107254
Mute This Topic: https://groups.io/mt/100361558/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table generation
  2023-07-25 23:38 [edk2-devel] [PATCH v3 0/5] DynamicTablesPkg: Add SMBIOS Table Generation Girish Mahadevan via groups.io
@ 2023-07-25 23:38 ` Girish Mahadevan via groups.io
  2023-08-24 19:02   ` Jose Marinho
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 2/5] DynamicTablesPkg: Split the ACPI and SMBIOS table generators Girish Mahadevan via groups.io
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Girish Mahadevan via groups.io @ 2023-07-25 23:38 UTC (permalink / raw)
  To: devel, sami.mujawar
  Cc: gmahadevan, Alexei.Fedorov, Pierre.Gondois, jbrasen, ashishsingha,
	nramirez

Add the SMBIOS Table generator code to the DynamicTablesPkg.

This change includes adding new logic to the DynamicTableManager
to process and add SMBIOS tables and augmenting the existing SMBIOS
Factory generator to include installing multiple SMBIOS tables .
Also included is running the SMBIOS and ACPI table generation as part
of the SMBIOS and ACPI protocol GUID callback notifications respectively.

Change-Id: Icc090108c16e87657260af6daf856f3d69b602e3
Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
---
 .../DynamicTableFactory.h                     |   5 +
 .../DynamicTableFactoryDxe.c                  |  10 +
 .../SmbiosTableFactory/SmbiosTableFactory.c   | 108 +++
 .../DynamicTableManagerDxe.c                  | 677 +++++++++++++++++-
 .../DynamicTableManagerDxe.inf                |   3 +-
 .../Protocol/DynamicTableFactoryProtocol.h    |  10 +
 .../Include/SmbiosTableGenerator.h            | 204 +++++-
 MdePkg/Include/IndustryStandard/SmBios.h      |   8 +
 8 files changed, 994 insertions(+), 31 deletions(-)

diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h
index b160dcf8ad..20e438ea70 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h
+++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h
@@ -49,6 +49,11 @@ typedef struct DynamicTableFactoryInfo {
         CustomDtTableGeneratorList[FixedPcdGet16 (
                                  PcdMaxCustomDTGenerators
                                  )];
+
+  /// An array for holding a map of SMBIOS handles and the CM Object
+  /// token used to build the SMBIOS record.
+  SMBIOS_HANDLE_MAP
+        SmbiosHandleMap[MAX_SMBIOS_HANDLES];
 } EDKII_DYNAMIC_TABLE_FACTORY_INFO;
 
 /** Return a pointer to the ACPI table generator.
diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c
index 6d6d3fa746..577cdb576e 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c
+++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c
@@ -1,6 +1,7 @@
 /** @file
   Dynamic Table Factory Dxe
 
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
   Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -44,6 +45,9 @@ EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  DynamicTableFactoryProtocol = {
   GetDtTableGenerator,
   RegisterDtTableGenerator,
   DeregisterDtTableGenerator,
+  AddSmbiosHandle,
+  FindSmbiosHandle,
+  FindSmbiosHandleEx,
   &TableFactoryInfo
 };
 
@@ -65,6 +69,12 @@ DynamicTableFactoryDxeInitialize (
   )
 {
   EFI_STATUS  Status;
+  UINTN       Idx;
+
+  for (Idx = 0; Idx < MAX_SMBIOS_HANDLES; Idx++) {
+    TableFactoryInfo.SmbiosHandleMap[Idx].SmbiosTblHandle = SMBIOS_HANDLE_PI_RESERVED;
+    TableFactoryInfo.SmbiosHandleMap[Idx].SmbiosCmToken   = 0;
+  }
 
   Status = gBS->InstallProtocolInterface (
                   &ImageHandle,
diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c
index 87795919f8..b928c28a14 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c
+++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/SmbiosTableFactory.c
@@ -1,6 +1,7 @@
 /** @file
   SMBIOS Table Factory
 
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
   Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -12,6 +13,7 @@
 #include <IndustryStandard/SmBios.h>
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
 #include <Library/DebugLib.h>
 
 // Module specific include files.
@@ -24,6 +26,71 @@
 
 extern EDKII_DYNAMIC_TABLE_FACTORY_INFO  TableFactoryInfo;
 
+/** Add a new entry to the SMBIOS table Map.
+
+  @param [in]  Smbios         SMBIOS Protocol pointer.
+  @param [in]  SmbiosHandle   SMBIOS Handle to be added, if the value SMBIOS_HANDLE_PI_RESERVED
+                              is passed then a new SmbiosHandle is assigned.
+  @param [in]  CmObjectToken  CmObjectToken of the CM_OBJECT used to build the SMBIOS Table
+  @param [in]  GeneratorId    Smbios Table Generator Id.
+
+  @retval EFI_SUCCESS               Successfully added/generated the handle.
+  @retval EFI_OUT_OF_RESOURCESNULL  Failure to add/generate the handle.
+**/
+EFI_STATUS
+EFIAPI
+AddSmbiosHandle (
+  IN EFI_SMBIOS_PROTOCOL         *Smbios,
+  IN SMBIOS_HANDLE               *SmbiosHandle,
+  IN CM_OBJECT_TOKEN             CmObjectToken,
+  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId
+  )
+{
+  EFI_STATUS  Status;
+  UINTN       Index;
+
+  Status = EFI_OUT_OF_RESOURCES;
+
+  for (Index = 0; Index < MAX_SMBIOS_HANDLES; Index++) {
+    if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle == SMBIOS_HANDLE_PI_RESERVED) {
+      TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle   = *SmbiosHandle;
+      TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken     = CmObjectToken;
+      TableFactoryInfo.SmbiosHandleMap[Index].SmbiosGeneratorId = GeneratorId;
+      Status                                                    = EFI_SUCCESS;
+      break;
+    }
+  }
+
+  return Status;
+}
+
+/** Return a pointer to the SMBIOS table Map.
+
+  @param [in]  GeneratorId  The CmObjectToken to look up an SMBIOS Handle.
+
+  @retval SMBIOS_HANDLE_MAP if the CmObjectToken is found.
+  @retval NULL if not found.
+**/
+SMBIOS_HANDLE_MAP *
+EFIAPI
+FindSmbiosHandle (
+  CM_OBJECT_TOKEN  CmObjectToken
+  )
+{
+  UINTN              Index;
+  SMBIOS_HANDLE_MAP  *SmbiosHandleMap;
+
+  SmbiosHandleMap = NULL;
+  for (Index = 0; Index < MAX_SMBIOS_HANDLES; Index++) {
+    if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken == CmObjectToken) {
+      SmbiosHandleMap = &TableFactoryInfo.SmbiosHandleMap[Index];
+      break;
+    }
+  }
+
+  return SmbiosHandleMap;
+}
+
 /** Return a pointer to the SMBIOS table generator.
 
   @param [in]  This         Pointer to the Dynamic Table Factory Protocol.
@@ -229,3 +296,44 @@ DeregisterSmbiosTableGenerator (
   DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description));
   return EFI_SUCCESS;
 }
+
+/** Find and return SMBIOS handle based on associated CM object token.
+
+  @param [in]  GeneratorId     SMBIOS generator ID used to build the SMBIOS Table.
+  @param [in]  CmObjectToken   Token of the CM_OBJECT used to build the SMBIOS Table.
+
+  @return  SMBIOS handle of the table associated with SmbiosGeneratorId and
+           CmObjectToken if found. Otherwise, returns 0xFFFF.
+**/
+UINT16
+EFIAPI
+FindSmbiosHandleEx (
+  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId,
+  IN  CM_OBJECT_TOKEN            CmObjToken
+  )
+{
+  SMBIOS_HANDLE_MAP  *HandleMap;
+
+  if (CmObjToken == CM_NULL_TOKEN) {
+    return SMBIOS_HANDLE_INVALID;
+  }
+
+  HandleMap = FindSmbiosHandle (CmObjToken);
+  if (HandleMap == NULL) {
+    return SMBIOS_HANDLE_INVALID;
+  }
+
+  if (HandleMap->SmbiosGeneratorId != GeneratorId) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Expect ID %d but get %d\n",
+      __FUNCTION__,
+      GeneratorId,
+      HandleMap->SmbiosGeneratorId
+      ));
+    ASSERT (FALSE);
+    return SMBIOS_HANDLE_INVALID;
+  }
+
+  return HandleMap->SmbiosTblHandle;
+}
diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
index 1e9b811c40..26aa9b55cf 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
+++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
@@ -8,10 +8,13 @@
 **/
 
 #include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
 #include <Library/PcdLib.h>
 #include <Library/UefiBootServicesTableLib.h>
 #include <Protocol/AcpiSystemDescriptionTable.h>
 #include <Protocol/AcpiTable.h>
+#include <Protocol/Smbios.h>
+#include <Library/BaseMemoryLib.h>
 
 // Module specific include files.
 #include <AcpiTableGenerator.h>
@@ -22,6 +25,7 @@
 #include <Protocol/ConfigurationManagerProtocol.h>
 #include <Protocol/DynamicTableFactoryProtocol.h>
 #include <SmbiosTableGenerator.h>
+#include <SmbiosTableDispatcher.h>
 
 ///
 /// Bit definitions for acceptable ACPI table presence formats.
@@ -84,6 +88,18 @@ GET_OBJECT_LIST (
   CM_STD_OBJ_ACPI_TABLE_INFO
   )
 
+/** This macro expands to a function that retrieves the SMBIOS Table
+    List from the Configuration Manager.
+*/
+GET_OBJECT_LIST (
+  EObjNameSpaceStandard,
+  EStdObjSmbiosTableList,
+  CM_STD_OBJ_SMBIOS_TABLE_INFO
+  )
+
+STATIC VOID *AcpiTableProtocolRegistration;
+STATIC VOID  *SmbiosProtocolRegistration;
+
 /** A helper function to build and install a single ACPI table.
 
   This is a helper function that invokes the Table generator interface
@@ -530,6 +546,490 @@ VerifyMandatoryTablesArePresent (
   return Status;
 }
 
+/** A helper function to build and install an SMBIOS table.
+
+  This is a helper function that invokes the Table generator interface
+  for building an SMBIOS table. It uses the SmbiosProtocol to install the
+  table, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  SmbiosProtocol       Pointer to the SMBIOS protocol.
+  @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+BuildAndInstallSingleSmbiosTable (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN CONST SMBIOS_TABLE_GENERATOR                *CONST  Generator,
+  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
+  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
+  )
+{
+  EFI_STATUS         Status;
+  EFI_STATUS         Status1;
+  SMBIOS_STRUCTURE   *SmbiosTable;
+  CM_OBJECT_TOKEN    CmObjToken;
+  EFI_SMBIOS_HANDLE  TableHandle;
+
+  SmbiosTable = NULL;
+  Status      = Generator->BuildSmbiosTable (
+                             Generator,
+                             TableFactoryProtocol,
+                             SmbiosTableInfo,
+                             CfgMgrProtocol,
+                             &SmbiosTable,
+                             &CmObjToken
+                             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Build Table." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      SmbiosTableInfo->TableGeneratorId,
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  if (SmbiosTable == NULL) {
+    Status = EFI_NOT_FOUND;
+    goto exit_handler;
+  }
+
+  TableHandle = SMBIOS_HANDLE_PI_RESERVED;
+  // Install SMBIOS table
+  Status = SmbiosProtocol->Add (
+                             SmbiosProtocol,
+                             NULL,
+                             &TableHandle,
+                             SmbiosTable
+                             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Install SMBIOS Table. Status = %r\n",
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  Status = TableFactoryProtocol->AddSmbiosHandle (
+                                   SmbiosProtocol,
+                                   &TableHandle,
+                                   CmObjToken,
+                                   SmbiosTableInfo->TableGeneratorId
+                                   );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Add SMBIOS Handle. Status = %r\n",
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: SMBIOS Table installed. Status = %r\n",
+    Status
+    ));
+
+exit_handler:
+  // Free any resources allocated for generating the tables.
+  if (Generator->FreeTableResources != NULL) {
+    Status1 = Generator->FreeTableResources (
+                           Generator,
+                           TableFactoryProtocol,
+                           SmbiosTableInfo,
+                           CfgMgrProtocol,
+                           &SmbiosTable
+                           );
+    if (EFI_ERROR (Status1)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Free Table Resources." \
+        "TableGeneratorId = 0x%x. Status = %r\n",
+        SmbiosTableInfo->TableGeneratorId,
+        Status1
+        ));
+    }
+
+    // Return the first error status in case of failure
+    if (!EFI_ERROR (Status)) {
+      Status = Status1;
+    }
+  }
+
+  return Status;
+}
+
+/** A helper function to build and install multiple SMBIOS tables.
+
+  This is a helper function that invokes the Table generator interface
+  for building SMBIOS tables. It uses the SmbiosProtocol to install the
+  tables, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  Generator            Pointer to the SmbiosTable generator.
+  @param [in]  SmbiosProtocol       Pointer to the Smbios protocol.
+  @param [in]  AcpiTableInfo        Pointer to the SMBIOS table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+BuildAndInstallMultipleSmbiosTables (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN CONST SMBIOS_TABLE_GENERATOR                *CONST  Generator,
+  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
+  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
+  )
+{
+  EFI_STATUS         Status;
+  EFI_STATUS         Status1;
+  SMBIOS_STRUCTURE   **SmbiosTable;
+  CM_OBJECT_TOKEN    *CmObjToken;
+  EFI_SMBIOS_HANDLE  TableHandle;
+  UINTN              TableCount;
+  UINTN              Index;
+
+  TableCount = 0;
+  Status     = Generator->BuildSmbiosTableEx (
+                            Generator,
+                            TableFactoryProtocol,
+                            SmbiosTableInfo,
+                            CfgMgrProtocol,
+                            &SmbiosTable,
+                            &CmObjToken,
+                            &TableCount
+                            );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Build Table." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      SmbiosTableInfo->TableGeneratorId,
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  if ((SmbiosTable == NULL) || (TableCount == 0)) {
+    Status = EFI_NOT_FOUND;
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: TableCount %u SmbiosTable %p \n",
+      __FUNCTION__,
+      TableCount,
+      SmbiosTable
+      ));
+    goto exit_handler;
+  }
+
+  for (Index = 0; Index < TableCount; Index++) {
+    TableHandle = SMBIOS_HANDLE_PI_RESERVED;
+
+    // Install SMBIOS table
+    Status = SmbiosProtocol->Add (
+                               SmbiosProtocol,
+                               NULL,
+                               &TableHandle,
+                               SmbiosTable[Index]
+                               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Install SMBIOS Table. Status = %r\n",
+        Status
+        ));
+      // Free any allocated resources.
+      goto exit_handler;
+    }
+
+    Status = TableFactoryProtocol->AddSmbiosHandle (
+                                     SmbiosProtocol,
+                                     &TableHandle,
+                                     CmObjToken[Index],
+                                     SmbiosTableInfo->TableGeneratorId
+                                     );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Add SMBIOS Handle. Status = %r\n",
+        Status
+        ));
+      // Free any allocated resources.
+      goto exit_handler;
+    }
+
+    DEBUG ((
+      DEBUG_INFO,
+      "INFO: SMBIOS Table installed. Status = %r\n",
+      Status
+      ));
+  }
+
+exit_handler:
+  // Free any resources allocated for generating the tables.
+  if (Generator->FreeTableResourcesEx != NULL) {
+    Status1 = Generator->FreeTableResourcesEx (
+                           Generator,
+                           TableFactoryProtocol,
+                           SmbiosTableInfo,
+                           CfgMgrProtocol,
+                           &SmbiosTable,
+                           &CmObjToken,
+                           TableCount
+                           );
+    if (EFI_ERROR (Status1)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Free Table Resources." \
+        "TableGeneratorId = 0x%x. Status = %r\n",
+        SmbiosTableInfo->TableGeneratorId,
+        Status1
+        ));
+    }
+
+    // Return the first error status in case of failure
+    if (!EFI_ERROR (Status)) {
+      Status = Status1;
+    }
+  }
+
+  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
+  return Status;
+}
+
+/** A helper function to invoke a Table generator
+
+  This is a helper function that invokes the Table generator interface
+  for building an SMBIOS table. It uses the SmbiosProtocol to install the
+  table, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  SmbiosProtocol       Pointer to the SMBIOS protocol.
+  @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+EFI_STATUS
+EFIAPI
+BuildAndInstallSmbiosTable (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
+  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
+  )
+{
+  EFI_STATUS                    Status;
+  CONST SMBIOS_TABLE_GENERATOR  *Generator;
+
+  ASSERT (TableFactoryProtocol != NULL);
+  ASSERT (CfgMgrProtocol != NULL);
+  ASSERT (SmbiosProtocol != NULL);
+  ASSERT (SmbiosTableInfo != NULL);
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: EStdObjSmbiosTableList: Address = 0x%p," \
+    " TableGeneratorId = 0x%x\n",
+    SmbiosTableInfo,
+    SmbiosTableInfo->TableGeneratorId
+    ));
+
+  Generator = NULL;
+  Status    = TableFactoryProtocol->GetSmbiosTableGenerator (
+                                      TableFactoryProtocol,
+                                      SmbiosTableInfo->TableGeneratorId,
+                                      &Generator
+                                      );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Table Generator not found." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      SmbiosTableInfo->TableGeneratorId,
+      Status
+      ));
+    return Status;
+  }
+
+  if (Generator == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: Generator found : %s\n",
+    Generator->Description
+    ));
+
+  if (Generator->BuildSmbiosTableEx != NULL) {
+    Status = BuildAndInstallMultipleSmbiosTables (
+               TableFactoryProtocol,
+               CfgMgrProtocol,
+               Generator,
+               SmbiosProtocol,
+               SmbiosTableInfo
+               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to find build and install SMBIOS Tables." \
+        " Status = %r\n",
+        Status
+        ));
+    }
+  } else if (Generator->BuildSmbiosTable != NULL) {
+    Status = BuildAndInstallSingleSmbiosTable (
+               TableFactoryProtocol,
+               CfgMgrProtocol,
+               Generator,
+               SmbiosProtocol,
+               SmbiosTableInfo
+               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to find build and install SMBIOS Table." \
+        " Status = %r\n",
+        Status
+        ));
+    }
+  } else {
+    Status = EFI_INVALID_PARAMETER;
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Table Generator does not implement the" \
+      "SMBIOS_TABLE_GENERATOR_BUILD_TABLE  interface." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      SmbiosTableInfo->TableGeneratorId,
+      Status
+      ));
+  }
+
+  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
+  return Status;
+}
+
+/** Generate and install SMBIOS tables.
+
+  The function gathers the information necessary for installing the
+  SMBIOS tables from the Configuration Manager, invokes the generators
+  and installs them (via BuildAndInstallAcpiTable).
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+
+  @retval EFI_SUCCESS   Success.
+  @retval EFI_NOT_FOUND If a mandatory table or a generator is not found.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ProcessSmbiosTables (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol
+  )
+{
+  EFI_STATUS                    Status;
+  EFI_SMBIOS_PROTOCOL           *SmbiosProtocol;
+  CM_STD_OBJ_SMBIOS_TABLE_INFO  *SmbiosTableInfo;
+  UINT32                        SmbiosTableCount;
+
+  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&SmbiosProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "Could not locate SMBIOS protocol.  %r\n", Status));
+    return Status;
+  }
+
+  Status = GetEStdObjSmbiosTableList (
+             CfgMgrProtocol,
+             CM_NULL_TOKEN,
+             &SmbiosTableInfo,
+             &SmbiosTableCount
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to get SMBIOS Table List. Status = %r\n",
+      Status
+      ));
+    return Status;
+  }
+
+  if (SmbiosTableCount == 0) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: EStdObjSmbiosTableList: SmbiosTableCount = %d\n",
+      SmbiosTableCount
+      ));
+    return EFI_NOT_FOUND;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: EStdObjSmbiosTableList: SmbiosTableCount = %d\n",
+    SmbiosTableCount
+    ));
+
+  InitSmbiosTableDispatcher (SmbiosTableInfo, SmbiosTableCount);
+
+  Status = DispatchSmbiosTables (
+             TableFactoryProtocol,
+             CfgMgrProtocol,
+             SmbiosProtocol,
+             SmbiosTableInfo,
+             SmbiosTableCount
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to install SMBIOS Tables.Status = %r\n",
+      Status
+      ));
+  }
+
+  return Status;
+}
+
 /** Generate and install ACPI tables.
 
   The function gathers the information necessary for installing the
@@ -701,30 +1201,20 @@ ProcessAcpiTables (
   return Status;
 }
 
-/** Entrypoint of Dynamic Table Manager Dxe.
+/** Callback function for ACPI Protocol .
 
-  The Dynamic Table Manager uses the Configuration Manager Protocol
-  to get the list of ACPI and SMBIOS tables to install. For each table
-  in the list it requests the corresponding ACPI/SMBIOS table factory for
-  a generator capable of building the ACPI/SMBIOS table.
-  If a suitable table generator is found, it invokes the generator interface
-  to build the table. The Dynamic Table Manager then installs the
-  table and invokes another generator interface to free any resources
-  allocated for building the table.
+  Callback function for ACPI protocol that installs ACPI tables
 
-  @param  ImageHandle
-  @param  SystemTable
+  @param  Event
+  @param  Context
 
-  @retval EFI_SUCCESS           Success.
-  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
-  @retval EFI_NOT_FOUND         Required interface/object was not found.
-  @retval EFI_INVALID_PARAMETER Some parameter is incorrect/invalid.
+  @retval None
 **/
-EFI_STATUS
-EFIAPI
-DynamicTableManagerDxeInitialize (
-  IN  EFI_HANDLE        ImageHandle,
-  IN  EFI_SYSTEM_TABLE  *SystemTable
+STATIC
+VOID
+AcpiTableProtocolReady (
+  IN  EFI_EVENT  Event,
+  IN  VOID       *Context
   )
 {
   EFI_STATUS                             Status;
@@ -745,7 +1235,7 @@ DynamicTableManagerDxeInitialize (
       " Status = %r\n",
       Status
       ));
-    return Status;
+    return;
   }
 
   // Locate the Configuration Manager for the Platform
@@ -760,7 +1250,7 @@ DynamicTableManagerDxeInitialize (
       "ERROR: Failed to find Configuration Manager protocol. Status = %r\n",
       Status
       ));
-    return Status;
+    return;
   }
 
   Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
@@ -770,7 +1260,7 @@ DynamicTableManagerDxeInitialize (
       "ERROR: Failed to get Configuration Manager info. Status = %r\n",
       Status
       ));
-    return Status;
+    return;
   }
 
   DEBUG ((
@@ -793,6 +1283,147 @@ DynamicTableManagerDxeInitialize (
       Status
       ));
   }
+}
+
+/** Callback function for SMBIOS Protocol .
+
+  Callback function for SMBIOS protocol that installs SMBIOS tables
+  that use the DynamicTables Package.
+
+  @param  Event
+  @param  Context
+
+  @retval None
+**/
+STATIC
+VOID
+SmbiosProtocolReady (
+  IN  EFI_EVENT  Event,
+  IN  VOID       *Context
+  )
+{
+  EFI_STATUS                             Status;
+  EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CfgMgrProtocol;
+  CM_STD_OBJ_CONFIGURATION_MANAGER_INFO  *CfgMfrInfo;
+  EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *TableFactoryProtocol;
+
+  // Locate the Dynamic Table Factory
+  Status = gBS->LocateProtocol (
+                  &gEdkiiDynamicTableFactoryProtocolGuid,
+                  NULL,
+                  (VOID **)&TableFactoryProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to find Dynamic Table Factory protocol." \
+      " Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  // Locate the Configuration Manager for the Platform
+  Status = gBS->LocateProtocol (
+                  &gEdkiiConfigurationManagerProtocolGuid,
+                  NULL,
+                  (VOID **)&CfgMgrProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to find Configuration Manager protocol. Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to get Configuration Manager info. Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  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]
+    ));
+
+  Status = ProcessSmbiosTables (TableFactoryProtocol, CfgMgrProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: SMBIOS Table processing failure. Status = %r\n",
+      Status
+      ));
+  }
+}
+
+/** Entrypoint of Dynamic Table Manager Dxe.
+
+  The Dynamic Table Manager uses the Configuration Manager Protocol
+  to get the list of ACPI and SMBIOS tables to install. For each table
+  in the list it requests the corresponding ACPI/SMBIOS table factory for
+  a generator capable of building the ACPI/SMBIOS table.
+  If a suitable table generator is found, it invokes the generator interface
+  to build the table. The Dynamic Table Manager then installs the
+  table and invokes another generator interface to free any resources
+  allocated for building the table.
+
+  @param  ImageHandle
+  @param  SystemTable
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
+  @retval EFI_NOT_FOUND         Required interface/object was not found.
+  @retval EFI_INVALID_PARAMETER Some parameter is incorrect/invalid.
+**/
+EFI_STATUS
+EFIAPI
+DynamicTableManagerDxeInitialize (
+  IN  EFI_HANDLE        ImageHandle,
+  IN  EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+  EFI_EVENT   AcpiEvent;
+  EFI_EVENT   SmbiosEvent;
+
+  AcpiEvent = EfiCreateProtocolNotifyEvent (
+                &gEfiAcpiTableProtocolGuid,
+                TPL_CALLBACK,
+                AcpiTableProtocolReady,
+                NULL,
+                &AcpiTableProtocolRegistration
+                );
+  if (AcpiEvent == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to ACPI create protocol event\r\n", __FUNCTION__));
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  SmbiosEvent = EfiCreateProtocolNotifyEvent (
+                  &gEfiSmbiosProtocolGuid,
+                  TPL_CALLBACK,
+                  SmbiosProtocolReady,
+                  NULL,
+                  &SmbiosProtocolRegistration
+                  );
+  if (SmbiosEvent == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a: Failed to SMBIOS create protocol event\r\n", __FUNCTION__));
+    gBS->CloseEvent (AcpiEvent);
+    return EFI_OUT_OF_RESOURCES;
+  }
 
   return Status;
 }
diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf
index b09272d883..3beab7420a 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf
+++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf
@@ -33,6 +33,7 @@
 [LibraryClasses]
   PrintLib
   TableHelperLib
+  UefiLib
   UefiBootServicesTableLib
   UefiDriverEntryPoint
 
@@ -42,12 +43,12 @@
 [Protocols]
   gEfiAcpiTableProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED
   gEfiAcpiSdtProtocolGuid                       # PROTOCOL ALWAYS_CONSUMED
+  gEfiSmbiosProtocolGuid                        # PROTOCOL ALWAYS_CONSUMED
 
   gEdkiiConfigurationManagerProtocolGuid        # PROTOCOL ALWAYS_CONSUMED
   gEdkiiDynamicTableFactoryProtocolGuid         # PROTOCOL ALWAYS_CONSUMED
 
 [Depex]
-  gEfiAcpiTableProtocolGuid AND
   gEdkiiConfigurationManagerProtocolGuid AND
   gEdkiiDynamicTableFactoryProtocolGuid
 
diff --git a/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h b/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h
index b11fc0c9f1..e298236311 100644
--- a/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h
+++ b/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h
@@ -1,5 +1,6 @@
 /** @file
 
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
   Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -239,6 +240,15 @@ typedef struct DynamicTableFactoryProtocol {
   EDKII_DYNAMIC_TABLE_FACTORY_DEREGISTER_DT_TABLE_GENERATOR
                                                             DeregisterDtTableGenerator;
 
+  EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_ADD_HANDLE
+                                                            AddSmbiosHandle;
+
+  EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE
+                                                            GetSmbiosHandle;
+
+  EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE_EX
+                                                            GetSmbiosHandleEx;
+
   /** Pointer to the data structure that holds the
       list of registered table generators
   */
diff --git a/DynamicTablesPkg/Include/SmbiosTableGenerator.h b/DynamicTablesPkg/Include/SmbiosTableGenerator.h
index 934d56c90d..a9f8199a3b 100644
--- a/DynamicTablesPkg/Include/SmbiosTableGenerator.h
+++ b/DynamicTablesPkg/Include/SmbiosTableGenerator.h
@@ -1,5 +1,6 @@
 /** @file
 
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
   Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -10,7 +11,7 @@
 #define SMBIOS_TABLE_GENERATOR_H_
 
 #include <IndustryStandard/SmBios.h>
-
+#include <Protocol/Smbios.h>
 #include <TableGenerator.h>
 
 #pragma pack(1)
@@ -121,12 +122,21 @@ typedef enum StdSmbiosTableGeneratorId {
             ETableGeneratorNameSpaceStd,        \
             TableId                             \
             )
+#define MAX_SMBIOS_HANDLES  (255)
 
 /** Forward declarations.
 */
 typedef struct ConfigurationManagerProtocol EDKII_CONFIGURATION_MANAGER_PROTOCOL;
 typedef struct CmStdObjSmbiosTableInfo      CM_STD_OBJ_SMBIOS_TABLE_INFO;
 typedef struct SmbiosTableGenerator         SMBIOS_TABLE_GENERATOR;
+typedef struct DynamicTableFactoryProtocol  EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL;
+typedef UINTN                               CM_OBJECT_TOKEN;
+
+typedef struct SmbiosHandleCmObjMap {
+  SMBIOS_TABLE_GENERATOR_ID    SmbiosGeneratorId;
+  SMBIOS_HANDLE                SmbiosTblHandle;
+  CM_OBJECT_TOKEN              SmbiosCmToken;
+} SMBIOS_HANDLE_MAP;
 
 /** This function pointer describes the interface to SMBIOS table build
     functions provided by the SMBIOS table generator and called by the
@@ -143,9 +153,11 @@ typedef struct SmbiosTableGenerator         SMBIOS_TABLE_GENERATOR;
 **/
 typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLE) (
   IN  CONST SMBIOS_TABLE_GENERATOR                        *Generator,
+  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
   IN        CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo,
   IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
-  OUT       SMBIOS_STRUCTURE                              **Table
+  OUT       SMBIOS_STRUCTURE                              **Table,
+  OUT       CM_OBJECT_TOKEN                               *CmObjToken
   );
 
 /** This function pointer describes the interface to used by the
@@ -163,32 +175,147 @@ typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLE) (
 **/
 typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_FREE_TABLE) (
   IN  CONST SMBIOS_TABLE_GENERATOR                        *Generator,
+  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
   IN  CONST CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo,
   IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
   IN        SMBIOS_STRUCTURE                              **Table
   );
 
+/** This function pointer describes the interface to SMBIOS table build
+    functions provided by the SMBIOS table generator and called by the
+    Table Manager to build an SMBIOS table.
+
+  @param [in]  Generator       Pointer to the SMBIOS table generator.
+  @param [in]  SmbiosTableInfo Pointer to the SMBIOS table information.
+  @param [in]  CfgMgrProtocol  Pointer to the Configuration Manager
+                               Protocol interface.
+  @param [out] Table           Pointer to the generated SMBIOS table.
+
+  @return EFI_SUCCESS  If the table is generated successfully or other
+                        failure codes as returned by the generator.
+**/
+typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX) (
+  IN  CONST SMBIOS_TABLE_GENERATOR                         *Generator,
+  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *CONST  TableFactoryProtocol,
+  IN        CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST   SmbiosTableInfo,
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST   CfgMgrProtocol,
+  OUT       SMBIOS_STRUCTURE                               ***Table,
+  OUT       CM_OBJECT_TOKEN                                **CmObjectToken,
+  OUT       UINTN                                 *CONST   TableCount
+  );
+
+/** This function pointer describes the interface to used by the
+    Table Manager to give the generator an opportunity to free
+    any resources allocated for building the SMBIOS table.
+
+  @param [in]  Generator       Pointer to the SMBIOS table generator.
+  @param [in]  SmbiosTableInfo Pointer to the SMBIOS table information.
+  @param [in]  CfgMgrProtocol  Pointer to the Configuration Manager
+                               Protocol interface.
+  @param [in]  Table           Pointer to the generated SMBIOS table.
+
+  @return  EFI_SUCCESS If freed successfully or other failure codes
+                        as returned by the generator.
+**/
+typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_FREE_TABLEEX) (
+  IN  CONST SMBIOS_TABLE_GENERATOR                        *Generator,
+  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN  CONST CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo,
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN        SMBIOS_STRUCTURE                              ***Table,
+  IN        CM_OBJECT_TOKEN                               **CmObjectToken,
+  IN  CONST UINTN                                         TableCount
+  );
+
+/** This function pointer describes the interface to used by the
+    Table Manager to give the generator an opportunity to add
+    an SMBIOS Handle.
+
+  This function is called by the Dynamic Table Manager to add a newly added
+  SMBIOS Table OR it can be called by an SMBIOS Table generator to create
+  and add a new SMBIOS Handle if there is a reference to another table and
+  if there is a generator for that table that hasn't been called yet.
+
+  @param [in]  Smbios         Pointer to the SMBIOS protocol.
+  @param [in]  SmbiosHandle   Pointer to an SMBIOS handle (either generated by
+                              SmbiosDxe Driver or  SMBIOS_HANDLE_PI_RESERVED
+                              if a handle needs to be generated).
+  @param [in]  CmObjectToken  The CM Object token for that is used to generate
+                              SMBIOS record.
+  @param [in]  GeneratorId    The SMBIOS table generator Id.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_OUT_OF_RESOURCES  Unable to add the handle.
+  @retval EFI_NOT_FOUND         The requested generator is not found
+                                in the list of registered generators.
+**/
+typedef EFI_STATUS (EFIAPI *EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_ADD_HANDLE)(
+  IN  EFI_SMBIOS_PROTOCOL        *Smbios,
+  IN  SMBIOS_HANDLE              *SmbiosHandle,
+  IN  CM_OBJECT_TOKEN            CmObjectToken,
+  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId
+  );
+
+/** This function pointer describes the interface to used by the
+    Table Manager to give the generator an opportunity to find
+    an SMBIOS Handle.
+
+  This function is called by the SMBIOS table generator to find an SMBIOS
+  handle needed as part of generating an SMBIOS Table.
+
+  @param [in]  CmObjectToken    The CM Object token used to generate the SMBIOS
+                                record.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_NOT_FOUND         The requested generator is not found
+                                in the list of registered generators.
+**/
+typedef SMBIOS_HANDLE_MAP *(EFIAPI *EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE)(
+  IN  CM_OBJECT_TOKEN      CmObjectToken
+  );
+
+/** Find and return SMBIOS handle based on associated CM object token.
+
+  @param [in]  GeneratorId     SMBIOS generator ID used to build the SMBIOS Table.
+  @param [in]  CmObjectToken   Token of the CM_OBJECT used to build the SMBIOS Table.
+
+  @return  SMBIOS handle of the table associated with SmbiosTableId and
+           CmObjectToken if found. Otherwise, returns 0xFFFF.
+**/
+typedef UINT16 (EFIAPI *EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE_EX)(
+  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId,
+  IN  CM_OBJECT_TOKEN            CmObjToken
+  );
+
 /** The SMBIOS_TABLE_GENERATOR structure provides an interface that the
     Table Manager can use to invoke the functions to build SMBIOS tables.
 */
 typedef struct SmbiosTableGenerator {
   /// The SMBIOS table generator ID.
-  SMBIOS_TABLE_GENERATOR_ID             GeneratorID;
+  SMBIOS_TABLE_GENERATOR_ID               GeneratorID;
 
   /// String describing the DT table
   /// generator.
-  CONST CHAR16                          *Description;
+  CONST CHAR16                            *Description;
 
   /// The SMBIOS table type.
-  SMBIOS_TYPE                           Type;
+  SMBIOS_TYPE                             Type;
 
   /// SMBIOS table build function pointer.
-  SMBIOS_TABLE_GENERATOR_BUILD_TABLE    BuildSmbiosTable;
+  SMBIOS_TABLE_GENERATOR_BUILD_TABLE      BuildSmbiosTable;
+
+  /** The function to free any resources
+      allocated for building the SMBIOS table.
+  */
+  SMBIOS_TABLE_GENERATOR_FREE_TABLE       FreeTableResources;
+
+  /// SMBIOS table extended build function pointer.
+  SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX    BuildSmbiosTableEx;
 
   /** The function to free any resources
       allocated for building the SMBIOS table.
   */
-  SMBIOS_TABLE_GENERATOR_FREE_TABLE     FreeTableResources;
+  SMBIOS_TABLE_GENERATOR_FREE_TABLEEX     FreeTableResourcesEx;
 } SMBIOS_TABLE_GENERATOR;
 
 /** Register SMBIOS table factory generator.
@@ -229,6 +356,69 @@ DeregisterSmbiosTableGenerator (
   IN CONST SMBIOS_TABLE_GENERATOR                 *CONST  Generator
   );
 
+/** Add SMBIOS Handle.
+
+  This function is called by the Dynamic Table Manager to add a newly added
+  SMBIOS Table OR it can be called by an SMBIOS Table generator to create
+  and add a new SMBIOS Handle if there is a reference to another table and
+  if there is a generator for that table that hasn't been called yet.
+
+  @param [in]  Smbios         Pointer to the SMBIOS protocol.
+  @param [in]  SmbiosHandle   Pointer to an SMBIOS handle (either generated by
+                              SmbiosDxe Driver or  SMBIOS_HANDLE_PI_RESERVED
+                              if a handle needs to be generated).
+  @param [in]  CmObjectToken  The CM Object token for that is used to generate
+                              SMBIOS record.
+  @param [in]  GeneratorId    The SMBIOS table generator Id.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_OUT_OF_RESOURCES  Unable to add the handle.
+  @retval EFI_NOT_FOUND         The requested generator is not found
+                                in the list of registered generators.
+**/
+EFI_STATUS
+EFIAPI
+AddSmbiosHandle (
+  IN EFI_SMBIOS_PROTOCOL         *Smbios,
+  IN SMBIOS_HANDLE               *SmbiosHandle,
+  IN CM_OBJECT_TOKEN             CmObjectToken,
+  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId
+  );
+
+/** Find SMBIOS Handle given the CM Object token used to generate the SMBIOS
+    record..
+
+  This function is called by the SMBIOS table generator to find an SMBIOS
+  handle needed as part of generating an SMBIOS Table.
+
+  @param [in]  CmObjectToken    The CM Object token used to generate the SMBIOS
+                                record.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_NOT_FOUND         The requested generator is not found
+                                in the list of registered generators.
+**/
+SMBIOS_HANDLE_MAP *
+EFIAPI
+FindSmbiosHandle (
+  IN CM_OBJECT_TOKEN  CmObjectToken
+  );
+
+/** Find and return SMBIOS handle based on associated CM object token.
+
+  @param [in]  GeneratorId     SMBIOS generator ID used to build the SMBIOS Table.
+  @param [in]  CmObjectToken   Token of the CM_OBJECT used to build the SMBIOS Table.
+
+  @return  SMBIOS handle of the table associated with SmbiosTableId and
+           CmObjectToken if found. Otherwise, returns 0xFFFF.
+**/
+UINT16
+EFIAPI
+FindSmbiosHandleEx (
+  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId,
+  IN  CM_OBJECT_TOKEN            CmObjToken
+  );
+
 #pragma pack()
 
 #endif // SMBIOS_TABLE_GENERATOR_H_
diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/IndustryStandard/SmBios.h
index 89985bb418..c40986157c 100644
--- a/MdePkg/Include/IndustryStandard/SmBios.h
+++ b/MdePkg/Include/IndustryStandard/SmBios.h
@@ -28,6 +28,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 ///
 #define SMBIOS_HANDLE_PI_RESERVED  0xFFFE
 
+///
+/// Reference SMBIOS 3.6, chapter 6.1.2.
+/// Unless otherwise specified, when referring to another structure’s handle, the value
+/// 0FFFFh is used to indicate that the referenced handle is not applicable or does not
+/// exist.
+///
+#define SMBIOS_HANDLE_INVALID  0xFFFF
+
 ///
 /// Reference SMBIOS 2.6, chapter 3.1.3.
 /// Each text string is limited to 64 significant characters due to system MIF limitations.
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107255): https://edk2.groups.io/g/devel/message/107255
Mute This Topic: https://groups.io/mt/100361559/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [edk2-devel] [PATCH v3 2/5] DynamicTablesPkg: Split the ACPI and SMBIOS table generators
  2023-07-25 23:38 [edk2-devel] [PATCH v3 0/5] DynamicTablesPkg: Add SMBIOS Table Generation Girish Mahadevan via groups.io
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table generation Girish Mahadevan via groups.io
@ 2023-07-25 23:38 ` Girish Mahadevan via groups.io
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 3/5] DynamicTablesPkg: Introduce new namespace for SMBIOS Objects Girish Mahadevan via groups.io
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Girish Mahadevan via groups.io @ 2023-07-25 23:38 UTC (permalink / raw)
  To: devel, sami.mujawar
  Cc: gmahadevan, Alexei.Fedorov, Pierre.Gondois, jbrasen, ashishsingha,
	nramirez

Split the SMBIOS and ACPI table generators into their own files.

Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
---
 .../DynamicTableManagerDxe/AcpiTableBuilder.c |  798 ++++++++++
 .../DynamicTableManagerDxe.c                  | 1356 +----------------
 .../DynamicTableManagerDxe.inf                |    2 +
 .../SmbiosTableBuilder.c                      |  606 ++++++++
 4 files changed, 1419 insertions(+), 1343 deletions(-)
 create mode 100644 DynamicTablesPkg/Drivers/DynamicTableManagerDxe/AcpiTableBuilder.c
 create mode 100644 DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c

diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/AcpiTableBuilder.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/AcpiTableBuilder.c
new file mode 100644
index 0000000000..2adfb0378e
--- /dev/null
+++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/AcpiTableBuilder.c
@@ -0,0 +1,798 @@
+/** @file
+  Acpi Table Manager Dxe
+
+  Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2022 - 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/AcpiSystemDescriptionTable.h>
+#include <Protocol/AcpiTable.h>
+#include <Library/BaseMemoryLib.h>
+
+// Module specific include files.
+#include <AcpiTableGenerator.h>
+#include <ConfigurationManagerObject.h>
+#include <ConfigurationManagerHelper.h>
+#include <DeviceTreeTableGenerator.h>
+#include <Library/TableHelperLib.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+#include <Protocol/DynamicTableFactoryProtocol.h>
+
+///
+/// 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 },
+};
+
+/** This macro expands to a function that retrieves the ACPI Table
+    List from the Configuration Manager.
+*/
+GET_OBJECT_LIST (
+  EObjNameSpaceStandard,
+  EStdObjAcpiTableList,
+  CM_STD_OBJ_ACPI_TABLE_INFO
+  )
+
+/** A helper function to build and install a single ACPI table.
+
+  This is a helper function that invokes the Table generator interface
+  for building an ACPI table. It uses the AcpiTableProtocol to install the
+  table, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  Generator            Pointer to the AcpiTable generator.
+  @param [in]  AcpiTableProtocol    Pointer to the AcpiTable protocol.
+  @param [in]  AcpiTableInfo        Pointer to the ACPI table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+BuildAndInstallSingleAcpiTable (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN CONST ACPI_TABLE_GENERATOR                  *CONST  Generator,
+  IN       EFI_ACPI_TABLE_PROTOCOL                       *AcpiTableProtocol,
+  IN CONST CM_STD_OBJ_ACPI_TABLE_INFO            *CONST  AcpiTableInfo
+  )
+{
+  EFI_STATUS                   Status;
+  EFI_STATUS                   Status1;
+  EFI_ACPI_DESCRIPTION_HEADER  *AcpiTable;
+  UINTN                        TableHandle;
+
+  AcpiTable = NULL;
+  Status    = Generator->BuildAcpiTable (
+                           Generator,
+                           AcpiTableInfo,
+                           CfgMgrProtocol,
+                           &AcpiTable
+                           );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Build Table." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      AcpiTableInfo->TableGeneratorId,
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  if (AcpiTable == NULL) {
+    Status = EFI_NOT_FOUND;
+    goto exit_handler;
+  }
+
+  // Dump ACPI Table Header
+  DUMP_ACPI_TABLE_HEADER (AcpiTable);
+
+  // Install ACPI table
+  Status = AcpiTableProtocol->InstallAcpiTable (
+                                AcpiTableProtocol,
+                                AcpiTable,
+                                AcpiTable->Length,
+                                &TableHandle
+                                );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Install ACPI Table. Status = %r\n",
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: ACPI Table installed. Status = %r\n",
+    Status
+    ));
+
+exit_handler:
+  // Free any resources allocated for generating the tables.
+  if (Generator->FreeTableResources != NULL) {
+    Status1 = Generator->FreeTableResources (
+                           Generator,
+                           AcpiTableInfo,
+                           CfgMgrProtocol,
+                           &AcpiTable
+                           );
+    if (EFI_ERROR (Status1)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Free Table Resources." \
+        "TableGeneratorId = 0x%x. Status = %r\n",
+        AcpiTableInfo->TableGeneratorId,
+        Status1
+        ));
+    }
+
+    // Return the first error status in case of failure
+    if (!EFI_ERROR (Status)) {
+      Status = Status1;
+    }
+  }
+
+  return Status;
+}
+
+/** A helper function to build and install multiple ACPI tables.
+
+  This is a helper function that invokes the Table generator interface
+  for building an ACPI table. It uses the AcpiTableProtocol to install the
+  table, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  Generator            Pointer to the AcpiTable generator.
+  @param [in]  AcpiTableProtocol    Pointer to the AcpiTable protocol.
+  @param [in]  AcpiTableInfo        Pointer to the ACPI table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+BuildAndInstallMultipleAcpiTable (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN CONST ACPI_TABLE_GENERATOR                  *CONST  Generator,
+  IN       EFI_ACPI_TABLE_PROTOCOL                       *AcpiTableProtocol,
+  IN CONST CM_STD_OBJ_ACPI_TABLE_INFO            *CONST  AcpiTableInfo
+  )
+{
+  EFI_STATUS                   Status;
+  EFI_STATUS                   Status1;
+  EFI_ACPI_DESCRIPTION_HEADER  **AcpiTable;
+  UINTN                        TableCount;
+  UINTN                        TableHandle;
+  UINTN                        Index;
+
+  AcpiTable  = NULL;
+  TableCount = 0;
+  Status     = Generator->BuildAcpiTableEx (
+                            Generator,
+                            AcpiTableInfo,
+                            CfgMgrProtocol,
+                            &AcpiTable,
+                            &TableCount
+                            );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Build Table." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      AcpiTableInfo->TableGeneratorId,
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  if ((AcpiTable == NULL) || (TableCount == 0)) {
+    Status = EFI_NOT_FOUND;
+    goto exit_handler;
+  }
+
+  for (Index = 0; Index < TableCount; Index++) {
+    // Dump ACPI Table Header
+    DUMP_ACPI_TABLE_HEADER (AcpiTable[Index]);
+    // Install ACPI table
+    Status = AcpiTableProtocol->InstallAcpiTable (
+                                  AcpiTableProtocol,
+                                  AcpiTable[Index],
+                                  AcpiTable[Index]->Length,
+                                  &TableHandle
+                                  );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Install ACPI Table. Status = %r\n",
+        Status
+        ));
+      // Free any allocated resources.
+      goto exit_handler;
+    }
+
+    DEBUG ((
+      DEBUG_INFO,
+      "INFO: ACPI Table installed. Status = %r\n",
+      Status
+      ));
+  }
+
+exit_handler:
+  // Free any resources allocated for generating the tables.
+  if (Generator->FreeTableResourcesEx != NULL) {
+    Status1 = Generator->FreeTableResourcesEx (
+                           Generator,
+                           AcpiTableInfo,
+                           CfgMgrProtocol,
+                           &AcpiTable,
+                           TableCount
+                           );
+    if (EFI_ERROR (Status1)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Free Table Resources." \
+        "TableGeneratorId = 0x%x. Status = %r\n",
+        AcpiTableInfo->TableGeneratorId,
+        Status1
+        ));
+    }
+
+    // Return the first error status in case of failure
+    if (!EFI_ERROR (Status)) {
+      Status = Status1;
+    }
+  }
+
+  return Status;
+}
+
+/** A helper function to invoke a Table generator
+
+  This is a helper function that invokes the Table generator interface
+  for building an ACPI table. It uses the AcpiTableProtocol to install the
+  table, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  AcpiTableProtocol    Pointer to the AcpiTable protocol.
+  @param [in]  AcpiTableInfo        Pointer to the ACPI table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+BuildAndInstallAcpiTable (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN       EFI_ACPI_TABLE_PROTOCOL                       *AcpiTableProtocol,
+  IN CONST CM_STD_OBJ_ACPI_TABLE_INFO            *CONST  AcpiTableInfo
+  )
+{
+  EFI_STATUS                  Status;
+  CONST ACPI_TABLE_GENERATOR  *Generator;
+
+  ASSERT (TableFactoryProtocol != NULL);
+  ASSERT (CfgMgrProtocol != NULL);
+  ASSERT (AcpiTableProtocol != NULL);
+  ASSERT (AcpiTableInfo != NULL);
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: EStdObjAcpiTableList: Address = 0x%p," \
+    " TableGeneratorId = 0x%x\n",
+    AcpiTableInfo,
+    AcpiTableInfo->TableGeneratorId
+    ));
+
+  Generator = NULL;
+  Status    = TableFactoryProtocol->GetAcpiTableGenerator (
+                                      TableFactoryProtocol,
+                                      AcpiTableInfo->TableGeneratorId,
+                                      &Generator
+                                      );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Table Generator not found." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      AcpiTableInfo->TableGeneratorId,
+      Status
+      ));
+    return Status;
+  }
+
+  if (Generator == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: Generator found : %s\n",
+    Generator->Description
+    ));
+
+  if (Generator->BuildAcpiTableEx != NULL) {
+    Status = BuildAndInstallMultipleAcpiTable (
+               TableFactoryProtocol,
+               CfgMgrProtocol,
+               Generator,
+               AcpiTableProtocol,
+               AcpiTableInfo
+               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to find build and install ACPI Table." \
+        " Status = %r\n",
+        Status
+        ));
+    }
+  } else if (Generator->BuildAcpiTable != NULL) {
+    Status = BuildAndInstallSingleAcpiTable (
+               TableFactoryProtocol,
+               CfgMgrProtocol,
+               Generator,
+               AcpiTableProtocol,
+               AcpiTableInfo
+               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to find build and install ACPI Table." \
+        " Status = %r\n",
+        Status
+        ));
+    }
+  } else {
+    Status = EFI_INVALID_PARAMETER;
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Table Generator does not implement the" \
+      " ACPI_TABLE_GENERATOR_BUILD_TABLE interface." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      AcpiTableInfo->TableGeneratorId,
+      Status
+      ));
+  }
+
+  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
+  ACPI tables from the Configuration Manager, invokes the generators
+  and installs them (via BuildAndInstallAcpiTable).
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_NOT_FOUND         If a mandatory table or a generator is not found.
+  @retval EFI_ALREADY_STARTED   If mandatory table found in AcpiTableInfo is already installed.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ProcessAcpiTables (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol
+  )
+{
+  EFI_STATUS                  Status;
+  EFI_ACPI_TABLE_PROTOCOL     *AcpiTableProtocol;
+  CM_STD_OBJ_ACPI_TABLE_INFO  *AcpiTableInfo;
+  UINT32                      AcpiTableCount;
+  UINT32                      Idx;
+
+  ASSERT (TableFactoryProtocol != NULL);
+  ASSERT (CfgMgrProtocol != NULL);
+
+  // Find the AcpiTable protocol
+  Status = gBS->LocateProtocol (
+                  &gEfiAcpiTableProtocolGuid,
+                  NULL,
+                  (VOID **)&AcpiTableProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to find AcpiTable protocol. Status = %r\n",
+      Status
+      ));
+    return Status;
+  }
+
+  Status = GetEStdObjAcpiTableList (
+             CfgMgrProtocol,
+             CM_NULL_TOKEN,
+             &AcpiTableInfo,
+             &AcpiTableCount
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to get ACPI Table List. Status = %r\n",
+      Status
+      ));
+    return Status;
+  }
+
+  if (0 == AcpiTableCount) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: EStdObjAcpiTableList: AcpiTableCount = %d\n",
+      AcpiTableCount
+      ));
+    return EFI_NOT_FOUND;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: EStdObjAcpiTableList: AcpiTableCount = %d\n",
+    AcpiTableCount
+    ));
+
+  // Check if mandatory ACPI tables are present.
+  Status = VerifyMandatoryTablesArePresent (
+             AcpiTableInfo,
+             AcpiTableCount
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to verify mandatory ACPI Table(s) presence."
+      " Status = %r\n",
+      Status
+      ));
+    return Status;
+  }
+
+  // Add the FADT Table first.
+  if ((mAcpiVerifyTables[ACPI_TABLE_VERIFY_FADT].Presence & ACPI_TABLE_PRESENT_INSTALLED) == 0) {
+    // FADT is not yet installed
+    for (Idx = 0; Idx < AcpiTableCount; Idx++) {
+      if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) ==
+          AcpiTableInfo[Idx].TableGeneratorId)
+      {
+        Status = BuildAndInstallAcpiTable (
+                   TableFactoryProtocol,
+                   CfgMgrProtocol,
+                   AcpiTableProtocol,
+                   &AcpiTableInfo[Idx]
+                   );
+        if (EFI_ERROR (Status)) {
+          DEBUG ((
+            DEBUG_ERROR,
+            "ERROR: Failed to find build and install ACPI FADT Table." \
+            " Status = %r\n",
+            Status
+            ));
+          return Status;
+        }
+
+        break;
+      }
+    } // for
+  }
+
+  // Add remaining ACPI Tables
+  for (Idx = 0; Idx < AcpiTableCount; Idx++) {
+    DEBUG ((
+      DEBUG_INFO,
+      "INFO: AcpiTableInfo[%d].TableGeneratorId = 0x%x\n",
+      Idx,
+      AcpiTableInfo[Idx].TableGeneratorId
+      ));
+
+    // Skip FADT Table since we have already added
+    if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) ==
+        AcpiTableInfo[Idx].TableGeneratorId)
+    {
+      continue;
+    }
+
+    // Skip the Reserved table Generator ID for standard generators
+    if ((IS_GENERATOR_NAMESPACE_STD (AcpiTableInfo[Idx].TableGeneratorId)) &&
+        ((CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdReserved)           >=
+          AcpiTableInfo[Idx].TableGeneratorId)                           ||
+         (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdMax)                <=
+          AcpiTableInfo[Idx].TableGeneratorId)))
+    {
+      DEBUG ((
+        DEBUG_WARN,
+        "WARNING: Invalid ACPI Generator table ID = 0x%x, Skipping...\n",
+        AcpiTableInfo[Idx].TableGeneratorId
+        ));
+      continue;
+    }
+
+    Status = BuildAndInstallAcpiTable (
+               TableFactoryProtocol,
+               CfgMgrProtocol,
+               AcpiTableProtocol,
+               &AcpiTableInfo[Idx]
+               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to find, build, and install ACPI Table." \
+        " Status = %r\n",
+        Status
+        ));
+      return Status;
+    }
+  } // for
+
+  return Status;
+}
+
+/** Entrypoint of Dynamic Table Manager Dxe.
+
+  The Dynamic Table Manager uses the Configuration Manager Protocol
+  to get the list of ACPI and SMBIOS tables to install. For each table
+  in the list it requests the corresponding ACPI/SMBIOS table factory for
+  a generator capable of building the ACPI/SMBIOS table.
+  If a suitable table generator is found, it invokes the generator interface
+  to build the table. The Dynamic Table Manager then installs the
+  table and invokes another generator interface to free any resources
+  allocated for building the table.
+
+  @param  ImageHandle
+  @param  SystemTable
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
+  @retval EFI_NOT_FOUND         Required interface/object was not found.
+  @retval EFI_INVALID_PARAMETER Some parameter is incorrect/invalid.
+**/
+VOID
+EFIAPI
+AcpiTableProtocolReady (
+  IN  EFI_EVENT  Event,
+  IN  VOID       *Context
+  )
+{
+  EFI_STATUS                             Status;
+  EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CfgMgrProtocol;
+  CM_STD_OBJ_CONFIGURATION_MANAGER_INFO  *CfgMfrInfo;
+  EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *TableFactoryProtocol;
+
+  // Locate the Dynamic Table Factory
+  Status = gBS->LocateProtocol (
+                  &gEdkiiDynamicTableFactoryProtocolGuid,
+                  NULL,
+                  (VOID **)&TableFactoryProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to find Dynamic Table Factory protocol." \
+      " Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  // Locate the Configuration Manager for the Platform
+  Status = gBS->LocateProtocol (
+                  &gEdkiiConfigurationManagerProtocolGuid,
+                  NULL,
+                  (VOID **)&CfgMgrProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to find Configuration Manager protocol. Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to get Configuration Manager info. Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  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]
+    ));
+
+  Status = ProcessAcpiTables (TableFactoryProtocol, CfgMgrProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: ACPI Table processing failure. Status = %r\n",
+      Status
+      ));
+  }
+}
diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
index 26aa9b55cf..6ad2e623b2 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
+++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c
@@ -2,6 +2,7 @@
   Dynamic Table Manager Dxe
 
   Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2022 - 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -11,10 +12,6 @@
 #include <Library/UefiLib.h>
 #include <Library/PcdLib.h>
 #include <Library/UefiBootServicesTableLib.h>
-#include <Protocol/AcpiSystemDescriptionTable.h>
-#include <Protocol/AcpiTable.h>
-#include <Protocol/Smbios.h>
-#include <Library/BaseMemoryLib.h>
 
 // Module specific include files.
 #include <AcpiTableGenerator.h>
@@ -24,1351 +21,25 @@
 #include <Library/TableHelperLib.h>
 #include <Protocol/ConfigurationManagerProtocol.h>
 #include <Protocol/DynamicTableFactoryProtocol.h>
-#include <SmbiosTableGenerator.h>
-#include <SmbiosTableDispatcher.h>
 
-///
-/// 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 },
-};
-
-/** This macro expands to a function that retrieves the ACPI Table
-    List from the Configuration Manager.
-*/
-GET_OBJECT_LIST (
-  EObjNameSpaceStandard,
-  EStdObjAcpiTableList,
-  CM_STD_OBJ_ACPI_TABLE_INFO
-  )
-
-/** This macro expands to a function that retrieves the SMBIOS Table
-    List from the Configuration Manager.
-*/
-GET_OBJECT_LIST (
-  EObjNameSpaceStandard,
-  EStdObjSmbiosTableList,
-  CM_STD_OBJ_SMBIOS_TABLE_INFO
-  )
-
-STATIC VOID *AcpiTableProtocolRegistration;
+STATIC VOID  *AcpiTableProtocolRegistration;
 STATIC VOID  *SmbiosProtocolRegistration;
 
-/** A helper function to build and install a single ACPI table.
-
-  This is a helper function that invokes the Table generator interface
-  for building an ACPI table. It uses the AcpiTableProtocol to install the
-  table, then frees the resources allocated for generating it.
-
-  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
-                                    interface.
-  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
-                                    Protocol Interface.
-  @param [in]  Generator            Pointer to the AcpiTable generator.
-  @param [in]  AcpiTableProtocol    Pointer to the AcpiTable protocol.
-  @param [in]  AcpiTableInfo        Pointer to the ACPI table Info.
-
-  @retval EFI_SUCCESS           Success.
-  @retval EFI_INVALID_PARAMETER A parameter is invalid.
-  @retval EFI_NOT_FOUND         Required object is not found.
-  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
-                                is less than the Object size for the
-                                requested object.
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-BuildAndInstallSingleAcpiTable (
-  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
-  IN CONST ACPI_TABLE_GENERATOR                  *CONST  Generator,
-  IN       EFI_ACPI_TABLE_PROTOCOL                       *AcpiTableProtocol,
-  IN CONST CM_STD_OBJ_ACPI_TABLE_INFO            *CONST  AcpiTableInfo
-  )
-{
-  EFI_STATUS                   Status;
-  EFI_STATUS                   Status1;
-  EFI_ACPI_DESCRIPTION_HEADER  *AcpiTable;
-  UINTN                        TableHandle;
-
-  AcpiTable = NULL;
-  Status    = Generator->BuildAcpiTable (
-                           Generator,
-                           AcpiTableInfo,
-                           CfgMgrProtocol,
-                           &AcpiTable
-                           );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to Build Table." \
-      " TableGeneratorId = 0x%x. Status = %r\n",
-      AcpiTableInfo->TableGeneratorId,
-      Status
-      ));
-    // Free any allocated resources.
-    goto exit_handler;
-  }
-
-  if (AcpiTable == NULL) {
-    Status = EFI_NOT_FOUND;
-    goto exit_handler;
-  }
-
-  // Dump ACPI Table Header
-  DUMP_ACPI_TABLE_HEADER (AcpiTable);
-
-  // Install ACPI table
-  Status = AcpiTableProtocol->InstallAcpiTable (
-                                AcpiTableProtocol,
-                                AcpiTable,
-                                AcpiTable->Length,
-                                &TableHandle
-                                );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to Install ACPI Table. Status = %r\n",
-      Status
-      ));
-    // Free any allocated resources.
-    goto exit_handler;
-  }
-
-  DEBUG ((
-    DEBUG_INFO,
-    "INFO: ACPI Table installed. Status = %r\n",
-    Status
-    ));
-
-exit_handler:
-  // Free any resources allocated for generating the tables.
-  if (Generator->FreeTableResources != NULL) {
-    Status1 = Generator->FreeTableResources (
-                           Generator,
-                           AcpiTableInfo,
-                           CfgMgrProtocol,
-                           &AcpiTable
-                           );
-    if (EFI_ERROR (Status1)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to Free Table Resources." \
-        "TableGeneratorId = 0x%x. Status = %r\n",
-        AcpiTableInfo->TableGeneratorId,
-        Status1
-        ));
-    }
-
-    // Return the first error status in case of failure
-    if (!EFI_ERROR (Status)) {
-      Status = Status1;
-    }
-  }
-
-  return Status;
-}
-
-/** A helper function to build and install multiple ACPI tables.
-
-  This is a helper function that invokes the Table generator interface
-  for building an ACPI table. It uses the AcpiTableProtocol to install the
-  table, then frees the resources allocated for generating it.
-
-  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
-                                    interface.
-  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
-                                    Protocol Interface.
-  @param [in]  Generator            Pointer to the AcpiTable generator.
-  @param [in]  AcpiTableProtocol    Pointer to the AcpiTable protocol.
-  @param [in]  AcpiTableInfo        Pointer to the ACPI table Info.
-
-  @retval EFI_SUCCESS           Success.
-  @retval EFI_INVALID_PARAMETER A parameter is invalid.
-  @retval EFI_NOT_FOUND         Required object is not found.
-  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
-                                is less than the Object size for the
-                                requested object.
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-BuildAndInstallMultipleAcpiTable (
-  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
-  IN CONST ACPI_TABLE_GENERATOR                  *CONST  Generator,
-  IN       EFI_ACPI_TABLE_PROTOCOL                       *AcpiTableProtocol,
-  IN CONST CM_STD_OBJ_ACPI_TABLE_INFO            *CONST  AcpiTableInfo
-  )
-{
-  EFI_STATUS                   Status;
-  EFI_STATUS                   Status1;
-  EFI_ACPI_DESCRIPTION_HEADER  **AcpiTable;
-  UINTN                        TableCount;
-  UINTN                        TableHandle;
-  UINTN                        Index;
-
-  AcpiTable  = NULL;
-  TableCount = 0;
-  Status     = Generator->BuildAcpiTableEx (
-                            Generator,
-                            AcpiTableInfo,
-                            CfgMgrProtocol,
-                            &AcpiTable,
-                            &TableCount
-                            );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to Build Table." \
-      " TableGeneratorId = 0x%x. Status = %r\n",
-      AcpiTableInfo->TableGeneratorId,
-      Status
-      ));
-    // Free any allocated resources.
-    goto exit_handler;
-  }
-
-  if ((AcpiTable == NULL) || (TableCount == 0)) {
-    Status = EFI_NOT_FOUND;
-    goto exit_handler;
-  }
-
-  for (Index = 0; Index < TableCount; Index++) {
-    // Dump ACPI Table Header
-    DUMP_ACPI_TABLE_HEADER (AcpiTable[Index]);
-    // Install ACPI table
-    Status = AcpiTableProtocol->InstallAcpiTable (
-                                  AcpiTableProtocol,
-                                  AcpiTable[Index],
-                                  AcpiTable[Index]->Length,
-                                  &TableHandle
-                                  );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to Install ACPI Table. Status = %r\n",
-        Status
-        ));
-      // Free any allocated resources.
-      goto exit_handler;
-    }
-
-    DEBUG ((
-      DEBUG_INFO,
-      "INFO: ACPI Table installed. Status = %r\n",
-      Status
-      ));
-  }
-
-exit_handler:
-  // Free any resources allocated for generating the tables.
-  if (Generator->FreeTableResourcesEx != NULL) {
-    Status1 = Generator->FreeTableResourcesEx (
-                           Generator,
-                           AcpiTableInfo,
-                           CfgMgrProtocol,
-                           &AcpiTable,
-                           TableCount
-                           );
-    if (EFI_ERROR (Status1)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to Free Table Resources." \
-        "TableGeneratorId = 0x%x. Status = %r\n",
-        AcpiTableInfo->TableGeneratorId,
-        Status1
-        ));
-    }
-
-    // Return the first error status in case of failure
-    if (!EFI_ERROR (Status)) {
-      Status = Status1;
-    }
-  }
-
-  return Status;
-}
-
-/** A helper function to invoke a Table generator
-
-  This is a helper function that invokes the Table generator interface
-  for building an ACPI table. It uses the AcpiTableProtocol to install the
-  table, then frees the resources allocated for generating it.
-
-  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
-                                    interface.
-  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
-                                    Protocol Interface.
-  @param [in]  AcpiTableProtocol    Pointer to the AcpiTable protocol.
-  @param [in]  AcpiTableInfo        Pointer to the ACPI table Info.
-
-  @retval EFI_SUCCESS           Success.
-  @retval EFI_INVALID_PARAMETER A parameter is invalid.
-  @retval EFI_NOT_FOUND         Required object is not found.
-  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
-                                is less than the Object size for the
-                                requested object.
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-BuildAndInstallAcpiTable (
-  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
-  IN       EFI_ACPI_TABLE_PROTOCOL                       *AcpiTableProtocol,
-  IN CONST CM_STD_OBJ_ACPI_TABLE_INFO            *CONST  AcpiTableInfo
-  )
-{
-  EFI_STATUS                  Status;
-  CONST ACPI_TABLE_GENERATOR  *Generator;
-
-  ASSERT (TableFactoryProtocol != NULL);
-  ASSERT (CfgMgrProtocol != NULL);
-  ASSERT (AcpiTableProtocol != NULL);
-  ASSERT (AcpiTableInfo != NULL);
-
-  DEBUG ((
-    DEBUG_INFO,
-    "INFO: EStdObjAcpiTableList: Address = 0x%p," \
-    " TableGeneratorId = 0x%x\n",
-    AcpiTableInfo,
-    AcpiTableInfo->TableGeneratorId
-    ));
-
-  Generator = NULL;
-  Status    = TableFactoryProtocol->GetAcpiTableGenerator (
-                                      TableFactoryProtocol,
-                                      AcpiTableInfo->TableGeneratorId,
-                                      &Generator
-                                      );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Table Generator not found." \
-      " TableGeneratorId = 0x%x. Status = %r\n",
-      AcpiTableInfo->TableGeneratorId,
-      Status
-      ));
-    return Status;
-  }
-
-  if (Generator == NULL) {
-    return EFI_NOT_FOUND;
-  }
-
-  DEBUG ((
-    DEBUG_INFO,
-    "INFO: Generator found : %s\n",
-    Generator->Description
-    ));
-
-  if (Generator->BuildAcpiTableEx != NULL) {
-    Status = BuildAndInstallMultipleAcpiTable (
-               TableFactoryProtocol,
-               CfgMgrProtocol,
-               Generator,
-               AcpiTableProtocol,
-               AcpiTableInfo
-               );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to find build and install ACPI Table." \
-        " Status = %r\n",
-        Status
-        ));
-    }
-  } else if (Generator->BuildAcpiTable != NULL) {
-    Status = BuildAndInstallSingleAcpiTable (
-               TableFactoryProtocol,
-               CfgMgrProtocol,
-               Generator,
-               AcpiTableProtocol,
-               AcpiTableInfo
-               );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to find build and install ACPI Table." \
-        " Status = %r\n",
-        Status
-        ));
-    }
-  } else {
-    Status = EFI_INVALID_PARAMETER;
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Table Generator does not implement the" \
-      " ACPI_TABLE_GENERATOR_BUILD_TABLE interface." \
-      " TableGeneratorId = 0x%x. Status = %r\n",
-      AcpiTableInfo->TableGeneratorId,
-      Status
-      ));
-  }
-
-  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;
-}
-
-/** A helper function to build and install an SMBIOS table.
-
-  This is a helper function that invokes the Table generator interface
-  for building an SMBIOS table. It uses the SmbiosProtocol to install the
-  table, then frees the resources allocated for generating it.
-
-  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
-                                    interface.
-  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
-                                    Protocol Interface.
-  @param [in]  SmbiosProtocol       Pointer to the SMBIOS protocol.
-  @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table Info.
-
-  @retval EFI_SUCCESS           Success.
-  @retval EFI_INVALID_PARAMETER A parameter is invalid.
-  @retval EFI_NOT_FOUND         Required object is not found.
-  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
-                                is less than the Object size for the
-                                requested object.
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-BuildAndInstallSingleSmbiosTable (
-  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
-  IN CONST SMBIOS_TABLE_GENERATOR                *CONST  Generator,
-  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
-  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
-  )
-{
-  EFI_STATUS         Status;
-  EFI_STATUS         Status1;
-  SMBIOS_STRUCTURE   *SmbiosTable;
-  CM_OBJECT_TOKEN    CmObjToken;
-  EFI_SMBIOS_HANDLE  TableHandle;
-
-  SmbiosTable = NULL;
-  Status      = Generator->BuildSmbiosTable (
-                             Generator,
-                             TableFactoryProtocol,
-                             SmbiosTableInfo,
-                             CfgMgrProtocol,
-                             &SmbiosTable,
-                             &CmObjToken
-                             );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to Build Table." \
-      " TableGeneratorId = 0x%x. Status = %r\n",
-      SmbiosTableInfo->TableGeneratorId,
-      Status
-      ));
-    // Free any allocated resources.
-    goto exit_handler;
-  }
-
-  if (SmbiosTable == NULL) {
-    Status = EFI_NOT_FOUND;
-    goto exit_handler;
-  }
-
-  TableHandle = SMBIOS_HANDLE_PI_RESERVED;
-  // Install SMBIOS table
-  Status = SmbiosProtocol->Add (
-                             SmbiosProtocol,
-                             NULL,
-                             &TableHandle,
-                             SmbiosTable
-                             );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to Install SMBIOS Table. Status = %r\n",
-      Status
-      ));
-    // Free any allocated resources.
-    goto exit_handler;
-  }
-
-  Status = TableFactoryProtocol->AddSmbiosHandle (
-                                   SmbiosProtocol,
-                                   &TableHandle,
-                                   CmObjToken,
-                                   SmbiosTableInfo->TableGeneratorId
-                                   );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to Add SMBIOS Handle. Status = %r\n",
-      Status
-      ));
-    // Free any allocated resources.
-    goto exit_handler;
-  }
-
-  DEBUG ((
-    DEBUG_INFO,
-    "INFO: SMBIOS Table installed. Status = %r\n",
-    Status
-    ));
-
-exit_handler:
-  // Free any resources allocated for generating the tables.
-  if (Generator->FreeTableResources != NULL) {
-    Status1 = Generator->FreeTableResources (
-                           Generator,
-                           TableFactoryProtocol,
-                           SmbiosTableInfo,
-                           CfgMgrProtocol,
-                           &SmbiosTable
-                           );
-    if (EFI_ERROR (Status1)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to Free Table Resources." \
-        "TableGeneratorId = 0x%x. Status = %r\n",
-        SmbiosTableInfo->TableGeneratorId,
-        Status1
-        ));
-    }
-
-    // Return the first error status in case of failure
-    if (!EFI_ERROR (Status)) {
-      Status = Status1;
-    }
-  }
-
-  return Status;
-}
-
-/** A helper function to build and install multiple SMBIOS tables.
-
-  This is a helper function that invokes the Table generator interface
-  for building SMBIOS tables. It uses the SmbiosProtocol to install the
-  tables, then frees the resources allocated for generating it.
-
-  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
-                                    interface.
-  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
-                                    Protocol Interface.
-  @param [in]  Generator            Pointer to the SmbiosTable generator.
-  @param [in]  SmbiosProtocol       Pointer to the Smbios protocol.
-  @param [in]  AcpiTableInfo        Pointer to the SMBIOS table Info.
-
-  @retval EFI_SUCCESS           Success.
-  @retval EFI_INVALID_PARAMETER A parameter is invalid.
-  @retval EFI_NOT_FOUND         Required object is not found.
-  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
-                                is less than the Object size for the
-                                requested object.
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-BuildAndInstallMultipleSmbiosTables (
-  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
-  IN CONST SMBIOS_TABLE_GENERATOR                *CONST  Generator,
-  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
-  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
-  )
-{
-  EFI_STATUS         Status;
-  EFI_STATUS         Status1;
-  SMBIOS_STRUCTURE   **SmbiosTable;
-  CM_OBJECT_TOKEN    *CmObjToken;
-  EFI_SMBIOS_HANDLE  TableHandle;
-  UINTN              TableCount;
-  UINTN              Index;
-
-  TableCount = 0;
-  Status     = Generator->BuildSmbiosTableEx (
-                            Generator,
-                            TableFactoryProtocol,
-                            SmbiosTableInfo,
-                            CfgMgrProtocol,
-                            &SmbiosTable,
-                            &CmObjToken,
-                            &TableCount
-                            );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to Build Table." \
-      " TableGeneratorId = 0x%x. Status = %r\n",
-      SmbiosTableInfo->TableGeneratorId,
-      Status
-      ));
-    // Free any allocated resources.
-    goto exit_handler;
-  }
-
-  if ((SmbiosTable == NULL) || (TableCount == 0)) {
-    Status = EFI_NOT_FOUND;
-    DEBUG ((
-      DEBUG_ERROR,
-      "%a: TableCount %u SmbiosTable %p \n",
-      __FUNCTION__,
-      TableCount,
-      SmbiosTable
-      ));
-    goto exit_handler;
-  }
-
-  for (Index = 0; Index < TableCount; Index++) {
-    TableHandle = SMBIOS_HANDLE_PI_RESERVED;
-
-    // Install SMBIOS table
-    Status = SmbiosProtocol->Add (
-                               SmbiosProtocol,
-                               NULL,
-                               &TableHandle,
-                               SmbiosTable[Index]
-                               );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to Install SMBIOS Table. Status = %r\n",
-        Status
-        ));
-      // Free any allocated resources.
-      goto exit_handler;
-    }
-
-    Status = TableFactoryProtocol->AddSmbiosHandle (
-                                     SmbiosProtocol,
-                                     &TableHandle,
-                                     CmObjToken[Index],
-                                     SmbiosTableInfo->TableGeneratorId
-                                     );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to Add SMBIOS Handle. Status = %r\n",
-        Status
-        ));
-      // Free any allocated resources.
-      goto exit_handler;
-    }
-
-    DEBUG ((
-      DEBUG_INFO,
-      "INFO: SMBIOS Table installed. Status = %r\n",
-      Status
-      ));
-  }
-
-exit_handler:
-  // Free any resources allocated for generating the tables.
-  if (Generator->FreeTableResourcesEx != NULL) {
-    Status1 = Generator->FreeTableResourcesEx (
-                           Generator,
-                           TableFactoryProtocol,
-                           SmbiosTableInfo,
-                           CfgMgrProtocol,
-                           &SmbiosTable,
-                           &CmObjToken,
-                           TableCount
-                           );
-    if (EFI_ERROR (Status1)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to Free Table Resources." \
-        "TableGeneratorId = 0x%x. Status = %r\n",
-        SmbiosTableInfo->TableGeneratorId,
-        Status1
-        ));
-    }
-
-    // Return the first error status in case of failure
-    if (!EFI_ERROR (Status)) {
-      Status = Status1;
-    }
-  }
-
-  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
-  return Status;
-}
-
-/** A helper function to invoke a Table generator
-
-  This is a helper function that invokes the Table generator interface
-  for building an SMBIOS table. It uses the SmbiosProtocol to install the
-  table, then frees the resources allocated for generating it.
-
-  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
-                                    interface.
-  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
-                                    Protocol Interface.
-  @param [in]  SmbiosProtocol       Pointer to the SMBIOS protocol.
-  @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table Info.
-
-  @retval EFI_SUCCESS           Success.
-  @retval EFI_INVALID_PARAMETER A parameter is invalid.
-  @retval EFI_NOT_FOUND         Required object is not found.
-  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
-                                is less than the Object size for the
-                                requested object.
-**/
-EFI_STATUS
-EFIAPI
-BuildAndInstallSmbiosTable (
-  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
-  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
-  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
-  )
-{
-  EFI_STATUS                    Status;
-  CONST SMBIOS_TABLE_GENERATOR  *Generator;
-
-  ASSERT (TableFactoryProtocol != NULL);
-  ASSERT (CfgMgrProtocol != NULL);
-  ASSERT (SmbiosProtocol != NULL);
-  ASSERT (SmbiosTableInfo != NULL);
-
-  DEBUG ((
-    DEBUG_INFO,
-    "INFO: EStdObjSmbiosTableList: Address = 0x%p," \
-    " TableGeneratorId = 0x%x\n",
-    SmbiosTableInfo,
-    SmbiosTableInfo->TableGeneratorId
-    ));
-
-  Generator = NULL;
-  Status    = TableFactoryProtocol->GetSmbiosTableGenerator (
-                                      TableFactoryProtocol,
-                                      SmbiosTableInfo->TableGeneratorId,
-                                      &Generator
-                                      );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Table Generator not found." \
-      " TableGeneratorId = 0x%x. Status = %r\n",
-      SmbiosTableInfo->TableGeneratorId,
-      Status
-      ));
-    return Status;
-  }
-
-  if (Generator == NULL) {
-    return EFI_NOT_FOUND;
-  }
-
-  DEBUG ((
-    DEBUG_INFO,
-    "INFO: Generator found : %s\n",
-    Generator->Description
-    ));
-
-  if (Generator->BuildSmbiosTableEx != NULL) {
-    Status = BuildAndInstallMultipleSmbiosTables (
-               TableFactoryProtocol,
-               CfgMgrProtocol,
-               Generator,
-               SmbiosProtocol,
-               SmbiosTableInfo
-               );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to find build and install SMBIOS Tables." \
-        " Status = %r\n",
-        Status
-        ));
-    }
-  } else if (Generator->BuildSmbiosTable != NULL) {
-    Status = BuildAndInstallSingleSmbiosTable (
-               TableFactoryProtocol,
-               CfgMgrProtocol,
-               Generator,
-               SmbiosProtocol,
-               SmbiosTableInfo
-               );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to find build and install SMBIOS Table." \
-        " Status = %r\n",
-        Status
-        ));
-    }
-  } else {
-    Status = EFI_INVALID_PARAMETER;
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Table Generator does not implement the" \
-      "SMBIOS_TABLE_GENERATOR_BUILD_TABLE  interface." \
-      " TableGeneratorId = 0x%x. Status = %r\n",
-      SmbiosTableInfo->TableGeneratorId,
-      Status
-      ));
-  }
-
-  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
-  return Status;
-}
-
-/** Generate and install SMBIOS tables.
-
-  The function gathers the information necessary for installing the
-  SMBIOS tables from the Configuration Manager, invokes the generators
-  and installs them (via BuildAndInstallAcpiTable).
-
-  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
-                                    interface.
-  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
-                                    Protocol Interface.
-
-  @retval EFI_SUCCESS   Success.
-  @retval EFI_NOT_FOUND If a mandatory table or a generator is not found.
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-ProcessSmbiosTables (
-  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol
-  )
-{
-  EFI_STATUS                    Status;
-  EFI_SMBIOS_PROTOCOL           *SmbiosProtocol;
-  CM_STD_OBJ_SMBIOS_TABLE_INFO  *SmbiosTableInfo;
-  UINT32                        SmbiosTableCount;
-
-  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&SmbiosProtocol);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((DEBUG_ERROR, "Could not locate SMBIOS protocol.  %r\n", Status));
-    return Status;
-  }
-
-  Status = GetEStdObjSmbiosTableList (
-             CfgMgrProtocol,
-             CM_NULL_TOKEN,
-             &SmbiosTableInfo,
-             &SmbiosTableCount
-             );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to get SMBIOS Table List. Status = %r\n",
-      Status
-      ));
-    return Status;
-  }
-
-  if (SmbiosTableCount == 0) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: EStdObjSmbiosTableList: SmbiosTableCount = %d\n",
-      SmbiosTableCount
-      ));
-    return EFI_NOT_FOUND;
-  }
-
-  DEBUG ((
-    DEBUG_INFO,
-    "INFO: EStdObjSmbiosTableList: SmbiosTableCount = %d\n",
-    SmbiosTableCount
-    ));
-
-  InitSmbiosTableDispatcher (SmbiosTableInfo, SmbiosTableCount);
-
-  Status = DispatchSmbiosTables (
-             TableFactoryProtocol,
-             CfgMgrProtocol,
-             SmbiosProtocol,
-             SmbiosTableInfo,
-             SmbiosTableCount
-             );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to install SMBIOS Tables.Status = %r\n",
-      Status
-      ));
-  }
-
-  return Status;
-}
-
-/** Generate and install ACPI tables.
-
-  The function gathers the information necessary for installing the
-  ACPI tables from the Configuration Manager, invokes the generators
-  and installs them (via BuildAndInstallAcpiTable).
-
-  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
-                                    interface.
-  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
-                                    Protocol Interface.
-
-  @retval EFI_SUCCESS           Success.
-  @retval EFI_NOT_FOUND         If a mandatory table or a generator is not found.
-  @retval EFI_ALREADY_STARTED   If mandatory table found in AcpiTableInfo is already installed.
-**/
-STATIC
-EFI_STATUS
-EFIAPI
-ProcessAcpiTables (
-  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol
-  )
-{
-  EFI_STATUS                  Status;
-  EFI_ACPI_TABLE_PROTOCOL     *AcpiTableProtocol;
-  CM_STD_OBJ_ACPI_TABLE_INFO  *AcpiTableInfo;
-  UINT32                      AcpiTableCount;
-  UINT32                      Idx;
-
-  ASSERT (TableFactoryProtocol != NULL);
-  ASSERT (CfgMgrProtocol != NULL);
-
-  // Find the AcpiTable protocol
-  Status = gBS->LocateProtocol (
-                  &gEfiAcpiTableProtocolGuid,
-                  NULL,
-                  (VOID **)&AcpiTableProtocol
-                  );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to find AcpiTable protocol. Status = %r\n",
-      Status
-      ));
-    return Status;
-  }
-
-  Status = GetEStdObjAcpiTableList (
-             CfgMgrProtocol,
-             CM_NULL_TOKEN,
-             &AcpiTableInfo,
-             &AcpiTableCount
-             );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to get ACPI Table List. Status = %r\n",
-      Status
-      ));
-    return Status;
-  }
-
-  if (0 == AcpiTableCount) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: EStdObjAcpiTableList: AcpiTableCount = %d\n",
-      AcpiTableCount
-      ));
-    return EFI_NOT_FOUND;
-  }
-
-  DEBUG ((
-    DEBUG_INFO,
-    "INFO: EStdObjAcpiTableList: AcpiTableCount = %d\n",
-    AcpiTableCount
-    ));
-
-  // Check if mandatory ACPI tables are present.
-  Status = VerifyMandatoryTablesArePresent (
-             AcpiTableInfo,
-             AcpiTableCount
-             );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to verify mandatory ACPI Table(s) presence."
-      " Status = %r\n",
-      Status
-      ));
-    return Status;
-  }
-
-  // Add the FADT Table first.
-  if ((mAcpiVerifyTables[ACPI_TABLE_VERIFY_FADT].Presence & ACPI_TABLE_PRESENT_INSTALLED) == 0) {
-    // FADT is not yet installed
-    for (Idx = 0; Idx < AcpiTableCount; Idx++) {
-      if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) ==
-          AcpiTableInfo[Idx].TableGeneratorId)
-      {
-        Status = BuildAndInstallAcpiTable (
-                   TableFactoryProtocol,
-                   CfgMgrProtocol,
-                   AcpiTableProtocol,
-                   &AcpiTableInfo[Idx]
-                   );
-        if (EFI_ERROR (Status)) {
-          DEBUG ((
-            DEBUG_ERROR,
-            "ERROR: Failed to find build and install ACPI FADT Table." \
-            " Status = %r\n",
-            Status
-            ));
-          return Status;
-        }
-
-        break;
-      }
-    } // for
-  }
-
-  // Add remaining ACPI Tables
-  for (Idx = 0; Idx < AcpiTableCount; Idx++) {
-    DEBUG ((
-      DEBUG_INFO,
-      "INFO: AcpiTableInfo[%d].TableGeneratorId = 0x%x\n",
-      Idx,
-      AcpiTableInfo[Idx].TableGeneratorId
-      ));
-
-    // Skip FADT Table since we have already added
-    if (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdFadt) ==
-        AcpiTableInfo[Idx].TableGeneratorId)
-    {
-      continue;
-    }
-
-    // Skip the Reserved table Generator ID for standard generators
-    if ((IS_GENERATOR_NAMESPACE_STD (AcpiTableInfo[Idx].TableGeneratorId)) &&
-        ((CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdReserved)           >=
-          AcpiTableInfo[Idx].TableGeneratorId)                           ||
-         (CREATE_STD_ACPI_TABLE_GEN_ID (EStdAcpiTableIdMax)                <=
-          AcpiTableInfo[Idx].TableGeneratorId)))
-    {
-      DEBUG ((
-        DEBUG_WARN,
-        "WARNING: Invalid ACPI Generator table ID = 0x%x, Skipping...\n",
-        AcpiTableInfo[Idx].TableGeneratorId
-        ));
-      continue;
-    }
-
-    Status = BuildAndInstallAcpiTable (
-               TableFactoryProtocol,
-               CfgMgrProtocol,
-               AcpiTableProtocol,
-               &AcpiTableInfo[Idx]
-               );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: Failed to find, build, and install ACPI Table." \
-        " Status = %r\n",
-        Status
-        ));
-      return Status;
-    }
-  } // for
-
-  return Status;
-}
-
-/** Callback function for ACPI Protocol .
-
-  Callback function for ACPI protocol that installs ACPI tables
-
-  @param  Event
-  @param  Context
-
-  @retval None
-**/
-STATIC
+extern
 VOID
-AcpiTableProtocolReady (
+EFIAPI
+SmbiosProtocolReady (
   IN  EFI_EVENT  Event,
   IN  VOID       *Context
-  )
-{
-  EFI_STATUS                             Status;
-  EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CfgMgrProtocol;
-  CM_STD_OBJ_CONFIGURATION_MANAGER_INFO  *CfgMfrInfo;
-  EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *TableFactoryProtocol;
-
-  // Locate the Dynamic Table Factory
-  Status = gBS->LocateProtocol (
-                  &gEdkiiDynamicTableFactoryProtocolGuid,
-                  NULL,
-                  (VOID **)&TableFactoryProtocol
-                  );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to find Dynamic Table Factory protocol." \
-      " Status = %r\n",
-      Status
-      ));
-    return;
-  }
+  );
 
-  // Locate the Configuration Manager for the Platform
-  Status = gBS->LocateProtocol (
-                  &gEdkiiConfigurationManagerProtocolGuid,
-                  NULL,
-                  (VOID **)&CfgMgrProtocol
-                  );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to find Configuration Manager protocol. Status = %r\n",
-      Status
-      ));
-    return;
-  }
-
-  Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to get Configuration Manager info. Status = %r\n",
-      Status
-      ));
-    return;
-  }
-
-  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]
-    ));
-
-  Status = ProcessAcpiTables (TableFactoryProtocol, CfgMgrProtocol);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: ACPI Table processing failure. Status = %r\n",
-      Status
-      ));
-  }
-}
-
-/** Callback function for SMBIOS Protocol .
-
-  Callback function for SMBIOS protocol that installs SMBIOS tables
-  that use the DynamicTables Package.
-
-  @param  Event
-  @param  Context
-
-  @retval None
-**/
-STATIC
+extern
 VOID
-SmbiosProtocolReady (
+EFIAPI
+AcpiTableProtocolReady (
   IN  EFI_EVENT  Event,
   IN  VOID       *Context
-  )
-{
-  EFI_STATUS                             Status;
-  EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CfgMgrProtocol;
-  CM_STD_OBJ_CONFIGURATION_MANAGER_INFO  *CfgMfrInfo;
-  EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *TableFactoryProtocol;
-
-  // Locate the Dynamic Table Factory
-  Status = gBS->LocateProtocol (
-                  &gEdkiiDynamicTableFactoryProtocolGuid,
-                  NULL,
-                  (VOID **)&TableFactoryProtocol
-                  );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to find Dynamic Table Factory protocol." \
-      " Status = %r\n",
-      Status
-      ));
-    return;
-  }
-
-  // Locate the Configuration Manager for the Platform
-  Status = gBS->LocateProtocol (
-                  &gEdkiiConfigurationManagerProtocolGuid,
-                  NULL,
-                  (VOID **)&CfgMgrProtocol
-                  );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to find Configuration Manager protocol. Status = %r\n",
-      Status
-      ));
-    return;
-  }
-
-  Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: Failed to get Configuration Manager info. Status = %r\n",
-      Status
-      ));
-    return;
-  }
-
-  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]
-    ));
-
-  Status = ProcessSmbiosTables (TableFactoryProtocol, CfgMgrProtocol);
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: SMBIOS Table processing failure. Status = %r\n",
-      Status
-      ));
-  }
-}
+  );
 
 /** Entrypoint of Dynamic Table Manager Dxe.
 
@@ -1396,9 +67,8 @@ DynamicTableManagerDxeInitialize (
   IN  EFI_SYSTEM_TABLE  *SystemTable
   )
 {
-  EFI_STATUS  Status;
-  EFI_EVENT   AcpiEvent;
-  EFI_EVENT   SmbiosEvent;
+  EFI_EVENT  AcpiEvent;
+  EFI_EVENT  SmbiosEvent;
 
   AcpiEvent = EfiCreateProtocolNotifyEvent (
                 &gEfiAcpiTableProtocolGuid,
@@ -1425,5 +95,5 @@ DynamicTableManagerDxeInitialize (
     return EFI_OUT_OF_RESOURCES;
   }
 
-  return Status;
+  return EFI_SUCCESS;
 }
diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf
index 3beab7420a..93fde9f44f 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf
+++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf
@@ -24,6 +24,8 @@
   DynamicTableManagerDxe.c
   SmbiosTableDispatcher.c
   SmbiosTableDispatcher.h
+  AcpiTableBuilder.c
+  SmbiosTableBuilder.c
 
 [Packages]
   MdePkg/MdePkg.dec
diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
new file mode 100644
index 0000000000..bfddaac3aa
--- /dev/null
+++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
@@ -0,0 +1,606 @@
+/** @file
+  Dynamic Table Manager Dxe
+
+  Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
+  Copyright (c) 2022 - 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/PcdLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/Smbios.h>
+#include <Library/BaseMemoryLib.h>
+
+// Module specific include files.
+#include <ConfigurationManagerObject.h>
+#include <ConfigurationManagerHelper.h>
+#include <DeviceTreeTableGenerator.h>
+#include <Library/TableHelperLib.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+#include <Protocol/DynamicTableFactoryProtocol.h>
+#include <SmbiosTableGenerator.h>
+#include <SmbiosTableDispatcher.h>
+
+/** This macro expands to a function that retrieves the SMBIOS Table
+    List from the Configuration Manager.
+*/
+GET_OBJECT_LIST (
+  EObjNameSpaceStandard,
+  EStdObjSmbiosTableList,
+  CM_STD_OBJ_SMBIOS_TABLE_INFO
+  )
+
+/** A helper function to build and install an SMBIOS table.
+
+  This is a helper function that invokes the Table generator interface
+  for building an SMBIOS table. It uses the SmbiosProtocol to install the
+  table, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  SmbiosProtocol       Pointer to the SMBIOS protocol.
+  @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+BuildAndInstallSingleSmbiosTable (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN CONST SMBIOS_TABLE_GENERATOR                *CONST  Generator,
+  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
+  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
+  )
+{
+  EFI_STATUS         Status;
+  EFI_STATUS         Status1;
+  SMBIOS_STRUCTURE   *SmbiosTable;
+  CM_OBJECT_TOKEN    CmObjToken;
+  EFI_SMBIOS_HANDLE  TableHandle;
+
+  SmbiosTable = NULL;
+  Status      = Generator->BuildSmbiosTable (
+                             Generator,
+                             TableFactoryProtocol,
+                             SmbiosTableInfo,
+                             CfgMgrProtocol,
+                             &SmbiosTable,
+                             &CmObjToken
+                             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Build Table." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      SmbiosTableInfo->TableGeneratorId,
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  if (SmbiosTable == NULL) {
+    Status = EFI_NOT_FOUND;
+    goto exit_handler;
+  }
+
+  TableHandle = SMBIOS_HANDLE_PI_RESERVED;
+
+  // Install SMBIOS table
+  Status = SmbiosProtocol->Add (
+                             SmbiosProtocol,
+                             NULL,
+                             &TableHandle,
+                             SmbiosTable
+                             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Install SMBIOS Table. Status = %r\n",
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  Status = TableFactoryProtocol->AddSmbiosHandle (
+                                   SmbiosProtocol,
+                                   &TableHandle,
+                                   CmObjToken,
+                                   SmbiosTableInfo->TableGeneratorId
+                                   );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Add SMBIOS Handle. Status = %r\n",
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: SMBIOS Table installed. Status = %r\n",
+    Status
+    ));
+
+exit_handler:
+  // Free any resources allocated for generating the tables.
+  if (Generator->FreeTableResources != NULL) {
+    Status1 = Generator->FreeTableResources (
+                           Generator,
+                           TableFactoryProtocol,
+                           SmbiosTableInfo,
+                           CfgMgrProtocol,
+                           &SmbiosTable
+                           );
+    if (EFI_ERROR (Status1)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Free Table Resources." \
+        "TableGeneratorId = 0x%x. Status = %r\n",
+        SmbiosTableInfo->TableGeneratorId,
+        Status1
+        ));
+    }
+
+    // Return the first error status in case of failure
+    if (!EFI_ERROR (Status)) {
+      Status = Status1;
+    }
+  }
+
+  return Status;
+}
+
+/** A helper function to build and install multiple SMBIOS tables.
+
+  This is a helper function that invokes the Table generator interface
+  for building SMBIOS tables. It uses the SmbiosProtocol to install the
+  tables, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  Generator            Pointer to the SmbiosTable generator.
+  @param [in]  SmbiosProtocol       Pointer to the Smbios protocol.
+  @param [in]  AcpiTableInfo        Pointer to the SMBIOS table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+BuildAndInstallMultipleSmbiosTables (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN CONST SMBIOS_TABLE_GENERATOR                *CONST  Generator,
+  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
+  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
+  )
+{
+  EFI_STATUS         Status;
+  EFI_STATUS         Status1;
+  SMBIOS_STRUCTURE   **SmbiosTable;
+  CM_OBJECT_TOKEN    *CmObjToken;
+  EFI_SMBIOS_HANDLE  TableHandle;
+  UINTN              TableCount;
+  UINTN              Index;
+
+  TableCount = 0;
+  Status     = Generator->BuildSmbiosTableEx (
+                            Generator,
+                            TableFactoryProtocol,
+                            SmbiosTableInfo,
+                            CfgMgrProtocol,
+                            &SmbiosTable,
+                            &CmObjToken,
+                            &TableCount
+                            );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to Build Table." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      SmbiosTableInfo->TableGeneratorId,
+      Status
+      ));
+    // Free any allocated resources.
+    goto exit_handler;
+  }
+
+  if ((SmbiosTable == NULL) || (TableCount == 0)) {
+    Status = EFI_NOT_FOUND;
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: TableCount %u SmbiosTable %p \n",
+      __FUNCTION__,
+      TableCount,
+      SmbiosTable
+      ));
+    goto exit_handler;
+  }
+
+  for (Index = 0; Index < TableCount; Index++) {
+    TableHandle = SMBIOS_HANDLE_PI_RESERVED;
+
+    // Install SMBIOS table
+    Status = SmbiosProtocol->Add (
+                               SmbiosProtocol,
+                               NULL,
+                               &TableHandle,
+                               SmbiosTable[Index]
+                               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Install SMBIOS Table. Status = %r\n",
+        Status
+        ));
+      // Free any allocated resources.
+      goto exit_handler;
+    }
+
+    Status = TableFactoryProtocol->AddSmbiosHandle (
+                                     SmbiosProtocol,
+                                     &TableHandle,
+                                     CmObjToken[Index],
+                                     SmbiosTableInfo->TableGeneratorId
+                                     );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Add SMBIOS Handle. Status = %r\n",
+        Status
+        ));
+      // Free any allocated resources.
+      goto exit_handler;
+    }
+
+    DEBUG ((
+      DEBUG_INFO,
+      "INFO: SMBIOS Table installed. Status = %r\n",
+      Status
+      ));
+  }
+
+exit_handler:
+  // Free any resources allocated for generating the tables.
+  if (Generator->FreeTableResourcesEx != NULL) {
+    Status1 = Generator->FreeTableResourcesEx (
+                           Generator,
+                           TableFactoryProtocol,
+                           SmbiosTableInfo,
+                           CfgMgrProtocol,
+                           &SmbiosTable,
+                           &CmObjToken,
+                           TableCount
+                           );
+    if (EFI_ERROR (Status1)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to Free Table Resources." \
+        "TableGeneratorId = 0x%x. Status = %r\n",
+        SmbiosTableInfo->TableGeneratorId,
+        Status1
+        ));
+    }
+
+    // Return the first error status in case of failure
+    if (!EFI_ERROR (Status)) {
+      Status = Status1;
+    }
+  }
+
+  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
+  return Status;
+}
+
+/** A helper function to invoke a Table generator
+
+  This is a helper function that invokes the Table generator interface
+  for building an SMBIOS table. It uses the SmbiosProtocol to install the
+  table, then frees the resources allocated for generating it.
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+  @param [in]  SmbiosProtocol       Pointer to the SMBIOS protocol.
+  @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table Info.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         Required object is not found.
+  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration Manager
+                                is less than the Object size for the
+                                requested object.
+**/
+EFI_STATUS
+EFIAPI
+BuildAndInstallSmbiosTable (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
+  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
+  )
+{
+  EFI_STATUS                    Status;
+  CONST SMBIOS_TABLE_GENERATOR  *Generator;
+
+  ASSERT (TableFactoryProtocol != NULL);
+  ASSERT (CfgMgrProtocol != NULL);
+  ASSERT (SmbiosProtocol != NULL);
+  ASSERT (SmbiosTableInfo != NULL);
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: EStdObjSmbiosTableList: Address = 0x%p," \
+    " TableGeneratorId = 0x%x\n",
+    SmbiosTableInfo,
+    SmbiosTableInfo->TableGeneratorId
+    ));
+
+  Generator = NULL;
+  Status    = TableFactoryProtocol->GetSmbiosTableGenerator (
+                                      TableFactoryProtocol,
+                                      SmbiosTableInfo->TableGeneratorId,
+                                      &Generator
+                                      );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Table Generator not found." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      SmbiosTableInfo->TableGeneratorId,
+      Status
+      ));
+    return Status;
+  }
+
+  if (Generator == NULL) {
+    return EFI_NOT_FOUND;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: Generator found : %s\n",
+    Generator->Description
+    ));
+
+  if (Generator->BuildSmbiosTableEx != NULL) {
+    Status = BuildAndInstallMultipleSmbiosTables (
+               TableFactoryProtocol,
+               CfgMgrProtocol,
+               Generator,
+               SmbiosProtocol,
+               SmbiosTableInfo
+               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to find build and install SMBIOS Tables." \
+        " Status = %r\n",
+        Status
+        ));
+    }
+  } else if (Generator->BuildSmbiosTable != NULL) {
+    Status = BuildAndInstallSingleSmbiosTable (
+               TableFactoryProtocol,
+               CfgMgrProtocol,
+               Generator,
+               SmbiosProtocol,
+               SmbiosTableInfo
+               );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((
+        DEBUG_ERROR,
+        "ERROR: Failed to find build and install SMBIOS Table." \
+        " Status = %r\n",
+        Status
+        ));
+    }
+  } else {
+    Status = EFI_INVALID_PARAMETER;
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Table Generator does not implement the" \
+      "SMBIOS_TABLE_GENERATOR_BUILD_TABLE  interface." \
+      " TableGeneratorId = 0x%x. Status = %r\n",
+      SmbiosTableInfo->TableGeneratorId,
+      Status
+      ));
+  }
+
+  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
+  return Status;
+}
+
+/** Generate and install SMBIOS tables.
+
+  The function gathers the information necessary for installing the
+  SMBIOS tables from the Configuration Manager, invokes the generators
+  and installs them (via BuildAndInstallAcpiTable).
+
+  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
+                                    interface.
+  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                    Protocol Interface.
+
+  @retval EFI_SUCCESS   Success.
+  @retval EFI_NOT_FOUND If a mandatory table or a generator is not found.
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+ProcessSmbiosTables (
+  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST  TableFactoryProtocol,
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol
+  )
+{
+  EFI_STATUS                    Status;
+  EFI_SMBIOS_PROTOCOL           *SmbiosProtocol;
+  CM_STD_OBJ_SMBIOS_TABLE_INFO  *SmbiosTableInfo;
+  UINT32                        SmbiosTableCount;
+
+  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&SmbiosProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "Could not locate SMBIOS protocol.  %r\n", Status));
+    return Status;
+  }
+
+  Status = GetEStdObjSmbiosTableList (
+             CfgMgrProtocol,
+             CM_NULL_TOKEN,
+             &SmbiosTableInfo,
+             &SmbiosTableCount
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to get SMBIOS Table List. Status = %r\n",
+      Status
+      ));
+    return Status;
+  }
+
+  if (SmbiosTableCount == 0) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: EStdObjSmbiosTableList: SmbiosTableCount = %d\n",
+      SmbiosTableCount
+      ));
+    return EFI_NOT_FOUND;
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "INFO: EStdObjSmbiosTableList: SmbiosTableCount = %d\n",
+    SmbiosTableCount
+    ));
+
+  InitSmbiosTableDispatcher (SmbiosTableInfo, SmbiosTableCount);
+
+  Status = DispatchSmbiosTables (
+             TableFactoryProtocol,
+             CfgMgrProtocol,
+             SmbiosProtocol,
+             SmbiosTableInfo,
+             SmbiosTableCount
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to install SMBIOS Tables.Status = %r\n",
+      Status
+      ));
+  }
+
+  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
+  return Status;
+}
+
+/** Callback function for SMBIOS Protocol .
+
+  Callback function for SMBIOS protocol that installs SMBIOS tables
+  that use the DynamicTables Package.
+
+  @param  Event
+  @param  Context
+
+  @retval None
+**/
+VOID
+EFIAPI
+SmbiosProtocolReady (
+  IN  EFI_EVENT  Event,
+  IN  VOID       *Context
+  )
+{
+  EFI_STATUS                             Status;
+  EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CfgMgrProtocol;
+  CM_STD_OBJ_CONFIGURATION_MANAGER_INFO  *CfgMfrInfo;
+  EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *TableFactoryProtocol;
+
+  // Locate the Dynamic Table Factory
+  Status = gBS->LocateProtocol (
+                  &gEdkiiDynamicTableFactoryProtocolGuid,
+                  NULL,
+                  (VOID **)&TableFactoryProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to find Dynamic Table Factory protocol." \
+      " Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  // Locate the Configuration Manager for the Platform
+  Status = gBS->LocateProtocol (
+                  &gEdkiiConfigurationManagerProtocolGuid,
+                  NULL,
+                  (VOID **)&CfgMgrProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to find Configuration Manager protocol. Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: Failed to get Configuration Manager info. Status = %r\n",
+      Status
+      ));
+    return;
+  }
+
+  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]
+    ));
+
+  Status = ProcessSmbiosTables (TableFactoryProtocol, CfgMgrProtocol);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: SMBIOS Table processing failure. Status = %r\n",
+      Status
+      ));
+  }
+}
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107257): https://edk2.groups.io/g/devel/message/107257
Mute This Topic: https://groups.io/mt/100361561/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [edk2-devel] [PATCH v3 3/5] DynamicTablesPkg: Introduce new namespace for SMBIOS Objects
  2023-07-25 23:38 [edk2-devel] [PATCH v3 0/5] DynamicTablesPkg: Add SMBIOS Table Generation Girish Mahadevan via groups.io
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table generation Girish Mahadevan via groups.io
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 2/5] DynamicTablesPkg: Split the ACPI and SMBIOS table generators Girish Mahadevan via groups.io
@ 2023-07-25 23:38 ` Girish Mahadevan via groups.io
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 4/5] DynamicTablesPkg: Smbios Memory Device (Type 17) Girish Mahadevan via groups.io
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Smbios Physical Memory Array (Type 16) Girish Mahadevan via groups.io
  4 siblings, 0 replies; 8+ messages in thread
From: Girish Mahadevan via groups.io @ 2023-07-25 23:38 UTC (permalink / raw)
  To: devel, sami.mujawar
  Cc: gmahadevan, Alexei.Fedorov, Pierre.Gondois, jbrasen, ashishsingha,
	nramirez

Introduce a new namespace for SMBIOS related CM Objects.

Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
Reviewed-by: Nick Ramirez <nramirez@nvidia.com>
Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
---
 .../Include/ConfigurationManagerObject.h      | 14 ++++++-
 .../Include/SmbiosNameSpaceObjects.h          | 42 +++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h

diff --git a/DynamicTablesPkg/Include/ConfigurationManagerObject.h b/DynamicTablesPkg/Include/ConfigurationManagerObject.h
index 74ad25d5d9..445c560545 100644
--- a/DynamicTablesPkg/Include/ConfigurationManagerObject.h
+++ b/DynamicTablesPkg/Include/ConfigurationManagerObject.h
@@ -14,6 +14,7 @@
 
 #include <ArmNameSpaceObjects.h>
 #include <StandardNameSpaceObjects.h>
+#include <SmbiosNameSpaceObjects.h>
 
 #pragma pack(1)
 
@@ -107,7 +108,8 @@ typedef UINT32 CM_OBJECT_ID;
 typedef enum ObjectNameSpaceID {
   EObjNameSpaceStandard,      ///< Standard Objects Namespace
   EObjNameSpaceArm,           ///< ARM Objects Namespace
-  EObjNameSpaceOem = 0x8,     ///< OEM Objects Namespace
+  EObjNameSpaceOem    = 0x8,  ///< OEM Objects Namespace
+  EObjNameSpaceSmbios = 0xA,  ///< SMBIOS Objects Namespace
   EObjNameSpaceMax
 } EOBJECT_NAMESPACE_ID;
 
@@ -192,4 +194,14 @@ typedef struct CmObjDescriptor {
 #define CREATE_CM_OEM_OBJECT_ID(ObjectId) \
           (CREATE_CM_OBJECT_ID (EObjNameSpaceOem, ObjectId))
 
+/** This macro returns a Configuration Manager Object ID
+    in the SMBIOS Object Namespace.
+
+  @param [in] ObjectId    The Object ID.
+
+  @retval Returns an SMBIOS Configuration Manager Object ID.
+**/
+#define CREATE_CM_SMBIOS_OBJECT_ID(ObjectId) \
+          (CREATE_CM_OBJECT_ID (EObjNameSpaceSmbios, ObjectId))
+
 #endif // CONFIGURATION_MANAGER_OBJECT_H_
diff --git a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
new file mode 100644
index 0000000000..836c902e40
--- /dev/null
+++ b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
@@ -0,0 +1,42 @@
+/** @file
+
+  Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+    - Cm or CM   - Configuration Manager
+    - Obj or OBJ - Object
+    - Std or STD - Standard
+**/
+
+#ifndef SMBIOS_NAMESPACE_OBJECTS_H_
+#define SMBIOS_NAMESPACE_OBJECTS_H_
+
+#pragma pack(1)
+
+typedef enum SmbiosObjectID {
+  ESmbiosObjReserved,                  ///< 0  - Reserved
+  ESmbiosObjBaseboardInfo,             ///< 1  - Baseboard Information
+  ESmbiosObjSystemSlotInfo,            ///< 2  - System Slot Information
+  ESmbiosObjSystemInfo,                ///< 3  - System Information
+  ESmbiosObjTpmDeviceInfo,             ///< 4  - TPM Device Info
+  ESmbiosObjOemStrings,                ///< 5  - OEM Strings
+  ESmbiosObjPortConnectorInfo,         ///< 6  - Port connector Information
+  ESmbiosObjBiosInfo,                  ///< 7 - Bios Information
+  ESmbiosObjOnboardDeviceExInfo,       ///< 8 - Onboard Device Ex Information
+  ESmbiosObjGroupAssociations,         ///< 9 - Group Associations
+  ESmbiosObjBiosLanguageInfo,          ///< 10 - BIOS Language Information
+  ESmbiosObjEnclosureInfo,             ///< 11 - Enclosure Information
+  ESmbiosObjMemoryDeviceInfo,          ///< 12 - Memory Device Information
+  ESmbiosObjSystemBootInfo,            ///< 13 - System Boot Info
+  ESmbiosObjPhysicalMemoryArray,       ///< 14 - Physical Memory Array
+  ESmbiosObjMemoryArrayMappedAddress,  ///< 15 - Memory Mapped Address
+  ESmbiosObjPowerSupplyInfo,           ///< 16 - Power Supply Info
+  ESmbiosObjFirmwareInventoryInfo,     ///< 17 - Firmware Inventory Info
+  ESmbiosObjMax
+} ESMBIOS_OBJECT_ID;
+
+#pragma pack()
+
+#endif // SMBIOS_NAMESPACE_OBJECTS_H_
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107258): https://edk2.groups.io/g/devel/message/107258
Mute This Topic: https://groups.io/mt/100361562/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [edk2-devel] [PATCH v3 4/5] DynamicTablesPkg: Smbios Memory Device (Type 17)
  2023-07-25 23:38 [edk2-devel] [PATCH v3 0/5] DynamicTablesPkg: Add SMBIOS Table Generation Girish Mahadevan via groups.io
                   ` (2 preceding siblings ...)
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 3/5] DynamicTablesPkg: Introduce new namespace for SMBIOS Objects Girish Mahadevan via groups.io
@ 2023-07-25 23:38 ` Girish Mahadevan via groups.io
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Smbios Physical Memory Array (Type 16) Girish Mahadevan via groups.io
  4 siblings, 0 replies; 8+ messages in thread
From: Girish Mahadevan via groups.io @ 2023-07-25 23:38 UTC (permalink / raw)
  To: devel, sami.mujawar
  Cc: gmahadevan, Alexei.Fedorov, Pierre.Gondois, jbrasen, ashishsingha,
	nramirez

Add the Generator library for SMBIOS Table Type 17 - Memory
Device.

Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
---
 .../Include/SmbiosNameSpaceObjects.h          |  70 +++
 .../SmbiosType17Lib/SmbiosType17Generator.c   | 445 ++++++++++++++++++
 .../SmbiosType17Lib/SmbiosType17Lib.inf       |  36 ++
 3 files changed, 551 insertions(+)
 create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c
 create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf

diff --git a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
index 836c902e40..e44d703fac 100644
--- a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
+++ b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
@@ -13,6 +13,8 @@
 #ifndef SMBIOS_NAMESPACE_OBJECTS_H_
 #define SMBIOS_NAMESPACE_OBJECTS_H_
 
+#include <IndustryStandard/SmBios.h>
+
 #pragma pack(1)
 
 typedef enum SmbiosObjectID {
@@ -37,6 +39,74 @@ typedef enum SmbiosObjectID {
   ESmbiosObjMax
 } ESMBIOS_OBJECT_ID;
 
+/** A structure that describes the physical memory device.
+
+  The physical memory devices on the system are described by this object.
+
+  SMBIOS Specification v3.5.0 Type17
+
+  ID: ESmbiosObjMemoryDeviceInfo,
+*/
+typedef struct CmSmbiosMemoryDeviceInfo {
+  /** Size of the device.
+    Size of the device in bytes.
+  */
+  UINT64                       Size;
+
+  /** Device Set */
+  UINT8                        DeviceSet;
+
+  /** Speed of the device
+    Speed of the device in MegaTransfers/second.
+  */
+  UINT32                       Speed;
+
+  /** Serial Number of device  */
+  CHAR8                        *SerialNum;
+
+  /** AssetTag identifying the device */
+  CHAR8                        *AssetTag;
+
+  /** Device Locator String for the device.
+   String that describes the slot or position of the device on the board.
+   */
+  CHAR8                        *DeviceLocator;
+
+  /** Bank locator string for the device.
+   String that describes the bank where the device is located.
+   */
+  CHAR8                        *BankLocator;
+
+  /** Firmware version of the memory device */
+  CHAR8                        *FirmwareVersion;
+
+  /** Manufacturer Id.
+   2 byte Manufacturer Id as per JEDEC Standard JEP106AV
+  */
+  UINT16                       ModuleManufacturerId;
+
+  /** Manufacturer Product Id
+   2 byte Manufacturer Id as designated by Manufacturer.
+  */
+  UINT16                       ModuleProductId;
+
+  CM_OBJECT_TOKEN              MemoryDeviceInfoToken;
+  CM_OBJECT_TOKEN              PhysicalArrayToken;
+  UINT16                       DataWidth;
+  UINT16                       TotalWidth;
+  UINT8                        Rank;
+
+  MEMORY_DEVICE_TYPE           DeviceType;
+  MEMORY_DEVICE_TYPE_DETAIL    TypeDetail;
+  MEMORY_DEVICE_TECHNOLOGY     DeviceTechnology;
+  MEMORY_FORM_FACTOR           FormFactor;
+} CM_SMBIOS_MEMORY_DEVICE_INFO;
+
+typedef struct {
+  CM_OBJECT_TOKEN              CmObjToken;
+  SMBIOS_TABLE_GENERATOR_ID    GeneratorId;
+} CONTAINED_CM_OBJECTS;
+
 #pragma pack()
 
 #endif // SMBIOS_NAMESPACE_OBJECTS_H_
diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c
new file mode 100644
index 0000000000..27f2dfc235
--- /dev/null
+++ b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Generator.c
@@ -0,0 +1,445 @@
+/** @file
+  SMBIOS Type17 Table Generator.
+
+  Copyright (c) 2022 - 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PrintLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/SmbiosStringTableLib.h>
+
+// Module specific include files.
+#include <ConfigurationManagerObject.h>
+#include <ConfigurationManagerHelper.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+#include <Protocol/DynamicTableFactoryProtocol.h>
+#include <Protocol/Smbios.h>
+#include <IndustryStandard/SmBios.h>
+
+/** This macro expands to a function that retrieves the Memory Device
+    information from the Configuration Manager.
+*/
+GET_OBJECT_LIST (
+  EObjNameSpaceSmbios,
+  ESmbiosObjMemoryDeviceInfo,
+  CM_SMBIOS_MEMORY_DEVICE_INFO
+  )
+
+#define EXTENDED_SIZE_THRESHOLD     (0x7FFF00000LL)
+#define SIZE_GRANULARITY_THRESHOLD  (0x100000L)
+#define SIZE_GRANULARITY_BITMASK    (0x8000)
+#define EXTENDED_SPEED_THRESHOLD    (0xFFFF)
+#define SMBIOS_TYPE17_MAX_STRINGS   (7)
+#define RANK_MASK                   (0x7)
+
+STATIC
+EFI_STATUS
+FreeSmbiosType17TableEx (
+  IN      CONST SMBIOS_TABLE_GENERATOR                   *CONST  This,
+  IN      CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL     *CONST  TableFactoryProtocol,
+  IN      CONST CM_STD_OBJ_SMBIOS_TABLE_INFO             *CONST  SmbiosTableInfo,
+  IN      CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL     *CONST  CfgMgrProtocol,
+  IN      SMBIOS_STRUCTURE                             ***CONST  Table,
+  IN      CM_OBJECT_TOKEN                                        **CmObjectToken,
+  IN      CONST UINTN                                            TableCount
+  )
+{
+  UINTN             Index;
+  SMBIOS_STRUCTURE  **TableList;
+
+  TableList = *Table;
+  for (Index = 0; Index < TableCount; Index++) {
+    if (TableList[Index] != NULL) {
+      FreePool (TableList[Index]);
+    }
+  }
+
+  if (*CmObjectToken != NULL) {
+    FreePool (*CmObjectToken);
+  }
+
+  if (TableList != NULL) {
+    FreePool (TableList);
+  }
+
+  return EFI_SUCCESS;
+}
+
+STATIC
+VOID
+AddPhysArrHandle (
+  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *CONST  TableFactoryProtocol,
+  IN  CM_OBJECT_TOKEN                                      CmObjToken,
+  OUT SMBIOS_TABLE_TYPE17                                  *SmbiosRecord
+  )
+{
+  EFI_SMBIOS_HANDLE  PhysMemArrHandle;
+  SMBIOS_HANDLE_MAP  *HandleMap;
+
+  HandleMap = TableFactoryProtocol->GetSmbiosHandle (CmObjToken);
+  if (HandleMap == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a:Failed to get SMBIOS Handle\n", __FUNCTION__));
+    PhysMemArrHandle = 0;
+  } else {
+    PhysMemArrHandle = HandleMap->SmbiosTblHandle;
+  }
+
+  SmbiosRecord->MemoryArrayHandle = PhysMemArrHandle;
+}
+
+STATIC
+VOID
+UpdateSmbiosType17Size (
+  IN  UINT64               Size,
+  OUT SMBIOS_TABLE_TYPE17  *SmbiosRecord
+  )
+{
+  if (Size < SIZE_GRANULARITY_THRESHOLD) {
+    SmbiosRecord->Size  = Size / SIZE_1KB;
+    SmbiosRecord->Size |= SIZE_GRANULARITY_BITMASK;
+  } else if (Size >= EXTENDED_SIZE_THRESHOLD) {
+    SmbiosRecord->Size         = 0x7FFF;
+    SmbiosRecord->ExtendedSize = (Size / SIZE_1MB);
+  } else {
+    SmbiosRecord->Size = (Size / SIZE_1MB);
+  }
+}
+
+STATIC
+VOID
+UpdateSmbiosType17Speed (
+  IN  UINT32               Speed,
+  OUT SMBIOS_TABLE_TYPE17  *SmbiosRecord
+  )
+{
+  if (Speed > -EXTENDED_SPEED_THRESHOLD) {
+    SmbiosRecord->Speed         = EXTENDED_SPEED_THRESHOLD;
+    SmbiosRecord->ExtendedSpeed = Speed;
+  } else {
+    SmbiosRecord->Speed = Speed;
+  }
+}
+
+STATIC
+VOID
+UpdateSmbiosType17Rank (
+  IN  UINT8                Rank,
+  OUT SMBIOS_TABLE_TYPE17  *SmbiosRecord
+  )
+{
+  if (Rank > RANK_MASK) {
+    SmbiosRecord->Attributes = 0;
+  } else {
+    SmbiosRecord->Attributes |= (Rank & RANK_MASK);
+  }
+}
+
+/** Construct SMBIOS Type17 Table describing memory devices.
+
+  If this function allocates any resources then they must be freed
+  in the FreeXXXXTableResources function.
+
+  @param [in]  This            Pointer to the SMBIOS table generator.
+  @param [in]  SmbiosTableInfo Pointer to the SMBIOS table information.
+  @param [in]  CfgMgrProtocol  Pointer to the Configuration Manager
+                               Protocol interface.
+  @param [out] Table           Pointer to the SMBIOS table.
+
+  @retval EFI_SUCCESS            Table generated successfully.
+  @retval EFI_BAD_BUFFER_SIZE    The size returned by the Configuration
+                                 Manager is less than the Object size for
+                                 the requested object.
+  @retval EFI_INVALID_PARAMETER  A parameter is invalid.
+  @retval EFI_NOT_FOUND          Could not find information.
+  @retval EFI_OUT_OF_RESOURCES   Could not allocate memory.
+  @retval EFI_UNSUPPORTED        Unsupported configuration.
+**/
+STATIC
+EFI_STATUS
+BuildSmbiosType17TableEx (
+  IN  CONST SMBIOS_TABLE_GENERATOR                         *This,
+  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *CONST  TableFactoryProtocol,
+  IN        CM_STD_OBJ_SMBIOS_TABLE_INFO           *CONST  SmbiosTableInfo,
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CONST  CfgMgrProtocol,
+  OUT       SMBIOS_STRUCTURE                               ***Table,
+  OUT       CM_OBJECT_TOKEN                                **CmObjectToken,
+  OUT       UINTN                                  *CONST  TableCount
+  )
+{
+  EFI_STATUS                    Status;
+  UINT32                        NumMemDevices;
+  SMBIOS_STRUCTURE              **TableList;
+  CM_OBJECT_TOKEN               *CmObjectList;
+  CM_SMBIOS_MEMORY_DEVICE_INFO  *MemoryDevicesInfo;
+  UINTN                         Index;
+  UINT8                         SerialNumRef;
+  UINT8                         AssetTagRef;
+  UINT8                         DeviceLocatorRef;
+  UINT8                         BankLocatorRef;
+  UINT8                         FirmwareVersionRef;
+  CHAR8                         *OptionalStrings;
+  SMBIOS_TABLE_TYPE17           *SmbiosRecord;
+  UINTN                         SmbiosRecordSize;
+  STRING_TABLE                  StrTable;
+
+  ASSERT (This != NULL);
+  ASSERT (SmbiosTableInfo != NULL);
+  ASSERT (CfgMgrProtocol != NULL);
+  ASSERT (Table != NULL);
+  ASSERT (TableCount != NULL);
+  ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID);
+
+  if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) ||
+      (Table == NULL) || (TableCount == NULL) ||
+      (SmbiosTableInfo->TableGeneratorId != This->GeneratorID))
+  {
+    DEBUG ((DEBUG_ERROR, "%a:Invalid Paramater\n ", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *Table = NULL;
+  Status = GetESmbiosObjMemoryDeviceInfo (
+             CfgMgrProtocol,
+             CM_NULL_TOKEN,
+             &MemoryDevicesInfo,
+             &NumMemDevices
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "Failed to get Memory Devices CM Object %r\n",
+      Status
+      ));
+    return Status;
+  }
+
+  TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * NumMemDevices);
+  if (TableList == NULL) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a:Failed to alloc memory for %u devices table\n",
+      __FUNCTION__,
+      NumMemDevices
+      ));
+    Status = EFI_OUT_OF_RESOURCES;
+    goto exit;
+  }
+
+  CmObjectList = (CM_OBJECT_TOKEN *)AllocateZeroPool (sizeof (CM_OBJECT_TOKEN *) * NumMemDevices);
+  if (CmObjectList == NULL) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to alloc memory for %u CM Objects\n",
+      __FUNCTION__,
+      NumMemDevices
+      ));
+    Status = EFI_OUT_OF_RESOURCES;
+    goto exit;
+  }
+
+  for (Index = 0; Index < NumMemDevices; Index++) {
+    StringTableInitialize (&StrTable, SMBIOS_TYPE17_MAX_STRINGS);
+
+    SerialNumRef       = 0;
+    AssetTagRef        = 0;
+    DeviceLocatorRef   = 0;
+    BankLocatorRef     = 0;
+    FirmwareVersionRef = 0;
+
+    if (MemoryDevicesInfo[Index].DeviceLocator != NULL) {
+      Status = StringTableAddString (
+                 &StrTable,
+                 MemoryDevicesInfo[Index].DeviceLocator,
+                 &DeviceLocatorRef
+                 );
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "Failed to add DeviceLocator String %r \n", Status));
+      }
+    }
+
+    if (MemoryDevicesInfo[Index].BankLocator != NULL) {
+      Status = StringTableAddString (
+                 &StrTable,
+                 MemoryDevicesInfo[Index].BankLocator,
+                 &BankLocatorRef
+                 );
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "Failed to BankLocator String %r \n", Status));
+      }
+    }
+
+    if (MemoryDevicesInfo[Index].SerialNum != NULL) {
+      Status = StringTableAddString (
+                 &StrTable,
+                 MemoryDevicesInfo[Index].SerialNum,
+                 &SerialNumRef
+                 );
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "Failed to add SerialNum String %r \n", Status));
+      }
+    }
+
+    if (MemoryDevicesInfo[Index].AssetTag != NULL) {
+      Status = StringTableAddString (
+                 &StrTable,
+                 MemoryDevicesInfo[Index].AssetTag,
+                 &AssetTagRef
+                 );
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "Failed to add Asset Tag String %r \n", Status));
+      }
+    }
+
+    if (MemoryDevicesInfo[Index].FirmwareVersion != NULL) {
+      Status = StringTableAddString (
+                 &StrTable,
+                 MemoryDevicesInfo[Index].FirmwareVersion,
+                 &FirmwareVersionRef
+                 );
+      if (EFI_ERROR (Status)) {
+        DEBUG ((DEBUG_ERROR, "Failed to add Asset Tag String %r \n", Status));
+      }
+    }
+
+    SmbiosRecordSize = sizeof (SMBIOS_TABLE_TYPE17) +
+                       StringTableGetStringSetSize (&StrTable);
+    SmbiosRecord = (SMBIOS_TABLE_TYPE17 *)AllocateZeroPool (SmbiosRecordSize);
+    if (SmbiosRecord == NULL) {
+      Status = EFI_OUT_OF_RESOURCES;
+      goto exit;
+    }
+
+    UpdateSmbiosType17Size (MemoryDevicesInfo[Index].Size, SmbiosRecord);
+    UpdateSmbiosType17Speed (MemoryDevicesInfo[Index].Speed, SmbiosRecord);
+    UpdateSmbiosType17Rank (MemoryDevicesInfo[Index].Rank, SmbiosRecord);
+
+    SmbiosRecord->DeviceSet            = MemoryDevicesInfo[Index].DeviceSet;
+    SmbiosRecord->ModuleManufacturerID =
+      MemoryDevicesInfo[Index].ModuleManufacturerId;
+    SmbiosRecord->ModuleProductID =
+      MemoryDevicesInfo[Index].ModuleProductId;
+    SmbiosRecord->DataWidth        = MemoryDevicesInfo[Index].DataWidth;
+    SmbiosRecord->TotalWidth       = MemoryDevicesInfo[Index].TotalWidth;
+    SmbiosRecord->MemoryType       = MemoryDevicesInfo[Index].DeviceType;
+    SmbiosRecord->FormFactor       = MemoryDevicesInfo[Index].FormFactor;
+    SmbiosRecord->MemoryTechnology = MemoryDevicesInfo[Index].DeviceTechnology;
+    // Is there a reference to a Physical Array Device.
+    if (MemoryDevicesInfo[Index].PhysicalArrayToken != CM_NULL_TOKEN) {
+      AddPhysArrHandle (
+        TableFactoryProtocol,
+        MemoryDevicesInfo[Index].PhysicalArrayToken,
+        SmbiosRecord
+        );
+    }
+
+    SmbiosRecord->DeviceLocator   = DeviceLocatorRef;
+    SmbiosRecord->BankLocator     = BankLocatorRef;
+    SmbiosRecord->AssetTag        = AssetTagRef;
+    SmbiosRecord->SerialNumber    = SerialNumRef;
+    SmbiosRecord->FirmwareVersion = FirmwareVersionRef;
+    OptionalStrings               = (CHAR8 *)(SmbiosRecord + 1);
+    // publish the string set
+    StringTablePublishStringSet (
+      &StrTable,
+      OptionalStrings,
+      (SmbiosRecordSize - sizeof (SMBIOS_TABLE_TYPE17))
+      );
+    // setup the header
+    SmbiosRecord->Hdr.Type   = EFI_SMBIOS_TYPE_MEMORY_DEVICE;
+    SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE17);
+    TableList[Index]         = (SMBIOS_STRUCTURE *)SmbiosRecord;
+    CmObjectList[Index]      = MemoryDevicesInfo[Index].MemoryDeviceInfoToken;
+    StringTableFree (&StrTable);
+  }
+
+  *Table         = TableList;
+  *CmObjectToken = CmObjectList;
+  *TableCount    = NumMemDevices;
+exit:
+  // free string table
+  return Status;
+}
+
+/** The interface for the SMBIOS Type17 Table Generator.
+*/
+STATIC
+CONST
+SMBIOS_TABLE_GENERATOR  SmbiosType17Generator = {
+  // Generator ID
+  CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType17),
+  // Generator Description
+  L"SMBIOS.TYPE17.GENERATOR",
+  // SMBIOS Table Type
+  EFI_SMBIOS_TYPE_MEMORY_DEVICE,
+  NULL,
+  NULL,
+  // Build table function Extended.
+  BuildSmbiosType17TableEx,
+  // Free function Extended.
+  FreeSmbiosType17TableEx
+};
+
+/** Register the Generator with the SMBIOS Table Factory.
+
+  @param [in]  ImageHandle  The handle to the image.
+  @param [in]  SystemTable  Pointer to the System Table.
+
+  @retval EFI_SUCCESS           The Generator is registered.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_ALREADY_STARTED   The Generator for the Table ID
+                                is already registered.
+**/
+EFI_STATUS
+EFIAPI
+SmbiosType17LibConstructor (
+  IN  EFI_HANDLE        ImageHandle,
+  IN  EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = RegisterSmbiosTableGenerator (&SmbiosType17Generator);
+  DEBUG ((
+    DEBUG_INFO,
+    "SMBIOS Type 17: Register Generator. Status = %r\n",
+    Status
+    ));
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
+}
+
+/** Deregister the Generator from the SMBIOS Table Factory.
+
+  @param [in]  ImageHandle  The handle to the image.
+  @param [in]  SystemTable  Pointer to the System Table.
+
+  @retval EFI_SUCCESS           The Generator is deregistered.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         The Generator is not registered.
+**/
+EFI_STATUS
+EFIAPI
+SmbiosType17LibDestructor (
+  IN  EFI_HANDLE        ImageHandle,
+  IN  EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = DeregisterSmbiosTableGenerator (&SmbiosType17Generator);
+  DEBUG ((
+    DEBUG_INFO,
+    "SMBIOS Type17: Deregister Generator. Status = %r\n",
+    Status
+    ));
+  ASSERT_EFI_ERROR (Status);
+  return Status;
+}
diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf
new file mode 100644
index 0000000000..e5067f3000
--- /dev/null
+++ b/DynamicTablesPkg/Library/Smbios/SmbiosType17Lib/SmbiosType17Lib.inf
@@ -0,0 +1,36 @@
+## @file
+# SMBIOS Type17 Table Generator
+#
+#  Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+#  Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION    = 0x0001001B
+  BASE_NAME      = SmbiosType17LibArm
+  FILE_GUID      = 1f063bac-f8f1-4e08-8ffd-9aae52c75497
+  VERSION_STRING = 1.0
+  MODULE_TYPE    = DXE_DRIVER
+  LIBRARY_CLASS  = NULL|DXE_DRIVER
+  CONSTRUCTOR    = SmbiosType17LibConstructor
+  DESTRUCTOR     = SmbiosType17LibDestructor
+
+[Sources]
+  SmbiosType17Generator.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  ArmPlatformPkg/ArmPlatformPkg.dec
+  DynamicTablesPkg/DynamicTablesPkg.dec
+
+[Protocols]
+  gEfiSmbiosProtocolGuid                        # PROTOCOL ALWAYS_CONSUMED
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  SmbiosStringTableLib
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107256): https://edk2.groups.io/g/devel/message/107256
Mute This Topic: https://groups.io/mt/100361560/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Smbios Physical Memory Array (Type 16)
  2023-07-25 23:38 [edk2-devel] [PATCH v3 0/5] DynamicTablesPkg: Add SMBIOS Table Generation Girish Mahadevan via groups.io
                   ` (3 preceding siblings ...)
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 4/5] DynamicTablesPkg: Smbios Memory Device (Type 17) Girish Mahadevan via groups.io
@ 2023-07-25 23:38 ` Girish Mahadevan via groups.io
  2023-08-24 19:36   ` Jose Marinho
  4 siblings, 1 reply; 8+ messages in thread
From: Girish Mahadevan via groups.io @ 2023-07-25 23:38 UTC (permalink / raw)
  To: devel, sami.mujawar
  Cc: gmahadevan, Alexei.Fedorov, Pierre.Gondois, jbrasen, ashishsingha,
	nramirez

Add the Generator library for SMBIOS Table Type 16 - Physical
Memory Array.

Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
Reviewed-by: Nick Ramirez <nramirez@nvidia.com>
---
 .../SmbiosTableBuilder.c                      |   3 -
 .../Include/SmbiosNameSpaceObjects.h          |  19 +
 .../SmbiosType16Lib/SmbiosType16Generator.c   | 361 ++++++++++++++++++
 .../SmbiosType16Lib/SmbiosType16Lib.inf       |  35 ++
 4 files changed, 415 insertions(+), 3 deletions(-)
 create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c
 create mode 100644 DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf

diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
index bfddaac3aa..5feafcac66 100644
--- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
+++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
@@ -312,7 +312,6 @@ exit_handler:
     }
   }
 
-  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
   return Status;
 }
 
@@ -432,7 +431,6 @@ BuildAndInstallSmbiosTable (
       ));
   }
 
-  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
   return Status;
 }
 
@@ -516,7 +514,6 @@ ProcessSmbiosTables (
       ));
   }
 
-  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
   return Status;
 }
 
diff --git a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
index e44d703fac..760b082021 100644
--- a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
+++ b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
@@ -107,6 +107,25 @@ typedef struct {
   SMBIOS_TABLE_GENERATOR_ID    GeneratorId;
 } CONTAINED_CM_OBJECTS;
 
+/** A structure that describes the Physical Memory Array.
+
+  SMBIOS Specification v3.6.0 Type 16
+
+  ID: ESmbiosObjPhysicalMemoryArray
+**/
+typedef struct CmSmbiosPhysicalMemoryArray {
+  UINT8              Use;
+  UINT8              Location;
+  UINT16             MemoryErrorCorrection;
+  UINT16             MemoryErrorInformationHandle;
+  UINT16             NumberOfMemoryDevices;
+  UINT8              MemoryErrorCorrectionType;
+  UINT64             Size;
+  UINT8              NumMemDevices;
+  CM_OBJECT_TOKEN    MemoryErrInfoToken;
+  CM_OBJECT_TOKEN    PhysMemArrayToken;
+} CM_SMBIOS_PHYSICAL_MEMORY_ARRAY;
+
 #pragma pack()
 
 #endif // SMBIOS_NAMESPACE_OBJECTS_H_
diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c
new file mode 100644
index 0000000000..dad7588ed5
--- /dev/null
+++ b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator.c
@@ -0,0 +1,361 @@
+/** @file
+  SMBIOS Type16 Table Generator.
+
+  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+  Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PrintLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/SmbiosStringTableLib.h>
+
+// Module specific include files.
+#include <ConfigurationManagerObject.h>
+#include <ConfigurationManagerHelper.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+#include <Protocol/DynamicTableFactoryProtocol.h>
+#include <Protocol/Smbios.h>
+#include <IndustryStandard/SmBios.h>
+
+/** This macro expands to a function that retrieves the Memory Device
+    information from the Configuration Manager.
+*/
+GET_OBJECT_LIST (
+  EObjNameSpaceSmbios,
+  ESmbiosObjPhysicalMemoryArray,
+  CM_SMBIOS_PHYSICAL_MEMORY_ARRAY
+  )
+
+#define EXTENDED_SIZE_THRESHOLD  (SIZE_2TB)
+
+/**
+ * Free any resources allocated when installing SMBIOS Type16 table.
+ *
+ * @param [in]  This                 Pointer to the SMBIOS table generator.
+ * @param [in]  TableFactoryProtocol Pointer to the SMBIOS Table Factory
+                                      Protocol interface.
+
+ * @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table information.
+ * @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+                                     Protocol interface.
+ * @param [in] Table                 Pointer to the SMBIOS table.
+ * @param [in] CmObjectToken         Pointer to the CM ObjectToken Array.
+ * @param [in] TableCount            Number of SMBIOS tables.
+
+ * @retval EFI_SUCCESS            Table generated successfully.
+ * @retval EFI_BAD_BUFFER_SIZE    The size returned by the Configuration
+                                  Manager is less than the Object size for
+                                  the requested object.
+ * @retval EFI_INVALID_PARAMETER  A parameter is invalid.
+ * @retval EFI_NOT_FOUND          Could not find information.
+ * @retval EFI_OUT_OF_RESOURCES   Could not allocate memory.
+ * @retval EFI_UNSUPPORTED        Unsupported configuration.
+**/
+STATIC
+EFI_STATUS
+FreeSmbiosType16TableEx (
+  IN      CONST SMBIOS_TABLE_GENERATOR                    *CONST   This,
+  IN      CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL      *CONST   TableFactoryProtocol,
+  IN      CONST CM_STD_OBJ_SMBIOS_TABLE_INFO              *CONST   SmbiosTableInfo,
+  IN      CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL      *CONST   CfgMgrProtocol,
+  IN      SMBIOS_STRUCTURE                               ***CONST  Table,
+  IN      CM_OBJECT_TOKEN                                          **CmObjectToken,
+  IN      CONST UINTN                                              TableCount
+  )
+{
+  UINTN             Index;
+  SMBIOS_STRUCTURE  **TableList;
+
+  TableList = *Table;
+  for (Index = 0; Index < TableCount; Index++) {
+    if (TableList[Index] != NULL) {
+      FreePool (TableList[Index]);
+    }
+  }
+
+  if (*CmObjectToken != NULL) {
+    FreePool (*CmObjectToken);
+  }
+
+  if (TableList != NULL) {
+    FreePool (TableList);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+ *  Update the Size encoding for Type 16.
+ *
+ *  @param [in]     SizeBytes    Size of the Memory device.
+ *  @param [out]    SmbiosRecord SMBIOS record to update.
+**/
+STATIC
+VOID
+UpdateSmbiosType16Size (
+  IN     UINT64               SizeBytes,
+  IN OUT SMBIOS_TABLE_TYPE16  *SmbiosRecord
+  )
+{
+  UINT64  SizeKb = SizeBytes / SIZE_1KB;
+
+  if (SizeBytes < EXTENDED_SIZE_THRESHOLD) {
+    SmbiosRecord->MaximumCapacity = SizeKb;
+  } else {
+    SmbiosRecord->MaximumCapacity         = 0x80000000;
+    SmbiosRecord->ExtendedMaximumCapacity = SizeKb;
+  }
+}
+
+/**
+ *  Add the SMBIOS table handle reference to the Error Tables.
+ *
+ *  @param [in]     TableFactoryProtocol   Pointer to the SMBIOS Table Factory.
+ *  @param [in]     CmObjToken             CM Token to lookup..
+ *  @param [out]    SmbiosRecord           SMBIOS record to update.
+**/
+STATIC
+VOID
+AddMemErrDeviceHandle (
+  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *CONST  TableFactoryProtocol,
+  IN  CM_OBJECT_TOKEN                                      CmObjToken,
+  OUT SMBIOS_TABLE_TYPE16                                  *SmbiosRecord
+  )
+{
+  EFI_SMBIOS_HANDLE  Handle;
+  SMBIOS_HANDLE_MAP  *HandleMap;
+
+  HandleMap = TableFactoryProtocol->GetSmbiosHandle (CmObjToken);
+  if (HandleMap == NULL) {
+    DEBUG ((DEBUG_ERROR, "%a:Failed to get SMBIOS Handle\n", __FUNCTION__));
+    Handle = 0xFFFF;
+  } else {
+    Handle = HandleMap->SmbiosTblHandle;
+  }
+
+  SmbiosRecord->MemoryErrorInformationHandle = Handle;
+}
+
+/** Construct SMBIOS Type16 Table describing memory devices.
+
+  If this function allocates any resources then they must be freed
+  in the FreeXXXXTableResources function.
+
+ * @param [in]  This                 Pointer to the SMBIOS table generator.
+ * @param [in]  TableFactoryProtocol Pointer to the SMBIOS Table Factory
+ *                                   Protocol interface.
+ * @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table information.
+ * @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
+ *                                   Protocol interface.
+ * @param [out] Table                Pointer to the SMBIOS table.
+ * @param [out] CmObjectToken        Pointer to the CM Object Token Array.
+ * @param [out] TableCount           Number of tables installed.
+
+ * @retval EFI_SUCCESS            Table generated successfully.
+ * @retval EFI_BAD_BUFFER_SIZE    The size returned by the Configuration
+ *                                Manager is less than the Object size for
+ *                                the requested object.
+ * @retval EFI_INVALID_PARAMETER  A parameter is invalid.
+ * @retval EFI_NOT_FOUND          Could not find information.
+ * @retval EFI_OUT_OF_RESOURCES   Could not allocate memory.
+ * @retval EFI_UNSUPPORTED        Unsupported configuration.
+**/
+STATIC
+EFI_STATUS
+BuildSmbiosType16TableEx (
+  IN  CONST SMBIOS_TABLE_GENERATOR                         *This,
+  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *CONST  TableFactoryProtocol,
+  IN        CM_STD_OBJ_SMBIOS_TABLE_INFO           *CONST  SmbiosTableInfo,
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CONST  CfgMgrProtocol,
+  OUT       SMBIOS_STRUCTURE                               ***Table,
+  OUT       CM_OBJECT_TOKEN                                **CmObjectToken,
+  OUT       UINTN                                  *CONST  TableCount
+  )
+{
+  EFI_STATUS                       Status;
+  SMBIOS_STRUCTURE                 **TableList;
+  SMBIOS_TABLE_TYPE16              *SmbiosRecord;
+  CM_OBJECT_TOKEN                  *CmObjectList;
+  CM_SMBIOS_PHYSICAL_MEMORY_ARRAY  *PhysMemoryArray;
+  UINT32                           NumObj;
+  UINTN                            Index;
+
+  ASSERT (This != NULL);
+  ASSERT (SmbiosTableInfo != NULL);
+  ASSERT (CfgMgrProtocol != NULL);
+  ASSERT (Table != NULL);
+  ASSERT (TableCount != NULL);
+  ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID);
+
+  if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL) ||
+      (Table == NULL) || (TableCount == NULL) ||
+      (SmbiosTableInfo->TableGeneratorId != This->GeneratorID))
+  {
+    DEBUG ((DEBUG_ERROR, "%a:Invalid Paramater\n ", __FUNCTION__));
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *Table = NULL;
+  Status = GetESmbiosObjPhysicalMemoryArray (
+             CfgMgrProtocol,
+             CM_NULL_TOKEN,
+             &PhysMemoryArray,
+             &NumObj
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to get Memory Devices CM Object %r\n",
+      __FUNCTION__,
+      Status
+      ));
+    return Status;
+  }
+
+  TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof (SMBIOS_STRUCTURE *) * NumObj);
+  if (TableList == NULL) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to alloc memory for %u devices table\n",
+      __FUNCTION__,
+      NumObj
+      ));
+    Status = EFI_OUT_OF_RESOURCES;
+    goto exitBuildSmbiosType16Table;
+  }
+
+  CmObjectList = (CM_OBJECT_TOKEN *)AllocateZeroPool (sizeof (CM_OBJECT_TOKEN *) * NumObj);
+  if (CmObjectList == NULL) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to alloc memory for %u CM Objects.\n",
+      __FUNCTION__,
+      NumObj
+      ));
+    Status = EFI_OUT_OF_RESOURCES;
+    goto exitBuildSmbiosType16Table;
+  }
+
+  for (Index = 0; Index < NumObj; Index++) {
+    /**
+     * Per Spec each structure is terminated by a double-NULL if there are no
+     * strings.
+     */
+    SmbiosRecord = (SMBIOS_TABLE_TYPE16 *)AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE16) + 1 + 1);
+    if (SmbiosRecord == NULL) {
+      Status = EFI_OUT_OF_RESOURCES;
+      goto exitBuildSmbiosType16Table;
+    }
+
+    UpdateSmbiosType16Size (PhysMemoryArray->Size, SmbiosRecord);
+    SmbiosRecord->Location              = PhysMemoryArray[Index].Location;
+    SmbiosRecord->Use                   = PhysMemoryArray[Index].Use;
+    SmbiosRecord->MemoryErrorCorrection = PhysMemoryArray[Index].MemoryErrorCorrectionType;
+    SmbiosRecord->NumberOfMemoryDevices = PhysMemoryArray->NumMemDevices;
+    if (PhysMemoryArray[Index].MemoryErrInfoToken != CM_NULL_TOKEN) {
+      AddMemErrDeviceHandle (
+        TableFactoryProtocol,
+        PhysMemoryArray[Index].MemoryErrInfoToken,
+        SmbiosRecord
+        );
+    } else {
+      SmbiosRecord->MemoryErrorInformationHandle = 0xFFFF;
+    }
+
+    // Setup the header
+    SmbiosRecord->Hdr.Type   = EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY;
+    SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE16);
+
+    TableList[Index]    = (SMBIOS_STRUCTURE *)SmbiosRecord;
+    CmObjectList[Index] = PhysMemoryArray[Index].PhysMemArrayToken;
+  }
+
+  *Table         = TableList;
+  *CmObjectToken = CmObjectList;
+  *TableCount    = NumObj;
+exitBuildSmbiosType16Table:
+  return Status;
+}
+
+/** The interface for the SMBIOS Type16 Table Generator.
+*/
+STATIC
+CONST
+SMBIOS_TABLE_GENERATOR  SmbiosType16Generator = {
+  // Generator ID
+  CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType16),
+  // Generator Description
+  L"SMBIOS.TYPE16.GENERATOR",
+  // SMBIOS Table Type
+  EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY,
+  NULL,
+  NULL,
+  // Build table function.
+  BuildSmbiosType16TableEx,
+  // Free function.
+  FreeSmbiosType16TableEx,
+};
+
+/** Register the Generator with the SMBIOS Table Factory.
+
+  @param [in]  ImageHandle  The handle to the image.
+  @param [in]  SystemTable  Pointer to the System Table.
+
+  @retval EFI_SUCCESS           The Generator is registered.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_ALREADY_STARTED   The Generator for the Table ID
+                                is already registered.
+**/
+EFI_STATUS
+EFIAPI
+SmbiosType16LibConstructor (
+  IN  EFI_HANDLE        ImageHandle,
+  IN  EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = RegisterSmbiosTableGenerator (&SmbiosType16Generator);
+  DEBUG ((
+    DEBUG_INFO,
+    "SMBIOS Type 16: Register Generator. Status = %r\n",
+    Status
+    ));
+  ASSERT_EFI_ERROR (Status);
+
+  return Status;
+}
+
+/** Deregister the Generator from the SMBIOS Table Factory.
+
+  @param [in]  ImageHandle  The handle to the image.
+  @param [in]  SystemTable  Pointer to the System Table.
+
+  @retval EFI_SUCCESS           The Generator is deregistered.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         The Generator is not registered.
+**/
+EFI_STATUS
+EFIAPI
+SmbiosType16LibDestructor (
+  IN  EFI_HANDLE        ImageHandle,
+  IN  EFI_SYSTEM_TABLE  *SystemTable
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = DeregisterSmbiosTableGenerator (&SmbiosType16Generator);
+  DEBUG ((
+    DEBUG_INFO,
+    "SMBIOS Type16: Deregister Generator. Status = %r\n",
+    Status
+    ));
+  ASSERT_EFI_ERROR (Status);
+  return Status;
+}
diff --git a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf
new file mode 100644
index 0000000000..5bb40db21c
--- /dev/null
+++ b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf
@@ -0,0 +1,35 @@
+## @file
+# SMBIOS Type17 Table Generator
+#
+#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+#  Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION    = 0x0001001B
+  BASE_NAME      = SmbiosType16LibArm
+  FILE_GUID      = a256956a-de0b-4aa7-8eac-5ce13bbfbb1f
+  VERSION_STRING = 1.0
+  MODULE_TYPE    = DXE_DRIVER
+  LIBRARY_CLASS  = NULL|DXE_DRIVER
+  CONSTRUCTOR    = SmbiosType16LibConstructor
+  DESTRUCTOR     = SmbiosType16LibDestructor
+
+[Sources]
+  SmbiosType16Generator.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  ArmPlatformPkg/ArmPlatformPkg.dec
+  DynamicTablesPkg/DynamicTablesPkg.dec
+
+[Protocols]
+  gEfiSmbiosProtocolGuid                        # PROTOCOL ALWAYS_CONSUMED
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107259): https://edk2.groups.io/g/devel/message/107259
Mute This Topic: https://groups.io/mt/100361564/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table generation
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table generation Girish Mahadevan via groups.io
@ 2023-08-24 19:02   ` Jose Marinho
  0 siblings, 0 replies; 8+ messages in thread
From: Jose Marinho @ 2023-08-24 19:02 UTC (permalink / raw)
  To: devel@edk2.groups.io, gmahadevan@nvidia.com, Sami Mujawar
  Cc: Alexei Fedorov, Pierre Gondois, Jeff Brasen (jbrasen@nvidia.com),
	ashishsingha@nvidia.com, nramirez@nvidia.com, nd

Hi,

I have a couple of minor comments.

reviewed-by: Jose Marinho <jose.marinho@arm.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Girish
> Mahadevan via groups.io
> Sent: Wednesday, July 26, 2023 12:38 AM
> To: devel@edk2.groups.io; Sami Mujawar <Sami.Mujawar@arm.com>
> Cc: gmahadevan@nvidia.com; Alexei Fedorov <Alexei.Fedorov@arm.com>;
> Pierre Gondois <Pierre.Gondois@arm.com>; Jeff Brasen (jbrasen@nvidia.com)
> <jbrasen@nvidia.com>; ashishsingha@nvidia.com; nramirez@nvidia.com
> Subject: [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table
> generation
> 
> Add the SMBIOS Table generator code to the DynamicTablesPkg.
> 
> This change includes adding new logic to the DynamicTableManager to
> process and add SMBIOS tables and augmenting the existing SMBIOS Factory
> generator to include installing multiple SMBIOS tables .
> Also included is running the SMBIOS and ACPI table generation as part of the
> SMBIOS and ACPI protocol GUID callback notifications respectively.
> 
> Change-Id: Icc090108c16e87657260af6daf856f3d69b602e3
> Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
> Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
> ---
>  .../DynamicTableFactory.h                     |   5 +
>  .../DynamicTableFactoryDxe.c                  |  10 +
>  .../SmbiosTableFactory/SmbiosTableFactory.c   | 108 +++
>  .../DynamicTableManagerDxe.c                  | 677 +++++++++++++++++-
>  .../DynamicTableManagerDxe.inf                |   3 +-
>  .../Protocol/DynamicTableFactoryProtocol.h    |  10 +
>  .../Include/SmbiosTableGenerator.h            | 204 +++++-
>  MdePkg/Include/IndustryStandard/SmBios.h      |   8 +
>  8 files changed, 994 insertions(+), 31 deletions(-)
> 
> diff --git
> a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h
> b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.
> h
> index b160dcf8ad..20e438ea70 100644
> ---
> a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactory.h
> +++
> b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactor
> +++ y.h
> @@ -49,6 +49,11 @@ typedef struct DynamicTableFactoryInfo {
>          CustomDtTableGeneratorList[FixedPcdGet16 (
>                                   PcdMaxCustomDTGenerators
>                                   )];
> +
> +  /// An array for holding a map of SMBIOS handles and the CM Object
> + /// token used to build the SMBIOS record.
> +  SMBIOS_HANDLE_MAP
> +        SmbiosHandleMap[MAX_SMBIOS_HANDLES];
>  } EDKII_DYNAMIC_TABLE_FACTORY_INFO;
> 
>  /** Return a pointer to the ACPI table generator.
> diff --git
> a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryD
> xe.c
> b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryD
> xe.c
> index 6d6d3fa746..577cdb576e 100644
> ---
> a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryD
> xe.c
> +++
> b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactor
> +++ yDxe.c
> @@ -1,6 +1,7 @@
>  /** @file
>    Dynamic Table Factory Dxe
> 
> +  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
>    Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -44,6 +45,9 @@
> EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  DynamicTableFactoryProtocol =
> {
>    GetDtTableGenerator,
>    RegisterDtTableGenerator,
>    DeregisterDtTableGenerator,
> +  AddSmbiosHandle,
> +  FindSmbiosHandle,
> +  FindSmbiosHandleEx,
>    &TableFactoryInfo
>  };
> 
> @@ -65,6 +69,12 @@ DynamicTableFactoryDxeInitialize (
>    )
>  {
>    EFI_STATUS  Status;
> +  UINTN       Idx;
> +
> +  for (Idx = 0; Idx < MAX_SMBIOS_HANDLES; Idx++) {
> +    TableFactoryInfo.SmbiosHandleMap[Idx].SmbiosTblHandle =
> SMBIOS_HANDLE_PI_RESERVED;
> +    TableFactoryInfo.SmbiosHandleMap[Idx].SmbiosCmToken   = 0;
> +  }
> 
>    Status = gBS->InstallProtocolInterface (
>                    &ImageHandle,
> diff --git
> a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/S
> mbiosTableFactory.c
> b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/S
> mbiosTableFactory.c
> index 87795919f8..b928c28a14 100644
> ---
> a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory/S
> mbiosTableFactory.c
> +++
> b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/SmbiosTableFactory
> +++ /SmbiosTableFactory.c
> @@ -1,6 +1,7 @@
>  /** @file
>    SMBIOS Table Factory
> 
> +  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
>    Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -12,6 +13,7 @@  #include
> <IndustryStandard/SmBios.h>  #include <Library/BaseLib.h>  #include
> <Library/BaseMemoryLib.h>
> +#include <Library/MemoryAllocationLib.h>
>  #include <Library/DebugLib.h>
> 
>  // Module specific include files.
> @@ -24,6 +26,71 @@
> 
>  extern EDKII_DYNAMIC_TABLE_FACTORY_INFO  TableFactoryInfo;
> 
> +/** Add a new entry to the SMBIOS table Map.
> +
> +  @param [in]  Smbios         SMBIOS Protocol pointer.
> +  @param [in]  SmbiosHandle   SMBIOS Handle to be added, if the value
> SMBIOS_HANDLE_PI_RESERVED
> +                              is passed then a new SmbiosHandle is assigned.
> +  @param [in]  CmObjectToken  CmObjectToken of the CM_OBJECT used to
> build the SMBIOS Table
> +  @param [in]  GeneratorId    Smbios Table Generator Id.
> +
> +  @retval EFI_SUCCESS               Successfully added/generated the handle.
> +  @retval EFI_OUT_OF_RESOURCESNULL  Failure to add/generate the handle.
> +**/
> +EFI_STATUS
> +EFIAPI
> +AddSmbiosHandle (
> +  IN EFI_SMBIOS_PROTOCOL         *Smbios,
> +  IN SMBIOS_HANDLE               *SmbiosHandle,
> +  IN CM_OBJECT_TOKEN             CmObjectToken,
> +  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId
> +  )
> +{
> +  EFI_STATUS  Status;
> +  UINTN       Index;

nit: Does it make sense to name index variables in a coherent way? You used "Idx" above.

> +
> +  Status = EFI_OUT_OF_RESOURCES;
> +
> +  for (Index = 0; Index < MAX_SMBIOS_HANDLES; Index++) {
> +    if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle ==
> SMBIOS_HANDLE_PI_RESERVED) {
> +      TableFactoryInfo.SmbiosHandleMap[Index].SmbiosTblHandle   =
> *SmbiosHandle;
> +      TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken     =
> CmObjectToken;
> +      TableFactoryInfo.SmbiosHandleMap[Index].SmbiosGeneratorId =
> GeneratorId;
> +      Status                                                    = EFI_SUCCESS;
> +      break;
> +    }
> +  }
> +
> +  return Status;
> +}
> +
> +/** Return a pointer to the SMBIOS table Map.
> +
> +  @param [in]  GeneratorId  The CmObjectToken to look up an SMBIOS
> Handle.
> +
> +  @retval SMBIOS_HANDLE_MAP if the CmObjectToken is found.
> +  @retval NULL if not found.
> +**/
> +SMBIOS_HANDLE_MAP *
> +EFIAPI
> +FindSmbiosHandle (
> +  CM_OBJECT_TOKEN  CmObjectToken
> +  )
> +{
> +  UINTN              Index;
> +  SMBIOS_HANDLE_MAP  *SmbiosHandleMap;
> +
> +  SmbiosHandleMap = NULL;
> +  for (Index = 0; Index < MAX_SMBIOS_HANDLES; Index++) {
> +    if (TableFactoryInfo.SmbiosHandleMap[Index].SmbiosCmToken ==
> CmObjectToken) {
> +      SmbiosHandleMap = &TableFactoryInfo.SmbiosHandleMap[Index];
> +      break;
> +    }
> +  }
> +
> +  return SmbiosHandleMap;
> +}
> +
>  /** Return a pointer to the SMBIOS table generator.
> 
>    @param [in]  This         Pointer to the Dynamic Table Factory Protocol.
> @@ -229,3 +296,44 @@ DeregisterSmbiosTableGenerator (
>    DEBUG ((DEBUG_INFO, "Deregistering %s\n", Generator->Description));
>    return EFI_SUCCESS;
>  }
> +
> +/** Find and return SMBIOS handle based on associated CM object token.
> +
> +  @param [in]  GeneratorId     SMBIOS generator ID used to build the SMBIOS
> Table.
> +  @param [in]  CmObjectToken   Token of the CM_OBJECT used to build the
> SMBIOS Table.
> +
> +  @return  SMBIOS handle of the table associated with SmbiosGeneratorId
> and
> +           CmObjectToken if found. Otherwise, returns 0xFFFF.
> +**/
> +UINT16
> +EFIAPI
> +FindSmbiosHandleEx (
> +  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId,
> +  IN  CM_OBJECT_TOKEN            CmObjToken
> +  )
> +{
> +  SMBIOS_HANDLE_MAP  *HandleMap;
> +
> +  if (CmObjToken == CM_NULL_TOKEN) {
> +    return SMBIOS_HANDLE_INVALID;
> +  }
> +
> +  HandleMap = FindSmbiosHandle (CmObjToken);  if (HandleMap == NULL) {
> +    return SMBIOS_HANDLE_INVALID;
> +  }
> +
> +  if (HandleMap->SmbiosGeneratorId != GeneratorId) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "%a: Expect ID %d but get %d\n",
> +      __FUNCTION__,
> +      GeneratorId,
> +      HandleMap->SmbiosGeneratorId
> +      ));
> +    ASSERT (FALSE);
> +    return SMBIOS_HANDLE_INVALID;
> +  }
> +
> +  return HandleMap->SmbiosTblHandle;
> +}
> diff --git
> a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManag
> erDxe.c
> b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManag
> erDxe.c
> index 1e9b811c40..26aa9b55cf 100644
> ---
> a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManag
> erDxe.c
> +++
> b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManag
> e
> +++ rDxe.c
> @@ -8,10 +8,13 @@
>  **/
> 
>  #include <Library/DebugLib.h>
> +#include <Library/UefiLib.h>
>  #include <Library/PcdLib.h>
>  #include <Library/UefiBootServicesTableLib.h>
>  #include <Protocol/AcpiSystemDescriptionTable.h>
>  #include <Protocol/AcpiTable.h>
> +#include <Protocol/Smbios.h>
> +#include <Library/BaseMemoryLib.h>
> 
>  // Module specific include files.
>  #include <AcpiTableGenerator.h>
> @@ -22,6 +25,7 @@
>  #include <Protocol/ConfigurationManagerProtocol.h>
>  #include <Protocol/DynamicTableFactoryProtocol.h>
>  #include <SmbiosTableGenerator.h>
> +#include <SmbiosTableDispatcher.h>
> 
>  ///
>  /// Bit definitions for acceptable ACPI table presence formats.
> @@ -84,6 +88,18 @@ GET_OBJECT_LIST (
>    CM_STD_OBJ_ACPI_TABLE_INFO
>    )
> 
> +/** This macro expands to a function that retrieves the SMBIOS Table
> +    List from the Configuration Manager.
> +*/
> +GET_OBJECT_LIST (
> +  EObjNameSpaceStandard,
> +  EStdObjSmbiosTableList,
> +  CM_STD_OBJ_SMBIOS_TABLE_INFO
> +  )
> +
> +STATIC VOID *AcpiTableProtocolRegistration; STATIC VOID
> +*SmbiosProtocolRegistration;
> +
>  /** A helper function to build and install a single ACPI table.
> 
>    This is a helper function that invokes the Table generator interface @@ -
> 530,6 +546,490 @@ VerifyMandatoryTablesArePresent (
>    return Status;
>  }
> 
> +/** A helper function to build and install an SMBIOS table.
> +
> +  This is a helper function that invokes the Table generator interface
> + for building an SMBIOS table. It uses the SmbiosProtocol to install
> + the  table, then frees the resources allocated for generating it.
> +
> +  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
> +                                    interface.
> +  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
> +                                    Protocol Interface.
> +  @param [in]  SmbiosProtocol       Pointer to the SMBIOS protocol.
> +  @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table Info.
> +
> +  @retval EFI_SUCCESS           Success.
> +  @retval EFI_INVALID_PARAMETER A parameter is invalid.
> +  @retval EFI_NOT_FOUND         Required object is not found.
> +  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration
> Manager
> +                                is less than the Object size for the
> +                                requested object.
> +**/
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +BuildAndInstallSingleSmbiosTable (
> +  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST
> +TableFactoryProtocol,
> +  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST
> CfgMgrProtocol,
> +  IN CONST SMBIOS_TABLE_GENERATOR                *CONST  Generator,
> +  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
> +  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
> +  )
> +{
> +  EFI_STATUS         Status;
> +  EFI_STATUS         Status1;
> +  SMBIOS_STRUCTURE   *SmbiosTable;
> +  CM_OBJECT_TOKEN    CmObjToken;
> +  EFI_SMBIOS_HANDLE  TableHandle;
> +
> +  SmbiosTable = NULL;
> +  Status      = Generator->BuildSmbiosTable (
> +                             Generator,
> +                             TableFactoryProtocol,
> +                             SmbiosTableInfo,
> +                             CfgMgrProtocol,
> +                             &SmbiosTable,
> +                             &CmObjToken
> +                             );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to Build Table." \
> +      " TableGeneratorId = 0x%x. Status = %r\n",
> +      SmbiosTableInfo->TableGeneratorId,
> +      Status
> +      ));
> +    // Free any allocated resources.
> +    goto exit_handler;
> +  }
> +
> +  if (SmbiosTable == NULL) {
> +    Status = EFI_NOT_FOUND;
> +    goto exit_handler;
> +  }
> +
> +  TableHandle = SMBIOS_HANDLE_PI_RESERVED;  // Install SMBIOS table
> + Status = SmbiosProtocol->Add (
> +                             SmbiosProtocol,
> +                             NULL,
> +                             &TableHandle,
> +                             SmbiosTable
> +                             );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to Install SMBIOS Table. Status = %r\n",
> +      Status
> +      ));
> +    // Free any allocated resources.
> +    goto exit_handler;
> +  }
> +
> +  Status = TableFactoryProtocol->AddSmbiosHandle (
> +                                   SmbiosProtocol,
> +                                   &TableHandle,
> +                                   CmObjToken,
> +                                   SmbiosTableInfo->TableGeneratorId
> +                                   );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to Add SMBIOS Handle. Status = %r\n",
> +      Status
> +      ));
> +    // Free any allocated resources.
> +    goto exit_handler;
> +  }
> +
> +  DEBUG ((
> +    DEBUG_INFO,
> +    "INFO: SMBIOS Table installed. Status = %r\n",
> +    Status
> +    ));
> +
> +exit_handler:
> +  // Free any resources allocated for generating the tables.
> +  if (Generator->FreeTableResources != NULL) {
> +    Status1 = Generator->FreeTableResources (
> +                           Generator,
> +                           TableFactoryProtocol,
> +                           SmbiosTableInfo,
> +                           CfgMgrProtocol,
> +                           &SmbiosTable
> +                           );
> +    if (EFI_ERROR (Status1)) {
> +      DEBUG ((
> +        DEBUG_ERROR,
> +        "ERROR: Failed to Free Table Resources." \
> +        "TableGeneratorId = 0x%x. Status = %r\n",
> +        SmbiosTableInfo->TableGeneratorId,
> +        Status1
> +        ));
> +    }
> +
> +    // Return the first error status in case of failure
> +    if (!EFI_ERROR (Status)) {
> +      Status = Status1;
> +    }
> +  }
> +
> +  return Status;
> +}
> +
> +/** A helper function to build and install multiple SMBIOS tables.
> +
> +  This is a helper function that invokes the Table generator interface
> + for building SMBIOS tables. It uses the SmbiosProtocol to install the
> + tables, then frees the resources allocated for generating it.
> +
> +  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
> +                                    interface.
> +  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
> +                                    Protocol Interface.
> +  @param [in]  Generator            Pointer to the SmbiosTable generator.
> +  @param [in]  SmbiosProtocol       Pointer to the Smbios protocol.
> +  @param [in]  AcpiTableInfo        Pointer to the SMBIOS table Info.
> +
> +  @retval EFI_SUCCESS           Success.
> +  @retval EFI_INVALID_PARAMETER A parameter is invalid.
> +  @retval EFI_NOT_FOUND         Required object is not found.
> +  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration
> Manager
> +                                is less than the Object size for the
> +                                requested object.
> +**/
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +BuildAndInstallMultipleSmbiosTables (
> +  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST
> +TableFactoryProtocol,
> +  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST
> CfgMgrProtocol,
> +  IN CONST SMBIOS_TABLE_GENERATOR                *CONST  Generator,
> +  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
> +  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
> +  )
> +{
> +  EFI_STATUS         Status;
> +  EFI_STATUS         Status1;
> +  SMBIOS_STRUCTURE   **SmbiosTable;
> +  CM_OBJECT_TOKEN    *CmObjToken;
> +  EFI_SMBIOS_HANDLE  TableHandle;
> +  UINTN              TableCount;
> +  UINTN              Index;
> +
> +  TableCount = 0;
> +  Status     = Generator->BuildSmbiosTableEx (
> +                            Generator,
> +                            TableFactoryProtocol,
> +                            SmbiosTableInfo,
> +                            CfgMgrProtocol,
> +                            &SmbiosTable,
> +                            &CmObjToken,
> +                            &TableCount
> +                            );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to Build Table." \
> +      " TableGeneratorId = 0x%x. Status = %r\n",
> +      SmbiosTableInfo->TableGeneratorId,
> +      Status
> +      ));
> +    // Free any allocated resources.
> +    goto exit_handler;
> +  }
> +
> +  if ((SmbiosTable == NULL) || (TableCount == 0)) {
> +    Status = EFI_NOT_FOUND;
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "%a: TableCount %u SmbiosTable %p \n",
> +      __FUNCTION__,
> +      TableCount,
> +      SmbiosTable
> +      ));
> +    goto exit_handler;
> +  }
> +
> +  for (Index = 0; Index < TableCount; Index++) {
> +    TableHandle = SMBIOS_HANDLE_PI_RESERVED;
> +

Does the logic below reimplement BuildAndInstallSingleSmbiosTable?
If yes, could that function be called here instead?

> +    // Install SMBIOS table
> +    Status = SmbiosProtocol->Add (
> +                               SmbiosProtocol,
> +                               NULL,
> +                               &TableHandle,
> +                               SmbiosTable[Index]
> +                               );
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((
> +        DEBUG_ERROR,
> +        "ERROR: Failed to Install SMBIOS Table. Status = %r\n",
> +        Status
> +        ));
> +      // Free any allocated resources.
> +      goto exit_handler;
> +    }
> +
> +    Status = TableFactoryProtocol->AddSmbiosHandle (
> +                                     SmbiosProtocol,
> +                                     &TableHandle,
> +                                     CmObjToken[Index],
> +                                     SmbiosTableInfo->TableGeneratorId
> +                                     );
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((
> +        DEBUG_ERROR,
> +        "ERROR: Failed to Add SMBIOS Handle. Status = %r\n",
> +        Status
> +        ));
> +      // Free any allocated resources.
> +      goto exit_handler;
> +    }
> +
> +    DEBUG ((
> +      DEBUG_INFO,
> +      "INFO: SMBIOS Table installed. Status = %r\n",
> +      Status
> +      ));
> +  }
> +
> +exit_handler:
> +  // Free any resources allocated for generating the tables.
> +  if (Generator->FreeTableResourcesEx != NULL) {
> +    Status1 = Generator->FreeTableResourcesEx (
> +                           Generator,
> +                           TableFactoryProtocol,
> +                           SmbiosTableInfo,
> +                           CfgMgrProtocol,
> +                           &SmbiosTable,
> +                           &CmObjToken,
> +                           TableCount
> +                           );
> +    if (EFI_ERROR (Status1)) {
> +      DEBUG ((
> +        DEBUG_ERROR,
> +        "ERROR: Failed to Free Table Resources." \
> +        "TableGeneratorId = 0x%x. Status = %r\n",
> +        SmbiosTableInfo->TableGeneratorId,
> +        Status1
> +        ));
> +    }
> +
> +    // Return the first error status in case of failure
> +    if (!EFI_ERROR (Status)) {
> +      Status = Status1;
> +    }
> +  }
> +
> +  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
> +  return Status;
> +}
> +
> +/** A helper function to invoke a Table generator
> +
> +  This is a helper function that invokes the Table generator interface
> + for building an SMBIOS table. It uses the SmbiosProtocol to install
> + the  table, then frees the resources allocated for generating it.
> +
> +  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
> +                                    interface.
> +  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
> +                                    Protocol Interface.
> +  @param [in]  SmbiosProtocol       Pointer to the SMBIOS protocol.
> +  @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table Info.
> +
> +  @retval EFI_SUCCESS           Success.
> +  @retval EFI_INVALID_PARAMETER A parameter is invalid.
> +  @retval EFI_NOT_FOUND         Required object is not found.
> +  @retval EFI_BAD_BUFFER_SIZE   Size returned by the Configuration
> Manager
> +                                is less than the Object size for the
> +                                requested object.
> +**/
> +EFI_STATUS
> +EFIAPI
> +BuildAndInstallSmbiosTable (
> +  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST
> +TableFactoryProtocol,
> +  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST
> CfgMgrProtocol,
> +  IN       EFI_SMBIOS_PROTOCOL                           *SmbiosProtocol,
> +  IN       CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo
> +  )
> +{
> +  EFI_STATUS                    Status;
> +  CONST SMBIOS_TABLE_GENERATOR  *Generator;
> +
> +  ASSERT (TableFactoryProtocol != NULL);  ASSERT (CfgMgrProtocol !=
> + NULL);  ASSERT (SmbiosProtocol != NULL);  ASSERT (SmbiosTableInfo !=
> + NULL);
> +
> +  DEBUG ((
> +    DEBUG_INFO,
> +    "INFO: EStdObjSmbiosTableList: Address = 0x%p," \
> +    " TableGeneratorId = 0x%x\n",
> +    SmbiosTableInfo,
> +    SmbiosTableInfo->TableGeneratorId
> +    ));
> +
> +  Generator = NULL;
> +  Status    = TableFactoryProtocol->GetSmbiosTableGenerator (
> +                                      TableFactoryProtocol,
> +                                      SmbiosTableInfo->TableGeneratorId,
> +                                      &Generator
> +                                      );  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Table Generator not found." \
> +      " TableGeneratorId = 0x%x. Status = %r\n",
> +      SmbiosTableInfo->TableGeneratorId,
> +      Status
> +      ));
> +    return Status;
> +  }
> +
> +  if (Generator == NULL) {
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  DEBUG ((
> +    DEBUG_INFO,
> +    "INFO: Generator found : %s\n",
> +    Generator->Description
> +    ));
> +
> +  if (Generator->BuildSmbiosTableEx != NULL) {
> +    Status = BuildAndInstallMultipleSmbiosTables (
> +               TableFactoryProtocol,
> +               CfgMgrProtocol,
> +               Generator,
> +               SmbiosProtocol,
> +               SmbiosTableInfo
> +               );
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((
> +        DEBUG_ERROR,
> +        "ERROR: Failed to find build and install SMBIOS Tables." \
> +        " Status = %r\n",
> +        Status
> +        ));
> +    }
> +  } else if (Generator->BuildSmbiosTable != NULL) {
> +    Status = BuildAndInstallSingleSmbiosTable (
> +               TableFactoryProtocol,
> +               CfgMgrProtocol,
> +               Generator,
> +               SmbiosProtocol,
> +               SmbiosTableInfo
> +               );
> +    if (EFI_ERROR (Status)) {
> +      DEBUG ((
> +        DEBUG_ERROR,
> +        "ERROR: Failed to find build and install SMBIOS Table." \
> +        " Status = %r\n",
> +        Status
> +        ));
> +    }
> +  } else {
> +    Status = EFI_INVALID_PARAMETER;
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Table Generator does not implement the" \
> +      "SMBIOS_TABLE_GENERATOR_BUILD_TABLE  interface." \
> +      " TableGeneratorId = 0x%x. Status = %r\n",
> +      SmbiosTableInfo->TableGeneratorId,
> +      Status
> +      ));
> +  }
> +
> +  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
> +  return Status;
> +}
> +
> +/** Generate and install SMBIOS tables.
> +
> +  The function gathers the information necessary for installing the
> + SMBIOS tables from the Configuration Manager, invokes the generators
> + and installs them (via BuildAndInstallAcpiTable).
> +
> +  @param [in]  TableFactoryProtocol Pointer to the Table Factory Protocol
> +                                    interface.
> +  @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
> +                                    Protocol Interface.
> +
> +  @retval EFI_SUCCESS   Success.
> +  @retval EFI_NOT_FOUND If a mandatory table or a generator is not found.
> +**/
> +STATIC
> +EFI_STATUS
> +EFIAPI
> +ProcessSmbiosTables (
> +  IN CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST
> +TableFactoryProtocol,
> +  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST
> CfgMgrProtocol
> +  )
> +{
> +  EFI_STATUS                    Status;
> +  EFI_SMBIOS_PROTOCOL           *SmbiosProtocol;
> +  CM_STD_OBJ_SMBIOS_TABLE_INFO  *SmbiosTableInfo;
> +  UINT32                        SmbiosTableCount;
> +
> +  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID
> + **)&SmbiosProtocol);  if (EFI_ERROR (Status)) {
> +    DEBUG ((DEBUG_ERROR, "Could not locate SMBIOS protocol.  %r\n",
> Status));
> +    return Status;
> +  }
> +
> +  Status = GetEStdObjSmbiosTableList (
> +             CfgMgrProtocol,
> +             CM_NULL_TOKEN,
> +             &SmbiosTableInfo,
> +             &SmbiosTableCount
> +             );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to get SMBIOS Table List. Status = %r\n",
> +      Status
> +      ));
> +    return Status;
> +  }
> +
> +  if (SmbiosTableCount == 0) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: EStdObjSmbiosTableList: SmbiosTableCount = %d\n",
> +      SmbiosTableCount
> +      ));
> +    return EFI_NOT_FOUND;
> +  }
> +
> +  DEBUG ((
> +    DEBUG_INFO,
> +    "INFO: EStdObjSmbiosTableList: SmbiosTableCount = %d\n",
> +    SmbiosTableCount
> +    ));
> +
> +  InitSmbiosTableDispatcher (SmbiosTableInfo, SmbiosTableCount);
> +
> +  Status = DispatchSmbiosTables (
> +             TableFactoryProtocol,
> +             CfgMgrProtocol,
> +             SmbiosProtocol,
> +             SmbiosTableInfo,
> +             SmbiosTableCount
> +             );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to install SMBIOS Tables.Status = %r\n",
> +      Status
> +      ));
> +  }
> +
> +  return Status;
> +}
> +
>  /** Generate and install ACPI tables.
> 
>    The function gathers the information necessary for installing the @@ -
> 701,30 +1201,20 @@ ProcessAcpiTables (
>    return Status;
>  }
> 
> -/** Entrypoint of Dynamic Table Manager Dxe.
> +/** Callback function for ACPI Protocol .
> 
> -  The Dynamic Table Manager uses the Configuration Manager Protocol
> -  to get the list of ACPI and SMBIOS tables to install. For each table
> -  in the list it requests the corresponding ACPI/SMBIOS table factory for
> -  a generator capable of building the ACPI/SMBIOS table.
> -  If a suitable table generator is found, it invokes the generator interface
> -  to build the table. The Dynamic Table Manager then installs the
> -  table and invokes another generator interface to free any resources
> -  allocated for building the table.
> +  Callback function for ACPI protocol that installs ACPI tables
> 
> -  @param  ImageHandle
> -  @param  SystemTable
> +  @param  Event
> +  @param  Context
> 
> -  @retval EFI_SUCCESS           Success.
> -  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
> -  @retval EFI_NOT_FOUND         Required interface/object was not found.
> -  @retval EFI_INVALID_PARAMETER Some parameter is incorrect/invalid.
> +  @retval None
>  **/
> -EFI_STATUS
> -EFIAPI
> -DynamicTableManagerDxeInitialize (
> -  IN  EFI_HANDLE        ImageHandle,
> -  IN  EFI_SYSTEM_TABLE  *SystemTable
> +STATIC
> +VOID
> +AcpiTableProtocolReady (
> +  IN  EFI_EVENT  Event,
> +  IN  VOID       *Context
>    )
>  {
>    EFI_STATUS                             Status;
> @@ -745,7 +1235,7 @@ DynamicTableManagerDxeInitialize (
>        " Status = %r\n",
>        Status
>        ));
> -    return Status;
> +    return;
>    }
> 
>    // Locate the Configuration Manager for the Platform @@ -760,7 +1250,7
> @@ DynamicTableManagerDxeInitialize (
>        "ERROR: Failed to find Configuration Manager protocol. Status = %r\n",
>        Status
>        ));
> -    return Status;
> +    return;
>    }
> 
>    Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo); @@ -770,7 +1260,7
> @@ DynamicTableManagerDxeInitialize (
>        "ERROR: Failed to get Configuration Manager info. Status = %r\n",
>        Status
>        ));
> -    return Status;
> +    return;
>    }
> 
>    DEBUG ((
> @@ -793,6 +1283,147 @@ DynamicTableManagerDxeInitialize (
>        Status
>        ));
>    }
> +}
> +
> +/** Callback function for SMBIOS Protocol .
> +
> +  Callback function for SMBIOS protocol that installs SMBIOS tables
> + that use the DynamicTables Package.
> +
> +  @param  Event
> +  @param  Context
> +
> +  @retval None
> +**/
> +STATIC
> +VOID
> +SmbiosProtocolReady (
> +  IN  EFI_EVENT  Event,
> +  IN  VOID       *Context
> +  )
> +{
> +  EFI_STATUS                             Status;
> +  EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CfgMgrProtocol;
> +  CM_STD_OBJ_CONFIGURATION_MANAGER_INFO  *CfgMfrInfo;
> +  EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *TableFactoryProtocol;
> +
> +  // Locate the Dynamic Table Factory
> +  Status = gBS->LocateProtocol (
> +                  &gEdkiiDynamicTableFactoryProtocolGuid,
> +                  NULL,
> +                  (VOID **)&TableFactoryProtocol
> +                  );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to find Dynamic Table Factory protocol." \
> +      " Status = %r\n",
> +      Status
> +      ));
> +    return;
> +  }
> +
> +  // Locate the Configuration Manager for the Platform  Status =
> + gBS->LocateProtocol (
> +                  &gEdkiiConfigurationManagerProtocolGuid,
> +                  NULL,
> +                  (VOID **)&CfgMgrProtocol
> +                  );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to find Configuration Manager protocol. Status = %r\n",
> +      Status
> +      ));
> +    return;
> +  }
> +
> +  Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo);  if (EFI_ERROR
> + (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: Failed to get Configuration Manager info. Status = %r\n",
> +      Status
> +      ));
> +    return;
> +  }
> +
> +  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]
> +    ));
> +
> +  Status = ProcessSmbiosTables (TableFactoryProtocol, CfgMgrProtocol);
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "ERROR: SMBIOS Table processing failure. Status = %r\n",
> +      Status
> +      ));
> +  }
> +}
> +
> +/** Entrypoint of Dynamic Table Manager Dxe.
> +
> +  The Dynamic Table Manager uses the Configuration Manager Protocol  to
> + get the list of ACPI and SMBIOS tables to install. For each table  in
> + the list it requests the corresponding ACPI/SMBIOS table factory for
> + a generator capable of building the ACPI/SMBIOS table.
> +  If a suitable table generator is found, it invokes the generator
> + interface  to build the table. The Dynamic Table Manager then installs
> + the  table and invokes another generator interface to free any
> + resources  allocated for building the table.
> +
> +  @param  ImageHandle
> +  @param  SystemTable
> +
> +  @retval EFI_SUCCESS           Success.
> +  @retval EFI_OUT_OF_RESOURCES  Memory allocation failed.
> +  @retval EFI_NOT_FOUND         Required interface/object was not found.
> +  @retval EFI_INVALID_PARAMETER Some parameter is incorrect/invalid.
> +**/
> +EFI_STATUS
> +EFIAPI
> +DynamicTableManagerDxeInitialize (
> +  IN  EFI_HANDLE        ImageHandle,
> +  IN  EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  EFI_STATUS  Status;
> +  EFI_EVENT   AcpiEvent;
> +  EFI_EVENT   SmbiosEvent;
> +
> +  AcpiEvent = EfiCreateProtocolNotifyEvent (
> +                &gEfiAcpiTableProtocolGuid,
> +                TPL_CALLBACK,
> +                AcpiTableProtocolReady,
> +                NULL,
> +                &AcpiTableProtocolRegistration
> +                );
> +  if (AcpiEvent == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a: Failed to ACPI create protocol event\r\n",
> __FUNCTION__));
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> +
> +  SmbiosEvent = EfiCreateProtocolNotifyEvent (
> +                  &gEfiSmbiosProtocolGuid,
> +                  TPL_CALLBACK,
> +                  SmbiosProtocolReady,
> +                  NULL,
> +                  &SmbiosProtocolRegistration
> +                  );
> +  if (SmbiosEvent == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a: Failed to SMBIOS create protocol
> event\r\n", __FUNCTION__));
> +    gBS->CloseEvent (AcpiEvent);
> +    return EFI_OUT_OF_RESOURCES;
> +  }
> 
>    return Status;
>  }
> diff --git
> a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManag
> erDxe.inf
> b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManag
> erDxe.inf
> index b09272d883..3beab7420a 100644
> ---
> a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManag
> erDxe.inf
> +++
> b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManag
> e
> +++ rDxe.inf
> @@ -33,6 +33,7 @@
>  [LibraryClasses]
>    PrintLib
>    TableHelperLib
> +  UefiLib
>    UefiBootServicesTableLib
>    UefiDriverEntryPoint
> 
> @@ -42,12 +43,12 @@
>  [Protocols]
>    gEfiAcpiTableProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED
>    gEfiAcpiSdtProtocolGuid                       # PROTOCOL ALWAYS_CONSUMED
> +  gEfiSmbiosProtocolGuid                        # PROTOCOL ALWAYS_CONSUMED
> 
>    gEdkiiConfigurationManagerProtocolGuid        # PROTOCOL
> ALWAYS_CONSUMED
>    gEdkiiDynamicTableFactoryProtocolGuid         # PROTOCOL
> ALWAYS_CONSUMED
> 
>  [Depex]
> -  gEfiAcpiTableProtocolGuid AND

Why is this depex being removed?
If this change is required, does it make sense to move it to a separate commit?

>    gEdkiiConfigurationManagerProtocolGuid AND
>    gEdkiiDynamicTableFactoryProtocolGuid
> 
> diff --git
> a/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h
> b/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h
> index b11fc0c9f1..e298236311 100644
> --- a/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h
> +++ b/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h
> @@ -1,5 +1,6 @@
>  /** @file
> 
> +  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
>    Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -239,6 +240,15 @@
> typedef struct DynamicTableFactoryProtocol {
>    EDKII_DYNAMIC_TABLE_FACTORY_DEREGISTER_DT_TABLE_GENERATOR
>                                                              DeregisterDtTableGenerator;
> 
> +  EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_ADD_HANDLE
> +
> + AddSmbiosHandle;
> +
> +  EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE
> +
> + GetSmbiosHandle;
> +
> +  EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE_EX
> +
> + GetSmbiosHandleEx;
> +
>    /** Pointer to the data structure that holds the
>        list of registered table generators
>    */
> diff --git a/DynamicTablesPkg/Include/SmbiosTableGenerator.h
> b/DynamicTablesPkg/Include/SmbiosTableGenerator.h
> index 934d56c90d..a9f8199a3b 100644
> --- a/DynamicTablesPkg/Include/SmbiosTableGenerator.h
> +++ b/DynamicTablesPkg/Include/SmbiosTableGenerator.h
> @@ -1,5 +1,6 @@
>  /** @file
> 
> +  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
>    Copyright (c) 2017 - 2019, ARM Limited. All rights reserved.
> 
>    SPDX-License-Identifier: BSD-2-Clause-Patent @@ -10,7 +11,7 @@  #define
> SMBIOS_TABLE_GENERATOR_H_
> 
>  #include <IndustryStandard/SmBios.h>
> -
> +#include <Protocol/Smbios.h>
>  #include <TableGenerator.h>
> 
>  #pragma pack(1)
> @@ -121,12 +122,21 @@ typedef enum StdSmbiosTableGeneratorId {
>              ETableGeneratorNameSpaceStd,        \
>              TableId                             \
>              )
> +#define MAX_SMBIOS_HANDLES  (255)
> 
>  /** Forward declarations.
>  */
>  typedef struct ConfigurationManagerProtocol
> EDKII_CONFIGURATION_MANAGER_PROTOCOL;
>  typedef struct CmStdObjSmbiosTableInfo
> CM_STD_OBJ_SMBIOS_TABLE_INFO;
>  typedef struct SmbiosTableGenerator         SMBIOS_TABLE_GENERATOR;
> +typedef struct DynamicTableFactoryProtocol
> EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL;
> +typedef UINTN                               CM_OBJECT_TOKEN;
> +
> +typedef struct SmbiosHandleCmObjMap {
> +  SMBIOS_TABLE_GENERATOR_ID    SmbiosGeneratorId;
> +  SMBIOS_HANDLE                SmbiosTblHandle;
> +  CM_OBJECT_TOKEN              SmbiosCmToken;
> +} SMBIOS_HANDLE_MAP;
> 
>  /** This function pointer describes the interface to SMBIOS table build
>      functions provided by the SMBIOS table generator and called by the
> @@ -143,9 +153,11 @@ typedef struct SmbiosTableGenerator
> SMBIOS_TABLE_GENERATOR;
>  **/
>  typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLE) (
>    IN  CONST SMBIOS_TABLE_GENERATOR                        *Generator,
> +  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST
> + TableFactoryProtocol,
>    IN        CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST  SmbiosTableInfo,
>    IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST
> CfgMgrProtocol,
> -  OUT       SMBIOS_STRUCTURE                              **Table
> +  OUT       SMBIOS_STRUCTURE                              **Table,
> +  OUT       CM_OBJECT_TOKEN                               *CmObjToken
>    );
> 
>  /** This function pointer describes the interface to used by the @@ -163,32
> +175,147 @@ typedef EFI_STATUS
> (*SMBIOS_TABLE_GENERATOR_BUILD_TABLE) (  **/  typedef EFI_STATUS
> (*SMBIOS_TABLE_GENERATOR_FREE_TABLE) (
>    IN  CONST SMBIOS_TABLE_GENERATOR                        *Generator,
> +  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST

nit: one space too many before *CONST (to ensure correct alignment with the other *CONST)

> + TableFactoryProtocol,
>    IN  CONST CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST
> SmbiosTableInfo,
>    IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST
> CfgMgrProtocol,
>    IN        SMBIOS_STRUCTURE                              **Table
>    );
> 
> +/** This function pointer describes the interface to SMBIOS table build
> +    functions provided by the SMBIOS table generator and called by the
> +    Table Manager to build an SMBIOS table.
> +
> +  @param [in]  Generator       Pointer to the SMBIOS table generator.
> +  @param [in]  SmbiosTableInfo Pointer to the SMBIOS table information.
> +  @param [in]  CfgMgrProtocol  Pointer to the Configuration Manager
> +                               Protocol interface.
> +  @param [out] Table           Pointer to the generated SMBIOS table.
> +
> +  @return EFI_SUCCESS  If the table is generated successfully or other
> +                        failure codes as returned by the generator.
> +**/
> +typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX) (
> +  IN  CONST SMBIOS_TABLE_GENERATOR                         *Generator,
> +  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *CONST
> TableFactoryProtocol,
> +  IN        CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST   SmbiosTableInfo,
> +  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST
> CfgMgrProtocol,
> +  OUT       SMBIOS_STRUCTURE                               ***Table,
> +  OUT       CM_OBJECT_TOKEN                                **CmObjectToken,
> +  OUT       UINTN                                 *CONST   TableCount
> +  );
> +
> +/** This function pointer describes the interface to used by the
> +    Table Manager to give the generator an opportunity to free
> +    any resources allocated for building the SMBIOS table.
> +
> +  @param [in]  Generator       Pointer to the SMBIOS table generator.
> +  @param [in]  SmbiosTableInfo Pointer to the SMBIOS table information.
> +  @param [in]  CfgMgrProtocol  Pointer to the Configuration Manager
> +                               Protocol interface.
> +  @param [in]  Table           Pointer to the generated SMBIOS table.
> +
> +  @return  EFI_SUCCESS If freed successfully or other failure codes
> +                        as returned by the generator.
> +**/
> +typedef EFI_STATUS (*SMBIOS_TABLE_GENERATOR_FREE_TABLEEX) (
> +  IN  CONST SMBIOS_TABLE_GENERATOR                        *Generator,
> +  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL  *CONST
> TableFactoryProtocol,
> +  IN  CONST CM_STD_OBJ_SMBIOS_TABLE_INFO          *CONST
> SmbiosTableInfo,
> +  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST
> CfgMgrProtocol,
> +  IN        SMBIOS_STRUCTURE                              ***Table,
> +  IN        CM_OBJECT_TOKEN                               **CmObjectToken,
> +  IN  CONST UINTN                                         TableCount
> +  );
> +
> +/** This function pointer describes the interface to used by the
> +    Table Manager to give the generator an opportunity to add
> +    an SMBIOS Handle.
> +
> +  This function is called by the Dynamic Table Manager to add a newly
> + added  SMBIOS Table OR it can be called by an SMBIOS Table generator
> + to create  and add a new SMBIOS Handle if there is a reference to
> + another table and  if there is a generator for that table that hasn't been
> called yet.
> +
> +  @param [in]  Smbios         Pointer to the SMBIOS protocol.
> +  @param [in]  SmbiosHandle   Pointer to an SMBIOS handle (either
> generated by
> +                              SmbiosDxe Driver or  SMBIOS_HANDLE_PI_RESERVED
> +                              if a handle needs to be generated).
> +  @param [in]  CmObjectToken  The CM Object token for that is used to
> generate
> +                              SMBIOS record.
> +  @param [in]  GeneratorId    The SMBIOS table generator Id.
> +
> +  @retval EFI_SUCCESS           Success.
> +  @retval EFI_OUT_OF_RESOURCES  Unable to add the handle.
> +  @retval EFI_NOT_FOUND         The requested generator is not found
> +                                in the list of registered generators.
> +**/
> +typedef EFI_STATUS (EFIAPI
> *EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_ADD_HANDLE)(
> +  IN  EFI_SMBIOS_PROTOCOL        *Smbios,
> +  IN  SMBIOS_HANDLE              *SmbiosHandle,
> +  IN  CM_OBJECT_TOKEN            CmObjectToken,
> +  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId
> +  );
> +
> +/** This function pointer describes the interface to used by the
> +    Table Manager to give the generator an opportunity to find
> +    an SMBIOS Handle.
> +
> +  This function is called by the SMBIOS table generator to find an
> + SMBIOS  handle needed as part of generating an SMBIOS Table.
> +
> +  @param [in]  CmObjectToken    The CM Object token used to generate the
> SMBIOS
> +                                record.
> +
> +  @retval EFI_SUCCESS           Success.
> +  @retval EFI_NOT_FOUND         The requested generator is not found
> +                                in the list of registered generators.
> +**/
> +typedef SMBIOS_HANDLE_MAP *(EFIAPI
> *EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE)(
> +  IN  CM_OBJECT_TOKEN      CmObjectToken
> +  );
> +
> +/** Find and return SMBIOS handle based on associated CM object token.
> +
> +  @param [in]  GeneratorId     SMBIOS generator ID used to build the SMBIOS
> Table.
> +  @param [in]  CmObjectToken   Token of the CM_OBJECT used to build the
> SMBIOS Table.
> +
> +  @return  SMBIOS handle of the table associated with SmbiosTableId and
> +           CmObjectToken if found. Otherwise, returns 0xFFFF.
> +**/
> +typedef UINT16 (EFIAPI
> +*EDKII_DYNAMIC_TABLE_FACTORY_SMBIOS_TABLE_GET_HANDLE_EX)(
> +  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId,
> +  IN  CM_OBJECT_TOKEN            CmObjToken
> +  );
> +
>  /** The SMBIOS_TABLE_GENERATOR structure provides an interface that the
>      Table Manager can use to invoke the functions to build SMBIOS tables.
>  */
>  typedef struct SmbiosTableGenerator {
>    /// The SMBIOS table generator ID.
> -  SMBIOS_TABLE_GENERATOR_ID             GeneratorID;
> +  SMBIOS_TABLE_GENERATOR_ID               GeneratorID;
> 
>    /// String describing the DT table
>    /// generator.
> -  CONST CHAR16                          *Description;
> +  CONST CHAR16                            *Description;
> 
>    /// The SMBIOS table type.
> -  SMBIOS_TYPE                           Type;
> +  SMBIOS_TYPE                             Type;
> 
>    /// SMBIOS table build function pointer.
> -  SMBIOS_TABLE_GENERATOR_BUILD_TABLE    BuildSmbiosTable;
> +  SMBIOS_TABLE_GENERATOR_BUILD_TABLE      BuildSmbiosTable;
> +
> +  /** The function to free any resources
> +      allocated for building the SMBIOS table.
> +  */
> +  SMBIOS_TABLE_GENERATOR_FREE_TABLE       FreeTableResources;
> +
> +  /// SMBIOS table extended build function pointer.
> +  SMBIOS_TABLE_GENERATOR_BUILD_TABLEEX    BuildSmbiosTableEx;
> 
>    /** The function to free any resources
>        allocated for building the SMBIOS table.
>    */
> -  SMBIOS_TABLE_GENERATOR_FREE_TABLE     FreeTableResources;
> +  SMBIOS_TABLE_GENERATOR_FREE_TABLEEX     FreeTableResourcesEx;
>  } SMBIOS_TABLE_GENERATOR;
> 
>  /** Register SMBIOS table factory generator.
> @@ -229,6 +356,69 @@ DeregisterSmbiosTableGenerator (
>    IN CONST SMBIOS_TABLE_GENERATOR                 *CONST  Generator
>    );
> 
> +/** Add SMBIOS Handle.
> +
> +  This function is called by the Dynamic Table Manager to add a newly
> + added  SMBIOS Table OR it can be called by an SMBIOS Table generator
> + to create  and add a new SMBIOS Handle if there is a reference to
> + another table and  if there is a generator for that table that hasn't been
> called yet.
> +
> +  @param [in]  Smbios         Pointer to the SMBIOS protocol.
> +  @param [in]  SmbiosHandle   Pointer to an SMBIOS handle (either
> generated by
> +                              SmbiosDxe Driver or  SMBIOS_HANDLE_PI_RESERVED
> +                              if a handle needs to be generated).
> +  @param [in]  CmObjectToken  The CM Object token for that is used to
> generate
> +                              SMBIOS record.
> +  @param [in]  GeneratorId    The SMBIOS table generator Id.
> +
> +  @retval EFI_SUCCESS           Success.
> +  @retval EFI_OUT_OF_RESOURCES  Unable to add the handle.
> +  @retval EFI_NOT_FOUND         The requested generator is not found
> +                                in the list of registered generators.
> +**/
> +EFI_STATUS
> +EFIAPI
> +AddSmbiosHandle (
> +  IN EFI_SMBIOS_PROTOCOL         *Smbios,
> +  IN SMBIOS_HANDLE               *SmbiosHandle,
> +  IN CM_OBJECT_TOKEN             CmObjectToken,
> +  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId
> +  );
> +
> +/** Find SMBIOS Handle given the CM Object token used to generate the
> SMBIOS
> +    record..

nit: remove one of the full stops.

Jose

> +
> +  This function is called by the SMBIOS table generator to find an
> + SMBIOS  handle needed as part of generating an SMBIOS Table.
> +
> +  @param [in]  CmObjectToken    The CM Object token used to generate the
> SMBIOS
> +                                record.
> +
> +  @retval EFI_SUCCESS           Success.
> +  @retval EFI_NOT_FOUND         The requested generator is not found
> +                                in the list of registered generators.
> +**/
> +SMBIOS_HANDLE_MAP *
> +EFIAPI
> +FindSmbiosHandle (
> +  IN CM_OBJECT_TOKEN  CmObjectToken
> +  );
> +
> +/** Find and return SMBIOS handle based on associated CM object token.
> +
> +  @param [in]  GeneratorId     SMBIOS generator ID used to build the SMBIOS
> Table.
> +  @param [in]  CmObjectToken   Token of the CM_OBJECT used to build the
> SMBIOS Table.
> +
> +  @return  SMBIOS handle of the table associated with SmbiosTableId and
> +           CmObjectToken if found. Otherwise, returns 0xFFFF.
> +**/
> +UINT16
> +EFIAPI
> +FindSmbiosHandleEx (
> +  IN  SMBIOS_TABLE_GENERATOR_ID  GeneratorId,
> +  IN  CM_OBJECT_TOKEN            CmObjToken
> +  );
> +
>  #pragma pack()
> 
>  #endif // SMBIOS_TABLE_GENERATOR_H_
> diff --git a/MdePkg/Include/IndustryStandard/SmBios.h
> b/MdePkg/Include/IndustryStandard/SmBios.h
> index 89985bb418..c40986157c 100644
> --- a/MdePkg/Include/IndustryStandard/SmBios.h
> +++ b/MdePkg/Include/IndustryStandard/SmBios.h
> @@ -28,6 +28,14 @@ SPDX-License-Identifier: BSD-2-Clause-Patent  ///
> #define SMBIOS_HANDLE_PI_RESERVED  0xFFFE
> 
> +///
> +/// Reference SMBIOS 3.6, chapter 6.1.2.
> +/// Unless otherwise specified, when referring to another structure’s
> +handle, the value /// 0FFFFh is used to indicate that the referenced
> +handle is not applicable or does not /// exist.
> +///
> +#define SMBIOS_HANDLE_INVALID  0xFFFF
> +
>  ///
>  /// Reference SMBIOS 2.6, chapter 3.1.3.
>  /// Each text string is limited to 64 significant characters due to system MIF
> limitations.
> --
> 2.17.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108020): https://edk2.groups.io/g/devel/message/108020
Mute This Topic: https://groups.io/mt/100361559/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Smbios Physical Memory Array (Type 16)
  2023-07-25 23:38 ` [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Smbios Physical Memory Array (Type 16) Girish Mahadevan via groups.io
@ 2023-08-24 19:36   ` Jose Marinho
  0 siblings, 0 replies; 8+ messages in thread
From: Jose Marinho @ 2023-08-24 19:36 UTC (permalink / raw)
  To: devel@edk2.groups.io, gmahadevan@nvidia.com, Sami Mujawar
  Cc: Alexei Fedorov, Pierre Gondois, Jeff Brasen (jbrasen@nvidia.com),
	ashishsingha@nvidia.com, nramirez@nvidia.com, nd



> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Girish
> Mahadevan via groups.io
> Sent: Wednesday, July 26, 2023 12:38 AM
> To: devel@edk2.groups.io; Sami Mujawar <Sami.Mujawar@arm.com>
> Cc: gmahadevan@nvidia.com; Alexei Fedorov <Alexei.Fedorov@arm.com>;
> Pierre Gondois <Pierre.Gondois@arm.com>; Jeff Brasen (jbrasen@nvidia.com)
> <jbrasen@nvidia.com>; ashishsingha@nvidia.com; nramirez@nvidia.com
> Subject: [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Smbios Physical
> Memory Array (Type 16)
> 
> Add the Generator library for SMBIOS Table Type 16 - Physical Memory Array.
> 
> Signed-off-by: Girish Mahadevan <gmahadevan@nvidia.com>
> Reviewed-by: Jeff Brasen <jbrasen@nvidia.com>
> Reviewed-by: Nick Ramirez <nramirez@nvidia.com>
> ---
>  .../SmbiosTableBuilder.c                      |   3 -
>  .../Include/SmbiosNameSpaceObjects.h          |  19 +
>  .../SmbiosType16Lib/SmbiosType16Generator.c   | 361 ++++++++++++++++++
>  .../SmbiosType16Lib/SmbiosType16Lib.inf       |  35 ++
>  4 files changed, 415 insertions(+), 3 deletions(-)  create mode 100644
> DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generator
> .c
>  create mode 100644
> DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf
> 
> diff --git
> a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
> b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
> index bfddaac3aa..5feafcac66 100644
> ---
> a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder.c
> +++
> b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/SmbiosTableBuilder
> +++ .c
> @@ -312,7 +312,6 @@ exit_handler:
>      }
>    }
> 
> -  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
>    return Status;

nit: these debug statements were added in the commit with title
" DynamicTablesPkg: Split the ACPI and SMBIOS table generators"
Should these be removed there?

Jose

>  }
> 
> @@ -432,7 +431,6 @@ BuildAndInstallSmbiosTable (
>        ));
>    }
> 
> -  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
>    return Status;
>  }
> 
> @@ -516,7 +514,6 @@ ProcessSmbiosTables (
>        ));
>    }
> 
> -  DEBUG ((DEBUG_ERROR, "%a: Returning %r\n", __FUNCTION__, Status));
>    return Status;
>  }
> 
> diff --git a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
> b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
> index e44d703fac..760b082021 100644
> --- a/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
> +++ b/DynamicTablesPkg/Include/SmbiosNameSpaceObjects.h
> @@ -107,6 +107,25 @@ typedef struct {
>    SMBIOS_TABLE_GENERATOR_ID    GeneratorId;
>  } CONTAINED_CM_OBJECTS;
> 
> +/** A structure that describes the Physical Memory Array.
> +
> +  SMBIOS Specification v3.6.0 Type 16
> +
> +  ID: ESmbiosObjPhysicalMemoryArray
> +**/
> +typedef struct CmSmbiosPhysicalMemoryArray {
> +  UINT8              Use;
> +  UINT8              Location;
> +  UINT16             MemoryErrorCorrection;
> +  UINT16             MemoryErrorInformationHandle;
> +  UINT16             NumberOfMemoryDevices;
> +  UINT8              MemoryErrorCorrectionType;
> +  UINT64             Size;
> +  UINT8              NumMemDevices;
> +  CM_OBJECT_TOKEN    MemoryErrInfoToken;
> +  CM_OBJECT_TOKEN    PhysMemArrayToken;
> +} CM_SMBIOS_PHYSICAL_MEMORY_ARRAY;
> +
>  #pragma pack()
> 
>  #endif // SMBIOS_NAMESPACE_OBJECTS_H_
> diff --git
> a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generat
> or.c
> b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Generat
> or.c
> new file mode 100644
> index 0000000000..dad7588ed5
> --- /dev/null
> +++
> b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Genera
> +++ tor.c
> @@ -0,0 +1,361 @@
> +/** @file
> +  SMBIOS Type16 Table Generator.
> +
> +  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +  Copyright (c) 2020 - 2021, Arm Limited. All rights reserved.<BR>
> +
> +  SPDX-License-Identifier: BSD-2-Clause-Patent **/
> +
> +#include <Library/BaseLib.h>
> +#include <Library/BaseMemoryLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/PrintLib.h>
> +#include <Library/MemoryAllocationLib.h> #include
> +<Library/UefiBootServicesTableLib.h>
> +#include <Library/SmbiosStringTableLib.h>
> +
> +// Module specific include files.
> +#include <ConfigurationManagerObject.h> #include
> +<ConfigurationManagerHelper.h> #include
> +<Protocol/ConfigurationManagerProtocol.h>
> +#include <Protocol/DynamicTableFactoryProtocol.h>
> +#include <Protocol/Smbios.h>
> +#include <IndustryStandard/SmBios.h>
> +
> +/** This macro expands to a function that retrieves the Memory Device
> +    information from the Configuration Manager.
> +*/
> +GET_OBJECT_LIST (
> +  EObjNameSpaceSmbios,
> +  ESmbiosObjPhysicalMemoryArray,
> +  CM_SMBIOS_PHYSICAL_MEMORY_ARRAY
> +  )
> +
> +#define EXTENDED_SIZE_THRESHOLD  (SIZE_2TB)
> +
> +/**
> + * Free any resources allocated when installing SMBIOS Type16 table.
> + *
> + * @param [in]  This                 Pointer to the SMBIOS table generator.
> + * @param [in]  TableFactoryProtocol Pointer to the SMBIOS Table Factory
> +                                      Protocol interface.
> +
> + * @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table
> information.
> + * @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
> +                                     Protocol interface.
> + * @param [in] Table                 Pointer to the SMBIOS table.
> + * @param [in] CmObjectToken         Pointer to the CM ObjectToken Array.
> + * @param [in] TableCount            Number of SMBIOS tables.
> +
> + * @retval EFI_SUCCESS            Table generated successfully.
> + * @retval EFI_BAD_BUFFER_SIZE    The size returned by the Configuration
> +                                  Manager is less than the Object size for
> +                                  the requested object.
> + * @retval EFI_INVALID_PARAMETER  A parameter is invalid.
> + * @retval EFI_NOT_FOUND          Could not find information.
> + * @retval EFI_OUT_OF_RESOURCES   Could not allocate memory.
> + * @retval EFI_UNSUPPORTED        Unsupported configuration.
> +**/
> +STATIC
> +EFI_STATUS
> +FreeSmbiosType16TableEx (
> +  IN      CONST SMBIOS_TABLE_GENERATOR                    *CONST   This,
> +  IN      CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL      *CONST
> TableFactoryProtocol,
> +  IN      CONST CM_STD_OBJ_SMBIOS_TABLE_INFO              *CONST
> SmbiosTableInfo,
> +  IN      CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL      *CONST
> CfgMgrProtocol,
> +  IN      SMBIOS_STRUCTURE                               ***CONST  Table,
> +  IN      CM_OBJECT_TOKEN                                          **CmObjectToken,
> +  IN      CONST UINTN                                              TableCount
> +  )
> +{
> +  UINTN             Index;
> +  SMBIOS_STRUCTURE  **TableList;
> +
> +  TableList = *Table;
> +  for (Index = 0; Index < TableCount; Index++) {
> +    if (TableList[Index] != NULL) {
> +      FreePool (TableList[Index]);
> +    }
> +  }
> +
> +  if (*CmObjectToken != NULL) {
> +    FreePool (*CmObjectToken);
> +  }
> +
> +  if (TableList != NULL) {
> +    FreePool (TableList);
> +  }
> +
> +  return EFI_SUCCESS;
> +}
> +
> +/**
> + *  Update the Size encoding for Type 16.
> + *
> + *  @param [in]     SizeBytes    Size of the Memory device.
> + *  @param [out]    SmbiosRecord SMBIOS record to update.
> +**/
> +STATIC
> +VOID
> +UpdateSmbiosType16Size (
> +  IN     UINT64               SizeBytes,
> +  IN OUT SMBIOS_TABLE_TYPE16  *SmbiosRecord
> +  )
> +{
> +  UINT64  SizeKb = SizeBytes / SIZE_1KB;
> +
> +  if (SizeBytes < EXTENDED_SIZE_THRESHOLD) {
> +    SmbiosRecord->MaximumCapacity = SizeKb;
> +  } else {
> +    SmbiosRecord->MaximumCapacity         = 0x80000000;
> +    SmbiosRecord->ExtendedMaximumCapacity = SizeKb;
> +  }
> +}
> +
> +/**
> + *  Add the SMBIOS table handle reference to the Error Tables.
> + *
> + *  @param [in]     TableFactoryProtocol   Pointer to the SMBIOS Table
> Factory.
> + *  @param [in]     CmObjToken             CM Token to lookup..
> + *  @param [out]    SmbiosRecord           SMBIOS record to update.
> +**/
> +STATIC
> +VOID
> +AddMemErrDeviceHandle (
> +  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *CONST
> TableFactoryProtocol,
> +  IN  CM_OBJECT_TOKEN                                      CmObjToken,
> +  OUT SMBIOS_TABLE_TYPE16                                  *SmbiosRecord
> +  )
> +{
> +  EFI_SMBIOS_HANDLE  Handle;
> +  SMBIOS_HANDLE_MAP  *HandleMap;
> +
> +  HandleMap = TableFactoryProtocol->GetSmbiosHandle (CmObjToken);  if
> + (HandleMap == NULL) {
> +    DEBUG ((DEBUG_ERROR, "%a:Failed to get SMBIOS Handle\n",
> __FUNCTION__));
> +    Handle = 0xFFFF;
> +  } else {
> +    Handle = HandleMap->SmbiosTblHandle;  }
> +
> +  SmbiosRecord->MemoryErrorInformationHandle = Handle; }
> +
> +/** Construct SMBIOS Type16 Table describing memory devices.
> +
> +  If this function allocates any resources then they must be freed  in
> + the FreeXXXXTableResources function.
> +
> + * @param [in]  This                 Pointer to the SMBIOS table generator.
> + * @param [in]  TableFactoryProtocol Pointer to the SMBIOS Table Factory
> + *                                   Protocol interface.
> + * @param [in]  SmbiosTableInfo      Pointer to the SMBIOS table
> information.
> + * @param [in]  CfgMgrProtocol       Pointer to the Configuration Manager
> + *                                   Protocol interface.
> + * @param [out] Table                Pointer to the SMBIOS table.
> + * @param [out] CmObjectToken        Pointer to the CM Object Token Array.
> + * @param [out] TableCount           Number of tables installed.
> +
> + * @retval EFI_SUCCESS            Table generated successfully.
> + * @retval EFI_BAD_BUFFER_SIZE    The size returned by the Configuration
> + *                                Manager is less than the Object size for
> + *                                the requested object.
> + * @retval EFI_INVALID_PARAMETER  A parameter is invalid.
> + * @retval EFI_NOT_FOUND          Could not find information.
> + * @retval EFI_OUT_OF_RESOURCES   Could not allocate memory.
> + * @retval EFI_UNSUPPORTED        Unsupported configuration.
> +**/
> +STATIC
> +EFI_STATUS
> +BuildSmbiosType16TableEx (
> +  IN  CONST SMBIOS_TABLE_GENERATOR                         *This,
> +  IN  CONST EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL   *CONST
> TableFactoryProtocol,
> +  IN        CM_STD_OBJ_SMBIOS_TABLE_INFO           *CONST  SmbiosTableInfo,
> +  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL   *CONST
> CfgMgrProtocol,
> +  OUT       SMBIOS_STRUCTURE                               ***Table,
> +  OUT       CM_OBJECT_TOKEN                                **CmObjectToken,
> +  OUT       UINTN                                  *CONST  TableCount
> +  )
> +{
> +  EFI_STATUS                       Status;
> +  SMBIOS_STRUCTURE                 **TableList;
> +  SMBIOS_TABLE_TYPE16              *SmbiosRecord;
> +  CM_OBJECT_TOKEN                  *CmObjectList;
> +  CM_SMBIOS_PHYSICAL_MEMORY_ARRAY  *PhysMemoryArray;
> +  UINT32                           NumObj;
> +  UINTN                            Index;
> +
> +  ASSERT (This != NULL);
> +  ASSERT (SmbiosTableInfo != NULL);
> +  ASSERT (CfgMgrProtocol != NULL);
> +  ASSERT (Table != NULL);
> +  ASSERT (TableCount != NULL);
> +  ASSERT (SmbiosTableInfo->TableGeneratorId == This->GeneratorID);
> +
> +  if ((This == NULL) || (SmbiosTableInfo == NULL) || (CfgMgrProtocol == NULL)
> ||
> +      (Table == NULL) || (TableCount == NULL) ||
> +      (SmbiosTableInfo->TableGeneratorId != This->GeneratorID))  {
> +    DEBUG ((DEBUG_ERROR, "%a:Invalid Paramater\n ", __FUNCTION__));
> +    return EFI_INVALID_PARAMETER;
> +  }
> +
> +  *Table = NULL;
> +  Status = GetESmbiosObjPhysicalMemoryArray (
> +             CfgMgrProtocol,
> +             CM_NULL_TOKEN,
> +             &PhysMemoryArray,
> +             &NumObj
> +             );
> +  if (EFI_ERROR (Status)) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "%a: Failed to get Memory Devices CM Object %r\n",
> +      __FUNCTION__,
> +      Status
> +      ));
> +    return Status;
> +  }
> +
> +  TableList = (SMBIOS_STRUCTURE **)AllocateZeroPool (sizeof
> + (SMBIOS_STRUCTURE *) * NumObj);  if (TableList == NULL) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "%a: Failed to alloc memory for %u devices table\n",
> +      __FUNCTION__,
> +      NumObj
> +      ));
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto exitBuildSmbiosType16Table;
> +  }
> +
> +  CmObjectList = (CM_OBJECT_TOKEN *)AllocateZeroPool (sizeof
> + (CM_OBJECT_TOKEN *) * NumObj);  if (CmObjectList == NULL) {
> +    DEBUG ((
> +      DEBUG_ERROR,
> +      "%a: Failed to alloc memory for %u CM Objects.\n",
> +      __FUNCTION__,
> +      NumObj
> +      ));
> +    Status = EFI_OUT_OF_RESOURCES;
> +    goto exitBuildSmbiosType16Table;
> +  }
> +
> +  for (Index = 0; Index < NumObj; Index++) {
> +    /**
> +     * Per Spec each structure is terminated by a double-NULL if there are no
> +     * strings.
> +     */
> +    SmbiosRecord = (SMBIOS_TABLE_TYPE16 *)AllocateZeroPool (sizeof
> (SMBIOS_TABLE_TYPE16) + 1 + 1);
> +    if (SmbiosRecord == NULL) {
> +      Status = EFI_OUT_OF_RESOURCES;
> +      goto exitBuildSmbiosType16Table;
> +    }
> +
> +    UpdateSmbiosType16Size (PhysMemoryArray->Size, SmbiosRecord);
> +    SmbiosRecord->Location              = PhysMemoryArray[Index].Location;
> +    SmbiosRecord->Use                   = PhysMemoryArray[Index].Use;
> +    SmbiosRecord->MemoryErrorCorrection =
> PhysMemoryArray[Index].MemoryErrorCorrectionType;
> +    SmbiosRecord->NumberOfMemoryDevices = PhysMemoryArray-
> >NumMemDevices;
> +    if (PhysMemoryArray[Index].MemoryErrInfoToken != CM_NULL_TOKEN) {
> +      AddMemErrDeviceHandle (
> +        TableFactoryProtocol,
> +        PhysMemoryArray[Index].MemoryErrInfoToken,
> +        SmbiosRecord
> +        );
> +    } else {
> +      SmbiosRecord->MemoryErrorInformationHandle = 0xFFFF;
> +    }
> +
> +    // Setup the header
> +    SmbiosRecord->Hdr.Type   =
> EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY;
> +    SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE16);
> +
> +    TableList[Index]    = (SMBIOS_STRUCTURE *)SmbiosRecord;
> +    CmObjectList[Index] = PhysMemoryArray[Index].PhysMemArrayToken;
> +  }
> +
> +  *Table         = TableList;
> +  *CmObjectToken = CmObjectList;
> +  *TableCount    = NumObj;
> +exitBuildSmbiosType16Table:
> +  return Status;
> +}
> +
> +/** The interface for the SMBIOS Type16 Table Generator.
> +*/
> +STATIC
> +CONST
> +SMBIOS_TABLE_GENERATOR  SmbiosType16Generator = {
> +  // Generator ID
> +  CREATE_STD_SMBIOS_TABLE_GEN_ID (EStdSmbiosTableIdType16),
> +  // Generator Description
> +  L"SMBIOS.TYPE16.GENERATOR",
> +  // SMBIOS Table Type
> +  EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY,
> +  NULL,
> +  NULL,
> +  // Build table function.
> +  BuildSmbiosType16TableEx,
> +  // Free function.
> +  FreeSmbiosType16TableEx,
> +};
> +
> +/** Register the Generator with the SMBIOS Table Factory.
> +
> +  @param [in]  ImageHandle  The handle to the image.
> +  @param [in]  SystemTable  Pointer to the System Table.
> +
> +  @retval EFI_SUCCESS           The Generator is registered.
> +  @retval EFI_INVALID_PARAMETER A parameter is invalid.
> +  @retval EFI_ALREADY_STARTED   The Generator for the Table ID
> +                                is already registered.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmbiosType16LibConstructor (
> +  IN  EFI_HANDLE        ImageHandle,
> +  IN  EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  EFI_STATUS  Status;
> +
> +  Status = RegisterSmbiosTableGenerator (&SmbiosType16Generator);
> + DEBUG ((
> +    DEBUG_INFO,
> +    "SMBIOS Type 16: Register Generator. Status = %r\n",
> +    Status
> +    ));
> +  ASSERT_EFI_ERROR (Status);
> +
> +  return Status;
> +}
> +
> +/** Deregister the Generator from the SMBIOS Table Factory.
> +
> +  @param [in]  ImageHandle  The handle to the image.
> +  @param [in]  SystemTable  Pointer to the System Table.
> +
> +  @retval EFI_SUCCESS           The Generator is deregistered.
> +  @retval EFI_INVALID_PARAMETER A parameter is invalid.
> +  @retval EFI_NOT_FOUND         The Generator is not registered.
> +**/
> +EFI_STATUS
> +EFIAPI
> +SmbiosType16LibDestructor (
> +  IN  EFI_HANDLE        ImageHandle,
> +  IN  EFI_SYSTEM_TABLE  *SystemTable
> +  )
> +{
> +  EFI_STATUS  Status;
> +
> +  Status = DeregisterSmbiosTableGenerator (&SmbiosType16Generator);
> +  DEBUG ((
> +    DEBUG_INFO,
> +    "SMBIOS Type16: Deregister Generator. Status = %r\n",
> +    Status
> +    ));
> +  ASSERT_EFI_ERROR (Status);
> +  return Status;
> +}
> diff --git
> a/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf
> b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.inf
> new file mode 100644
> index 0000000000..5bb40db21c
> --- /dev/null
> +++
> b/DynamicTablesPkg/Library/Smbios/SmbiosType16Lib/SmbiosType16Lib.in
> +++ f
> @@ -0,0 +1,35 @@
> +## @file
> +# SMBIOS Type17 Table Generator
> +#
> +#  Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
> +#  Copyright (c) 2019 - 2021, Arm Limited. All rights reserved.<BR> # #
> +SPDX-License-Identifier: BSD-2-Clause-Patent ##
> +
> +[Defines]
> +  INF_VERSION    = 0x0001001B
> +  BASE_NAME      = SmbiosType16LibArm
> +  FILE_GUID      = a256956a-de0b-4aa7-8eac-5ce13bbfbb1f
> +  VERSION_STRING = 1.0
> +  MODULE_TYPE    = DXE_DRIVER
> +  LIBRARY_CLASS  = NULL|DXE_DRIVER
> +  CONSTRUCTOR    = SmbiosType16LibConstructor
> +  DESTRUCTOR     = SmbiosType16LibDestructor
> +
> +[Sources]
> +  SmbiosType16Generator.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  MdeModulePkg/MdeModulePkg.dec
> +  EmbeddedPkg/EmbeddedPkg.dec
> +  ArmPlatformPkg/ArmPlatformPkg.dec
> +  DynamicTablesPkg/DynamicTablesPkg.dec
> +
> +[Protocols]
> +  gEfiSmbiosProtocolGuid                        # PROTOCOL ALWAYS_CONSUMED
> +
> +[LibraryClasses]
> +  BaseLib
> +  DebugLib
> --
> 2.17.1
> 
> 
> 
> 
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108021): https://edk2.groups.io/g/devel/message/108021
Mute This Topic: https://groups.io/mt/100361564/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-08-24 19:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-25 23:38 [edk2-devel] [PATCH v3 0/5] DynamicTablesPkg: Add SMBIOS Table Generation Girish Mahadevan via groups.io
2023-07-25 23:38 ` [edk2-devel] [PATCH v3 1/5] DynamicTablesPkg: Add SMBIOS table generation Girish Mahadevan via groups.io
2023-08-24 19:02   ` Jose Marinho
2023-07-25 23:38 ` [edk2-devel] [PATCH v3 2/5] DynamicTablesPkg: Split the ACPI and SMBIOS table generators Girish Mahadevan via groups.io
2023-07-25 23:38 ` [edk2-devel] [PATCH v3 3/5] DynamicTablesPkg: Introduce new namespace for SMBIOS Objects Girish Mahadevan via groups.io
2023-07-25 23:38 ` [edk2-devel] [PATCH v3 4/5] DynamicTablesPkg: Smbios Memory Device (Type 17) Girish Mahadevan via groups.io
2023-07-25 23:38 ` [edk2-devel] [PATCH v3 5/5] DynamicTablesPkg: Smbios Physical Memory Array (Type 16) Girish Mahadevan via groups.io
2023-08-24 19:36   ` Jose Marinho

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox