paravirt-smp.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2013 Cavium, Inc.
  7. */
  8. #include <linux/interrupt.h>
  9. #include <linux/cpumask.h>
  10. #include <linux/kernel.h>
  11. #include <linux/sched.h>
  12. #include <asm/mipsregs.h>
  13. #include <asm/setup.h>
  14. #include <asm/time.h>
  15. #include <asm/smp.h>
  16. /*
  17. * Writing the sp releases the CPU, so writes must be ordered, gp
  18. * first, then sp.
  19. */
  20. unsigned long paravirt_smp_sp[NR_CPUS];
  21. unsigned long paravirt_smp_gp[NR_CPUS];
  22. static int numcpus = 1;
  23. static int __init set_numcpus(char *str)
  24. {
  25. int newval;
  26. if (get_option(&str, &newval)) {
  27. if (newval < 1 || newval >= NR_CPUS)
  28. goto bad;
  29. numcpus = newval;
  30. return 0;
  31. }
  32. bad:
  33. return -EINVAL;
  34. }
  35. early_param("numcpus", set_numcpus);
  36. static void paravirt_smp_setup(void)
  37. {
  38. int id;
  39. unsigned int cpunum = get_ebase_cpunum();
  40. if (WARN_ON(cpunum >= NR_CPUS))
  41. return;
  42. /* The present CPUs are initially just the boot cpu (CPU 0). */
  43. for (id = 0; id < NR_CPUS; id++) {
  44. set_cpu_possible(id, id == 0);
  45. set_cpu_present(id, id == 0);
  46. }
  47. __cpu_number_map[cpunum] = 0;
  48. __cpu_logical_map[0] = cpunum;
  49. for (id = 0; id < numcpus; id++) {
  50. set_cpu_possible(id, true);
  51. set_cpu_present(id, true);
  52. __cpu_number_map[id] = id;
  53. __cpu_logical_map[id] = id;
  54. }
  55. }
  56. void irq_mbox_ipi(int cpu, unsigned int actions);
  57. static void paravirt_send_ipi_single(int cpu, unsigned int action)
  58. {
  59. irq_mbox_ipi(cpu, action);
  60. }
  61. static void paravirt_send_ipi_mask(const struct cpumask *mask, unsigned int action)
  62. {
  63. unsigned int cpu;
  64. for_each_cpu(cpu, mask)
  65. paravirt_send_ipi_single(cpu, action);
  66. }
  67. static void paravirt_init_secondary(void)
  68. {
  69. unsigned int sr;
  70. sr = set_c0_status(ST0_BEV);
  71. write_c0_ebase((u32)ebase);
  72. sr |= STATUSF_IP2; /* Interrupt controller on IP2 */
  73. write_c0_status(sr);
  74. irq_cpu_online();
  75. }
  76. static void paravirt_smp_finish(void)
  77. {
  78. /* to generate the first CPU timer interrupt */
  79. write_c0_compare(read_c0_count() + mips_hpt_frequency / HZ);
  80. local_irq_enable();
  81. }
  82. static void paravirt_boot_secondary(int cpu, struct task_struct *idle)
  83. {
  84. paravirt_smp_gp[cpu] = (unsigned long)task_thread_info(idle);
  85. smp_wmb();
  86. paravirt_smp_sp[cpu] = __KSTK_TOS(idle);
  87. }
  88. static irqreturn_t paravirt_reched_interrupt(int irq, void *dev_id)
  89. {
  90. scheduler_ipi();
  91. return IRQ_HANDLED;
  92. }
  93. static irqreturn_t paravirt_function_interrupt(int irq, void *dev_id)
  94. {
  95. smp_call_function_interrupt();
  96. return IRQ_HANDLED;
  97. }
  98. static void paravirt_prepare_cpus(unsigned int max_cpus)
  99. {
  100. if (request_irq(MIPS_IRQ_MBOX0, paravirt_reched_interrupt,
  101. IRQF_PERCPU | IRQF_NO_THREAD, "Scheduler",
  102. paravirt_reched_interrupt)) {
  103. panic("Cannot request_irq for SchedulerIPI");
  104. }
  105. if (request_irq(MIPS_IRQ_MBOX1, paravirt_function_interrupt,
  106. IRQF_PERCPU | IRQF_NO_THREAD, "SMP-Call",
  107. paravirt_function_interrupt)) {
  108. panic("Cannot request_irq for SMP-Call");
  109. }
  110. }
  111. struct plat_smp_ops paravirt_smp_ops = {
  112. .send_ipi_single = paravirt_send_ipi_single,
  113. .send_ipi_mask = paravirt_send_ipi_mask,
  114. .init_secondary = paravirt_init_secondary,
  115. .smp_finish = paravirt_smp_finish,
  116. .boot_secondary = paravirt_boot_secondary,
  117. .smp_setup = paravirt_smp_setup,
  118. .prepare_cpus = paravirt_prepare_cpus,
  119. };