cache-v6.S 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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_SMP
  203. str r0, [r0] @ write for ownership
  204. #endif
  205. #ifdef HARVARD_CACHE
  206. mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
  207. #else
  208. mcr p15, 0, r0, c7, c7, 1 @ invalidate unified line
  209. #endif
  210. add r0, r0, #D_CACHE_LINE_SIZE
  211. cmp r0, r1
  212. blo 1b
  213. mov r0, #0
  214. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  215. mov pc, lr
  216. /*
  217. * v6_dma_clean_range(start,end)
  218. * - start - virtual start address of region
  219. * - end - virtual end address of region
  220. */
  221. v6_dma_clean_range:
  222. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  223. 1:
  224. #ifdef CONFIG_SMP
  225. ldr r2, [r0] @ read for ownership
  226. #endif
  227. #ifdef HARVARD_CACHE
  228. mcr p15, 0, r0, c7, c10, 1 @ clean D line
  229. #else
  230. mcr p15, 0, r0, c7, c11, 1 @ clean unified line
  231. #endif
  232. add r0, r0, #D_CACHE_LINE_SIZE
  233. cmp r0, r1
  234. blo 1b
  235. mov r0, #0
  236. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  237. mov pc, lr
  238. /*
  239. * v6_dma_flush_range(start,end)
  240. * - start - virtual start address of region
  241. * - end - virtual end address of region
  242. */
  243. ENTRY(v6_dma_flush_range)
  244. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  245. 1:
  246. #ifdef CONFIG_SMP
  247. ldr r2, [r0] @ read for ownership
  248. str r2, [r0] @ write for ownership
  249. #endif
  250. #ifdef HARVARD_CACHE
  251. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  252. #else
  253. mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate line
  254. #endif
  255. add r0, r0, #D_CACHE_LINE_SIZE
  256. cmp r0, r1
  257. blo 1b
  258. mov r0, #0
  259. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  260. mov pc, lr
  261. /*
  262. * dma_map_area(start, size, dir)
  263. * - start - kernel virtual start address
  264. * - size - size of region
  265. * - dir - DMA direction
  266. */
  267. ENTRY(v6_dma_map_area)
  268. add r1, r1, r0
  269. teq r2, #DMA_FROM_DEVICE
  270. beq v6_dma_inv_range
  271. teq r2, #DMA_TO_DEVICE
  272. beq v6_dma_clean_range
  273. b v6_dma_flush_range
  274. ENDPROC(v6_dma_map_area)
  275. /*
  276. * dma_unmap_area(start, size, dir)
  277. * - start - kernel virtual start address
  278. * - size - size of region
  279. * - dir - DMA direction
  280. */
  281. ENTRY(v6_dma_unmap_area)
  282. mov pc, lr
  283. ENDPROC(v6_dma_unmap_area)
  284. __INITDATA
  285. .type v6_cache_fns, #object
  286. ENTRY(v6_cache_fns)
  287. .long v6_flush_kern_cache_all
  288. .long v6_flush_user_cache_all
  289. .long v6_flush_user_cache_range
  290. .long v6_coherent_kern_range
  291. .long v6_coherent_user_range
  292. .long v6_flush_kern_dcache_area
  293. .long v6_dma_map_area
  294. .long v6_dma_unmap_area
  295. .long v6_dma_flush_range
  296. .size v6_cache_fns, . - v6_cache_fns