]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Update PeiMemoryAllocationLib instance to support AllocateReservedPages() API.
authorLiming Gao <liming.gao@intel.com>
Fri, 12 Jul 2013 02:49:22 +0000 (02:49 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 12 Jul 2013 02:49:22 +0000 (02:49 +0000)
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: michael.d.kinney@intel.com
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14466 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

index 531ad7472fc72cb5355057abdd03488115b79c1a..90d4bbfd4941cf9b9c2d1fdc009f3a678c4ce055 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 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2013, 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
@@ -21,6 +21,7 @@
 #include <Library/PeiServicesLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
 \r
 \r
 /**\r
@@ -44,15 +45,43 @@ 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
-  Status = PeiServicesAllocatePages (MemoryType, Pages, &Memory);\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
   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
 \r
index 82e4b8b7b7d402aa5ac20677ada52431b06301f6..c32c498929bcc5477138ba67c202960bb1c3e6b9 100644 (file)
@@ -4,7 +4,7 @@
 # Memory Allocation Library that uses PEI Services to allocate memory.\r
 #  Free operations are ignored.\r
 #\r
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -40,4 +40,5 @@
   DebugLib\r
   BaseMemoryLib\r
   PeiServicesLib\r
+  HobLib\r
 \r