2 * sc-ip22.c: Indy cache management functions.
4 * Copyright (C) 1997, 2001 Ralf Baechle (ralf@gnu.org),
5 * derived from r4xx0.c by David S. Miller (davem@davemloft.net).
7 #include <linux/init.h>
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
12 #include <asm/bcache.h>
14 #include <asm/pgtable.h>
15 #include <asm/bootinfo.h>
16 #include <asm/sgi/ip22.h>
17 #include <asm/sgi/mc.h>
19 /* Secondary cache size in bytes, if present. */
20 static unsigned long scache_size;
24 #define SC_SIZE 0x00080000
26 #define CI_MASK (SC_SIZE - SC_LINE)
27 #define SC_INDEX(n) ((n) & CI_MASK)
29 static inline void indy_sc_wipe(unsigned long first, unsigned long last)
34 " .set push # indy_sc_wipe \n"
39 " li $1, 0x80 # Go 64 bit \n"
42 " dli $1, 0x9000000080000000 \n"
43 " or %0, $1 # first line to flush \n"
44 " or %1, $1 # last line to flush \n"
51 " mtc0 %2, $12 # Back to 32 bit \n"
52 " nop # pipeline hazard \n"
57 : "=r" (first), "=r" (last), "=&r" (tmp)
58 : "0" (first), "1" (last));
61 static void indy_sc_wback_invalidate(unsigned long addr, unsigned long size)
63 unsigned long first_line, last_line;
67 printk("indy_sc_wback_invalidate[%08lx,%08lx]", addr, size);
70 /* Catch bad driver code */
73 /* Which lines to flush? */
74 first_line = SC_INDEX(addr);
75 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);
83 indy_sc_wipe(first_line, SC_SIZE - SC_LINE);
84 indy_sc_wipe(0, last_line);
86 local_irq_restore(flags);
89 static void indy_sc_enable(void)
91 unsigned long addr, tmp1, tmp2;
93 /* This is really cool... */
95 printk("Enabling R4600 SCACHE\n");
102 "nop; nop; nop; nop;\n\t"
105 "nop; nop; nop; nop;\n\t"
108 "lui\t%1, 0x9000\n\t"
113 "nop; nop; nop; nop;\n\t"
115 "nop; nop; nop; nop;\n\t"
117 : "=r" (tmp1), "=r" (tmp2), "=r" (addr));
120 static void indy_sc_disable(void)
122 unsigned long tmp1, tmp2, tmp3;
125 printk("Disabling R4600 SCACHE\n");
127 __asm__ __volatile__(
129 ".set\tnoreorder\n\t"
133 "lui\t%1, 0x9000\n\t"
137 "nop; nop; nop; nop\n\t"
140 "nop; nop; nop; nop\n\t"
143 "nop; nop; nop; nop\n\t"
145 "nop; nop; nop; nop\n\t"
147 : "=r" (tmp1), "=r" (tmp2), "=r" (tmp3));
150 static inline int __init indy_sc_probe(void)
152 unsigned int size = ip22_eeprom_read(&sgimc->eeprom, 17);
157 printk(KERN_INFO "R4600/R5000 SCACHE size %dK, linesize 32 bytes.\n",
164 /* XXX Check with wje if the Indy caches can differenciate between
165 writeback + invalidate and just invalidate. */
166 static struct bcache_ops indy_sc_ops = {
167 .bc_enable = indy_sc_enable,
168 .bc_disable = indy_sc_disable,
169 .bc_wback_inv = indy_sc_wback_invalidate,
170 .bc_inv = indy_sc_wback_invalidate
173 void indy_sc_init(void)
175 if (indy_sc_probe()) {
177 bcops = &indy_sc_ops;