smpboot_64.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * x86 SMP booting functions
  3. *
  4. * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
  5. * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
  6. * Copyright 2001 Andi Kleen, SuSE Labs.
  7. *
  8. * Much of the core SMP work is based on previous work by Thomas Radke, to
  9. * whom a great many thanks are extended.
  10. *
  11. * Thanks to Intel for making available several different Pentium,
  12. * Pentium Pro and Pentium-II/Xeon MP machines.
  13. * Original development of Linux SMP code supported by Caldera.
  14. *
  15. * This code is released under the GNU General Public License version 2
  16. *
  17. * Fixes
  18. * Felix Koop : NR_CPUS used properly
  19. * Jose Renau : Handle single CPU case.
  20. * Alan Cox : By repeated request 8) - Total BogoMIP report.
  21. * Greg Wright : Fix for kernel stacks panic.
  22. * Erich Boleyn : MP v1.4 and additional changes.
  23. * Matthias Sattler : Changes for 2.1 kernel map.
  24. * Michel Lespinasse : Changes for 2.1 kernel map.
  25. * Michael Chastain : Change trampoline.S to gnu as.
  26. * Alan Cox : Dumb bug: 'B' step PPro's are fine
  27. * Ingo Molnar : Added APIC timers, based on code
  28. * from Jose Renau
  29. * Ingo Molnar : various cleanups and rewrites
  30. * Tigran Aivazian : fixed "0.00 in /proc/uptime on SMP" bug.
  31. * Maciej W. Rozycki : Bits for genuine 82489DX APICs
  32. * Andi Kleen : Changed for SMP boot into long mode.
  33. * Rusty Russell : Hacked into shape for new "hotplug" boot process.
  34. * Andi Kleen : Converted to new state machine.
  35. * Various cleanups.
  36. * Probably mostly hotplug CPU ready now.
  37. * Ashok Raj : CPU hotplug support
  38. */
  39. #include <linux/init.h>
  40. #include <linux/mm.h>
  41. #include <linux/kernel_stat.h>
  42. #include <linux/bootmem.h>
  43. #include <linux/thread_info.h>
  44. #include <linux/module.h>
  45. #include <linux/delay.h>
  46. #include <linux/mc146818rtc.h>
  47. #include <linux/smp.h>
  48. #include <linux/kdebug.h>
  49. #include <asm/mtrr.h>
  50. #include <asm/pgalloc.h>
  51. #include <asm/desc.h>
  52. #include <asm/tlbflush.h>
  53. #include <asm/proto.h>
  54. #include <asm/nmi.h>
  55. #include <asm/irq.h>
  56. #include <asm/hw_irq.h>
  57. #include <asm/numa.h>
  58. #include <mach_wakecpu.h>
  59. #include <mach_apic.h>
  60. #include <smpboot_hooks.h>
  61. #include <mach_apic.h>
  62. /* Set when the idlers are all forked */
  63. int smp_threads_ready;
  64. cycles_t cacheflush_time;
  65. unsigned long cache_decay_ticks;
  66. static int boot_cpu_logical_apicid;
  67. /*
  68. * Fall back to non SMP mode after errors.
  69. *
  70. * RED-PEN audit/test this more. I bet there is more state messed up here.
  71. */
  72. static __init void disable_smp(void)
  73. {
  74. cpu_present_map = cpumask_of_cpu(0);
  75. cpu_possible_map = cpumask_of_cpu(0);
  76. if (smp_found_config)
  77. phys_cpu_present_map =
  78. physid_mask_of_physid(boot_cpu_physical_apicid);
  79. else
  80. phys_cpu_present_map = physid_mask_of_physid(0);
  81. cpu_set(0, per_cpu(cpu_sibling_map, 0));
  82. cpu_set(0, per_cpu(cpu_core_map, 0));
  83. }
  84. /*
  85. * Various sanity checks.
  86. */
  87. static int __init smp_sanity_check(unsigned max_cpus)
  88. {
  89. if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
  90. printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
  91. hard_smp_processor_id());
  92. physid_set(hard_smp_processor_id(), phys_cpu_present_map);
  93. }
  94. /*
  95. * If we couldn't find an SMP configuration at boot time,
  96. * get out of here now!
  97. */
  98. if (!smp_found_config) {
  99. printk(KERN_NOTICE "SMP motherboard not detected.\n");
  100. disable_smp();
  101. if (APIC_init_uniprocessor())
  102. printk(KERN_NOTICE "Local APIC not detected."
  103. " Using dummy APIC emulation.\n");
  104. return -1;
  105. }
  106. /*
  107. * Should not be necessary because the MP table should list the boot
  108. * CPU too, but we do it for the sake of robustness anyway.
  109. */
  110. if (!physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map)) {
  111. printk(KERN_NOTICE
  112. "weird, boot CPU (#%d) not listed by the BIOS.\n",
  113. boot_cpu_physical_apicid);
  114. physid_set(hard_smp_processor_id(), phys_cpu_present_map);
  115. }
  116. /*
  117. * If we couldn't find a local APIC, then get out of here now!
  118. */
  119. if (!cpu_has_apic) {
  120. printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
  121. boot_cpu_physical_apicid);
  122. printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
  123. nr_ioapics = 0;
  124. return -1;
  125. }
  126. /*
  127. * If SMP should be disabled, then really disable it!
  128. */
  129. if (!max_cpus) {
  130. printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
  131. nr_ioapics = 0;
  132. return -1;
  133. }
  134. return 0;
  135. }
  136. static void __init smp_cpu_index_default(void)
  137. {
  138. int i;
  139. struct cpuinfo_x86 *c;
  140. for_each_cpu_mask(i, cpu_possible_map) {
  141. c = &cpu_data(i);
  142. /* mark all to hotplug */
  143. c->cpu_index = NR_CPUS;
  144. }
  145. }
  146. /*
  147. * Prepare for SMP bootup. The MP table or ACPI has been read
  148. * earlier. Just do some sanity checking here and enable APIC mode.
  149. */
  150. void __init native_smp_prepare_cpus(unsigned int max_cpus)
  151. {
  152. nmi_watchdog_default();
  153. smp_cpu_index_default();
  154. cpu_callin_map = cpumask_of_cpu(0);
  155. mb();
  156. current_cpu_data = boot_cpu_data;
  157. boot_cpu_logical_apicid = logical_smp_processor_id();
  158. current_thread_info()->cpu = 0; /* needed? */
  159. set_cpu_sibling_map(0);
  160. if (smp_sanity_check(max_cpus) < 0) {
  161. printk(KERN_INFO "SMP disabled\n");
  162. disable_smp();
  163. return;
  164. }
  165. if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid) {
  166. panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
  167. GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_physical_apicid);
  168. /* Or can we switch back to PIC here? */
  169. }
  170. /*
  171. * Switch from PIC to APIC mode.
  172. */
  173. setup_local_APIC();
  174. /*
  175. * Enable IO APIC before setting up error vector
  176. */
  177. if (!skip_ioapic_setup && nr_ioapics)
  178. enable_IO_APIC();
  179. end_local_APIC_setup();
  180. /*
  181. * Set up local APIC timer on boot CPU.
  182. */
  183. setup_boot_clock();
  184. printk(KERN_INFO "CPU%d: ", 0);
  185. print_cpu_info(&cpu_data(0));
  186. }