4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Copyright (C) 2007, 2008 MIPS Technologies, Inc.
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/ptrace.h>
14 #include <linux/stddef.h>
17 #include <asm/mipsregs.h>
18 #include <asm/r4kcache.h>
19 #include <asm/hazards.h>
22 * These definitions are correct for the 24K/34K/74K SPRAM sample
23 * implementation. The 4KS interpreted the tags differently...
25 #define SPRAM_TAG0_ENABLE 0x00000080
26 #define SPRAM_TAG0_PA_MASK 0xfffff000
27 #define SPRAM_TAG1_SIZE_MASK 0xfffff000
29 #define SPRAM_TAG_STRIDE 8
31 #define ERRCTL_SPRAM (1 << 28)
34 #define read_c0_errctl(x) read_c0_ecc(x)
35 #define write_c0_errctl(x) write_c0_ecc(x)
38 * Different semantics to the set_c0_* function built by __BUILD_SET_C0
40 static unsigned int bis_c0_errctl(unsigned int set
)
43 res
= read_c0_errctl();
44 write_c0_errctl(res
| set
);
48 static void ispram_store_tag(unsigned int offset
, unsigned int data
)
52 /* enable SPRAM tag access */
53 errctl
= bis_c0_errctl(ERRCTL_SPRAM
);
59 cache_op(Index_Store_Tag_I
, CKSEG0
|offset
);
62 write_c0_errctl(errctl
);
67 static unsigned int ispram_load_tag(unsigned int offset
)
72 /* enable SPRAM tag access */
73 errctl
= bis_c0_errctl(ERRCTL_SPRAM
);
75 cache_op(Index_Load_Tag_I
, CKSEG0
| offset
);
77 data
= read_c0_taglo();
79 write_c0_errctl(errctl
);
85 static void dspram_store_tag(unsigned int offset
, unsigned int data
)
89 /* enable SPRAM tag access */
90 errctl
= bis_c0_errctl(ERRCTL_SPRAM
);
92 write_c0_dtaglo(data
);
94 cache_op(Index_Store_Tag_D
, CKSEG0
| offset
);
96 write_c0_errctl(errctl
);
101 static unsigned int dspram_load_tag(unsigned int offset
)
106 errctl
= bis_c0_errctl(ERRCTL_SPRAM
);
108 cache_op(Index_Load_Tag_D
, CKSEG0
| offset
);
110 data
= read_c0_dtaglo();
112 write_c0_errctl(errctl
);
118 static void probe_spram(char *type
,
120 unsigned int (*read
)(unsigned int),
121 void (*write
)(unsigned int, unsigned int))
123 unsigned int firstsize
= 0, lastsize
= 0;
124 unsigned int firstpa
= 0, lastpa
= 0, pa
= 0;
125 unsigned int offset
= 0;
126 unsigned int size
, tag0
, tag1
;
127 unsigned int enabled
;
131 * The limit is arbitrary but avoids the loop running away if
132 * the SPRAM tags are implemented differently
135 for (i
= 0; i
< 8; i
++) {
137 tag1
= read(offset
+SPRAM_TAG_STRIDE
);
138 pr_debug("DBG %s%d: tag0=%08x tag1=%08x\n",
139 type
, i
, tag0
, tag1
);
141 size
= tag1
& SPRAM_TAG1_SIZE_MASK
;
147 /* tags may repeat... */
148 if ((pa
== firstpa
&& size
== firstsize
) ||
149 (pa
== lastpa
&& size
== lastsize
))
153 /* Align base with size */
154 base
= (base
+ size
- 1) & ~(size
-1);
156 /* reprogram the base address base address and enable */
157 tag0
= (base
& SPRAM_TAG0_PA_MASK
) | SPRAM_TAG0_ENABLE
;
164 pa
= tag0
& SPRAM_TAG0_PA_MASK
;
165 enabled
= tag0
& SPRAM_TAG0_ENABLE
;
175 if (strcmp(type
, "DSPRAM") == 0) {
176 unsigned int *vp
= (unsigned int *)(CKSEG1
| pa
);
178 #define TDAT 0x5a5aa5a5
186 printk(KERN_ERR
"vp=%p wrote=%08x got=%08x\n",
190 printk(KERN_ERR
"vp=%p wrote=%08x got=%08x\n",
194 pr_info("%s%d: PA=%08x,Size=%08x%s\n",
195 type
, i
, pa
, size
, enabled
? ",enabled" : "");
196 offset
+= 2 * SPRAM_TAG_STRIDE
;
199 void spram_config(void)
201 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
202 unsigned int config0
;
204 switch (c
->cputype
) {
209 config0
= read_c0_config();
210 /* FIXME: addresses are Malta specific */
211 if (config0
& (1<<24)) {
212 probe_spram("ISPRAM", 0x1c000000,
213 &ispram_load_tag
, &ispram_store_tag
);
215 if (config0
& (1<<23))
216 probe_spram("DSPRAM", 0x1c100000,
217 &dspram_load_tag
, &dspram_store_tag
);