smp-cmp.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * This program is free software; you can distribute it and/or modify it
  3. * under the terms of the GNU General Public License (Version 2) as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  9. * for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License along
  12. * with this program; if not, write to the Free Software Foundation, Inc.,
  13. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  14. *
  15. * Copyright (C) 2007 MIPS Technologies, Inc.
  16. * Chris Dearman (chris@mips.com)
  17. */
  18. #undef DEBUG
  19. #include <linux/kernel.h>
  20. #include <linux/sched.h>
  21. #include <linux/smp.h>
  22. #include <linux/cpumask.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/compiler.h>
  25. #include <linux/atomic.h>
  26. #include <asm/cacheflush.h>
  27. #include <asm/cpu.h>
  28. #include <asm/processor.h>
  29. #include <asm/hardirq.h>
  30. #include <asm/mmu_context.h>
  31. #include <asm/smp.h>
  32. #include <asm/time.h>
  33. #include <asm/mipsregs.h>
  34. #include <asm/mipsmtregs.h>
  35. #include <asm/mips_mt.h>
  36. #include <asm/amon.h>
  37. #include <asm/gic.h>
  38. static void cmp_init_secondary(void)
  39. {
  40. struct cpuinfo_mips *c __maybe_unused = &current_cpu_data;
  41. /* Assume GIC is present */
  42. change_c0_status(ST0_IM, STATUSF_IP3 | STATUSF_IP4 | STATUSF_IP6 |
  43. STATUSF_IP7);
  44. /* Enable per-cpu interrupts: platform specific */
  45. #if defined(CONFIG_MIPS_MT_SMP) || defined(CONFIG_MIPS_MT_SMTC)
  46. if (cpu_has_mipsmt)
  47. c->vpe_id = (read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) &
  48. TCBIND_CURVPE;
  49. #endif
  50. #ifdef CONFIG_MIPS_MT_SMTC
  51. c->tc_id = (read_c0_tcbind() & TCBIND_CURTC) >> TCBIND_CURTC_SHIFT;
  52. #endif
  53. }
  54. static void cmp_smp_finish(void)
  55. {
  56. pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
  57. /* CDFIXME: remove this? */
  58. write_c0_compare(read_c0_count() + (8 * mips_hpt_frequency / HZ));
  59. #ifdef CONFIG_MIPS_MT_FPAFF
  60. /* If we have an FPU, enroll ourselves in the FPU-full mask */
  61. if (cpu_has_fpu)
  62. cpu_set(smp_processor_id(), mt_fpu_cpumask);
  63. #endif /* CONFIG_MIPS_MT_FPAFF */
  64. local_irq_enable();
  65. }
  66. static void cmp_cpus_done(void)
  67. {
  68. pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
  69. }
  70. /*
  71. * Setup the PC, SP, and GP of a secondary processor and start it running
  72. * smp_bootstrap is the place to resume from
  73. * __KSTK_TOS(idle) is apparently the stack pointer
  74. * (unsigned long)idle->thread_info the gp
  75. */
  76. static void cmp_boot_secondary(int cpu, struct task_struct *idle)
  77. {
  78. struct thread_info *gp = task_thread_info(idle);
  79. unsigned long sp = __KSTK_TOS(idle);
  80. unsigned long pc = (unsigned long)&smp_bootstrap;
  81. unsigned long a0 = 0;
  82. pr_debug("SMPCMP: CPU%d: %s cpu %d\n", smp_processor_id(),
  83. __func__, cpu);
  84. #if 0
  85. /* Needed? */
  86. flush_icache_range((unsigned long)gp,
  87. (unsigned long)(gp + sizeof(struct thread_info)));
  88. #endif
  89. amon_cpu_start(cpu, pc, sp, (unsigned long)gp, a0);
  90. }
  91. /*
  92. * Common setup before any secondaries are started
  93. */
  94. void __init cmp_smp_setup(void)
  95. {
  96. int i;
  97. int ncpu = 0;
  98. pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
  99. #ifdef CONFIG_MIPS_MT_FPAFF
  100. /* If we have an FPU, enroll ourselves in the FPU-full mask */
  101. if (cpu_has_fpu)
  102. cpu_set(0, mt_fpu_cpumask);
  103. #endif /* CONFIG_MIPS_MT_FPAFF */
  104. for (i = 1; i < NR_CPUS; i++) {
  105. if (amon_cpu_avail(i)) {
  106. set_cpu_possible(i, true);
  107. __cpu_number_map[i] = ++ncpu;
  108. __cpu_logical_map[ncpu] = i;
  109. }
  110. }
  111. if (cpu_has_mipsmt) {
  112. unsigned int nvpe = 1;
  113. #ifdef CONFIG_MIPS_MT_SMP
  114. unsigned int mvpconf0 = read_c0_mvpconf0();
  115. nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
  116. #elif defined(CONFIG_MIPS_MT_SMTC)
  117. unsigned int mvpconf0 = read_c0_mvpconf0();
  118. nvpe = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
  119. #endif
  120. smp_num_siblings = nvpe;
  121. }
  122. pr_info("Detected %i available secondary CPU(s)\n", ncpu);
  123. }
  124. void __init cmp_prepare_cpus(unsigned int max_cpus)
  125. {
  126. pr_debug("SMPCMP: CPU%d: %s max_cpus=%d\n",
  127. smp_processor_id(), __func__, max_cpus);
  128. #ifdef CONFIG_MIPS_MT
  129. /*
  130. * FIXME: some of these options are per-system, some per-core and
  131. * some per-cpu
  132. */
  133. mips_mt_set_cpuoptions();
  134. #endif
  135. }
  136. struct plat_smp_ops cmp_smp_ops = {
  137. .send_ipi_single = gic_send_ipi_single,
  138. .send_ipi_mask = gic_send_ipi_mask,
  139. .init_secondary = cmp_init_secondary,
  140. .smp_finish = cmp_smp_finish,
  141. .cpus_done = cmp_cpus_done,
  142. .boot_secondary = cmp_boot_secondary,
  143. .smp_setup = cmp_smp_setup,
  144. .prepare_cpus = cmp_prepare_cpus,
  145. };