cache-v7.S 6.5 KB

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