smp.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * SMP support for BPA machines.
  4. *
  5. * Dave Engebretsen, Peter Bergner, and
  6. * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
  7. *
  8. * Plus various changes from other IBM teams...
  9. */
  10. #undef DEBUG
  11. #include <linux/kernel.h>
  12. #include <linux/sched.h>
  13. #include <linux/smp.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/delay.h>
  16. #include <linux/init.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/cache.h>
  19. #include <linux/err.h>
  20. #include <linux/device.h>
  21. #include <linux/cpu.h>
  22. #include <linux/pgtable.h>
  23. #include <asm/ptrace.h>
  24. #include <linux/atomic.h>
  25. #include <asm/irq.h>
  26. #include <asm/page.h>
  27. #include <asm/io.h>
  28. #include <asm/smp.h>
  29. #include <asm/paca.h>
  30. #include <asm/machdep.h>
  31. #include <asm/cputable.h>
  32. #include <asm/firmware.h>
  33. #include <asm/rtas.h>
  34. #include <asm/cputhreads.h>
  35. #include <asm/code-patching.h>
  36. #include "interrupt.h"
  37. #include <asm/udbg.h>
  38. #ifdef DEBUG
  39. #define DBG(fmt...) udbg_printf(fmt)
  40. #else
  41. #define DBG(fmt...)
  42. #endif
  43. /*
  44. * The Primary thread of each non-boot processor was started from the OF client
  45. * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop.
  46. */
  47. static cpumask_t of_spin_map;
  48. /**
  49. * smp_startup_cpu() - start the given cpu
  50. *
  51. * At boot time, there is nothing to do for primary threads which were
  52. * started from Open Firmware. For anything else, call RTAS with the
  53. * appropriate start location.
  54. *
  55. * Returns:
  56. * 0 - failure
  57. * 1 - success
  58. */
  59. static inline int smp_startup_cpu(unsigned int lcpu)
  60. {
  61. int status;
  62. unsigned long start_here =
  63. __pa(ppc_function_entry(generic_secondary_smp_init));
  64. unsigned int pcpu;
  65. int start_cpu;
  66. if (cpumask_test_cpu(lcpu, &of_spin_map))
  67. /* Already started by OF and sitting in spin loop */
  68. return 1;
  69. pcpu = get_hard_smp_processor_id(lcpu);
  70. /*
  71. * If the RTAS start-cpu token does not exist then presume the
  72. * cpu is already spinning.
  73. */
  74. start_cpu = rtas_token("start-cpu");
  75. if (start_cpu == RTAS_UNKNOWN_SERVICE)
  76. return 1;
  77. status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
  78. if (status != 0) {
  79. printk(KERN_ERR "start-cpu failed: %i\n", status);
  80. return 0;
  81. }
  82. return 1;
  83. }
  84. static void smp_cell_setup_cpu(int cpu)
  85. {
  86. if (cpu != boot_cpuid)
  87. iic_setup_cpu();
  88. /*
  89. * change default DABRX to allow user watchpoints
  90. */
  91. mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
  92. }
  93. static int smp_cell_kick_cpu(int nr)
  94. {
  95. if (nr < 0 || nr >= nr_cpu_ids)
  96. return -EINVAL;
  97. if (!smp_startup_cpu(nr))
  98. return -ENOENT;
  99. /*
  100. * The processor is currently spinning, waiting for the
  101. * cpu_start field to become non-zero After we set cpu_start,
  102. * the processor will continue on to secondary_start
  103. */
  104. paca_ptrs[nr]->cpu_start = 1;
  105. return 0;
  106. }
  107. static struct smp_ops_t bpa_iic_smp_ops = {
  108. .message_pass = iic_message_pass,
  109. .probe = iic_request_IPIs,
  110. .kick_cpu = smp_cell_kick_cpu,
  111. .setup_cpu = smp_cell_setup_cpu,
  112. .cpu_bootable = smp_generic_cpu_bootable,
  113. };
  114. /* This is called very early */
  115. void __init smp_init_cell(void)
  116. {
  117. int i;
  118. DBG(" -> smp_init_cell()\n");
  119. smp_ops = &bpa_iic_smp_ops;
  120. /* Mark threads which are still spinning in hold loops. */
  121. if (cpu_has_feature(CPU_FTR_SMT)) {
  122. for_each_present_cpu(i) {
  123. if (cpu_thread_in_core(i) == 0)
  124. cpumask_set_cpu(i, &of_spin_map);
  125. }
  126. } else
  127. cpumask_copy(&of_spin_map, cpu_present_mask);
  128. cpumask_clear_cpu(boot_cpuid, &of_spin_map);
  129. /* Non-lpar has additional take/give timebase */
  130. if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
  131. smp_ops->give_timebase = rtas_give_timebase;
  132. smp_ops->take_timebase = rtas_take_timebase;
  133. }
  134. DBG(" <- smp_init_cell()\n");
  135. }