smp.c 4.4 KB

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