cache.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Cache maintenance
  4. *
  5. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  6. * Copyright (C) 2012 ARM Ltd.
  7. */
  8. #include <linux/errno.h>
  9. #include <linux/linkage.h>
  10. #include <linux/init.h>
  11. #include <asm/assembler.h>
  12. #include <asm/cpufeature.h>
  13. #include <asm/alternative.h>
  14. #include <asm/asm-uaccess.h>
  15. /*
  16. * caches_clean_inval_pou_macro(start,end) [fixup]
  17. *
  18. * Ensure that the I and D caches are coherent within specified region.
  19. * This is typically used when code has been written to a memory region,
  20. * and will be executed.
  21. *
  22. * - start - virtual start address of region
  23. * - end - virtual end address of region
  24. * - fixup - optional label to branch to on user fault
  25. */
  26. .macro caches_clean_inval_pou_macro, fixup
  27. alternative_if ARM64_HAS_CACHE_IDC
  28. dsb ishst
  29. b .Ldc_skip_\@
  30. alternative_else_nop_endif
  31. mov x2, x0
  32. mov x3, x1
  33. dcache_by_line_op cvau, ish, x2, x3, x4, x5, \fixup
  34. .Ldc_skip_\@:
  35. alternative_if ARM64_HAS_CACHE_DIC
  36. isb
  37. b .Lic_skip_\@
  38. alternative_else_nop_endif
  39. invalidate_icache_by_line x0, x1, x2, x3, \fixup
  40. .Lic_skip_\@:
  41. .endm
  42. /*
  43. * caches_clean_inval_pou(start,end)
  44. *
  45. * Ensure that the I and D caches are coherent within specified region.
  46. * This is typically used when code has been written to a memory region,
  47. * and will be executed.
  48. *
  49. * - start - virtual start address of region
  50. * - end - virtual end address of region
  51. */
  52. SYM_FUNC_START(caches_clean_inval_pou)
  53. caches_clean_inval_pou_macro
  54. ret
  55. SYM_FUNC_END(caches_clean_inval_pou)
  56. /*
  57. * caches_clean_inval_user_pou(start,end)
  58. *
  59. * Ensure that the I and D caches are coherent within specified region.
  60. * This is typically used when code has been written to a memory region,
  61. * and will be executed.
  62. *
  63. * - start - virtual start address of region
  64. * - end - virtual end address of region
  65. */
  66. SYM_FUNC_START(caches_clean_inval_user_pou)
  67. uaccess_ttbr0_enable x2, x3, x4
  68. caches_clean_inval_pou_macro 2f
  69. mov x0, xzr
  70. 1:
  71. uaccess_ttbr0_disable x1, x2
  72. ret
  73. 2:
  74. mov x0, #-EFAULT
  75. b 1b
  76. SYM_FUNC_END(caches_clean_inval_user_pou)
  77. /*
  78. * icache_inval_pou(start,end)
  79. *
  80. * Ensure that the I cache is invalid within specified region.
  81. *
  82. * - start - virtual start address of region
  83. * - end - virtual end address of region
  84. */
  85. SYM_FUNC_START(icache_inval_pou)
  86. alternative_if ARM64_HAS_CACHE_DIC
  87. isb
  88. ret
  89. alternative_else_nop_endif
  90. invalidate_icache_by_line x0, x1, x2, x3
  91. ret
  92. SYM_FUNC_END(icache_inval_pou)
  93. /*
  94. * dcache_clean_inval_poc(start, end)
  95. *
  96. * Ensure that any D-cache lines for the interval [start, end)
  97. * are cleaned and invalidated to the PoC.
  98. *
  99. * - start - virtual start address of region
  100. * - end - virtual end address of region
  101. */
  102. SYM_FUNC_START(__pi_dcache_clean_inval_poc)
  103. dcache_by_line_op civac, sy, x0, x1, x2, x3
  104. ret
  105. SYM_FUNC_END(__pi_dcache_clean_inval_poc)
  106. SYM_FUNC_ALIAS(dcache_clean_inval_poc, __pi_dcache_clean_inval_poc)
  107. /*
  108. * dcache_clean_pou(start, end)
  109. *
  110. * Ensure that any D-cache lines for the interval [start, end)
  111. * are cleaned to the PoU.
  112. *
  113. * - start - virtual start address of region
  114. * - end - virtual end address of region
  115. */
  116. SYM_FUNC_START(dcache_clean_pou)
  117. alternative_if ARM64_HAS_CACHE_IDC
  118. dsb ishst
  119. ret
  120. alternative_else_nop_endif
  121. dcache_by_line_op cvau, ish, x0, x1, x2, x3
  122. ret
  123. SYM_FUNC_END(dcache_clean_pou)
  124. /*
  125. * dcache_inval_poc(start, end)
  126. *
  127. * Ensure that any D-cache lines for the interval [start, end)
  128. * are invalidated. Any partial lines at the ends of the interval are
  129. * also cleaned to PoC to prevent data loss.
  130. *
  131. * - start - kernel start address of region
  132. * - end - kernel end address of region
  133. */
  134. SYM_FUNC_START(__pi_dcache_inval_poc)
  135. dcache_line_size x2, x3
  136. sub x3, x2, #1
  137. tst x1, x3 // end cache line aligned?
  138. bic x1, x1, x3
  139. b.eq 1f
  140. dc civac, x1 // clean & invalidate D / U line
  141. 1: tst x0, x3 // start cache line aligned?
  142. bic x0, x0, x3
  143. b.eq 2f
  144. dc civac, x0 // clean & invalidate D / U line
  145. b 3f
  146. 2: dc ivac, x0 // invalidate D / U line
  147. 3: add x0, x0, x2
  148. cmp x0, x1
  149. b.lo 2b
  150. dsb sy
  151. ret
  152. SYM_FUNC_END(__pi_dcache_inval_poc)
  153. SYM_FUNC_ALIAS(dcache_inval_poc, __pi_dcache_inval_poc)
  154. /*
  155. * dcache_clean_poc(start, end)
  156. *
  157. * Ensure that any D-cache lines for the interval [start, end)
  158. * are cleaned to the PoC.
  159. *
  160. * - start - virtual start address of region
  161. * - end - virtual end address of region
  162. */
  163. SYM_FUNC_START(__pi_dcache_clean_poc)
  164. dcache_by_line_op cvac, sy, x0, x1, x2, x3
  165. ret
  166. SYM_FUNC_END(__pi_dcache_clean_poc)
  167. SYM_FUNC_ALIAS(dcache_clean_poc, __pi_dcache_clean_poc)
  168. /*
  169. * dcache_clean_pop(start, end)
  170. *
  171. * Ensure that any D-cache lines for the interval [start, end)
  172. * are cleaned to the PoP.
  173. *
  174. * - start - virtual start address of region
  175. * - end - virtual end address of region
  176. */
  177. SYM_FUNC_START(__pi_dcache_clean_pop)
  178. alternative_if_not ARM64_HAS_DCPOP
  179. b dcache_clean_poc
  180. alternative_else_nop_endif
  181. dcache_by_line_op cvap, sy, x0, x1, x2, x3
  182. ret
  183. SYM_FUNC_END(__pi_dcache_clean_pop)
  184. SYM_FUNC_ALIAS(dcache_clean_pop, __pi_dcache_clean_pop)