mips-mt.c 7.4 KB

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