xref: /openbmc/linux/arch/mips/kernel/mips-mt.c (revision b633648c5ad3cfbda0b3daea50d2135d44899259)
141c594abSRalf Baechle /*
2*b633648cSRalf Baechle  * General MIPS MT support routines, usable in AP/SP and SMVP.
341c594abSRalf Baechle  * Copyright (C) 2005 Mips Technologies, Inc
441c594abSRalf Baechle  */
541c594abSRalf Baechle 
627a3bbafSRalf Baechle #include <linux/device.h>
741c594abSRalf Baechle #include <linux/kernel.h>
841c594abSRalf Baechle #include <linux/sched.h>
973bc256dSPaul Gortmaker #include <linux/export.h>
1041c594abSRalf Baechle #include <linux/interrupt.h>
11f72af3cfSYoichi Yuasa #include <linux/security.h>
1241c594abSRalf Baechle 
1341c594abSRalf Baechle #include <asm/cpu.h>
1441c594abSRalf Baechle #include <asm/processor.h>
1560063497SArun Sharma #include <linux/atomic.h>
1641c594abSRalf Baechle #include <asm/hardirq.h>
1741c594abSRalf Baechle #include <asm/mmu_context.h>
1841c594abSRalf Baechle #include <asm/mipsmtregs.h>
1941c594abSRalf Baechle #include <asm/r4kcache.h>
2041c594abSRalf Baechle #include <asm/cacheflush.h>
2141c594abSRalf Baechle 
2207cc0c9eSRalf Baechle int vpelimit;
2307cc0c9eSRalf Baechle 
2407cc0c9eSRalf Baechle static int __init maxvpes(char *str)
2507cc0c9eSRalf Baechle {
2607cc0c9eSRalf Baechle 	get_option(&str, &vpelimit);
2707cc0c9eSRalf Baechle 
2807cc0c9eSRalf Baechle 	return 1;
2907cc0c9eSRalf Baechle }
3007cc0c9eSRalf Baechle 
3107cc0c9eSRalf Baechle __setup("maxvpes=", maxvpes);
3207cc0c9eSRalf Baechle 
3307cc0c9eSRalf Baechle int tclimit;
3407cc0c9eSRalf Baechle 
3507cc0c9eSRalf Baechle static int __init maxtcs(char *str)
3607cc0c9eSRalf Baechle {
3707cc0c9eSRalf Baechle 	get_option(&str, &tclimit);
3807cc0c9eSRalf Baechle 
3907cc0c9eSRalf Baechle 	return 1;
4007cc0c9eSRalf Baechle }
4107cc0c9eSRalf Baechle 
4207cc0c9eSRalf Baechle __setup("maxtcs=", maxtcs);
4307cc0c9eSRalf Baechle 
4441c594abSRalf Baechle /*
4541c594abSRalf Baechle  * Dump new MIPS MT state for the core. Does not leave TCs halted.
4641c594abSRalf Baechle  * Takes an argument which taken to be a pre-call MVPControl value.
4741c594abSRalf Baechle  */
4841c594abSRalf Baechle 
4941c594abSRalf Baechle void mips_mt_regdump(unsigned long mvpctl)
5041c594abSRalf Baechle {
5141c594abSRalf Baechle 	unsigned long flags;
5241c594abSRalf Baechle 	unsigned long vpflags;
5341c594abSRalf Baechle 	unsigned long mvpconf0;
5441c594abSRalf Baechle 	int nvpe;
5541c594abSRalf Baechle 	int ntc;
5641c594abSRalf Baechle 	int i;
5741c594abSRalf Baechle 	int tc;
5841c594abSRalf Baechle 	unsigned long haltval;
5941c594abSRalf Baechle 	unsigned long tcstatval;
6041c594abSRalf Baechle 
6141c594abSRalf Baechle 	local_irq_save(flags);
6241c594abSRalf Baechle 	vpflags = dvpe();
6341c594abSRalf Baechle 	printk("=== MIPS MT State Dump ===\n");
6441c594abSRalf Baechle 	printk("-- Global State --\n");
6541c594abSRalf Baechle 	printk("   MVPControl Passed: %08lx\n", mvpctl);
6641c594abSRalf Baechle 	printk("   MVPControl Read: %08lx\n", vpflags);
6741c594abSRalf Baechle 	printk("   MVPConf0 : %08lx\n", (mvpconf0 = read_c0_mvpconf0()));
6841c594abSRalf Baechle 	nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
6941c594abSRalf Baechle 	ntc = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
7041c594abSRalf Baechle 	printk("-- per-VPE State --\n");
7141c594abSRalf Baechle 	for (i = 0; i < nvpe; i++) {
7241c594abSRalf Baechle 		for (tc = 0; tc < ntc; tc++) {
7341c594abSRalf Baechle 			settc(tc);
7441c594abSRalf Baechle 			if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
7541c594abSRalf Baechle 				printk("  VPE %d\n", i);
76d223a861SRalf Baechle 				printk("   VPEControl : %08lx\n",
77d223a861SRalf Baechle 				       read_vpe_c0_vpecontrol());
78d223a861SRalf Baechle 				printk("   VPEConf0 : %08lx\n",
79d223a861SRalf Baechle 				       read_vpe_c0_vpeconf0());
8041c594abSRalf Baechle 				printk("   VPE%d.Status : %08lx\n",
8141c594abSRalf Baechle 				       i, read_vpe_c0_status());
82b012cffeSRalf Baechle 				printk("   VPE%d.EPC : %08lx %pS\n",
83b012cffeSRalf Baechle 				       i, read_vpe_c0_epc(),
84b012cffeSRalf Baechle 				       (void *) read_vpe_c0_epc());
85d223a861SRalf Baechle 				printk("   VPE%d.Cause : %08lx\n",
86d223a861SRalf Baechle 				       i, read_vpe_c0_cause());
8741c594abSRalf Baechle 				printk("   VPE%d.Config7 : %08lx\n",
8841c594abSRalf Baechle 				       i, read_vpe_c0_config7());
8941c594abSRalf Baechle 				break; /* Next VPE */
9041c594abSRalf Baechle 			}
9141c594abSRalf Baechle 		}
9241c594abSRalf Baechle 	}
9341c594abSRalf Baechle 	printk("-- per-TC State --\n");
9441c594abSRalf Baechle 	for (tc = 0; tc < ntc; tc++) {
9541c594abSRalf Baechle 		settc(tc);
9641c594abSRalf Baechle 		if (read_tc_c0_tcbind() == read_c0_tcbind()) {
9741c594abSRalf Baechle 			/* Are we dumping ourself?  */
9841c594abSRalf Baechle 			haltval = 0; /* Then we're not halted, and mustn't be */
9941c594abSRalf Baechle 			tcstatval = flags; /* And pre-dump TCStatus is flags */
10041c594abSRalf Baechle 			printk("  TC %d (current TC with VPE EPC above)\n", tc);
10141c594abSRalf Baechle 		} else {
10241c594abSRalf Baechle 			haltval = read_tc_c0_tchalt();
10341c594abSRalf Baechle 			write_tc_c0_tchalt(1);
10441c594abSRalf Baechle 			tcstatval = read_tc_c0_tcstatus();
10541c594abSRalf Baechle 			printk("  TC %d\n", tc);
10641c594abSRalf Baechle 		}
10741c594abSRalf Baechle 		printk("   TCStatus : %08lx\n", tcstatval);
10841c594abSRalf Baechle 		printk("   TCBind : %08lx\n", read_tc_c0_tcbind());
109b012cffeSRalf Baechle 		printk("   TCRestart : %08lx %pS\n",
110b012cffeSRalf Baechle 		       read_tc_c0_tcrestart(), (void *) read_tc_c0_tcrestart());
11141c594abSRalf Baechle 		printk("   TCHalt : %08lx\n", haltval);
11241c594abSRalf Baechle 		printk("   TCContext : %08lx\n", read_tc_c0_tccontext());
11341c594abSRalf Baechle 		if (!haltval)
11441c594abSRalf Baechle 			write_tc_c0_tchalt(0);
11541c594abSRalf Baechle 	}
11641c594abSRalf Baechle 	printk("===========================\n");
11741c594abSRalf Baechle 	evpe(vpflags);
11841c594abSRalf Baechle 	local_irq_restore(flags);
11941c594abSRalf Baechle }
12041c594abSRalf Baechle 
121982f6ffeSRalf Baechle static int mt_opt_norps;
12241c594abSRalf Baechle static int mt_opt_rpsctl = -1;
12341c594abSRalf Baechle static int mt_opt_nblsu = -1;
124982f6ffeSRalf Baechle static int mt_opt_forceconfig7;
12541c594abSRalf Baechle static int mt_opt_config7 = -1;
12641c594abSRalf Baechle 
12741c594abSRalf Baechle static int __init rps_disable(char *s)
12841c594abSRalf Baechle {
12941c594abSRalf Baechle 	mt_opt_norps = 1;
13041c594abSRalf Baechle 	return 1;
13141c594abSRalf Baechle }
13241c594abSRalf Baechle __setup("norps", rps_disable);
13341c594abSRalf Baechle 
13441c594abSRalf Baechle static int __init rpsctl_set(char *str)
13541c594abSRalf Baechle {
13641c594abSRalf Baechle 	get_option(&str, &mt_opt_rpsctl);
13741c594abSRalf Baechle 	return 1;
13841c594abSRalf Baechle }
13941c594abSRalf Baechle __setup("rpsctl=", rpsctl_set);
14041c594abSRalf Baechle 
14141c594abSRalf Baechle static int __init nblsu_set(char *str)
14241c594abSRalf Baechle {
14341c594abSRalf Baechle 	get_option(&str, &mt_opt_nblsu);
14441c594abSRalf Baechle 	return 1;
14541c594abSRalf Baechle }
14641c594abSRalf Baechle __setup("nblsu=", nblsu_set);
14741c594abSRalf Baechle 
14841c594abSRalf Baechle static int __init config7_set(char *str)
14941c594abSRalf Baechle {
15041c594abSRalf Baechle 	get_option(&str, &mt_opt_config7);
15141c594abSRalf Baechle 	mt_opt_forceconfig7 = 1;
15241c594abSRalf Baechle 	return 1;
15341c594abSRalf Baechle }
15441c594abSRalf Baechle __setup("config7=", config7_set);
15541c594abSRalf Baechle 
15641c594abSRalf Baechle /* Experimental cache flush control parameters that should go away some day */
157982f6ffeSRalf Baechle int mt_protiflush;
158982f6ffeSRalf Baechle int mt_protdflush;
15941c594abSRalf Baechle int mt_n_iflushes = 1;
16041c594abSRalf Baechle int mt_n_dflushes = 1;
16141c594abSRalf Baechle 
16241c594abSRalf Baechle static int __init set_protiflush(char *s)
16341c594abSRalf Baechle {
16441c594abSRalf Baechle 	mt_protiflush = 1;
16541c594abSRalf Baechle 	return 1;
16641c594abSRalf Baechle }
16741c594abSRalf Baechle __setup("protiflush", set_protiflush);
16841c594abSRalf Baechle 
16941c594abSRalf Baechle static int __init set_protdflush(char *s)
17041c594abSRalf Baechle {
17141c594abSRalf Baechle 	mt_protdflush = 1;
17241c594abSRalf Baechle 	return 1;
17341c594abSRalf Baechle }
17441c594abSRalf Baechle __setup("protdflush", set_protdflush);
17541c594abSRalf Baechle 
17641c594abSRalf Baechle static int __init niflush(char *s)
17741c594abSRalf Baechle {
17841c594abSRalf Baechle 	get_option(&s, &mt_n_iflushes);
17941c594abSRalf Baechle 	return 1;
18041c594abSRalf Baechle }
18141c594abSRalf Baechle __setup("niflush=", niflush);
18241c594abSRalf Baechle 
18341c594abSRalf Baechle static int __init ndflush(char *s)
18441c594abSRalf Baechle {
18541c594abSRalf Baechle 	get_option(&s, &mt_n_dflushes);
18641c594abSRalf Baechle 	return 1;
18741c594abSRalf Baechle }
18841c594abSRalf Baechle __setup("ndflush=", ndflush);
18941c594abSRalf Baechle 
190982f6ffeSRalf Baechle static unsigned int itc_base;
19141c594abSRalf Baechle 
19241c594abSRalf Baechle static int __init set_itc_base(char *str)
19341c594abSRalf Baechle {
19441c594abSRalf Baechle 	get_option(&str, &itc_base);
19541c594abSRalf Baechle 	return 1;
19641c594abSRalf Baechle }
19741c594abSRalf Baechle 
19841c594abSRalf Baechle __setup("itcbase=", set_itc_base);
19941c594abSRalf Baechle 
20041c594abSRalf Baechle void mips_mt_set_cpuoptions(void)
20141c594abSRalf Baechle {
20241c594abSRalf Baechle 	unsigned int oconfig7 = read_c0_config7();
20341c594abSRalf Baechle 	unsigned int nconfig7 = oconfig7;
20441c594abSRalf Baechle 
20541c594abSRalf Baechle 	if (mt_opt_norps) {
2066997991aSMasanari Iida 		printk("\"norps\" option deprecated: use \"rpsctl=\"\n");
20741c594abSRalf Baechle 	}
20841c594abSRalf Baechle 	if (mt_opt_rpsctl >= 0) {
20941c594abSRalf Baechle 		printk("34K return prediction stack override set to %d.\n",
21041c594abSRalf Baechle 			mt_opt_rpsctl);
21141c594abSRalf Baechle 		if (mt_opt_rpsctl)
21241c594abSRalf Baechle 			nconfig7 |= (1 << 2);
21341c594abSRalf Baechle 		else
21441c594abSRalf Baechle 			nconfig7 &= ~(1 << 2);
21541c594abSRalf Baechle 	}
21641c594abSRalf Baechle 	if (mt_opt_nblsu >= 0) {
21741c594abSRalf Baechle 		printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu);
21841c594abSRalf Baechle 		if (mt_opt_nblsu)
21941c594abSRalf Baechle 			nconfig7 |= (1 << 5);
22041c594abSRalf Baechle 		else
22141c594abSRalf Baechle 			nconfig7 &= ~(1 << 5);
22241c594abSRalf Baechle 	}
22341c594abSRalf Baechle 	if (mt_opt_forceconfig7) {
22441c594abSRalf Baechle 		printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7);
22541c594abSRalf Baechle 		nconfig7 = mt_opt_config7;
22641c594abSRalf Baechle 	}
22741c594abSRalf Baechle 	if (oconfig7 != nconfig7) {
22841c594abSRalf Baechle 		__asm__ __volatile("sync");
22941c594abSRalf Baechle 		write_c0_config7(nconfig7);
23041c594abSRalf Baechle 		ehb();
23141c594abSRalf Baechle 		printk("Config7: 0x%08x\n", read_c0_config7());
23241c594abSRalf Baechle 	}
23341c594abSRalf Baechle 
23441c594abSRalf Baechle 	/* Report Cache management debug options */
23541c594abSRalf Baechle 	if (mt_protiflush)
23641c594abSRalf Baechle 		printk("I-cache flushes single-threaded\n");
23741c594abSRalf Baechle 	if (mt_protdflush)
23841c594abSRalf Baechle 		printk("D-cache flushes single-threaded\n");
23941c594abSRalf Baechle 	if (mt_n_iflushes != 1)
24041c594abSRalf Baechle 		printk("I-Cache Flushes Repeated %d times\n", mt_n_iflushes);
24141c594abSRalf Baechle 	if (mt_n_dflushes != 1)
24241c594abSRalf Baechle 		printk("D-Cache Flushes Repeated %d times\n", mt_n_dflushes);
24341c594abSRalf Baechle 
24441c594abSRalf Baechle 	if (itc_base != 0) {
24541c594abSRalf Baechle 		/*
24641c594abSRalf Baechle 		 * Configure ITC mapping.  This code is very
24741c594abSRalf Baechle 		 * specific to the 34K core family, which uses
24841c594abSRalf Baechle 		 * a special mode bit ("ITC") in the ErrCtl
24941c594abSRalf Baechle 		 * register to enable access to ITC control
25041c594abSRalf Baechle 		 * registers via cache "tag" operations.
25141c594abSRalf Baechle 		 */
25241c594abSRalf Baechle 		unsigned long ectlval;
25341c594abSRalf Baechle 		unsigned long itcblkgrn;
25441c594abSRalf Baechle 
25541c594abSRalf Baechle 		/* ErrCtl register is known as "ecc" to Linux */
25641c594abSRalf Baechle 		ectlval = read_c0_ecc();
25741c594abSRalf Baechle 		write_c0_ecc(ectlval | (0x1 << 26));
25841c594abSRalf Baechle 		ehb();
25941c594abSRalf Baechle #define INDEX_0 (0x80000000)
26041c594abSRalf Baechle #define INDEX_8 (0x80000008)
26141c594abSRalf Baechle 		/* Read "cache tag" for Dcache pseudo-index 8 */
26241c594abSRalf Baechle 		cache_op(Index_Load_Tag_D, INDEX_8);
26341c594abSRalf Baechle 		ehb();
26441c594abSRalf Baechle 		itcblkgrn = read_c0_dtaglo();
26541c594abSRalf Baechle 		itcblkgrn &= 0xfffe0000;
26641c594abSRalf Baechle 		/* Set for 128 byte pitch of ITC cells */
26741c594abSRalf Baechle 		itcblkgrn |= 0x00000c00;
26841c594abSRalf Baechle 		/* Stage in Tag register */
26941c594abSRalf Baechle 		write_c0_dtaglo(itcblkgrn);
27041c594abSRalf Baechle 		ehb();
27141c594abSRalf Baechle 		/* Write out to ITU with CACHE op */
27241c594abSRalf Baechle 		cache_op(Index_Store_Tag_D, INDEX_8);
27341c594abSRalf Baechle 		/* Now set base address, and turn ITC on with 0x1 bit */
27441c594abSRalf Baechle 		write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 );
27541c594abSRalf Baechle 		ehb();
27641c594abSRalf Baechle 		/* Write out to ITU with CACHE op */
27741c594abSRalf Baechle 		cache_op(Index_Store_Tag_D, INDEX_0);
27841c594abSRalf Baechle 		write_c0_ecc(ectlval);
27941c594abSRalf Baechle 		ehb();
28041c594abSRalf Baechle 		printk("Mapped %ld ITC cells starting at 0x%08x\n",
28141c594abSRalf Baechle 			((itcblkgrn & 0x7fe00000) >> 20), itc_base);
28241c594abSRalf Baechle 	}
28341c594abSRalf Baechle }
28441c594abSRalf Baechle 
28541c594abSRalf Baechle /*
28641c594abSRalf Baechle  * Function to protect cache flushes from concurrent execution
28741c594abSRalf Baechle  * depends on MP software model chosen.
28841c594abSRalf Baechle  */
28941c594abSRalf Baechle 
29041c594abSRalf Baechle void mt_cflush_lockdown(void)
29141c594abSRalf Baechle {
29241c594abSRalf Baechle 	/* FILL IN VSMP and AP/SP VERSIONS HERE */
29341c594abSRalf Baechle }
29441c594abSRalf Baechle 
29541c594abSRalf Baechle void mt_cflush_release(void)
29641c594abSRalf Baechle {
29741c594abSRalf Baechle 	/* FILL IN VSMP and AP/SP VERSIONS HERE */
29841c594abSRalf Baechle }
29927a3bbafSRalf Baechle 
30027a3bbafSRalf Baechle struct class *mt_class;
30127a3bbafSRalf Baechle 
30227a3bbafSRalf Baechle static int __init mt_init(void)
30327a3bbafSRalf Baechle {
30427a3bbafSRalf Baechle 	struct class *mtc;
30527a3bbafSRalf Baechle 
30627a3bbafSRalf Baechle 	mtc = class_create(THIS_MODULE, "mt");
30727a3bbafSRalf Baechle 	if (IS_ERR(mtc))
30827a3bbafSRalf Baechle 		return PTR_ERR(mtc);
30927a3bbafSRalf Baechle 
31027a3bbafSRalf Baechle 	mt_class = mtc;
31127a3bbafSRalf Baechle 
31227a3bbafSRalf Baechle 	return 0;
31327a3bbafSRalf Baechle }
31427a3bbafSRalf Baechle 
31527a3bbafSRalf Baechle subsys_initcall(mt_init);
316