From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3BF058220F for ; Thu, 2 Mar 2017 21:08:10 -0800 (PST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2017 21:08:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,235,1484035200"; d="scan'208";a="55329003" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga002.jf.intel.com with ESMTP; 02 Mar 2017 21:08:09 -0800 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 2 Mar 2017 21:08:09 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.248.2; Thu, 2 Mar 2017 21:08:09 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.204]) with mapi id 14.03.0248.002; Fri, 3 Mar 2017 13:08:05 +0800 From: "Zeng, Star" To: Ard Biesheuvel , "edk2-devel@lists.01.org" , "Gao, Liming" CC: "Zeng, Star" Thread-Topic: [edk2] [PATCH] MdeModulePkg/PeiCore: honour minimal runtime allocation granularity Thread-Index: AQHSk2HY7SosRY0kJkKd3MmEVyoCt6GCkC1w Date: Fri, 3 Mar 2017 05:08:05 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B82E6FF@shsmsx102.ccr.corp.intel.com> References: <1488465136-9905-1-git-send-email-ard.biesheuvel@linaro.org> In-Reply-To: <1488465136-9905-1-git-send-email-ard.biesheuvel@linaro.org> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdeModulePkg/PeiCore: honour minimal runtime allocation granularity X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2017 05:08:10 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ard, The code line below also needs to be considered. if (RemainingPages < Pages) { The Pages needs to be converted to granularity aligned before the if statem= ent, like the code below in DXE phase. NumberOfPages +=3D EFI_SIZE_TO_PAGES (Alignment) - 1; NumberOfPages &=3D ~(EFI_SIZE_TO_PAGES (Alignment) - 1); Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ard = Biesheuvel Sent: Thursday, March 2, 2017 10:32 PM To: edk2-devel@lists.01.org; Gao, Liming Cc: Ard Biesheuvel Subject: [edk2] [PATCH] MdeModulePkg/PeiCore: honour minimal runtime alloca= tion granularity Architectures such as AArch64 may run the OS with 16 KB or 64 KB sized page= s, and for this reason, the UEFI spec mandates a minimal allocation granula= rity of 64 KB for regions that may require different memory attributes at O= S runtime. So make PeiCore's implementation of AllocatePages () take this into account= as well. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 20 ++++++++++++++++---- MdeModulePkg/Core/Pei/PeiMain.h | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/C= ore/Pei/Memory/MemoryServices.c index 4efe14313ca5..201904e415b9 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -140,6 +140,7 @@ PeiAllocatePages ( EFI_PHYSICAL_ADDRESS *FreeMemoryTop; EFI_PHYSICAL_ADDRESS *FreeMemoryBottom; UINTN RemainingPages; + UINTN Granularity; =20 if ((MemoryType !=3D EfiLoaderCode) && (MemoryType !=3D EfiLoaderData) && @@ -153,6 +154,16 @@ PeiAllocatePages ( return EFI_INVALID_PARAMETER; } =20 + Granularity =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (MemoryType =3D=3D EfiACPIReclaimMemory || + MemoryType =3D=3D EfiACPIMemoryNVS || + MemoryType =3D=3D EfiRuntimeServicesCode || + MemoryType =3D=3D EfiRuntimeServicesData) { + + Granularity =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + PrivateData =3D PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); Hob.Raw =3D PrivateData->HobList.Raw; =20 @@ -176,9 +187,10 @@ PeiAllocatePages ( } =20 // - // Check to see if on 4k boundary, If not aligned, make the allocation a= ligned. + // Check to see if on correct boundary for the memory type. + // If not aligned, make the allocation aligned. // - *(FreeMemoryTop) -=3D *(FreeMemoryTop) & 0xFFF; + *(FreeMemoryTop) -=3D *(FreeMemoryTop) & (Granularity - 1); =20 // // Verify that there is sufficient memory to satisfy the allocation. @@ -200,7 +212,7 @@ PeiAllocatePages ( // // Update the PHIT to reflect the memory usage // - *(FreeMemoryTop) -=3D Pages * EFI_PAGE_SIZE; + *(FreeMemoryTop) -=3D ALIGN_VALUE (Pages * EFI_PAGE_SIZE,=20 + Granularity); =20 // // Update the value for the caller @@ -212,7 +224,7 @@ PeiAllocatePages ( // BuildMemoryAllocationHob ( *(FreeMemoryTop), - Pages * EFI_PAGE_SIZE, + ALIGN_VALUE (Pages * EFI_PAGE_SIZE, Granularity), MemoryType ); =20 diff --git a/MdeModulePkg/Core/Pei/PeiMain.h b/MdeModulePkg/Core/Pei/PeiMai= n.h index 69eea514920b..e8358d3c4e6d 100644 --- a/MdeModulePkg/Core/Pei/PeiMain.h +++ b/MdeModulePkg/Core/Pei/PeiMain.h @@ -55,6 +55,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHE= R EXPRESS OR IMPLIED. /// #define PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE 0xff =20 +#if defined (MDE_CPU_AARCH64) +/// +/// 64-bit ARM systems allow the OS to execute with 64 KB page size,=20 +/// so for improved interoperability with the firmware, align the ///=20 +runtime regions to 64 KB as well /// +#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (SIZE_64KB) +#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (EFI_PAGE_SIZE) + +#else +/// +/// For generic EFI machines make the default allocations 4K aligned=20 +/// +#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (EFI_PAGE_SIZE) +#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (EFI_PAGE_SIZE) + +#endif + /// /// Pei Core private data structures /// -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel