mips-mt.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * General MIPS MT support routines, usable in AP/SP, SMVP, or SMTC kernels
  3. * Copyright (C) 2005 Mips Technologies, Inc
  4. */
  5. #include <linux/device.h>
  6. #include <linux/kallsyms.h>
  7. #include <linux/kernel.h>
  8. #include <linux/sched.h>
  9. #include <linux/module.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/security.h>
  12. #include <asm/cpu.h>
  13. #include <asm/processor.h>
  14. #include <asm/atomic.h>
  15. #include <asm/system.h>
  16. #include <asm/hardirq.h>
  17. #include <asm/mmu_context.h>
  18. #include <asm/smp.h>
  19. #include <asm/mipsmtregs.h>
  20. #include <asm/r4kcache.h>
  21. #include <asm/cacheflush.h>
  22. int vpelimit;
  23. static int __init maxvpes(char *str)
  24. {
  25. get_option(&str, &vpelimit);
  26. return 1;
  27. }
  28. __setup("maxvpes=", maxvpes);
  29. int tclimit;
  30. static int __init maxtcs(char *str)
  31. {
  32. get_option(&str, &tclimit);
  33. return 1;
  34. }
  35. __setup("maxtcs=", maxtcs);
  36. /*
  37. * Dump new MIPS MT state for the core. Does not leave TCs halted.
  38. * Takes an argument which taken to be a pre-call MVPControl value.
  39. */
  40. void mips_mt_regdump(unsigned long mvpctl)
  41. {
  42. unsigned long flags;
  43. unsigned long vpflags;
  44. unsigned long mvpconf0;
  45. int nvpe;
  46. int ntc;
  47. int i;
  48. int tc;
  49. unsigned long haltval;
  50. unsigned long tcstatval;
  51. #ifdef CONFIG_MIPS_MT_SMTC
  52. void smtc_soft_dump(void);
  53. #endif /* CONFIG_MIPT_MT_SMTC */
  54. local_irq_save(flags);
  55. vpflags = dvpe();
  56. printk("=== MIPS MT State Dump ===\n");
  57. printk("-- Global State --\n");
  58. printk(" MVPControl Passed: %08lx\n", mvpctl);
  59. printk(" MVPControl Read: %08lx\n", vpflags);
  60. printk(" MVPConf0 : %08lx\n", (mvpconf0 = read_c0_mvpconf0()));
  61. nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
  62. ntc = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
  63. printk("-- per-VPE State --\n");
  64. for (i = 0; i < nvpe; i++) {
  65. for (tc = 0; tc < ntc; tc++) {
  66. settc(tc);
  67. if ((read_tc_c0_tcbind() & TCBIND_CURVPE) == i) {
  68. printk(" VPE %d\n", i);
  69. printk(" VPEControl : %08lx\n",
  70. read_vpe_c0_vpecontrol());
  71. printk(" VPEConf0 : %08lx\n",
  72. read_vpe_c0_vpeconf0());
  73. printk(" VPE%d.Status : %08lx\n",
  74. i, read_vpe_c0_status());
  75. printk(" VPE%d.EPC : %08lx ",
  76. i, read_vpe_c0_epc());
  77. print_symbol("%s\n", read_vpe_c0_epc());
  78. printk(" VPE%d.Cause : %08lx\n",
  79. i, read_vpe_c0_cause());
  80. printk(" VPE%d.Config7 : %08lx\n",
  81. i, read_vpe_c0_config7());
  82. break; /* Next VPE */
  83. }
  84. }
  85. }
  86. printk("-- per-TC State --\n");
  87. for (tc = 0; tc < ntc; tc++) {
  88. settc(tc);
  89. if (read_tc_c0_tcbind() == read_c0_tcbind()) {
  90. /* Are we dumping ourself? */
  91. haltval = 0; /* Then we're not halted, and mustn't be */
  92. tcstatval = flags; /* And pre-dump TCStatus is flags */
  93. printk(" TC %d (current TC with VPE EPC above)\n", tc);
  94. } else {
  95. haltval = read_tc_c0_tchalt();
  96. write_tc_c0_tchalt(1);
  97. tcstatval = read_tc_c0_tcstatus();
  98. printk(" TC %d\n", tc);
  99. }
  100. printk(" TCStatus : %08lx\n", tcstatval);
  101. printk(" TCBind : %08lx\n", read_tc_c0_tcbind());
  102. printk(" TCRestart : %08lx ", read_tc_c0_tcrestart());
  103. print_symbol("%s\n", read_tc_c0_tcrestart());
  104. printk(" TCHalt : %08lx\n", haltval);
  105. printk(" TCContext : %08lx\n", read_tc_c0_tccontext());
  106. if (!haltval)
  107. write_tc_c0_tchalt(0);
  108. }
  109. #ifdef CONFIG_MIPS_MT_SMTC
  110. smtc_soft_dump();
  111. #endif /* CONFIG_MIPT_MT_SMTC */
  112. printk("===========================\n");
  113. evpe(vpflags);
  114. local_irq_restore(flags);
  115. }
  116. static int mt_opt_norps = 0;
  117. static int mt_opt_rpsctl = -1;
  118. static int mt_opt_nblsu = -1;
  119. static int mt_opt_forceconfig7 = 0;
  120. static int mt_opt_config7 = -1;
  121. static int __init rps_disable(char *s)
  122. {
  123. mt_opt_norps = 1;
  124. return 1;
  125. }
  126. __setup("norps", rps_disable);
  127. static int __init rpsctl_set(char *str)
  128. {
  129. get_option(&str, &mt_opt_rpsctl);
  130. return 1;
  131. }
  132. __setup("rpsctl=", rpsctl_set);
  133. static int __init nblsu_set(char *str)
  134. {
  135. get_option(&str, &mt_opt_nblsu);
  136. return 1;
  137. }
  138. __setup("nblsu=", nblsu_set);
  139. static int __init config7_set(char *str)
  140. {
  141. get_option(&str, &mt_opt_config7);
  142. mt_opt_forceconfig7 = 1;
  143. return 1;
  144. }
  145. __setup("config7=", config7_set);
  146. /* Experimental cache flush control parameters that should go away some day */
  147. int mt_protiflush = 0;
  148. int mt_protdflush = 0;
  149. int mt_n_iflushes = 1;
  150. int mt_n_dflushes = 1;
  151. static int __init set_protiflush(char *s)
  152. {
  153. mt_protiflush = 1;
  154. return 1;
  155. }
  156. __setup("protiflush", set_protiflush);
  157. static int __init set_protdflush(char *s)
  158. {
  159. mt_protdflush = 1;
  160. return 1;
  161. }
  162. __setup("protdflush", set_protdflush);
  163. static int __init niflush(char *s)
  164. {
  165. get_option(&s, &mt_n_iflushes);
  166. return 1;
  167. }
  168. __setup("niflush=", niflush);
  169. static int __init ndflush(char *s)
  170. {
  171. get_option(&s, &mt_n_dflushes);
  172. return 1;
  173. }
  174. __setup("ndflush=", ndflush);
  175. static unsigned int itc_base = 0;
  176. static int __init set_itc_base(char *str)
  177. {
  178. get_option(&str, &itc_base);
  179. return 1;
  180. }
  181. __setup("itcbase=", set_itc_base);
  182. void mips_mt_set_cpuoptions(void)
  183. {
  184. unsigned int oconfig7 = read_c0_config7();
  185. unsigned int nconfig7 = oconfig7;
  186. if (mt_opt_norps) {
  187. printk("\"norps\" option deprectated: use \"rpsctl=\"\n");
  188. }
  189. if (mt_opt_rpsctl >= 0) {
  190. printk("34K return prediction stack override set to %d.\n",
  191. mt_opt_rpsctl);
  192. if (mt_opt_rpsctl)
  193. nconfig7 |= (1 << 2);
  194. else
  195. nconfig7 &= ~(1 << 2);
  196. }
  197. if (mt_opt_nblsu >= 0) {
  198. printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu);
  199. if (mt_opt_nblsu)
  200. nconfig7 |= (1 << 5);
  201. else
  202. nconfig7 &= ~(1 << 5);
  203. }
  204. if (mt_opt_forceconfig7) {
  205. printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7);
  206. nconfig7 = mt_opt_config7;
  207. }
  208. if (oconfig7 != nconfig7) {
  209. __asm__ __volatile("sync");
  210. write_c0_config7(nconfig7);
  211. ehb();
  212. printk("Config7: 0x%08x\n", read_c0_config7());
  213. }
  214. /* Report Cache management debug options */
  215. if (mt_protiflush)
  216. printk("I-cache flushes single-threaded\n");
  217. if (mt_protdflush)
  218. printk("D-cache flushes single-threaded\n");
  219. if (mt_n_iflushes != 1)
  220. printk("I-Cache Flushes Repeated %d times\n", mt_n_iflushes);
  221. if (mt_n_dflushes != 1)
  222. printk("D-Cache Flushes Repeated %d times\n", mt_n_dflushes);
  223. if (itc_base != 0) {
  224. /*
  225. * Configure ITC mapping. This code is very
  226. * specific to the 34K core family, which uses
  227. * a special mode bit ("ITC") in the ErrCtl
  228. * register to enable access to ITC control
  229. * registers via cache "tag" operations.
  230. */
  231. unsigned long ectlval;
  232. unsigned long itcblkgrn;
  233. /* ErrCtl register is known as "ecc" to Linux */
  234. ectlval = read_c0_ecc();
  235. write_c0_ecc(ectlval | (0x1 << 26));
  236. ehb();
  237. #define INDEX_0 (0x80000000)
  238. #define INDEX_8 (0x80000008)
  239. /* Read "cache tag" for Dcache pseudo-index 8 */
  240. cache_op(Index_Load_Tag_D, INDEX_8);
  241. ehb();
  242. itcblkgrn = read_c0_dtaglo();
  243. itcblkgrn &= 0xfffe0000;
  244. /* Set for 128 byte pitch of ITC cells */
  245. itcblkgrn |= 0x00000c00;
  246. /* Stage in Tag register */
  247. write_c0_dtaglo(itcblkgrn);
  248. ehb();
  249. /* Write out to ITU with CACHE op */
  250. cache_op(Index_Store_Tag_D, INDEX_8);
  251. /* Now set base address, and turn ITC on with 0x1 bit */
  252. write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 );
  253. ehb();
  254. /* Write out to ITU with CACHE op */
  255. cache_op(Index_Store_Tag_D, INDEX_0);
  256. write_c0_ecc(ectlval);
  257. ehb();
  258. printk("Mapped %ld ITC cells starting at 0x%08x\n",
  259. ((itcblkgrn & 0x7fe00000) >> 20), itc_base);
  260. }
  261. }
  262. /*
  263. * Function to protect cache flushes from concurrent execution
  264. * depends on MP software model chosen.
  265. */
  266. void mt_cflush_lockdown(void)
  267. {
  268. #ifdef CONFIG_MIPS_MT_SMTC
  269. void smtc_cflush_lockdown(void);
  270. smtc_cflush_lockdown();
  271. #endif /* CONFIG_MIPS_MT_SMTC */
  272. /* FILL IN VSMP and AP/SP VERSIONS HERE */
  273. }
  274. void mt_cflush_release(void)
  275. {
  276. #ifdef CONFIG_MIPS_MT_SMTC
  277. void smtc_cflush_release(void);
  278. smtc_cflush_release();
  279. #endif /* CONFIG_MIPS_MT_SMTC */
  280. /* FILL IN VSMP and AP/SP VERSIONS HERE */
  281. }
  282. struct class *mt_class;
  283. static int __init mt_init(void)
  284. {
  285. struct class *mtc;
  286. mtc = class_create(THIS_MODULE, "mt");
  287. if (IS_ERR(mtc))
  288. return PTR_ERR(mtc);
  289. mt_class = mtc;
  290. return 0;
  291. }
  292. subsys_initcall(mt_init);