cache-v7.S 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. #ifdef CONFIG_ARM_ERRATA_775420
  239. dsb
  240. #endif
  241. mov r0, #-EFAULT
  242. mov pc, lr
  243. UNWIND(.fnend )
  244. ENDPROC(v7_coherent_kern_range)
  245. ENDPROC(v7_coherent_user_range)
  246. /*
  247. * v7_flush_kern_dcache_area(void *addr, size_t size)
  248. *
  249. * Ensure that the data held in the page kaddr is written back
  250. * to the page in question.
  251. *
  252. * - addr - kernel address
  253. * - size - region size
  254. */
  255. ENTRY(v7_flush_kern_dcache_area)
  256. dcache_line_size r2, r3
  257. add r1, r0, r1
  258. sub r3, r2, #1
  259. bic r0, r0, r3
  260. #ifdef CONFIG_ARM_ERRATA_764369
  261. ALT_SMP(W(dsb))
  262. ALT_UP(W(nop))
  263. #endif
  264. 1:
  265. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line / unified line
  266. add r0, r0, r2
  267. cmp r0, r1
  268. blo 1b
  269. dsb
  270. mov pc, lr
  271. ENDPROC(v7_flush_kern_dcache_area)
  272. /*
  273. * v7_dma_inv_range(start,end)
  274. *
  275. * Invalidate the data cache within the specified region; we will
  276. * be performing a DMA operation in this region and we want to
  277. * purge old data in the cache.
  278. *
  279. * - start - virtual start address of region
  280. * - end - virtual end address of region
  281. */
  282. v7_dma_inv_range:
  283. dcache_line_size r2, r3
  284. sub r3, r2, #1
  285. tst r0, r3
  286. bic r0, r0, r3
  287. #ifdef CONFIG_ARM_ERRATA_764369
  288. ALT_SMP(W(dsb))
  289. ALT_UP(W(nop))
  290. #endif
  291. mcrne p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line
  292. tst r1, r3
  293. bic r1, r1, r3
  294. mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D / U line
  295. 1:
  296. mcr p15, 0, r0, c7, c6, 1 @ invalidate D / U line
  297. add r0, r0, r2
  298. cmp r0, r1
  299. blo 1b
  300. dsb
  301. mov pc, lr
  302. ENDPROC(v7_dma_inv_range)
  303. /*
  304. * v7_dma_clean_range(start,end)
  305. * - start - virtual start address of region
  306. * - end - virtual end address of region
  307. */
  308. v7_dma_clean_range:
  309. dcache_line_size r2, r3
  310. sub r3, r2, #1
  311. bic r0, r0, r3
  312. #ifdef CONFIG_ARM_ERRATA_764369
  313. ALT_SMP(W(dsb))
  314. ALT_UP(W(nop))
  315. #endif
  316. 1:
  317. mcr p15, 0, r0, c7, c10, 1 @ clean D / U line
  318. add r0, r0, r2
  319. cmp r0, r1
  320. blo 1b
  321. dsb
  322. mov pc, lr
  323. ENDPROC(v7_dma_clean_range)
  324. /*
  325. * v7_dma_flush_range(start,end)
  326. * - start - virtual start address of region
  327. * - end - virtual end address of region
  328. */
  329. ENTRY(v7_dma_flush_range)
  330. dcache_line_size r2, r3
  331. sub r3, r2, #1
  332. bic r0, r0, r3
  333. #ifdef CONFIG_ARM_ERRATA_764369
  334. ALT_SMP(W(dsb))
  335. ALT_UP(W(nop))
  336. #endif
  337. 1:
  338. mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D / U line
  339. add r0, r0, r2
  340. cmp r0, r1
  341. blo 1b
  342. dsb
  343. mov pc, lr
  344. ENDPROC(v7_dma_flush_range)
  345. /*
  346. * dma_map_area(start, size, dir)
  347. * - start - kernel virtual start address
  348. * - size - size of region
  349. * - dir - DMA direction
  350. */
  351. ENTRY(v7_dma_map_area)
  352. add r1, r1, r0
  353. teq r2, #DMA_FROM_DEVICE
  354. beq v7_dma_inv_range
  355. b v7_dma_clean_range
  356. ENDPROC(v7_dma_map_area)
  357. /*
  358. * dma_unmap_area(start, size, dir)
  359. * - start - kernel virtual start address
  360. * - size - size of region
  361. * - dir - DMA direction
  362. */
  363. ENTRY(v7_dma_unmap_area)
  364. add r1, r1, r0
  365. teq r2, #DMA_TO_DEVICE
  366. bne v7_dma_inv_range
  367. mov pc, lr
  368. ENDPROC(v7_dma_unmap_area)
  369. __INITDATA
  370. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  371. define_cache_functions v7