smp.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Intel SMP support routines.
  3. *
  4. * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk>
  5. * (c) 1998-99, 2000, 2009 Ingo Molnar <mingo@redhat.com>
  6. * (c) 2002,2003 Andi Kleen, SuSE Labs.
  7. *
  8. * i386 and x86_64 integration by Glauber Costa <gcosta@redhat.com>
  9. *
  10. * This code is released under the GNU General Public License version 2 or
  11. * later.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/mm.h>
  15. #include <linux/delay.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/kernel_stat.h>
  18. #include <linux/mc146818rtc.h>
  19. #include <linux/cache.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/cpu.h>
  22. #include <asm/mtrr.h>
  23. #include <asm/tlbflush.h>
  24. #include <asm/mmu_context.h>
  25. #include <asm/proto.h>
  26. #include <asm/apic.h>
  27. /*
  28. * Some notes on x86 processor bugs affecting SMP operation:
  29. *
  30. * Pentium, Pentium Pro, II, III (and all CPUs) have bugs.
  31. * The Linux implications for SMP are handled as follows:
  32. *
  33. * Pentium III / [Xeon]
  34. * None of the E1AP-E3AP errata are visible to the user.
  35. *
  36. * E1AP. see PII A1AP
  37. * E2AP. see PII A2AP
  38. * E3AP. see PII A3AP
  39. *
  40. * Pentium II / [Xeon]
  41. * None of the A1AP-A3AP errata are visible to the user.
  42. *
  43. * A1AP. see PPro 1AP
  44. * A2AP. see PPro 2AP
  45. * A3AP. see PPro 7AP
  46. *
  47. * Pentium Pro
  48. * None of 1AP-9AP errata are visible to the normal user,
  49. * except occasional delivery of 'spurious interrupt' as trap #15.
  50. * This is very rare and a non-problem.
  51. *
  52. * 1AP. Linux maps APIC as non-cacheable
  53. * 2AP. worked around in hardware
  54. * 3AP. fixed in C0 and above steppings microcode update.
  55. * Linux does not use excessive STARTUP_IPIs.
  56. * 4AP. worked around in hardware
  57. * 5AP. symmetric IO mode (normal Linux operation) not affected.
  58. * 'noapic' mode has vector 0xf filled out properly.
  59. * 6AP. 'noapic' mode might be affected - fixed in later steppings
  60. * 7AP. We do not assume writes to the LVT deassering IRQs
  61. * 8AP. We do not enable low power mode (deep sleep) during MP bootup
  62. * 9AP. We do not use mixed mode
  63. *
  64. * Pentium
  65. * There is a marginal case where REP MOVS on 100MHz SMP
  66. * machines with B stepping processors can fail. XXX should provide
  67. * an L1cache=Writethrough or L1cache=off option.
  68. *
  69. * B stepping CPUs may hang. There are hardware work arounds
  70. * for this. We warn about it in case your board doesn't have the work
  71. * arounds. Basically that's so I can tell anyone with a B stepping
  72. * CPU and SMP problems "tough".
  73. *
  74. * Specific items [From Pentium Processor Specification Update]
  75. *
  76. * 1AP. Linux doesn't use remote read
  77. * 2AP. Linux doesn't trust APIC errors
  78. * 3AP. We work around this
  79. * 4AP. Linux never generated 3 interrupts of the same priority
  80. * to cause a lost local interrupt.
  81. * 5AP. Remote read is never used
  82. * 6AP. not affected - worked around in hardware
  83. * 7AP. not affected - worked around in hardware
  84. * 8AP. worked around in hardware - we get explicit CS errors if not
  85. * 9AP. only 'noapic' mode affected. Might generate spurious
  86. * interrupts, we log only the first one and count the
  87. * rest silently.
  88. * 10AP. not affected - worked around in hardware
  89. * 11AP. Linux reads the APIC between writes to avoid this, as per
  90. * the documentation. Make sure you preserve this as it affects
  91. * the C stepping chips too.
  92. * 12AP. not affected - worked around in hardware
  93. * 13AP. not affected - worked around in hardware
  94. * 14AP. we always deassert INIT during bootup
  95. * 15AP. not affected - worked around in hardware
  96. * 16AP. not affected - worked around in hardware
  97. * 17AP. not affected - worked around in hardware
  98. * 18AP. not affected - worked around in hardware
  99. * 19AP. not affected - worked around in BIOS
  100. *
  101. * If this sounds worrying believe me these bugs are either ___RARE___,
  102. * or are signal timing bugs worked around in hardware and there's
  103. * about nothing of note with C stepping upwards.
  104. */
  105. /*
  106. * this function sends a 'reschedule' IPI to another CPU.
  107. * it goes straight through and wastes no time serializing
  108. * anything. Worst case is that we lose a reschedule ...
  109. */
  110. static void native_smp_send_reschedule(int cpu)
  111. {
  112. if (unlikely(cpu_is_offline(cpu))) {
  113. WARN_ON(1);
  114. return;
  115. }
  116. apic->send_IPI_mask(cpumask_of(cpu), RESCHEDULE_VECTOR);
  117. }
  118. void native_send_call_func_single_ipi(int cpu)
  119. {
  120. apic->send_IPI_mask(cpumask_of(cpu), CALL_FUNCTION_SINGLE_VECTOR);
  121. }
  122. void native_send_call_func_ipi(const struct cpumask *mask)
  123. {
  124. cpumask_var_t allbutself;
  125. if (!alloc_cpumask_var(&allbutself, GFP_ATOMIC)) {
  126. apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
  127. return;
  128. }
  129. cpumask_copy(allbutself, cpu_online_mask);
  130. cpumask_clear_cpu(smp_processor_id(), allbutself);
  131. if (cpumask_equal(mask, allbutself) &&
  132. cpumask_equal(cpu_online_mask, cpu_callout_mask))
  133. apic->send_IPI_allbutself(CALL_FUNCTION_VECTOR);
  134. else
  135. apic->send_IPI_mask(mask, CALL_FUNCTION_VECTOR);
  136. free_cpumask_var(allbutself);
  137. }
  138. /*
  139. * this function calls the 'stop' function on all other CPUs in the system.
  140. */
  141. static void native_smp_send_stop(void)
  142. {
  143. unsigned long flags;
  144. if (reboot_force)
  145. return;
  146. smp_call_function(stop_this_cpu, NULL, 0);
  147. local_irq_save(flags);
  148. disable_local_APIC();
  149. local_irq_restore(flags);
  150. }
  151. /*
  152. * Reschedule call back. Nothing to do,
  153. * all the work is done automatically when
  154. * we return from the interrupt.
  155. */
  156. void smp_reschedule_interrupt(struct pt_regs *regs)
  157. {
  158. ack_APIC_irq();
  159. inc_irq_stat(irq_resched_count);
  160. }
  161. void smp_call_function_interrupt(struct pt_regs *regs)
  162. {
  163. ack_APIC_irq();
  164. irq_enter();
  165. generic_smp_call_function_interrupt();
  166. inc_irq_stat(irq_call_count);
  167. irq_exit();
  168. }
  169. void smp_call_function_single_interrupt(struct pt_regs *regs)
  170. {
  171. ack_APIC_irq();
  172. irq_enter();
  173. generic_smp_call_function_single_interrupt();
  174. inc_irq_stat(irq_call_count);
  175. irq_exit();
  176. }
  177. struct smp_ops smp_ops = {
  178. .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
  179. .smp_prepare_cpus = native_smp_prepare_cpus,
  180. .smp_cpus_done = native_smp_cpus_done,
  181. .smp_send_stop = native_smp_send_stop,
  182. .smp_send_reschedule = native_smp_send_reschedule,
  183. .cpu_up = native_cpu_up,
  184. .cpu_die = native_cpu_die,
  185. .cpu_disable = native_cpu_disable,
  186. .play_dead = native_play_dead,
  187. .send_call_func_ipi = native_send_call_func_ipi,
  188. .send_call_func_single_ipi = native_send_call_func_single_ipi,
  189. };
  190. EXPORT_SYMBOL_GPL(smp_ops);