cache-v6.S 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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_page(kaddr)
  153. *
  154. * Ensure that the data held in the page kaddr is written back
  155. * to the page in question.
  156. *
  157. * - kaddr - kernel address (guaranteed to be page aligned)
  158. */
  159. ENTRY(v6_flush_kern_dcache_page)
  160. add r1, r0, #PAGE_SZ
  161. 1:
  162. #ifdef HARVARD_CACHE
  163. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  164. #else
  165. mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate unified line
  166. #endif
  167. add r0, r0, #D_CACHE_LINE_SIZE
  168. cmp r0, r1
  169. blo 1b
  170. #ifdef HARVARD_CACHE
  171. mov r0, #0
  172. mcr p15, 0, r0, c7, c10, 4
  173. #endif
  174. mov pc, lr
  175. /*
  176. * v6_dma_inv_range(start,end)
  177. *
  178. * Invalidate the data cache within the specified region; we will
  179. * be performing a DMA operation in this region and we want to
  180. * purge old data in the cache.
  181. *
  182. * - start - virtual start address of region
  183. * - end - virtual end address of region
  184. */
  185. ENTRY(v6_dma_inv_range)
  186. tst r0, #D_CACHE_LINE_SIZE - 1
  187. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  188. #ifdef HARVARD_CACHE
  189. mcrne p15, 0, r0, c7, c10, 1 @ clean D line
  190. #else
  191. mcrne p15, 0, r0, c7, c11, 1 @ clean unified line
  192. #endif
  193. tst r1, #D_CACHE_LINE_SIZE - 1
  194. bic r1, r1, #D_CACHE_LINE_SIZE - 1
  195. #ifdef HARVARD_CACHE
  196. mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D line
  197. #else
  198. mcrne p15, 0, r1, c7, c15, 1 @ clean & invalidate unified line
  199. #endif
  200. 1:
  201. #ifdef HARVARD_CACHE
  202. mcr p15, 0, r0, c7, c6, 1 @ invalidate D line
  203. #else
  204. mcr p15, 0, r0, c7, c7, 1 @ invalidate unified line
  205. #endif
  206. add r0, r0, #D_CACHE_LINE_SIZE
  207. cmp r0, r1
  208. blo 1b
  209. mov r0, #0
  210. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  211. mov pc, lr
  212. /*
  213. * v6_dma_clean_range(start,end)
  214. * - start - virtual start address of region
  215. * - end - virtual end address of region
  216. */
  217. ENTRY(v6_dma_clean_range)
  218. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  219. 1:
  220. #ifdef HARVARD_CACHE
  221. mcr p15, 0, r0, c7, c10, 1 @ clean D line
  222. #else
  223. mcr p15, 0, r0, c7, c11, 1 @ clean unified line
  224. #endif
  225. add r0, r0, #D_CACHE_LINE_SIZE
  226. cmp r0, r1
  227. blo 1b
  228. mov r0, #0
  229. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  230. mov pc, lr
  231. /*
  232. * v6_dma_flush_range(start,end)
  233. * - start - virtual start address of region
  234. * - end - virtual end address of region
  235. */
  236. ENTRY(v6_dma_flush_range)
  237. bic r0, r0, #D_CACHE_LINE_SIZE - 1
  238. 1:
  239. #ifdef HARVARD_CACHE
  240. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  241. #else
  242. mcr p15, 0, r0, c7, c15, 1 @ clean & invalidate 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. mov pc, lr
  250. __INITDATA
  251. .type v6_cache_fns, #object
  252. ENTRY(v6_cache_fns)
  253. .long v6_flush_kern_cache_all
  254. .long v6_flush_user_cache_all
  255. .long v6_flush_user_cache_range
  256. .long v6_coherent_kern_range
  257. .long v6_coherent_user_range
  258. .long v6_flush_kern_dcache_page
  259. .long v6_dma_inv_range
  260. .long v6_dma_clean_range
  261. .long v6_dma_flush_range
  262. .size v6_cache_fns, . - v6_cache_fns