smp.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * SMP support for PowerNV machines.
  3. *
  4. * Copyright 2011 IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/sched.h>
  14. #include <linux/smp.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/delay.h>
  17. #include <linux/init.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/cpu.h>
  20. #include <asm/irq.h>
  21. #include <asm/smp.h>
  22. #include <asm/paca.h>
  23. #include <asm/machdep.h>
  24. #include <asm/cputable.h>
  25. #include <asm/firmware.h>
  26. #include <asm/system.h>
  27. #include <asm/rtas.h>
  28. #include <asm/vdso_datapage.h>
  29. #include <asm/cputhreads.h>
  30. #include <asm/xics.h>
  31. #include <asm/opal.h>
  32. #include "powernv.h"
  33. #ifdef DEBUG
  34. #include <asm/udbg.h>
  35. #define DBG(fmt...) udbg_printf(fmt)
  36. #else
  37. #define DBG(fmt...)
  38. #endif
  39. static void __cpuinit pnv_smp_setup_cpu(int cpu)
  40. {
  41. if (cpu != boot_cpuid)
  42. xics_setup_cpu();
  43. }
  44. static int pnv_smp_cpu_bootable(unsigned int nr)
  45. {
  46. /* Special case - we inhibit secondary thread startup
  47. * during boot if the user requests it.
  48. */
  49. if (system_state < SYSTEM_RUNNING && cpu_has_feature(CPU_FTR_SMT)) {
  50. if (!smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
  51. return 0;
  52. if (smt_enabled_at_boot
  53. && cpu_thread_in_core(nr) >= smt_enabled_at_boot)
  54. return 0;
  55. }
  56. return 1;
  57. }
  58. int __devinit pnv_smp_kick_cpu(int nr)
  59. {
  60. unsigned int pcpu = get_hard_smp_processor_id(nr);
  61. unsigned long start_here = __pa(*((unsigned long *)
  62. generic_secondary_smp_init));
  63. long rc;
  64. BUG_ON(nr < 0 || nr >= NR_CPUS);
  65. /* On OPAL v2 the CPU are still spinning inside OPAL itself,
  66. * get them back now
  67. */
  68. if (firmware_has_feature(FW_FEATURE_OPALv2)) {
  69. pr_devel("OPAL: Starting CPU %d (HW 0x%x)...\n", nr, pcpu);
  70. rc = opal_start_cpu(pcpu, start_here);
  71. if (rc != OPAL_SUCCESS)
  72. pr_warn("OPAL Error %ld starting CPU %d\n",
  73. rc, nr);
  74. }
  75. return smp_generic_kick_cpu(nr);
  76. }
  77. #ifdef CONFIG_HOTPLUG_CPU
  78. static int pnv_smp_cpu_disable(void)
  79. {
  80. int cpu = smp_processor_id();
  81. /* This is identical to pSeries... might consolidate by
  82. * moving migrate_irqs_away to a ppc_md with default to
  83. * the generic fixup_irqs. --BenH.
  84. */
  85. set_cpu_online(cpu, false);
  86. vdso_data->processorCount--;
  87. if (cpu == boot_cpuid)
  88. boot_cpuid = cpumask_any(cpu_online_mask);
  89. xics_migrate_irqs_away();
  90. return 0;
  91. }
  92. static void pnv_smp_cpu_kill_self(void)
  93. {
  94. unsigned int cpu;
  95. /* If powersave_nap is enabled, use NAP mode, else just
  96. * spin aimlessly
  97. */
  98. if (!powersave_nap) {
  99. generic_mach_cpu_die();
  100. return;
  101. }
  102. /* Standard hot unplug procedure */
  103. local_irq_disable();
  104. idle_task_exit();
  105. current->active_mm = NULL; /* for sanity */
  106. cpu = smp_processor_id();
  107. DBG("CPU%d offline\n", cpu);
  108. generic_set_cpu_dead(cpu);
  109. smp_wmb();
  110. /* We don't want to take decrementer interrupts while we are offline,
  111. * so clear LPCR:PECE1. We keep PECE2 enabled.
  112. */
  113. mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) & ~(u64)LPCR_PECE1);
  114. while (!generic_check_cpu_restart(cpu)) {
  115. power7_idle();
  116. if (!generic_check_cpu_restart(cpu)) {
  117. DBG("CPU%d Unexpected exit while offline !\n", cpu);
  118. /* We may be getting an IPI, so we re-enable
  119. * interrupts to process it, it will be ignored
  120. * since we aren't online (hopefully)
  121. */
  122. local_irq_enable();
  123. local_irq_disable();
  124. }
  125. }
  126. mtspr(SPRN_LPCR, mfspr(SPRN_LPCR) | LPCR_PECE1);
  127. DBG("CPU%d coming online...\n", cpu);
  128. }
  129. #endif /* CONFIG_HOTPLUG_CPU */
  130. static struct smp_ops_t pnv_smp_ops = {
  131. .message_pass = smp_muxed_ipi_message_pass,
  132. .cause_ipi = NULL, /* Filled at runtime by xics_smp_probe() */
  133. .probe = xics_smp_probe,
  134. .kick_cpu = pnv_smp_kick_cpu,
  135. .setup_cpu = pnv_smp_setup_cpu,
  136. .cpu_bootable = pnv_smp_cpu_bootable,
  137. #ifdef CONFIG_HOTPLUG_CPU
  138. .cpu_disable = pnv_smp_cpu_disable,
  139. .cpu_die = generic_cpu_die,
  140. #endif /* CONFIG_HOTPLUG_CPU */
  141. };
  142. /* This is called very early during platform setup_arch */
  143. void __init pnv_smp_init(void)
  144. {
  145. smp_ops = &pnv_smp_ops;
  146. /* XXX We don't yet have a proper entry point from HAL, for
  147. * now we rely on kexec-style entry from BML
  148. */
  149. #ifdef CONFIG_PPC_RTAS
  150. /* Non-lpar has additional take/give timebase */
  151. if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
  152. smp_ops->give_timebase = rtas_give_timebase;
  153. smp_ops->take_timebase = rtas_take_timebase;
  154. }
  155. #endif /* CONFIG_PPC_RTAS */
  156. #ifdef CONFIG_HOTPLUG_CPU
  157. ppc_md.cpu_die = pnv_smp_cpu_kill_self;
  158. #endif
  159. }