smp-cmp.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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/irqchip/mips-gic.h>
  26. #include <linux/atomic.h>
  27. #include <asm/cacheflush.h>
  28. #include <asm/cpu.h>
  29. #include <asm/processor.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. 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_IP2 | STATUSF_IP3 | STATUSF_IP4 |
  43. STATUSF_IP5 | STATUSF_IP6 | STATUSF_IP7);
  44. /* Enable per-cpu interrupts: platform specific */
  45. #ifdef CONFIG_MIPS_MT_SMP
  46. if (cpu_has_mipsmt)
  47. c->vpe_id = (read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) &
  48. TCBIND_CURVPE;
  49. #endif
  50. }
  51. static void cmp_smp_finish(void)
  52. {
  53. pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
  54. /* CDFIXME: remove this? */
  55. write_c0_compare(read_c0_count() + (8 * mips_hpt_frequency / HZ));
  56. #ifdef CONFIG_MIPS_MT_FPAFF
  57. /* If we have an FPU, enroll ourselves in the FPU-full mask */
  58. if (cpu_has_fpu)
  59. cpumask_set_cpu(smp_processor_id(), &mt_fpu_cpumask);
  60. #endif /* CONFIG_MIPS_MT_FPAFF */
  61. local_irq_enable();
  62. }
  63. /*
  64. * Setup the PC, SP, and GP of a secondary processor and start it running
  65. * smp_bootstrap is the place to resume from
  66. * __KSTK_TOS(idle) is apparently the stack pointer
  67. * (unsigned long)idle->thread_info the gp
  68. */
  69. static void cmp_boot_secondary(int cpu, struct task_struct *idle)
  70. {
  71. struct thread_info *gp = task_thread_info(idle);
  72. unsigned long sp = __KSTK_TOS(idle);
  73. unsigned long pc = (unsigned long)&smp_bootstrap;
  74. unsigned long a0 = 0;
  75. pr_debug("SMPCMP: CPU%d: %s cpu %d\n", smp_processor_id(),
  76. __func__, cpu);
  77. #if 0
  78. /* Needed? */
  79. flush_icache_range((unsigned long)gp,
  80. (unsigned long)(gp + sizeof(struct thread_info)));
  81. #endif
  82. amon_cpu_start(cpu, pc, sp, (unsigned long)gp, a0);
  83. }
  84. /*
  85. * Common setup before any secondaries are started
  86. */
  87. void __init cmp_smp_setup(void)
  88. {
  89. int i;
  90. int ncpu = 0;
  91. pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
  92. #ifdef CONFIG_MIPS_MT_FPAFF
  93. /* If we have an FPU, enroll ourselves in the FPU-full mask */
  94. if (cpu_has_fpu)
  95. cpumask_set_cpu(0, &mt_fpu_cpumask);
  96. #endif /* CONFIG_MIPS_MT_FPAFF */
  97. for (i = 1; i < NR_CPUS; i++) {
  98. if (amon_cpu_avail(i)) {
  99. set_cpu_possible(i, true);
  100. __cpu_number_map[i] = ++ncpu;
  101. __cpu_logical_map[ncpu] = i;
  102. }
  103. }
  104. if (cpu_has_mipsmt) {
  105. unsigned int nvpe = 1;
  106. #ifdef CONFIG_MIPS_MT_SMP
  107. unsigned int mvpconf0 = read_c0_mvpconf0();
  108. nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
  109. #endif
  110. smp_num_siblings = nvpe;
  111. }
  112. pr_info("Detected %i available secondary CPU(s)\n", ncpu);
  113. }
  114. void __init cmp_prepare_cpus(unsigned int max_cpus)
  115. {
  116. pr_debug("SMPCMP: CPU%d: %s max_cpus=%d\n",
  117. smp_processor_id(), __func__, max_cpus);
  118. #ifdef CONFIG_MIPS_MT
  119. /*
  120. * FIXME: some of these options are per-system, some per-core and
  121. * some per-cpu
  122. */
  123. mips_mt_set_cpuoptions();
  124. #endif
  125. }
  126. struct plat_smp_ops cmp_smp_ops = {
  127. .send_ipi_single = gic_send_ipi_single,
  128. .send_ipi_mask = gic_send_ipi_mask,
  129. .init_secondary = cmp_init_secondary,
  130. .smp_finish = cmp_smp_finish,
  131. .boot_secondary = cmp_boot_secondary,
  132. .smp_setup = cmp_smp_setup,
  133. .prepare_cpus = cmp_prepare_cpus,
  134. };