MdeModulePkg/AcpiTableDxe: use pool allocation for RSDT/XSDT if possible

If no memory allocation limit is in effect for ACPI tables, prefer
pool allocations over page allocations, to avoid wasting memory on
systems where page based allocations are rounded up to 64 KB, such
as AArch64.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Ard Biesheuvel 2020-10-16 16:53:53 +02:00 committed by mergify[bot]
parent 0e0ae47da6
commit cf299745ae
1 changed files with 72 additions and 46 deletions

View File

@ -355,6 +355,7 @@ ReallocateAcpiTableBuffer (
NewMaxTableNumber * sizeof (UINT32);
}
if (mAcpiTableAllocType != AllocateAnyPages) {
//
// Allocate memory in the lower 32 bit of address range for
// compatibility with ACPI 1.0 OS.
@ -371,12 +372,22 @@ ReallocateAcpiTableBuffer (
EFI_SIZE_TO_PAGES (TotalSize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
EfiACPIReclaimMemory,
TotalSize,
(VOID **)&Pointer
);
}
if (EFI_ERROR (Status)) {
return EFI_OUT_OF_RESOURCES;
}
Pointer = (UINT8 *) (UINTN) PageAddress;
if (mAcpiTableAllocType != AllocateAnyPages) {
Pointer = (UINT8 *)(UINTN)PageAddress;
}
ZeroMem (Pointer, TotalSize);
AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;
@ -406,6 +417,7 @@ ReallocateAcpiTableBuffer (
}
CopyMem (AcpiTableInstance->Xsdt, TempPrivateData.Xsdt, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT64)));
if (mAcpiTableAllocType != AllocateAnyPages) {
//
// Calculate orignal ACPI table buffer size
//
@ -419,7 +431,11 @@ ReallocateAcpiTableBuffer (
mEfiAcpiMaxNumTables * sizeof (UINT32);
}
gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1, EFI_SIZE_TO_PAGES (TotalSize));
gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1,
EFI_SIZE_TO_PAGES (TotalSize));
} else {
gBS->FreePool (TempPrivateData.Rsdt1);
}
//
// Update the Max ACPI table number
@ -1763,6 +1779,7 @@ AcpiTableAcpiTableConstructor (
mEfiAcpiMaxNumTables * sizeof (UINT32);
}
if (mAcpiTableAllocType != AllocateAnyPages) {
//
// Allocate memory in the lower 32 bit of address range for
// compatibility with ACPI 1.0 OS.
@ -1779,13 +1796,22 @@ AcpiTableAcpiTableConstructor (
EFI_SIZE_TO_PAGES (TotalSize),
&PageAddress
);
} else {
Status = gBS->AllocatePool (
EfiACPIReclaimMemory,
TotalSize,
(VOID **)&Pointer
);
}
if (EFI_ERROR (Status)) {
gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1, EFI_SIZE_TO_PAGES (RsdpTableSize));
return EFI_OUT_OF_RESOURCES;
}
Pointer = (UINT8 *) (UINTN) PageAddress;
if (mAcpiTableAllocType != AllocateAnyPages) {
Pointer = (UINT8 *)(UINTN)PageAddress;
}
ZeroMem (Pointer, TotalSize);
AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;