Revision: 14466
          http://sourceforge.net/p/edk2/code/14466
Author:   lgao4
Date:     2013-07-12 02:49:22 +0000 (Fri, 12 Jul 2013)
Log Message:
-----------
Update PeiMemoryAllocationLib instance to support AllocateReservedPages() API.
Signed-off-by: Liming Gao <[email protected]>
Reviewed-by: [email protected]

Modified Paths:
--------------
    trunk/edk2/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
    trunk/edk2/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

Modified: trunk/edk2/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
===================================================================
--- trunk/edk2/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c      
2013-07-12 02:48:08 UTC (rev 14465)
+++ trunk/edk2/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c      
2013-07-12 02:49:22 UTC (rev 14466)
@@ -2,7 +2,7 @@
   Support routines for memory allocation routines 
   based on PeiService for PEI phase drivers.
 
-  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials                          
   are licensed and made available under the terms and conditions of the BSD 
License         
   which accompanies this distribution.  The full text of the license may be 
found at        
@@ -21,6 +21,7 @@
 #include <Library/PeiServicesLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
+#include <Library/HobLib.h>
 
 
 /**
@@ -44,15 +45,43 @@
 {
   EFI_STATUS            Status;
   EFI_PHYSICAL_ADDRESS  Memory; 
+  EFI_MEMORY_TYPE       RequestType;
+  EFI_PEI_HOB_POINTERS  Hob;
 
   if (Pages == 0) {
     return NULL;
   }
 
-  Status = PeiServicesAllocatePages (MemoryType, Pages, &Memory);
+  RequestType = MemoryType;
+  if (MemoryType == EfiReservedMemoryType) {
+    //
+    // PEI AllocatePages() doesn't support EfiReservedMemoryType. 
+    // Change RequestType to EfiBootServicesData for memory allocation.
+    //
+    RequestType = EfiBootServicesData;
+  }
+
+  Status = PeiServicesAllocatePages (RequestType, Pages, &Memory);
   if (EFI_ERROR (Status)) {
     return NULL;
   }
+  
+  if (MemoryType == EfiReservedMemoryType) {
+    //
+    // Memory type needs to be updated to EfiReservedMemoryType. Per PI spec 
Volume 1, 
+    // PEI AllocatePages() will automate the creation of the Memory Allocation 
HOB types. 
+    // Search Memory Allocation HOB and find the matched memory region,
+    // then change its memory type to EfiReservedMemoryType.
+    //
+    Hob.Raw = GetFirstHob (EFI_HOB_TYPE_MEMORY_ALLOCATION);
+    while (Hob.Raw != NULL && 
Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress != Memory) {
+      Hob.Raw = GET_NEXT_HOB (Hob);
+      Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw);
+    }
+    ASSERT (Hob.Raw != NULL);
+    Hob.MemoryAllocation->AllocDescriptor.MemoryType = EfiReservedMemoryType;
+  }
+
   return (VOID *) (UINTN) Memory;
 }
 

Modified: 
trunk/edk2/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
===================================================================
--- trunk/edk2/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf 
2013-07-12 02:48:08 UTC (rev 14465)
+++ trunk/edk2/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf 
2013-07-12 02:49:22 UTC (rev 14466)
@@ -4,7 +4,7 @@
 # Memory Allocation Library that uses PEI Services to allocate memory.
 #  Free operations are ignored.
 #
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
@@ -40,4 +40,5 @@
   DebugLib
   BaseMemoryLib
   PeiServicesLib
+  HobLib
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to