cache-v6.S 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * linux/arch/arm/mm/cache-v6.S
  4. *
  5. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  6. *
  7. * This is the "shell" of the ARMv6 processor support.
  8. */
  9. #include <linux/linkage.h>
  10. #include <linux/init.h>
  11. #include <asm/assembler.h>
  12. #include <asm/errno.h>
  13. #include <asm/unwind.h>
  14. #include "proc-macros.S"
  15. #define HARVARD_CACHE
  16. #define CACHE_LINE_SIZE 32
  17. #define D_CACHE_LINE_SIZE 32
  18. #define BTB_FLUSH_SIZE 8
  19. /*
  20. * v6_flush_icache_all()
  21. *
  22. * Flush the whole I-cache.
  23. *
  24. * ARM1136 erratum 411920 - Invalidate Instruction Cache operation can fail.
  25. * This erratum is present in 1136, 1156 and 1176. It does not affect the
  26. * MPCore.
  27. *
  28. * Registers:
  29. * r0 - set to 0
  30. * r1 - corrupted
  31. */
  32. ENTRY(v6_flush_icache_all)
  33. mov r0, #0
  34. #ifdef CONFIG_ARM_ERRATA_411920
  35. mrs r1, cpsr
  36. cpsid ifa @ disable interrupts
  37. mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
  38. mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
  39. mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
  40. mcr p15, 0, r0, c7, c5, 0 @ invalidate entire I-cache
  41. msr cpsr_cx, r1 @ restore interrupts
  42. .rept 11 @ ARM Ltd recommends at least
  43. nop @ 11 NOPs
  44. .endr
  45. #else
  46. mcr p15, 0, r0, c7, c5, 0 @ invalidate I-cache
  47. #endif
  48. ret lr
  49. ENDPROC(v6_flush_icache_all)
  50. /*
  51. * v6_flush_cache_all()
  52. *
  53. * Flush the entire cache.
  54. *
  55. * It is assumed that:
  56. */
  57. ENTRY(v6_flush_kern_cache_all)
  58. mov r0, #0
  59. #ifdef HARVARD_CACHE
  60. mcr p15, 0, r0, c7, c14, 0 @ D cache clean+invalidate
  61. #ifndef CONFIG_ARM_ERRATA_411920
  62. mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
  63. #else
  64. b v6_flush_icache_all
  65. #endif
  66. #else
  67. mcr p15, 0, r0, c7, c15, 0 @ Cache clean+invalidate
  68. #endif
  69. ret lr
  70. /*
  71. * v6_flush_cache_all()
  72. *
  73. * Flush all TLB entries in a particular address space
  74. *
  75. * - mm - mm_struct describing address space
  76. */
  77. ENTRY(v6_flush_user_cache_all)
  78. /*FALLTHROUGH*/
  79. /*
  80. * v6_flush_cache_range(start, end, flags)
  81. *
  82. * Flush a range of TLB entries in the specified address space.
  83. *
  84. * - start - start address (may not be aligned)
  85. * - end - end address (exclusive, may not be aligned)
  86. * - flags - vm_area_struct flags describing address space
  87. *
  88. * It is assumed that:
  89. * - we have a VIPT cache.
  90. */
  91. ENTRY(v6_flush_user_cache_range)
  92. ret lr
  93. /*
  94. * v6_coherent_kern_range(start,end)
  95. *
  96. * Ensure that the I and D caches are coherent within specified
  97. * region. This is typically used when code has been written to
  98. * a memory region, and will be executed.
  99. *
  100. * - start - virtual start address of region
  101. * - end - virtual end address of region
  102. *
  103. * It is assumed that:
  104. * - the Icache does not read data from the write buffer
  105. */
  106. ENTRY(v6_coherent_kern_range)
  107. /* FALLTHROUGH */
  108. /*
  109. * v6_coherent_user_range(start,end)
  110. *
  111. * Ensure that the I and D caches are coherent within specified
  112. * region. This is typically used when code has been written to
  113. * a memory region, and will be executed.
  114. *
  115. * - start - virtual start address of region
  116. * - end - virtual end address of region
  117. *
  118. * It is assumed that:
  119. * - the Icache does not read data from the write buffer
  120. */
  121. ENTRY(v6_coherent_user_range)
  122. UNWIND(.fnstart )
  123. #ifdef HARVARD_CACHE
  124. bic r0, r0, #CACHE_LINE_SIZE - 1
  125. 1:
  126. USER( mcr p15, 0, r0, c7, c10, 1 ) @ clean D line
  127. add r0, r0, #CACHE_LINE_SIZE
  128. cmp r0, r1
  129. blo 1b
  130. #endif
  131. mov r0, #0
  132. #ifdef HARVARD_CACHE
  133. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  134. #ifndef CONFIG_ARM_ERRATA_411920
  135. mcr p15, 0, r0, c7, c5, 0 @ I+BTB cache invalidate
  136. #else
  137. b v6_flush_icache_all
  138. #endif
  139. #else
  140. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
  141. #endif
  142. ret lr
  143. /*
  144. * Fault handling for the cache operation above. If the virtual address in r0
  145. * isn't mapped, fail with -EFAULT.
  146. */
  147. 9001:
  148. mov r0, #-EFAULT
  149. ret lr
  150. UNWIND(.fnend )
  151. ENDPROC(v6_coherent_user_range)
  152. ENDPROC(v6_coherent_kern_range)
  153. /*
  154. * v6_flush_kern_dcache_area(void *addr, size_t size)
  155. *
  156. * Ensure that the data held in the page kaddr is written back
  157. * to the page in question.
  158. *
  159. * - addr - kernel address
  160. * - size - region size
  161. */
  162. ENTRY(v6_flush_kern_dcache_area)
  163. add r1, r0, r1
  164. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  165. 1:
  166. #ifdef HARVARD_CACHE
  167. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  168. #else
  169. mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate unified line
  170. #endif
  171. add r0, r0, #D_CACHE_LINE_SIZE
  172. cmp r0, r1
  173. blo 1b
  174. #ifdef HARVARD_CACHE
  175. mov r0, #0
  176. mcr p15, 0, r0, c7, c10, 4
  177. #endif
  178. ret lr
  179. /*
  180. * v6_dma_inv_range(start,end)
  181. *
  182. * Invalidate the data cache within the specified region; we will
  183. * be performing a DMA operation in this region and we want to
  184. * purge old data in the cache.
  185. *
  186. * - start - virtual start address of region
  187. * - end - virtual end address of region
  188. */
  189. v6_dma_inv_range:
  190. #ifdef CONFIG_DMA_CACHE_RWFO
  191. ldrb r2, [r0] @ read for ownership
  192. strb r2, [r0] @ write for ownership
  193. #endif
  194. tst r0, #D_CACHE_LINE_SIZE - 1
  195. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  196. #ifdef HARVARD_CACHE
  197. mcrne p15, 0, r0, c7, c10, 1 @ clean D line
  198. #else
  199. mcrne p15, 0, r0, c7, c11, 1 @ clean unified line
  200. #endif
  201. tst r1, #D_CACHE_LINE_SIZE - 1
  202. #ifdef CONFIG_DMA_CACHE_RWFO
  203. ldrbne r2, [r1, #-1] @ read for ownership
  204. strbne r2, [r1, #-1] @ write for ownership
  205. #endif
  206. bic r1, r1, #D_CACHE_LINE_SIZE - 1
  207. #ifdef HARVARD_CACHE
  208. mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line
  209. #else
  210. mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line
  211. #endif
  212. 1:
  213. #ifdef HARVARD_CACHE
  214. mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
  215. #else
  216. mcr p15, 0, r0, c7, c7, 1 @ invalidate unified line
  217. #endif
  218. add r0, r0, #D_CACHE_LINE_SIZE
  219. cmp r0, r1
  220. #ifdef CONFIG_DMA_CACHE_RWFO
  221. ldrlo r2, [r0] @ read for ownership
  222. strlo r2, [r0] @ write for ownership
  223. #endif
  224. blo 1b
  225. mov r0, #0
  226. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  227. ret lr
  228. /*
  229. * v6_dma_clean_range(start,end)
  230. * - start - virtual start address of region
  231. * - end - virtual end address of region
  232. */
  233. v6_dma_clean_range:
  234. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  235. 1:
  236. #ifdef CONFIG_DMA_CACHE_RWFO
  237. ldr r2, [r0] @ read for ownership
  238. #endif
  239. #ifdef HARVARD_CACHE
  240. mcr p15, 0, r0, c7, c10, 1 @ clean D line
  241. #else
  242. mcr p15, 0, r0, c7, c11, 1 @ clean unified line
  243. #endif
  244. add r0, r0, #D_CACHE_LINE_SIZE
  245. cmp r0, r1
  246. blo 1b
  247. mov r0, #0
  248. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  249. ret lr
  250. /*
  251. * v6_dma_flush_range(start,end)
  252. * - start - virtual start address of region
  253. * - end - virtual end address of region
  254. */
  255. ENTRY(v6_dma_flush_range)
  256. #ifdef CONFIG_DMA_CACHE_RWFO
  257. ldrb r2, [r0] @ read for ownership
  258. strb r2, [r0] @ write for ownership
  259. #endif
  260. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  261. 1:
  262. #ifdef HARVARD_CACHE
  263. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  264. #else
  265. mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate line
  266. #endif
  267. add r0, r0, #D_CACHE_LINE_SIZE
  268. cmp r0, r1
  269. #ifdef CONFIG_DMA_CACHE_RWFO
  270. ldrblo r2, [r0] @ read for ownership
  271. strblo r2, [r0] @ write for ownership
  272. #endif
  273. blo 1b
  274. mov r0, #0
  275. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  276. ret lr
  277. /*
  278. * dma_map_area(start, size, dir)
  279. * - start - kernel virtual start address
  280. * - size - size of region
  281. * - dir - DMA direction
  282. */
  283. ENTRY(v6_dma_map_area)
  284. add r1, r1, r0
  285. teq r2, #DMA_FROM_DEVICE
  286. beq v6_dma_inv_range
  287. #ifndef CONFIG_DMA_CACHE_RWFO
  288. b v6_dma_clean_range
  289. #else
  290. teq r2, #DMA_TO_DEVICE
  291. beq v6_dma_clean_range
  292. b v6_dma_flush_range
  293. #endif
  294. ENDPROC(v6_dma_map_area)
  295. /*
  296. * dma_unmap_area(start, size, dir)
  297. * - start - kernel virtual start address
  298. * - size - size of region
  299. * - dir - DMA direction
  300. */
  301. ENTRY(v6_dma_unmap_area)
  302. #ifndef CONFIG_DMA_CACHE_RWFO
  303. add r1, r1, r0
  304. teq r2, #DMA_TO_DEVICE
  305. bne v6_dma_inv_range
  306. #endif
  307. ret lr
  308. ENDPROC(v6_dma_unmap_area)
  309. .globl v6_flush_kern_cache_louis
  310. .equ v6_flush_kern_cache_louis, v6_flush_kern_cache_all
  311. __INITDATA
  312. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  313. define_cache_functions v6