cache-fa.S 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * linux/arch/arm/mm/cache-fa.S
  3. *
  4. * Copyright (C) 2005 Faraday Corp.
  5. * Copyright (C) 2008-2009 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
  6. *
  7. * Based on cache-v4wb.S:
  8. * Copyright (C) 1997-2002 Russell king
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * Processors: FA520 FA526 FA626
  15. */
  16. #include <linux/linkage.h>
  17. #include <linux/init.h>
  18. #include <asm/assembler.h>
  19. #include <asm/memory.h>
  20. #include <asm/page.h>
  21. #include "proc-macros.S"
  22. /*
  23. * The size of one data cache line.
  24. */
  25. #define CACHE_DLINESIZE 16
  26. /*
  27. * The total size of the data cache.
  28. */
  29. #ifdef CONFIG_ARCH_GEMINI
  30. #define CACHE_DSIZE 8192
  31. #else
  32. #define CACHE_DSIZE 16384
  33. #endif
  34. /* FIXME: put optimal value here. Current one is just estimation */
  35. #define CACHE_DLIMIT (CACHE_DSIZE * 2)
  36. /*
  37. * flush_icache_all()
  38. *
  39. * Unconditionally clean and invalidate the entire icache.
  40. */
  41. ENTRY(fa_flush_icache_all)
  42. mov r0, #0
  43. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  44. ret lr
  45. ENDPROC(fa_flush_icache_all)
  46. /*
  47. * flush_user_cache_all()
  48. *
  49. * Clean and invalidate all cache entries in a particular address
  50. * space.
  51. */
  52. ENTRY(fa_flush_user_cache_all)
  53. /* FALLTHROUGH */
  54. /*
  55. * flush_kern_cache_all()
  56. *
  57. * Clean and invalidate the entire cache.
  58. */
  59. ENTRY(fa_flush_kern_cache_all)
  60. mov ip, #0
  61. mov r2, #VM_EXEC
  62. __flush_whole_cache:
  63. mcr p15, 0, ip, c7, c14, 0 @ clean/invalidate D cache
  64. tst r2, #VM_EXEC
  65. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  66. mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
  67. mcrne p15, 0, ip, c7, c10, 4 @ drain write buffer
  68. mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
  69. ret lr
  70. /*
  71. * flush_user_cache_range(start, end, flags)
  72. *
  73. * Invalidate a range of cache entries in the specified
  74. * address space.
  75. *
  76. * - start - start address (inclusive, page aligned)
  77. * - end - end address (exclusive, page aligned)
  78. * - flags - vma_area_struct flags describing address space
  79. */
  80. ENTRY(fa_flush_user_cache_range)
  81. mov ip, #0
  82. sub r3, r1, r0 @ calculate total size
  83. cmp r3, #CACHE_DLIMIT @ total size >= limit?
  84. bhs __flush_whole_cache @ flush whole D cache
  85. 1: tst r2, #VM_EXEC
  86. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I line
  87. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  88. add r0, r0, #CACHE_DLINESIZE
  89. cmp r0, r1
  90. blo 1b
  91. tst r2, #VM_EXEC
  92. mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
  93. mcrne p15, 0, ip, c7, c10, 4 @ data write barrier
  94. mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
  95. ret lr
  96. /*
  97. * coherent_kern_range(start, end)
  98. *
  99. * Ensure coherency between the Icache and the Dcache in the
  100. * region described by start. If you have non-snooping
  101. * Harvard caches, you need to implement this function.
  102. *
  103. * - start - virtual start address
  104. * - end - virtual end address
  105. */
  106. ENTRY(fa_coherent_kern_range)
  107. /* fall through */
  108. /*
  109. * coherent_user_range(start, end)
  110. *
  111. * Ensure coherency between the Icache and the Dcache in the
  112. * region described by start. If you have non-snooping
  113. * Harvard caches, you need to implement this function.
  114. *
  115. * - start - virtual start address
  116. * - end - virtual end address
  117. */
  118. ENTRY(fa_coherent_user_range)
  119. bic r0, r0, #CACHE_DLINESIZE - 1
  120. 1: mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  121. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  122. add r0, r0, #CACHE_DLINESIZE
  123. cmp r0, r1
  124. blo 1b
  125. mov r0, #0
  126. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
  127. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  128. mcr p15, 0, r0, c7, c5, 4 @ prefetch flush
  129. ret lr
  130. /*
  131. * flush_kern_dcache_area(void *addr, size_t size)
  132. *
  133. * Ensure that the data held in the page kaddr is written back
  134. * to the page in question.
  135. *
  136. * - addr - kernel address
  137. * - size - size of region
  138. */
  139. ENTRY(fa_flush_kern_dcache_area)
  140. add r1, r0, r1
  141. 1: mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  142. add r0, r0, #CACHE_DLINESIZE
  143. cmp r0, r1
  144. blo 1b
  145. mov r0, #0
  146. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  147. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  148. ret lr
  149. /*
  150. * dma_inv_range(start, end)
  151. *
  152. * Invalidate (discard) the specified virtual address range.
  153. * May not write back any entries. If 'start' or 'end'
  154. * are not cache line aligned, those lines must be written
  155. * back.
  156. *
  157. * - start - virtual start address
  158. * - end - virtual end address
  159. */
  160. fa_dma_inv_range:
  161. tst r0, #CACHE_DLINESIZE - 1
  162. bic r0, r0, #CACHE_DLINESIZE - 1
  163. mcrne p15, 0, r0, c7, c14, 1 @ clean & invalidate D entry
  164. tst r1, #CACHE_DLINESIZE - 1
  165. bic r1, r1, #CACHE_DLINESIZE - 1
  166. mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D entry
  167. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  168. add r0, r0, #CACHE_DLINESIZE
  169. cmp r0, r1
  170. blo 1b
  171. mov r0, #0
  172. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  173. ret lr
  174. /*
  175. * dma_clean_range(start, end)
  176. *
  177. * Clean (write back) the specified virtual address range.
  178. *
  179. * - start - virtual start address
  180. * - end - virtual end address
  181. */
  182. fa_dma_clean_range:
  183. bic r0, r0, #CACHE_DLINESIZE - 1
  184. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  185. add r0, r0, #CACHE_DLINESIZE
  186. cmp r0, r1
  187. blo 1b
  188. mov r0, #0
  189. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  190. ret lr
  191. /*
  192. * dma_flush_range(start,end)
  193. * - start - virtual start address of region
  194. * - end - virtual end address of region
  195. */
  196. ENTRY(fa_dma_flush_range)
  197. bic r0, r0, #CACHE_DLINESIZE - 1
  198. 1: mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D entry
  199. add r0, r0, #CACHE_DLINESIZE
  200. cmp r0, r1
  201. blo 1b
  202. mov r0, #0
  203. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  204. ret lr
  205. /*
  206. * dma_map_area(start, size, dir)
  207. * - start - kernel virtual start address
  208. * - size - size of region
  209. * - dir - DMA direction
  210. */
  211. ENTRY(fa_dma_map_area)
  212. add r1, r1, r0
  213. cmp r2, #DMA_TO_DEVICE
  214. beq fa_dma_clean_range
  215. bcs fa_dma_inv_range
  216. b fa_dma_flush_range
  217. ENDPROC(fa_dma_map_area)
  218. /*
  219. * dma_unmap_area(start, size, dir)
  220. * - start - kernel virtual start address
  221. * - size - size of region
  222. * - dir - DMA direction
  223. */
  224. ENTRY(fa_dma_unmap_area)
  225. ret lr
  226. ENDPROC(fa_dma_unmap_area)
  227. .globl fa_flush_kern_cache_louis
  228. .equ fa_flush_kern_cache_louis, fa_flush_kern_cache_all
  229. __INITDATA
  230. @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
  231. define_cache_functions fa