cache-v4wb.S 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/arch/arm/mm/cache-v4wb.S
  4. *
  5. * Copyright (C) 1997-2002 Russell king
  6. */
  7. #include <linux/linkage.h>
  8. #include <linux/init.h>
  9. #include <linux/cfi_types.h>
  10. #include <asm/assembler.h>
  11. #include <asm/page.h>
  12. #include "proc-macros.S"
  13. /*
  14. * The size of one data cache line.
  15. */
  16. #define CACHE_DLINESIZE 32
  17. /*
  18. * The total size of the data cache.
  19. */
  20. #if defined(CONFIG_CPU_SA110)
  21. # define CACHE_DSIZE 16384
  22. #elif defined(CONFIG_CPU_SA1100)
  23. # define CACHE_DSIZE 8192
  24. #else
  25. # error Unknown cache size
  26. #endif
  27. /*
  28. * This is the size at which it becomes more efficient to
  29. * clean the whole cache, rather than using the individual
  30. * cache line maintenance instructions.
  31. *
  32. * Size Clean (ticks) Dirty (ticks)
  33. * 4096 21 20 21 53 55 54
  34. * 8192 40 41 40 106 100 102
  35. * 16384 77 77 76 140 140 138
  36. * 32768 150 149 150 214 216 212 <---
  37. * 65536 296 297 296 351 358 361
  38. * 131072 591 591 591 656 657 651
  39. * Whole 132 136 132 221 217 207 <---
  40. */
  41. #define CACHE_DLIMIT (CACHE_DSIZE * 4)
  42. .data
  43. .align 2
  44. flush_base:
  45. .long FLUSH_BASE
  46. .text
  47. /*
  48. * flush_icache_all()
  49. *
  50. * Unconditionally clean and invalidate the entire icache.
  51. */
  52. SYM_TYPED_FUNC_START(v4wb_flush_icache_all)
  53. mov r0, #0
  54. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  55. ret lr
  56. SYM_FUNC_END(v4wb_flush_icache_all)
  57. /*
  58. * flush_user_cache_all()
  59. *
  60. * Clean and invalidate all cache entries in a particular address
  61. * space.
  62. */
  63. SYM_FUNC_ALIAS(v4wb_flush_user_cache_all, v4wb_flush_kern_cache_all)
  64. /*
  65. * flush_kern_cache_all()
  66. *
  67. * Clean and invalidate the entire cache.
  68. */
  69. SYM_TYPED_FUNC_START(v4wb_flush_kern_cache_all)
  70. mov ip, #0
  71. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  72. __flush_whole_cache:
  73. ldr r3, =flush_base
  74. ldr r1, [r3, #0]
  75. eor r1, r1, #CACHE_DSIZE
  76. str r1, [r3, #0]
  77. add r2, r1, #CACHE_DSIZE
  78. 1: ldr r3, [r1], #32
  79. cmp r1, r2
  80. blo 1b
  81. #ifdef FLUSH_BASE_MINICACHE
  82. add r2, r2, #FLUSH_BASE_MINICACHE - FLUSH_BASE
  83. sub r1, r2, #512 @ only 512 bytes
  84. 1: ldr r3, [r1], #32
  85. cmp r1, r2
  86. blo 1b
  87. #endif
  88. mcr p15, 0, ip, c7, c10, 4 @ drain write buffer
  89. ret lr
  90. SYM_FUNC_END(v4wb_flush_kern_cache_all)
  91. /*
  92. * flush_user_cache_range(start, end, flags)
  93. *
  94. * Invalidate a range of cache entries in the specified
  95. * address space.
  96. *
  97. * - start - start address (inclusive, page aligned)
  98. * - end - end address (exclusive, page aligned)
  99. * - flags - vma_area_struct flags describing address space
  100. */
  101. SYM_TYPED_FUNC_START(v4wb_flush_user_cache_range)
  102. mov ip, #0
  103. sub r3, r1, r0 @ calculate total size
  104. tst r2, #VM_EXEC @ executable region?
  105. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  106. cmp r3, #CACHE_DLIMIT @ total size >= limit?
  107. bhs __flush_whole_cache @ flush whole D cache
  108. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  109. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  110. add r0, r0, #CACHE_DLINESIZE
  111. cmp r0, r1
  112. blo 1b
  113. tst r2, #VM_EXEC
  114. mcrne p15, 0, ip, c7, c10, 4 @ drain write buffer
  115. ret lr
  116. SYM_FUNC_END(v4wb_flush_user_cache_range)
  117. /*
  118. * flush_kern_dcache_area(void *addr, size_t size)
  119. *
  120. * Ensure no D cache aliasing occurs, either with itself or
  121. * the I cache
  122. *
  123. * - addr - kernel address
  124. * - size - region size
  125. */
  126. SYM_TYPED_FUNC_START(v4wb_flush_kern_dcache_area)
  127. add r1, r0, r1
  128. #ifdef CONFIG_CFI /* Fallthrough if !CFI */
  129. b v4wb_coherent_user_range
  130. #endif
  131. SYM_FUNC_END(v4wb_flush_kern_dcache_area)
  132. /*
  133. * coherent_kern_range(start, end)
  134. *
  135. * Ensure coherency between the Icache and the Dcache in the
  136. * region described by start. If you have non-snooping
  137. * Harvard caches, you need to implement this function.
  138. *
  139. * - start - virtual start address
  140. * - end - virtual end address
  141. */
  142. SYM_TYPED_FUNC_START(v4wb_coherent_kern_range)
  143. #ifdef CONFIG_CFI /* Fallthrough if !CFI */
  144. b v4wb_coherent_user_range
  145. #endif
  146. SYM_FUNC_END(v4wb_coherent_kern_range)
  147. /*
  148. * coherent_user_range(start, end)
  149. *
  150. * Ensure coherency between the Icache and the Dcache in the
  151. * region described by start. If you have non-snooping
  152. * Harvard caches, you need to implement this function.
  153. *
  154. * - start - virtual start address
  155. * - end - virtual end address
  156. */
  157. SYM_TYPED_FUNC_START(v4wb_coherent_user_range)
  158. bic r0, r0, #CACHE_DLINESIZE - 1
  159. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  160. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  161. add r0, r0, #CACHE_DLINESIZE
  162. cmp r0, r1
  163. blo 1b
  164. mov r0, #0
  165. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  166. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  167. ret lr
  168. SYM_FUNC_END(v4wb_coherent_user_range)
  169. /*
  170. * dma_inv_range(start, end)
  171. *
  172. * Invalidate (discard) the specified virtual address range.
  173. * May not write back any entries. If 'start' or 'end'
  174. * are not cache line aligned, those lines must be written
  175. * back.
  176. *
  177. * - start - virtual start address
  178. * - end - virtual end address
  179. */
  180. v4wb_dma_inv_range:
  181. tst r0, #CACHE_DLINESIZE - 1
  182. bic r0, r0, #CACHE_DLINESIZE - 1
  183. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  184. tst r1, #CACHE_DLINESIZE - 1
  185. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  186. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  187. add r0, r0, #CACHE_DLINESIZE
  188. cmp r0, r1
  189. blo 1b
  190. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  191. ret lr
  192. /*
  193. * dma_clean_range(start, end)
  194. *
  195. * Clean (write back) the specified virtual address range.
  196. *
  197. * - start - virtual start address
  198. * - end - virtual end address
  199. */
  200. v4wb_dma_clean_range:
  201. bic r0, r0, #CACHE_DLINESIZE - 1
  202. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  203. add r0, r0, #CACHE_DLINESIZE
  204. cmp r0, r1
  205. blo 1b
  206. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  207. ret lr
  208. /*
  209. * dma_flush_range(start, end)
  210. *
  211. * Clean and invalidate the specified virtual address range.
  212. *
  213. * - start - virtual start address
  214. * - end - virtual end address
  215. *
  216. * This is actually the same as v4wb_coherent_kern_range()
  217. */
  218. .globl v4wb_dma_flush_range
  219. .set v4wb_dma_flush_range, v4wb_coherent_kern_range
  220. /*
  221. * dma_map_area(start, size, dir)
  222. * - start - kernel virtual start address
  223. * - size - size of region
  224. * - dir - DMA direction
  225. */
  226. SYM_TYPED_FUNC_START(v4wb_dma_map_area)
  227. add r1, r1, r0
  228. cmp r2, #DMA_TO_DEVICE
  229. beq v4wb_dma_clean_range
  230. bcs v4wb_dma_inv_range
  231. b v4wb_dma_flush_range
  232. SYM_FUNC_END(v4wb_dma_map_area)
  233. /*
  234. * dma_unmap_area(start, size, dir)
  235. * - start - kernel virtual start address
  236. * - size - size of region
  237. * - dir - DMA direction
  238. */
  239. SYM_TYPED_FUNC_START(v4wb_dma_unmap_area)
  240. ret lr
  241. SYM_FUNC_END(v4wb_dma_unmap_area)