mips-mt.c 7.8 KB

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