cache-v7.S 8.1 KB

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