cache-fa.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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_user_cache_all()
  37. *
  38. * Clean and invalidate all cache entries in a particular address
  39. * space.
  40. */
  41. ENTRY(fa_flush_user_cache_all)
  42. /* FALLTHROUGH */
  43. /*
  44. * flush_kern_cache_all()
  45. *
  46. * Clean and invalidate the entire cache.
  47. */
  48. ENTRY(fa_flush_kern_cache_all)
  49. mov ip, #0
  50. mov r2, #VM_EXEC
  51. __flush_whole_cache:
  52. mcr p15, 0, ip, c7, c14, 0 @ clean/invalidate D cache
  53. tst r2, #VM_EXEC
  54. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  55. mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
  56. mcrne p15, 0, ip, c7, c10, 4 @ drain write buffer
  57. mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
  58. mov pc, lr
  59. /*
  60. * flush_user_cache_range(start, end, flags)
  61. *
  62. * Invalidate a range of cache entries in the specified
  63. * address space.
  64. *
  65. * - start - start address (inclusive, page aligned)
  66. * - end - end address (exclusive, page aligned)
  67. * - flags - vma_area_struct flags describing address space
  68. */
  69. ENTRY(fa_flush_user_cache_range)
  70. mov ip, #0
  71. sub r3, r1, r0 @ calculate total size
  72. cmp r3, #CACHE_DLIMIT @ total size >= limit?
  73. bhs __flush_whole_cache @ flush whole D cache
  74. 1: tst r2, #VM_EXEC
  75. mcrne p15, 0, r0, c7, c5, 1 @ invalidate I line
  76. mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  77. add r0, r0, #CACHE_DLINESIZE
  78. cmp r0, r1
  79. blo 1b
  80. tst r2, #VM_EXEC
  81. mcrne p15, 0, ip, c7, c5, 6 @ invalidate BTB
  82. mcrne p15, 0, ip, c7, c10, 4 @ data write barrier
  83. mcrne p15, 0, ip, c7, c5, 4 @ prefetch flush
  84. mov pc, lr
  85. /*
  86. * coherent_kern_range(start, end)
  87. *
  88. * Ensure coherency between the Icache and the Dcache in the
  89. * region described by start. If you have non-snooping
  90. * Harvard caches, you need to implement this function.
  91. *
  92. * - start - virtual start address
  93. * - end - virtual end address
  94. */
  95. ENTRY(fa_coherent_kern_range)
  96. /* fall through */
  97. /*
  98. * coherent_user_range(start, end)
  99. *
  100. * Ensure coherency between the Icache and the Dcache in the
  101. * region described by start. If you have non-snooping
  102. * Harvard caches, you need to implement this function.
  103. *
  104. * - start - virtual start address
  105. * - end - virtual end address
  106. */
  107. ENTRY(fa_coherent_user_range)
  108. bic r0, r0, #CACHE_DLINESIZE - 1
  109. 1: mcr p15, 0, r0, c7, c14, 1 @ clean and invalidate D entry
  110. mcr p15, 0, r0, c7, c5, 1 @ invalidate I entry
  111. add r0, r0, #CACHE_DLINESIZE
  112. cmp r0, r1
  113. blo 1b
  114. mov r0, #0
  115. mcr p15, 0, r0, c7, c5, 6 @ invalidate BTB
  116. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  117. mcr p15, 0, r0, c7, c5, 4 @ prefetch flush
  118. mov pc, lr
  119. /*
  120. * flush_kern_dcache_page(kaddr)
  121. *
  122. * Ensure that the data held in the page kaddr is written back
  123. * to the page in question.
  124. *
  125. * - kaddr - kernel address (guaranteed to be page aligned)
  126. */
  127. ENTRY(fa_flush_kern_dcache_page)
  128. add r1, r0, #PAGE_SZ
  129. 1: mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D line
  130. add r0, r0, #CACHE_DLINESIZE
  131. cmp r0, r1
  132. blo 1b
  133. mov r0, #0
  134. mcr p15, 0, r0, c7, c5, 0 @ invalidate I cache
  135. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  136. mov pc, lr
  137. /*
  138. * dma_inv_range(start, end)
  139. *
  140. * Invalidate (discard) the specified virtual address range.
  141. * May not write back any entries. If 'start' or 'end'
  142. * are not cache line aligned, those lines must be written
  143. * back.
  144. *
  145. * - start - virtual start address
  146. * - end - virtual end address
  147. */
  148. ENTRY(fa_dma_inv_range)
  149. tst r0, #CACHE_DLINESIZE - 1
  150. bic r0, r0, #CACHE_DLINESIZE - 1
  151. mcrne p15, 0, r0, c7, c14, 1 @ clean & invalidate D entry
  152. tst r1, #CACHE_DLINESIZE - 1
  153. bic r1, r1, #CACHE_DLINESIZE - 1
  154. mcrne p15, 0, r1, c7, c14, 1 @ clean & invalidate D entry
  155. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  156. add r0, r0, #CACHE_DLINESIZE
  157. cmp r0, r1
  158. blo 1b
  159. mov r0, #0
  160. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  161. mov pc, lr
  162. /*
  163. * dma_clean_range(start, end)
  164. *
  165. * Clean (write back) the specified virtual address range.
  166. *
  167. * - start - virtual start address
  168. * - end - virtual end address
  169. */
  170. ENTRY(fa_dma_clean_range)
  171. bic r0, r0, #CACHE_DLINESIZE - 1
  172. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  173. add r0, r0, #CACHE_DLINESIZE
  174. cmp r0, r1
  175. blo 1b
  176. mov r0, #0
  177. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  178. mov pc, lr
  179. /*
  180. * dma_flush_range(start,end)
  181. * - start - virtual start address of region
  182. * - end - virtual end address of region
  183. */
  184. ENTRY(fa_dma_flush_range)
  185. bic r0, r0, #CACHE_DLINESIZE - 1
  186. 1: mcr p15, 0, r0, c7, c14, 1 @ clean & invalidate D entry
  187. add r0, r0, #CACHE_DLINESIZE
  188. cmp r0, r1
  189. blo 1b
  190. mov r0, #0
  191. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  192. mov pc, lr
  193. __INITDATA
  194. .type fa_cache_fns, #object
  195. ENTRY(fa_cache_fns)
  196. .long fa_flush_kern_cache_all
  197. .long fa_flush_user_cache_all
  198. .long fa_flush_user_cache_range
  199. .long fa_coherent_kern_range
  200. .long fa_coherent_user_range
  201. .long fa_flush_kern_dcache_page
  202. .long fa_dma_inv_range
  203. .long fa_dma_clean_range
  204. .long fa_dma_flush_range
  205. .size fa_cache_fns, . - fa_cache_fns