From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smarthost01b.ixn.mail.zen.net.uk (smarthost01b.ixn.mail.zen.net.uk [212.23.1.21]) by mx.groups.io with SMTP id smtpd.web12.3501.1645393281915474052 for ; Sun, 20 Feb 2022 13:41:22 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=permerror, err=parse error for token &{10 18 sdn.klaviyomail.com}: permanent DNS error (domain: starlabs.systems, ip: 212.23.1.21, mailfrom: sean@starlabs.systems) Received: from [217.155.46.38] (helo=sean-StarBook.lan) by smarthost01b.ixn.mail.zen.net.uk with esmtp (Exim 4.90_1) (envelope-from ) id 1nLtxI-0000p8-1i; Sun, 20 Feb 2022 21:41:20 +0000 From: "Sean Rhodes" To: devel@edk2.groups.io Cc: guo.dong@intel.com, Sean Rhodes , Ray Ni , Maurice Ma , Benjamin You Subject: [PATCH] UefiPayloadPkg: Add build option for Above 4G Memory Date: Sun, 20 Feb 2022 21:41:18 +0000 Message-Id: <27c3e79bb0a770392e6aa573afd0ebc0a377e133.1645393278.git.sean@starlabs.systems> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Originating-smarthost01b-IP: [217.155.46.38] Feedback-ID: 217.155.46.38 Content-Transfer-Encoding: quoted-printable When build option ABOVE_4G_MEMORY is set to true, nothing will change and EDKII will use all available memory. Setting it to false will create memory type information HOB in payload entry, so that EDKII will reserve enough memory below 4G for EDKII modules. This option is useful for bootloaders that are not fully 64-bit aware such as Qubes R4.0.4 bootloader, Zorin and Proxmox. Cc: Guo Dong Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Signed-off-by: Sean Rhodes --- .../Library/BrotliCustomDecompressLib/brotli | 2 +- .../UefiPayloadEntry/UefiPayloadEntry.c | 39 +++++++++++++++++++ .../UefiPayloadEntry/UefiPayloadEntry.inf | 7 ++++ UefiPayloadPkg/UefiPayloadPkg.dec | 3 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 3 ++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Library/BrotliCustomDecompressLib/brotli b/MdeMod= ulePkg/Library/BrotliCustomDecompressLib/brotli index f4153a09f8..666c3280cc 160000 --- a/MdeModulePkg/Library/BrotliCustomDecompressLib/brotli +++ b/MdeModulePkg/Library/BrotliCustomDecompressLib/brotli @@ -1 +1 @@ -Subproject commit f4153a09f87cbb9c826d8fc12c74642bb2d879ea +Subproject commit 666c3280cc11dc433c303d79a83d4ffbdd12cc8d diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPaylo= adPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e3691..998895e201 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -5,10 +5,44 @@ =0D **/=0D =0D +#include =0D #include "UefiPayloadEntry.h"=0D =0D STATIC UINT32 mTopOfLowerUsableDram =3D 0;=0D =0D +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] =3D {=0D + { EfiACPIReclaimMemory, FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemo= ry) },=0D + { EfiACPIMemoryNVS, FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS) = },=0D + { EfiReservedMemoryType, FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryT= ype) },=0D + { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServices= Data) },=0D + { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServices= Code) },=0D + { EfiMaxMemoryType, 0 = }=0D +};=0D +=0D +/**=0D + Function to reserve memory below 4GB for EDKII Modules.=0D +=0D + This causes the DXE to dispatch everything under 4GB and allows Operati= ng=0D + System's that require EFI_LOADED_IMAGE to be under 4GB to start.=0D + e.g. Xen hypervisor used in Qubes.=0D +**/=0D +VOID=0D +ForceModulesBelow4G (=0D + VOID=0D + )=0D +{=0D + DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to below 4= G.\n"));=0D +=0D + //=0D + // Create Memory Type Information HOB=0D + //=0D + BuildGuidDataHob (=0D + &gEfiMemoryTypeInformationGuid,=0D + mDefaultMemoryTypeInformation,=0D + sizeof (mDefaultMemoryTypeInformation)=0D + );=0D +}=0D +=0D /**=0D Callback function to build resource descriptor HOB=0D =0D @@ -438,6 +472,11 @@ _ModuleEntryPoint ( // Build other HOBs required by DXE=0D BuildGenericHob ();=0D =0D + // Create a HOB to make resources for EDKII modules below 4G=0D + if (!FixedPcdGetBool (PcdAbove4GMemory)) {=0D + ForceModulesBelow4G ();=0D + }=0D +=0D // Load the DXE Core=0D Status =3D LoadDxeCore (&DxeCoreEntryPoint);=0D ASSERT_EFI_ERROR (Status);=0D diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPay= loadPkg/UefiPayloadEntry/UefiPayloadEntry.inf index 1847d6481a..2ca47e3bb5 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf @@ -86,8 +86,15 @@ gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize=0D gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter=0D gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize=0D + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS=0D + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory=0D + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType=0D + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData=0D + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode=0D =0D gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES=0D gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIM= ES_CONSUMES=0D gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIM= ES_CONSUMES=0D =0D + gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory=0D +=0D diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayload= Pkg.dec index 551f0a4915..653a52b5a7 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSi= ze|0x04000000|UINT32|0x =0D gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0= xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOI= D*|0x00000018=0D =0D +# Above 4G Memory=0D +gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory|TRUE|BOOLEAN|0x00000019=0D +=0D ## FFS filename to find the default variable initial data file.=0D # @Prompt FFS Name of variable initial data file=0D gUefiPayloadPkgTokenSpaceGuid.PcdNvsDataFile |{ 0x1a, 0xf1, 0xb1, 0xae, 0= x42, 0xcc, 0xcf, 0x4e, 0xac, 0x60, 0xdb, 0xab, 0xf6, 0xca, 0x69, 0xe6 }|VOI= D*|0x00000025=0D diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index 1ce96a51c1..dad14be343 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -33,6 +33,7 @@ DEFINE UNIVERSAL_PAYLOAD =3D FALSE=0D DEFINE SECURITY_STUB_ENABLE =3D TRUE=0D DEFINE SMM_SUPPORT =3D FALSE=0D + DEFINE ABOVE_4G_MEMORY =3D TRUE=0D #=0D # SBL: UEFI payload for Slim Bootloader=0D # COREBOOT: UEFI payload for coreboot=0D @@ -399,6 +400,8 @@ gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask | 0x1=0D !endif=0D =0D + gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory|$(ABOVE_4G_MEMORY)=0D +=0D [PcdsPatchableInModule.X64]=0D gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister|$(RTC_INDEX_REGISTER)= =0D gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister|$(RTC_TARGET_REGISTER= )=0D --=20 2.32.0