ArmPlatformPkg/MemoryInitPei: Check if the main System Memory resource has been declared

The PlatformLib could have declared the resource hob for
the main system memory region.
This change would prevent to get this system memory resource
to be declared twice.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <Olivier.Martin@arm.com>
Reviewed-by: Ronald Cron <Ronald.Cron@arm.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17834 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Olivier Martin 2015-07-06 16:55:29 +00:00 committed by oliviermartin
parent b1179c1929
commit 40a3f38f67
1 changed files with 44 additions and 20 deletions

View File

@ -1,6 +1,6 @@
/** @file /** @file
* *
* Copyright (c) 2011-2014, ARM Limited. All rights reserved. * Copyright (c) 2011-2015, ARM Limited. All rights reserved.
* *
* This program and the accompanying materials * This program and the accompanying materials
* are licensed and made available under the terms and conditions of the BSD License * are licensed and made available under the terms and conditions of the BSD License
@ -25,19 +25,17 @@ BuildMemoryTypeInformationHob (
VOID VOID
); );
STATIC
VOID VOID
InitMmu ( InitMmu (
VOID IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable
) )
{ {
ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
VOID *TranslationTableBase; VOID *TranslationTableBase;
UINTN TranslationTableSize; UINTN TranslationTableSize;
RETURN_STATUS Status; RETURN_STATUS Status;
// Get Virtual Memory Map from the Platform Library
ArmPlatformGetVirtualMemoryMap (&MemoryTable);
//Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in //Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in
// DRAM (even at the top of DRAM as it is the first permanent memory allocation) // DRAM (even at the top of DRAM as it is the first permanent memory allocation)
Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize); Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);
@ -69,13 +67,17 @@ MemoryPeim (
IN UINT64 UefiMemorySize IN UINT64 UefiMemorySize
) )
{ {
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
UINT64 ResourceLength; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes;
EFI_PEI_HOB_POINTERS NextHob; UINT64 ResourceLength;
EFI_PHYSICAL_ADDRESS FdTop; EFI_PEI_HOB_POINTERS NextHob;
EFI_PHYSICAL_ADDRESS SystemMemoryTop; EFI_PHYSICAL_ADDRESS FdTop;
EFI_PHYSICAL_ADDRESS ResourceTop; EFI_PHYSICAL_ADDRESS SystemMemoryTop;
BOOLEAN Found; EFI_PHYSICAL_ADDRESS ResourceTop;
BOOLEAN Found;
// Get Virtual Memory Map from the Platform Library
ArmPlatformGetVirtualMemoryMap (&MemoryTable);
// Ensure PcdSystemMemorySize has been set // Ensure PcdSystemMemorySize has been set
ASSERT (PcdGet64 (PcdSystemMemorySize) != 0); ASSERT (PcdGet64 (PcdSystemMemorySize) != 0);
@ -93,13 +95,35 @@ MemoryPeim (
EFI_RESOURCE_ATTRIBUTE_TESTED EFI_RESOURCE_ATTRIBUTE_TESTED
); );
//
// Check if the resource for the main system memory has been declared
//
Found = FALSE;
NextHob.Raw = GetHobList ();
while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {
if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) &&
(PcdGet64 (PcdSystemMemoryBase) >= NextHob.ResourceDescriptor->PhysicalStart) &&
(NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength <= PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)))
{
Found = TRUE;
break;
}
NextHob.Raw = GET_NEXT_HOB (NextHob);
}
if (!Found) {
// Reserved the memory space occupied by the firmware volume
BuildResourceDescriptorHob (
EFI_RESOURCE_SYSTEM_MEMORY,
ResourceAttributes,
PcdGet64 (PcdSystemMemoryBase),
PcdGet64 (PcdSystemMemorySize)
);
}
//
// Reserved the memory space occupied by the firmware volume // Reserved the memory space occupied by the firmware volume
BuildResourceDescriptorHob ( //
EFI_RESOURCE_SYSTEM_MEMORY,
ResourceAttributes,
PcdGet64 (PcdSystemMemoryBase),
PcdGet64 (PcdSystemMemorySize)
);
SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize); SystemMemoryTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemoryBase) + (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdSystemMemorySize);
FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize); FdTop = (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFdBaseAddress) + (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFdSize);
@ -163,7 +187,7 @@ MemoryPeim (
} }
// Build Memory Allocation Hob // Build Memory Allocation Hob
InitMmu (); InitMmu (MemoryTable);
if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) { if (FeaturePcdGet (PcdPrePiProduceMemoryTypeInformationHob)) {
// Optional feature that helps prevent EFI memory map fragmentation. // Optional feature that helps prevent EFI memory map fragmentation.