smp.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. * @lcpu: Logical CPU ID of the CPU to be started.
  51. *
  52. * At boot time, there is nothing to do for primary threads which were
  53. * started from Open Firmware. For anything else, call RTAS with the
  54. * appropriate start location.
  55. *
  56. * Returns:
  57. * 0 - failure
  58. * 1 - success
  59. */
  60. static inline int smp_startup_cpu(unsigned int lcpu)
  61. {
  62. int status;
  63. unsigned long start_here =
  64. __pa(ppc_function_entry(generic_secondary_smp_init));
  65. unsigned int pcpu;
  66. int start_cpu;
  67. if (cpumask_test_cpu(lcpu, &of_spin_map))
  68. /* Already started by OF and sitting in spin loop */
  69. return 1;
  70. pcpu = get_hard_smp_processor_id(lcpu);
  71. /*
  72. * If the RTAS start-cpu token does not exist then presume the
  73. * cpu is already spinning.
  74. */
  75. start_cpu = rtas_function_token(RTAS_FN_START_CPU);
  76. if (start_cpu == RTAS_UNKNOWN_SERVICE)
  77. return 1;
  78. status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
  79. if (status != 0) {
  80. printk(KERN_ERR "start-cpu failed: %i\n", status);
  81. return 0;
  82. }
  83. return 1;
  84. }
  85. static void smp_cell_setup_cpu(int cpu)
  86. {
  87. if (cpu != boot_cpuid)
  88. iic_setup_cpu();
  89. /*
  90. * change default DABRX to allow user watchpoints
  91. */
  92. mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
  93. }
  94. static int smp_cell_kick_cpu(int nr)
  95. {
  96. if (nr < 0 || nr >= nr_cpu_ids)
  97. return -EINVAL;
  98. if (!smp_startup_cpu(nr))
  99. return -ENOENT;
  100. /*
  101. * The processor is currently spinning, waiting for the
  102. * cpu_start field to become non-zero After we set cpu_start,
  103. * the processor will continue on to secondary_start
  104. */
  105. paca_ptrs[nr]->cpu_start = 1;
  106. return 0;
  107. }
  108. static struct smp_ops_t bpa_iic_smp_ops = {
  109. .message_pass = iic_message_pass,
  110. .probe = iic_request_IPIs,
  111. .kick_cpu = smp_cell_kick_cpu,
  112. .setup_cpu = smp_cell_setup_cpu,
  113. .cpu_bootable = smp_generic_cpu_bootable,
  114. };
  115. /* This is called very early */
  116. void __init smp_init_cell(void)
  117. {
  118. int i;
  119. DBG(" -> smp_init_cell()\n");
  120. smp_ops = &bpa_iic_smp_ops;
  121. /* Mark threads which are still spinning in hold loops. */
  122. if (cpu_has_feature(CPU_FTR_SMT)) {
  123. for_each_present_cpu(i) {
  124. if (cpu_thread_in_core(i) == 0)
  125. cpumask_set_cpu(i, &of_spin_map);
  126. }
  127. } else
  128. cpumask_copy(&of_spin_map, cpu_present_mask);
  129. cpumask_clear_cpu(boot_cpuid, &of_spin_map);
  130. /* Non-lpar has additional take/give timebase */
  131. if (rtas_function_token(RTAS_FN_FREEZE_TIME_BASE) != RTAS_UNKNOWN_SERVICE) {
  132. smp_ops->give_timebase = rtas_give_timebase;
  133. smp_ops->take_timebase = rtas_take_timebase;
  134. }
  135. DBG(" <- smp_init_cell()\n");
  136. }