From 1dde8b08dd0c575a54fa502d0563b9fa355a0e3b Mon Sep 17 00:00:00 2001 From: Liming Gao Date: Fri, 12 Jul 2013 02:49:22 +0000 Subject: [PATCH] Update PeiMemoryAllocationLib instance to support AllocateReservedPages() API. Signed-off-by: Liming Gao 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 --- .../MemoryAllocationLib.c | 33 +++++++++++++++++-- .../PeiMemoryAllocationLib.inf | 3 +- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c index 531ad7472f..90d4bbfd49 100644 --- a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c +++ b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c @@ -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.
+ Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
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 #include #include +#include /** @@ -44,15 +45,43 @@ InternalAllocatePages ( { 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; } diff --git a/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf b/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf index 82e4b8b7b7..c32c498929 100644 --- a/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf +++ b/MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf @@ -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.
+# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
# # 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 -- 2.39.2