cache.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * 40x cores have 8K or 16K dcache and 32 byte line size.
  72. * 44x has a 32K dcache and 32 byte line size.
  73. * 8xx has 1, 2, 4, 8K variants.
  74. * For now, cover the worst case of the 44x.
  75. * Must be called with external interrupts disabled.
  76. */
  77. #define CACHE_NWAYS 64
  78. #define CACHE_NLINES 32
  79. _GLOBAL(flush_dcache)
  80. li r4,(2 * CACHE_NWAYS * CACHE_NLINES)
  81. mtctr r4
  82. lis r5,0
  83. 1: lwz r3,0(r5) /* Load one word from every line */
  84. addi r5,r5,L1_CACHE_BYTES
  85. bdnz 1b
  86. sync
  87. blr
  88. _GLOBAL(invalidate_dcache)
  89. addi r6,0,0x0000 /* clear GPR 6 */
  90. /* Do loop for # of dcache congruence classes. */
  91. lis r7,(CONFIG_SYS_DCACHE_SIZE / L1_CACHE_BYTES / 2)@ha /* TBS for large sized cache */
  92. ori r7,r7,(CONFIG_SYS_DCACHE_SIZE / L1_CACHE_BYTES / 2)@l
  93. /* NOTE: dccci invalidates both */
  94. mtctr r7 /* ways in the D cache */
  95. ..dcloop:
  96. dccci 0,r6 /* invalidate line */
  97. addi r6,r6,L1_CACHE_BYTES /* bump to next line */
  98. bdnz ..dcloop
  99. sync
  100. blr
  101. /*
  102. * Cache functions.
  103. *
  104. * NOTE: currently the 440s run with dcache _disabled_ once relocated to DRAM,
  105. * although for some cache-ralated calls stubs have to be provided to satisfy
  106. * symbols resolution.
  107. * Icache-related functions are used in POST framework.
  108. *
  109. */
  110. #ifdef CONFIG_440
  111. .globl dcache_disable
  112. .globl dcache_enable
  113. .globl icache_disable
  114. .globl icache_enable
  115. dcache_disable:
  116. dcache_enable:
  117. icache_disable:
  118. icache_enable:
  119. blr
  120. .globl dcache_status
  121. .globl icache_status
  122. dcache_status:
  123. icache_status:
  124. mr r3, 0
  125. blr
  126. #else /* CONFIG_440 */
  127. .globl icache_enable
  128. icache_enable:
  129. mflr r8
  130. bl invalidate_icache
  131. mtlr r8
  132. isync
  133. addis r3,r0, 0xc000 /* set bit 0 */
  134. mticcr r3
  135. blr
  136. .globl icache_disable
  137. icache_disable:
  138. addis r3,r0, 0x0000 /* clear bit 0 */
  139. mticcr r3
  140. isync
  141. blr
  142. .globl icache_status
  143. icache_status:
  144. mficcr r3
  145. srwi r3, r3, 31 /* >>31 => select bit 0 */
  146. blr
  147. .globl dcache_enable
  148. dcache_enable:
  149. mflr r8
  150. bl invalidate_dcache
  151. mtlr r8
  152. isync
  153. addis r3,r0, 0x8000 /* set bit 0 */
  154. mtdccr r3
  155. blr
  156. .globl dcache_disable
  157. dcache_disable:
  158. mflr r8
  159. bl flush_dcache
  160. mtlr r8
  161. addis r3,r0, 0x0000 /* clear bit 0 */
  162. mtdccr r3
  163. blr
  164. .globl dcache_status
  165. dcache_status:
  166. mfdccr r3
  167. srwi r3, r3, 31 /* >>31 => select bit 0 */
  168. blr
  169. #endif /* CONFIG_440 */