2 * General MIPS MT support routines, usable in AP/SP, SMVP, or SMTC kernels
3 * Copyright (C) 2005 Mips Technologies, Inc
6 #include <linux/device.h>
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9 #include <linux/module.h>
10 #include <linux/interrupt.h>
11 #include <linux/security.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>
20 #include <asm/mipsmtregs.h>
21 #include <asm/r4kcache.h>
22 #include <asm/cacheflush.h>
25 * Dump new MIPS MT state for the core. Does not leave TCs halted.
26 * Takes an argument which taken to be a pre-call MVPControl value.
29 void mips_mt_regdump(unsigned long mvpctl)
32 unsigned long vpflags;
33 unsigned long mvpconf0;
38 unsigned long haltval;
39 unsigned long tcstatval;
40 #ifdef CONFIG_MIPS_MT_SMTC
41 void smtc_soft_dump(void);
42 #endif /* CONFIG_MIPT_MT_SMTC */
44 local_irq_save(flags);
46 printk("=== MIPS MT State Dump ===\n");
47 printk("-- Global State --\n");
48 printk(" MVPControl Passed: %08lx\n", mvpctl);
49 printk(" MVPControl Read: %08lx\n", vpflags);
50 printk(" MVPConf0 : %08lx\n", (mvpconf0 = read_c0_mvpconf0()));
51 nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
52 ntc = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
53 printk("-- per-VPE State --\n");
54 for (i = 0; i < nvpe; i++) {
55 for (tc = 0; tc < ntc; tc++) {
57 if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
58 printk(" VPE %d\n", i);
59 printk(" VPEControl : %08lx\n",
60 read_vpe_c0_vpecontrol());
61 printk(" VPEConf0 : %08lx\n",
62 read_vpe_c0_vpeconf0());
63 printk(" VPE%d.Status : %08lx\n",
64 i, read_vpe_c0_status());
65 printk(" VPE%d.EPC : %08lx\n",
66 i, read_vpe_c0_epc());
67 printk(" VPE%d.Cause : %08lx\n",
68 i, read_vpe_c0_cause());
69 printk(" VPE%d.Config7 : %08lx\n",
70 i, read_vpe_c0_config7());
75 printk("-- per-TC State --\n");
76 for (tc = 0; tc < ntc; tc++) {
78 if (read_tc_c0_tcbind() == read_c0_tcbind()) {
79 /* Are we dumping ourself? */
80 haltval = 0; /* Then we're not halted, and mustn't be */
81 tcstatval = flags; /* And pre-dump TCStatus is flags */
82 printk(" TC %d (current TC with VPE EPC above)\n", tc);
84 haltval = read_tc_c0_tchalt();
85 write_tc_c0_tchalt(1);
86 tcstatval = read_tc_c0_tcstatus();
87 printk(" TC %d\n", tc);
89 printk(" TCStatus : %08lx\n", tcstatval);
90 printk(" TCBind : %08lx\n", read_tc_c0_tcbind());
91 printk(" TCRestart : %08lx\n", read_tc_c0_tcrestart());
92 printk(" TCHalt : %08lx\n", haltval);
93 printk(" TCContext : %08lx\n", read_tc_c0_tccontext());
95 write_tc_c0_tchalt(0);
97 #ifdef CONFIG_MIPS_MT_SMTC
99 #endif /* CONFIG_MIPT_MT_SMTC */
100 printk("===========================\n");
102 local_irq_restore(flags);
105 static int mt_opt_norps = 0;
106 static int mt_opt_rpsctl = -1;
107 static int mt_opt_nblsu = -1;
108 static int mt_opt_forceconfig7 = 0;
109 static int mt_opt_config7 = -1;
111 static int __init rps_disable(char *s)
116 __setup("norps", rps_disable);
118 static int __init rpsctl_set(char *str)
120 get_option(&str, &mt_opt_rpsctl);
123 __setup("rpsctl=", rpsctl_set);
125 static int __init nblsu_set(char *str)
127 get_option(&str, &mt_opt_nblsu);
130 __setup("nblsu=", nblsu_set);
132 static int __init config7_set(char *str)
134 get_option(&str, &mt_opt_config7);
135 mt_opt_forceconfig7 = 1;
138 __setup("config7=", config7_set);
140 /* Experimental cache flush control parameters that should go away some day */
141 int mt_protiflush = 0;
142 int mt_protdflush = 0;
143 int mt_n_iflushes = 1;
144 int mt_n_dflushes = 1;
146 static int __init set_protiflush(char *s)
151 __setup("protiflush", set_protiflush);
153 static int __init set_protdflush(char *s)
158 __setup("protdflush", set_protdflush);
160 static int __init niflush(char *s)
162 get_option(&s, &mt_n_iflushes);
165 __setup("niflush=", niflush);
167 static int __init ndflush(char *s)
169 get_option(&s, &mt_n_dflushes);
172 __setup("ndflush=", ndflush);
174 static unsigned int itc_base = 0;
176 static int __init set_itc_base(char *str)
178 get_option(&str, &itc_base);
182 __setup("itcbase=", set_itc_base);
184 void mips_mt_set_cpuoptions(void)
186 unsigned int oconfig7 = read_c0_config7();
187 unsigned int nconfig7 = oconfig7;
190 printk("\"norps\" option deprectated: use \"rpsctl=\"\n");
192 if (mt_opt_rpsctl >= 0) {
193 printk("34K return prediction stack override set to %d.\n",
196 nconfig7 |= (1 << 2);
198 nconfig7 &= ~(1 << 2);
200 if (mt_opt_nblsu >= 0) {
201 printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu);
203 nconfig7 |= (1 << 5);
205 nconfig7 &= ~(1 << 5);
207 if (mt_opt_forceconfig7) {
208 printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7);
209 nconfig7 = mt_opt_config7;
211 if (oconfig7 != nconfig7) {
212 __asm__ __volatile("sync");
213 write_c0_config7(nconfig7);
215 printk("Config7: 0x%08x\n", read_c0_config7());
218 /* Report Cache management debug options */
220 printk("I-cache flushes single-threaded\n");
222 printk("D-cache flushes single-threaded\n");
223 if (mt_n_iflushes != 1)
224 printk("I-Cache Flushes Repeated %d times\n", mt_n_iflushes);
225 if (mt_n_dflushes != 1)
226 printk("D-Cache Flushes Repeated %d times\n", mt_n_dflushes);
230 * Configure ITC mapping. This code is very
231 * specific to the 34K core family, which uses
232 * a special mode bit ("ITC") in the ErrCtl
233 * register to enable access to ITC control
234 * registers via cache "tag" operations.
236 unsigned long ectlval;
237 unsigned long itcblkgrn;
239 /* ErrCtl register is known as "ecc" to Linux */
240 ectlval = read_c0_ecc();
241 write_c0_ecc(ectlval | (0x1 << 26));
243 #define INDEX_0 (0x80000000)
244 #define INDEX_8 (0x80000008)
245 /* Read "cache tag" for Dcache pseudo-index 8 */
246 cache_op(Index_Load_Tag_D, INDEX_8);
248 itcblkgrn = read_c0_dtaglo();
249 itcblkgrn &= 0xfffe0000;
250 /* Set for 128 byte pitch of ITC cells */
251 itcblkgrn |= 0x00000c00;
252 /* Stage in Tag register */
253 write_c0_dtaglo(itcblkgrn);
255 /* Write out to ITU with CACHE op */
256 cache_op(Index_Store_Tag_D, INDEX_8);
257 /* Now set base address, and turn ITC on with 0x1 bit */
258 write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 );
260 /* Write out to ITU with CACHE op */
261 cache_op(Index_Store_Tag_D, INDEX_0);
262 write_c0_ecc(ectlval);
264 printk("Mapped %ld ITC cells starting at 0x%08x\n",
265 ((itcblkgrn & 0x7fe00000) >> 20), itc_base);
270 * Function to protect cache flushes from concurrent execution
271 * depends on MP software model chosen.
274 void mt_cflush_lockdown(void)
276 #ifdef CONFIG_MIPS_MT_SMTC
277 void smtc_cflush_lockdown(void);
279 smtc_cflush_lockdown();
280 #endif /* CONFIG_MIPS_MT_SMTC */
281 /* FILL IN VSMP and AP/SP VERSIONS HERE */
284 void mt_cflush_release(void)
286 #ifdef CONFIG_MIPS_MT_SMTC
287 void smtc_cflush_release(void);
289 smtc_cflush_release();
290 #endif /* CONFIG_MIPS_MT_SMTC */
291 /* FILL IN VSMP and AP/SP VERSIONS HERE */
294 struct class *mt_class;
296 static int __init mt_init(void)
300 mtc = class_create(THIS_MODULE, "mt");
309 subsys_initcall(mt_init);