summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorddeptford <136014411+ddeptford@users.noreply.github.com>2023-07-07 08:49:45 -0700
committerLiming Gao <gaoliming@byosoft.com.cn>2025-08-06 08:59:25 +0800
commit5c7ef27b96421d5bac7ebe90a7d07d0cfc3f144f (patch)
tree2310caf64a464126cded8bd40efe16fe96b72590
parent686f1e3ea8373db48ea3a8457cc758c986455de0 (diff)
downloadedk2-5c7ef27b96421d5bac7ebe90a7d07d0cfc3f144f.tar.gz
edk2-5c7ef27b96421d5bac7ebe90a7d07d0cfc3f144f.zip
MdeModulePkg: UefiBootManagerLib Change default alignment for ramdisk boot.
The ramdisk is modelled as an NVDIMM which have a naturally higher alignment than 4K. Operating systems may wish to map NVDIMMs using large pages, so force the allocation alignment to 2MB. This change was tested using HTTP ramdisk boot, targeting a flat windows image. Signed-off-by: Aaron Pop <aaronpop@microsoft.com>
-rw-r--r--MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
index 3343e607fc..22ab4d7e48 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c
@@ -1404,7 +1404,7 @@ BmDestroyRamDisk (
Status = mRamDisk->Unregister (RamDiskDevicePath);
ASSERT_EFI_ERROR (Status);
- FreePages (RamDiskBuffer, RamDiskSizeInPages);
+ FreeAlignedPages (RamDiskBuffer, RamDiskSizeInPages);
}
/**
@@ -1454,8 +1454,12 @@ BmExpandLoadFile (
//
// The load option resides in a RAM disk.
+ // Use a reasonable default of 2MB for alignment as the ramdisk device is
+ // implemented as an NVDIMM persistent memory and operating systems may
+ // wish to map this with huge page support.
//
- FileBuffer = AllocateReservedPages (EFI_SIZE_TO_PAGES (BufferSize));
+
+ FileBuffer = AllocateAlignedReservedPages (EFI_SIZE_TO_PAGES (BufferSize), SIZE_2MB);
if (FileBuffer == NULL) {
DEBUG_CODE_BEGIN ();
EFI_DEVICE_PATH *LoadFilePath;
@@ -1496,7 +1500,7 @@ BmExpandLoadFile (
Status = LoadFile->LoadFile (LoadFile, FilePath, TRUE, &BufferSize, FileBuffer);
if (EFI_ERROR (Status)) {
- FreePages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize));
+ FreeAlignedPages (FileBuffer, EFI_SIZE_TO_PAGES (BufferSize));
return NULL;
}