From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 19397821FA for ; Fri, 3 Mar 2017 01:06:08 -0800 (PST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Mar 2017 01:05:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,236,1484035200"; d="scan'208";a="71746723" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga005.fm.intel.com with ESMTP; 03 Mar 2017 01:05:54 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 3 Mar 2017 01:05:53 -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 17:05:50 +0800 From: "Gao, Liming" To: Ard Biesheuvel , "edk2-devel@lists.01.org" , "Zeng, Star" Thread-Topic: [edk2] [PATCH v2] MdeModulePkg/PeiCore: honour minimal runtime allocation granularity Thread-Index: AQHSk/mC0ayelJWZfkKfsWEISL342qGCzZZw Date: Fri, 3 Mar 2017 09:05:49 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14D6E7A69@shsmsx102.ccr.corp.intel.com> References: <1488530263-22906-1-git-send-email-ard.biesheuvel@linaro.org> In-Reply-To: <1488530263-22906-1-git-send-email-ard.biesheuvel@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2] 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 09:06:08 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ard: First is to make FreeMemoryTop at the expected alignment. If original Fre= eMemoryTop is not aligned, it will be adjusted to be align. Then, there is = one memory hole that can't be used any more. I suggest to create BuildMemor= yAllocationHob() with EfiConventionalMemory to describe this hole. Now, Md= ePkg\Library\PeiMemoryAllocationLib AllocateAlignedPages() uses this way to= describe extra memory space.=20 Thanks Liming >-----Original Message----- >From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ard >Biesheuvel >Sent: Friday, March 03, 2017 4:38 PM >To: edk2-devel@lists.01.org; Gao, Liming ; Zeng, Sta= r > >Cc: Ard Biesheuvel >Subject: [edk2] [PATCH v2] MdeModulePkg/PeiCore: honour minimal runtime >allocation granularity > >Architectures such as AArch64 may run the OS with 16 KB or 64 KB sized >pages, and for this reason, the UEFI spec mandates a minimal allocation >granularity of 64 KB for regions that may require different memory >attributes at OS 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 | 21 >++++++++++++++++++-- > MdeModulePkg/Core/Pei/PeiMain.h | 18 +++++++++++++++++ > 2 files changed, 37 insertions(+), 2 deletions(-) > >diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c >b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c >index 4efe14313ca5..cc78ca2a1625 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; > > if ((MemoryType !=3D EfiLoaderCode) && > (MemoryType !=3D EfiLoaderData) && >@@ -153,6 +154,20 @@ PeiAllocatePages ( > return EFI_INVALID_PARAMETER; > } > >+ Granularity =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; >+ >+ if (RUNTIME_PAGE_ALLOCATION_GRANULARITY > >DEFAULT_PAGE_ALLOCATION_GRANULARITY && >+ (MemoryType =3D=3D EfiACPIReclaimMemory || >+ MemoryType =3D=3D EfiACPIMemoryNVS || >+ MemoryType =3D=3D EfiRuntimeServicesCode || >+ MemoryType =3D=3D EfiRuntimeServicesData)) { >+ >+ Granularity =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; >+ >+ DEBUG ((DEBUG_INFO, "AllocatePages: rounding up allocation to %d >KB\n", >+ Granularity)); >+ } >+ > PrivateData =3D PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); > Hob.Raw =3D PrivateData->HobList.Raw; > >@@ -176,9 +191,10 @@ PeiAllocatePages ( > } > > // >- // Check to see if on 4k boundary, If not aligned, make the allocation = aligned. >+ // 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); > > // > // Verify that there is sufficient memory to satisfy the allocation. >@@ -192,6 +208,7 @@ PeiAllocatePages ( > // > // The number of remaining pages needs to be greater than or equal to t= hat >of the request pages. > // >+ Pages =3D ALIGN_VALUE (Pages, EFI_SIZE_TO_PAGES (Granularity)); > if (RemainingPages < Pages) { > DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is >available.\n", (UINT64) Pages)); > DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource = to >be allocated.\n", (UINT64) RemainingPages)); >diff --git a/MdeModulePkg/Core/Pei/PeiMain.h >b/MdeModulePkg/Core/Pei/PeiMain.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, EITHER EXPRESS OR IMPLIED. > /// > #define PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE 0xff > >+#if defined (MDE_CPU_AARCH64) >+/// >+/// 64-bit ARM systems allow the OS to execute with 64 KB page size, >+/// so for improved interoperability with the firmware, align the >+/// 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 >+/// >+#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