cache-fa.S 6.1 KB

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