cache.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. SYM_FUNC_ALIAS(__pi_caches_clean_inval_pou, caches_clean_inval_pou)
  57. /*
  58. * caches_clean_inval_user_pou(start,end)
  59. *
  60. * Ensure that the I and D caches are coherent within specified region.
  61. * This is typically used when code has been written to a memory region,
  62. * and will be executed.
  63. *
  64. * - start - virtual start address of region
  65. * - end - virtual end address of region
  66. */
  67. SYM_FUNC_START(caches_clean_inval_user_pou)
  68. uaccess_ttbr0_enable x2, x3, x4
  69. caches_clean_inval_pou_macro 2f
  70. mov x0, xzr
  71. 1:
  72. uaccess_ttbr0_disable x1, x2
  73. ret
  74. 2:
  75. mov x0, #-EFAULT
  76. b 1b
  77. SYM_FUNC_END(caches_clean_inval_user_pou)
  78. /*
  79. * icache_inval_pou(start,end)
  80. *
  81. * Ensure that the I cache is invalid within specified region.
  82. *
  83. * - start - virtual start address of region
  84. * - end - virtual end address of region
  85. */
  86. SYM_FUNC_START(icache_inval_pou)
  87. alternative_if ARM64_HAS_CACHE_DIC
  88. isb
  89. ret
  90. alternative_else_nop_endif
  91. invalidate_icache_by_line x0, x1, x2, x3
  92. ret
  93. SYM_FUNC_END(icache_inval_pou)
  94. /*
  95. * dcache_clean_inval_poc(start, end)
  96. *
  97. * Ensure that any D-cache lines for the interval [start, end)
  98. * are cleaned and invalidated to the PoC.
  99. *
  100. * - start - virtual start address of region
  101. * - end - virtual end address of region
  102. */
  103. SYM_FUNC_START(__pi_dcache_clean_inval_poc)
  104. dcache_by_line_op civac, sy, x0, x1, x2, x3
  105. ret
  106. SYM_FUNC_END(__pi_dcache_clean_inval_poc)
  107. SYM_FUNC_ALIAS(dcache_clean_inval_poc, __pi_dcache_clean_inval_poc)
  108. /*
  109. * dcache_clean_pou(start, end)
  110. *
  111. * Ensure that any D-cache lines for the interval [start, end)
  112. * are cleaned to the PoU.
  113. *
  114. * - start - virtual start address of region
  115. * - end - virtual end address of region
  116. */
  117. SYM_FUNC_START(dcache_clean_pou)
  118. alternative_if ARM64_HAS_CACHE_IDC
  119. dsb ishst
  120. ret
  121. alternative_else_nop_endif
  122. dcache_by_line_op cvau, ish, x0, x1, x2, x3
  123. ret
  124. SYM_FUNC_END(dcache_clean_pou)
  125. /*
  126. * dcache_inval_poc(start, end)
  127. *
  128. * Ensure that any D-cache lines for the interval [start, end)
  129. * are invalidated. Any partial lines at the ends of the interval are
  130. * also cleaned to PoC to prevent data loss.
  131. *
  132. * - start - kernel start address of region
  133. * - end - kernel end address of region
  134. */
  135. SYM_FUNC_START(__pi_dcache_inval_poc)
  136. dcache_line_size x2, x3
  137. sub x3, x2, #1
  138. tst x1, x3 // end cache line aligned?
  139. bic x1, x1, x3
  140. b.eq 1f
  141. dc civac, x1 // clean & invalidate D / U line
  142. 1: tst x0, x3 // start cache line aligned?
  143. bic x0, x0, x3
  144. b.eq 2f
  145. dc civac, x0 // clean & invalidate D / U line
  146. b 3f
  147. 2: dc ivac, x0 // invalidate D / U line
  148. 3: add x0, x0, x2
  149. cmp x0, x1
  150. b.lo 2b
  151. dsb sy
  152. ret
  153. SYM_FUNC_END(__pi_dcache_inval_poc)
  154. SYM_FUNC_ALIAS(dcache_inval_poc, __pi_dcache_inval_poc)
  155. /*
  156. * dcache_clean_poc(start, end)
  157. *
  158. * Ensure that any D-cache lines for the interval [start, end)
  159. * are cleaned to the PoC.
  160. *
  161. * - start - virtual start address of region
  162. * - end - virtual end address of region
  163. */
  164. SYM_FUNC_START(__pi_dcache_clean_poc)
  165. dcache_by_line_op cvac, sy, x0, x1, x2, x3
  166. ret
  167. SYM_FUNC_END(__pi_dcache_clean_poc)
  168. SYM_FUNC_ALIAS(dcache_clean_poc, __pi_dcache_clean_poc)
  169. /*
  170. * dcache_clean_pop(start, end)
  171. *
  172. * Ensure that any D-cache lines for the interval [start, end)
  173. * are cleaned to the PoP.
  174. *
  175. * - start - virtual start address of region
  176. * - end - virtual end address of region
  177. */
  178. SYM_FUNC_START(__pi_dcache_clean_pop)
  179. alternative_if_not ARM64_HAS_DCPOP
  180. b dcache_clean_poc
  181. alternative_else_nop_endif
  182. dcache_by_line_op cvap, sy, x0, x1, x2, x3
  183. ret
  184. SYM_FUNC_END(__pi_dcache_clean_pop)
  185. SYM_FUNC_ALIAS(dcache_clean_pop, __pi_dcache_clean_pop)