summaryrefslogtreecommitdiff
path: root/MdeModulePkg
diff options
context:
space:
mode:
authorStar Zeng <star.zeng@intel.com>2014-10-14 06:53:18 +0000
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>2014-10-14 06:53:18 +0000
commit5e574a01ca816e1e1dc0863c61b92d7638a6d5fd (patch)
treea5b84b3408d1a9d5074b63a4d0f13c02ccc52472 /MdeModulePkg
parent544ccd1051108dcaf9eced3d57f465dd24a4e43e (diff)
downloadedk2-5e574a01ca816e1e1dc0863c61b92d7638a6d5fd.zip
edk2-5e574a01ca816e1e1dc0863c61b92d7638a6d5fd.tar.gz
edk2-5e574a01ca816e1e1dc0863c61b92d7638a6d5fd.tar.bz2
MdeModulePkg PeiCore: Update the code of PeiAllocatePages() to correctly consider the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION).
It can fix the confused ERROR log like below. "AllocatePages failed: No 0x1 Pages is available. There is only left 0x1 pages memory resource to be allocated." Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16211 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg')
-rw-r--r--MdeModulePkg/Core/Pei/Memory/MemoryServices.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
index 10f21d5..1213702 100644
--- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
+++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
@@ -178,16 +178,20 @@ PeiAllocatePages (
// Check to see if on 4k boundary, If not aligned, make the allocation aligned.
//
*(FreeMemoryTop) -= *(FreeMemoryTop) & 0xFFF;
-
+
//
- // Verify that there is sufficient memory to satisfy the allocation
+ // Verify that there is sufficient memory to satisfy the allocation.
+ // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs to be considered.
//
- RemainingPages = (UINTN)(*FreeMemoryTop - *FreeMemoryBottom) >> EFI_PAGE_SHIFT;
+ if ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom) < (UINTN) ALIGN_VALUE (sizeof (EFI_HOB_MEMORY_ALLOCATION), 8)) {
+ DEBUG ((EFI_D_ERROR, "AllocatePages failed: No space to build memory allocation hob.\n"));
+ return EFI_OUT_OF_RESOURCES;
+ }
+ RemainingPages = (UINTN)(*FreeMemoryTop - *FreeMemoryBottom - ALIGN_VALUE (sizeof (EFI_HOB_MEMORY_ALLOCATION), 8)) >> EFI_PAGE_SHIFT;
//
- // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs one extra page.
- // So the number of remaining pages needs to be greater than that of the request pages.
+ // The number of remaining pages needs to be greater than or equal to that of the request pages.
//
- if (RemainingPages <= Pages) {
+ if (RemainingPages < Pages) {
DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages));
DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));
return EFI_OUT_OF_RESOURCES;