smp-mt.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. *
  4. * Copyright (C) 2004, 05, 06 MIPS Technologies, Inc.
  5. * Elizabeth Clarke (beth@mips.com)
  6. * Ralf Baechle (ralf@linux-mips.org)
  7. * Copyright (C) 2006 Ralf Baechle (ralf@linux-mips.org)
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/cpumask.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/compiler.h>
  14. #include <linux/sched/task_stack.h>
  15. #include <linux/smp.h>
  16. #include <linux/atomic.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/cpu.h>
  19. #include <asm/processor.h>
  20. #include <asm/hardirq.h>
  21. #include <asm/mmu_context.h>
  22. #include <asm/time.h>
  23. #include <asm/mipsregs.h>
  24. #include <asm/mipsmtregs.h>
  25. #include <asm/mips_mt.h>
  26. #include <asm/mips-cps.h>
  27. static void __init smvp_copy_vpe_config(void)
  28. {
  29. write_vpe_c0_status(
  30. (read_c0_status() & ~(ST0_IM | ST0_IE | ST0_KSU)) | ST0_CU0);
  31. /* set config to be the same as vpe0, particularly kseg0 coherency alg */
  32. write_vpe_c0_config( read_c0_config());
  33. /* make sure there are no software interrupts pending */
  34. write_vpe_c0_cause(0);
  35. /* Propagate Config7 */
  36. write_vpe_c0_config7(read_c0_config7());
  37. write_vpe_c0_count(read_c0_count());
  38. }
  39. static unsigned int __init smvp_vpe_init(unsigned int tc, unsigned int mvpconf0,
  40. unsigned int ncpu)
  41. {
  42. if (tc >= smp_max_threads ||
  43. (tc > ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT)))
  44. return ncpu;
  45. /* Deactivate all but VPE 0 */
  46. if (tc != 0) {
  47. unsigned long tmp = read_vpe_c0_vpeconf0();
  48. tmp &= ~VPECONF0_VPA;
  49. /* master VPE */
  50. tmp |= VPECONF0_MVP;
  51. write_vpe_c0_vpeconf0(tmp);
  52. /* Record this as available CPU */
  53. set_cpu_possible(tc, true);
  54. set_cpu_present(tc, true);
  55. __cpu_number_map[tc] = ++ncpu;
  56. __cpu_logical_map[ncpu] = tc;
  57. }
  58. /* Disable multi-threading with TC's */
  59. write_vpe_c0_vpecontrol(read_vpe_c0_vpecontrol() & ~VPECONTROL_TE);
  60. if (tc != 0)
  61. smvp_copy_vpe_config();
  62. cpu_set_vpe_id(&cpu_data[ncpu], tc);
  63. return ncpu;
  64. }
  65. static void __init smvp_tc_init(unsigned int tc, unsigned int mvpconf0)
  66. {
  67. unsigned long tmp;
  68. if (!tc)
  69. return;
  70. /* bind a TC to each VPE, May as well put all excess TC's
  71. on the last VPE */
  72. if (tc >= (((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT)+1))
  73. write_tc_c0_tcbind(read_tc_c0_tcbind() | ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT));
  74. else {
  75. write_tc_c0_tcbind(read_tc_c0_tcbind() | tc);
  76. /* and set XTC */
  77. write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | (tc << VPECONF0_XTC_SHIFT));
  78. }
  79. tmp = read_tc_c0_tcstatus();
  80. /* mark not allocated and not dynamically allocatable */
  81. tmp &= ~(TCSTATUS_A | TCSTATUS_DA);
  82. tmp |= TCSTATUS_IXMT; /* interrupt exempt */
  83. write_tc_c0_tcstatus(tmp);
  84. write_tc_c0_tchalt(TCHALT_H);
  85. }
  86. static void vsmp_init_secondary(void)
  87. {
  88. /* This is Malta specific: IPI,performance and timer interrupts */
  89. if (mips_gic_present())
  90. change_c0_status(ST0_IM, STATUSF_IP2 | STATUSF_IP3 |
  91. STATUSF_IP4 | STATUSF_IP5 |
  92. STATUSF_IP6 | STATUSF_IP7);
  93. else
  94. change_c0_status(ST0_IM, STATUSF_IP0 | STATUSF_IP1 |
  95. STATUSF_IP6 | STATUSF_IP7);
  96. }
  97. static void vsmp_smp_finish(void)
  98. {
  99. /* CDFIXME: remove this? */
  100. write_c0_compare(read_c0_count() + (8* mips_hpt_frequency/HZ));
  101. #ifdef CONFIG_MIPS_MT_FPAFF
  102. /* If we have an FPU, enroll ourselves in the FPU-full mask */
  103. if (cpu_has_fpu)
  104. cpumask_set_cpu(smp_processor_id(), &mt_fpu_cpumask);
  105. #endif /* CONFIG_MIPS_MT_FPAFF */
  106. local_irq_enable();
  107. }
  108. /*
  109. * Setup the PC, SP, and GP of a secondary processor and start it
  110. * running!
  111. * smp_bootstrap is the place to resume from
  112. * __KSTK_TOS(idle) is apparently the stack pointer
  113. * (unsigned long)idle->thread_info the gp
  114. * assumes a 1:1 mapping of TC => VPE
  115. */
  116. static int vsmp_boot_secondary(int cpu, struct task_struct *idle)
  117. {
  118. struct thread_info *gp = task_thread_info(idle);
  119. dvpe();
  120. set_c0_mvpcontrol(MVPCONTROL_VPC);
  121. settc(cpu);
  122. /* restart */
  123. write_tc_c0_tcrestart((unsigned long)&smp_bootstrap);
  124. /* enable the tc this vpe/cpu will be running */
  125. write_tc_c0_tcstatus((read_tc_c0_tcstatus() & ~TCSTATUS_IXMT) | TCSTATUS_A);
  126. write_tc_c0_tchalt(0);
  127. /* enable the VPE */
  128. write_vpe_c0_vpeconf0(read_vpe_c0_vpeconf0() | VPECONF0_VPA);
  129. /* stack pointer */
  130. write_tc_gpr_sp( __KSTK_TOS(idle));
  131. /* global pointer */
  132. write_tc_gpr_gp((unsigned long)gp);
  133. flush_icache_range((unsigned long)gp,
  134. (unsigned long)(gp + sizeof(struct thread_info)));
  135. /* finally out of configuration and into chaos */
  136. clear_c0_mvpcontrol(MVPCONTROL_VPC);
  137. evpe(EVPE_ENABLE);
  138. return 0;
  139. }
  140. /*
  141. * Common setup before any secondaries are started
  142. * Make sure all CPU's are in a sensible state before we boot any of the
  143. * secondaries
  144. */
  145. static void __init vsmp_smp_setup(void)
  146. {
  147. unsigned int mvpconf0, ntc, tc, ncpu = 0;
  148. unsigned int nvpe;
  149. #ifdef CONFIG_MIPS_MT_FPAFF
  150. /* If we have an FPU, enroll ourselves in the FPU-full mask */
  151. if (cpu_has_fpu)
  152. cpumask_set_cpu(0, &mt_fpu_cpumask);
  153. #endif /* CONFIG_MIPS_MT_FPAFF */
  154. if (!cpu_has_mipsmt)
  155. return;
  156. /* disable MT so we can configure */
  157. dvpe();
  158. dmt();
  159. /* Put MVPE's into 'configuration state' */
  160. set_c0_mvpcontrol(MVPCONTROL_VPC);
  161. mvpconf0 = read_c0_mvpconf0();
  162. ntc = (mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT;
  163. nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
  164. smp_num_siblings = nvpe;
  165. /* we'll always have more TC's than VPE's, so loop setting everything
  166. to a sensible state */
  167. for (tc = 0; tc <= ntc; tc++) {
  168. settc(tc);
  169. smvp_tc_init(tc, mvpconf0);
  170. ncpu = smvp_vpe_init(tc, mvpconf0, ncpu);
  171. }
  172. /* Release config state */
  173. clear_c0_mvpcontrol(MVPCONTROL_VPC);
  174. /* We'll wait until starting the secondaries before starting MVPE */
  175. printk(KERN_INFO "Detected %i available secondary CPU(s)\n", ncpu);
  176. }
  177. static void __init vsmp_prepare_cpus(unsigned int max_cpus)
  178. {
  179. mips_mt_set_cpuoptions();
  180. }
  181. const struct plat_smp_ops vsmp_smp_ops = {
  182. .send_ipi_single = mips_smp_send_ipi_single,
  183. .send_ipi_mask = mips_smp_send_ipi_mask,
  184. .init_secondary = vsmp_init_secondary,
  185. .smp_finish = vsmp_smp_finish,
  186. .boot_secondary = vsmp_boot_secondary,
  187. .smp_setup = vsmp_smp_setup,
  188. .prepare_cpus = vsmp_prepare_cpus,
  189. };