cache-v4wb.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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/config.h>
  11. #include <linux/linkage.h>
  12. #include <linux/init.h>
  13. #include <asm/hardware.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 maintainence 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. /*
  46. * flush_user_cache_all()
  47. *
  48. * Clean and invalidate all cache entries in a particular address
  49. * space.
  50. */
  51. ENTRY(v4wb_flush_user_cache_all)
  52. /* FALLTHROUGH */
  53. /*
  54. * flush_kern_cache_all()
  55. *
  56. * Clean and invalidate the entire cache.
  57. */
  58. ENTRY(v4wb_flush_kern_cache_all)
  59. mov ip, #0
  60. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  61. __flush_whole_cache:
  62. mov r0, #FLUSH_BASE
  63. add r1, r0, #CACHE_DSIZE
  64. 1: ldr r2, [r0], #32
  65. cmp r0, r1
  66. blo 1b
  67. mcr p15, 0, ip, c7, c10, 4 @ drain write buffer
  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(v4wb_flush_user_cache_range)
  80. sub r3, r1, r0 @ calculate total size
  81. tst r2, #VM_EXEC @ executable region?
  82. mcrne p15, 0, ip, c7, c5, 0 @ invalidate I cache
  83. cmp r3, #CACHE_DLIMIT @ total size >= limit?
  84. bhs __flush_whole_cache @ flush whole D cache
  85. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  86. mcr p15, 0, r0, c7, c6, 1 @ 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, c10, 4 @ drain write buffer
  92. mov pc, lr
  93. /*
  94. * flush_kern_dcache_page(void *page)
  95. *
  96. * Ensure no D cache aliasing occurs, either with itself or
  97. * the I cache
  98. *
  99. * - addr - page aligned address
  100. */
  101. ENTRY(v4wb_flush_kern_dcache_page)
  102. add r1, r0, #PAGE_SZ
  103. /* fall through */
  104. /*
  105. * coherent_kern_range(start, end)
  106. *
  107. * Ensure coherency between the Icache and the Dcache in the
  108. * region described by start. If you have non-snooping
  109. * Harvard caches, you need to implement this function.
  110. *
  111. * - start - virtual start address
  112. * - end - virtual end address
  113. */
  114. ENTRY(v4wb_coherent_kern_range)
  115. /* fall through */
  116. /*
  117. * coherent_user_range(start, end)
  118. *
  119. * Ensure coherency between the Icache and the Dcache in the
  120. * region described by start. If you have non-snooping
  121. * Harvard caches, you need to implement this function.
  122. *
  123. * - start - virtual start address
  124. * - end - virtual end address
  125. */
  126. ENTRY(v4wb_coherent_user_range)
  127. bic r0, r0, #CACHE_DLINESIZE - 1
  128. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  129. mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  130. add r0, r0, #CACHE_DLINESIZE
  131. cmp r0, r1
  132. blo 1b
  133. mov ip, #0
  134. mcr p15, 0, ip, c7, c5, 0 @ invalidate I cache
  135. mcr p15, 0, ip, c7, c10, 4 @ drain WB
  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(v4wb_dma_inv_range)
  149. tst r0, #CACHE_DLINESIZE - 1
  150. bic r0, r0, #CACHE_DLINESIZE - 1
  151. mcrne p15, 0, r0, c7, c10, 1 @ clean D entry
  152. tst r1, #CACHE_DLINESIZE - 1
  153. mcrne p15, 0, r1, c7, c10, 1 @ clean D entry
  154. 1: mcr p15, 0, r0, c7, c6, 1 @ invalidate D entry
  155. add r0, r0, #CACHE_DLINESIZE
  156. cmp r0, r1
  157. blo 1b
  158. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  159. mov pc, lr
  160. /*
  161. * dma_clean_range(start, end)
  162. *
  163. * Clean (write back) the specified virtual address range.
  164. *
  165. * - start - virtual start address
  166. * - end - virtual end address
  167. */
  168. ENTRY(v4wb_dma_clean_range)
  169. bic r0, r0, #CACHE_DLINESIZE - 1
  170. 1: mcr p15, 0, r0, c7, c10, 1 @ clean D entry
  171. add r0, r0, #CACHE_DLINESIZE
  172. cmp r0, r1
  173. blo 1b
  174. mcr p15, 0, r0, c7, c10, 4 @ drain write buffer
  175. mov pc, lr
  176. /*
  177. * dma_flush_range(start, end)
  178. *
  179. * Clean and invalidate the specified virtual address range.
  180. *
  181. * - start - virtual start address
  182. * - end - virtual end address
  183. *
  184. * This is actually the same as v4wb_coherent_kern_range()
  185. */
  186. .globl v4wb_dma_flush_range
  187. .set v4wb_dma_flush_range, v4wb_coherent_kern_range
  188. __INITDATA
  189. .type v4wb_cache_fns, #object
  190. ENTRY(v4wb_cache_fns)
  191. .long v4wb_flush_kern_cache_all
  192. .long v4wb_flush_user_cache_all
  193. .long v4wb_flush_user_cache_range
  194. .long v4wb_coherent_kern_range
  195. .long v4wb_coherent_user_range
  196. .long v4wb_flush_kern_dcache_page
  197. .long v4wb_dma_inv_range
  198. .long v4wb_dma_clean_range
  199. .long v4wb_dma_flush_range
  200. .size v4wb_cache_fns, . - v4wb_cache_fns