From patchwork Thu Mar 2 14:32:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 94783 Delivered-To: patch@linaro.org Received: by 10.140.82.71 with SMTP id g65csp188198qgd; Thu, 2 Mar 2017 06:32:26 -0800 (PST) X-Received: by 10.84.232.134 with SMTP id i6mr19282326plk.101.1488465145943; Thu, 02 Mar 2017 06:32:25 -0800 (PST) Return-Path: Received: from ml01.01.org (ml01.01.org. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id j185si7592342pge.68.2017.03.02.06.32.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Mar 2017 06:32:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; 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 2001:19d0:306:5::1 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 5242F821DD; Thu, 2 Mar 2017 06:32:25 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wr0-x231.google.com (mail-wr0-x231.google.com [IPv6:2a00:1450:400c:c0c::231]) (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 089B5821DD for ; Thu, 2 Mar 2017 06:32:24 -0800 (PST) Received: by mail-wr0-x231.google.com with SMTP id u48so53531123wrc.0 for ; Thu, 02 Mar 2017 06:32:23 -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=JP83N4GCgnzTZTmDssYP9Rli75ZaKo7z8jpEgZQlzyo=; b=RUK96lCnTM2xLLK3XKspAoMX/M9A2QC69DcFDmEr8kjVYTF4EEeypHBFjz3Ma8w6nA nftZRxrN29HtvvbVuG3IXeX6mBvCh6ZvobFgbA2AwZwd5AfOhcEz1fT+5DWYgn/DZYbe BH03M6ee5SSAV9aGEg5Ic81i5iKG/g9i0aU90= 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=JP83N4GCgnzTZTmDssYP9Rli75ZaKo7z8jpEgZQlzyo=; b=ALYCGUEccx5gfZHZd010mat505IvPN5os3zWzaGsudp+waCRwFFK8PQDj+Sv6NzJBO MBv1CccC45wN+z+Tmnu4QV7lBxthxUadwrlCuS0ED052nyUzRYWrA9ZJur4HQS0fZDe6 QycIB8whILx3yP9GoXY/2nbNDUuEoK3yiOGV1911PXc8D7IArfxXIq+1IibtRh9RgLfv JuwJoseTXsxnEJvMhemv1aU9sxyk86vOUn81g4CeNmsPHbUmhjGOhh8ShRPzwuVc6upV hXx+ODXcDgm+5KqwDhwKip6siD2p40PKmnfuoo8mWkxkTYXNloji0IKBIwN+QynxATaU Lu0g== X-Gm-Message-State: AMke39lXbdOxyP4KroA7+VfkuXFypi9XdW2rKzFay/aeWjMJqavziZC5tioXK9rKugMNDdC0 X-Received: by 10.223.136.82 with SMTP id e18mr12644976wre.28.1488465142523; Thu, 02 Mar 2017 06:32:22 -0800 (PST) Received: from localhost.localdomain ([105.147.1.203]) by smtp.gmail.com with ESMTPSA id m83sm27245859wmc.33.2017.03.02.06.32.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Mar 2017 06:32:21 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, liming.gao@intel.com Date: Thu, 2 Mar 2017 14:32:16 +0000 Message-Id: <1488465136-9905-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [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: , 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 | 20 ++++++++++++++++---- MdeModulePkg/Core/Pei/PeiMain.h | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Signed-off-by: Ard Biesheuvel diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/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; if ((MemoryType != EfiLoaderCode) && (MemoryType != EfiLoaderData) && @@ -153,6 +154,16 @@ PeiAllocatePages ( return EFI_INVALID_PARAMETER; } + Granularity = DEFAULT_PAGE_ALLOCATION_GRANULARITY; + + if (MemoryType == EfiACPIReclaimMemory || + MemoryType == EfiACPIMemoryNVS || + MemoryType == EfiRuntimeServicesCode || + MemoryType == EfiRuntimeServicesData) { + + Granularity = RUNTIME_PAGE_ALLOCATION_GRANULARITY; + } + PrivateData = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); Hob.Raw = PrivateData->HobList.Raw; @@ -176,9 +187,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. @@ -200,7 +212,7 @@ PeiAllocatePages ( // // Update the PHIT to reflect the memory usage // - *(FreeMemoryTop) -= Pages * EFI_PAGE_SIZE; + *(FreeMemoryTop) -= ALIGN_VALUE (Pages * EFI_PAGE_SIZE, Granularity); // // 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 ); 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 ///