CoreInitializeMemoryServices() will essentially pickup a piece of memory out of *any* memory descriptor HOB completely ignoring the memory allocation HOBs. This change considers memory allocation hobs in this API.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Liming Gao <[email protected]> --- MdeModulePkg/Core/Dxe/Gcd/Gcd.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c index a50fda2..24f4ba7 100644 --- a/MdeModulePkg/Core/Dxe/Gcd/Gcd.c +++ b/MdeModulePkg/Core/Dxe/Gcd/Gcd.c @@ -2001,10 +2001,39 @@ CoreConvertResourceDescriptorHobAttributesToCapabilities ( } return Capabilities; } +/** + Check whether the memory allocation hob is in the specified resource hob range. + + @param HobStart The start address of the HOB. + @param ResourceHob Resource range to be checked. + + @retval TRUE Memory allocation hob is in the specified ResourceHob. + @retval FALSE No memory allocation hob is in the specified ResourceHob. + +**/ +BOOLEAN +OverlapWithMemoryAllocationHob ( + IN VOID **HobStart, + IN EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob + ) +{ + EFI_PEI_HOB_POINTERS Hob; + + for (Hob.Raw = *HobStart; !END_OF_HOB_LIST(Hob); Hob.Raw = GET_NEXT_HOB(Hob)) { + if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_MEMORY_ALLOCATION) { + if (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress >= ResourceHob->PhysicalStart && + Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress < ResourceHob->PhysicalStart + ResourceHob->ResourceLength) { + return TRUE; + } + } + } + + return FALSE; +} /** External function. Initializes memory services based on the memory descriptor HOBs. This function is responsible for priming the memory map, so memory allocations and resource allocations can be made. @@ -2216,10 +2245,17 @@ CoreInitializeMemoryServices ( if (TestedMemoryLength < MINIMUM_INITIAL_MEMORY_SIZE) { continue; } // + // Skip Resource Descriptor HOBs that some of resource have been allocated in PEI. + // + if (OverlapWithMemoryAllocationHob (HobStart, ResourceHob)) { + continue; + } + + // // Save the Resource Descriptor HOB context that is large enough to initilize the DXE Core // MaxMemoryBaseAddress = TestedMemoryBaseAddress; MaxMemoryLength = TestedMemoryLength; MaxMemoryAttributes = ResourceHob->ResourceAttribute; -- 1.9.5.msysgit.0 _______________________________________________ edk2-devel mailing list [email protected] https://lists.01.org/mailman/listinfo/edk2-devel

