Revision: 16211
          http://sourceforge.net/p/edk2/code/16211
Author:   lzeng14
Date:     2014-10-14 06:53:18 +0000 (Tue, 14 Oct 2014)
Log Message:
-----------
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 <[email protected]>
Reviewed-by: Liming Gao <[email protected]>

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Core/Pei/Memory/MemoryServices.c

Modified: trunk/edk2/MdeModulePkg/Core/Pei/Memory/MemoryServices.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Pei/Memory/MemoryServices.c    2014-10-14 
06:30:17 UTC (rev 16210)
+++ trunk/edk2/MdeModulePkg/Core/Pei/Memory/MemoryServices.c    2014-10-14 
06:53:18 UTC (rev 16211)
@@ -178,16 +178,20 @@
   // 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;


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to