From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.12305.1647966068654128018 for ; Tue, 22 Mar 2022 09:21:08 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=Xubj6TWR; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.202.59.224]) by linux.microsoft.com (Postfix) with ESMTPSA id 617C020B4783; Tue, 22 Mar 2022 09:21:07 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 617C020B4783 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1647966068; bh=644WJVWXIivik96wtiZxT8n93zqkoFUpjFhR0pA5hkw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xubj6TWR29bOKo5laxfR7GAu9F2kP67QluPmEDgtEyRNfOuZCZX13zIQ/mJhnmE9Z 4sYwkri+p15ojG5ip7MZDMV58dGz5kgWW6DtcrvFYfHNs94SB1ePTO4yJvgjZNsXq7 C48Bqibvq86uQjZASUmycPGk+tH8gVbAKFeM2Ymg= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Andrew Fish , Kang Gao , Michael D Kinney , Michael Kubacki , Leif Lindholm , Benjamin You , Liu Yun , Ankit Sinha , Nate DeSimone Subject: [PATCH v1 12/41] PrmPkg: Enable variable growth for the PRM_MODULE_EXPORT macro Date: Tue, 22 Mar 2022 12:19:18 -0400 Message-Id: <20220322161947.9319-13-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220322161947.9319-1-mikuback@linux.microsoft.com> References: <20220322161947.9319-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki 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 Cc: Kang Gao Cc: Michael D Kinney Cc: Michael Kubacki Cc: Leif Lindholm Cc: Benjamin You Cc: Liu Yun Cc: Ankit Sinha Cc: Nate DeSimone Signed-off-by: Michael Kubacki --- 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/Prm= LoaderDxe.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 =3D (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *) (= (UINTN) CurrentImageAddress + ExportAddressTable[PrmModuleExportDescripto= rOrdinal]); - if (TempExportDescriptor->Signature =3D=3D PRM_MODULE_EXPORT_DESCR= IPTOR_SIGNATURE) { + if (TempExportDescriptor->Header.Signature =3D=3D PRM_MODULE_EXPOR= T_DESCRIPTOR_SIGNATURE) { *ExportDescriptor =3D 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->Li= nk); - mPrmHandlerCount +=3D TempPrmModuleImageContext.ExportDescriptor->Nu= mberPrmHandlers; + mPrmHandlerCount +=3D TempPrmModuleImageContext.ExportDescriptor->He= ader.NumberPrmHandlers; mPrmModuleCount++; // Todo: Match with global variable refactor chan= ge 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 + CurrentImageExportDirecto= ry->Name), - CurrentExportDescriptorStruct->NumberPrmHandlers + CurrentExportDescriptorStruct->Header.NumberPrmHandlers )); =20 CurrentModuleInfoStruct->StructureRevision =3D PRM_MODULE_INFORMATIO= N_STRUCT_REVISION; CurrentModuleInfoStruct->StructureLength =3D ( OFFSET_OF (PRM_MODULE_INFOR= MATION_STRUCT, HandlerInfoStructure) + - (CurrentExportDescriptorStr= uct->NumberPrmHandlers * sizeof (PRM_HANDLER_INFORMATION_STRUCT)) + (CurrentExportDescriptorStr= uct->Header.NumberPrmHandlers * sizeof (PRM_HANDLER_INFORMATION_STRUCT)) ); - CopyGuid (&CurrentModuleInfoStruct->Identifier, &CurrentExportDescri= ptorStruct->ModuleGuid); - CurrentModuleInfoStruct->HandlerCount =3D (UINT32) CurrentExpo= rtDescriptorStruct->NumberPrmHandlers; + CopyGuid (&CurrentModuleInfoStruct->Identifier, &CurrentExportDescri= ptorStruct->Header.ModuleGuid); + CurrentModuleInfoStruct->HandlerCount =3D (UINT32) CurrentExpo= rtDescriptorStruct->Header.NumberPrmHandlers; CurrentModuleInfoStruct->HandlerInfoOffset =3D OFFSET_OF (PRM_MODUL= E_INFORMATION_STRUCT, HandlerInfoStructure); =20 CurrentModuleInfoStruct->MajorRevision =3D 0; @@ -737,7 +737,7 @@ ProcessPrmModules ( // // Iterate across all PRM handlers in the PRM Module // - for (HandlerIndex =3D 0; HandlerIndex < CurrentExportDescriptorStruc= t->NumberPrmHandlers; HandlerIndex++) { + for (HandlerIndex =3D 0; HandlerIndex < CurrentExportDescriptorStruc= t->Header.NumberPrmHandlers; HandlerIndex++) { CurrentHandlerInfoStruct =3D &(CurrentModuleInfoStruct->HandlerInf= oStructure[HandlerIndex]); =20 CurrentHandlerInfoStruct->StructureRevision =3D PRM_HANDLER_INFORM= ATION_STRUCT_REVISION; diff --git a/PrmPkg/Include/PrmExportDescriptor.h b/PrmPkg/Include/PrmExp= ortDescriptor.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 PrmHandlerExportDescriptor= s[1]; } PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT; =20 #pragma pack(pop) =20 +#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 Handle= r. =20 @@ -73,8 +85,15 @@ typedef struct { this module. =20 **/ -#define PRM_MODULE_EXPORT(...) = \ - PRM_EXPORT_API PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT PRM_MODULE_EXPORT_D= ESCRIPTOR_NAME =3D { \ +#define PRM_MODULE_EXPORT(...) = \ + PRM_PACKED_STRUCT( = \ + { = \ + PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_HEADER Header; = \ + PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT PrmHandlerExportDescri= ptors[VA_ARG_COUNT(__VA_ARGS__)]; \ + } PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_ = \ + ); = \ + = \ + PRM_EXPORT_API PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT_ PRM_MODULE_EXPORT_= DESCRIPTOR_NAME =3D { \ { = \ PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE, = \ PRM_MODULE_EXPORT_REVISION, = \ --=20 2.28.0.windows.1