cache-v7.S 6.9 KB

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