sc-ip22.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 (dm@engr.sgi.com).
  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/system.h>
  15. #include <asm/bootinfo.h>
  16. #include <asm/sgi/ip22.h>
  17. #include <asm/sgi/mc.h>
  18. /* Secondary cache size in bytes, if present. */
  19. static unsigned long scache_size;
  20. #undef DEBUG_CACHE
  21. #define SC_SIZE 0x00080000
  22. #define SC_LINE 32
  23. #define CI_MASK (SC_SIZE - SC_LINE)
  24. #define SC_INDEX(n) ((n) & CI_MASK)
  25. static inline void indy_sc_wipe(unsigned long first, unsigned long last)
  26. {
  27. unsigned long tmp;
  28. __asm__ __volatile__(
  29. ".set\tpush\t\t\t# indy_sc_wipe\n\t"
  30. ".set\tnoreorder\n\t"
  31. ".set\tmips3\n\t"
  32. ".set\tnoat\n\t"
  33. "mfc0\t%2, $12\n\t"
  34. "li\t$1, 0x80\t\t\t# Go 64 bit\n\t"
  35. "mtc0\t$1, $12\n\t"
  36. "dli\t$1, 0x9000000080000000\n\t"
  37. "or\t%0, $1\t\t\t# first line to flush\n\t"
  38. "or\t%1, $1\t\t\t# last line to flush\n\t"
  39. ".set\tat\n\t"
  40. "1:\tsw\t$0, 0(%0)\n\t"
  41. "bne\t%0, %1, 1b\n\t"
  42. " daddu\t%0, 32\n\t"
  43. "mtc0\t%2, $12\t\t\t# Back to 32 bit\n\t"
  44. "nop; nop; nop; nop;\n\t"
  45. ".set\tpop"
  46. : "=r" (first), "=r" (last), "=&r" (tmp)
  47. : "0" (first), "1" (last));
  48. }
  49. static void indy_sc_wback_invalidate(unsigned long addr, unsigned long size)
  50. {
  51. unsigned long first_line, last_line;
  52. unsigned long flags;
  53. #ifdef DEBUG_CACHE
  54. printk("indy_sc_wback_invalidate[%08lx,%08lx]", addr, size);
  55. #endif
  56. /* Catch bad driver code */
  57. BUG_ON(size == 0);
  58. /* Which lines to flush? */
  59. first_line = SC_INDEX(addr);
  60. last_line = SC_INDEX(addr + size - 1);
  61. local_irq_save(flags);
  62. if (first_line <= last_line) {
  63. indy_sc_wipe(first_line, last_line);
  64. goto out;
  65. }
  66. indy_sc_wipe(first_line, SC_SIZE - SC_LINE);
  67. indy_sc_wipe(0, last_line);
  68. out:
  69. local_irq_restore(flags);
  70. }
  71. static void indy_sc_enable(void)
  72. {
  73. unsigned long addr, tmp1, tmp2;
  74. /* This is really cool... */
  75. #ifdef DEBUG_CACHE
  76. printk("Enabling R4600 SCACHE\n");
  77. #endif
  78. __asm__ __volatile__(
  79. ".set\tpush\n\t"
  80. ".set\tnoreorder\n\t"
  81. ".set\tmips3\n\t"
  82. "mfc0\t%2, $12\n\t"
  83. "nop; nop; nop; nop;\n\t"
  84. "li\t%1, 0x80\n\t"
  85. "mtc0\t%1, $12\n\t"
  86. "nop; nop; nop; nop;\n\t"
  87. "li\t%0, 0x1\n\t"
  88. "dsll\t%0, 31\n\t"
  89. "lui\t%1, 0x9000\n\t"
  90. "dsll32\t%1, 0\n\t"
  91. "or\t%0, %1, %0\n\t"
  92. "sb\t$0, 0(%0)\n\t"
  93. "mtc0\t$0, $12\n\t"
  94. "nop; nop; nop; nop;\n\t"
  95. "mtc0\t%2, $12\n\t"
  96. "nop; nop; nop; nop;\n\t"
  97. ".set\tpop"
  98. : "=r" (tmp1), "=r" (tmp2), "=r" (addr));
  99. }
  100. static void indy_sc_disable(void)
  101. {
  102. unsigned long tmp1, tmp2, tmp3;
  103. #ifdef DEBUG_CACHE
  104. printk("Disabling R4600 SCACHE\n");
  105. #endif
  106. __asm__ __volatile__(
  107. ".set\tpush\n\t"
  108. ".set\tnoreorder\n\t"
  109. ".set\tmips3\n\t"
  110. "li\t%0, 0x1\n\t"
  111. "dsll\t%0, 31\n\t"
  112. "lui\t%1, 0x9000\n\t"
  113. "dsll32\t%1, 0\n\t"
  114. "or\t%0, %1, %0\n\t"
  115. "mfc0\t%2, $12\n\t"
  116. "nop; nop; nop; nop\n\t"
  117. "li\t%1, 0x80\n\t"
  118. "mtc0\t%1, $12\n\t"
  119. "nop; nop; nop; nop\n\t"
  120. "sh\t$0, 0(%0)\n\t"
  121. "mtc0\t$0, $12\n\t"
  122. "nop; nop; nop; nop\n\t"
  123. "mtc0\t%2, $12\n\t"
  124. "nop; nop; nop; nop\n\t"
  125. ".set\tpop"
  126. : "=r" (tmp1), "=r" (tmp2), "=r" (tmp3));
  127. }
  128. static inline int __init indy_sc_probe(void)
  129. {
  130. unsigned int size = ip22_eeprom_read(&sgimc->eeprom, 17);
  131. if (size == 0)
  132. return 0;
  133. size <<= PAGE_SHIFT;
  134. printk(KERN_INFO "R4600/R5000 SCACHE size %dK, linesize 32 bytes.\n",
  135. size >> 10);
  136. scache_size = size;
  137. return 1;
  138. }
  139. /* XXX Check with wje if the Indy caches can differenciate between
  140. writeback + invalidate and just invalidate. */
  141. struct bcache_ops indy_sc_ops = {
  142. .bc_enable = indy_sc_enable,
  143. .bc_disable = indy_sc_disable,
  144. .bc_wback_inv = indy_sc_wback_invalidate,
  145. .bc_inv = indy_sc_wback_invalidate
  146. };
  147. void __init indy_sc_init(void)
  148. {
  149. if (indy_sc_probe()) {
  150. indy_sc_enable();
  151. bcops = &indy_sc_ops;
  152. }
  153. }