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