cache-v7.S 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. /*
  2. * linux/arch/arm/mm/cache-v7.S
  3. *
  4. * Copyright (C) 2001 Deep Blue Solutions Ltd.
  5. * Copyright (C) 2005 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This is the "shell" of the ARMv7 processor support.
  12. */
  13. #include <linux/linkage.h>
  14. #include <linux/init.h>
  15. #include <asm/assembler.h>
  16. #include <asm/errno.h>
  17. #include <asm/unwind.h>
  18. #include "proc-macros.S"
  19. /*
  20. * v7_flush_icache_all()
  21. *
  22. * Flush the whole I-cache.
  23. *
  24. * Registers:
  25. * r0 - set to 0
  26. */
  27. ENTRY(v7_flush_icache_all)
  28. mov r0, #0
  29. ALT_SMP(mcr p15, 0, r0, c7, c1, 0) @ invalidate I-cache inner shareable
  30. ALT_UP(mcr p15, 0, r0, c7, c5, 0) @ I+BTB cache invalidate
  31. mov pc, lr
  32. ENDPROC(v7_flush_icache_all)
  33. /*
  34. * v7_flush_dcache_all()
  35. *
  36. * Flush the whole D-cache.
  37. *
  38. * Corrupted registers: r0-r7, r9-r11 (r6 only in Thumb mode)
  39. *
  40. * - mm - mm_struct describing address space
  41. */
  42. ENTRY(v7_flush_dcache_all)
  43. dmb @ ensure ordering with previous memory accesses
  44. mrc p15, 1, r0, c0, c0, 1 @ read clidr
  45. ands r3, r0, #0x7000000 @ extract loc from clidr
  46. mov r3, r3, lsr #23 @ left align loc bit field
  47. beq finished @ if loc is 0, then no need to clean
  48. mov r10, #0 @ start clean at cache level 0
  49. loop1:
  50. add r2, r10, r10, lsr #1 @ work out 3x current cache level
  51. mov r1, r0, lsr r2 @ extract cache type bits from clidr
  52. and r1, r1, #7 @ mask of the bits for current cache only
  53. cmp r1, #2 @ see what cache we have at this level
  54. blt skip @ skip if no cache, or just i-cache
  55. #ifdef CONFIG_PREEMPT
  56. save_and_disable_irqs_notrace r9 @ make cssr&csidr read atomic
  57. #endif
  58. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  59. isb @ isb to sych the new cssr&csidr
  60. mrc p15, 1, r1, c0, c0, 0 @ read the new csidr
  61. #ifdef CONFIG_PREEMPT
  62. restore_irqs_notrace r9
  63. #endif
  64. and r2, r1, #7 @ extract the length of the cache lines
  65. add r2, r2, #4 @ add 4 (line length offset)
  66. ldr r4, =0x3ff
  67. ands r4, r4, r1, lsr #3 @ find maximum number on the way size
  68. clz r5, r4 @ find bit position of way size increment
  69. ldr r7, =0x7fff
  70. ands r7, r7, r1, lsr #13 @ extract max number of the index size
  71. loop2:
  72. mov r9, r4 @ create working copy of max way size
  73. loop3:
  74. ARM( orr r11, r10, r9, lsl r5 ) @ factor way and cache number into r11
  75. THUMB( lsl r6, r9, r5 )
  76. THUMB( orr r11, r10, r6 ) @ factor way and cache number into r11
  77. ARM( orr r11, r11, r7, lsl r2 ) @ factor index number into r11
  78. THUMB( lsl r6, r7, r2 )
  79. THUMB( orr r11, r11, r6 ) @ factor index number into r11
  80. mcr p15, 0, r11, c7, c14, 2 @ clean & invalidate by set/way
  81. subs r9, r9, #1 @ decrement the way
  82. bge loop3
  83. subs r7, r7, #1 @ decrement the index
  84. bge loop2
  85. skip:
  86. add r10, r10, #2 @ increment cache number
  87. cmp r3, r10
  88. bgt loop1
  89. finished:
  90. mov r10, #0 @ swith back to cache level 0
  91. mcr p15, 2, r10, c0, c0, 0 @ select current cache level in cssr
  92. dsb
  93. isb
  94. mov pc, lr
  95. ENDPROC(v7_flush_dcache_all)
  96. /*
  97. * v7_flush_cache_all()
  98. *
  99. * Flush the entire cache system.
  100. * The data cache flush is now achieved using atomic clean / invalidates
  101. * working outwards from L1 cache. This is done using Set/Way based cache
  102. * maintenance instructions.
  103. * The instruction cache can still be invalidated back to the point of
  104. * unification in a single instruction.
  105. *
  106. */
  107. ENTRY(v7_flush_kern_cache_all)
  108. ARM( stmfd sp!, {r4-r5, r7, r9-r11, lr} )
  109. THUMB( stmfd sp!, {r4-r7, r9-r11, lr} )
  110. bl v7_flush_dcache_all
  111. mov r0, #0
  112. ALT_SMP(mcr p15, 0, r0, c7, c1, 0) @ invalidate I-cache inner shareable
  113. ALT_UP(mcr p15, 0, r0, c7, c5, 0) @ I+BTB cache invalidate
  114. ARM( ldmfd sp!, {r4-r5, r7, r9-r11, lr} )
  115. THUMB( ldmfd sp!, {r4-r7, r9-r11, lr} )
  116. mov pc, lr
  117. ENDPROC(v7_flush_kern_cache_all)
  118. /*
  119. * v7_flush_cache_all()
  120. *
  121. * Flush all TLB entries in a particular address space
  122. *
  123. * - mm - mm_struct describing address space
  124. */
  125. ENTRY(v7_flush_user_cache_all)
  126. /*FALLTHROUGH*/
  127. /*
  128. * v7_flush_cache_range(start, end, flags)
  129. *
  130. * Flush a range of TLB entries in the specified address space.
  131. *
  132. * - start - start address (may not be aligned)
  133. * - end - end address (exclusive, may not be aligned)
  134. * - flags - vm_area_struct flags describing address space
  135. *
  136. * It is assumed that:
  137. * - we have a VIPT cache.
  138. */
  139. ENTRY(v7_flush_user_cache_range)
  140. mov pc, lr
  141. ENDPROC(v7_flush_user_cache_all)
  142. ENDPROC(v7_flush_user_cache_range)
  143. /*
  144. * v7_coherent_kern_range(start,end)
  145. *
  146. * Ensure that the I and D caches are coherent within specified
  147. * region. This is typically used when code has been written to
  148. * a memory region, and will be executed.
  149. *
  150. * - start - virtual start address of region
  151. * - end - virtual end address of region
  152. *
  153. * It is assumed that:
  154. * - the Icache does not read data from the write buffer
  155. */
  156. ENTRY(v7_coherent_kern_range)
  157. /* FALLTHROUGH */
  158. /*
  159. * v7_coherent_user_range(start,end)
  160. *
  161. * Ensure that the I and D caches are coherent within specified
  162. * region. This is typically used when code has been written to
  163. * a memory region, and will be executed.
  164. *
  165. * - start - virtual start address of region
  166. * - end - virtual end address of region
  167. *
  168. * It is assumed that:
  169. * - the Icache does not read data from the write buffer
  170. */
  171. ENTRY(v7_coherent_user_range)
  172. UNWIND(.fnstart )
  173. dcache_line_size r2, r3
  174. sub r3, r2, #1
  175. bic r12, r0, r3
  176. #ifdef CONFIG_ARM_ERRATA_764369
  177. ALT_SMP(W(dsb))
  178. ALT_UP(W(nop))
  179. #endif
  180. 1:
  181. USER( mcr p15, 0, r12, c7, c11, 1 ) @ clean D line to the point of unification
  182. add r12, r12, r2
  183. cmp r12, r1
  184. blo 1b
  185. dsb
  186. icache_line_size r2, r3
  187. sub r3, r2, #1
  188. bic r12, r0, r3
  189. 2:
  190. USER( mcr p15, 0, r12, c7, c5, 1 ) @ invalidate I line
  191. add r12, r12, r2
  192. cmp r12, r1
  193. blo 2b
  194. mov r0, #0
  195. ALT_SMP(mcr p15, 0, r0, c7, c1, 6) @ invalidate BTB Inner Shareable
  196. ALT_UP(mcr p15, 0, r0, c7, c5, 6) @ invalidate BTB
  197. dsb
  198. isb
  199. mov pc, lr
  200. /*
  201. * Fault handling for the cache operation above. If the virtual address in r0
  202. * isn't mapped, fail with -EFAULT.
  203. */
  204. 9001:
  205. mov r0, #-EFAULT
  206. mov pc, lr
  207. UNWIND(.fnend )
  208. ENDPROC(v7_coherent_kern_range)
  209. ENDPROC(v7_coherent_user_range)
  210. /*
  211. * v7_flush_kern_dcache_area(void *addr, size_t size)
  212. *
  213. * Ensure that the data held in the page kaddr is written back
  214. * to the page in question.
  215. *
  216. * - addr - kernel address
  217. * - size - region size
  218. */
  219. ENTRY(v7_flush_kern_dcache_area)
  220. dcache_line_size r2, r3
  221. add r1, r0, r1
  222. sub r3, r2, #1
  223. bic r0, r0, r3
  224. #ifdef CONFIG_ARM_ERRATA_764369
  225. ALT_SMP(W(dsb))
  226. ALT_UP(W(nop))
  227. #endif
  228. 1:
  229. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line / unified line
  230. add r0, r0, r2
  231. cmp r0, r1
  232. blo 1b
  233. dsb
  234. mov pc, lr
  235. ENDPROC(v7_flush_kern_dcache_area)
  236. /*
  237. * v7_dma_inv_range(start,end)
  238. *
  239. * Invalidate the data cache within the specified region; we will
  240. * be performing a DMA operation in this region and we want to
  241. * purge old data in the cache.
  242. *
  243. * - start - virtual start address of region
  244. * - end - virtual end address of region
  245. */
  246. v7_dma_inv_range:
  247. dcache_line_size r2, r3
  248. sub r3, r2, #1
  249. tst r0, r3
  250. bic r0, r0, r3
  251. #ifdef CONFIG_ARM_ERRATA_764369
  252. ALT_SMP(W(dsb))
  253. ALT_UP(W(nop))
  254. #endif
  255. mcrne p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line
  256. tst r1, r3
  257. bic r1, r1, r3
  258. mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D / U line
  259. 1:
  260. mcr p15, 0, r0, c7, c6, 1 @ invalidate D / U line
  261. add r0, r0, r2
  262. cmp r0, r1
  263. blo 1b
  264. dsb
  265. mov pc, lr
  266. ENDPROC(v7_dma_inv_range)
  267. /*
  268. * v7_dma_clean_range(start,end)
  269. * - start - virtual start address of region
  270. * - end - virtual end address of region
  271. */
  272. v7_dma_clean_range:
  273. dcache_line_size r2, r3
  274. sub r3, r2, #1
  275. bic r0, r0, r3
  276. #ifdef CONFIG_ARM_ERRATA_764369
  277. ALT_SMP(W(dsb))
  278. ALT_UP(W(nop))
  279. #endif
  280. 1:
  281. mcr p15, 0, r0, c7, c10, 1 @ clean D / U line
  282. add r0, r0, r2
  283. cmp r0, r1
  284. blo 1b
  285. dsb
  286. mov pc, lr
  287. ENDPROC(v7_dma_clean_range)
  288. /*
  289. * v7_dma_flush_range(start,end)
  290. * - start - virtual start address of region
  291. * - end - virtual end address of region
  292. */
  293. ENTRY(v7_dma_flush_range)
  294. dcache_line_size r2, r3
  295. sub r3, r2, #1
  296. bic r0, r0, r3
  297. #ifdef CONFIG_ARM_ERRATA_764369
  298. ALT_SMP(W(dsb))
  299. ALT_UP(W(nop))
  300. #endif
  301. 1:
  302. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line
  303. add r0, r0, r2
  304. cmp r0, r1
  305. blo 1b
  306. dsb
  307. mov pc, lr
  308. ENDPROC(v7_dma_flush_range)
  309. /*
  310. * dma_map_area(start, size, dir)
  311. * - start - kernel virtual start address
  312. * - size - size of region
  313. * - dir - DMA direction
  314. */
  315. ENTRY(v7_dma_map_area)
  316. add r1, r1, r0
  317. teq r2, #DMA_FROM_DEVICE
  318. beq v7_dma_inv_range
  319. b v7_dma_clean_range
  320. ENDPROC(v7_dma_map_area)
  321. /*
  322. * dma_unmap_area(start, size, dir)
  323. * - start - kernel virtual start address
  324. * - size - size of region
  325. * - dir - DMA direction
  326. */
  327. ENTRY(v7_dma_unmap_area)
  328. add r1, r1, r0
  329. teq r2, #DMA_TO_DEVICE
  330. bne v7_dma_inv_range
  331. mov pc, lr
  332. ENDPROC(v7_dma_unmap_area)
  333. __INITDATA
  334. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  335. define_cache_functions v7