sc-ip22.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * sc-ip22.c: Indy cache management functions.
  3. *
  4. * Copyright (C) 1997, 2001 Ralf Baechle (ralf@gnu.org),
  5. * derived from r4xx0.c by David S. Miller (davem@davemloft.net).
  6. */
  7. #include <linux/init.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/mm.h>
  11. #include <asm/bcache.h>
  12. #include <asm/page.h>
  13. #include <asm/pgtable.h>
  14. #include <asm/bootinfo.h>
  15. #include <asm/sgi/ip22.h>
  16. #include <asm/sgi/mc.h>
  17. /* Secondary cache size in bytes, if present. */
  18. static unsigned long scache_size;
  19. #undef DEBUG_CACHE
  20. #define SC_SIZE 0x00080000
  21. #define SC_LINE 32
  22. #define CI_MASK (SC_SIZE - SC_LINE)
  23. #define SC_INDEX(n) ((n) & CI_MASK)
  24. static inline void indy_sc_wipe(unsigned long first, unsigned long last)
  25. {
  26. unsigned long tmp;
  27. __asm__ __volatile__(
  28. " .set push # indy_sc_wipe \n"
  29. " .set noreorder \n"
  30. " .set mips3 \n"
  31. " .set noat \n"
  32. " mfc0 %2, $12 \n"
  33. " li $1, 0x80 # Go 64 bit \n"
  34. " mtc0 $1, $12 \n"
  35. " \n"
  36. " # \n"
  37. " # Open code a dli $1, 0x9000000080000000 \n"
  38. " # \n"
  39. " # Required because binutils 2.25 will happily accept \n"
  40. " # 64 bit instructions in .set mips3 mode but puke on \n"
  41. " # 64 bit constants when generating 32 bit ELF \n"
  42. " # \n"
  43. " lui $1,0x9000 \n"
  44. " dsll $1,$1,0x10 \n"
  45. " ori $1,$1,0x8000 \n"
  46. " dsll $1,$1,0x10 \n"
  47. " \n"
  48. " or %0, $1 # first line to flush \n"
  49. " or %1, $1 # last line to flush \n"
  50. " .set at \n"
  51. " \n"
  52. "1: sw $0, 0(%0) \n"
  53. " bne %0, %1, 1b \n"
  54. " daddu %0, 32 \n"
  55. " \n"
  56. " mtc0 %2, $12 # Back to 32 bit \n"
  57. " nop # pipeline hazard \n"
  58. " nop \n"
  59. " nop \n"
  60. " nop \n"
  61. " .set pop \n"
  62. : "=r" (first), "=r" (last), "=&r" (tmp)
  63. : "0" (first), "1" (last));
  64. }
  65. static void indy_sc_wback_invalidate(unsigned long addr, unsigned long size)
  66. {
  67. unsigned long first_line, last_line;
  68. unsigned long flags;
  69. #ifdef DEBUG_CACHE
  70. printk("indy_sc_wback_invalidate[%08lx,%08lx]", addr, size);
  71. #endif
  72. /* Catch bad driver code */
  73. BUG_ON(size == 0);
  74. /* Which lines to flush? */
  75. first_line = SC_INDEX(addr);
  76. last_line = SC_INDEX(addr + size - 1);
  77. local_irq_save(flags);
  78. if (first_line <= last_line) {
  79. indy_sc_wipe(first_line, last_line);
  80. goto out;
  81. }
  82. indy_sc_wipe(first_line, SC_SIZE - SC_LINE);
  83. indy_sc_wipe(0, last_line);
  84. out:
  85. local_irq_restore(flags);
  86. }
  87. static void indy_sc_enable(void)
  88. {
  89. unsigned long addr, tmp1, tmp2;
  90. /* This is really cool... */
  91. #ifdef DEBUG_CACHE
  92. printk("Enabling R4600 SCACHE\n");
  93. #endif
  94. __asm__ __volatile__(
  95. ".set\tpush\n\t"
  96. ".set\tnoreorder\n\t"
  97. ".set\tmips3\n\t"
  98. "mfc0\t%2, $12\n\t"
  99. "nop; nop; nop; nop;\n\t"
  100. "li\t%1, 0x80\n\t"
  101. "mtc0\t%1, $12\n\t"
  102. "nop; nop; nop; nop;\n\t"
  103. "li\t%0, 0x1\n\t"
  104. "dsll\t%0, 31\n\t"
  105. "lui\t%1, 0x9000\n\t"
  106. "dsll32\t%1, 0\n\t"
  107. "or\t%0, %1, %0\n\t"
  108. "sb\t$0, 0(%0)\n\t"
  109. "mtc0\t$0, $12\n\t"
  110. "nop; nop; nop; nop;\n\t"
  111. "mtc0\t%2, $12\n\t"
  112. "nop; nop; nop; nop;\n\t"
  113. ".set\tpop"
  114. : "=r" (tmp1), "=r" (tmp2), "=r" (addr));
  115. }
  116. static void indy_sc_disable(void)
  117. {
  118. unsigned long tmp1, tmp2, tmp3;
  119. #ifdef DEBUG_CACHE
  120. printk("Disabling R4600 SCACHE\n");
  121. #endif
  122. __asm__ __volatile__(
  123. ".set\tpush\n\t"
  124. ".set\tnoreorder\n\t"
  125. ".set\tmips3\n\t"
  126. "li\t%0, 0x1\n\t"
  127. "dsll\t%0, 31\n\t"
  128. "lui\t%1, 0x9000\n\t"
  129. "dsll32\t%1, 0\n\t"
  130. "or\t%0, %1, %0\n\t"
  131. "mfc0\t%2, $12\n\t"
  132. "nop; nop; nop; nop\n\t"
  133. "li\t%1, 0x80\n\t"
  134. "mtc0\t%1, $12\n\t"
  135. "nop; nop; nop; nop\n\t"
  136. "sh\t$0, 0(%0)\n\t"
  137. "mtc0\t$0, $12\n\t"
  138. "nop; nop; nop; nop\n\t"
  139. "mtc0\t%2, $12\n\t"
  140. "nop; nop; nop; nop\n\t"
  141. ".set\tpop"
  142. : "=r" (tmp1), "=r" (tmp2), "=r" (tmp3));
  143. }
  144. static inline int __init indy_sc_probe(void)
  145. {
  146. unsigned int size = ip22_eeprom_read(&sgimc->eeprom, 17);
  147. if (size == 0)
  148. return 0;
  149. size <<= PAGE_SHIFT;
  150. printk(KERN_INFO "R4600/R5000 SCACHE size %dK, linesize 32 bytes.\n",
  151. size >> 10);
  152. scache_size = size;
  153. return 1;
  154. }
  155. /* XXX Check with wje if the Indy caches can differentiate between
  156. writeback + invalidate and just invalidate. */
  157. static struct bcache_ops indy_sc_ops = {
  158. .bc_enable = indy_sc_enable,
  159. .bc_disable = indy_sc_disable,
  160. .bc_wback_inv = indy_sc_wback_invalidate,
  161. .bc_inv = indy_sc_wback_invalidate
  162. };
  163. void indy_sc_init(void)
  164. {
  165. if (indy_sc_probe()) {
  166. indy_sc_enable();
  167. bcops = &indy_sc_ops;
  168. }
  169. }