From patchwork Fri Jul 1 15:43:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 71318 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp367478qgy; Fri, 1 Jul 2016 08:44:16 -0700 (PDT) X-Received: by 10.98.53.6 with SMTP id c6mr32704034pfa.47.1467387856122; Fri, 01 Jul 2016 08:44:16 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id m125si1860646pfm.117.2016.07.01.08.44.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2016 08:44:16 -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 023311A1E3B; Fri, 1 Jul 2016 08:44:51 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com [IPv6:2a00:1450:400c:c09::22d]) (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 E5CB91A1E34 for ; Fri, 1 Jul 2016 08:44:48 -0700 (PDT) Received: by mail-wm0-x22d.google.com with SMTP id r201so34648551wme.1 for ; Fri, 01 Jul 2016 08:44:11 -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=s8NImZZa8WbtN9MoZKee6PxhO/NvldYwJbHBwf99ytg=; b=Hnb16D4x3EQxuameGFXS9I+BQyNY2OQagIDQAK1ZijVBK2yjouOTze9CngOwrd2Gq0 FmHrPfE4k8D7gmIAqhJbgyHnKacsw4XTNkB4qQ9GebiiQ5Uj82ZJI0SxwZP1ewxaNKUV PrDv1/DGJ6mr78HDYtPb4VzVu5EDypDUH+Rwg= 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=s8NImZZa8WbtN9MoZKee6PxhO/NvldYwJbHBwf99ytg=; b=P+5wLpvVTugF9eSJBiqwSroc6NaM0x/A3+9INLx0buNpwUSyOEV8g05+TAGilVQAZx i885VzGFOrO7qMu5c0uk902aTiaJ1zgC9X3tWXUQmhZ4ywDCOZgg/rAeqs+YHjuE7tHi bxdI1zjjEXhsv7N8KQWw+1ALc+B8YI985XqIIlnKHHEtddadJvEzbwjvhmH7SnqJBbsu SnjZ/QEXNBp/1jRC2RoJKxaeNV/Gv1R2x4PCmblLOBQF/FvaE+4o1vURLqDbIX2oiaQm OZSTF9miHXR1nHCKmmRntDHts7pT04CXlgRTPrfpTU+iJ799Ve3QCghOW5q0EYr7eXNS icyg== X-Gm-Message-State: ALyK8tIJjjD6IyNw9zh3IOEv8UrzFH9uJVA6zzHfSYKQoZ5JYl/DFFJ64o8XuhduFvSn/XnQ X-Received: by 10.28.101.134 with SMTP id z128mr187195wmb.71.1467387850420; Fri, 01 Jul 2016 08:44:10 -0700 (PDT) Received: from localhost.localdomain ([188.203.148.129]) by smtp.gmail.com with ESMTPSA id l1sm6678056wjy.17.2016.07.01.08.44.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 Jul 2016 08:44:09 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, lersek@redhat.com Date: Fri, 1 Jul 2016 17:43:56 +0200 Message-Id: <1467387836-3419-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1467387836-3419-1-git-send-email-ard.biesheuvel@linaro.org> References: <1467387836-3419-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 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: 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 | 61 ++++++++++++++++++++ ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf | 36 ++++++++++++ 2 files changed, 97 insertions(+) -- 2.7.4 _______________________________________________ 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..d370b507a807 --- /dev/null +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c @@ -0,0 +1,61 @@ +#/* @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 firmware image + // can be assumed to be clean to the PoC when running XIP, even when PEI + // is executing from DRAM, we only need to perform the cache maintenance + // 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