smp-cmp.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 ipi_call_function(unsigned int cpu)
  39. {
  40. pr_debug("CPU%d: %s cpu %d status %08x\n",
  41. smp_processor_id(), __func__, cpu, read_c0_status());
  42. gic_send_ipi(plat_ipi_call_int_xlate(cpu));
  43. }
  44. static void ipi_resched(unsigned int cpu)
  45. {
  46. pr_debug("CPU%d: %s cpu %d status %08x\n",
  47. smp_processor_id(), __func__, cpu, read_c0_status());
  48. gic_send_ipi(plat_ipi_resched_int_xlate(cpu));
  49. }
  50. /*
  51. * FIXME: This isn't restricted to CMP
  52. * The SMVP kernel could use GIC interrupts if available
  53. */
  54. void cmp_send_ipi_single(int cpu, unsigned int action)
  55. {
  56. unsigned long flags;
  57. local_irq_save(flags);
  58. switch (action) {
  59. case SMP_CALL_FUNCTION:
  60. ipi_call_function(cpu);
  61. break;
  62. case SMP_RESCHEDULE_YOURSELF:
  63. ipi_resched(cpu);
  64. break;
  65. }
  66. local_irq_restore(flags);
  67. }
  68. static void cmp_send_ipi_mask(const struct cpumask *mask, unsigned int action)
  69. {
  70. unsigned int i;
  71. for_each_cpu(i, mask)
  72. cmp_send_ipi_single(i, action);
  73. }
  74. static void cmp_init_secondary(void)
  75. {
  76. struct cpuinfo_mips *c = &current_cpu_data;
  77. /* Assume GIC is present */
  78. change_c0_status(ST0_IM, STATUSF_IP3 | STATUSF_IP4 | STATUSF_IP6 |
  79. STATUSF_IP7);
  80. /* Enable per-cpu interrupts: platform specific */
  81. c->core = (read_c0_ebase() >> 1) & 0xff;
  82. #if defined(CONFIG_MIPS_MT_SMP) || defined(CONFIG_MIPS_MT_SMTC)
  83. c->vpe_id = (read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) & TCBIND_CURVPE;
  84. #endif
  85. #ifdef CONFIG_MIPS_MT_SMTC
  86. c->tc_id = (read_c0_tcbind() >> TCBIND_CURTC_SHIFT) & TCBIND_CURTC;
  87. #endif
  88. }
  89. static void cmp_smp_finish(void)
  90. {
  91. pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
  92. /* CDFIXME: remove this? */
  93. write_c0_compare(read_c0_count() + (8 * mips_hpt_frequency / HZ));
  94. #ifdef CONFIG_MIPS_MT_FPAFF
  95. /* If we have an FPU, enroll ourselves in the FPU-full mask */
  96. if (cpu_has_fpu)
  97. cpu_set(smp_processor_id(), mt_fpu_cpumask);
  98. #endif /* CONFIG_MIPS_MT_FPAFF */
  99. local_irq_enable();
  100. }
  101. static void cmp_cpus_done(void)
  102. {
  103. pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
  104. }
  105. /*
  106. * Setup the PC, SP, and GP of a secondary processor and start it running
  107. * smp_bootstrap is the place to resume from
  108. * __KSTK_TOS(idle) is apparently the stack pointer
  109. * (unsigned long)idle->thread_info the gp
  110. */
  111. static void cmp_boot_secondary(int cpu, struct task_struct *idle)
  112. {
  113. struct thread_info *gp = task_thread_info(idle);
  114. unsigned long sp = __KSTK_TOS(idle);
  115. unsigned long pc = (unsigned long)&smp_bootstrap;
  116. unsigned long a0 = 0;
  117. pr_debug("SMPCMP: CPU%d: %s cpu %d\n", smp_processor_id(),
  118. __func__, cpu);
  119. #if 0
  120. /* Needed? */
  121. flush_icache_range((unsigned long)gp,
  122. (unsigned long)(gp + sizeof(struct thread_info)));
  123. #endif
  124. amon_cpu_start(cpu, pc, sp, (unsigned long)gp, a0);
  125. }
  126. /*
  127. * Common setup before any secondaries are started
  128. */
  129. void __init cmp_smp_setup(void)
  130. {
  131. int i;
  132. int ncpu = 0;
  133. pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
  134. #ifdef CONFIG_MIPS_MT_FPAFF
  135. /* If we have an FPU, enroll ourselves in the FPU-full mask */
  136. if (cpu_has_fpu)
  137. cpu_set(0, mt_fpu_cpumask);
  138. #endif /* CONFIG_MIPS_MT_FPAFF */
  139. for (i = 1; i < NR_CPUS; i++) {
  140. if (amon_cpu_avail(i)) {
  141. set_cpu_possible(i, true);
  142. __cpu_number_map[i] = ++ncpu;
  143. __cpu_logical_map[ncpu] = i;
  144. }
  145. }
  146. if (cpu_has_mipsmt) {
  147. unsigned int nvpe, mvpconf0 = read_c0_mvpconf0();
  148. nvpe = ((mvpconf0 & MVPCONF0_PTC) >> MVPCONF0_PTC_SHIFT) + 1;
  149. smp_num_siblings = nvpe;
  150. }
  151. pr_info("Detected %i available secondary CPU(s)\n", ncpu);
  152. }
  153. void __init cmp_prepare_cpus(unsigned int max_cpus)
  154. {
  155. pr_debug("SMPCMP: CPU%d: %s max_cpus=%d\n",
  156. smp_processor_id(), __func__, max_cpus);
  157. /*
  158. * FIXME: some of these options are per-system, some per-core and
  159. * some per-cpu
  160. */
  161. mips_mt_set_cpuoptions();
  162. }
  163. struct plat_smp_ops cmp_smp_ops = {
  164. .send_ipi_single = cmp_send_ipi_single,
  165. .send_ipi_mask = cmp_send_ipi_mask,
  166. .init_secondary = cmp_init_secondary,
  167. .smp_finish = cmp_smp_finish,
  168. .cpus_done = cmp_cpus_done,
  169. .boot_secondary = cmp_boot_secondary,
  170. .smp_setup = cmp_smp_setup,
  171. .prepare_cpus = cmp_prepare_cpus,
  172. };