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 (dm@engr.sgi.com).
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/system.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\tpush\t\t\t# indy_sc_wipe\n\t"
40 "li\t$1, 0x80\t\t\t# Go 64 bit\n\t"
43 "dli\t$1, 0x9000000080000000\n\t"
44 "or\t%0, $1\t\t\t# first line to flush\n\t"
45 "or\t%1, $1\t\t\t# last line to flush\n\t"
48 "1:\tsw\t$0, 0(%0)\n\t"
52 "mtc0\t%2, $12\t\t\t# Back to 32 bit\n\t"
53 "nop; nop; nop; nop;\n\t"
55 : "=r" (first
), "=r" (last
), "=&r" (tmp
)
56 : "0" (first
), "1" (last
));
59 static void indy_sc_wback_invalidate(unsigned long addr
, unsigned long size
)
61 unsigned long first_line
, last_line
;
65 printk("indy_sc_wback_invalidate[%08lx,%08lx]", addr
, size
);
68 /* Catch bad driver code */
71 /* Which lines to flush? */
72 first_line
= SC_INDEX(addr
);
73 last_line
= SC_INDEX(addr
+ size
- 1);
75 local_irq_save(flags
);
76 if (first_line
<= last_line
) {
77 indy_sc_wipe(first_line
, last_line
);
81 indy_sc_wipe(first_line
, SC_SIZE
- SC_LINE
);
82 indy_sc_wipe(0, last_line
);
84 local_irq_restore(flags
);
87 static void indy_sc_enable(void)
89 unsigned long addr
, tmp1
, tmp2
;
91 /* This is really cool... */
93 printk("Enabling R4600 SCACHE\n");
100 "nop; nop; nop; nop;\n\t"
103 "nop; nop; nop; nop;\n\t"
106 "lui\t%1, 0x9000\n\t"
111 "nop; nop; nop; nop;\n\t"
113 "nop; nop; nop; nop;\n\t"
115 : "=r" (tmp1
), "=r" (tmp2
), "=r" (addr
));
118 static void indy_sc_disable(void)
120 unsigned long tmp1
, tmp2
, tmp3
;
123 printk("Disabling R4600 SCACHE\n");
125 __asm__
__volatile__(
127 ".set\tnoreorder\n\t"
131 "lui\t%1, 0x9000\n\t"
135 "nop; nop; nop; nop\n\t"
138 "nop; nop; nop; nop\n\t"
141 "nop; nop; nop; nop\n\t"
143 "nop; nop; nop; nop\n\t"
145 : "=r" (tmp1
), "=r" (tmp2
), "=r" (tmp3
));
148 static inline int __init
indy_sc_probe(void)
150 unsigned int size
= ip22_eeprom_read(&sgimc
->eeprom
, 17);
155 printk(KERN_INFO
"R4600/R5000 SCACHE size %dK, linesize 32 bytes.\n",
162 /* XXX Check with wje if the Indy caches can differenciate between
163 writeback + invalidate and just invalidate. */
164 static struct bcache_ops indy_sc_ops
= {
165 .bc_enable
= indy_sc_enable
,
166 .bc_disable
= indy_sc_disable
,
167 .bc_wback_inv
= indy_sc_wback_invalidate
,
168 .bc_inv
= indy_sc_wback_invalidate
171 void __cpuinit
indy_sc_init(void)
173 if (indy_sc_probe()) {
175 bcops
= &indy_sc_ops
;