cache-v4wb.S 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * linux/arch/arm/mm/cache-v4wb.S
  3. *
  4. * Copyright (C) 1997-2002 Russell king
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/linkage.h>
  11. #include <linux/init.h>
  12. #include <asm/assembler.h>
  13. #include <asm/memory.h>
  14. #include <asm/page.h>
  15. #include "proc-macros.S"
  16. /*
  17. * The size of one data cache line.
  18. */
  19. #define CACHE_DLINESIZE 32
  20. /*
  21. * The total size of the data cache.
  22. */
  23. #if defined(CONFIG_CPU_SA110)
  24. # define CACHE_DSIZE 16384
  25. #elif defined(CONFIG_CPU_SA1100)
  26. # define CACHE_DSIZE 8192
  27. #else
  28. # error Unknown cache size
  29. #endif
  30. /*
  31. * This is the size at which it becomes more efficient to
  32. * clean the whole cache, rather than using the individual
  33. * cache line maintenance instructions.
  34. *
  35. * Size Clean (ticks) Dirty (ticks)
  36. * 4096 21 20 21 53 55 54
  37. * 8192 40 41 40 106 100 102
  38. * 16384 77 77 76 140 140 138
  39. * 32768 150 149 150 214 216 212 <---
  40. * 65536 296 297 296 351 358 361
  41. * 131072 591 591 591 656 657 651
  42. * Whole 132 136 132 221 217 207 <---
  43. */
  44. #define CACHE_DLIMIT (CACHE_DSIZE * 4)
  45. .data
  46. .align 2
  47. flush_base:
  48. .long FLUSH_BASE
  49. .text
  50. /*
  51. * flush_icache_all()
  52. *
  53. * Unconditionally clean and invalidate the entire icache.
  54. */
  55. ENTRY(v4wb_flush_icache_all)
  56. mov r0, #0
  57. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  58. ret lr
  59. ENDPROC(v4wb_flush_icache_all)
  60. /*
  61. * flush_user_cache_all()
  62. *
  63. * Clean and invalidate all cache entries in a particular address
  64. * space.
  65. */
  66. ENTRY(v4wb_flush_user_cache_all)
  67. /* FALLTHROUGH */
  68. /*
  69. * flush_kern_cache_all()
  70. *
  71. * Clean and invalidate the entire cache.
  72. */
  73. ENTRY(v4wb_flush_kern_cache_all)
  74. mov ip, #0
  75. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  76. __flush_whole_cache:
  77. ldr r3, =flush_base
  78. ldr r1, [r3, #0]
  79. eor r1, r1, #CACHE_DSIZE
  80. str r1, [r3, #0]
  81. add r2, r1, #CACHE_DSIZE
  82. 1: ldr r3, [r1], #32
  83. cmp r1, r2
  84. blo 1b
  85. #ifdef FLUSH_BASE_MINICACHE
  86. add r2, r2, #FLUSH_BASE_MINICACHE - FLUSH_BASE
  87. sub r1, r2, #512 @ only 512 bytes
  88. 1: ldr r3, [r1], #32
  89. cmp r1, r2
  90. blo 1b
  91. #endif
  92. mcr p15, 0, ip, c7, c10, 4 @ drain write buffer
  93. ret lr
  94. /*
  95. * flush_user_cache_range(start, end, flags)
  96. *
  97. * Invalidate a range of cache entries in the specified
  98. * address space.
  99. *
  100. * - start - start address (inclusive, page aligned)
  101. * - end - end address (exclusive, page aligned)
  102. * - flags - vma_area_struct flags describing address space
  103. */
  104. ENTRY(v4wb_flush_user_cache_range)
  105. mov ip, #0
  106. sub r3, r1, r0 @ calculate total size
  107. tst r2, #VM_EXEC @ executable region?
  108. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  109. cmp r3, #CACHE_DLIMIT @ total size >= limit?
  110. bhs __flush_whole_cache @ flush whole D cache
  111. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  112. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  113. add r0, r0, #CACHE_DLINESIZE
  114. cmp r0, r1
  115. blo 1b
  116. tst r2, #VM_EXEC
  117. mcrne p15, 0, ip, c7, c10, 4 @ drain write buffer
  118. ret lr
  119. /*
  120. * flush_kern_dcache_area(void *addr, size_t size)
  121. *
  122. * Ensure no D cache aliasing occurs, either with itself or
  123. * the I cache
  124. *
  125. * - addr - kernel address
  126. * - size - region size
  127. */
  128. ENTRY(v4wb_flush_kern_dcache_area)
  129. add r1, r0, r1
  130. /* fall through */
  131. /*
  132. * coherent_kern_range(start, end)
  133. *
  134. * Ensure coherency between the Icache and the Dcache in the
  135. * region described by start. If you have non-snooping
  136. * Harvard caches, you need to implement this function.
  137. *
  138. * - start - virtual start address
  139. * - end - virtual end address
  140. */
  141. ENTRY(v4wb_coherent_kern_range)
  142. /* fall through */
  143. /*
  144. * coherent_user_range(start, end)
  145. *
  146. * Ensure coherency between the Icache and the Dcache in the
  147. * region described by start. If you have non-snooping
  148. * Harvard caches, you need to implement this function.
  149. *
  150. * - start - virtual start address
  151. * - end - virtual end address
  152. */
  153. ENTRY(v4wb_coherent_user_range)
  154. bic r0, r0, #CACHE_DLINESIZE - 1
  155. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  156. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  157. add r0, r0, #CACHE_DLINESIZE
  158. cmp r0, r1
  159. blo 1b
  160. mov r0, #0
  161. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  162. mcr p15, 0, r0, c7, c10, 4 @ drain WB
  163. ret lr
  164. /*
  165. * dma_inv_range(start, end)
  166. *
  167. * Invalidate (discard) the specified virtual address range.
  168. * May not write back any entries. If 'start' or 'end'
  169. * are not cache line aligned, those lines must be written
  170. * back.
  171. *
  172. * - start - virtual start address
  173. * - end - virtual end address
  174. */
  175. v4wb_dma_inv_range:
  176. tst r0, #CACHE_DLINESIZE - 1
  177. bic r0, r0, #CACHE_DLINESIZE - 1
  178. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  179. tst r1, #CACHE_DLINESIZE - 1
  180. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  181. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  182. add r0, r0, #CACHE_DLINESIZE
  183. cmp r0, r1
  184. blo 1b
  185. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  186. ret lr
  187. /*
  188. * dma_clean_range(start, end)
  189. *
  190. * Clean (write back) the specified virtual address range.
  191. *
  192. * - start - virtual start address
  193. * - end - virtual end address
  194. */
  195. v4wb_dma_clean_range:
  196. bic r0, r0, #CACHE_DLINESIZE - 1
  197. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  198. add r0, r0, #CACHE_DLINESIZE
  199. cmp r0, r1
  200. blo 1b
  201. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  202. ret lr
  203. /*
  204. * dma_flush_range(start, end)
  205. *
  206. * Clean and invalidate the specified virtual address range.
  207. *
  208. * - start - virtual start address
  209. * - end - virtual end address
  210. *
  211. * This is actually the same as v4wb_coherent_kern_range()
  212. */
  213. .globl v4wb_dma_flush_range
  214. .set v4wb_dma_flush_range, v4wb_coherent_kern_range
  215. /*
  216. * dma_map_area(start, size, dir)
  217. * - start - kernel virtual start address
  218. * - size - size of region
  219. * - dir - DMA direction
  220. */
  221. ENTRY(v4wb_dma_map_area)
  222. add r1, r1, r0
  223. cmp r2, #DMA_TO_DEVICE
  224. beq v4wb_dma_clean_range
  225. bcs v4wb_dma_inv_range
  226. b v4wb_dma_flush_range
  227. ENDPROC(v4wb_dma_map_area)
  228. /*
  229. * dma_unmap_area(start, size, dir)
  230. * - start - kernel virtual start address
  231. * - size - size of region
  232. * - dir - DMA direction
  233. */
  234. ENTRY(v4wb_dma_unmap_area)
  235. ret lr
  236. ENDPROC(v4wb_dma_unmap_area)
  237. .globl v4wb_flush_kern_cache_louis
  238. .equ v4wb_flush_kern_cache_louis, v4wb_flush_kern_cache_all
  239. __INITDATA
  240. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  241. define_cache_functions v4wb