]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c
ArmPkg: Fix Ecc error 5007 in ArmCacheMaintenanceLib
[mirror_edk2.git] / ArmPkg / Library / ArmCacheMaintenanceLib / ArmCacheMaintenanceLib.c
index d4c16a60746575398f7fbe1357b4ff85f62d4708..db9290f275db59cd0097d9a07f5845376d322caf 100644 (file)
@@ -1,39 +1,38 @@
 /** @file\r
 \r
   Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
-  Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.\r
+  Copyright (c) 2011 - 2021, ARM 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
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 #include <Base.h>\r
 #include <Library/ArmLib.h>\r
+#include <Library/DebugLib.h>\r
 #include <Library/PcdLib.h>\r
 \r
+STATIC\r
 VOID\r
 CacheRangeOperation (\r
   IN  VOID            *Start,\r
   IN  UINTN           Length,\r
-  IN  LINE_OPERATION  LineOperation\r
+  IN  LINE_OPERATION  LineOperation,\r
+  IN  UINTN           LineLength\r
   )\r
 {\r
-  UINTN ArmCacheLineLength         = ArmDataCacheLineLength();\r
-  UINTN ArmCacheLineAlignmentMask  = ArmCacheLineLength - 1;\r
-\r
+  UINTN ArmCacheLineAlignmentMask;\r
   // Align address (rounding down)\r
-  UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);\r
-  UINTN EndAddress     = (UINTN)Start + Length;\r
+  UINTN AlignedAddress;\r
+  UINTN EndAddress;\r
+\r
+  ArmCacheLineAlignmentMask = LineLength - 1;\r
+  AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);\r
+  EndAddress     = (UINTN)Start + Length;\r
 \r
   // Perform the line operation on an address in each cache line\r
   while (AlignedAddress < EndAddress) {\r
     LineOperation(AlignedAddress);\r
-    AlignedAddress += ArmCacheLineLength;\r
+    AlignedAddress += LineLength;\r
   }\r
   ArmDataSynchronizationBarrier ();\r
 }\r
@@ -44,8 +43,7 @@ InvalidateInstructionCache (
   VOID\r
   )\r
 {\r
-  ArmCleanDataCache();\r
-  ArmInvalidateInstructionCache();\r
+  ASSERT (FALSE);\r
 }\r
 \r
 VOID\r
@@ -54,7 +52,7 @@ InvalidateDataCache (
   VOID\r
   )\r
 {\r
-  ArmInvalidateDataCache();\r
+  ASSERT (FALSE);\r
 }\r
 \r
 VOID *\r
@@ -64,8 +62,14 @@ InvalidateInstructionCacheRange (
   IN      UINTN                     Length\r
   )\r
 {\r
-  CacheRangeOperation (Address, Length, ArmCleanDataCacheEntryByMVA);\r
-  ArmInvalidateInstructionCache ();\r
+  CacheRangeOperation (Address, Length, ArmCleanDataCacheEntryToPoUByMVA,\r
+    ArmDataCacheLineLength ());\r
+  CacheRangeOperation (Address, Length,\r
+    ArmInvalidateInstructionCacheEntryToPoUByMVA,\r
+    ArmInstructionCacheLineLength ());\r
+\r
+  ArmInstructionSynchronizationBarrier ();\r
+\r
   return Address;\r
 }\r
 \r
@@ -75,7 +79,7 @@ WriteBackInvalidateDataCache (
   VOID\r
   )\r
 {\r
-  ArmCleanInvalidateDataCache();\r
+  ASSERT (FALSE);\r
 }\r
 \r
 VOID *\r
@@ -85,7 +89,8 @@ WriteBackInvalidateDataCacheRange (
   IN      UINTN                     Length\r
   )\r
 {\r
-  CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCacheEntryByMVA);\r
+  CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCacheEntryByMVA,\r
+    ArmDataCacheLineLength ());\r
   return Address;\r
 }\r
 \r
@@ -95,7 +100,7 @@ WriteBackDataCache (
   VOID\r
   )\r
 {\r
-  ArmCleanDataCache();\r
+  ASSERT (FALSE);\r
 }\r
 \r
 VOID *\r
@@ -105,7 +110,8 @@ WriteBackDataCacheRange (
   IN      UINTN                     Length\r
   )\r
 {\r
-  CacheRangeOperation(Address, Length, ArmCleanDataCacheEntryByMVA);\r
+  CacheRangeOperation(Address, Length, ArmCleanDataCacheEntryByMVA,\r
+    ArmDataCacheLineLength ());\r
   return Address;\r
 }\r
 \r
@@ -116,6 +122,7 @@ InvalidateDataCacheRange (
   IN      UINTN                     Length\r
   )\r
 {\r
-  CacheRangeOperation(Address, Length, ArmInvalidateDataCacheEntryByMVA);\r
+  CacheRangeOperation(Address, Length, ArmInvalidateDataCacheEntryByMVA,\r
+    ArmDataCacheLineLength ());\r
   return Address;\r
 }\r