mips-mt.c 7.3 KB

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