Skip to content

Commit 091b6a1

Browse files
Sean-StarLabsmergify[bot]
authored andcommitted
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. Cc: Guo Dong <[email protected]> Cc: Ray Ni <[email protected]> Cc: Maurice Ma <[email protected]> Cc: Benjamin You <[email protected]> Signed-off-by: Sean Rhodes <[email protected]> Reviewed-by: Guo Dong <[email protected]> Reviewed-by: Ray Ni <[email protected]>
1 parent 949b8a3 commit 091b6a1

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,44 @@
55
66
**/
77

8+
#include <Guid/MemoryTypeInformation.h>
89
#include "UefiPayloadEntry.h"
910

1011
STATIC UINT32 mTopOfLowerUsableDram = 0;
1112

13+
EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {
14+
{ EfiACPIReclaimMemory, FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory) },
15+
{ EfiACPIMemoryNVS, FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS) },
16+
{ EfiReservedMemoryType, FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) },
17+
{ EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData) },
18+
{ EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode) },
19+
{ EfiMaxMemoryType, 0 }
20+
};
21+
22+
/**
23+
Function to reserve memory below 4GB for EDKII Modules.
24+
25+
This causes the DXE to dispatch everything under 4GB and allows Operating
26+
System's that require EFI_LOADED_IMAGE to be under 4GB to start.
27+
e.g. Xen hypervisor used in Qubes.
28+
**/
29+
VOID
30+
ForceModulesBelow4G (
31+
VOID
32+
)
33+
{
34+
DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to below 4G.\n"));
35+
36+
//
37+
// Create Memory Type Information HOB
38+
//
39+
BuildGuidDataHob (
40+
&gEfiMemoryTypeInformationGuid,
41+
mDefaultMemoryTypeInformation,
42+
sizeof (mDefaultMemoryTypeInformation)
43+
);
44+
}
45+
1246
/**
1347
Callback function to build resource descriptor HOB
1448
@@ -438,6 +472,11 @@ _ModuleEntryPoint (
438472
// Build other HOBs required by DXE
439473
BuildGenericHob ();
440474

475+
// Create a HOB to make resources for EDKII modules below 4G
476+
if (!FixedPcdGetBool (PcdDispatchModuleAbove4GMemory)) {
477+
ForceModulesBelow4G ();
478+
}
479+
441480
// Load the DXE Core
442481
Status = LoadDxeCore (&DxeCoreEntryPoint);
443482
ASSERT_EFI_ERROR (Status);

UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,15 @@
8686
gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize
8787
gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter
8888
gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
89+
gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS
90+
gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory
91+
gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType
92+
gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData
93+
gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode
8994

9095
gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIMES_CONSUMES
9196
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES
9297
gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES
9398

99+
gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory
100+

UefiPayloadPkg/UefiPayloadPkg.dec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x04000000|UINT32|0x
8383

8484
gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOID*|0x00000018
8585

86+
# Above 4G Memory
87+
gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory|TRUE|BOOLEAN|0x00000019
88+
8689
## FFS filename to find the default variable initial data file.
8790
# @Prompt FFS Name of variable initial data file
8891
gUefiPayloadPkgTokenSpaceGuid.PcdNvsDataFile |{ 0x1a, 0xf1, 0xb1, 0xae, 0x42, 0xcc, 0xcf, 0x4e, 0xac, 0x60, 0xdb, 0xab, 0xf6, 0xca, 0x69, 0xe6 }|VOID*|0x00000025

UefiPayloadPkg/UefiPayloadPkg.dsc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
DEFINE UNIVERSAL_PAYLOAD = FALSE
3434
DEFINE SECURITY_STUB_ENABLE = TRUE
3535
DEFINE SMM_SUPPORT = FALSE
36+
DEFINE ABOVE_4G_MEMORY = TRUE
3637
#
3738
# SBL: UEFI payload for Slim Bootloader
3839
# COREBOOT: UEFI payload for coreboot
@@ -399,6 +400,8 @@
399400
gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask | 0x1
400401
!endif
401402

403+
gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory|$(ABOVE_4G_MEMORY)
404+
402405
[PcdsPatchableInModule.X64]
403406
gPcAtChipsetPkgTokenSpaceGuid.PcdRtcIndexRegister|$(RTC_INDEX_REGISTER)
404407
gPcAtChipsetPkgTokenSpaceGuid.PcdRtcTargetRegister|$(RTC_TARGET_REGISTER)

0 commit comments

Comments
 (0)