more debug output
[linux-2.4.git] / arch / mips / mm / sc-r5k.c
1 /*
2  * Copyright (C) 1997, 2001 Ralf Baechle (ralf@gnu.org),
3  * derived from r4xx0.c by David S. Miller (dm@engr.sgi.com).
4  */
5 #include <linux/init.h>
6 #include <linux/kernel.h>
7 #include <linux/sched.h>
8 #include <linux/mm.h>
9
10 #include <asm/mipsregs.h>
11 #include <asm/bcache.h>
12 #include <asm/cacheops.h>
13 #include <asm/page.h>
14 #include <asm/pgtable.h>
15 #include <asm/system.h>
16 #include <asm/mmu_context.h>
17
18 /* Secondary cache size in bytes, if present.  */
19 static unsigned long scache_size;
20
21 #define SC_LINE 32
22 #define SC_PAGE (128*SC_LINE)
23
24 #define cache_op(base,op)                   \
25 __asm__ __volatile__("                          \
26                 .set noreorder;                 \
27                 .set mips3;                     \
28                 cache %1, (%0);                 \
29                 .set mips0;                     \
30                 .set reorder"                   \
31                 :                               \
32                 : "r" (base),                   \
33                   "i" (op));
34
35 static inline void blast_r5000_scache(void)
36 {
37         unsigned long start = KSEG0;
38         unsigned long end = KSEG0 + scache_size;
39
40         while(start < end) {
41                 cache_op(start, R5K_Page_Invalidate_S);
42                 start += SC_PAGE;
43         }
44 }
45
46 static void r5k_dma_cache_inv_sc(unsigned long addr, unsigned long size)
47 {
48         unsigned long end, a;
49
50         /* Catch bad driver code */
51         BUG_ON(size == 0);
52
53         if (size >= scache_size) {
54                 blast_r5000_scache();
55                 return;
56         }
57
58         /* On the R5000 secondary cache we cannot
59          * invalidate less than a page at a time.
60          * The secondary cache is physically indexed, write-through.
61          */
62         a = addr & ~(SC_PAGE - 1);
63         end = (addr + size - 1) & ~(SC_PAGE - 1);
64         while (a <= end) {
65                 cache_op(a, R5K_Page_Invalidate_S);
66                 a += SC_PAGE;
67         }
68 }
69
70 static void r5k_sc_enable(void)
71 {
72         unsigned long flags;
73
74         local_irq_save(flags);
75         change_c0_config(R5K_CONF_SE, R5K_CONF_SE);
76         blast_r5000_scache();
77         local_irq_restore(flags);
78 }
79
80 static void r5k_sc_disable(void)
81 {
82         unsigned long flags;
83
84         local_irq_save(flags);
85         blast_r5000_scache();
86         change_c0_config(R5K_CONF_SE, 0);
87         local_irq_restore(flags);
88 }
89
90 static inline int __init r5k_sc_probe(void)
91 {
92         unsigned long config = read_c0_config();
93
94         if (config & CONF_SC)
95                 return(0);
96
97         scache_size = (512 * 1024) << ((config & R5K_CONF_SS) >> 20);
98
99         printk("R5000 SCACHE size %ldkB, linesize 32 bytes.\n",
100                         scache_size >> 10);
101
102         return 1;
103 }
104
105 static struct bcache_ops r5k_sc_ops = {
106         .bc_enable = r5k_sc_enable,
107         .bc_disable = r5k_sc_disable,
108         .bc_wback_inv = r5k_dma_cache_inv_sc,
109         .bc_inv = r5k_dma_cache_inv_sc
110 };
111
112 void __init r5k_sc_init(void)
113 {
114         if (r5k_sc_probe()) {
115                 r5k_sc_enable();
116                 bcops = &r5k_sc_ops;
117         }
118 }