1 // SPDX-License-Identifier: GPL-2.0
3 * sc-ip22.c: Indy cache management functions.
5 * Copyright (C) 1997, 2001 Ralf Baechle (ralf@gnu.org),
6 * derived from r4xx0.c by David S. Miller (davem@davemloft.net).
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
13 #include <asm/bcache.h>
15 #include <asm/pgtable.h>
16 #include <asm/bootinfo.h>
17 #include <asm/sgi/ip22.h>
18 #include <asm/sgi/mc.h>
20 /* Secondary cache size in bytes, if present. */
21 static unsigned long scache_size
;
25 #define SC_SIZE 0x00080000
27 #define CI_MASK (SC_SIZE - SC_LINE)
28 #define SC_INDEX(n) ((n) & CI_MASK)
30 static inline void indy_sc_wipe(unsigned long first
, unsigned long last
)
35 " .set push # indy_sc_wipe \n"
40 " li $1, 0x80 # Go 64 bit \n"
44 " # Open code a dli $1, 0x9000000080000000 \n"
46 " # Required because binutils 2.25 will happily accept \n"
47 " # 64 bit instructions in .set mips3 mode but puke on \n"
48 " # 64 bit constants when generating 32 bit ELF \n"
52 " ori $1,$1,0x8000 \n"
55 " or %0, $1 # first line to flush \n"
56 " or %1, $1 # last line to flush \n"
63 " mtc0 %2, $12 # Back to 32 bit \n"
64 " nop # pipeline hazard \n"
69 : "=r" (first
), "=r" (last
), "=&r" (tmp
)
70 : "0" (first
), "1" (last
));
73 static void indy_sc_wback_invalidate(unsigned long addr
, unsigned long size
)
75 unsigned long first_line
, last_line
;
79 printk("indy_sc_wback_invalidate[%08lx,%08lx]", addr
, size
);
82 /* Catch bad driver code */
85 /* Which lines to flush? */
86 first_line
= SC_INDEX(addr
);
87 last_line
= SC_INDEX(addr
+ size
- 1);
89 local_irq_save(flags
);
90 if (first_line
<= last_line
) {
91 indy_sc_wipe(first_line
, last_line
);
95 indy_sc_wipe(first_line
, SC_SIZE
- SC_LINE
);
96 indy_sc_wipe(0, last_line
);
98 local_irq_restore(flags
);
101 static void indy_sc_enable(void)
103 unsigned long addr
, tmp1
, tmp2
;
105 /* This is really cool... */
107 printk("Enabling R4600 SCACHE\n");
109 __asm__
__volatile__(
111 ".set\tnoreorder\n\t"
114 "nop; nop; nop; nop;\n\t"
117 "nop; nop; nop; nop;\n\t"
120 "lui\t%1, 0x9000\n\t"
125 "nop; nop; nop; nop;\n\t"
127 "nop; nop; nop; nop;\n\t"
129 : "=r" (tmp1
), "=r" (tmp2
), "=r" (addr
));
132 static void indy_sc_disable(void)
134 unsigned long tmp1
, tmp2
, tmp3
;
137 printk("Disabling R4600 SCACHE\n");
139 __asm__
__volatile__(
141 ".set\tnoreorder\n\t"
145 "lui\t%1, 0x9000\n\t"
149 "nop; nop; nop; nop\n\t"
152 "nop; nop; nop; nop\n\t"
155 "nop; nop; nop; nop\n\t"
157 "nop; nop; nop; nop\n\t"
159 : "=r" (tmp1
), "=r" (tmp2
), "=r" (tmp3
));
162 static inline int __init
indy_sc_probe(void)
164 unsigned int size
= ip22_eeprom_read(&sgimc
->eeprom
, 17);
169 printk(KERN_INFO
"R4600/R5000 SCACHE size %dK, linesize 32 bytes.\n",
176 /* XXX Check with wje if the Indy caches can differentiate between
177 writeback + invalidate and just invalidate. */
178 static struct bcache_ops indy_sc_ops
= {
179 .bc_enable
= indy_sc_enable
,
180 .bc_disable
= indy_sc_disable
,
181 .bc_wback_inv
= indy_sc_wback_invalidate
,
182 .bc_inv
= indy_sc_wback_invalidate
185 void indy_sc_init(void)
187 if (indy_sc_probe()) {
189 bcops
= &indy_sc_ops
;