From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.19271.1602863382145638521 for ; Fri, 16 Oct 2020 08:49:42 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BA9801474; Fri, 16 Oct 2020 08:49:40 -0700 (PDT) Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2DD133F719; Fri, 16 Oct 2020 08:49:39 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Dandan Bi , Liming Gao , Jian J Wang , Hao A Wu , Sami Mujawar , Laszlo Ersek , Leif Lindholm Subject: [PATCH 3/3] MdeModulePkg/AcpiTableDxe: use pool allocation for RSDP if possible Date: Fri, 16 Oct 2020 17:49:23 +0200 Message-Id: <20201016154923.21260-4-ard.biesheuvel@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201016154923.21260-1-ard.biesheuvel@arm.com> References: <20201016154923.21260-1-ard.biesheuvel@arm.com> Use a pool allocation for the RSDP ACPI root pointer structure if no memory limit is in effect that forces us to use page based allocation, which may be wasteful if they get rounded up to 64 KB as is the case on AArch64. Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c | 30 ++++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index 22f49a8489e7..fb939aa00f49 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -1737,19 +1737,26 @@ AcpiTableAcpiTableConstructor ( RsdpTableSize += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER); } - PageAddress = 0xFFFFFFFF; - Status = gBS->AllocatePages ( - mAcpiTableAllocType, - EfiACPIReclaimMemory, - EFI_SIZE_TO_PAGES (RsdpTableSize), - &PageAddress - ); + if (mAcpiTableAllocType != AllocateAnyPages) { + PageAddress = 0xFFFFFFFF; + Status = gBS->AllocatePages ( + mAcpiTableAllocType, + EfiACPIReclaimMemory, + EFI_SIZE_TO_PAGES (RsdpTableSize), + &PageAddress + ); + Pointer = (UINT8 *)(UINTN)PageAddress; + } else { + Status = gBS->AllocatePool ( + EfiACPIReclaimMemory, + RsdpTableSize, + (VOID **)&Pointer); + } if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } - Pointer = (UINT8 *) (UINTN) PageAddress; ZeroMem (Pointer, RsdpTableSize); AcpiTableInstance->Rsdp1 = (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) Pointer; @@ -1797,7 +1804,12 @@ AcpiTableAcpiTableConstructor ( } if (EFI_ERROR (Status)) { - gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1, EFI_SIZE_TO_PAGES (RsdpTableSize)); + if (mAcpiTableAllocType != AllocateAnyPages) { + gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1, + EFI_SIZE_TO_PAGES (RsdpTableSize)); + } else { + gBS->FreePool (AcpiTableInstance->Rsdp1); + } return EFI_OUT_OF_RESOURCES; } -- 2.17.1