1 // SPDX-License-Identifier: GPL-2.0
3 * sc-ip22.c: Indy cache management functions.
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
13 #include <asm/bcache.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"
43 " # Open code a dli $1, 0x9000000080000000 \n"
45 " # Required because binutils 2.25 will happily accept \n"
46 " # 64 bit instructions in .set mips3 mode but puke on \n"
47 " # 64 bit constants when generating 32 bit ELF \n"
51 " ori $1,$1,0x8000 \n"
54 " or %0, $1 # first line to flush \n"
55 " or %1, $1 # last line to flush \n"
62 " mtc0 %2, $12 # Back to 32 bit \n"
63 " nop # pipeline hazard \n"
68 : "=r" (first), "=r" (last), "=&r" (tmp)
69 : "0" (first), "1" (last));
72 static void indy_sc_wback_invalidate(unsigned long addr, unsigned long size)
74 unsigned long first_line, last_line;
78 printk("indy_sc_wback_invalidate[%08lx,%08lx]", addr, size);
81 /* Catch bad driver code */
84 /* Which lines to flush? */
85 first_line = SC_INDEX(addr);
86 last_line = SC_INDEX(addr + size - 1);
88 local_irq_save(flags);
89 if (first_line <= last_line) {
90 indy_sc_wipe(first_line, last_line);
94 indy_sc_wipe(first_line, SC_SIZE - SC_LINE);
95 indy_sc_wipe(0, last_line);
97 local_irq_restore(flags);
100 static void indy_sc_enable(void)
102 unsigned long addr, tmp1, tmp2;
104 /* This is really cool... */
106 printk("Enabling R4600 SCACHE\n");
108 __asm__ __volatile__(
110 ".set\tnoreorder\n\t"
113 "nop; nop; nop; nop;\n\t"
116 "nop; nop; nop; nop;\n\t"
119 "lui\t%1, 0x9000\n\t"
124 "nop; nop; nop; nop;\n\t"
126 "nop; nop; nop; nop;\n\t"
128 : "=r" (tmp1), "=r" (tmp2), "=r" (addr));
131 static void indy_sc_disable(void)
133 unsigned long tmp1, tmp2, tmp3;
136 printk("Disabling R4600 SCACHE\n");
138 __asm__ __volatile__(
140 ".set\tnoreorder\n\t"
144 "lui\t%1, 0x9000\n\t"
148 "nop; nop; nop; nop\n\t"
151 "nop; nop; nop; nop\n\t"
154 "nop; nop; nop; nop\n\t"
156 "nop; nop; nop; nop\n\t"
158 : "=r" (tmp1), "=r" (tmp2), "=r" (tmp3));
161 static inline int __init indy_sc_probe(void)
163 unsigned int size = ip22_eeprom_read(&sgimc->eeprom, 17);
168 printk(KERN_INFO "R4600/R5000 SCACHE size %dK, linesize 32 bytes.\n",
175 /* XXX Check with wje if the Indy caches can differentiate between
176 writeback + invalidate and just invalidate. */
177 static struct bcache_ops indy_sc_ops = {
178 .bc_enable = indy_sc_enable,
179 .bc_disable = indy_sc_disable,
180 .bc_wback_inv = indy_sc_wback_invalidate,
181 .bc_inv = indy_sc_wback_invalidate
184 void indy_sc_init(void)
186 if (indy_sc_probe()) {
188 bcops = &indy_sc_ops;