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>
18 #include <asm/mipsregs.h>
19 #include <asm/system.h>
20 #include <asm/r4kcache.h>
21 #include <asm/hazards.h>
24 * These definitions are correct for the 24K/34K/74K SPRAM sample
25 * implementation. The 4KS interpreted the tags differently...
27 #define SPRAM_TAG0_ENABLE 0x00000080
28 #define SPRAM_TAG0_PA_MASK 0xfffff000
29 #define SPRAM_TAG1_SIZE_MASK 0xfffff000
31 #define SPRAM_TAG_STRIDE 8
33 #define ERRCTL_SPRAM (1 << 28)
36 #define read_c0_errctl(x) read_c0_ecc(x)
37 #define write_c0_errctl(x) write_c0_ecc(x)
40 * Different semantics to the set_c0_* function built by __BUILD_SET_C0
42 static __cpuinit
unsigned int bis_c0_errctl(unsigned int set
)
45 res
= read_c0_errctl();
46 write_c0_errctl(res
| set
);
50 static __cpuinit
void ispram_store_tag(unsigned int offset
, unsigned int data
)
54 /* enable SPRAM tag access */
55 errctl
= bis_c0_errctl(ERRCTL_SPRAM
);
61 cache_op(Index_Store_Tag_I
, CKSEG0
|offset
);
64 write_c0_errctl(errctl
);
69 static __cpuinit
unsigned int ispram_load_tag(unsigned int offset
)
74 /* enable SPRAM tag access */
75 errctl
= bis_c0_errctl(ERRCTL_SPRAM
);
77 cache_op(Index_Load_Tag_I
, CKSEG0
| offset
);
79 data
= read_c0_taglo();
81 write_c0_errctl(errctl
);
87 static __cpuinit
void dspram_store_tag(unsigned int offset
, unsigned int data
)
91 /* enable SPRAM tag access */
92 errctl
= bis_c0_errctl(ERRCTL_SPRAM
);
94 write_c0_dtaglo(data
);
96 cache_op(Index_Store_Tag_D
, CKSEG0
| offset
);
98 write_c0_errctl(errctl
);
103 static __cpuinit
unsigned int dspram_load_tag(unsigned int offset
)
108 errctl
= bis_c0_errctl(ERRCTL_SPRAM
);
110 cache_op(Index_Load_Tag_D
, CKSEG0
| offset
);
112 data
= read_c0_dtaglo();
114 write_c0_errctl(errctl
);
120 static __cpuinit
void probe_spram(char *type
,
122 unsigned int (*read
)(unsigned int),
123 void (*write
)(unsigned int, unsigned int))
125 unsigned int firstsize
= 0, lastsize
= 0;
126 unsigned int firstpa
= 0, lastpa
= 0, pa
= 0;
127 unsigned int offset
= 0;
128 unsigned int size
, tag0
, tag1
;
129 unsigned int enabled
;
133 * The limit is arbitrary but avoids the loop running away if
134 * the SPRAM tags are implemented differently
137 for (i
= 0; i
< 8; i
++) {
139 tag1
= read(offset
+SPRAM_TAG_STRIDE
);
140 pr_debug("DBG %s%d: tag0=%08x tag1=%08x\n",
141 type
, i
, tag0
, tag1
);
143 size
= tag1
& SPRAM_TAG1_SIZE_MASK
;
149 /* tags may repeat... */
150 if ((pa
== firstpa
&& size
== firstsize
) ||
151 (pa
== lastpa
&& size
== lastsize
))
155 /* Align base with size */
156 base
= (base
+ size
- 1) & ~(size
-1);
158 /* reprogram the base address base address and enable */
159 tag0
= (base
& SPRAM_TAG0_PA_MASK
) | SPRAM_TAG0_ENABLE
;
166 pa
= tag0
& SPRAM_TAG0_PA_MASK
;
167 enabled
= tag0
& SPRAM_TAG0_ENABLE
;
177 if (strcmp(type
, "DSPRAM") == 0) {
178 unsigned int *vp
= (unsigned int *)(CKSEG1
| pa
);
180 #define TDAT 0x5a5aa5a5
188 printk(KERN_ERR
"vp=%p wrote=%08x got=%08x\n",
192 printk(KERN_ERR
"vp=%p wrote=%08x got=%08x\n",
196 pr_info("%s%d: PA=%08x,Size=%08x%s\n",
197 type
, i
, pa
, size
, enabled
? ",enabled" : "");
198 offset
+= 2 * SPRAM_TAG_STRIDE
;
202 __cpuinit
void spram_config(void)
204 struct cpuinfo_mips
*c
= ¤t_cpu_data
;
205 unsigned int config0
;
207 switch (c
->cputype
) {
211 config0
= read_c0_config();
212 /* FIXME: addresses are Malta specific */
213 if (config0
& (1<<24)) {
214 probe_spram("ISPRAM", 0x1c000000,
215 &ispram_load_tag
, &ispram_store_tag
);
217 if (config0
& (1<<23))
218 probe_spram("DSPRAM", 0x1c100000,
219 &dspram_load_tag
, &dspram_store_tag
);