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> 1541c594abSRalf Baechle #include <asm/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/smp.h> 2041c594abSRalf Baechle #include <asm/mipsmtregs.h> 2141c594abSRalf Baechle #include <asm/r4kcache.h> 2241c594abSRalf Baechle #include <asm/cacheflush.h> 2341c594abSRalf Baechle 24*07cc0c9eSRalf Baechle int vpelimit; 25*07cc0c9eSRalf Baechle 26*07cc0c9eSRalf Baechle static int __init maxvpes(char *str) 27*07cc0c9eSRalf Baechle { 28*07cc0c9eSRalf Baechle get_option(&str, &vpelimit); 29*07cc0c9eSRalf Baechle 30*07cc0c9eSRalf Baechle return 1; 31*07cc0c9eSRalf Baechle } 32*07cc0c9eSRalf Baechle 33*07cc0c9eSRalf Baechle __setup("maxvpes=", maxvpes); 34*07cc0c9eSRalf Baechle 35*07cc0c9eSRalf Baechle int tclimit; 36*07cc0c9eSRalf Baechle 37*07cc0c9eSRalf Baechle static int __init maxtcs(char *str) 38*07cc0c9eSRalf Baechle { 39*07cc0c9eSRalf Baechle get_option(&str, &tclimit); 40*07cc0c9eSRalf Baechle 41*07cc0c9eSRalf Baechle return 1; 42*07cc0c9eSRalf Baechle } 43*07cc0c9eSRalf Baechle 44*07cc0c9eSRalf Baechle __setup("maxtcs=", maxtcs); 45*07cc0c9eSRalf Baechle 4641c594abSRalf Baechle /* 4741c594abSRalf Baechle * Dump new MIPS MT state for the core. Does not leave TCs halted. 4841c594abSRalf Baechle * Takes an argument which taken to be a pre-call MVPControl value. 4941c594abSRalf Baechle */ 5041c594abSRalf Baechle 5141c594abSRalf Baechle void mips_mt_regdump(unsigned long mvpctl) 5241c594abSRalf Baechle { 5341c594abSRalf Baechle unsigned long flags; 5441c594abSRalf Baechle unsigned long vpflags; 5541c594abSRalf Baechle unsigned long mvpconf0; 5641c594abSRalf Baechle int nvpe; 5741c594abSRalf Baechle int ntc; 5841c594abSRalf Baechle int i; 5941c594abSRalf Baechle int tc; 6041c594abSRalf Baechle unsigned long haltval; 6141c594abSRalf Baechle unsigned long tcstatval; 6241c594abSRalf Baechle #ifdef CONFIG_MIPS_MT_SMTC 6341c594abSRalf Baechle void smtc_soft_dump(void); 6441c594abSRalf Baechle #endif /* CONFIG_MIPT_MT_SMTC */ 6541c594abSRalf Baechle 6641c594abSRalf Baechle local_irq_save(flags); 6741c594abSRalf Baechle vpflags = dvpe(); 6841c594abSRalf Baechle printk("=== MIPS MT State Dump ===\n"); 6941c594abSRalf Baechle printk("-- Global State --\n"); 7041c594abSRalf Baechle printk(" MVPControl Passed: %08lx\n", mvpctl); 7141c594abSRalf Baechle printk(" MVPControl Read: %08lx\n", vpflags); 7241c594abSRalf Baechle printk(" MVPConf0 : %08lx\n", (mvpconf0 = read_c0_mvpconf0())); 7341c594abSRalf Baechle nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1; 7441c594abSRalf Baechle ntc = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1; 7541c594abSRalf Baechle printk("-- per-VPE State --\n"); 7641c594abSRalf Baechle for (i = 0; i < nvpe; i++) { 7741c594abSRalf Baechle for (tc = 0; tc < ntc; tc++) { 7841c594abSRalf Baechle settc(tc); 7941c594abSRalf Baechle if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) { 8041c594abSRalf Baechle printk(" VPE %d\n", i); 81d223a861SRalf Baechle printk(" VPEControl : %08lx\n", 82d223a861SRalf Baechle read_vpe_c0_vpecontrol()); 83d223a861SRalf Baechle printk(" VPEConf0 : %08lx\n", 84d223a861SRalf Baechle read_vpe_c0_vpeconf0()); 8541c594abSRalf Baechle printk(" VPE%d.Status : %08lx\n", 8641c594abSRalf Baechle i, read_vpe_c0_status()); 87d223a861SRalf Baechle printk(" VPE%d.EPC : %08lx\n", 88d223a861SRalf Baechle i, 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()); 11341c594abSRalf Baechle printk(" TCRestart : %08lx\n", read_tc_c0_tcrestart()); 11441c594abSRalf Baechle printk(" TCHalt : %08lx\n", haltval); 11541c594abSRalf Baechle printk(" TCContext : %08lx\n", read_tc_c0_tccontext()); 11641c594abSRalf Baechle if (!haltval) 11741c594abSRalf Baechle write_tc_c0_tchalt(0); 11841c594abSRalf Baechle } 11941c594abSRalf Baechle #ifdef CONFIG_MIPS_MT_SMTC 12041c594abSRalf Baechle smtc_soft_dump(); 12141c594abSRalf Baechle #endif /* CONFIG_MIPT_MT_SMTC */ 12241c594abSRalf Baechle printk("===========================\n"); 12341c594abSRalf Baechle evpe(vpflags); 12441c594abSRalf Baechle local_irq_restore(flags); 12541c594abSRalf Baechle } 12641c594abSRalf Baechle 12741c594abSRalf Baechle static int mt_opt_norps = 0; 12841c594abSRalf Baechle static int mt_opt_rpsctl = -1; 12941c594abSRalf Baechle static int mt_opt_nblsu = -1; 13041c594abSRalf Baechle static int mt_opt_forceconfig7 = 0; 13141c594abSRalf Baechle static int mt_opt_config7 = -1; 13241c594abSRalf Baechle 13341c594abSRalf Baechle static int __init rps_disable(char *s) 13441c594abSRalf Baechle { 13541c594abSRalf Baechle mt_opt_norps = 1; 13641c594abSRalf Baechle return 1; 13741c594abSRalf Baechle } 13841c594abSRalf Baechle __setup("norps", rps_disable); 13941c594abSRalf Baechle 14041c594abSRalf Baechle static int __init rpsctl_set(char *str) 14141c594abSRalf Baechle { 14241c594abSRalf Baechle get_option(&str, &mt_opt_rpsctl); 14341c594abSRalf Baechle return 1; 14441c594abSRalf Baechle } 14541c594abSRalf Baechle __setup("rpsctl=", rpsctl_set); 14641c594abSRalf Baechle 14741c594abSRalf Baechle static int __init nblsu_set(char *str) 14841c594abSRalf Baechle { 14941c594abSRalf Baechle get_option(&str, &mt_opt_nblsu); 15041c594abSRalf Baechle return 1; 15141c594abSRalf Baechle } 15241c594abSRalf Baechle __setup("nblsu=", nblsu_set); 15341c594abSRalf Baechle 15441c594abSRalf Baechle static int __init config7_set(char *str) 15541c594abSRalf Baechle { 15641c594abSRalf Baechle get_option(&str, &mt_opt_config7); 15741c594abSRalf Baechle mt_opt_forceconfig7 = 1; 15841c594abSRalf Baechle return 1; 15941c594abSRalf Baechle } 16041c594abSRalf Baechle __setup("config7=", config7_set); 16141c594abSRalf Baechle 16241c594abSRalf Baechle /* Experimental cache flush control parameters that should go away some day */ 16341c594abSRalf Baechle int mt_protiflush = 0; 16441c594abSRalf Baechle int mt_protdflush = 0; 16541c594abSRalf Baechle int mt_n_iflushes = 1; 16641c594abSRalf Baechle int mt_n_dflushes = 1; 16741c594abSRalf Baechle 16841c594abSRalf Baechle static int __init set_protiflush(char *s) 16941c594abSRalf Baechle { 17041c594abSRalf Baechle mt_protiflush = 1; 17141c594abSRalf Baechle return 1; 17241c594abSRalf Baechle } 17341c594abSRalf Baechle __setup("protiflush", set_protiflush); 17441c594abSRalf Baechle 17541c594abSRalf Baechle static int __init set_protdflush(char *s) 17641c594abSRalf Baechle { 17741c594abSRalf Baechle mt_protdflush = 1; 17841c594abSRalf Baechle return 1; 17941c594abSRalf Baechle } 18041c594abSRalf Baechle __setup("protdflush", set_protdflush); 18141c594abSRalf Baechle 18241c594abSRalf Baechle static int __init niflush(char *s) 18341c594abSRalf Baechle { 18441c594abSRalf Baechle get_option(&s, &mt_n_iflushes); 18541c594abSRalf Baechle return 1; 18641c594abSRalf Baechle } 18741c594abSRalf Baechle __setup("niflush=", niflush); 18841c594abSRalf Baechle 18941c594abSRalf Baechle static int __init ndflush(char *s) 19041c594abSRalf Baechle { 19141c594abSRalf Baechle get_option(&s, &mt_n_dflushes); 19241c594abSRalf Baechle return 1; 19341c594abSRalf Baechle } 19441c594abSRalf Baechle __setup("ndflush=", ndflush); 19541c594abSRalf Baechle 19641c594abSRalf Baechle static unsigned int itc_base = 0; 19741c594abSRalf Baechle 19841c594abSRalf Baechle static int __init set_itc_base(char *str) 19941c594abSRalf Baechle { 20041c594abSRalf Baechle get_option(&str, &itc_base); 20141c594abSRalf Baechle return 1; 20241c594abSRalf Baechle } 20341c594abSRalf Baechle 20441c594abSRalf Baechle __setup("itcbase=", set_itc_base); 20541c594abSRalf Baechle 20641c594abSRalf Baechle void mips_mt_set_cpuoptions(void) 20741c594abSRalf Baechle { 20841c594abSRalf Baechle unsigned int oconfig7 = read_c0_config7(); 20941c594abSRalf Baechle unsigned int nconfig7 = oconfig7; 21041c594abSRalf Baechle 21141c594abSRalf Baechle if (mt_opt_norps) { 21241c594abSRalf Baechle printk("\"norps\" option deprectated: use \"rpsctl=\"\n"); 21341c594abSRalf Baechle } 21441c594abSRalf Baechle if (mt_opt_rpsctl >= 0) { 21541c594abSRalf Baechle printk("34K return prediction stack override set to %d.\n", 21641c594abSRalf Baechle mt_opt_rpsctl); 21741c594abSRalf Baechle if (mt_opt_rpsctl) 21841c594abSRalf Baechle nconfig7 |= (1 << 2); 21941c594abSRalf Baechle else 22041c594abSRalf Baechle nconfig7 &= ~(1 << 2); 22141c594abSRalf Baechle } 22241c594abSRalf Baechle if (mt_opt_nblsu >= 0) { 22341c594abSRalf Baechle printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu); 22441c594abSRalf Baechle if (mt_opt_nblsu) 22541c594abSRalf Baechle nconfig7 |= (1 << 5); 22641c594abSRalf Baechle else 22741c594abSRalf Baechle nconfig7 &= ~(1 << 5); 22841c594abSRalf Baechle } 22941c594abSRalf Baechle if (mt_opt_forceconfig7) { 23041c594abSRalf Baechle printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7); 23141c594abSRalf Baechle nconfig7 = mt_opt_config7; 23241c594abSRalf Baechle } 23341c594abSRalf Baechle if (oconfig7 != nconfig7) { 23441c594abSRalf Baechle __asm__ __volatile("sync"); 23541c594abSRalf Baechle write_c0_config7(nconfig7); 23641c594abSRalf Baechle ehb (); 23741c594abSRalf Baechle printk("Config7: 0x%08x\n", read_c0_config7()); 23841c594abSRalf Baechle } 23941c594abSRalf Baechle 24041c594abSRalf Baechle /* Report Cache management debug options */ 24141c594abSRalf Baechle if (mt_protiflush) 24241c594abSRalf Baechle printk("I-cache flushes single-threaded\n"); 24341c594abSRalf Baechle if (mt_protdflush) 24441c594abSRalf Baechle printk("D-cache flushes single-threaded\n"); 24541c594abSRalf Baechle if (mt_n_iflushes != 1) 24641c594abSRalf Baechle printk("I-Cache Flushes Repeated %d times\n", mt_n_iflushes); 24741c594abSRalf Baechle if (mt_n_dflushes != 1) 24841c594abSRalf Baechle printk("D-Cache Flushes Repeated %d times\n", mt_n_dflushes); 24941c594abSRalf Baechle 25041c594abSRalf Baechle if (itc_base != 0) { 25141c594abSRalf Baechle /* 25241c594abSRalf Baechle * Configure ITC mapping. This code is very 25341c594abSRalf Baechle * specific to the 34K core family, which uses 25441c594abSRalf Baechle * a special mode bit ("ITC") in the ErrCtl 25541c594abSRalf Baechle * register to enable access to ITC control 25641c594abSRalf Baechle * registers via cache "tag" operations. 25741c594abSRalf Baechle */ 25841c594abSRalf Baechle unsigned long ectlval; 25941c594abSRalf Baechle unsigned long itcblkgrn; 26041c594abSRalf Baechle 26141c594abSRalf Baechle /* ErrCtl register is known as "ecc" to Linux */ 26241c594abSRalf Baechle ectlval = read_c0_ecc(); 26341c594abSRalf Baechle write_c0_ecc(ectlval | (0x1 << 26)); 26441c594abSRalf Baechle ehb(); 26541c594abSRalf Baechle #define INDEX_0 (0x80000000) 26641c594abSRalf Baechle #define INDEX_8 (0x80000008) 26741c594abSRalf Baechle /* Read "cache tag" for Dcache pseudo-index 8 */ 26841c594abSRalf Baechle cache_op(Index_Load_Tag_D, INDEX_8); 26941c594abSRalf Baechle ehb(); 27041c594abSRalf Baechle itcblkgrn = read_c0_dtaglo(); 27141c594abSRalf Baechle itcblkgrn &= 0xfffe0000; 27241c594abSRalf Baechle /* Set for 128 byte pitch of ITC cells */ 27341c594abSRalf Baechle itcblkgrn |= 0x00000c00; 27441c594abSRalf Baechle /* Stage in Tag register */ 27541c594abSRalf Baechle write_c0_dtaglo(itcblkgrn); 27641c594abSRalf Baechle ehb(); 27741c594abSRalf Baechle /* Write out to ITU with CACHE op */ 27841c594abSRalf Baechle cache_op(Index_Store_Tag_D, INDEX_8); 27941c594abSRalf Baechle /* Now set base address, and turn ITC on with 0x1 bit */ 28041c594abSRalf Baechle write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 ); 28141c594abSRalf Baechle ehb(); 28241c594abSRalf Baechle /* Write out to ITU with CACHE op */ 28341c594abSRalf Baechle cache_op(Index_Store_Tag_D, INDEX_0); 28441c594abSRalf Baechle write_c0_ecc(ectlval); 28541c594abSRalf Baechle ehb(); 28641c594abSRalf Baechle printk("Mapped %ld ITC cells starting at 0x%08x\n", 28741c594abSRalf Baechle ((itcblkgrn & 0x7fe00000) >> 20), itc_base); 28841c594abSRalf Baechle } 28941c594abSRalf Baechle } 29041c594abSRalf Baechle 29141c594abSRalf Baechle /* 29241c594abSRalf Baechle * Function to protect cache flushes from concurrent execution 29341c594abSRalf Baechle * depends on MP software model chosen. 29441c594abSRalf Baechle */ 29541c594abSRalf Baechle 29641c594abSRalf Baechle void mt_cflush_lockdown(void) 29741c594abSRalf Baechle { 29841c594abSRalf Baechle #ifdef CONFIG_MIPS_MT_SMTC 29941c594abSRalf Baechle void smtc_cflush_lockdown(void); 30041c594abSRalf Baechle 30141c594abSRalf Baechle smtc_cflush_lockdown(); 30241c594abSRalf Baechle #endif /* CONFIG_MIPS_MT_SMTC */ 30341c594abSRalf Baechle /* FILL IN VSMP and AP/SP VERSIONS HERE */ 30441c594abSRalf Baechle } 30541c594abSRalf Baechle 30641c594abSRalf Baechle void mt_cflush_release(void) 30741c594abSRalf Baechle { 30841c594abSRalf Baechle #ifdef CONFIG_MIPS_MT_SMTC 30941c594abSRalf Baechle void smtc_cflush_release(void); 31041c594abSRalf Baechle 31141c594abSRalf Baechle smtc_cflush_release(); 31241c594abSRalf Baechle #endif /* CONFIG_MIPS_MT_SMTC */ 31341c594abSRalf Baechle /* FILL IN VSMP and AP/SP VERSIONS HERE */ 31441c594abSRalf Baechle } 31527a3bbafSRalf Baechle 31627a3bbafSRalf Baechle struct class *mt_class; 31727a3bbafSRalf Baechle 31827a3bbafSRalf Baechle static int __init mt_init(void) 31927a3bbafSRalf Baechle { 32027a3bbafSRalf Baechle struct class *mtc; 32127a3bbafSRalf Baechle 32227a3bbafSRalf Baechle mtc = class_create(THIS_MODULE, "mt"); 32327a3bbafSRalf Baechle if (IS_ERR(mtc)) 32427a3bbafSRalf Baechle return PTR_ERR(mtc); 32527a3bbafSRalf Baechle 32627a3bbafSRalf Baechle mt_class = mtc; 32727a3bbafSRalf Baechle 32827a3bbafSRalf Baechle return 0; 32927a3bbafSRalf Baechle } 33027a3bbafSRalf Baechle 33127a3bbafSRalf Baechle subsys_initcall(mt_init); 332