cache-v6.S 7.6 KB

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