]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ArmPkg / Library / ArmCacheMaintenanceLib / ArmCacheMaintenanceLib.c
index 7da6b42a928b8b9ab91ecd769bbfa35d14fa9dee..bad5d244cbbadc8a96938f48c048dcb13143e26e 100644 (file)
-/** @file
-
-  Copyright (c) 2008-2009, Apple Inc. All rights reserved.
-  
-  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 <Base.h>
-#include <Library/ArmLib.h>
-#include <Library/PcdLib.h>
-
-VOID
-CacheRangeOperation (
-  IN  VOID            *Start,
-  IN  UINTN           Length,
-  IN  CACHE_OPERATION CacheOperation,
-  IN  LINE_OPERATION  LineOperation
-  )
-{
-  UINTN ArmCacheLineLength         = ArmDataCacheLineLength();
-  UINTN ArmCacheLineAlignmentMask  = ArmCacheLineLength - 1;
-  UINTN ArmCacheOperationThreshold = PcdGet32(PcdArmCacheOperationThreshold);
-  
-  if ((CacheOperation != NULL) && (Length >= ArmCacheOperationThreshold))
-  {
-    CacheOperation();
-  }
-  else
-  {
-    // Align address (rounding down)
-    UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);
-    UINTN EndAddress     = (UINTN)Start + Length;
-
-    // Perform the line operation on an address in each cache line
-    while (AlignedAddress < EndAddress)
-    {
-      LineOperation(AlignedAddress);
-      AlignedAddress += ArmCacheLineLength;
-    }
-  }
-}
-
-VOID
-EFIAPI
-InvalidateInstructionCache (
-  VOID
-  )
-{
-  ArmCleanDataCache();
-  ArmInvalidateInstructionCache();
-}
-
-VOID
-EFIAPI
-InvalidateDataCache (
-  VOID
-  )
-{
-  ArmInvalidateDataCache();
-}
-
-VOID *
-EFIAPI
-InvalidateInstructionCacheRange (
-  IN      VOID                      *Address,
-  IN      UINTN                     Length
-  )
-{
-  CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA);
-  ArmInvalidateInstructionCache();
-  return Address;
-}
-
-VOID
-EFIAPI
-WriteBackInvalidateDataCache (
-  VOID
-  )
-{
-  ArmCleanInvalidateDataCache();
-}
-
-VOID *
-EFIAPI
-WriteBackInvalidateDataCacheRange (
-  IN      VOID                      *Address,
-  IN      UINTN                     Length
-  )
-{
-  CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCache, ArmCleanInvalidateDataCacheEntryByMVA);
-  return Address;
-}
-
-VOID
-EFIAPI
-WriteBackDataCache (
-  VOID
-  )
-{
-  ArmCleanDataCache();
-}
-
-VOID *
-EFIAPI
-WriteBackDataCacheRange (
-  IN      VOID                      *Address,
-  IN      UINTN                     Length
-  )
-{
-  CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA);
-  return Address;
-}
-
-VOID *
-EFIAPI
-InvalidateDataCacheRange (
-  IN      VOID                      *Address,
-  IN      UINTN                     Length
-  )
-{
-  CacheRangeOperation(Address, Length, NULL, ArmInvalidateDataCacheEntryByMVA);
-  return Address;
-}
+/** @file\r
+\r
+  Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2021, ARM Limited. All rights reserved.\r
+\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  UINTN           LineLength\r
+  )\r
+{\r
+  UINTN  ArmCacheLineAlignmentMask;\r
+  // Align address (rounding down)\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 += LineLength;\r
+  }\r
+\r
+  ArmDataSynchronizationBarrier ();\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+InvalidateInstructionCache (\r
+  VOID\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+InvalidateDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+InvalidateInstructionCacheRange (\r
+  IN      VOID   *Address,\r
+  IN      UINTN  Length\r
+  )\r
+{\r
+  CacheRangeOperation (\r
+    Address,\r
+    Length,\r
+    ArmCleanDataCacheEntryToPoUByMVA,\r
+    ArmDataCacheLineLength ()\r
+    );\r
+  CacheRangeOperation (\r
+    Address,\r
+    Length,\r
+    ArmInvalidateInstructionCacheEntryToPoUByMVA,\r
+    ArmInstructionCacheLineLength ()\r
+    );\r
+\r
+  ArmInstructionSynchronizationBarrier ();\r
+\r
+  return Address;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+WriteBackInvalidateDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+WriteBackInvalidateDataCacheRange (\r
+  IN      VOID   *Address,\r
+  IN      UINTN  Length\r
+  )\r
+{\r
+  CacheRangeOperation (\r
+    Address,\r
+    Length,\r
+    ArmCleanInvalidateDataCacheEntryByMVA,\r
+    ArmDataCacheLineLength ()\r
+    );\r
+  return Address;\r
+}\r
+\r
+VOID\r
+EFIAPI\r
+WriteBackDataCache (\r
+  VOID\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+WriteBackDataCacheRange (\r
+  IN      VOID   *Address,\r
+  IN      UINTN  Length\r
+  )\r
+{\r
+  CacheRangeOperation (\r
+    Address,\r
+    Length,\r
+    ArmCleanDataCacheEntryByMVA,\r
+    ArmDataCacheLineLength ()\r
+    );\r
+  return Address;\r
+}\r
+\r
+VOID *\r
+EFIAPI\r
+InvalidateDataCacheRange (\r
+  IN      VOID   *Address,\r
+  IN      UINTN  Length\r
+  )\r
+{\r
+  CacheRangeOperation (\r
+    Address,\r
+    Length,\r
+    ArmInvalidateDataCacheEntryByMVA,\r
+    ArmDataCacheLineLength ()\r
+    );\r
+  return Address;\r
+}\r