1 // SPDX-License-Identifier: GPL-2.0
3 * General MIPS MT support routines, usable in AP/SP and SMVP.
4 * Copyright (C) 2005 Mips Technologies, Inc
7 #include <linux/device.h>
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/export.h>
11 #include <linux/interrupt.h>
12 #include <linux/security.h>
15 #include <asm/processor.h>
16 #include <linux/atomic.h>
17 #include <asm/hardirq.h>
18 #include <asm/mmu_context.h>
19 #include <asm/mipsmtregs.h>
20 #include <asm/r4kcache.h>
21 #include <asm/cacheflush.h>
25 static int __init
maxvpes(char *str
)
27 get_option(&str
, &vpelimit
);
32 __setup("maxvpes=", maxvpes
);
36 static int __init
maxtcs(char *str
)
38 get_option(&str
, &tclimit
);
43 __setup("maxtcs=", maxtcs
);
46 * Dump new MIPS MT state for the core. Does not leave TCs halted.
47 * Takes an argument which taken to be a pre-call MVPControl value.
50 void mips_mt_regdump(unsigned long mvpctl
)
53 unsigned long vpflags
;
54 unsigned long mvpconf0
;
59 unsigned long haltval
;
60 unsigned long tcstatval
;
62 local_irq_save(flags
);
64 printk("=== MIPS MT State Dump ===\n");
65 printk("-- Global State --\n");
66 printk(" MVPControl Passed: %08lx\n", mvpctl
);
67 printk(" MVPControl Read: %08lx\n", vpflags
);
68 printk(" MVPConf0 : %08lx\n", (mvpconf0
= read_c0_mvpconf0()));
69 nvpe
= ((mvpconf0
& MVPCONF0_PVPE
) >> MVPCONF0_PVPE_SHIFT
) + 1;
70 ntc
= ((mvpconf0
& MVPCONF0_PTC
) >> MVPCONF0_PTC_SHIFT
) + 1;
71 printk("-- per-VPE State --\n");
72 for (i
= 0; i
< nvpe
; i
++) {
73 for (tc
= 0; tc
< ntc
; tc
++) {
75 if ((read_tc_c0_tcbind() & TCBIND_CURVPE
) == i
) {
76 printk(" VPE %d\n", i
);
77 printk(" VPEControl : %08lx\n",
78 read_vpe_c0_vpecontrol());
79 printk(" VPEConf0 : %08lx\n",
80 read_vpe_c0_vpeconf0());
81 printk(" VPE%d.Status : %08lx\n",
82 i
, read_vpe_c0_status());
83 printk(" VPE%d.EPC : %08lx %pS\n",
85 (void *) read_vpe_c0_epc());
86 printk(" VPE%d.Cause : %08lx\n",
87 i
, read_vpe_c0_cause());
88 printk(" VPE%d.Config7 : %08lx\n",
89 i
, read_vpe_c0_config7());
94 printk("-- per-TC State --\n");
95 for (tc
= 0; tc
< ntc
; tc
++) {
97 if (read_tc_c0_tcbind() == read_c0_tcbind()) {
98 /* Are we dumping ourself? */
99 haltval
= 0; /* Then we're not halted, and mustn't be */
100 tcstatval
= flags
; /* And pre-dump TCStatus is flags */
101 printk(" TC %d (current TC with VPE EPC above)\n", tc
);
103 haltval
= read_tc_c0_tchalt();
104 write_tc_c0_tchalt(1);
105 tcstatval
= read_tc_c0_tcstatus();
106 printk(" TC %d\n", tc
);
108 printk(" TCStatus : %08lx\n", tcstatval
);
109 printk(" TCBind : %08lx\n", read_tc_c0_tcbind());
110 printk(" TCRestart : %08lx %pS\n",
111 read_tc_c0_tcrestart(), (void *) read_tc_c0_tcrestart());
112 printk(" TCHalt : %08lx\n", haltval
);
113 printk(" TCContext : %08lx\n", read_tc_c0_tccontext());
115 write_tc_c0_tchalt(0);
117 printk("===========================\n");
119 local_irq_restore(flags
);
122 static int mt_opt_norps
;
123 static int mt_opt_rpsctl
= -1;
124 static int mt_opt_nblsu
= -1;
125 static int mt_opt_forceconfig7
;
126 static int mt_opt_config7
= -1;
128 static int __init
rps_disable(char *s
)
133 __setup("norps", rps_disable
);
135 static int __init
rpsctl_set(char *str
)
137 get_option(&str
, &mt_opt_rpsctl
);
140 __setup("rpsctl=", rpsctl_set
);
142 static int __init
nblsu_set(char *str
)
144 get_option(&str
, &mt_opt_nblsu
);
147 __setup("nblsu=", nblsu_set
);
149 static int __init
config7_set(char *str
)
151 get_option(&str
, &mt_opt_config7
);
152 mt_opt_forceconfig7
= 1;
155 __setup("config7=", config7_set
);
157 /* Experimental cache flush control parameters that should go away some day */
160 int mt_n_iflushes
= 1;
161 int mt_n_dflushes
= 1;
163 static int __init
set_protiflush(char *s
)
168 __setup("protiflush", set_protiflush
);
170 static int __init
set_protdflush(char *s
)
175 __setup("protdflush", set_protdflush
);
177 static int __init
niflush(char *s
)
179 get_option(&s
, &mt_n_iflushes
);
182 __setup("niflush=", niflush
);
184 static int __init
ndflush(char *s
)
186 get_option(&s
, &mt_n_dflushes
);
189 __setup("ndflush=", ndflush
);
191 static unsigned int itc_base
;
193 static int __init
set_itc_base(char *str
)
195 get_option(&str
, &itc_base
);
199 __setup("itcbase=", set_itc_base
);
201 void mips_mt_set_cpuoptions(void)
203 unsigned int oconfig7
= read_c0_config7();
204 unsigned int nconfig7
= oconfig7
;
207 printk("\"norps\" option deprecated: use \"rpsctl=\"\n");
209 if (mt_opt_rpsctl
>= 0) {
210 printk("34K return prediction stack override set to %d.\n",
213 nconfig7
|= (1 << 2);
215 nconfig7
&= ~(1 << 2);
217 if (mt_opt_nblsu
>= 0) {
218 printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu
);
220 nconfig7
|= (1 << 5);
222 nconfig7
&= ~(1 << 5);
224 if (mt_opt_forceconfig7
) {
225 printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7
);
226 nconfig7
= mt_opt_config7
;
228 if (oconfig7
!= nconfig7
) {
229 __asm__
__volatile("sync");
230 write_c0_config7(nconfig7
);
232 printk("Config7: 0x%08x\n", read_c0_config7());
235 /* Report Cache management debug options */
237 printk("I-cache flushes single-threaded\n");
239 printk("D-cache flushes single-threaded\n");
240 if (mt_n_iflushes
!= 1)
241 printk("I-Cache Flushes Repeated %d times\n", mt_n_iflushes
);
242 if (mt_n_dflushes
!= 1)
243 printk("D-Cache Flushes Repeated %d times\n", mt_n_dflushes
);
247 * Configure ITC mapping. This code is very
248 * specific to the 34K core family, which uses
249 * a special mode bit ("ITC") in the ErrCtl
250 * register to enable access to ITC control
251 * registers via cache "tag" operations.
253 unsigned long ectlval
;
254 unsigned long itcblkgrn
;
256 /* ErrCtl register is known as "ecc" to Linux */
257 ectlval
= read_c0_ecc();
258 write_c0_ecc(ectlval
| (0x1 << 26));
260 #define INDEX_0 (0x80000000)
261 #define INDEX_8 (0x80000008)
262 /* Read "cache tag" for Dcache pseudo-index 8 */
263 cache_op(Index_Load_Tag_D
, INDEX_8
);
265 itcblkgrn
= read_c0_dtaglo();
266 itcblkgrn
&= 0xfffe0000;
267 /* Set for 128 byte pitch of ITC cells */
268 itcblkgrn
|= 0x00000c00;
269 /* Stage in Tag register */
270 write_c0_dtaglo(itcblkgrn
);
272 /* Write out to ITU with CACHE op */
273 cache_op(Index_Store_Tag_D
, INDEX_8
);
274 /* Now set base address, and turn ITC on with 0x1 bit */
275 write_c0_dtaglo((itc_base
& 0xfffffc00) | 0x1 );
277 /* Write out to ITU with CACHE op */
278 cache_op(Index_Store_Tag_D
, INDEX_0
);
279 write_c0_ecc(ectlval
);
281 printk("Mapped %ld ITC cells starting at 0x%08x\n",
282 ((itcblkgrn
& 0x7fe00000) >> 20), itc_base
);
287 * Function to protect cache flushes from concurrent execution
288 * depends on MP software model chosen.
291 void mt_cflush_lockdown(void)
293 /* FILL IN VSMP and AP/SP VERSIONS HERE */
296 void mt_cflush_release(void)
298 /* FILL IN VSMP and AP/SP VERSIONS HERE */
301 struct class *mt_class
;
303 static int __init
mt_init(void)
307 mtc
= class_create(THIS_MODULE
, "mt");
316 subsys_initcall(mt_init
);