1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
241c594abSRalf Baechle /*
3b633648cSRalf Baechle * General MIPS MT support routines, usable in AP/SP and SMVP.
441c594abSRalf Baechle * Copyright (C) 2005 Mips Technologies, Inc
541c594abSRalf Baechle */
641c594abSRalf Baechle
727a3bbafSRalf Baechle #include <linux/device.h>
841c594abSRalf Baechle #include <linux/kernel.h>
941c594abSRalf Baechle #include <linux/sched.h>
1073bc256dSPaul Gortmaker #include <linux/export.h>
1141c594abSRalf Baechle #include <linux/interrupt.h>
12f72af3cfSYoichi Yuasa #include <linux/security.h>
1341c594abSRalf Baechle
1441c594abSRalf Baechle #include <asm/cpu.h>
1541c594abSRalf Baechle #include <asm/processor.h>
1660063497SArun Sharma #include <linux/atomic.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
maxvpes(char * str)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
maxtcs(char * str)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
mips_mt_regdump(unsigned long mvpctl)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
6241c594abSRalf Baechle local_irq_save(flags);
6341c594abSRalf Baechle vpflags = dvpe();
6441c594abSRalf Baechle printk("=== MIPS MT State Dump ===\n");
6541c594abSRalf Baechle printk("-- Global State --\n");
6641c594abSRalf Baechle printk(" MVPControl Passed: %08lx\n", mvpctl);
6741c594abSRalf Baechle printk(" MVPControl Read: %08lx\n", vpflags);
6841c594abSRalf Baechle printk(" MVPConf0 : %08lx\n", (mvpconf0 = read_c0_mvpconf0()));
6941c594abSRalf Baechle nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
7041c594abSRalf Baechle ntc = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
7141c594abSRalf Baechle printk("-- per-VPE State --\n");
7241c594abSRalf Baechle for (i = 0; i < nvpe; i++) {
7341c594abSRalf Baechle for (tc = 0; tc < ntc; tc++) {
7441c594abSRalf Baechle settc(tc);
7541c594abSRalf Baechle if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
7641c594abSRalf Baechle printk(" VPE %d\n", i);
77d223a861SRalf Baechle printk(" VPEControl : %08lx\n",
78d223a861SRalf Baechle read_vpe_c0_vpecontrol());
79d223a861SRalf Baechle printk(" VPEConf0 : %08lx\n",
80d223a861SRalf Baechle read_vpe_c0_vpeconf0());
8141c594abSRalf Baechle printk(" VPE%d.Status : %08lx\n",
8241c594abSRalf Baechle i, read_vpe_c0_status());
83b012cffeSRalf Baechle printk(" VPE%d.EPC : %08lx %pS\n",
84b012cffeSRalf Baechle i, read_vpe_c0_epc(),
85b012cffeSRalf Baechle (void *) read_vpe_c0_epc());
86d223a861SRalf Baechle printk(" VPE%d.Cause : %08lx\n",
87d223a861SRalf Baechle i, read_vpe_c0_cause());
8841c594abSRalf Baechle printk(" VPE%d.Config7 : %08lx\n",
8941c594abSRalf Baechle i, read_vpe_c0_config7());
9041c594abSRalf Baechle break; /* Next VPE */
9141c594abSRalf Baechle }
9241c594abSRalf Baechle }
9341c594abSRalf Baechle }
9441c594abSRalf Baechle printk("-- per-TC State --\n");
9541c594abSRalf Baechle for (tc = 0; tc < ntc; tc++) {
9641c594abSRalf Baechle settc(tc);
9741c594abSRalf Baechle if (read_tc_c0_tcbind() == read_c0_tcbind()) {
9841c594abSRalf Baechle /* Are we dumping ourself? */
9941c594abSRalf Baechle haltval = 0; /* Then we're not halted, and mustn't be */
10041c594abSRalf Baechle tcstatval = flags; /* And pre-dump TCStatus is flags */
10141c594abSRalf Baechle printk(" TC %d (current TC with VPE EPC above)\n", tc);
10241c594abSRalf Baechle } else {
10341c594abSRalf Baechle haltval = read_tc_c0_tchalt();
10441c594abSRalf Baechle write_tc_c0_tchalt(1);
10541c594abSRalf Baechle tcstatval = read_tc_c0_tcstatus();
10641c594abSRalf Baechle printk(" TC %d\n", tc);
10741c594abSRalf Baechle }
10841c594abSRalf Baechle printk(" TCStatus : %08lx\n", tcstatval);
10941c594abSRalf Baechle printk(" TCBind : %08lx\n", read_tc_c0_tcbind());
110b012cffeSRalf Baechle printk(" TCRestart : %08lx %pS\n",
111b012cffeSRalf Baechle read_tc_c0_tcrestart(), (void *) read_tc_c0_tcrestart());
11241c594abSRalf Baechle printk(" TCHalt : %08lx\n", haltval);
11341c594abSRalf Baechle printk(" TCContext : %08lx\n", read_tc_c0_tccontext());
11441c594abSRalf Baechle if (!haltval)
11541c594abSRalf Baechle write_tc_c0_tchalt(0);
11641c594abSRalf Baechle }
11741c594abSRalf Baechle printk("===========================\n");
11841c594abSRalf Baechle evpe(vpflags);
11941c594abSRalf Baechle local_irq_restore(flags);
12041c594abSRalf Baechle }
12141c594abSRalf Baechle
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
rpsctl_set(char * str)12741c594abSRalf Baechle static int __init rpsctl_set(char *str)
12841c594abSRalf Baechle {
12941c594abSRalf Baechle get_option(&str, &mt_opt_rpsctl);
13041c594abSRalf Baechle return 1;
13141c594abSRalf Baechle }
13241c594abSRalf Baechle __setup("rpsctl=", rpsctl_set);
13341c594abSRalf Baechle
nblsu_set(char * str)13441c594abSRalf Baechle static int __init nblsu_set(char *str)
13541c594abSRalf Baechle {
13641c594abSRalf Baechle get_option(&str, &mt_opt_nblsu);
13741c594abSRalf Baechle return 1;
13841c594abSRalf Baechle }
13941c594abSRalf Baechle __setup("nblsu=", nblsu_set);
14041c594abSRalf Baechle
config7_set(char * str)14141c594abSRalf Baechle static int __init config7_set(char *str)
14241c594abSRalf Baechle {
14341c594abSRalf Baechle get_option(&str, &mt_opt_config7);
14441c594abSRalf Baechle mt_opt_forceconfig7 = 1;
14541c594abSRalf Baechle return 1;
14641c594abSRalf Baechle }
14741c594abSRalf Baechle __setup("config7=", config7_set);
14841c594abSRalf Baechle
149982f6ffeSRalf Baechle static unsigned int itc_base;
15041c594abSRalf Baechle
set_itc_base(char * str)15141c594abSRalf Baechle static int __init set_itc_base(char *str)
15241c594abSRalf Baechle {
15341c594abSRalf Baechle get_option(&str, &itc_base);
15441c594abSRalf Baechle return 1;
15541c594abSRalf Baechle }
15641c594abSRalf Baechle
15741c594abSRalf Baechle __setup("itcbase=", set_itc_base);
15841c594abSRalf Baechle
mips_mt_set_cpuoptions(void)15941c594abSRalf Baechle void mips_mt_set_cpuoptions(void)
16041c594abSRalf Baechle {
16141c594abSRalf Baechle unsigned int oconfig7 = read_c0_config7();
16241c594abSRalf Baechle unsigned int nconfig7 = oconfig7;
16341c594abSRalf Baechle
16441c594abSRalf Baechle if (mt_opt_rpsctl >= 0) {
16541c594abSRalf Baechle printk("34K return prediction stack override set to %d.\n",
16641c594abSRalf Baechle mt_opt_rpsctl);
16741c594abSRalf Baechle if (mt_opt_rpsctl)
16841c594abSRalf Baechle nconfig7 |= (1 << 2);
16941c594abSRalf Baechle else
17041c594abSRalf Baechle nconfig7 &= ~(1 << 2);
17141c594abSRalf Baechle }
17241c594abSRalf Baechle if (mt_opt_nblsu >= 0) {
17341c594abSRalf Baechle printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu);
17441c594abSRalf Baechle if (mt_opt_nblsu)
17541c594abSRalf Baechle nconfig7 |= (1 << 5);
17641c594abSRalf Baechle else
17741c594abSRalf Baechle nconfig7 &= ~(1 << 5);
17841c594abSRalf Baechle }
17941c594abSRalf Baechle if (mt_opt_forceconfig7) {
18041c594abSRalf Baechle printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7);
18141c594abSRalf Baechle nconfig7 = mt_opt_config7;
18241c594abSRalf Baechle }
18341c594abSRalf Baechle if (oconfig7 != nconfig7) {
18441c594abSRalf Baechle __asm__ __volatile("sync");
18541c594abSRalf Baechle write_c0_config7(nconfig7);
18641c594abSRalf Baechle ehb();
18741c594abSRalf Baechle printk("Config7: 0x%08x\n", read_c0_config7());
18841c594abSRalf Baechle }
18941c594abSRalf Baechle
19041c594abSRalf Baechle if (itc_base != 0) {
19141c594abSRalf Baechle /*
19241c594abSRalf Baechle * Configure ITC mapping. This code is very
19341c594abSRalf Baechle * specific to the 34K core family, which uses
19441c594abSRalf Baechle * a special mode bit ("ITC") in the ErrCtl
19541c594abSRalf Baechle * register to enable access to ITC control
19641c594abSRalf Baechle * registers via cache "tag" operations.
19741c594abSRalf Baechle */
19841c594abSRalf Baechle unsigned long ectlval;
19941c594abSRalf Baechle unsigned long itcblkgrn;
20041c594abSRalf Baechle
20141c594abSRalf Baechle /* ErrCtl register is known as "ecc" to Linux */
20241c594abSRalf Baechle ectlval = read_c0_ecc();
20341c594abSRalf Baechle write_c0_ecc(ectlval | (0x1 << 26));
20441c594abSRalf Baechle ehb();
20541c594abSRalf Baechle #define INDEX_0 (0x80000000)
20641c594abSRalf Baechle #define INDEX_8 (0x80000008)
20741c594abSRalf Baechle /* Read "cache tag" for Dcache pseudo-index 8 */
20841c594abSRalf Baechle cache_op(Index_Load_Tag_D, INDEX_8);
20941c594abSRalf Baechle ehb();
21041c594abSRalf Baechle itcblkgrn = read_c0_dtaglo();
21141c594abSRalf Baechle itcblkgrn &= 0xfffe0000;
21241c594abSRalf Baechle /* Set for 128 byte pitch of ITC cells */
21341c594abSRalf Baechle itcblkgrn |= 0x00000c00;
21441c594abSRalf Baechle /* Stage in Tag register */
21541c594abSRalf Baechle write_c0_dtaglo(itcblkgrn);
21641c594abSRalf Baechle ehb();
21741c594abSRalf Baechle /* Write out to ITU with CACHE op */
21841c594abSRalf Baechle cache_op(Index_Store_Tag_D, INDEX_8);
21941c594abSRalf Baechle /* Now set base address, and turn ITC on with 0x1 bit */
22041c594abSRalf Baechle write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 );
22141c594abSRalf Baechle ehb();
22241c594abSRalf Baechle /* Write out to ITU with CACHE op */
22341c594abSRalf Baechle cache_op(Index_Store_Tag_D, INDEX_0);
22441c594abSRalf Baechle write_c0_ecc(ectlval);
22541c594abSRalf Baechle ehb();
22641c594abSRalf Baechle printk("Mapped %ld ITC cells starting at 0x%08x\n",
22741c594abSRalf Baechle ((itcblkgrn & 0x7fe00000) >> 20), itc_base);
22841c594abSRalf Baechle }
22941c594abSRalf Baechle }
23041c594abSRalf Baechle
23127a3bbafSRalf Baechle struct class *mt_class;
23227a3bbafSRalf Baechle
mips_mt_init(void)23315d2ce71SLiam R. Howlett static int __init mips_mt_init(void)
23427a3bbafSRalf Baechle {
23527a3bbafSRalf Baechle struct class *mtc;
23627a3bbafSRalf Baechle
237*1aaba11dSGreg Kroah-Hartman mtc = class_create("mt");
23827a3bbafSRalf Baechle if (IS_ERR(mtc))
23927a3bbafSRalf Baechle return PTR_ERR(mtc);
24027a3bbafSRalf Baechle
24127a3bbafSRalf Baechle mt_class = mtc;
24227a3bbafSRalf Baechle
24327a3bbafSRalf Baechle return 0;
24427a3bbafSRalf Baechle }
24527a3bbafSRalf Baechle
24615d2ce71SLiam R. Howlett subsys_initcall(mips_mt_init);
247