From: Michael Kubacki <michael.kuba...@microsoft.com>

The PRM_MODULE_EXPORT parameterized macro allows a caller to produce
a static PRM module export descriptor structure in the binary by
simply passing PRM_HANDLER_EXPORT_ENTRY arguments with each argument
representing a PRM handler to be exported by the module.

Previously, the PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT used in the
PRM_MODULE_EXPORT macro was fixed to a maximum of three handlers.

This change removes that restriction and allows the structure to
grow based on the number of PRM handlers given to the macro. This
means a local type will be customized per PRM module. The reference
type PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT keeps a field at the end
that allows array access to PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT
members.

Cc: Andrew Fish <af...@apple.com>
Cc: Kang Gao <kang....@intel.com>
Cc: Michael D Kinney <michael.d.kin...@intel.com>
Cc: Michael Kubacki <michael.kuba...@microsoft.com>
Cc: Leif Lindholm <l...@nuviainc.com>
Cc: Benjamin You <benjamin....@intel.com>
Cc: Liu Yun <yun.y....@intel.com>
Cc: Ankit Sinha <ankit.si...@intel.com>
Cc: Nate DeSimone <nathaniel.l.desim...@intel.com>
Signed-off-by: Michael Kubacki <michael.kuba...@microsoft.com>
---
 PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c   | 14 +++++------
 PrmPkg/Include/PrmExportDescriptor.h | 25 +++++++++++++++++---
 2 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c 
b/PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c
index 85fffdcbd9f1..5fda4c1b01da 100644
--- a/PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c
+++ b/PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c
@@ -122,7 +122,7 @@ GetPrmModuleExportDescriptorTable (
         return EFI_NOT_FOUND;
       }
       TempExportDescriptor = (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *) ((UINTN) 
CurrentImageAddress + ExportAddressTable[PrmModuleExportDescriptorOrdinal]);
-      if (TempExportDescriptor->Signature == 
PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE) {
+      if (TempExportDescriptor->Header.Signature == 
PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE) {
         *ExportDescriptor = TempExportDescriptor;
         DEBUG ((DEBUG_INFO, "  %a %a: PRM Module Export Descriptor found at 
0x%x.\n", _DBGMSGID_, __FUNCTION__, (UINTN) ExportDescriptor));
       } else {
@@ -528,7 +528,7 @@ DiscoverPrmModules (
       sizeof (*(PrmModuleImageContextListEntry->Context))
       );
     InsertTailList (&mPrmModuleList, &PrmModuleImageContextListEntry->Link);
-    mPrmHandlerCount += 
TempPrmModuleImageContext.ExportDescriptor->NumberPrmHandlers;
+    mPrmHandlerCount += 
TempPrmModuleImageContext.ExportDescriptor->Header.NumberPrmHandlers;
     mPrmModuleCount++; // Todo: Match with global variable refactor change in 
the future
     DEBUG ((DEBUG_INFO, "%a %a: New PRM Module inserted into list to be 
processed.\n", _DBGMSGID_, __FUNCTION__));
   }
@@ -684,16 +684,16 @@ ProcessPrmModules (
       _DBGMSGID_,
       __FUNCTION__,
       (CHAR8 *) ((UINTN) CurrentImageAddress + 
CurrentImageExportDirectory->Name),
-      CurrentExportDescriptorStruct->NumberPrmHandlers
+      CurrentExportDescriptorStruct->Header.NumberPrmHandlers
       ));
 
     CurrentModuleInfoStruct->StructureRevision = 
PRM_MODULE_INFORMATION_STRUCT_REVISION;
     CurrentModuleInfoStruct->StructureLength = (
                                              OFFSET_OF 
(PRM_MODULE_INFORMATION_STRUCT, HandlerInfoStructure) +
-                                             
(CurrentExportDescriptorStruct->NumberPrmHandlers * sizeof 
(PRM_HANDLER_INFORMATION_STRUCT))
+                                             
(CurrentExportDescriptorStruct->Header.NumberPrmHandlers * sizeof 
(PRM_HANDLER_INFORMATION_STRUCT))
                                              );
-    CopyGuid (&CurrentModuleInfoStruct->Identifier, 
&CurrentExportDescriptorStruct->ModuleGuid);
-    CurrentModuleInfoStruct->HandlerCount       = (UINT32) 
CurrentExportDescriptorStruct->NumberPrmHandlers;
+    CopyGuid (&CurrentModuleInfoStruct->Identifier, 
&CurrentExportDescriptorStruct->Header.ModuleGuid);
+    CurrentModuleInfoStruct->HandlerCount       = (UINT32) 
CurrentExportDescriptorStruct->Header.NumberPrmHandlers;
     CurrentModuleInfoStruct->HandlerInfoOffset  = OFFSET_OF 
(PRM_MODULE_INFORMATION_STRUCT, HandlerInfoStructure);
 
     CurrentModuleInfoStruct->MajorRevision = 0;
@@ -737,7 +737,7 @@ ProcessPrmModules (
     //
     // Iterate across all PRM handlers in the PRM Module
     //
-    for (HandlerIndex = 0; HandlerIndex < 
CurrentExportDescriptorStruct->NumberPrmHandlers; HandlerIndex++) {
+    for (HandlerIndex = 0; HandlerIndex < 
CurrentExportDescriptorStruct->Header.NumberPrmHandlers; HandlerIndex++) {
       CurrentHandlerInfoStruct = 
&(CurrentModuleInfoStruct->HandlerInfoStructure[HandlerIndex]);
 
       CurrentHandlerInfoStruct->StructureRevision = 
PRM_HANDLER_INFORMATION_STRUCT_REVISION;
diff --git a/PrmPkg/Include/PrmExportDescriptor.h 
b/PrmPkg/Include/PrmExportDescriptor.h
index 95198cef659c..fc313fd1acc7 100644
--- a/PrmPkg/Include/PrmExportDescriptor.h
+++ b/PrmPkg/Include/PrmExportDescriptor.h
@@ -31,11 +31,23 @@ typedef struct {
   UINT16                                Revision;
   UINT16                                NumberPrmHandlers;
   GUID                                  ModuleGuid;
-  PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT  PrmHandlerExportDescriptors[3];
+} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER;
+
+typedef struct {
+  PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER  Header;
+  PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT        PrmHandlerExportDescriptors[1];
 } PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT;
 
 #pragma pack(pop)
 
+#if defined(_MSC_VER)
+  #define PRM_PACKED_STRUCT(definition) \
+  __pragma(pack(push, 1)) typedef struct definition __pragma(pack(pop))
+#elif defined (__GNUC__) || defined (__clang__)
+  #define PRM_PACKED_STRUCT(definition) \
+  typedef struct __attribute__((packed)) definition
+#endif
+
 /**
   A macro that declares a PRM Handler Export Descriptor for a PRM Handler.
 
@@ -73,8 +85,15 @@ typedef struct {
                                     this module.
 
 **/
-#define PRM_MODULE_EXPORT(...)                                                 
             \
-  PRM_EXPORT_API PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT 
PRM_MODULE_EXPORT_DESCRIPTOR_NAME = {               \
+#define PRM_MODULE_EXPORT(...)                                                 
                           \
+  PRM_PACKED_STRUCT(                                                           
                           \
+    {                                                                          
                           \
+      PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER  Header;                      
                           \
+      PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT        
PrmHandlerExportDescriptors[VA_ARG_COUNT(__VA_ARGS__)]; \
+    } PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_                                     
                           \
+  );                                                                           
                           \
+                                                                               
                           \
+  PRM_EXPORT_API PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_ 
PRM_MODULE_EXPORT_DESCRIPTOR_NAME = {               \
     {                                                                          
                           \
       PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE,                                  
                           \
       PRM_MODULE_EXPORT_REVISION,                                              
                           \
-- 
2.28.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#87854): https://edk2.groups.io/g/devel/message/87854
Mute This Topic: https://groups.io/mt/89955976/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to