]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
MdePkg PeiMemoryAllocationLib: Update Free(Aligned)Pages
[mirror_edk2.git] / MdePkg / Library / PeiMemoryAllocationLib / MemoryAllocationLib.c
index afc3909612aa9c687ca7a4d6aa2f4f53f9068200..37273dde561ac45e889e8ecc33c0ef089349faf2 100644 (file)
@@ -2,7 +2,7 @@
   Support routines for memory allocation routines \r
   based on PeiService for PEI phase drivers.\r
 \r
-  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2017, 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
@@ -45,42 +45,15 @@ InternalAllocatePages (
 {\r
   EFI_STATUS            Status;\r
   EFI_PHYSICAL_ADDRESS  Memory; \r
-  EFI_MEMORY_TYPE       RequestType;\r
-  EFI_PEI_HOB_POINTERS  Hob;\r
 \r
   if (Pages == 0) {\r
     return NULL;\r
   }\r
 \r
-  RequestType = MemoryType;\r
-  if (MemoryType == EfiReservedMemoryType) {\r
-    //\r
-    // PEI AllocatePages() doesn't support EfiReservedMemoryType. \r
-    // Change RequestType to EfiBootServicesData for memory allocation.\r
-    //\r
-    RequestType = EfiBootServicesData;\r
-  }\r
-\r
-  Status = PeiServicesAllocatePages (RequestType, Pages, &Memory);\r
+  Status = PeiServicesAllocatePages (MemoryType, Pages, &Memory);\r
   if (EFI_ERROR (Status)) {\r
     return NULL;\r
   }\r
-  \r
-  if (MemoryType == EfiReservedMemoryType) {\r
-    //\r
-    // Memory type needs to be updated to EfiReservedMemoryType. Per PI spec Volume 1, \r
-    // PEI AllocatePages() will automate the creation of the Memory Allocation HOB types. \r
-    // Search Memory Allocation HOB and find the matched memory region,\r
-    // then change its memory type to EfiReservedMemoryType.\r
-    //\r
-    Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);\r
-    while (Hob.Raw != NULL && Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress != Memory) {\r
-      Hob.Raw = GET_NEXT_HOB (Hob);\r
-      Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);\r
-    }\r
-    ASSERT (Hob.Raw != NULL);\r
-    Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiReservedMemoryType;\r
-  }\r
 \r
   return (VOID *) (UINTN) Memory;\r
 }\r
@@ -175,10 +148,11 @@ FreePages (
   IN UINTN  Pages\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+\r
   ASSERT (Pages != 0);\r
-  //\r
-  // PEI phase does not support to free pages, so leave it as NOP.\r
-  //\r
+  Status = PeiServicesFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+  ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
 /**\r
@@ -471,10 +445,11 @@ FreeAlignedPages (
   IN UINTN  Pages\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+\r
   ASSERT (Pages != 0);\r
-  //\r
-  // PEI phase does not support to free pages, so leave it as NOP.\r
-  //\r
+  Status = PeiServicesFreePages ((EFI_PHYSICAL_ADDRESS) (UINTN) Buffer, Pages);\r
+  ASSERT_EFI_ERROR (Status);\r
 }\r
 \r
 /**\r