cache.S 4.7 KB

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