From nobody Mon Feb 9 17:37:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+66325+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+66325+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1602863385; cv=none; d=zohomail.com; s=zohoarc; b=MLIDo31JOO70vei5XhBpS+KvsU9vM3O6nAd22GULoWH5yWKuxE8gPZAA4kk6TUQpLXSnHii6gGJAcf52ytEkjFQ/sLC4ySQ1FL71fhGBDW7Fnxm1J9XruDBc4TlvLAKDSoW02BpMkx7bcMYCbqXgxAU7nh6e5JeQT8NTN02+KHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602863385; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=M3lt6DJgqap1S1MPtVngJ8UnymqMhXfCadRWZXSeTx0=; b=TkpOBXItMbuFPlcl7oT5D8ST8/C5Ls09ZlUISy2sH1gPpWf8S1RBXdAEj8fw97yvNZSrZxIXDZ78afvMO25A8IWN0bJGyas400ScfjXs78tR7v9GO0iTB2fQD0lVQo4ycm/tEIziDimltI070mndiZCri21W3VbHw8Kx6UYfKLI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+66325+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1602863385370117.36859921698374; Fri, 16 Oct 2020 08:49:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OTb9YY1788612xZuTvDOqGBW; Fri, 16 Oct 2020 08:49:44 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.19267.1602863379345516421 for ; Fri, 16 Oct 2020 08:49:39 -0700 X-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 DE749143D; Fri, 16 Oct 2020 08:49:38 -0700 (PDT) X-Received: from e123331-lin.nice.arm.com (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4724A3F719; Fri, 16 Oct 2020 08:49:37 -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: [edk2-devel] [PATCH 2/3] MdeModulePkg/AcpiTableDxe: use pool allocation for RSDT/XSDT if possible Date: Fri, 16 Oct 2020 17:49:22 +0200 Message-Id: <20201016154923.21260-3-ard.biesheuvel@arm.com> In-Reply-To: <20201016154923.21260-1-ard.biesheuvel@arm.com> References: <20201016154923.21260-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: bNMMtLTdEidf3OhJ99fNGBhux1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1602863384; bh=7o/DKR8nTnd5xbVTQRQirb0d0WEKT93ZOQUGi33GGeU=; h=Cc:Date:From:Reply-To:Subject:To; b=ZgpqUtf+JZFo+3qLNIn3TPKJbbn3XqQVtJ9ZrZnqmT1uTQytEHEKQ0cxxQy0sXUMcmP HI107VK00NdvCR+5u3UJrqkfpmJXspmMjOgy6xXpYpC7VO6LqgNnGCHXqcA89JI5nHBxh TbUlKrQy6AUpE/jtZKSwiL+7yoWrpYv9fb8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c | 111 +++++++= +++++-------- 1 file changed, 65 insertions(+), 46 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b= /MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index b05e57e6584f..22f49a8489e7 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -355,28 +355,35 @@ ReallocateAcpiTableBuffer ( NewMaxTableNumber * sizeof (UINT32); } =20 - // - // Allocate memory in the lower 32 bit of address range for - // compatibility with ACPI 1.0 OS. - // - // This is done because ACPI 1.0 pointers are 32 bit values. - // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresse= s. - // There is no architectural reason these should be below 4GB, it is pur= ely - // for convenience of implementation that we force memory below 4GB. - // - PageAddress =3D 0xFFFFFFFF; - Status =3D gBS->AllocatePages ( - mAcpiTableAllocType, - EfiACPIReclaimMemory, - EFI_SIZE_TO_PAGES (TotalSize), - &PageAddress - ); + if (mAcpiTableAllocType !=3D AllocateAnyPages) { + // + // Allocate memory in the lower 32 bit of address range for + // compatibility with ACPI 1.0 OS. + // + // This is done because ACPI 1.0 pointers are 32 bit values. + // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addres= ses. + // There is no architectural reason these should be below 4GB, it is p= urely + // for convenience of implementation that we force memory below 4GB. + // + PageAddress =3D 0xFFFFFFFF; + Status =3D gBS->AllocatePages ( + mAcpiTableAllocType, + EfiACPIReclaimMemory, + EFI_SIZE_TO_PAGES (TotalSize), + &PageAddress + ); + Pointer =3D (UINT8 *)(UINTN)PageAddress; + } else { + Status =3D gBS->AllocatePool ( + EfiACPIReclaimMemory, + TotalSize, + (VOID **)&Pointer); + } =20 if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } =20 - Pointer =3D (UINT8 *) (UINTN) PageAddress; ZeroMem (Pointer, TotalSize); =20 AcpiTableInstance->Rsdt1 =3D (EFI_ACPI_DESCRIPTION_HEADER *) Pointer; @@ -406,21 +413,26 @@ ReallocateAcpiTableBuffer ( } CopyMem (AcpiTableInstance->Xsdt, TempPrivateData.Xsdt, (sizeof (EFI_ACP= I_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT64))); =20 - // - // Calculate orignal ACPI table buffer size - // - TotalSize =3D sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI= 2.0/3.0 XSDT - mEfiAcpiMaxNumTables * sizeof (UINT64); + if (mAcpiTableAllocType !=3D AllocateAnyPages) { + // + // Calculate orignal ACPI table buffer size + // + TotalSize =3D sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for AC= PI 2.0/3.0 XSDT + mEfiAcpiMaxNumTables * sizeof (UINT64); =20 - if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0= B) !=3D 0) { - TotalSize +=3D sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for A= CPI 1.0 RSDT - mEfiAcpiMaxNumTables * sizeof (UINT32) + - sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACP= I 2.0/3.0 RSDT - mEfiAcpiMaxNumTables * sizeof (UINT32); + if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1= _0B) !=3D 0) { + TotalSize +=3D sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for= ACPI 1.0 RSDT + mEfiAcpiMaxNumTables * sizeof (UINT32) + + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for A= CPI 2.0/3.0 RSDT + mEfiAcpiMaxNumTables * sizeof (UINT32); + } + + gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1, + EFI_SIZE_TO_PAGES (TotalSize)); + } else { + gBS->FreePool (TempPrivateData.Rsdt1); } =20 - gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1, EFI_= SIZE_TO_PAGES (TotalSize)); - // // Update the Max ACPI table number // @@ -1759,29 +1771,36 @@ AcpiTableAcpiTableConstructor ( mEfiAcpiMaxNumTables * sizeof (UINT32); } =20 - // - // Allocate memory in the lower 32 bit of address range for - // compatibility with ACPI 1.0 OS. - // - // This is done because ACPI 1.0 pointers are 32 bit values. - // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresse= s. - // There is no architectural reason these should be below 4GB, it is pur= ely - // for convenience of implementation that we force memory below 4GB. - // - PageAddress =3D 0xFFFFFFFF; - Status =3D gBS->AllocatePages ( - mAcpiTableAllocType, - EfiACPIReclaimMemory, - EFI_SIZE_TO_PAGES (TotalSize), - &PageAddress - ); + if (mAcpiTableAllocType !=3D AllocateAnyPages) { + // + // Allocate memory in the lower 32 bit of address range for + // compatibility with ACPI 1.0 OS. + // + // This is done because ACPI 1.0 pointers are 32 bit values. + // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addres= ses. + // There is no architectural reason these should be below 4GB, it is p= urely + // for convenience of implementation that we force memory below 4GB. + // + PageAddress =3D 0xFFFFFFFF; + Status =3D gBS->AllocatePages ( + mAcpiTableAllocType, + EfiACPIReclaimMemory, + EFI_SIZE_TO_PAGES (TotalSize), + &PageAddress + ); + Pointer =3D (UINT8 *)(UINTN)PageAddress; + } else { + Status =3D gBS->AllocatePool ( + EfiACPIReclaimMemory, + TotalSize, + (VOID **)&Pointer); + } =20 if (EFI_ERROR (Status)) { gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1,= EFI_SIZE_TO_PAGES (RsdpTableSize)); return EFI_OUT_OF_RESOURCES; } =20 - Pointer =3D (UINT8 *) (UINTN) PageAddress; ZeroMem (Pointer, TotalSize); =20 AcpiTableInstance->Rsdt1 =3D (EFI_ACPI_DESCRIPTION_HEADER *) Pointer; --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#66325): https://edk2.groups.io/g/devel/message/66325 Mute This Topic: https://groups.io/mt/77553424/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-