blob: 3d6b1ec1f328b222b7b2a61cc47a5b01fdb024f7 [file] [log] [blame]
Ralf Baechle41c594a2006-04-05 09:45:45 +01001/*
2 * General MIPS MT support routines, usable in AP/SP, SMVP, or SMTC kernels
3 * Copyright (C) 2005 Mips Technologies, Inc
4 */
5
Ralf Baechle27a3bba2007-02-07 13:48:59 +00006#include <linux/device.h>
Ralf Baechlebdd3ede2007-08-10 18:30:57 +01007#include <linux/kallsyms.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +01008#include <linux/kernel.h>
9#include <linux/sched.h>
Ralf Baechle27a3bba2007-02-07 13:48:59 +000010#include <linux/module.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +010011#include <linux/interrupt.h>
Yoichi Yuasaf72af3c2006-07-04 22:16:28 +090012#include <linux/security.h>
Ralf Baechle41c594a2006-04-05 09:45:45 +010013
14#include <asm/cpu.h>
15#include <asm/processor.h>
16#include <asm/atomic.h>
17#include <asm/system.h>
18#include <asm/hardirq.h>
19#include <asm/mmu_context.h>
20#include <asm/smp.h>
21#include <asm/mipsmtregs.h>
22#include <asm/r4kcache.h>
23#include <asm/cacheflush.h>
24
Ralf Baechle07cc0c92007-07-27 19:31:10 +010025int vpelimit;
26
27static int __init maxvpes(char *str)
28{
29 get_option(&str, &vpelimit);
30
31 return 1;
32}
33
34__setup("maxvpes=", maxvpes);
35
36int tclimit;
37
38static int __init maxtcs(char *str)
39{
40 get_option(&str, &tclimit);
41
42 return 1;
43}
44
45__setup("maxtcs=", maxtcs);
46
Ralf Baechle41c594a2006-04-05 09:45:45 +010047/*
Ralf Baechle41c594a2006-04-05 09:45:45 +010048 * Dump new MIPS MT state for the core. Does not leave TCs halted.
49 * Takes an argument which taken to be a pre-call MVPControl value.
50 */
51
52void mips_mt_regdump(unsigned long mvpctl)
53{
54 unsigned long flags;
55 unsigned long vpflags;
56 unsigned long mvpconf0;
57 int nvpe;
58 int ntc;
59 int i;
60 int tc;
61 unsigned long haltval;
62 unsigned long tcstatval;
63#ifdef CONFIG_MIPS_MT_SMTC
64 void smtc_soft_dump(void);
65#endif /* CONFIG_MIPT_MT_SMTC */
66
67 local_irq_save(flags);
68 vpflags = dvpe();
69 printk("=== MIPS MT State Dump ===\n");
70 printk("-- Global State --\n");
71 printk(" MVPControl Passed: %08lx\n", mvpctl);
72 printk(" MVPControl Read: %08lx\n", vpflags);
73 printk(" MVPConf0 : %08lx\n", (mvpconf0 = read_c0_mvpconf0()));
74 nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
75 ntc = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
76 printk("-- per-VPE State --\n");
Ralf Baechled223a8612007-07-10 17:33:02 +010077 for (i = 0; i < nvpe; i++) {
78 for (tc = 0; tc < ntc; tc++) {
Ralf Baechle41c594a2006-04-05 09:45:45 +010079 settc(tc);
Ralf Baechled223a8612007-07-10 17:33:02 +010080 if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
81 printk(" VPE %d\n", i);
82 printk(" VPEControl : %08lx\n",
83 read_vpe_c0_vpecontrol());
84 printk(" VPEConf0 : %08lx\n",
85 read_vpe_c0_vpeconf0());
86 printk(" VPE%d.Status : %08lx\n",
87 i, read_vpe_c0_status());
Ralf Baechlebdd3ede2007-08-10 18:30:57 +010088 printk(" VPE%d.EPC : %08lx ",
Ralf Baechled223a8612007-07-10 17:33:02 +010089 i, read_vpe_c0_epc());
Ralf Baechlebdd3ede2007-08-10 18:30:57 +010090 print_symbol("%s\n", read_vpe_c0_epc());
Ralf Baechled223a8612007-07-10 17:33:02 +010091 printk(" VPE%d.Cause : %08lx\n",
92 i, read_vpe_c0_cause());
93 printk(" VPE%d.Config7 : %08lx\n",
94 i, read_vpe_c0_config7());
95 break; /* Next VPE */
96 }
Ralf Baechle41c594a2006-04-05 09:45:45 +010097 }
Ralf Baechle41c594a2006-04-05 09:45:45 +010098 }
99 printk("-- per-TC State --\n");
Ralf Baechled223a8612007-07-10 17:33:02 +0100100 for (tc = 0; tc < ntc; tc++) {
Ralf Baechle41c594a2006-04-05 09:45:45 +0100101 settc(tc);
Ralf Baechled223a8612007-07-10 17:33:02 +0100102 if (read_tc_c0_tcbind() == read_c0_tcbind()) {
Ralf Baechle41c594a2006-04-05 09:45:45 +0100103 /* Are we dumping ourself? */
104 haltval = 0; /* Then we're not halted, and mustn't be */
105 tcstatval = flags; /* And pre-dump TCStatus is flags */
106 printk(" TC %d (current TC with VPE EPC above)\n", tc);
107 } else {
108 haltval = read_tc_c0_tchalt();
109 write_tc_c0_tchalt(1);
110 tcstatval = read_tc_c0_tcstatus();
111 printk(" TC %d\n", tc);
112 }
113 printk(" TCStatus : %08lx\n", tcstatval);
114 printk(" TCBind : %08lx\n", read_tc_c0_tcbind());
Ralf Baechlebdd3ede2007-08-10 18:30:57 +0100115 printk(" TCRestart : %08lx ", read_tc_c0_tcrestart());
116 print_symbol("%s\n", read_tc_c0_tcrestart());
Ralf Baechle41c594a2006-04-05 09:45:45 +0100117 printk(" TCHalt : %08lx\n", haltval);
118 printk(" TCContext : %08lx\n", read_tc_c0_tccontext());
119 if (!haltval)
120 write_tc_c0_tchalt(0);
121 }
122#ifdef CONFIG_MIPS_MT_SMTC
123 smtc_soft_dump();
124#endif /* CONFIG_MIPT_MT_SMTC */
125 printk("===========================\n");
126 evpe(vpflags);
127 local_irq_restore(flags);
128}
129
130static int mt_opt_norps = 0;
131static int mt_opt_rpsctl = -1;
132static int mt_opt_nblsu = -1;
133static int mt_opt_forceconfig7 = 0;
134static int mt_opt_config7 = -1;
135
136static int __init rps_disable(char *s)
137{
138 mt_opt_norps = 1;
139 return 1;
140}
141__setup("norps", rps_disable);
142
143static int __init rpsctl_set(char *str)
144{
145 get_option(&str, &mt_opt_rpsctl);
146 return 1;
147}
148__setup("rpsctl=", rpsctl_set);
149
150static int __init nblsu_set(char *str)
151{
152 get_option(&str, &mt_opt_nblsu);
153 return 1;
154}
155__setup("nblsu=", nblsu_set);
156
157static int __init config7_set(char *str)
158{
159 get_option(&str, &mt_opt_config7);
160 mt_opt_forceconfig7 = 1;
161 return 1;
162}
163__setup("config7=", config7_set);
164
165/* Experimental cache flush control parameters that should go away some day */
166int mt_protiflush = 0;
167int mt_protdflush = 0;
168int mt_n_iflushes = 1;
169int mt_n_dflushes = 1;
170
171static int __init set_protiflush(char *s)
172{
173 mt_protiflush = 1;
174 return 1;
175}
176__setup("protiflush", set_protiflush);
177
178static int __init set_protdflush(char *s)
179{
180 mt_protdflush = 1;
181 return 1;
182}
183__setup("protdflush", set_protdflush);
184
185static int __init niflush(char *s)
186{
187 get_option(&s, &mt_n_iflushes);
188 return 1;
189}
190__setup("niflush=", niflush);
191
192static int __init ndflush(char *s)
193{
194 get_option(&s, &mt_n_dflushes);
195 return 1;
196}
197__setup("ndflush=", ndflush);
Ralf Baechle41c594a2006-04-05 09:45:45 +0100198
199static unsigned int itc_base = 0;
200
201static int __init set_itc_base(char *str)
202{
203 get_option(&str, &itc_base);
204 return 1;
205}
206
207__setup("itcbase=", set_itc_base);
208
209void mips_mt_set_cpuoptions(void)
210{
211 unsigned int oconfig7 = read_c0_config7();
212 unsigned int nconfig7 = oconfig7;
213
214 if (mt_opt_norps) {
215 printk("\"norps\" option deprectated: use \"rpsctl=\"\n");
216 }
217 if (mt_opt_rpsctl >= 0) {
218 printk("34K return prediction stack override set to %d.\n",
219 mt_opt_rpsctl);
220 if (mt_opt_rpsctl)
221 nconfig7 |= (1 << 2);
222 else
223 nconfig7 &= ~(1 << 2);
224 }
225 if (mt_opt_nblsu >= 0) {
226 printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu);
227 if (mt_opt_nblsu)
228 nconfig7 |= (1 << 5);
229 else
230 nconfig7 &= ~(1 << 5);
231 }
232 if (mt_opt_forceconfig7) {
233 printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7);
234 nconfig7 = mt_opt_config7;
235 }
236 if (oconfig7 != nconfig7) {
237 __asm__ __volatile("sync");
238 write_c0_config7(nconfig7);
Ralf Baechle49a89ef2007-10-11 23:46:15 +0100239 ehb();
Ralf Baechle41c594a2006-04-05 09:45:45 +0100240 printk("Config7: 0x%08x\n", read_c0_config7());
241 }
242
243 /* Report Cache management debug options */
244 if (mt_protiflush)
245 printk("I-cache flushes single-threaded\n");
246 if (mt_protdflush)
247 printk("D-cache flushes single-threaded\n");
248 if (mt_n_iflushes != 1)
249 printk("I-Cache Flushes Repeated %d times\n", mt_n_iflushes);
250 if (mt_n_dflushes != 1)
251 printk("D-Cache Flushes Repeated %d times\n", mt_n_dflushes);
252
Ralf Baechle41c594a2006-04-05 09:45:45 +0100253 if (itc_base != 0) {
254 /*
255 * Configure ITC mapping. This code is very
256 * specific to the 34K core family, which uses
257 * a special mode bit ("ITC") in the ErrCtl
258 * register to enable access to ITC control
259 * registers via cache "tag" operations.
260 */
261 unsigned long ectlval;
262 unsigned long itcblkgrn;
263
264 /* ErrCtl register is known as "ecc" to Linux */
265 ectlval = read_c0_ecc();
266 write_c0_ecc(ectlval | (0x1 << 26));
267 ehb();
268#define INDEX_0 (0x80000000)
269#define INDEX_8 (0x80000008)
270 /* Read "cache tag" for Dcache pseudo-index 8 */
271 cache_op(Index_Load_Tag_D, INDEX_8);
272 ehb();
273 itcblkgrn = read_c0_dtaglo();
274 itcblkgrn &= 0xfffe0000;
275 /* Set for 128 byte pitch of ITC cells */
276 itcblkgrn |= 0x00000c00;
277 /* Stage in Tag register */
278 write_c0_dtaglo(itcblkgrn);
279 ehb();
280 /* Write out to ITU with CACHE op */
281 cache_op(Index_Store_Tag_D, INDEX_8);
282 /* Now set base address, and turn ITC on with 0x1 bit */
283 write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 );
284 ehb();
285 /* Write out to ITU with CACHE op */
286 cache_op(Index_Store_Tag_D, INDEX_0);
287 write_c0_ecc(ectlval);
288 ehb();
289 printk("Mapped %ld ITC cells starting at 0x%08x\n",
290 ((itcblkgrn & 0x7fe00000) >> 20), itc_base);
291 }
292}
293
294/*
295 * Function to protect cache flushes from concurrent execution
296 * depends on MP software model chosen.
297 */
298
299void mt_cflush_lockdown(void)
300{
301#ifdef CONFIG_MIPS_MT_SMTC
302 void smtc_cflush_lockdown(void);
303
304 smtc_cflush_lockdown();
305#endif /* CONFIG_MIPS_MT_SMTC */
306 /* FILL IN VSMP and AP/SP VERSIONS HERE */
307}
308
309void mt_cflush_release(void)
310{
311#ifdef CONFIG_MIPS_MT_SMTC
312 void smtc_cflush_release(void);
313
314 smtc_cflush_release();
315#endif /* CONFIG_MIPS_MT_SMTC */
316 /* FILL IN VSMP and AP/SP VERSIONS HERE */
317}
Ralf Baechle27a3bba2007-02-07 13:48:59 +0000318
319struct class *mt_class;
320
321static int __init mt_init(void)
322{
323 struct class *mtc;
324
325 mtc = class_create(THIS_MODULE, "mt");
326 if (IS_ERR(mtc))
327 return PTR_ERR(mtc);
328
329 mt_class = mtc;
330
331 return 0;
332}
333
334subsys_initcall(mt_init);