]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Pei/Memory/MemoryServices.c
BaseTool/UPT: Add supporting of decimal numbers for INF_VERSION and DEC_SPECIFICATION
[mirror_edk2.git] / MdeModulePkg / Core / Pei / Memory / MemoryServices.c
index c7a06a3c5275322cbf6a8cd74079495f547af3f8..36bdc73ebdc59153a2b911c67e3940ca196df634 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   EFI PEI Core memory services\r
   \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -123,7 +123,7 @@ PeiInstallPeiMemory (
   @retval EFI_OUT_OF_RESOURCES  The pages could not be allocated.\r
   @retval EFI_INVALID_PARAMETER Type is not equal to EfiLoaderCode, EfiLoaderData, EfiRuntimeServicesCode, \r
                                 EfiRuntimeServicesData, EfiBootServicesCode, EfiBootServicesData,\r
-                                EfiACPIReclaimMemory, or EfiACPIMemoryNVS.\r
+                                EfiACPIReclaimMemory, EfiReservedMemoryType, or EfiACPIMemoryNVS.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -148,6 +148,7 @@ PeiAllocatePages (
       (MemoryType != EfiBootServicesCode) &&\r
       (MemoryType != EfiBootServicesData) &&\r
       (MemoryType != EfiACPIReclaimMemory) &&\r
+      (MemoryType != EfiReservedMemoryType) &&\r
       (MemoryType != EfiACPIMemoryNVS)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -178,16 +179,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 = EFI_SIZE_TO_PAGES ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom));\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