From patchwork Mon Jun 13 15:26:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 69893 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp1599908qgf; Mon, 13 Jun 2016 08:26:19 -0700 (PDT) X-Received: by 10.36.54.200 with SMTP id l191mr18075368itl.79.1465831579317; Mon, 13 Jun 2016 08:26:19 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id o10si18358564paw.103.2016.06.13.08.26.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jun 2016 08:26:19 -0700 (PDT) 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 dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B94D91A1DF0; Mon, 13 Jun 2016 08:26:42 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x233.google.com (mail-wm0-x233.google.com [IPv6:2a00:1450:400c:c09::233]) (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 231CE1A1DEE for ; Mon, 13 Jun 2016 08:26:41 -0700 (PDT) Received: by mail-wm0-x233.google.com with SMTP id k184so16290440wme.1 for ; Mon, 13 Jun 2016 08:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=qXCiayY0PprcW51X7UcBLcAqiZfsG06NRf5J/Aqs1Wc=; b=UPu3NSTXZ9RmfHNi5SAtjJ+eongNqHr+Cin4lvhmAMAqk0TOkcIDU/KInYiwiNGS6s 0lzGSTzYdkuSC7/inx/ijF5+twHPMRkD1BX6Ei3KPOnjBInY+ge5dICgWRO6NrE3ZvSd eHfMuxsH86N8xtInQmrNBYkscknfsVI2Wv+Xk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=qXCiayY0PprcW51X7UcBLcAqiZfsG06NRf5J/Aqs1Wc=; b=Ej9D/FYm9oh9W9gBu1wM/OwYvQpy4S+Wey4ffV5ge6ZHHNITWs0j7/hZ8UEhrfx7nW wHOVHmYoaV1Vm7LZlIbGA5XpLo+Cd1t0JNOyg65mUJMQPjKhTr+M93fdKejsVfPW7EjY b350+/GkL5/eKxEe2cqix5XYa41SC7ryPkKGwRTC+Q8auvWdLXNM+tZ7CBjUd5VnzDzB 8ZkiRADCR26VEJ6bglUCLot21wFqHeUMDE+4TiIY+fEaRHwDtn3GYLj/YMOqJDXeBOm3 O10ce7Yip9J16x3UcQJ6ipD1tCgZqBjRTXAKp2CRAcny8TU07yp9ZH94VbvW2wZaaMKA ivZQ== X-Gm-Message-State: ALyK8tIPckUGIvcd2ifouaTiagxvQYUoUISY4k78iPfJ5jHln3TSLubG97NfBiMuBN2nmZTi X-Received: by 10.28.68.85 with SMTP id r82mr188911wma.18.1465831575286; Mon, 13 Jun 2016 08:26:15 -0700 (PDT) Received: from ards-macbook-pro.lan (ip503c5505.speed.planet.nl. [80.60.85.5]) by smtp.gmail.com with ESMTPSA id kc2sm28131148wjb.5.2016.06.13.08.26.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Jun 2016 08:26:14 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, heyi.guo@Linaro.org, leif.lindholm@linaro.org Date: Mon, 13 Jun 2016 17:26:07 +0200 Message-Id: <1465831567-10819-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 Subject: [edk2] [PATCH v2] ArmPkg/ArmLib: avoid cache maintenance in PEIMs when executing in place X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" On some platforms, performing cache maintenance on regions that are backed by NOR flash result in SErrors. Since cache maintenance is unnecessary in that case, create a PEIM specific version that only performs said cache maintenance in its constructor if the module is shadowed in RAM. To avoid performing the cache maintenance if the MMU code is not used to begin with, check that explicitly in the constructor. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- As discussed in the thread dedicated to this subject, the preferred way of addressing this to split off the MMU manipulation code from ArmLib into a separate ArmMmuLib, but this affects other packages and platforms. So in the mean time, let's merge this patch so that D02 can use the upstream ArmLib unmodified. ArmPkg/Library/ArmLib/AArch64/{AArch64LibConstructor.c => AArch64BaseLibConstructor.c} | 0 ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf | 2 +- ArmPkg/Library/ArmLib/AArch64/AArch64LibPei.inf | 43 +++++++++++ ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c | 2 + ArmPkg/Library/ArmLib/AArch64/AArch64PeiLibConstructor.c | 75 ++++++++++++++++++++ 5 files changed, 121 insertions(+), 1 deletion(-) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel Tested-by: Heyi Guo Reviewed-by: Leif Lindholm diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64LibConstructor.c b/ArmPkg/Library/ArmLib/AArch64/AArch64BaseLibConstructor.c similarity index 100% rename from ArmPkg/Library/ArmLib/AArch64/AArch64LibConstructor.c rename to ArmPkg/Library/ArmLib/AArch64/AArch64BaseLibConstructor.c diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf index 58684e8492f2..ef9d261b910d 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Lib.inf @@ -32,7 +32,7 @@ [Sources.AARCH64] ../Common/AArch64/ArmLibSupport.S ../Common/ArmLib.c - AArch64LibConstructor.c + AArch64BaseLibConstructor.c [Packages] ArmPkg/ArmPkg.dec diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64LibPei.inf b/ArmPkg/Library/ArmLib/AArch64/AArch64LibPei.inf new file mode 100644 index 000000000000..c8f0b97750d4 --- /dev/null +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64LibPei.inf @@ -0,0 +1,43 @@ +#/** @file +# +# Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.
+# Portions copyright (c) 2011 - 2014, ARM Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = AArch64Lib + FILE_GUID = ef20ddf5-b334-47b3-94cf-52ff44c29138 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmLib|PEIM PEI_CORE + CONSTRUCTOR = AArch64LibConstructor + +[Sources.AARCH64] + AArch64Lib.c + AArch64Mmu.c + AArch64ArchTimer.c + ArmLibSupportV8.S + AArch64Support.S + AArch64ArchTimerSupport.S + + ../Common/AArch64/ArmLibSupport.S + ../Common/ArmLib.c + AArch64PeiLibConstructor.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + MemoryAllocationLib + CacheMaintenanceLib diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c index cf9b7222b47b..07864bac28e6 100644 --- a/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64Mmu.c @@ -26,6 +26,8 @@ // We use this index definition to define an invalid block entry #define TT_ATTR_INDX_INVALID ((UINT32)~0) +INT32 HaveMmuRoutines = 1; + STATIC UINT64 ArmMemoryAttributeToPageAttribute ( diff --git a/ArmPkg/Library/ArmLib/AArch64/AArch64PeiLibConstructor.c b/ArmPkg/Library/ArmLib/AArch64/AArch64PeiLibConstructor.c new file mode 100644 index 000000000000..2de9c7c54ed9 --- /dev/null +++ b/ArmPkg/Library/ArmLib/AArch64/AArch64PeiLibConstructor.c @@ -0,0 +1,75 @@ +#/* @file +# +# Copyright (c) 2016, Linaro Limited. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/ + +#include + +#include +#include +#include + +// +// This is a hack. We define a weak symbol with external linkage, which may or +// may not be overridden by a non-weak alternative that is defined with a non +// zero value in the object that contains the MMU routines. Since static +// libraries are pulled in on a per-object basis, and since the MMU object will +// only be pulled in if any of its other symbols are referenced by the client +// module, we can use the value below to figure out whether the MMU routines are +// in use by this module, and decide whether cache maintenance of the function +// ArmReplaceLiveTranslationEntry () is required. +// +INT32 __attribute__((weak)) HaveMmuRoutines; + +EFI_STATUS +EFIAPI +AArch64LibConstructor ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + extern UINT32 ArmReplaceLiveTranslationEntrySize; + + EFI_FV_FILE_INFO FileInfo; + EFI_STATUS Status; + + if (HaveMmuRoutines == 0) { + return RETURN_SUCCESS; + } + + ASSERT (FileHandle != NULL); + + Status = (*PeiServices)->FfsGetFileInfo (FileHandle, &FileInfo); + ASSERT_EFI_ERROR (Status); + + // + // Some platforms do not cope very well with cache maintenance being + // performed on regions backed by NOR flash. Since the cache maintenance + // is unnecessary to begin with in that case, perform it only when not + // executing in place. + // + if ((UINTN)FileInfo.Buffer <= (UINTN)ArmReplaceLiveTranslationEntry && + ((UINTN)FileInfo.Buffer + FileInfo.BufferSize >= + (UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize)) { + DEBUG ((EFI_D_INFO, "ArmLib: skipping cache maintence on XIP PEIM\n")); + } else { + DEBUG ((EFI_D_INFO, "ArmLib: performing cache maintence on shadowed PEIM\n")); + // + // The ArmReplaceLiveTranslationEntry () helper function may be invoked + // with the MMU off so we have to ensure that it gets cleaned to the PoC + // + WriteBackDataCacheRange (ArmReplaceLiveTranslationEntry, + ArmReplaceLiveTranslationEntrySize); + } + + return RETURN_SUCCESS; +}