mips-mt.c 7.7 KB

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