From patchwork Fri Mar 3 08:37:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 94822 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp120217qgd; Fri, 3 Mar 2017 00:37:51 -0800 (PST) X-Received: by 10.84.134.228 with SMTP id 91mr2550130plh.116.1488530271100; Fri, 03 Mar 2017 00:37:51 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id y1si9927114pli.222.2017.03.03.00.37.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Mar 2017 00:37:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A1619821F3; Fri, 3 Mar 2017 00:37:50 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x230.google.com (mail-wm0-x230.google.com [IPv6:2a00:1450:400c:c09::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9DBDB821F0 for ; Fri, 3 Mar 2017 00:37:49 -0800 (PST) Received: by mail-wm0-x230.google.com with SMTP id i17so6831095wmf.0 for ; Fri, 03 Mar 2017 00:37:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=ZqvoPXTmruCSbsXW84jtRzHM3bemCpv3eMse8/+SIEU=; b=XxiW1Jn+IlZeGqyiWIZlEbv/g+26HKj1ZBKKEn4I6iqTFf+zyW4c+xpwCGZebxV2J/ ZHY+uSAgTWJi0l6JvDpTF22SbDCnRymBrbt1a35MdVWldbvHGT+17pbbhLym6aYWLfFl CVfVNWB2DxlUoaFLuJidulzJULvwjFAOBPo9Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ZqvoPXTmruCSbsXW84jtRzHM3bemCpv3eMse8/+SIEU=; b=gABOfa5rUPa7RQJ3x7IRi+jyTuYSb6FCtje2dGgm2DSlpagAYiwp3oB+hI3EtLcKgx gkoiJD/cJzmh14NAB+PMgvnhLIOMgF+KMG4gs6Mlq66hyf7f6TeC32sAD/xEG68AghQH 1H5BRHPFQg+xLR0XDal3Y0YcyBiRjb26s//+AVawuSdILTExbFMq4HIXM+WAtxYW/HMl sfLeg518onUasp13aIpCzSAzpbNE5/aCmVm28vEuZD3H0a3FwNyyniJk2fY7Qpje0Y45 3ch6saBYq/HuOxL34uVuWo55+0ukujlqs5WFysJGQsU+zKkk0ZdkdCb1gX0hEqTY2QEK +SYg== X-Gm-Message-State: AMke39lS1qPg7a6rU19IYsjQE/YyHxz5nsFB+faIjGReT3ybLOWiI+whLupNGz1yVRh8zrxw X-Received: by 10.28.31.139 with SMTP id f133mr1917436wmf.25.1488530267792; Fri, 03 Mar 2017 00:37:47 -0800 (PST) Received: from localhost.localdomain ([105.147.1.203]) by smtp.gmail.com with ESMTPSA id 94sm14230292wrl.50.2017.03.03.00.37.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Mar 2017 00:37:47 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, liming.gao@intel.com, star.zeng@intel.com Date: Fri, 3 Mar 2017 08:37:43 +0000 Message-Id: <1488530263-22906-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [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: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" 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(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel 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 != EfiLoaderCode) && (MemoryType != EfiLoaderData) && @@ -153,6 +154,20 @@ PeiAllocatePages ( return EFI_INVALID_PARAMETER; } + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (RUNTIME_PAGE_ALLOCATION_GRANULARITY > DEFAULT_PAGE_ALLOCATION_GRANULARITY && + (MemoryType == EfiACPIReclaimMemory || + MemoryType == EfiACPIMemoryNVS || + MemoryType == EfiRuntimeServicesCode || + MemoryType == EfiRuntimeServicesData)) { + + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + + DEBUG ((DEBUG_INFO, "AllocatePages: rounding up allocation to %d KB\n", + Granularity)); + } + PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); Hob.Raw = 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) -= *(FreeMemoryTop) & 0xFFF; + *(FreeMemoryTop) -= *(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 that of the request pages. // + Pages = 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 ///