cache-v7.S 10 KB

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