From mboxrd@z Thu Jan 1 00:00:00 1970 Subject: Re: [edk2-devel] [PATCH 32/32] UefiPayloadPkg: Add build option for Above 4G Memory To: Guo Dong ,devel@edk2.groups.io From: "Sean Rhodes" X-Originating-Location: Surbiton, England, GB (217.155.46.38) X-Originating-Platform: Linux Chrome 97 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Sat, 29 Jan 2022 00:46:40 -0800 References: In-Reply-To: Message-ID: <690.1643446000445319196@groups.io> Content-Type: multipart/alternative; boundary="iLQDwEOlvzH2GGvSumPa" --iLQDwEOlvzH2GGvSumPa Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Thanks :) I've updated the PR. Do I need to resend the new patch again? [PATCH 33/33] UefiPayloadPkg: Add build option for Above 4G Memory 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. Signed-off-by: Sean Rhodes --- .../UefiPayloadEntry/UefiPayloadEntry.c=C2=A0 =C2=A0 =C2=A0 =C2=A0| 41 ++++= +++++++++++++++ .../UefiPayloadEntry/UefiPayloadEntry.inf=C2=A0 =C2=A0 =C2=A0|=C2=A0 7 ++++ UefiPayloadPkg/UefiPayloadPkg.dec=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0|=C2=A0 3 ++ UefiPayloadPkg/UefiPayloadPkg.dsc=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0|=C2=A0 3 ++ 4 files changed, 54 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPaylo= adPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e3691..d5c18dc343 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -5,10 +5,46 @@ **/ +#include #include "UefiPayloadEntry.h" STATIC UINT32=C2=A0 mTopOfLowerUsableDram =3D 0; +/** +=C2=A0 =C2=A0Function to reserve memory below 4GB for EDKII Modules. + +=C2=A0 =C2=A0This causes the DXE to dispatch everything under 4GB and allo= ws Operating +=C2=A0 =C2=A0System's that require EFI_LOADED_IMAGE to be under 4GB to sta= rt. +=C2=A0 =C2=A0e.g. Xen hypervisor used in Qubes + +=C2=A0 =C2=A0@param=C2=A0 None + +=C2=A0 @retval None +**/ +VOID +ForceModulesBelow4G ( +=C2=A0 VOID +=C2=A0 ) +{ +=C2=A0 DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to be= low 4G.\n")); +=C2=A0 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] =3D { +=C2=A0 =C2=A0 { EfiACPIReclaimMemory,=C2=A0 =C2=A0FixedPcdGet32 (PcdMemory= TypeEfiACPIReclaimMemory) }, +=C2=A0 =C2=A0 { EfiACPIMemoryNVS,=C2=A0 =C2=A0 =C2=A0 =C2=A0FixedPcdGet32 = (PcdMemoryTypeEfiACPIMemoryNVS) }, +=C2=A0 =C2=A0 { EfiReservedMemoryType,=C2=A0 FixedPcdGet32 (PcdMemoryTypeE= fiReservedMemoryType) }, +=C2=A0 =C2=A0 { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRun= timeServicesData) }, +=C2=A0 =C2=A0 { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRun= timeServicesCode) }, +=C2=A0 =C2=A0 { EfiMaxMemoryType,=C2=A0 =C2=A0 =C2=A0 =C2=A00=C2=A0 =C2=A0= =C2=A0} +=C2=A0 }; +=C2=A0 // +=C2=A0 // Create Memory Type Information HOB +=C2=A0 // +=C2=A0 BuildGuidDataHob ( +=C2=A0 =C2=A0 &gEfiMemoryTypeInformationGuid, +=C2=A0 =C2=A0 mDefaultMemoryTypeInformation, +=C2=A0 =C2=A0 sizeof(mDefaultMemoryTypeInformation) +=C2=A0 ); +} + /** Callback function to build resource descriptor HOB @@ -438,6 +474,11 @@ _ModuleEntryPoint ( // Build other HOBs required by DXE BuildGenericHob (); +=C2=A0 // Create a HOB to make resources for EDKII modules below 4G +=C2=A0 if (!FixedPcdGetBool (PcdAbove4GMemory) ) { +=C2=A0 =C2=A0 ForceModulesBelow4G (); +=C2=A0 } + // Load the DXE Core Status =3D LoadDxeCore (&DxeCoreEntryPoint); ASSERT_EFI_ERROR (Status); 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 gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize +=C2=A0 gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS +=C2=A0 gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory +=C2=A0 gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType +=C2=A0 gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData +=C2=A0 gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy=C2=A0 =C2=A0 =C2=A0= =C2=A0## SOMETIMES_CONSUMES +=C2=A0 gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory + 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 gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0x= ab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOID= *|0x00000018 +# Above 4G Memory +gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory|TRUE|BOOLEAN|0x00000019 + ## FFS filename to find the default variable initial data file. # @Prompt FFS Name of variable initial data file gUefiPayloadPkgTokenSpaceGuid.PcdNvsDataFile |{ 0x1a, 0xf1, 0xb1, 0xae, 0x4= 2, 0xcc, 0xcf, 0x4e, 0xac, 0x60, 0xdb, 0xab, 0xf6, 0xca, 0x69, 0xe6 }|VOID*= |0x00000025 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=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D FALSE DEFINE SECURITY_STUB_ENABLE=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D TRUE DEFINE SMM_SUPPORT=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =3D FALSE +=C2=A0 DEFINE ABOVE_4G_MEMORY=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =3D TRUE # # SBL:=C2=A0 =C2=A0 =C2=A0 UEFI payload for Slim Bootloader # COREBOOT: UEFI payload for coreboot @@ -399,6 +400,8 @@ gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask=C2=A0 =C2=A0 =C2= =A0 =C2=A0| 0x1 !endif +=C2=A0 gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory|$(ABOVE_4G_MEMORY) + [PcdsPatchableInModule.X64] gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister|$(RTC_INDEX_REGISTER) gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister|$(RTC_TARGET_REGISTER) -- 2.32.0 --iLQDwEOlvzH2GGvSumPa Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
Thanks :)

I've updated the PR. Do I need to resend the new = patch again?

[PATCH 33/33] UefiPayloadPkg: Add build option for = Above 4G Memory
 
When build option ABOVE_4G_MEMORY is set to true, nothing will change<= /div>
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<= /div>
fully 64-bit aware such as Qubes R4.0.4 bootloader, Zorin and Proxmox.=
 
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
 .../UefiPayloadEntry/UefiPayloadEntry.c      &nbs= p;| 41 +++++++++++++++++++
 .../UefiPayloadEntry/UefiPayloadEntry.inf     |&n= bsp; 7 ++++
 UefiPayloadPkg/UefiPayloadPkg.dec        &nb= sp;    |  3 ++
 UefiPayloadPkg/UefiPayloadPkg.dsc        &nb= sp;    |  3 ++
 4 files changed, 54 insertions(+)
 
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/Uefi= PayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
index 0fed1e3691..d5c18dc343 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
@@ -5,10 +5,46 @@
 
 **/
 
+#include <Guid/MemoryTypeInformation.h>
 #include "UefiPayloadEntry.h"
 
 STATIC UINT32  mTopOfLowerUsableDram =3D 0;
 
+/**
+   Function to reserve memory below 4GB for EDKII Modules.<= /div>
+
+   This causes the DXE to dispatch everything under 4GB and= allows Operating
+   System's that require EFI_LOADED_IMAGE to be under 4GB t= o start.
+   e.g. Xen hypervisor used in Qubes
+
+   @param  None
+
+  @retval None
+**/
+VOID
+ForceModulesBelow4G (
+  VOID
+  )
+{
+  DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces = to below 4G.\n"));
+  EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = =3D {
+    { EfiACPIReclaimMemory,   FixedPcdGet32 (PcdM= emoryTypeEfiACPIReclaimMemory) },
+    { EfiACPIMemoryNVS,       FixedPcdG= et32 (PcdMemoryTypeEfiACPIMemoryNVS) },
+    { EfiReservedMemoryType,  FixedPcdGet32 (PcdMemory= TypeEfiReservedMemoryType) },
+    { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeE= fiRuntimeServicesData) },
+    { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeE= fiRuntimeServicesCode) },
+    { EfiMaxMemoryType,       0  &= nbsp;  }
+  };
+  //
+  // Create Memory Type Information HOB
+  //
+  BuildGuidDataHob (
+    &gEfiMemoryTypeInformationGuid,
+    mDefaultMemoryTypeInformation,
+    sizeof(mDefaultMemoryTypeInformation)
+  );
+}
+
 /**
    Callback function to build resource descriptor HOB
 
@@ -438,6 +474,11 @@ _ModuleEntryPoint (
   // Build other HOBs required by DXE
   BuildGenericHob ();
 
+  // Create a HOB to make resources for EDKII modules below 4G
+  if (!FixedPcdGetBool (PcdAbove4GMemory) ) {
+    ForceModulesBelow4G ();
+  }
+
   // Load the DXE Core
   Status =3D LoadDxeCore (&DxeCoreEntryPoint);
   ASSERT_EFI_ERROR (Status);
diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/Ue= fiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index 1847d6481a..2ca47e3bb5 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -86,8 +86,15 @@
   gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize
   gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter
   gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSi= ze
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemor= y
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryTy= pe
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesD= ata
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesC= ode
 
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack  &nb= sp;            ## SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPo= licy ## SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy&n= bsp;      ## SOMETIMES_CONSUMES
 
+  gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory
+
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPa= yloadPkg.dec
index 551f0a4915..653a52b5a7 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dec
+++ b/UefiPayloadPkg/UefiPayloadPkg.dec
@@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiReg= ionSize|0x04000000|UINT32|0x
 
 gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xc= f, 0x80, 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, = 0x41 }|VOID*|0x00000018
 
+# Above 4G Memory
+gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory|TRUE|BOOLEAN|0x0000001= 9
+
 ## FFS filename to find the default variable initial data file.<= /div>
 # @Prompt FFS Name of variable initial data file
  gUefiPayloadPkgTokenSpaceGuid.PcdNvsDataFile |{ 0x1a, 0xf1, 0xb= 1, 0xae, 0x42, 0xcc, 0xcf, 0x4e, 0xac, 0x60, 0xdb, 0xab, 0xf6, 0xca, 0x69, = 0xe6 }|VOID*|0x00000025
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPa= yloadPkg.dsc
index 1ce96a51c1..dad14be343 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -33,6 +33,7 @@
   DEFINE UNIVERSAL_PAYLOAD         = ;   =3D FALSE
   DEFINE SECURITY_STUB_ENABLE        &n= bsp;=3D TRUE
   DEFINE SMM_SUPPORT          &nbs= p;       =3D FALSE
+  DEFINE ABOVE_4G_MEMORY           = ;   =3D TRUE
   #
   # SBL:      UEFI payload for Slim Bootload= er
   # COREBOOT: UEFI payload for coreboot
@@ -399,6 +400,8 @@
   gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMas= k       | 0x1
 !endif
 
+  gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory|$(ABOVE_4G_MEMO= RY)
+
 [PcdsPatchableInModule.X64]
   gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister|$(RTC_I= NDEX_REGISTER)
   gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister|$(RTC_= TARGET_REGISTER)
-- 
2.32.0
 
--iLQDwEOlvzH2GGvSumPa--