mips-mt.c 7.3 KB

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