From 771b45250724c9bee6210f041ec137ff27411c78 Mon Sep 17 00:00:00 2001 From: Pierre Gondois Date: Fri, 25 Apr 2025 13:44:04 +0200 Subject: [PATCH] DynamicTablesPkg: Add GetMetadataRoot() cb to DynamicTableFactory protocol The newly added MetadataObjLib allows to store information either: - generated by the DynamictTablesPkg framework - provided by a ConfigurationManager - parsed from another source of information This information might be subject to validation/verification. This step can only be done once the firmware tables generated by the DynamictTablesPkg have been generated. Add a new GetMetadataRoot() callback to the EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL. This callback allows to fetch the Metadata Root, allowing to access all the Metadata information generated. This Metadata is then validated by the DynamicTableManagerDxe. Signed-off-by: Pierre Gondois --- .../DynamicTableFactoryDxe.c | 27 +++++++++++++++++++ .../DynamicTableFactoryDxe.inf | 1 + .../DynamicTableManagerDxe.c | 14 ++++++++++ .../DynamicTableManagerDxe.inf | 1 + DynamicTablesPkg/Include/MetadataHelpers.h | 27 +++++++++++++++++++ .../Protocol/DynamicTableFactoryProtocol.h | 19 +++++++++++++ 6 files changed, 89 insertions(+) create mode 100644 DynamicTablesPkg/Include/MetadataHelpers.h diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c index 6d6d3fa746..4f38a062e8 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "DynamicTableFactory.h" @@ -29,6 +30,25 @@ */ EDKII_DYNAMIC_TABLE_FACTORY_INFO TableFactoryInfo; +STATIC METADATA_ROOT_HANDLE mMetadataRoot; + +/** Get the Root handle of the MetadataObjLib. + + During the firmware table generation, some Metadata information might be + generated by different generators. This Metadata might be subject to + additional validation. + + @return The Metadata Root handle. +**/ +METADATA_ROOT_HANDLE +EFIAPI +GetMetadataRoot ( + VOID + ) +{ + return mMetadataRoot; +} + /** A structure describing the Dynamic Table Factory protocol. */ STATIC @@ -44,6 +64,7 @@ EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL DynamicTableFactoryProtocol = { GetDtTableGenerator, RegisterDtTableGenerator, DeregisterDtTableGenerator, + GetMetadataRoot, &TableFactoryInfo }; @@ -66,6 +87,12 @@ DynamicTableFactoryDxeInitialize ( { EFI_STATUS Status; + Status = MetadataInitializeHandle (&mMetadataRoot); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + Status = gBS->InstallProtocolInterface ( &ImageHandle, &gEdkiiDynamicTableFactoryProtocolGuid, diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf index 29ed3dc2e5..b960b2c69c 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.inf @@ -35,6 +35,7 @@ [LibraryClasses] BaseLib MemoryAllocationLib + MetadataHandlerLib PrintLib TableHelperLib UefiBootServicesTableLib diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c index dfccccb839..ea8b5ba381 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -691,6 +692,7 @@ DynamicTableManagerDxeInitialize ( EDKII_CONFIGURATION_MANAGER_PROTOCOL *CfgMgrProtocol; CM_STD_OBJ_CONFIGURATION_MANAGER_INFO *CfgMfrInfo; EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL *TableFactoryProtocol; + METADATA_ROOT_HANDLE Root; // Locate the Dynamic Table Factory Status = gBS->LocateProtocol ( @@ -762,7 +764,19 @@ DynamicTableManagerDxeInitialize ( "ERROR: ACPI Table processing failure. Status = %r\n", Status )); + return Status; } + Root = TableFactoryProtocol->GetMetadataRoot (); + + // Validate the collected Metadata. + Status = MetadataHandlerValidate (Root); + if (EFI_ERROR (Status)) { + ASSERT_EFI_ERROR (Status); + return Status; + } + + MetadataFreeHandle (Root); + return Status; } diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf index c982b24c2a..30dc2b8291 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.inf @@ -37,6 +37,7 @@ DynamicTablesPkg/DynamicTablesPkg.dec [LibraryClasses] + MetadataHandlerLib PrintLib TableHelperLib UefiBootServicesTableLib diff --git a/DynamicTablesPkg/Include/MetadataHelpers.h b/DynamicTablesPkg/Include/MetadataHelpers.h new file mode 100644 index 0000000000..c881fcafc8 --- /dev/null +++ b/DynamicTablesPkg/Include/MetadataHelpers.h @@ -0,0 +1,27 @@ +/** @file + Metadata Helpers + + Copyright (c) 2025, Arm Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef METADATA_HELPER_H_ +#define METADATA_HELPER_H_ + +#include + +/** Get the Root handle of the MetadataObjLib. + + During the firmware table generation, some Metadata information might be + generated by different generators. This Metadata might be subject to + additional validation. + + @return The Metadata Root handle. +**/ +METADATA_ROOT_HANDLE +EFIAPI +GetMetadataRoot ( + VOID + ); + +#endif // METADATA_HELPER_H_ diff --git a/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h b/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h index b11fc0c9f1..c601e407dc 100644 --- a/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h +++ b/DynamicTablesPkg/Include/Protocol/DynamicTableFactoryProtocol.h @@ -16,6 +16,7 @@ #include #include #include +#include /** This macro defines the Dynamic Table Factory Protocol GUID. @@ -200,6 +201,20 @@ EFI_STATUS IN CONST DT_TABLE_GENERATOR *CONST Generator ); +/** Get the Root handle of the MetadataObjLib. + + During the firmware table generation, some Metadata information might be + generated by different generators. This Metadata might be subject to + additional validation. + + @return The Metadata Root handle. +**/ +typedef +VOID * +(EFIAPI *EDKII_DYNAMIC_TABLE_FACTORY_GET_METADATA_ROOT)( + VOID + ); + /** A structure describing the Dynamic Table Factory Protocol interface. */ typedef struct DynamicTableFactoryProtocol { @@ -239,6 +254,10 @@ typedef struct DynamicTableFactoryProtocol { EDKII_DYNAMIC_TABLE_FACTORY_DEREGISTER_DT_TABLE_GENERATOR DeregisterDtTableGenerator; + /// Finalization step + EDKII_DYNAMIC_TABLE_FACTORY_GET_METADATA_ROOT + GetMetadataRoot; + /** Pointer to the data structure that holds the list of registered table generators */