cache-v7.S 9.9 KB

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