summaryrefslogtreecommitdiff
path: root/ArmPkg
diff options
context:
space:
mode:
authorOlivier Martin <olivier.martin@arm.com>2013-06-27 18:18:24 +0000
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>2013-06-27 18:18:24 +0000
commita58266e5fde9ed7e0e88f0b039ae68e926745dc5 (patch)
tree3e9c1d5135c256cbd9bc0c1bb2d89b0310cc1c04 /ArmPkg
parenta3202839da599ce4a0267e5a1288eee7099af880 (diff)
ArmPkg/BdsLib: Fixed manipulation of the Memory Map returned by GetMemoryMap()
The UEFI specification mandates that software uses the DescriptorSize returned by the GetMemoryMap() function to find the start of each EFI_MEMORY_DESCRIPTOR in the MemoryMap array. This allows for future expansion of the EFI_MEMORY_DESCRIPTOR. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14447 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ArmPkg')
-rw-r--r--ArmPkg/Library/BdsLib/BdsLinuxFdt.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/ArmPkg/Library/BdsLib/BdsLinuxFdt.c b/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
index 821774020..1927de726 100644
--- a/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
+++ b/ArmPkg/Library/BdsLib/BdsLinuxFdt.c
@@ -354,6 +354,7 @@ PrepareFdt (
UINT64 CpuReleaseAddr;
UINTN MemoryMapSize;
EFI_MEMORY_DESCRIPTOR *MemoryMap;
+ EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;
UINTN MapKey;
UINTN DescriptorSize;
UINT32 DescriptorVersion;
@@ -483,24 +484,32 @@ PrepareFdt (
MemoryMapSize = 0;
Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
if (Status == EFI_BUFFER_TOO_SMALL) {
+ // The UEFI specification advises to allocate more memory for the MemoryMap buffer between successive
+ // calls to GetMemoryMap(), since allocation of the new buffer may potentially increase memory map size.
Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;
MemoryMap = AllocatePages (Pages);
+ if (MemoryMap == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto FAIL_COMPLETE_FDT;
+ }
Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
}
// Go through the list and add the reserved region to the Device Tree
if (!EFI_ERROR(Status)) {
- for (Index = 0; Index < (MemoryMapSize / sizeof(EFI_MEMORY_DESCRIPTOR)); Index++) {
- if (IsLinuxReservedRegion ((EFI_MEMORY_TYPE)MemoryMap[Index].Type)) {
+ MemoryMapPtr = MemoryMap;
+ for (Index = 0; Index < (MemoryMapSize / DescriptorSize); Index++) {
+ if (IsLinuxReservedRegion ((EFI_MEMORY_TYPE)MemoryMapPtr->Type)) {
DEBUG((DEBUG_VERBOSE, "Reserved region of type %d [0x%X, 0x%X]\n",
- MemoryMap[Index].Type,
- (UINTN)MemoryMap[Index].PhysicalStart,
- (UINTN)(MemoryMap[Index].PhysicalStart + MemoryMap[Index].NumberOfPages * EFI_PAGE_SIZE)));
- err = fdt_add_mem_rsv(fdt, MemoryMap[Index].PhysicalStart, MemoryMap[Index].NumberOfPages * EFI_PAGE_SIZE);
+ MemoryMapPtr->Type,
+ (UINTN)MemoryMapPtr->PhysicalStart,
+ (UINTN)(MemoryMapPtr->PhysicalStart + MemoryMapPtr->NumberOfPages * EFI_PAGE_SIZE)));
+ err = fdt_add_mem_rsv(fdt, MemoryMapPtr->PhysicalStart, MemoryMapPtr->NumberOfPages * EFI_PAGE_SIZE);
if (err != 0) {
Print(L"Warning: Fail to add 'memreserve' (err:%d)\n", err);
}
}
+ MemoryMapPtr = (EFI_MEMORY_DESCRIPTOR*)((UINTN)MemoryMapPtr + DescriptorSize);
}
}