xref: /openbmc/linux/arch/mips/kernel/mips-mt.c (revision 60063497a95e716c9a689af3be2687d261f115b4)
141c594abSRalf Baechle /*
241c594abSRalf Baechle  * General MIPS MT support routines, usable in AP/SP, SMVP, or SMTC kernels
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>
927a3bbafSRalf Baechle #include <linux/module.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>
15*60063497SArun Sharma #include <linux/atomic.h>
1641c594abSRalf Baechle #include <asm/system.h>
1741c594abSRalf Baechle #include <asm/hardirq.h>
1841c594abSRalf Baechle #include <asm/mmu_context.h>
1941c594abSRalf Baechle #include <asm/mipsmtregs.h>
2041c594abSRalf Baechle #include <asm/r4kcache.h>
2141c594abSRalf Baechle #include <asm/cacheflush.h>
2241c594abSRalf Baechle 
2307cc0c9eSRalf Baechle int vpelimit;
2407cc0c9eSRalf Baechle 
2507cc0c9eSRalf Baechle static int __init maxvpes(char *str)
2607cc0c9eSRalf Baechle {
2707cc0c9eSRalf Baechle 	get_option(&str, &vpelimit);
2807cc0c9eSRalf Baechle 
2907cc0c9eSRalf Baechle 	return 1;
3007cc0c9eSRalf Baechle }
3107cc0c9eSRalf Baechle 
3207cc0c9eSRalf Baechle __setup("maxvpes=", maxvpes);
3307cc0c9eSRalf Baechle 
3407cc0c9eSRalf Baechle int tclimit;
3507cc0c9eSRalf Baechle 
3607cc0c9eSRalf Baechle static int __init maxtcs(char *str)
3707cc0c9eSRalf Baechle {
3807cc0c9eSRalf Baechle 	get_option(&str, &tclimit);
3907cc0c9eSRalf Baechle 
4007cc0c9eSRalf Baechle 	return 1;
4107cc0c9eSRalf Baechle }
4207cc0c9eSRalf Baechle 
4307cc0c9eSRalf Baechle __setup("maxtcs=", maxtcs);
4407cc0c9eSRalf Baechle 
4541c594abSRalf Baechle /*
4641c594abSRalf Baechle  * Dump new MIPS MT state for the core. Does not leave TCs halted.
4741c594abSRalf Baechle  * Takes an argument which taken to be a pre-call MVPControl value.
4841c594abSRalf Baechle  */
4941c594abSRalf Baechle 
5041c594abSRalf Baechle void mips_mt_regdump(unsigned long mvpctl)
5141c594abSRalf Baechle {
5241c594abSRalf Baechle 	unsigned long flags;
5341c594abSRalf Baechle 	unsigned long vpflags;
5441c594abSRalf Baechle 	unsigned long mvpconf0;
5541c594abSRalf Baechle 	int nvpe;
5641c594abSRalf Baechle 	int ntc;
5741c594abSRalf Baechle 	int i;
5841c594abSRalf Baechle 	int tc;
5941c594abSRalf Baechle 	unsigned long haltval;
6041c594abSRalf Baechle 	unsigned long tcstatval;
6141c594abSRalf Baechle #ifdef CONFIG_MIPS_MT_SMTC
6241c594abSRalf Baechle 	void smtc_soft_dump(void);
6341c594abSRalf Baechle #endif /* CONFIG_MIPT_MT_SMTC */
6441c594abSRalf Baechle 
6541c594abSRalf Baechle 	local_irq_save(flags);
6641c594abSRalf Baechle 	vpflags = dvpe();
6741c594abSRalf Baechle 	printk("=== MIPS MT State Dump ===\n");
6841c594abSRalf Baechle 	printk("-- Global State --\n");
6941c594abSRalf Baechle 	printk("   MVPControl Passed: %08lx\n", mvpctl);
7041c594abSRalf Baechle 	printk("   MVPControl Read: %08lx\n", vpflags);
7141c594abSRalf Baechle 	printk("   MVPConf0 : %08lx\n", (mvpconf0 = read_c0_mvpconf0()));
7241c594abSRalf Baechle 	nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
7341c594abSRalf Baechle 	ntc = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
7441c594abSRalf Baechle 	printk("-- per-VPE State --\n");
7541c594abSRalf Baechle 	for (i = 0; i < nvpe; i++) {
7641c594abSRalf Baechle 		for (tc = 0; tc < ntc; tc++) {
7741c594abSRalf Baechle 			settc(tc);
7841c594abSRalf Baechle 			if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
7941c594abSRalf Baechle 				printk("  VPE %d\n", i);
80d223a861SRalf Baechle 				printk("   VPEControl : %08lx\n",
81d223a861SRalf Baechle 				       read_vpe_c0_vpecontrol());
82d223a861SRalf Baechle 				printk("   VPEConf0 : %08lx\n",
83d223a861SRalf Baechle 				       read_vpe_c0_vpeconf0());
8441c594abSRalf Baechle 				printk("   VPE%d.Status : %08lx\n",
8541c594abSRalf Baechle 				       i, read_vpe_c0_status());
86b012cffeSRalf Baechle 				printk("   VPE%d.EPC : %08lx %pS\n",
87b012cffeSRalf Baechle 				       i, read_vpe_c0_epc(),
88b012cffeSRalf Baechle 				       (void *) read_vpe_c0_epc());
89d223a861SRalf Baechle 				printk("   VPE%d.Cause : %08lx\n",
90d223a861SRalf Baechle 				       i, read_vpe_c0_cause());
9141c594abSRalf Baechle 				printk("   VPE%d.Config7 : %08lx\n",
9241c594abSRalf Baechle 				       i, read_vpe_c0_config7());
9341c594abSRalf Baechle 				break; /* Next VPE */
9441c594abSRalf Baechle 			}
9541c594abSRalf Baechle 		}
9641c594abSRalf Baechle 	}
9741c594abSRalf Baechle 	printk("-- per-TC State --\n");
9841c594abSRalf Baechle 	for (tc = 0; tc < ntc; tc++) {
9941c594abSRalf Baechle 		settc(tc);
10041c594abSRalf Baechle 		if (read_tc_c0_tcbind() == read_c0_tcbind()) {
10141c594abSRalf Baechle 			/* Are we dumping ourself?  */
10241c594abSRalf Baechle 			haltval = 0; /* Then we're not halted, and mustn't be */
10341c594abSRalf Baechle 			tcstatval = flags; /* And pre-dump TCStatus is flags */
10441c594abSRalf Baechle 			printk("  TC %d (current TC with VPE EPC above)\n", tc);
10541c594abSRalf Baechle 		} else {
10641c594abSRalf Baechle 			haltval = read_tc_c0_tchalt();
10741c594abSRalf Baechle 			write_tc_c0_tchalt(1);
10841c594abSRalf Baechle 			tcstatval = read_tc_c0_tcstatus();
10941c594abSRalf Baechle 			printk("  TC %d\n", tc);
11041c594abSRalf Baechle 		}
11141c594abSRalf Baechle 		printk("   TCStatus : %08lx\n", tcstatval);
11241c594abSRalf Baechle 		printk("   TCBind : %08lx\n", read_tc_c0_tcbind());
113b012cffeSRalf Baechle 		printk("   TCRestart : %08lx %pS\n",
114b012cffeSRalf Baechle 		       read_tc_c0_tcrestart(), (void *) read_tc_c0_tcrestart());
11541c594abSRalf Baechle 		printk("   TCHalt : %08lx\n", haltval);
11641c594abSRalf Baechle 		printk("   TCContext : %08lx\n", read_tc_c0_tccontext());
11741c594abSRalf Baechle 		if (!haltval)
11841c594abSRalf Baechle 			write_tc_c0_tchalt(0);
11941c594abSRalf Baechle 	}
12041c594abSRalf Baechle #ifdef CONFIG_MIPS_MT_SMTC
12141c594abSRalf Baechle 	smtc_soft_dump();
12241c594abSRalf Baechle #endif /* CONFIG_MIPT_MT_SMTC */
12341c594abSRalf Baechle 	printk("===========================\n");
12441c594abSRalf Baechle 	evpe(vpflags);
12541c594abSRalf Baechle 	local_irq_restore(flags);
12641c594abSRalf Baechle }
12741c594abSRalf Baechle 
128982f6ffeSRalf Baechle static int mt_opt_norps;
12941c594abSRalf Baechle static int mt_opt_rpsctl = -1;
13041c594abSRalf Baechle static int mt_opt_nblsu = -1;
131982f6ffeSRalf Baechle static int mt_opt_forceconfig7;
13241c594abSRalf Baechle static int mt_opt_config7 = -1;
13341c594abSRalf Baechle 
13441c594abSRalf Baechle static int __init rps_disable(char *s)
13541c594abSRalf Baechle {
13641c594abSRalf Baechle 	mt_opt_norps = 1;
13741c594abSRalf Baechle 	return 1;
13841c594abSRalf Baechle }
13941c594abSRalf Baechle __setup("norps", rps_disable);
14041c594abSRalf Baechle 
14141c594abSRalf Baechle static int __init rpsctl_set(char *str)
14241c594abSRalf Baechle {
14341c594abSRalf Baechle 	get_option(&str, &mt_opt_rpsctl);
14441c594abSRalf Baechle 	return 1;
14541c594abSRalf Baechle }
14641c594abSRalf Baechle __setup("rpsctl=", rpsctl_set);
14741c594abSRalf Baechle 
14841c594abSRalf Baechle static int __init nblsu_set(char *str)
14941c594abSRalf Baechle {
15041c594abSRalf Baechle 	get_option(&str, &mt_opt_nblsu);
15141c594abSRalf Baechle 	return 1;
15241c594abSRalf Baechle }
15341c594abSRalf Baechle __setup("nblsu=", nblsu_set);
15441c594abSRalf Baechle 
15541c594abSRalf Baechle static int __init config7_set(char *str)
15641c594abSRalf Baechle {
15741c594abSRalf Baechle 	get_option(&str, &mt_opt_config7);
15841c594abSRalf Baechle 	mt_opt_forceconfig7 = 1;
15941c594abSRalf Baechle 	return 1;
16041c594abSRalf Baechle }
16141c594abSRalf Baechle __setup("config7=", config7_set);
16241c594abSRalf Baechle 
16341c594abSRalf Baechle /* Experimental cache flush control parameters that should go away some day */
164982f6ffeSRalf Baechle int mt_protiflush;
165982f6ffeSRalf Baechle int mt_protdflush;
16641c594abSRalf Baechle int mt_n_iflushes = 1;
16741c594abSRalf Baechle int mt_n_dflushes = 1;
16841c594abSRalf Baechle 
16941c594abSRalf Baechle static int __init set_protiflush(char *s)
17041c594abSRalf Baechle {
17141c594abSRalf Baechle 	mt_protiflush = 1;
17241c594abSRalf Baechle 	return 1;
17341c594abSRalf Baechle }
17441c594abSRalf Baechle __setup("protiflush", set_protiflush);
17541c594abSRalf Baechle 
17641c594abSRalf Baechle static int __init set_protdflush(char *s)
17741c594abSRalf Baechle {
17841c594abSRalf Baechle 	mt_protdflush = 1;
17941c594abSRalf Baechle 	return 1;
18041c594abSRalf Baechle }
18141c594abSRalf Baechle __setup("protdflush", set_protdflush);
18241c594abSRalf Baechle 
18341c594abSRalf Baechle static int __init niflush(char *s)
18441c594abSRalf Baechle {
18541c594abSRalf Baechle 	get_option(&s, &mt_n_iflushes);
18641c594abSRalf Baechle 	return 1;
18741c594abSRalf Baechle }
18841c594abSRalf Baechle __setup("niflush=", niflush);
18941c594abSRalf Baechle 
19041c594abSRalf Baechle static int __init ndflush(char *s)
19141c594abSRalf Baechle {
19241c594abSRalf Baechle 	get_option(&s, &mt_n_dflushes);
19341c594abSRalf Baechle 	return 1;
19441c594abSRalf Baechle }
19541c594abSRalf Baechle __setup("ndflush=", ndflush);
19641c594abSRalf Baechle 
197982f6ffeSRalf Baechle static unsigned int itc_base;
19841c594abSRalf Baechle 
19941c594abSRalf Baechle static int __init set_itc_base(char *str)
20041c594abSRalf Baechle {
20141c594abSRalf Baechle 	get_option(&str, &itc_base);
20241c594abSRalf Baechle 	return 1;
20341c594abSRalf Baechle }
20441c594abSRalf Baechle 
20541c594abSRalf Baechle __setup("itcbase=", set_itc_base);
20641c594abSRalf Baechle 
20741c594abSRalf Baechle void mips_mt_set_cpuoptions(void)
20841c594abSRalf Baechle {
20941c594abSRalf Baechle 	unsigned int oconfig7 = read_c0_config7();
21041c594abSRalf Baechle 	unsigned int nconfig7 = oconfig7;
21141c594abSRalf Baechle 
21241c594abSRalf Baechle 	if (mt_opt_norps) {
21341c594abSRalf Baechle 		printk("\"norps\" option deprectated: use \"rpsctl=\"\n");
21441c594abSRalf Baechle 	}
21541c594abSRalf Baechle 	if (mt_opt_rpsctl >= 0) {
21641c594abSRalf Baechle 		printk("34K return prediction stack override set to %d.\n",
21741c594abSRalf Baechle 			mt_opt_rpsctl);
21841c594abSRalf Baechle 		if (mt_opt_rpsctl)
21941c594abSRalf Baechle 			nconfig7 |= (1 << 2);
22041c594abSRalf Baechle 		else
22141c594abSRalf Baechle 			nconfig7 &= ~(1 << 2);
22241c594abSRalf Baechle 	}
22341c594abSRalf Baechle 	if (mt_opt_nblsu >= 0) {
22441c594abSRalf Baechle 		printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu);
22541c594abSRalf Baechle 		if (mt_opt_nblsu)
22641c594abSRalf Baechle 			nconfig7 |= (1 << 5);
22741c594abSRalf Baechle 		else
22841c594abSRalf Baechle 			nconfig7 &= ~(1 << 5);
22941c594abSRalf Baechle 	}
23041c594abSRalf Baechle 	if (mt_opt_forceconfig7) {
23141c594abSRalf Baechle 		printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7);
23241c594abSRalf Baechle 		nconfig7 = mt_opt_config7;
23341c594abSRalf Baechle 	}
23441c594abSRalf Baechle 	if (oconfig7 != nconfig7) {
23541c594abSRalf Baechle 		__asm__ __volatile("sync");
23641c594abSRalf Baechle 		write_c0_config7(nconfig7);
23741c594abSRalf Baechle 		ehb();
23841c594abSRalf Baechle 		printk("Config7: 0x%08x\n", read_c0_config7());
23941c594abSRalf Baechle 	}
24041c594abSRalf Baechle 
24141c594abSRalf Baechle 	/* Report Cache management debug options */
24241c594abSRalf Baechle 	if (mt_protiflush)
24341c594abSRalf Baechle 		printk("I-cache flushes single-threaded\n");
24441c594abSRalf Baechle 	if (mt_protdflush)
24541c594abSRalf Baechle 		printk("D-cache flushes single-threaded\n");
24641c594abSRalf Baechle 	if (mt_n_iflushes != 1)
24741c594abSRalf Baechle 		printk("I-Cache Flushes Repeated %d times\n", mt_n_iflushes);
24841c594abSRalf Baechle 	if (mt_n_dflushes != 1)
24941c594abSRalf Baechle 		printk("D-Cache Flushes Repeated %d times\n", mt_n_dflushes);
25041c594abSRalf Baechle 
25141c594abSRalf Baechle 	if (itc_base != 0) {
25241c594abSRalf Baechle 		/*
25341c594abSRalf Baechle 		 * Configure ITC mapping.  This code is very
25441c594abSRalf Baechle 		 * specific to the 34K core family, which uses
25541c594abSRalf Baechle 		 * a special mode bit ("ITC") in the ErrCtl
25641c594abSRalf Baechle 		 * register to enable access to ITC control
25741c594abSRalf Baechle 		 * registers via cache "tag" operations.
25841c594abSRalf Baechle 		 */
25941c594abSRalf Baechle 		unsigned long ectlval;
26041c594abSRalf Baechle 		unsigned long itcblkgrn;
26141c594abSRalf Baechle 
26241c594abSRalf Baechle 		/* ErrCtl register is known as "ecc" to Linux */
26341c594abSRalf Baechle 		ectlval = read_c0_ecc();
26441c594abSRalf Baechle 		write_c0_ecc(ectlval | (0x1 << 26));
26541c594abSRalf Baechle 		ehb();
26641c594abSRalf Baechle #define INDEX_0 (0x80000000)
26741c594abSRalf Baechle #define INDEX_8 (0x80000008)
26841c594abSRalf Baechle 		/* Read "cache tag" for Dcache pseudo-index 8 */
26941c594abSRalf Baechle 		cache_op(Index_Load_Tag_D, INDEX_8);
27041c594abSRalf Baechle 		ehb();
27141c594abSRalf Baechle 		itcblkgrn = read_c0_dtaglo();
27241c594abSRalf Baechle 		itcblkgrn &= 0xfffe0000;
27341c594abSRalf Baechle 		/* Set for 128 byte pitch of ITC cells */
27441c594abSRalf Baechle 		itcblkgrn |= 0x00000c00;
27541c594abSRalf Baechle 		/* Stage in Tag register */
27641c594abSRalf Baechle 		write_c0_dtaglo(itcblkgrn);
27741c594abSRalf Baechle 		ehb();
27841c594abSRalf Baechle 		/* Write out to ITU with CACHE op */
27941c594abSRalf Baechle 		cache_op(Index_Store_Tag_D, INDEX_8);
28041c594abSRalf Baechle 		/* Now set base address, and turn ITC on with 0x1 bit */
28141c594abSRalf Baechle 		write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 );
28241c594abSRalf Baechle 		ehb();
28341c594abSRalf Baechle 		/* Write out to ITU with CACHE op */
28441c594abSRalf Baechle 		cache_op(Index_Store_Tag_D, INDEX_0);
28541c594abSRalf Baechle 		write_c0_ecc(ectlval);
28641c594abSRalf Baechle 		ehb();
28741c594abSRalf Baechle 		printk("Mapped %ld ITC cells starting at 0x%08x\n",
28841c594abSRalf Baechle 			((itcblkgrn & 0x7fe00000) >> 20), itc_base);
28941c594abSRalf Baechle 	}
29041c594abSRalf Baechle }
29141c594abSRalf Baechle 
29241c594abSRalf Baechle /*
29341c594abSRalf Baechle  * Function to protect cache flushes from concurrent execution
29441c594abSRalf Baechle  * depends on MP software model chosen.
29541c594abSRalf Baechle  */
29641c594abSRalf Baechle 
29741c594abSRalf Baechle void mt_cflush_lockdown(void)
29841c594abSRalf Baechle {
29941c594abSRalf Baechle #ifdef CONFIG_MIPS_MT_SMTC
30041c594abSRalf Baechle 	void smtc_cflush_lockdown(void);
30141c594abSRalf Baechle 
30241c594abSRalf Baechle 	smtc_cflush_lockdown();
30341c594abSRalf Baechle #endif /* CONFIG_MIPS_MT_SMTC */
30441c594abSRalf Baechle 	/* FILL IN VSMP and AP/SP VERSIONS HERE */
30541c594abSRalf Baechle }
30641c594abSRalf Baechle 
30741c594abSRalf Baechle void mt_cflush_release(void)
30841c594abSRalf Baechle {
30941c594abSRalf Baechle #ifdef CONFIG_MIPS_MT_SMTC
31041c594abSRalf Baechle 	void smtc_cflush_release(void);
31141c594abSRalf Baechle 
31241c594abSRalf Baechle 	smtc_cflush_release();
31341c594abSRalf Baechle #endif /* CONFIG_MIPS_MT_SMTC */
31441c594abSRalf Baechle 	/* FILL IN VSMP and AP/SP VERSIONS HERE */
31541c594abSRalf Baechle }
31627a3bbafSRalf Baechle 
31727a3bbafSRalf Baechle struct class *mt_class;
31827a3bbafSRalf Baechle 
31927a3bbafSRalf Baechle static int __init mt_init(void)
32027a3bbafSRalf Baechle {
32127a3bbafSRalf Baechle 	struct class *mtc;
32227a3bbafSRalf Baechle 
32327a3bbafSRalf Baechle 	mtc = class_create(THIS_MODULE, "mt");
32427a3bbafSRalf Baechle 	if (IS_ERR(mtc))
32527a3bbafSRalf Baechle 		return PTR_ERR(mtc);
32627a3bbafSRalf Baechle 
32727a3bbafSRalf Baechle 	mt_class = mtc;
32827a3bbafSRalf Baechle 
32927a3bbafSRalf Baechle 	return 0;
33027a3bbafSRalf Baechle }
33127a3bbafSRalf Baechle 
33227a3bbafSRalf Baechle subsys_initcall(mt_init);
333