From nobody Thu May 9 23:42:57 2024 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+66707+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+66707+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1603914172; cv=none; d=zohomail.com; s=zohoarc; b=eaTTVB/oEOBAGV/3aLuh8f67X+XyDYYTcwYrvt4R53H5cZ28excv67VwTyzuuFW/RkZjrL3uNQ/f7N2ow8023tgHblDWtCkvIRJ64H+x1bm4zZZf7Ue1O2gs7ThvkwjlVkqz4xF6l+YGFqL+ppVv2SgYDklERv//pFg+gUyQeCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603914172; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=IubL0+dly9Y6BQyQ1wT6d73mPa1+df6EWnKz9sXWp1c=; b=W9sEJRVFu/tkhspXJ1vua2/jdjJMDZhYmpKigil9MiVu3IjieT9LRHGd/mUnzCqbOXfcF9MDMutXRv7a+5uRVB8iIf5PC5ZUnZ6TbS3dKHFzmfz5Ie/ERWw6JGIKOrltO/8lsMu8DnYe7JCDEE/l+kfUuGz2b6LRcvQexLPReNk= 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+66707+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 160391417214156.787934011207426; Wed, 28 Oct 2020 12:42:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uQ4gYY1788612xXmRpDw0yB2; Wed, 28 Oct 2020 12:42:51 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.2599.1603914165696594133 for ; Wed, 28 Oct 2020 12:42:46 -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 68C7B1AED; Wed, 28 Oct 2020 12:42:45 -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 49CCB3F68F; Wed, 28 Oct 2020 12:42:43 -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 v2 1/3] MdeModulePkg/AcpiTableDxe: use pool allocations when possible Date: Wed, 28 Oct 2020 20:42:24 +0100 Message-Id: <20201028194226.21556-2-ard.biesheuvel@arm.com> In-Reply-To: <20201028194226.21556-1-ard.biesheuvel@arm.com> References: <20201028194226.21556-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: dXL4hDpMc0xJWTPICH5HQZxGx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1603914171; bh=+5idaoxxCbc3taIVxYYDR5wTeBWFLjJMnlOp5wQJ72Q=; h=Cc:Date:From:Reply-To:Subject:To; b=vsMqhgGB+aZenwBtvfDGn6GM2wkklItpIKYf+ViHU6tw15e7hpuR6t31Y+R2tTeKn4l oyHAXipwL51NqGM3QY9XGr/RrQf85GtjPJNcZKNQyAhm9q66Yf/Bk/mh+eyTdE6qa87U2 IgJgt1DuFhcsMRkNST34jAnk5Wd8GV4ublU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" On AArch64 systems, page based allocations for memory types that are relevant to the OS are rounded up to 64 KB multiples. This wastes some space in the ACPI table memory allocator, since it uses page based allocations in order to be able to place the ACPI tables low in memory. Since the latter requirement does not exist on AArch64, switch to pool allocations for all ACPI tables except the root tables if the active allocation policy permits them to be anywhere in memory. The root tables will be handled in a subsequent patch. Signed-off-by: Ard Biesheuvel Reviewed-by: Liming Gao --- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h | 11 ++- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c | 4 +- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c | 79 ++++++++= ++++++------ 3 files changed, 66 insertions(+), 28 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h b/MdeModu= lePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h index 425a462fd92b..9d7cf7ccfc76 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h @@ -55,18 +55,21 @@ // Link is the linked list data. // Version is the versions of the ACPI tables that this table belongs in. // Table is a pointer to the table. -// PageAddress is the address of the pages allocated for the table. -// NumberOfPages is the number of pages allocated at PageAddress. +// TableSize is the size of the table // Handle is used to identify a particular table. +// PoolAllocation carries the allocation type: +// FALSE: Table points to EFI_SIZE_TO_PAGES(TableSize) pages allocated = using +// gBS->AllocatePages () +// TRUE: Table points to TableSize bytes allocated using gBS->Allocate= Pool () // typedef struct { UINT32 Signature; LIST_ENTRY Link; EFI_ACPI_TABLE_VERSION Version; EFI_ACPI_COMMON_HEADER *Table; - EFI_PHYSICAL_ADDRESS PageAddress; - UINTN NumberOfPages; + UINTN TableSize; UINTN Handle; + BOOLEAN PoolAllocation; } EFI_ACPI_TABLE_LIST; =20 // diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c b/MdeModule= Pkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c index b1cba20c8ed7..14ced68e645f 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c @@ -68,8 +68,8 @@ FindTableByBuffer ( =20 while (CurrentLink !=3D StartLink) { CurrentTableList =3D EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink); - if (((UINTN)CurrentTableList->PageAddress <=3D (UINTN)Buffer) && - ((UINTN)CurrentTableList->PageAddress + EFI_PAGES_TO_SIZE(CurrentT= ableList->NumberOfPages) > (UINTN)Buffer)) { + if (((UINTN)CurrentTableList->Table <=3D (UINTN)Buffer) && + ((UINTN)CurrentTableList->Table + CurrentTableList->TableSize > (U= INTN)Buffer)) { // // Good! Found Table. // diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b= /MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index ad7baf8205b4..e85a98aee6bf 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -428,6 +428,26 @@ ReallocateAcpiTableBuffer ( return EFI_SUCCESS; } =20 +/** + Free the memory associated with the provided EFI_ACPI_TABLE_LIST instance + + @param TableEntry EFI_ACPI_TABLE_LIST instance pointer + +**/ +STATIC +VOID +FreeTableMemory ( + EFI_ACPI_TABLE_LIST *TableEntry + ) +{ + if (TableEntry->PoolAllocation) { + gBS->FreePool (TableEntry->Table); + } else { + gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)TableEntry->Table, + EFI_SIZE_TO_PAGES (TableEntry->TableSize)); + } +} + /** This function adds an ACPI table to the table list. It will detect FACS= and allocate the correct type of memory and properly align the table. @@ -454,14 +474,15 @@ AddTableToList ( OUT UINTN *Handle ) { - EFI_STATUS Status; - EFI_ACPI_TABLE_LIST *CurrentTableList; - UINT32 CurrentTableSignature; - UINT32 CurrentTableSize; - UINT32 *CurrentRsdtEntry; - VOID *CurrentXsdtEntry; - UINT64 Buffer64; - BOOLEAN AddToRsdt; + EFI_STATUS Status; + EFI_ACPI_TABLE_LIST *CurrentTableList; + UINT32 CurrentTableSignature; + UINT32 CurrentTableSize; + UINT32 *CurrentRsdtEntry; + VOID *CurrentXsdtEntry; + EFI_PHYSICAL_ADDRESS AllocPhysAddress; + UINT64 Buffer64; + BOOLEAN AddToRsdt; =20 // // Check for invalid input parameters @@ -496,8 +517,9 @@ AddTableToList ( // There is no architectural reason these should be below 4GB, it is pur= ely // for convenience of implementation that we force memory below 4GB. // - CurrentTableList->PageAddress =3D 0xFFFFFFFF; - CurrentTableList->NumberOfPages =3D EFI_SIZE_TO_PAGES (CurrentTableSize); + AllocPhysAddress =3D 0xFFFFFFFF; + CurrentTableList->TableSize =3D CurrentTableSize; + CurrentTableList->PoolAllocation =3D FALSE; =20 // // Allocation memory type depends on the type of the table @@ -518,9 +540,21 @@ AddTableToList ( Status =3D gBS->AllocatePages ( AllocateMaxAddress, EfiACPIMemoryNVS, - CurrentTableList->NumberOfPages, - &CurrentTableList->PageAddress + EFI_SIZE_TO_PAGES (CurrentTableList->TableSize), + &AllocPhysAddress ); + } else if (mAcpiTableAllocType =3D=3D AllocateAnyPages) { + // + // If there is no allocation limit, there is also no need to use page + // based allocations for ACPI tables, which may be wasteful on platfor= ms + // such as AArch64 that allocate multiples of 64 KB + // + Status =3D gBS->AllocatePool ( + EfiACPIReclaimMemory, + CurrentTableList->TableSize, + (VOID **)&CurrentTableList->Table + ); + CurrentTableList->PoolAllocation =3D TRUE; } else { // // All other tables are ACPI reclaim memory, no alignment requirements. @@ -528,9 +562,10 @@ AddTableToList ( Status =3D gBS->AllocatePages ( mAcpiTableAllocType, EfiACPIReclaimMemory, - CurrentTableList->NumberOfPages, - &CurrentTableList->PageAddress + EFI_SIZE_TO_PAGES (CurrentTableList->TableSize), + &AllocPhysAddress ); + CurrentTableList->Table =3D (EFI_ACPI_COMMON_HEADER *)(UINTN)AllocPhys= Address; } // // Check return value from memory alloc. @@ -539,10 +574,10 @@ AddTableToList ( gBS->FreePool (CurrentTableList); return EFI_OUT_OF_RESOURCES; } - // - // Update the table pointer with the allocated memory start - // - CurrentTableList->Table =3D (EFI_ACPI_COMMON_HEADER *) (UINTN) CurrentTa= bleList->PageAddress; + + if (!CurrentTableList->PoolAllocation) { + CurrentTableList->Table =3D (EFI_ACPI_COMMON_HEADER *)(UINTN)AllocPhys= Address; + } =20 // // Initialize the table contents @@ -575,7 +610,7 @@ AddTableToList ( if (((Version & EFI_ACPI_TABLE_VERSION_1_0B) !=3D 0 && AcpiTableInstan= ce->Fadt1 !=3D NULL) || ((Version & ACPI_TABLE_VERSION_GTE_2_0) !=3D 0 && AcpiTableInstan= ce->Fadt3 !=3D NULL) ) { - gBS->FreePages (CurrentTableList->PageAddress, CurrentTableList->Num= berOfPages); + FreeTableMemory (CurrentTableList); gBS->FreePool (CurrentTableList); return EFI_ACCESS_DENIED; } @@ -729,7 +764,7 @@ AddTableToList ( if (((Version & EFI_ACPI_TABLE_VERSION_1_0B) !=3D 0 && AcpiTableInstan= ce->Facs1 !=3D NULL) || ((Version & ACPI_TABLE_VERSION_GTE_2_0) !=3D 0 && AcpiTableInstan= ce->Facs3 !=3D NULL) ) { - gBS->FreePages (CurrentTableList->PageAddress, CurrentTableList->Num= berOfPages); + FreeTableMemory (CurrentTableList); gBS->FreePool (CurrentTableList); return EFI_ACCESS_DENIED; } @@ -813,7 +848,7 @@ AddTableToList ( if (((Version & EFI_ACPI_TABLE_VERSION_1_0B) !=3D 0 && AcpiTableInstan= ce->Dsdt1 !=3D NULL) || ((Version & ACPI_TABLE_VERSION_GTE_2_0) !=3D 0 && AcpiTableInstan= ce->Dsdt3 !=3D NULL) ) { - gBS->FreePages (CurrentTableList->PageAddress, CurrentTableList->Num= berOfPages); + FreeTableMemory (CurrentTableList); gBS->FreePool (CurrentTableList); return EFI_ACCESS_DENIED; } @@ -1449,7 +1484,7 @@ DeleteTable ( // // Free the Table // - gBS->FreePages (Table->PageAddress, Table->NumberOfPages); + FreeTableMemory (Table); RemoveEntryList (&(Table->Link)); gBS->FreePool (Table); } --=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 (#66707): https://edk2.groups.io/g/devel/message/66707 Mute This Topic: https://groups.io/mt/77871630/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- From nobody Thu May 9 23:42:57 2024 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+66708+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+66708+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1603914169; cv=none; d=zohomail.com; s=zohoarc; b=MyA+NH3yUBXM9JZ9UhBbLlslTe8QbWafBvRvDxjYtwe/s5TeuBHiZY0/wY/xemqf8tU5DuES5MLJePsDSVXX8UwCFfjJLjPQAPcOTiV9/SLlAt0cv7UrBaZFkonCwZzT0YJbYicKccLdVZG64akLYLiVKG+aAUDHfAvoqbmBGpU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603914169; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=1eVGYhn6iRVg4Qrdx+G7vjc7H3CAO3zQzxbKogjOacY=; b=CwZvn42/lwkd4AdzpBi5Og+7XwqnNrXdXAttt6x8WlqccgAqp8+cG/dPz3fhSKDYzVENKbf6XTvM/RhRJ6A/VHR1Oj9KR7NDXzjyCbvXIGNrg/Lr6xuNTvPrl3zZCBTQhSaGTWkEiLqTO8OV1f+OiUHOeFYEvSzK5KGw41DwSRg= 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+66708+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 1603914168949643.3129473498066; Wed, 28 Oct 2020 12:42:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FyxbYY1788612xRKvrkzeRh4; Wed, 28 Oct 2020 12:42:48 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.2598.1603914168116783998 for ; Wed, 28 Oct 2020 12:42:48 -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 CA1921BB2; Wed, 28 Oct 2020 12:42:47 -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 B98FB3F68F; Wed, 28 Oct 2020 12:42:45 -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 v2 2/3] MdeModulePkg/AcpiTableDxe: use pool allocation for RSDT/XSDT if possible Date: Wed, 28 Oct 2020 20:42:25 +0100 Message-Id: <20201028194226.21556-3-ard.biesheuvel@arm.com> In-Reply-To: <20201028194226.21556-1-ard.biesheuvel@arm.com> References: <20201028194226.21556-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: 2djIFtxLtVDfcE0MCOkevKKyx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1603914168; bh=zIOBdVN9eUkkLKW+Df0TvP3CCknfsBVvEA5Cxtybht4=; h=Cc:Date:From:Reply-To:Subject:To; b=Fgi/kcPWi/ofFt+6oEmZUnW2oke5so+miqJOpZst5QQ2/Zz8ZkwXzjtEdlfLNjkOZq+ zme+TP9N0XQTS0tP3ZdVSo0DhpcPROQi8x9+y4edA0zPEwCIuWGPQanMc0ruv4n7y5hb+ nlDFxTDSYTGv5DCQhapd2EfTtDMnejmFu5k= 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 Reviewed-by: Liming Gao --- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c | 118 +++++++= +++++-------- 1 file changed, 72 insertions(+), 46 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b= /MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index e85a98aee6bf..3793291a9668 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -355,28 +355,39 @@ 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 + ); + } 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; + if (mAcpiTableAllocType !=3D AllocateAnyPages) { + Pointer =3D (UINT8 *)(UINTN)PageAddress; + } + ZeroMem (Pointer, TotalSize); =20 AcpiTableInstance->Rsdt1 =3D (EFI_ACPI_DESCRIPTION_HEADER *) Pointer; @@ -406,21 +417,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 // @@ -1763,29 +1779,39 @@ 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 + ); + } 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; + if (mAcpiTableAllocType !=3D AllocateAnyPages) { + 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 (#66708): https://edk2.groups.io/g/devel/message/66708 Mute This Topic: https://groups.io/mt/77871633/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- From nobody Thu May 9 23:42:57 2024 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+66709+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+66709+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1603914171; cv=none; d=zohomail.com; s=zohoarc; b=WG4O5QkceZN0IidHG/ordvns0WLxRDqy6ar0/9iO64I/bAFZsrkcGsqb65ISHppOVRScnzTO/t3V6RaEMPb2eIadebGQCVKwjM5V7+nfHclRvum18WTYTOLH5Drfimjtnpdr/tAObk1/WouMEnBO0ervGAML5u91Z20xu1DWGdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603914171; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=2wYGgYvJinu8I7Kr2DeALKp7BeaP8oDSjI+g48nUSdE=; b=SNFxMtfbsitkE+Y4l2yVkNxypueX+fheT4hE8XD0tjunog7pGf7AgQWv26HIDha3PB3GFSPhZDLtJkaRHfxg/tahMRn4uOU0mgbgLmfdMyMjj5hs2oL8mpBNChB4aRa0MQbYtAngxHg+y0AuN7A+2qrlc/6uKGsrW8S7Dmpr8gQ= 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+66709+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 1603914171251625.9987617094722; Wed, 28 Oct 2020 12:42:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id K311YY1788612xZqhbtPRR8m; Wed, 28 Oct 2020 12:42:50 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.2602.1603914170408230078 for ; Wed, 28 Oct 2020 12:42:50 -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 03CED1BC0; Wed, 28 Oct 2020 12:42:50 -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 15FA43F68F; Wed, 28 Oct 2020 12:42:47 -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 v2 3/3] MdeModulePkg/AcpiTableDxe: use pool allocation for RSDP if possible Date: Wed, 28 Oct 2020 20:42:26 +0100 Message-Id: <20201028194226.21556-4-ard.biesheuvel@arm.com> In-Reply-To: <20201028194226.21556-1-ard.biesheuvel@arm.com> References: <20201028194226.21556-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: ATxW2ToBxGs7NiQnZc9o1E07x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1603914170; bh=vcLj0i64HQWt9w0QfhcddK+EeuvFhljOD+cHwrxcFp0=; h=Cc:Date:From:Reply-To:Subject:To; b=RI9pBoRCecvD4tq+qmEcMojvwGSDMQdFTlp9TNGZJn9+jqifRkANys7XgvQkZLm5Xbp YI1KDPqSVkxj5cN/R5LPOzws8OkNCLCGr8/MlrP5y58+zb+pS1jysj0CC0j1hOt6Rf2zN Iqi+L0YGfmx6hfEiexN5z7DeDxSbC4sQ1ig= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Liming Gao --- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c | 33 ++++++++= ++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b= /MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index 3793291a9668..edd7f9afd4fc 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -1745,19 +1745,29 @@ AcpiTableAcpiTableConstructor ( RsdpTableSize +=3D sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTE= R); } =20 - PageAddress =3D 0xFFFFFFFF; - Status =3D gBS->AllocatePages ( - mAcpiTableAllocType, - EfiACPIReclaimMemory, - EFI_SIZE_TO_PAGES (RsdpTableSize), - &PageAddress - ); + if (mAcpiTableAllocType !=3D AllocateAnyPages) { + PageAddress =3D 0xFFFFFFFF; + Status =3D gBS->AllocatePages ( + mAcpiTableAllocType, + EfiACPIReclaimMemory, + EFI_SIZE_TO_PAGES (RsdpTableSize), + &PageAddress + ); + } else { + Status =3D gBS->AllocatePool ( + EfiACPIReclaimMemory, + RsdpTableSize, + (VOID **)&Pointer + ); + } =20 if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } =20 - Pointer =3D (UINT8 *) (UINTN) PageAddress; + if (mAcpiTableAllocType !=3D AllocateAnyPages) { + Pointer =3D (UINT8 *)(UINTN)PageAddress; + } ZeroMem (Pointer, RsdpTableSize); =20 AcpiTableInstance->Rsdp1 =3D (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINT= ER *) Pointer; @@ -1805,7 +1815,12 @@ AcpiTableAcpiTableConstructor ( } =20 if (EFI_ERROR (Status)) { - gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1,= EFI_SIZE_TO_PAGES (RsdpTableSize)); + if (mAcpiTableAllocType !=3D AllocateAnyPages) { + gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp= 1, + EFI_SIZE_TO_PAGES (RsdpTableSize)); + } else { + gBS->FreePool (AcpiTableInstance->Rsdp1); + } return EFI_OUT_OF_RESOURCES; } =20 --=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 (#66709): https://edk2.groups.io/g/devel/message/66709 Mute This Topic: https://groups.io/mt/77871634/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-