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