From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com []) by mx.groups.io with SMTP id smtpd.web08.34931.1624204037148521455 for ; Sun, 20 Jun 2021 08:47:25 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: zhiguang.liu@intel.com) IronPort-SDR: pzoRrnLBZhQSUo7X50rQiOIfXll7etrbBvUA+KpGazmlnz0xPSGulj8UO4uJYH+RkXbW8TaI+f 2Wbc3VAl53lg== X-IronPort-AV: E=McAfee;i="6200,9189,10021"; a="194044416" X-IronPort-AV: E=Sophos;i="5.83,287,1616482800"; d="scan'208,223";a="194044416" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jun 2021 08:47:24 -0700 IronPort-SDR: MuFXSmX+j4mwYqI24lGLmQPOV+M7CvskXuRhuMnUgZ0zrTd3ciEdN7zeXLHrbnKHXzWARmK47m eM6IfPzgOeQA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,287,1616482800"; d="scan'208,223";a="451932647" Received: from fieedk002.ccr.corp.intel.com ([10.239.158.144]) by orsmga008.jf.intel.com with ESMTP; 20 Jun 2021 08:47:23 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Maurice Ma , Guo Dong , Benjamin You Subject: [PATCH 06/12] UefiPayloadPkg: Get and enter DxeCore for Universal Payload Date: Sun, 20 Jun 2021 23:46:56 +0800 Message-Id: <20210620154702.2681-7-zhiguang.liu@intel.com> X-Mailer: git-send-email 2.30.0.windows.2 In-Reply-To: <20210620154702.2681-1-zhiguang.liu@intel.com> References: <20210620154702.2681-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable >>From gUniversalPayloadExtraDataGuid Guid Hob, get the Dxe FV information, and get the Dxe Core from the FV. Also, make sure if there are muliple FV hob, the FV hob pointing to this FV will be the first in the hob list. Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Signed-off-by: Zhiguang Liu --- UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c | 47 +++++++++++= ++++++++++++++++++++++++++++++++++++ UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 17 +++++++++++= ++++++ UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c | 44 +++++++++++= +++++++++++++++++++++++++++++++-- UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf | 1 + UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c | 4 ++-- 5 files changed, 109 insertions(+), 4 deletions(-) diff --git a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c b/UefiPayloadPkg= /UefiPayloadEntry/LoadDxeCore.c index de9dbb0b0e..f5d70c59f8 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c +++ b/UefiPayloadPkg/UefiPayloadEntry/LoadDxeCore.c @@ -305,3 +305,50 @@ LoadDxeCore ( =0D return EFI_SUCCESS;=0D }=0D +=0D +/**=0D + Find DXE core from FV and build DXE core HOBs.=0D +=0D + @param[in] DxeFv The FV where to find the DXE core.=0D + @param[out] DxeCoreEntryPoint DXE core entry point=0D +=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval EFI_NOT_FOUND If it failed to load DXE FV.=0D +**/=0D +EFI_STATUS=0D +UniversalLoadDxeCore (=0D + IN EFI_FIRMWARE_VOLUME_HEADER *DxeFv,=0D + OUT PHYSICAL_ADDRESS *DxeCoreEntryPoint=0D + )=0D +{=0D + EFI_STATUS Status;=0D + EFI_FFS_FILE_HEADER *FileHeader;=0D + VOID *PeCoffImage;=0D + EFI_PHYSICAL_ADDRESS ImageAddress;=0D + UINT64 ImageSize;=0D +=0D + //=0D + // Find DXE core file from DXE FV=0D + //=0D + Status =3D FvFindFile (DxeFv, EFI_FV_FILETYPE_DXE_CORE, &FileHeader);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + Status =3D FileFindSection (FileHeader, EFI_SECTION_PE32, (VOID **)&PeCo= ffImage);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + //=0D + // Get DXE core info=0D + //=0D + Status =3D LoadPeCoffImage (PeCoffImage, &ImageAddress, &ImageSize, DxeC= oreEntryPoint);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D + BuildModuleHob (&FileHeader->Name, ImageAddress, EFI_SIZE_TO_PAGES ((UIN= T32) ImageSize) * EFI_PAGE_SIZE, *DxeCoreEntryPoint);=0D +=0D + return EFI_SUCCESS;=0D +}=0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPaylo= adPkg/UefiPayloadEntry/UefiPayloadEntry.h index e9c3ec3073..35098f5141 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h @@ -33,6 +33,8 @@ #include =0D #include =0D #include =0D +#include =0D +#include =0D =0D #define LEGACY_8259_MASK_REGISTER_MASTER 0x21=0D #define LEGACY_8259_MASK_REGISTER_SLAVE 0xA1=0D @@ -117,6 +119,21 @@ LoadDxeCore ( OUT PHYSICAL_ADDRESS *DxeCoreEntryPoint=0D );=0D =0D +/**=0D + Find DXE core from FV and build DXE core HOBs.=0D +=0D + @param[in] DxeFv The FV where to find the DXE core.=0D + @param[out] DxeCoreEntryPoint DXE core entry point=0D +=0D + @retval EFI_SUCCESS If it completed successfully.=0D + @retval EFI_NOT_FOUND If it failed to load DXE FV.=0D +**/=0D +EFI_STATUS=0D +UniversalLoadDxeCore (=0D + IN EFI_FIRMWARE_VOLUME_HEADER *DxeFv,=0D + OUT PHYSICAL_ADDRESS *DxeCoreEntryPoint=0D + );=0D +=0D /**=0D Transfers control to DxeCore.=0D =0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c b/Uefi= PayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c index 66e87bcb9b..9d59454486 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.c @@ -179,7 +179,8 @@ FindAnotherHighestBelow4GResourceDescriptor ( **/=0D EFI_STATUS=0D BuildHobs (=0D - IN UINTN BootloaderParameter=0D + IN UINTN BootloaderParameter,=0D + OUT EFI_FIRMWARE_VOLUME_HEADER **DxeFv=0D )=0D {=0D EFI_PEI_HOB_POINTERS Hob;=0D @@ -190,6 +191,10 @@ BuildHobs ( EFI_PHYSICAL_ADDRESS MemoryTop;=0D EFI_HOB_RESOURCE_DESCRIPTOR *PhitResourceHob;=0D EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;=0D + UNIVERSAL_PAYLOAD_EXTRA_DATA *ExtraData;=0D + UINT8 *GuidHob;=0D + EFI_HOB_FIRMWARE_VOLUME *FvHob;=0D + UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;=0D =0D Hob.Raw =3D (UINT8 *) BootloaderParameter;=0D MinimalNeededSize =3D FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);=0D @@ -254,6 +259,10 @@ BuildHobs ( // From now on, mHobList will point to the new Hob range.=0D //=0D =0D + //=0D + // Create an empty FvHob for the DXE FV that contains DXE core.=0D + //=0D + BuildFvHob ((EFI_PHYSICAL_ADDRESS) 0, 0);=0D //=0D // Since payload created new Hob, move all hobs except PHIT from boot lo= ader hob list.=0D //=0D @@ -265,6 +274,29 @@ BuildHobs ( Hob.Raw =3D GET_NEXT_HOB (Hob);=0D }=0D =0D + //=0D + // Get DXE FV location=0D + //=0D + GuidHob =3D GetFirstGuidHob(&gUniversalPayloadExtraDataGuid);=0D + ASSERT (GuidHob !=3D NULL);=0D + GenericHeader =3D (UNIVERSAL_PAYLOAD_GENERIC_HEADER *) GET_GUID_HOB_DATA= (GuidHob);=0D + ASSERT (sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) <=3D GET_GUID_HOB_DATA= _SIZE (GuidHob));=0D + ASSERT (GenericHeader->Length <=3D GET_GUID_HOB_DATA_SIZE (GuidHob));=0D + ASSERT (GenericHeader->Length >=3D (sizeof (UNIVERSAL_PAYLOAD_EXTRA_DATA= ) + sizeof (UNIVERSAL_PAYLOAD_EXTRA_DATA_ENTRY)));=0D + ExtraData =3D (UNIVERSAL_PAYLOAD_EXTRA_DATA *) GET_GUID_HOB_DATA (GuidHo= b);=0D + ASSERT (ExtraData->Count =3D=3D 1);=0D + ASSERT (AsciiStrCmp (ExtraData->Entry[0].Identifier, "uefi_fv") =3D=3D 0= );=0D +=0D + *DxeFv =3D (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) ExtraData->Entry[0].Ba= se;=0D + ASSERT ((*DxeFv)->FvLength =3D=3D ExtraData->Entry[0].Size);=0D +=0D + //=0D + // Update DXE FV information to first fv hob in the hob list, which=0D + // is the empty FvHob created before.=0D + //=0D + FvHob =3D GetFirstHob (EFI_HOB_TYPE_FV);=0D + FvHob->BaseAddress =3D (EFI_PHYSICAL_ADDRESS) (UINTN) *DxeFv;=0D + FvHob->Length =3D (*DxeFv)->FvLength;=0D return EFI_SUCCESS;=0D }=0D =0D @@ -280,10 +312,13 @@ _ModuleEntryPoint ( )=0D {=0D EFI_STATUS Status;=0D + PHYSICAL_ADDRESS DxeCoreEntryPoint;=0D EFI_HOB_HANDOFF_INFO_TABLE *HandoffHobTable;=0D EFI_PEI_HOB_POINTERS Hob;=0D + EFI_FIRMWARE_VOLUME_HEADER *DxeFv;=0D =0D mHobList =3D (VOID *) BootloaderParameter;=0D + DxeFv =3D NULL;=0D // Call constructor for all libraries=0D ProcessLibraryConstructorList ();=0D =0D @@ -294,7 +329,11 @@ _ModuleEntryPoint ( InitializeFloatingPointUnits ();=0D =0D // Build HOB based on information from Bootloader=0D - Status =3D BuildHobs (BootloaderParameter);=0D + Status =3D BuildHobs (BootloaderParameter, &DxeFv);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + Status =3D UniversalLoadDxeCore (DxeFv, &DxeCoreEntryPoint);=0D + ASSERT_EFI_ERROR (Status);=0D =0D //=0D // Mask off all legacy 8259 interrupt sources=0D @@ -304,6 +343,7 @@ _ModuleEntryPoint ( =0D HandoffHobTable =3D (EFI_HOB_HANDOFF_INFO_TABLE *) GetFirstHob(EFI_HOB_T= YPE_HANDOFF);=0D Hob.HandoffInformationTable =3D HandoffHobTable;=0D + HandOffToDxeCore (DxeCoreEntryPoint, Hob);=0D =0D // Should not get here=0D CpuDeadLoop ();=0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf b/Ue= fiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf index 58ff87d969..77cd25aafd 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf @@ -62,6 +62,7 @@ gEfiSmbiosTableGuid=0D gEfiAcpiTableGuid=0D gUefiSerialPortInfoGuid=0D + gUniversalPayloadExtraDataGuid=0D =0D [FeaturePcd.IA32]=0D gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode ## CONSUME= S=0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c b/UefiPayloa= dPkg/UefiPayloadEntry/X64/DxeLoadFunc.c index 73ea30e7a2..dec87ee1ef 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c +++ b/UefiPayloadPkg/UefiPayloadEntry/X64/DxeLoadFunc.c @@ -66,8 +66,8 @@ HandOffToDxeCore ( //=0D // Get the address and size of the GHCB pages=0D //=0D - GhcbBase =3D (VOID *) PcdGet64 (PcdGhcbBase);=0D - GhcbSize =3D PcdGet64 (PcdGhcbSize);=0D + GhcbBase =3D 0;=0D + GhcbSize =3D 0;=0D =0D PageTables =3D 0;=0D if (FeaturePcdGet (PcdDxeIplBuildPageTables)) {=0D --=20 2.16.2.windows.1