smp-cmp.c 5.2 KB

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