]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg PeiCore: Update the code of PeiAllocatePages() to correctly consider...
authorStar Zeng <star.zeng@intel.com>
Tue, 14 Oct 2014 06:53:18 +0000 (06:53 +0000)
committerlzeng14 <lzeng14@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 14 Oct 2014 06:53:18 +0000 (06:53 +0000)
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

MdeModulePkg/Core/Pei/Memory/MemoryServices.c

index 10f21d5628b2d833d8fb585e2706eb99af12cbbf..1213702c680580e9968dedaee49821bb4db9bca2 100644 (file)
@@ -178,16 +178,20 @@ PeiAllocatePages (
   // Check to see if on 4k boundary, If not aligned, make the allocation aligned.\r
   //\r
   *(FreeMemoryTop) -= *(FreeMemoryTop) & 0xFFF;\r
-  \r
+\r
   //\r
-  // Verify that there is sufficient memory to satisfy the allocation\r
+  // Verify that there is sufficient memory to satisfy the allocation.\r
+  // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs to be considered.\r
   //\r
-  RemainingPages = (UINTN)(*FreeMemoryTop - *FreeMemoryBottom) >> EFI_PAGE_SHIFT;\r
+  if ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom) < (UINTN) ALIGN_VALUE (sizeof (EFI_HOB_MEMORY_ALLOCATION), 8)) {\r
+    DEBUG ((EFI_D_ERROR, "AllocatePages failed: No space to build memory allocation hob.\n"));\r
+    return  EFI_OUT_OF_RESOURCES;\r
+  }\r
+  RemainingPages = (UINTN)(*FreeMemoryTop - *FreeMemoryBottom - ALIGN_VALUE (sizeof (EFI_HOB_MEMORY_ALLOCATION), 8)) >> EFI_PAGE_SHIFT;\r
   //\r
-  // For page allocation, the overhead sizeof (EFI_HOB_MEMORY_ALLOCATION) needs one extra page.\r
-  // So the number of remaining pages needs to be greater than that of the request pages.\r
+  // The number of remaining pages needs to be greater than or equal to that of the request pages.\r
   //\r
-  if (RemainingPages <= Pages) {\r
+  if (RemainingPages < Pages) {\r
     DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is available.\n", (UINT64) Pages));\r
     DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource to be allocated.\n", (UINT64) RemainingPages));\r
     return  EFI_OUT_OF_RESOURCES;\r