mips-mt.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. #include <asm/mips_mt.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. static int mt_opt_rpsctl = -1;
  36. static int mt_opt_nblsu = -1;
  37. static int mt_opt_forceconfig7;
  38. static int mt_opt_config7 = -1;
  39. static int __init rpsctl_set(char *str)
  40. {
  41. get_option(&str, &mt_opt_rpsctl);
  42. return 1;
  43. }
  44. __setup("rpsctl=", rpsctl_set);
  45. static int __init nblsu_set(char *str)
  46. {
  47. get_option(&str, &mt_opt_nblsu);
  48. return 1;
  49. }
  50. __setup("nblsu=", nblsu_set);
  51. static int __init config7_set(char *str)
  52. {
  53. get_option(&str, &mt_opt_config7);
  54. mt_opt_forceconfig7 = 1;
  55. return 1;
  56. }
  57. __setup("config7=", config7_set);
  58. static unsigned int itc_base;
  59. static int __init set_itc_base(char *str)
  60. {
  61. get_option(&str, &itc_base);
  62. return 1;
  63. }
  64. __setup("itcbase=", set_itc_base);
  65. void mips_mt_set_cpuoptions(void)
  66. {
  67. unsigned int oconfig7 = read_c0_config7();
  68. unsigned int nconfig7 = oconfig7;
  69. if (mt_opt_rpsctl >= 0) {
  70. printk("34K return prediction stack override set to %d.\n",
  71. mt_opt_rpsctl);
  72. if (mt_opt_rpsctl)
  73. nconfig7 |= (1 << 2);
  74. else
  75. nconfig7 &= ~(1 << 2);
  76. }
  77. if (mt_opt_nblsu >= 0) {
  78. printk("34K ALU/LSU sync override set to %d.\n", mt_opt_nblsu);
  79. if (mt_opt_nblsu)
  80. nconfig7 |= (1 << 5);
  81. else
  82. nconfig7 &= ~(1 << 5);
  83. }
  84. if (mt_opt_forceconfig7) {
  85. printk("CP0.Config7 forced to 0x%08x.\n", mt_opt_config7);
  86. nconfig7 = mt_opt_config7;
  87. }
  88. if (oconfig7 != nconfig7) {
  89. __asm__ __volatile("sync");
  90. write_c0_config7(nconfig7);
  91. ehb();
  92. printk("Config7: 0x%08x\n", read_c0_config7());
  93. }
  94. if (itc_base != 0) {
  95. /*
  96. * Configure ITC mapping. This code is very
  97. * specific to the 34K core family, which uses
  98. * a special mode bit ("ITC") in the ErrCtl
  99. * register to enable access to ITC control
  100. * registers via cache "tag" operations.
  101. */
  102. unsigned long ectlval;
  103. unsigned long itcblkgrn;
  104. /* ErrCtl register is known as "ecc" to Linux */
  105. ectlval = read_c0_ecc();
  106. write_c0_ecc(ectlval | (0x1 << 26));
  107. ehb();
  108. #define INDEX_0 (0x80000000)
  109. #define INDEX_8 (0x80000008)
  110. /* Read "cache tag" for Dcache pseudo-index 8 */
  111. cache_op(Index_Load_Tag_D, INDEX_8);
  112. ehb();
  113. itcblkgrn = read_c0_dtaglo();
  114. itcblkgrn &= 0xfffe0000;
  115. /* Set for 128 byte pitch of ITC cells */
  116. itcblkgrn |= 0x00000c00;
  117. /* Stage in Tag register */
  118. write_c0_dtaglo(itcblkgrn);
  119. ehb();
  120. /* Write out to ITU with CACHE op */
  121. cache_op(Index_Store_Tag_D, INDEX_8);
  122. /* Now set base address, and turn ITC on with 0x1 bit */
  123. write_c0_dtaglo((itc_base & 0xfffffc00) | 0x1 );
  124. ehb();
  125. /* Write out to ITU with CACHE op */
  126. cache_op(Index_Store_Tag_D, INDEX_0);
  127. write_c0_ecc(ectlval);
  128. ehb();
  129. printk("Mapped %ld ITC cells starting at 0x%08x\n",
  130. ((itcblkgrn & 0x7fe00000) >> 20), itc_base);
  131. }
  132. }
  133. const struct class mt_class = {
  134. .name = "mt",
  135. };
  136. static int __init mips_mt_init(void)
  137. {
  138. return class_register(&mt_class);
  139. }
  140. subsys_initcall(mips_mt_init);