From patchwork Thu Jun 16 10:29:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 70169 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp185383qgy; Thu, 16 Jun 2016 03:29:46 -0700 (PDT) X-Received: by 10.107.134.140 with SMTP id q12mr6369338ioi.25.1466072986408; Thu, 16 Jun 2016 03:29:46 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id b21si5397731pfk.45.2016.06.16.03.29.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jun 2016 03:29:46 -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 13DA51A1E40; Thu, 16 Jun 2016 03:30:09 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x236.google.com (mail-wm0-x236.google.com [IPv6:2a00:1450:400c:c09::236]) (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 720201A1E44 for ; Thu, 16 Jun 2016 03:30:07 -0700 (PDT) Received: by mail-wm0-x236.google.com with SMTP id a66so51094076wme.0 for ; Thu, 16 Jun 2016 03:29:41 -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:in-reply-to:references; bh=DGg/6qGCW0bf4QI7z5nt1VjTFsJTpdEmvmN8s37So6Q=; b=eQp/I1kf5LHU9uaB6ZjMM2ZpyUWzFEZsIeyYQc7+pZZEyAOs0pGa3REew2vk1OLZl7 rc/O1+Ntx/S6vudNH+xqOHdK4LtPT7zGxXg3f+6xpjUjRMIoQIJ8DU/ZP93f3EvB4COT mW4j5Mhg1+mqIYT7f9gP6OGTJTSoxUFpksy0Q= 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:in-reply-to :references; bh=DGg/6qGCW0bf4QI7z5nt1VjTFsJTpdEmvmN8s37So6Q=; b=GmpXjqHlFL0tBrAgv9ou/AxznRA+psLCzM1hIFWp1MqZu0cUZ/k6H8JJ58GnC7kVI3 znHJT32zNzu/NmTo4122KpFUR9mBaPUoAimdm/ISOH4wH7WBxTDtZPrV6EDmn0BtdK3R fBQZvGURBOLztnNQbQxCgx34S8IMKAtANEzDsikuiMs55MwpTRDhrYKLmgvbQucbDb6T r3GyQ8pz3WA1lAUueCQr8TnSt/2Wt7YO3YGQo0JXWzlEBdBTwjSplb+OD/CV90qWcr9R PNLQr8ti0lAJt/FEufnlPMTJ41Kj81zKrw1d/8sLwyBxDimhqHWKWnyDLw6vGaKSyXCb FW3Q== X-Gm-Message-State: ALyK8tJX32bkHRBP6jePzC98usIZu11tmRGbtOdXfkXfx78ioMiZHfp6rkU4tdvkm9R6aqhx X-Received: by 10.194.203.226 with SMTP id kt2mr279754wjc.75.1466072978113; Thu, 16 Jun 2016 03:29:38 -0700 (PDT) Received: from ards-macbook-pro.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id b200sm14163486wmb.9.2016.06.16.03.29.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Jun 2016 03:29:37 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, lersek@redhat.com Date: Thu, 16 Jun 2016 12:29:30 +0200 Message-Id: <1466072970-5318-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1466072970-5318-1-git-send-email-ard.biesheuvel@linaro.org> References: <1466072970-5318-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH 4/4] ArmPkg/ArmMmuLib: add PEI specific version of ArmMmuLib 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: heyi.guo@linaro.org, feng.tian@intel.com, star.zeng@intel.com, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" This introduces a special version of ArmMmuLib for PEIMs that takes care only to perform cache maintenance on the live entry replacement routine if the module is not executing in place. Not only is such cache maintenance unnecessary in that case, it may be actively harmful on some systems that fail to tolerate cache maintenance operations on NOR flash regions. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c | 60 ++++++++++++++++++++ ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf | 36 ++++++++++++ 2 files changed, 96 insertions(+) -- 1.9.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c new file mode 100644 index 000000000000..91dc1157e79a --- /dev/null +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c @@ -0,0 +1,60 @@ +#/* @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 +#include + +EFI_STATUS +EFIAPI +ArmMmuPeiLibConstructor ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + extern UINT32 ArmReplaceLiveTranslationEntrySize; + + EFI_FV_FILE_INFO FileInfo; + EFI_STATUS Status; + + 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, "ArmMmuLib: skipping cache maintenance on XIP PEIM\n")); + } else { + DEBUG ((EFI_D_INFO, "ArmMmuLib: performing cache maintenance 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; +} diff --git a/ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf b/ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf new file mode 100644 index 000000000000..14ebf8de673d --- /dev/null +++ b/ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf @@ -0,0 +1,36 @@ +#/** @file +# +# Copyright (c) 2016 Linaro Ltd. 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 = ArmMmuPeiLib + FILE_GUID = b50d8d53-1ad1-44ea-9e69-8c89d4a6d08b + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmMmuLib|PEIM + CONSTRUCTOR = ArmMmuPeiLibConstructor + +[Sources.AARCH64] + AArch64/ArmMmuLibCore.c + AArch64/ArmMmuPeiLibConstructor.c + AArch64/ArmMmuLibReplaceEntry.S + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmLib + CacheMaintenanceLib + MemoryAllocationLib