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