cache-flush-by-tag.S 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* MN10300 CPU core caching routines, using direct tag flushing
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/sys.h>
  12. #include <linux/linkage.h>
  13. #include <asm/smp.h>
  14. #include <asm/page.h>
  15. #include <asm/cache.h>
  16. #include <asm/irqflags.h>
  17. .am33_2
  18. #ifndef CONFIG_SMP
  19. .globl mn10300_dcache_flush
  20. .globl mn10300_dcache_flush_page
  21. .globl mn10300_dcache_flush_range
  22. .globl mn10300_dcache_flush_range2
  23. .globl mn10300_dcache_flush_inv
  24. .globl mn10300_dcache_flush_inv_page
  25. .globl mn10300_dcache_flush_inv_range
  26. .globl mn10300_dcache_flush_inv_range2
  27. mn10300_dcache_flush = mn10300_local_dcache_flush
  28. mn10300_dcache_flush_page = mn10300_local_dcache_flush_page
  29. mn10300_dcache_flush_range = mn10300_local_dcache_flush_range
  30. mn10300_dcache_flush_range2 = mn10300_local_dcache_flush_range2
  31. mn10300_dcache_flush_inv = mn10300_local_dcache_flush_inv
  32. mn10300_dcache_flush_inv_page = mn10300_local_dcache_flush_inv_page
  33. mn10300_dcache_flush_inv_range = mn10300_local_dcache_flush_inv_range
  34. mn10300_dcache_flush_inv_range2 = mn10300_local_dcache_flush_inv_range2
  35. #endif /* !CONFIG_SMP */
  36. ###############################################################################
  37. #
  38. # void mn10300_local_dcache_flush(void)
  39. # Flush the entire data cache back to RAM
  40. #
  41. ###############################################################################
  42. ALIGN
  43. .globl mn10300_local_dcache_flush
  44. .type mn10300_local_dcache_flush,@function
  45. mn10300_local_dcache_flush:
  46. movhu (CHCTR),d0
  47. btst CHCTR_DCEN,d0
  48. beq mn10300_local_dcache_flush_end
  49. # read the addresses tagged in the cache's tag RAM and attempt to flush
  50. # those addresses specifically
  51. # - we rely on the hardware to filter out invalid tag entry addresses
  52. mov DCACHE_TAG(0,0),a0 # dcache tag RAM access address
  53. mov DCACHE_PURGE(0,0),a1 # dcache purge request address
  54. mov L1_CACHE_NWAYS*L1_CACHE_NENTRIES,d1 # total number of entries
  55. mn10300_local_dcache_flush_loop:
  56. mov (a0),d0
  57. and L1_CACHE_TAG_MASK,d0
  58. or L1_CACHE_TAG_VALID,d0 # retain valid entries in the
  59. # cache
  60. mov d0,(a1) # conditional purge
  61. add L1_CACHE_BYTES,a0
  62. add L1_CACHE_BYTES,a1
  63. add -1,d1
  64. bne mn10300_local_dcache_flush_loop
  65. mn10300_local_dcache_flush_end:
  66. ret [],0
  67. .size mn10300_local_dcache_flush,.-mn10300_local_dcache_flush
  68. ###############################################################################
  69. #
  70. # void mn10300_local_dcache_flush_page(unsigned long start)
  71. # void mn10300_local_dcache_flush_range(unsigned long start, unsigned long end)
  72. # void mn10300_local_dcache_flush_range2(unsigned long start, unsigned long size)
  73. # Flush a range of addresses on a page in the dcache
  74. #
  75. ###############################################################################
  76. ALIGN
  77. .globl mn10300_local_dcache_flush_page
  78. .globl mn10300_local_dcache_flush_range
  79. .globl mn10300_local_dcache_flush_range2
  80. .type mn10300_local_dcache_flush_page,@function
  81. .type mn10300_local_dcache_flush_range,@function
  82. .type mn10300_local_dcache_flush_range2,@function
  83. mn10300_local_dcache_flush_page:
  84. and ~(PAGE_SIZE-1),d0
  85. mov PAGE_SIZE,d1
  86. mn10300_local_dcache_flush_range2:
  87. add d0,d1
  88. mn10300_local_dcache_flush_range:
  89. movm [d2],(sp)
  90. movhu (CHCTR),d2
  91. btst CHCTR_DCEN,d2
  92. beq mn10300_local_dcache_flush_range_end
  93. sub d0,d1,a0
  94. cmp MN10300_DCACHE_FLUSH_BORDER,a0
  95. ble 1f
  96. movm (sp),[d2]
  97. bra mn10300_local_dcache_flush
  98. 1:
  99. # round start addr down
  100. and L1_CACHE_TAG_MASK,d0
  101. mov d0,a1
  102. add L1_CACHE_BYTES,d1 # round end addr up
  103. and L1_CACHE_TAG_MASK,d1
  104. # write a request to flush all instances of an address from the cache
  105. mov DCACHE_PURGE(0,0),a0
  106. mov a1,d0
  107. and L1_CACHE_TAG_ENTRY,d0
  108. add d0,a0 # starting dcache purge control
  109. # reg address
  110. sub a1,d1
  111. lsr L1_CACHE_SHIFT,d1 # total number of entries to
  112. # examine
  113. or L1_CACHE_TAG_VALID,a1 # retain valid entries in the
  114. # cache
  115. mn10300_local_dcache_flush_range_loop:
  116. mov a1,(L1_CACHE_WAYDISP*0,a0) # conditionally purge this line
  117. # all ways
  118. add L1_CACHE_BYTES,a0
  119. add L1_CACHE_BYTES,a1
  120. and ~L1_CACHE_WAYDISP,a0 # make sure way stay on way 0
  121. add -1,d1
  122. bne mn10300_local_dcache_flush_range_loop
  123. mn10300_local_dcache_flush_range_end:
  124. ret [d2],4
  125. .size mn10300_local_dcache_flush_page,.-mn10300_local_dcache_flush_page
  126. .size mn10300_local_dcache_flush_range,.-mn10300_local_dcache_flush_range
  127. .size mn10300_local_dcache_flush_range2,.-mn10300_local_dcache_flush_range2
  128. ###############################################################################
  129. #
  130. # void mn10300_local_dcache_flush_inv(void)
  131. # Flush the entire data cache and invalidate all entries
  132. #
  133. ###############################################################################
  134. ALIGN
  135. .globl mn10300_local_dcache_flush_inv
  136. .type mn10300_local_dcache_flush_inv,@function
  137. mn10300_local_dcache_flush_inv:
  138. movhu (CHCTR),d0
  139. btst CHCTR_DCEN,d0
  140. beq mn10300_local_dcache_flush_inv_end
  141. mov L1_CACHE_NENTRIES,d1
  142. clr a1
  143. mn10300_local_dcache_flush_inv_loop:
  144. mov (DCACHE_PURGE_WAY0(0),a1),d0 # unconditional purge
  145. mov (DCACHE_PURGE_WAY1(0),a1),d0 # unconditional purge
  146. mov (DCACHE_PURGE_WAY2(0),a1),d0 # unconditional purge
  147. mov (DCACHE_PURGE_WAY3(0),a1),d0 # unconditional purge
  148. add L1_CACHE_BYTES,a1
  149. add -1,d1
  150. bne mn10300_local_dcache_flush_inv_loop
  151. mn10300_local_dcache_flush_inv_end:
  152. ret [],0
  153. .size mn10300_local_dcache_flush_inv,.-mn10300_local_dcache_flush_inv
  154. ###############################################################################
  155. #
  156. # void mn10300_local_dcache_flush_inv_page(unsigned long start)
  157. # void mn10300_local_dcache_flush_inv_range(unsigned long start, unsigned long end)
  158. # void mn10300_local_dcache_flush_inv_range2(unsigned long start, unsigned long size)
  159. # Flush and invalidate a range of addresses on a page in the dcache
  160. #
  161. ###############################################################################
  162. ALIGN
  163. .globl mn10300_local_dcache_flush_inv_page
  164. .globl mn10300_local_dcache_flush_inv_range
  165. .globl mn10300_local_dcache_flush_inv_range2
  166. .type mn10300_local_dcache_flush_inv_page,@function
  167. .type mn10300_local_dcache_flush_inv_range,@function
  168. .type mn10300_local_dcache_flush_inv_range2,@function
  169. mn10300_local_dcache_flush_inv_page:
  170. and ~(PAGE_SIZE-1),d0
  171. mov PAGE_SIZE,d1
  172. mn10300_local_dcache_flush_inv_range2:
  173. add d0,d1
  174. mn10300_local_dcache_flush_inv_range:
  175. movm [d2],(sp)
  176. movhu (CHCTR),d2
  177. btst CHCTR_DCEN,d2
  178. beq mn10300_local_dcache_flush_inv_range_end
  179. sub d0,d1,a0
  180. cmp MN10300_DCACHE_FLUSH_INV_BORDER,a0
  181. ble 1f
  182. movm (sp),[d2]
  183. bra mn10300_local_dcache_flush_inv
  184. 1:
  185. and L1_CACHE_TAG_MASK,d0 # round start addr down
  186. mov d0,a1
  187. add L1_CACHE_BYTES,d1 # round end addr up
  188. and L1_CACHE_TAG_MASK,d1
  189. # write a request to flush and invalidate all instances of an address
  190. # from the cache
  191. mov DCACHE_PURGE(0,0),a0
  192. mov a1,d0
  193. and L1_CACHE_TAG_ENTRY,d0
  194. add d0,a0 # starting dcache purge control
  195. # reg address
  196. sub a1,d1
  197. lsr L1_CACHE_SHIFT,d1 # total number of entries to
  198. # examine
  199. mn10300_local_dcache_flush_inv_range_loop:
  200. mov a1,(L1_CACHE_WAYDISP*0,a0) # conditionally purge this line
  201. # in all ways
  202. add L1_CACHE_BYTES,a0
  203. add L1_CACHE_BYTES,a1
  204. and ~L1_CACHE_WAYDISP,a0 # make sure way stay on way 0
  205. add -1,d1
  206. bne mn10300_local_dcache_flush_inv_range_loop
  207. mn10300_local_dcache_flush_inv_range_end:
  208. ret [d2],4
  209. .size mn10300_local_dcache_flush_inv_page,.-mn10300_local_dcache_flush_inv_page
  210. .size mn10300_local_dcache_flush_inv_range,.-mn10300_local_dcache_flush_inv_range
  211. .size mn10300_local_dcache_flush_inv_range2,.-mn10300_local_dcache_flush_inv_range2