mirror of https://github.com/acidanthera/audk.git
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
This commit is contained in:
parent
a3202839da
commit
a58266e5fd
|
@ -354,6 +354,7 @@ PrepareFdt (
|
||||||
UINT64 CpuReleaseAddr;
|
UINT64 CpuReleaseAddr;
|
||||||
UINTN MemoryMapSize;
|
UINTN MemoryMapSize;
|
||||||
EFI_MEMORY_DESCRIPTOR *MemoryMap;
|
EFI_MEMORY_DESCRIPTOR *MemoryMap;
|
||||||
|
EFI_MEMORY_DESCRIPTOR *MemoryMapPtr;
|
||||||
UINTN MapKey;
|
UINTN MapKey;
|
||||||
UINTN DescriptorSize;
|
UINTN DescriptorSize;
|
||||||
UINT32 DescriptorVersion;
|
UINT32 DescriptorVersion;
|
||||||
|
@ -483,24 +484,32 @@ PrepareFdt (
|
||||||
MemoryMapSize = 0;
|
MemoryMapSize = 0;
|
||||||
Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
||||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
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;
|
Pages = EFI_SIZE_TO_PAGES (MemoryMapSize) + 1;
|
||||||
MemoryMap = AllocatePages (Pages);
|
MemoryMap = AllocatePages (Pages);
|
||||||
|
if (MemoryMap == NULL) {
|
||||||
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
|
goto FAIL_COMPLETE_FDT;
|
||||||
|
}
|
||||||
Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
Status = gBS->GetMemoryMap (&MemoryMapSize, MemoryMap, &MapKey, &DescriptorSize, &DescriptorVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go through the list and add the reserved region to the Device Tree
|
// Go through the list and add the reserved region to the Device Tree
|
||||||
if (!EFI_ERROR(Status)) {
|
if (!EFI_ERROR(Status)) {
|
||||||
for (Index = 0; Index < (MemoryMapSize / sizeof(EFI_MEMORY_DESCRIPTOR)); Index++) {
|
MemoryMapPtr = MemoryMap;
|
||||||
if (IsLinuxReservedRegion ((EFI_MEMORY_TYPE)MemoryMap[Index].Type)) {
|
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",
|
DEBUG((DEBUG_VERBOSE, "Reserved region of type %d [0x%X, 0x%X]\n",
|
||||||
MemoryMap[Index].Type,
|
MemoryMapPtr->Type,
|
||||||
(UINTN)MemoryMap[Index].PhysicalStart,
|
(UINTN)MemoryMapPtr->PhysicalStart,
|
||||||
(UINTN)(MemoryMap[Index].PhysicalStart + MemoryMap[Index].NumberOfPages * EFI_PAGE_SIZE)));
|
(UINTN)(MemoryMapPtr->PhysicalStart + MemoryMapPtr->NumberOfPages * EFI_PAGE_SIZE)));
|
||||||
err = fdt_add_mem_rsv(fdt, MemoryMap[Index].PhysicalStart, MemoryMap[Index].NumberOfPages * EFI_PAGE_SIZE);
|
err = fdt_add_mem_rsv(fdt, MemoryMapPtr->PhysicalStart, MemoryMapPtr->NumberOfPages * EFI_PAGE_SIZE);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
Print(L"Warning: Fail to add 'memreserve' (err:%d)\n", err);
|
Print(L"Warning: Fail to add 'memreserve' (err:%d)\n", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
MemoryMapPtr = (EFI_MEMORY_DESCRIPTOR*)((UINTN)MemoryMapPtr + DescriptorSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue