ArmCacheMaintenanceLib.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /** @file
  2. Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
  3. Copyright (c) 2011 - 2014, ARM Limited. All rights reserved.
  4. This program and the accompanying materials
  5. are licensed and made available under the terms and conditions of the BSD License
  6. which accompanies this distribution. The full text of the license may be found at
  7. http://opensource.org/licenses/bsd-license.php
  8. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  10. **/
  11. #include <Base.h>
  12. #include <Library/ArmLib.h>
  13. #include <Library/PcdLib.h>
  14. VOID
  15. CacheRangeOperation (
  16. IN VOID *Start,
  17. IN UINTN Length,
  18. IN CACHE_OPERATION CacheOperation,
  19. IN LINE_OPERATION LineOperation
  20. )
  21. {
  22. UINTN ArmCacheLineLength = ArmDataCacheLineLength();
  23. UINTN ArmCacheLineAlignmentMask = ArmCacheLineLength - 1;
  24. UINTN ArmCacheOperationThreshold = PcdGet32(PcdArmCacheOperationThreshold);
  25. if ((CacheOperation != NULL) && (Length >= ArmCacheOperationThreshold)) {
  26. ArmDrainWriteBuffer ();
  27. CacheOperation ();
  28. } else {
  29. // Align address (rounding down)
  30. UINTN AlignedAddress = (UINTN)Start - ((UINTN)Start & ArmCacheLineAlignmentMask);
  31. UINTN EndAddress = (UINTN)Start + Length;
  32. // Perform the line operation on an address in each cache line
  33. while (AlignedAddress < EndAddress) {
  34. LineOperation(AlignedAddress);
  35. AlignedAddress += ArmCacheLineLength;
  36. }
  37. }
  38. }
  39. VOID
  40. EFIAPI
  41. InvalidateInstructionCache (
  42. VOID
  43. )
  44. {
  45. ArmCleanDataCache();
  46. ArmInvalidateInstructionCache();
  47. }
  48. VOID
  49. EFIAPI
  50. InvalidateDataCache (
  51. VOID
  52. )
  53. {
  54. ArmInvalidateDataCache();
  55. }
  56. VOID *
  57. EFIAPI
  58. InvalidateInstructionCacheRange (
  59. IN VOID *Address,
  60. IN UINTN Length
  61. )
  62. {
  63. CacheRangeOperation (Address, Length, ArmCleanDataCacheToPoU, ArmCleanDataCacheEntryByMVA);
  64. ArmInvalidateInstructionCache ();
  65. return Address;
  66. }
  67. VOID
  68. EFIAPI
  69. WriteBackInvalidateDataCache (
  70. VOID
  71. )
  72. {
  73. ArmCleanInvalidateDataCache();
  74. }
  75. VOID *
  76. EFIAPI
  77. WriteBackInvalidateDataCacheRange (
  78. IN VOID *Address,
  79. IN UINTN Length
  80. )
  81. {
  82. CacheRangeOperation(Address, Length, ArmCleanInvalidateDataCache, ArmCleanInvalidateDataCacheEntryByMVA);
  83. return Address;
  84. }
  85. VOID
  86. EFIAPI
  87. WriteBackDataCache (
  88. VOID
  89. )
  90. {
  91. ArmCleanDataCache();
  92. }
  93. VOID *
  94. EFIAPI
  95. WriteBackDataCacheRange (
  96. IN VOID *Address,
  97. IN UINTN Length
  98. )
  99. {
  100. CacheRangeOperation(Address, Length, ArmCleanDataCache, ArmCleanDataCacheEntryByMVA);
  101. return Address;
  102. }
  103. VOID *
  104. EFIAPI
  105. InvalidateDataCacheRange (
  106. IN VOID *Address,
  107. IN UINTN Length
  108. )
  109. {
  110. CacheRangeOperation(Address, Length, NULL, ArmInvalidateDataCacheEntryByMVA);
  111. return Address;
  112. }