smp.c 6.3 KB

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