]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmMmuLib: add PEI specific version of ArmMmuLib
authorArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 16 Jun 2016 10:21:50 +0000 (12:21 +0200)
committerArd Biesheuvel <ard.biesheuvel@linaro.org>
Thu, 7 Jul 2016 12:36:45 +0000 (14:36 +0200)
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 <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c [new file with mode: 0644]
ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf [new file with mode: 0644]

diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuPeiLibConstructor.c
new file mode 100644 (file)
index 0000000..d370b50
--- /dev/null
@@ -0,0 +1,61 @@
+#/* @file\r
+#\r
+#  Copyright (c) 2016, Linaro Limited. All rights reserved.\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution.  The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#*/\r
+\r
+#include <Base.h>\r
+\r
+#include <Library/ArmLib.h>\r
+#include <Library/ArmMmuLib.h>\r
+#include <Library/CacheMaintenanceLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+ArmMmuPeiLibConstructor (\r
+  IN       EFI_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+{\r
+  extern UINT32             ArmReplaceLiveTranslationEntrySize;\r
+\r
+  EFI_FV_FILE_INFO          FileInfo;\r
+  EFI_STATUS                Status;\r
+\r
+  ASSERT (FileHandle != NULL);\r
+\r
+  Status = (*PeiServices)->FfsGetFileInfo (FileHandle, &FileInfo);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Some platforms do not cope very well with cache maintenance being\r
+  // performed on regions backed by NOR flash. Since the firmware image\r
+  // can be assumed to be clean to the PoC when running XIP, even when PEI\r
+  // is executing from DRAM, we only need to perform the cache maintenance\r
+  // when not executing in place.\r
+  //\r
+  if ((UINTN)FileInfo.Buffer <= (UINTN)ArmReplaceLiveTranslationEntry &&\r
+      ((UINTN)FileInfo.Buffer + FileInfo.BufferSize >=\r
+       (UINTN)ArmReplaceLiveTranslationEntry + ArmReplaceLiveTranslationEntrySize)) {\r
+    DEBUG ((EFI_D_INFO, "ArmMmuLib: skipping cache maintenance on XIP PEIM\n"));\r
+  } else {\r
+    DEBUG ((EFI_D_INFO, "ArmMmuLib: performing cache maintenance on shadowed PEIM\n"));\r
+    //\r
+    // The ArmReplaceLiveTranslationEntry () helper function may be invoked\r
+    // with the MMU off so we have to ensure that it gets cleaned to the PoC\r
+    //\r
+    WriteBackDataCacheRange (ArmReplaceLiveTranslationEntry,\r
+      ArmReplaceLiveTranslationEntrySize);\r
+  }\r
+\r
+  return RETURN_SUCCESS;\r
+}\r
diff --git a/ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf b/ArmPkg/Library/ArmMmuLib/ArmMmuPeiLib.inf
new file mode 100644 (file)
index 0000000..14ebf8d
--- /dev/null
@@ -0,0 +1,36 @@
+#/** @file\r
+#\r
+#  Copyright (c) 2016 Linaro Ltd. All rights reserved.\r
+#\r
+#  This program and the accompanying materials\r
+#  are licensed and made available under the terms and conditions of the BSD License\r
+#  which accompanies this distribution. The full text of the license may be found at\r
+#  http://opensource.org/licenses/bsd-license.php\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = ArmMmuPeiLib\r
+  FILE_GUID                      = b50d8d53-1ad1-44ea-9e69-8c89d4a6d08b\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = ArmMmuLib|PEIM\r
+  CONSTRUCTOR                    = ArmMmuPeiLibConstructor\r
+\r
+[Sources.AARCH64]\r
+  AArch64/ArmMmuLibCore.c\r
+  AArch64/ArmMmuPeiLibConstructor.c\r
+  AArch64/ArmMmuLibReplaceEntry.S\r
+\r
+[Packages]\r
+  ArmPkg/ArmPkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+[LibraryClasses]\r
+  ArmLib\r
+  CacheMaintenanceLib\r
+  MemoryAllocationLib\r