cache.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * This file contains miscellaneous low-level functions.
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. *
  5. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  6. * and Paul Mackerras.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. *
  13. */
  14. #include <config.h>
  15. #include <config.h>
  16. #include <ppc4xx.h>
  17. #include <ppc_asm.tmpl>
  18. #include <ppc_defs.h>
  19. #include <asm/cache.h>
  20. #include <asm/mmu.h>
  21. /*
  22. * Flush instruction cache.
  23. */
  24. _GLOBAL(invalidate_icache)
  25. iccci r0,r0
  26. isync
  27. blr
  28. /*
  29. * Write any modified data cache blocks out to memory
  30. * and invalidate the corresponding instruction cache blocks.
  31. *
  32. * flush_icache_range(unsigned long start, unsigned long stop)
  33. */
  34. _GLOBAL(flush_icache_range)
  35. li r5,L1_CACHE_BYTES-1
  36. andc r3,r3,r5
  37. subf r4,r3,r4
  38. add r4,r4,r5
  39. srwi. r4,r4,L1_CACHE_SHIFT
  40. beqlr
  41. mtctr r4
  42. mr r6,r3
  43. 1: dcbst 0,r3
  44. addi r3,r3,L1_CACHE_BYTES
  45. bdnz 1b
  46. sync /* wait for dcbst's to get to ram */
  47. mtctr r4
  48. 2: icbi 0,r6
  49. addi r6,r6,L1_CACHE_BYTES
  50. bdnz 2b
  51. sync /* additional sync needed on g4 */
  52. isync
  53. blr
  54. /*
  55. * Write any modified data cache blocks out to memory.
  56. * Does not invalidate the corresponding cache lines (especially for
  57. * any corresponding instruction cache).
  58. *
  59. * clean_dcache_range(unsigned long start, unsigned long stop)
  60. */
  61. _GLOBAL(clean_dcache_range)
  62. li r5,L1_CACHE_BYTES-1
  63. andc r3,r3,r5
  64. subf r4,r3,r4
  65. add r4,r4,r5
  66. srwi. r4,r4,L1_CACHE_SHIFT
  67. beqlr
  68. mtctr r4
  69. 1: dcbst 0,r3
  70. addi r3,r3,L1_CACHE_BYTES
  71. bdnz 1b
  72. sync /* wait for dcbst's to get to ram */
  73. blr
  74. /*
  75. * Write any modified data cache blocks out to memory and invalidate them.
  76. * Does not invalidate the corresponding instruction cache blocks.
  77. *
  78. * flush_dcache_range(unsigned long start, unsigned long stop)
  79. */
  80. _GLOBAL(flush_dcache_range)
  81. li r5,L1_CACHE_BYTES-1
  82. andc r3,r3,r5
  83. subf r4,r3,r4
  84. add r4,r4,r5
  85. srwi. r4,r4,L1_CACHE_SHIFT
  86. beqlr
  87. mtctr r4
  88. 1: dcbf 0,r3
  89. addi r3,r3,L1_CACHE_BYTES
  90. bdnz 1b
  91. sync /* wait for dcbst's to get to ram */
  92. blr
  93. /*
  94. * Like above, but invalidate the D-cache. This is used by the 8xx
  95. * to invalidate the cache so the PPC core doesn't get stale data
  96. * from the CPM (no cache snooping here :-).
  97. *
  98. * invalidate_dcache_range(unsigned long start, unsigned long stop)
  99. */
  100. _GLOBAL(invalidate_dcache_range)
  101. li r5,L1_CACHE_BYTES-1
  102. andc r3,r3,r5
  103. subf r4,r3,r4
  104. add r4,r4,r5
  105. srwi. r4,r4,L1_CACHE_SHIFT
  106. beqlr
  107. mtctr r4
  108. 1: dcbi 0,r3
  109. addi r3,r3,L1_CACHE_BYTES
  110. bdnz 1b
  111. sync /* wait for dcbi's to get to ram */
  112. blr
  113. /*
  114. * 40x cores have 8K or 16K dcache and 32 byte line size.
  115. * 44x has a 32K dcache and 32 byte line size.
  116. * 8xx has 1, 2, 4, 8K variants.
  117. * For now, cover the worst case of the 44x.
  118. * Must be called with external interrupts disabled.
  119. */
  120. #define CACHE_NWAYS 64
  121. #define CACHE_NLINES 32
  122. _GLOBAL(flush_dcache)
  123. li r4,(2 * CACHE_NWAYS * CACHE_NLINES)
  124. mtctr r4
  125. lis r5,0
  126. 1: lwz r3,0(r5) /* Load one word from every line */
  127. addi r5,r5,L1_CACHE_BYTES
  128. bdnz 1b
  129. sync
  130. blr
  131. _GLOBAL(invalidate_dcache)
  132. addi r6,0,0x0000 /* clear GPR 6 */
  133. /* Do loop for # of dcache congruence classes. */
  134. lis r7,(CONFIG_SYS_DCACHE_SIZE / L1_CACHE_BYTES / 2)@ha /* TBS for large sized cache */
  135. ori r7,r7,(CONFIG_SYS_DCACHE_SIZE / L1_CACHE_BYTES / 2)@l
  136. /* NOTE: dccci invalidates both */
  137. mtctr r7 /* ways in the D cache */
  138. ..dcloop:
  139. dccci 0,r6 /* invalidate line */
  140. addi r6,r6,L1_CACHE_BYTES /* bump to next line */
  141. bdnz ..dcloop
  142. sync
  143. blr
  144. /*
  145. * Cache functions.
  146. *
  147. * NOTE: currently the 440s run with dcache _disabled_ once relocated to DRAM,
  148. * although for some cache-ralated calls stubs have to be provided to satisfy
  149. * symbols resolution.
  150. * Icache-related functions are used in POST framework.
  151. *
  152. */
  153. #ifdef CONFIG_440
  154. .globl dcache_disable
  155. .globl dcache_enable
  156. .globl icache_disable
  157. .globl icache_enable
  158. dcache_disable:
  159. dcache_enable:
  160. icache_disable:
  161. icache_enable:
  162. blr
  163. .globl dcache_status
  164. .globl icache_status
  165. dcache_status:
  166. icache_status:
  167. mr r3, 0
  168. blr
  169. #else /* CONFIG_440 */
  170. .globl icache_enable
  171. icache_enable:
  172. mflr r8
  173. bl invalidate_icache
  174. mtlr r8
  175. isync
  176. addis r3,r0, 0xc000 /* set bit 0 */
  177. mticcr r3
  178. blr
  179. .globl icache_disable
  180. icache_disable:
  181. addis r3,r0, 0x0000 /* clear bit 0 */
  182. mticcr r3
  183. isync
  184. blr
  185. .globl icache_status
  186. icache_status:
  187. mficcr r3
  188. srwi r3, r3, 31 /* >>31 => select bit 0 */
  189. blr
  190. .globl dcache_enable
  191. dcache_enable:
  192. mflr r8
  193. bl invalidate_dcache
  194. mtlr r8
  195. isync
  196. addis r3,r0, 0x8000 /* set bit 0 */
  197. mtdccr r3
  198. blr
  199. .globl dcache_disable
  200. dcache_disable:
  201. mflr r8
  202. bl flush_dcache
  203. mtlr r8
  204. addis r3,r0, 0x0000 /* clear bit 0 */
  205. mtdccr r3
  206. blr
  207. .globl dcache_status
  208. dcache_status:
  209. mfdccr r3
  210. srwi r3, r3, 31 /* >>31 => select bit 0 */
  211. blr
  212. #endif /* CONFIG_440 */