]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiPayloadPkg: Add build option for Above 4G Memory
authorSean Rhodes <sean@starlabs.systems>
Wed, 23 Feb 2022 22:59:33 +0000 (15:59 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 4 Mar 2022 22:17:49 +0000 (22:17 +0000)
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 <guo.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Benjamin You <benjamin.you@intel.com>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
Reviewed-by: Guo Dong <guo.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
UefiPayloadPkg/UefiPayloadPkg.dec
UefiPayloadPkg/UefiPayloadPkg.dsc

index 0fed1e36918aa6d58499a246a4b212a59833aa3d..780348eadfa87a9e103dfdf61e2f7eb00403090b 100644 (file)
@@ -5,10 +5,44 @@
 \r
 **/\r
 \r
+#include <Guid/MemoryTypeInformation.h>\r
 #include "UefiPayloadEntry.h"\r
 \r
 STATIC UINT32  mTopOfLowerUsableDram = 0;\r
 \r
+EFI_MEMORY_TYPE_INFORMATION  mDefaultMemoryTypeInformation[] = {\r
+  { EfiACPIReclaimMemory,   FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory)   },\r
+  { EfiACPIMemoryNVS,       FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS)       },\r
+  { EfiReservedMemoryType,  FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType)  },\r
+  { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData) },\r
+  { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode) },\r
+  { EfiMaxMemoryType,       0                                                   }\r
+};\r
+\r
+/**\r
+   Function to reserve memory below 4GB for EDKII Modules.\r
+\r
+   This causes the DXE to dispatch everything under 4GB and allows Operating\r
+   System's that require EFI_LOADED_IMAGE to be under 4GB to start.\r
+   e.g. Xen hypervisor used in Qubes.\r
+**/\r
+VOID\r
+ForceModulesBelow4G (\r
+  VOID\r
+  )\r
+{\r
+  DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to below 4G.\n"));\r
+\r
+  //\r
+  // Create Memory Type Information HOB\r
+  //\r
+  BuildGuidDataHob (\r
+    &gEfiMemoryTypeInformationGuid,\r
+    mDefaultMemoryTypeInformation,\r
+    sizeof (mDefaultMemoryTypeInformation)\r
+    );\r
+}\r
+\r
 /**\r
    Callback function to build resource descriptor HOB\r
 \r
@@ -438,6 +472,11 @@ _ModuleEntryPoint (
   // Build other HOBs required by DXE\r
   BuildGenericHob ();\r
 \r
+  // Create a HOB to make resources for EDKII modules below 4G\r
+  if (!FixedPcdGetBool (PcdDispatchModuleAbove4GMemory)) {\r
+    ForceModulesBelow4G ();\r
+  }\r
+\r
   // Load the DXE Core\r
   Status = LoadDxeCore (&DxeCoreEntryPoint);\r
   ASSERT_EFI_ERROR (Status);\r
index 1847d6481a235852d80889dcb009acde2891a95d..c4e4339ede4bf6ba2e7c3826c01a05ae8fc964a1 100644 (file)
   gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize\r
   gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter\r
   gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize\r
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS\r
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory\r
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType\r
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData\r
+  gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode\r
 \r
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack               ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy       ## SOMETIMES_CONSUMES\r
 \r
+  gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory\r
+\r
index 551f0a49158588def27d76b0583aa4c58cd37c24..e9204d1168012b60be9532b29121919d365f3916 100644 (file)
@@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000|UINT32|0x
 \r
 gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOID*|0x00000018\r
 \r
+# Above 4G Memory\r
+gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory|TRUE|BOOLEAN|0x00000019\r
+\r
 ## FFS filename to find the default variable initial data file.\r
 # @Prompt FFS Name of variable initial data file\r
  gUefiPayloadPkgTokenSpaceGuid.PcdNvsDataFile |{ 0x1a, 0xf1, 0xb1, 0xae, 0x42, 0xcc, 0xcf, 0x4e, 0xac, 0x60, 0xdb, 0xab, 0xf6, 0xca, 0x69, 0xe6 }|VOID*|0x00000025\r
index 1ce96a51c102049abf53991ed91496ab4fad7cc5..4fe81a61d6714b5f302c7d10bc1d9c6667bc6e67 100644 (file)
@@ -33,6 +33,7 @@
   DEFINE UNIVERSAL_PAYLOAD            = FALSE\r
   DEFINE SECURITY_STUB_ENABLE         = TRUE\r
   DEFINE SMM_SUPPORT                  = FALSE\r
+  DEFINE ABOVE_4G_MEMORY              = TRUE\r
   #\r
   # SBL:      UEFI payload for Slim Bootloader\r
   # COREBOOT: UEFI payload for coreboot\r
   gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask       | 0x1\r
 !endif\r
 \r
+  gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory|$(ABOVE_4G_MEMORY)\r
+\r
 [PcdsPatchableInModule.X64]\r
   gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister|$(RTC_INDEX_REGISTER)\r
   gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister|$(RTC_TARGET_REGISTER)\r