Re: [edk2-devel] [PATCH] UefiPayloadPkg: Add build option for Above 4G Memory
It was merged https://github.com/tianocore/edk2/commit/091b6a11970a447106aadb6538046a85d3f29df5 -Original Message- From: Ni, Ray Sent: Monday, February 28, 2022 11:53 PM To: Rhodes, Sean ; devel@edk2.groups.io Cc: Dong, Guo ; Rhodes, Sean ; Ma, Maurice ; You, Benjamin Subject: RE: [PATCH] UefiPayloadPkg: Add build option for Above 4G Memory Reviewed-by: Ray Ni -Original Message- From: Sean Rhodes Sent: Thursday, February 24, 2022 7:00 AM To: devel@edk2.groups.io Cc: Dong, Guo ; Rhodes, Sean ; Ni, Ray ; Ma, Maurice ; You, Benjamin Subject: [PATCH] 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 Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Signed-off-by: Sean Rhodes --- .../UefiPayloadEntry/UefiPayloadEntry.c | 39 +++ .../UefiPayloadEntry/UefiPayloadEntry.inf | 7 UefiPayloadPkg/UefiPayloadPkg.dec | 3 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 3 ++ 4 files changed, 52 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e3691..780348eadf 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -5,10 +5,44 @@ **/ +#include #include "UefiPayloadEntry.h" STATIC UINT32 mTopOfLowerUsableDram = 0; +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = { + { EfiACPIReclaimMemory, FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory) }, + { EfiACPIMemoryNVS, FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS) }, + { EfiReservedMemoryType, FixedPcdGet32 + (PcdMemoryTypeEfiReservedMemoryType) }, + { EfiRuntimeServicesData, FixedPcdGet32 + (PcdMemoryTypeEfiRuntimeServicesData) }, + { EfiRuntimeServicesCode, FixedPcdGet32 + (PcdMemoryTypeEfiRuntimeServicesCode) }, + { EfiMaxMemoryType, 0 } +}; + +/** + Function to reserve memory below 4GB for EDKII Modules. + + This causes the DXE to dispatch everything under 4GB and allows + Operating + System's that require EFI_LOADED_IMAGE to be under 4GB to start. + e.g. Xen hypervisor used in Qubes. +**/ +VOID +ForceModulesBelow4G ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to + below 4G.\n")); + + // + // Create Memory Type Information HOB + // + BuildGuidDataHob ( +, +mDefaultMemoryTypeInformation, +sizeof (mDefaultMemoryTypeInformation) +); +} + /** Callback function to build resource descriptor HOB @@ -438,6 +472,11 @@ _ModuleEntryPoint ( // Build other HOBs required by DXE BuildGenericHob (); + // Create a HOB to make resources for EDKII modules below 4G + if (!FixedPcdGetBool (PcdDispatchModuleAbove4GMemory)) { +ForceModulesBelow4G (); + } + // Load the DXE Core Status = LoadDxeCore (); ASSERT_EFI_ERROR (Status); diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf index 1847d6481a..c4e4339ede 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf @@ -86,8 +86,15 @@ gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES + gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory + diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayloadPkg.dec index 551f0a4915..e9204d1168 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x0400|UINT32|0x gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41
Re: [edk2-devel] [PATCH] UefiPayloadPkg: Add build option for Above 4G Memory
Reviewed-by: Ray Ni -Original Message- From: Sean Rhodes Sent: Thursday, February 24, 2022 7:00 AM To: devel@edk2.groups.io Cc: Dong, Guo ; Rhodes, Sean ; Ni, Ray ; Ma, Maurice ; You, Benjamin Subject: [PATCH] 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 Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Signed-off-by: Sean Rhodes --- .../UefiPayloadEntry/UefiPayloadEntry.c | 39 +++ .../UefiPayloadEntry/UefiPayloadEntry.inf | 7 UefiPayloadPkg/UefiPayloadPkg.dec | 3 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 3 ++ 4 files changed, 52 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e3691..780348eadf 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -5,10 +5,44 @@ **/ +#include #include "UefiPayloadEntry.h" STATIC UINT32 mTopOfLowerUsableDram = 0; +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = { + { EfiACPIReclaimMemory, FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory) }, + { EfiACPIMemoryNVS, FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS) }, + { EfiReservedMemoryType, FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) }, + { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData) }, + { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode) }, + { EfiMaxMemoryType, 0 } +}; + +/** + Function to reserve memory below 4GB for EDKII Modules. + + This causes the DXE to dispatch everything under 4GB and allows Operating + System's that require EFI_LOADED_IMAGE to be under 4GB to start. + e.g. Xen hypervisor used in Qubes. +**/ +VOID +ForceModulesBelow4G ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to below 4G.\n")); + + // + // Create Memory Type Information HOB + // + BuildGuidDataHob ( +, +mDefaultMemoryTypeInformation, +sizeof (mDefaultMemoryTypeInformation) +); +} + /** Callback function to build resource descriptor HOB @@ -438,6 +472,11 @@ _ModuleEntryPoint ( // Build other HOBs required by DXE BuildGenericHob (); + // Create a HOB to make resources for EDKII modules below 4G + if (!FixedPcdGetBool (PcdDispatchModuleAbove4GMemory)) { +ForceModulesBelow4G (); + } + // Load the DXE Core Status = LoadDxeCore (); ASSERT_EFI_ERROR (Status); diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf index 1847d6481a..c4e4339ede 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf @@ -86,8 +86,15 @@ gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES + gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory + diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayloadPkg.dec index 551f0a4915..e9204d1168 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x0400|UINT32|0x gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOID*|0x0018 +# Above 4G Memory +gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory|TRUE|BOOLEAN|0x0019 + ## FFS filename to find the default variable initial data file. # @Prompt FFS Name of variable initial data file gUefiPayloadPkgTokenSpaceGuid.PcdNvsDataFile |{ 0x1a, 0xf1, 0xb1, 0xae, 0x42, 0xcc, 0xcf, 0x4e, 0xac, 0x60, 0xdb, 0xab,
Re: [edk2-devel] [PATCH] UefiPayloadPkg: Add build option for Above 4G Memory
Reviewed-by: Guo Dong -Original Message- From: Sean Rhodes Sent: Wednesday, February 23, 2022 4:00 PM To: devel@edk2.groups.io Cc: Dong, Guo ; Rhodes, Sean ; Ni, Ray ; Ma, Maurice ; You, Benjamin Subject: [PATCH] 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 Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Signed-off-by: Sean Rhodes --- .../UefiPayloadEntry/UefiPayloadEntry.c | 39 +++ .../UefiPayloadEntry/UefiPayloadEntry.inf | 7 UefiPayloadPkg/UefiPayloadPkg.dec | 3 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 3 ++ 4 files changed, 52 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e3691..780348eadf 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -5,10 +5,44 @@ **/ +#include #include "UefiPayloadEntry.h" STATIC UINT32 mTopOfLowerUsableDram = 0; +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {+ { EfiACPIReclaimMemory, FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory) },+ { EfiACPIMemoryNVS, FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS) },+ { EfiReservedMemoryType, FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) },+ { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData) },+ { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode) },+ { EfiMaxMemoryType, 0 }+};++/**+ Function to reserve memory below 4GB for EDKII Modules.++ This causes the DXE to dispatch everything under 4GB and allows Operating+ System's that require EFI_LOADED_IMAGE to be under 4GB to start.+ e.g. Xen hypervisor used in Qubes.+**/+VOID+ForceModulesBelow4G (+ VOID+ )+{+ DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to below 4G.\n"));++ //+ // Create Memory Type Information HOB+ //+ BuildGuidDataHob (+ ,+mDefaultMemoryTypeInformation,+sizeof (mDefaultMemoryTypeInformation)+);+}+ /**Callback function to build resource descriptor HOB @@ -438,6 +472,11 @@ _ModuleEntryPoint ( // Build other HOBs required by DXE BuildGenericHob (); + // Create a HOB to make resources for EDKII modules below 4G+ if (!FixedPcdGetBool (PcdDispatchModuleAbove4GMemory)) {+ForceModulesBelow4G ();+ }+ // Load the DXE Core Status = LoadDxeCore (); ASSERT_EFI_ERROR (Status);diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf index 1847d6481a..c4e4339ede 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf @@ -86,8 +86,15 @@ gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES + gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory+diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayloadPkg.dec index 551f0a4915..e9204d1168 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x0400|UINT32|0x gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOID*|0x0018 +# Above 4G Memory+gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory|TRUE|BOOLEAN|0x0019+ ## FFS filename to find the default variable initial data file. # @Prompt FFS Name of variable initial data file gUefiPayloadPkgTokenSpaceGuid.PcdNvsDataFile |{ 0x1a, 0xf1, 0xb1, 0xae, 0x42, 0xcc, 0xcf, 0x4e, 0xac, 0x60, 0xdb, 0xab, 0xf6, 0xca, 0x69, 0xe6 }|VOID*|0x0025diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc
[edk2-devel] [PATCH] 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 Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Signed-off-by: Sean Rhodes --- .../UefiPayloadEntry/UefiPayloadEntry.c | 39 +++ .../UefiPayloadEntry/UefiPayloadEntry.inf | 7 UefiPayloadPkg/UefiPayloadPkg.dec | 3 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 3 ++ 4 files changed, 52 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e3691..780348eadf 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -5,10 +5,44 @@ **/ +#include #include "UefiPayloadEntry.h" STATIC UINT32 mTopOfLowerUsableDram = 0; +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = { + { EfiACPIReclaimMemory, FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory) }, + { EfiACPIMemoryNVS, FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS) }, + { EfiReservedMemoryType, FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) }, + { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData) }, + { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode) }, + { EfiMaxMemoryType, 0 } +}; + +/** + Function to reserve memory below 4GB for EDKII Modules. + + This causes the DXE to dispatch everything under 4GB and allows Operating + System's that require EFI_LOADED_IMAGE to be under 4GB to start. + e.g. Xen hypervisor used in Qubes. +**/ +VOID +ForceModulesBelow4G ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to below 4G.\n")); + + // + // Create Memory Type Information HOB + // + BuildGuidDataHob ( +, +mDefaultMemoryTypeInformation, +sizeof (mDefaultMemoryTypeInformation) +); +} + /** Callback function to build resource descriptor HOB @@ -438,6 +472,11 @@ _ModuleEntryPoint ( // Build other HOBs required by DXE BuildGenericHob (); + // Create a HOB to make resources for EDKII modules below 4G + if (!FixedPcdGetBool (PcdDispatchModuleAbove4GMemory)) { +ForceModulesBelow4G (); + } + // Load the DXE Core Status = LoadDxeCore (); ASSERT_EFI_ERROR (Status); diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf index 1847d6481a..c4e4339ede 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf @@ -86,8 +86,15 @@ gUefiPayloadPkgTokenSpaceGuid.PcdPayloadFdMemSize gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES + gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory + diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayloadPkg.dec index 551f0a4915..e9204d1168 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x0400|UINT32|0x gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOID*|0x0018 +# Above 4G Memory +gUefiPayloadPkgTokenSpaceGuid.PcdDispatchModuleAbove4GMemory|TRUE|BOOLEAN|0x0019 + ## FFS filename to find the default variable initial data file. # @Prompt FFS Name of variable initial data file gUefiPayloadPkgTokenSpaceGuid.PcdNvsDataFile |{ 0x1a, 0xf1, 0xb1, 0xae, 0x42, 0xcc, 0xcf, 0x4e, 0xac, 0x60, 0xdb, 0xab, 0xf6, 0xca, 0x69, 0xe6 }|VOID*|0x0025 diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc index 1ce96a51c1..4fe81a61d6 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -33,6 +33,7 @@ DEFINE UNIVERSAL_PAYLOAD= FALSE DEFINE SECURITY_STUB_ENABLE = TRUE
Re: [edk2-devel] [PATCH] UefiPayloadPkg: Add build option for Above 4G Memory
+# Above 4G Memory +gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory|TRUE|BOOLEAN|0x0019 It is not clear for the usage from the PCD name and comments. Better to change PcdAbove4GMemory to PcdDispatchModuleAbove4GMemory or others? Thanks, Guo -Original Message- From: devel@edk2.groups.io On Behalf Of Sean Rhodes Sent: Sunday, February 20, 2022 2:41 PM To: devel@edk2.groups.io Cc: Dong, Guo ; Rhodes, Sean ; Ni, Ray ; Ma, Maurice ; You, Benjamin Subject: [edk2-devel] [PATCH] 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 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/MdeModulePkg/Library/BrotliCustomDecompressLib/brotli index f4153a09f8..666c3280cc 16 --- 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/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e3691..998895e201 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -5,10 +5,44 @@ **/ +#include #include "UefiPayloadEntry.h" STATIC UINT32 mTopOfLowerUsableDram = 0; +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {+ { EfiACPIReclaimMemory, FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory) },+ { EfiACPIMemoryNVS, FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS) },+ { EfiReservedMemoryType, FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) },+ { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData) },+ { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode) },+ { EfiMaxMemoryType, 0 }+};++/**+ Function to reserve memory below 4GB for EDKII Modules.++ This causes the DXE to dispatch everything under 4GB and allows Operating+ System's that require EFI_LOADED_IMAGE to be under 4GB to start.+ e.g. Xen hypervisor used in Qubes.+**/+VOID+ForceModulesBelow4G (+ VOID+ )+{+ DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to below 4G.\n"));++ //+ // Create Memory Type Information HOB+ //+ BuildGuidDataHob (+ ,+mDefaultMemoryTypeInformation,+sizeof (mDefaultMemoryTypeInformation)+);+}+ /**Callback function to build resource descriptor HOB @@ -438,6 +472,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 = LoadDxeCore (); ASSERT_EFI_ERROR (Status);diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/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+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData+ gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES + gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory+diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayloadPkg.dec index 551f0a4915..653a52b5a7 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPay
[edk2-devel] [PATCH] 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 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/MdeModulePkg/Library/BrotliCustomDecompressLib/brotli index f4153a09f8..666c3280cc 16 --- 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/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c index 0fed1e3691..998895e201 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -5,10 +5,44 @@ **/ +#include #include "UefiPayloadEntry.h" STATIC UINT32 mTopOfLowerUsableDram = 0; +EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = { + { EfiACPIReclaimMemory, FixedPcdGet32 (PcdMemoryTypeEfiACPIReclaimMemory) }, + { EfiACPIMemoryNVS, FixedPcdGet32 (PcdMemoryTypeEfiACPIMemoryNVS) }, + { EfiReservedMemoryType, FixedPcdGet32 (PcdMemoryTypeEfiReservedMemoryType) }, + { EfiRuntimeServicesData, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesData) }, + { EfiRuntimeServicesCode, FixedPcdGet32 (PcdMemoryTypeEfiRuntimeServicesCode) }, + { EfiMaxMemoryType, 0 } +}; + +/** + Function to reserve memory below 4GB for EDKII Modules. + + This causes the DXE to dispatch everything under 4GB and allows Operating + System's that require EFI_LOADED_IMAGE to be under 4GB to start. + e.g. Xen hypervisor used in Qubes. +**/ +VOID +ForceModulesBelow4G ( + VOID + ) +{ + DEBUG ((DEBUG_INFO, "Building hob to restrict memory resorces to below 4G.\n")); + + // + // Create Memory Type Information HOB + // + BuildGuidDataHob ( +, +mDefaultMemoryTypeInformation, +sizeof (mDefaultMemoryTypeInformation) +); +} + /** Callback function to build resource descriptor HOB @@ -438,6 +472,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 = LoadDxeCore (); ASSERT_EFI_ERROR (Status); diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/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 + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiPayloadPkgTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIMES_CONSUMES + gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory + diff --git a/UefiPayloadPkg/UefiPayloadPkg.dec b/UefiPayloadPkg/UefiPayloadPkg.dec index 551f0a4915..653a52b5a7 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dec +++ b/UefiPayloadPkg/UefiPayloadPkg.dec @@ -83,6 +83,9 @@ gUefiPayloadPkgTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x0400|UINT32|0x gUefiPayloadPkgTokenSpaceGuid.PcdPcdDriverFile|{ 0x57, 0x72, 0xcf, 0x80, 0xab, 0x87, 0xf9, 0x47, 0xa3, 0xfe, 0xD5, 0x0B, 0x76, 0xd8, 0x95, 0x41 }|VOID*|0x0018 +# Above 4G Memory +gUefiPayloadPkgTokenSpaceGuid.PcdAbove4GMemory|TRUE|BOOLEAN|0x0019 + ## FFS filename to find the default variable initial data file. # @Prompt FFS Name of variable initial data file