smpboot_32.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. *
  7. * Much of the core SMP work is based on previous work by Thomas Radke, to
  8. * whom a great many thanks are extended.
  9. *
  10. * Thanks to Intel for making available several different Pentium,
  11. * Pentium Pro and Pentium-II/Xeon MP machines.
  12. * Original development of Linux SMP code supported by Caldera.
  13. *
  14. * This code is released under the GNU General Public License version 2 or
  15. * later.
  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 BogoMIPS 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. * Martin J. Bligh : Added support for multi-quad systems
  33. * Dave Jones : Report invalid combinations of Athlon CPUs.
  34. * Rusty Russell : Hacked into shape for new "hotplug" boot process. */
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/kernel.h>
  38. #include <linux/mm.h>
  39. #include <linux/sched.h>
  40. #include <linux/kernel_stat.h>
  41. #include <linux/bootmem.h>
  42. #include <linux/notifier.h>
  43. #include <linux/cpu.h>
  44. #include <linux/percpu.h>
  45. #include <linux/nmi.h>
  46. #include <linux/delay.h>
  47. #include <linux/mc146818rtc.h>
  48. #include <asm/tlbflush.h>
  49. #include <asm/desc.h>
  50. #include <asm/arch_hooks.h>
  51. #include <asm/nmi.h>
  52. #include <mach_apic.h>
  53. #include <mach_wakecpu.h>
  54. #include <smpboot_hooks.h>
  55. #include <asm/vmi.h>
  56. #include <asm/mtrr.h>
  57. /* which logical CPU number maps to which CPU (physical APIC ID) */
  58. u16 x86_cpu_to_apicid_init[NR_CPUS] __initdata =
  59. { [0 ... NR_CPUS-1] = BAD_APICID };
  60. void *x86_cpu_to_apicid_early_ptr;
  61. DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID;
  62. EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid);
  63. u16 x86_bios_cpu_apicid_init[NR_CPUS] __initdata
  64. = { [0 ... NR_CPUS-1] = BAD_APICID };
  65. void *x86_bios_cpu_apicid_early_ptr;
  66. DEFINE_PER_CPU(u16, x86_bios_cpu_apicid) = BAD_APICID;
  67. EXPORT_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
  68. u8 apicid_2_node[MAX_APICID];
  69. extern void map_cpu_to_logical_apicid(void);
  70. extern void unmap_cpu_to_logical_apicid(int cpu);
  71. /* State of each CPU. */
  72. DEFINE_PER_CPU(int, cpu_state) = { 0 };
  73. #ifdef CONFIG_HOTPLUG_CPU
  74. void cpu_exit_clear(void)
  75. {
  76. int cpu = raw_smp_processor_id();
  77. idle_task_exit();
  78. cpu_uninit();
  79. irq_ctx_exit(cpu);
  80. cpu_clear(cpu, cpu_callout_map);
  81. cpu_clear(cpu, cpu_callin_map);
  82. unmap_cpu_to_logical_apicid(cpu);
  83. }
  84. #endif
  85. static int boot_cpu_logical_apicid;
  86. /* Where the IO area was mapped on multiquad, always 0 otherwise */
  87. void *xquad_portio;
  88. #ifdef CONFIG_X86_NUMAQ
  89. EXPORT_SYMBOL(xquad_portio);
  90. #endif
  91. static void __init disable_smp(void)
  92. {
  93. cpu_possible_map = cpumask_of_cpu(0);
  94. cpu_present_map = cpumask_of_cpu(0);
  95. smpboot_clear_io_apic_irqs();
  96. phys_cpu_present_map = physid_mask_of_physid(0);
  97. map_cpu_to_logical_apicid();
  98. cpu_set(0, per_cpu(cpu_sibling_map, 0));
  99. cpu_set(0, per_cpu(cpu_core_map, 0));
  100. }
  101. static int __init smp_sanity_check(unsigned max_cpus)
  102. {
  103. /*
  104. * If we couldn't find an SMP configuration at boot time,
  105. * get out of here now!
  106. */
  107. if (!smp_found_config && !acpi_lapic) {
  108. printk(KERN_NOTICE "SMP motherboard not detected.\n");
  109. disable_smp();
  110. if (APIC_init_uniprocessor())
  111. printk(KERN_NOTICE "Local APIC not detected."
  112. " Using dummy APIC emulation.\n");
  113. return -1;
  114. }
  115. /*
  116. * Should not be necessary because the MP table should list the boot
  117. * CPU too, but we do it for the sake of robustness anyway.
  118. * Makes no sense to do this check in clustered apic mode, so skip it
  119. */
  120. if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
  121. printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
  122. boot_cpu_physical_apicid);
  123. physid_set(hard_smp_processor_id(), phys_cpu_present_map);
  124. }
  125. /*
  126. * If we couldn't find a local APIC, then get out of here now!
  127. */
  128. if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && !cpu_has_apic) {
  129. printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
  130. boot_cpu_physical_apicid);
  131. printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
  132. return -1;
  133. }
  134. verify_local_APIC();
  135. /*
  136. * If SMP should be disabled, then really disable it!
  137. */
  138. if (!max_cpus) {
  139. smp_found_config = 0;
  140. printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
  141. if (nmi_watchdog == NMI_LOCAL_APIC) {
  142. printk(KERN_INFO "activating minimal APIC for NMI watchdog use.\n");
  143. connect_bsp_APIC();
  144. setup_local_APIC();
  145. end_local_APIC_setup();
  146. }
  147. return -1;
  148. }
  149. return 0;
  150. }
  151. /*
  152. * Cycle through the processors sending APIC IPIs to boot each.
  153. */
  154. static void __init smp_boot_cpus(unsigned int max_cpus)
  155. {
  156. /*
  157. * Setup boot CPU information
  158. */
  159. smp_store_cpu_info(0); /* Final full version of the data */
  160. printk(KERN_INFO "CPU%d: ", 0);
  161. print_cpu_info(&cpu_data(0));
  162. boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  163. boot_cpu_logical_apicid = logical_smp_processor_id();
  164. current_thread_info()->cpu = 0;
  165. set_cpu_sibling_map(0);
  166. if (smp_sanity_check(max_cpus) < 0) {
  167. printk(KERN_INFO "SMP disabled\n");
  168. disable_smp();
  169. return;
  170. }
  171. connect_bsp_APIC();
  172. setup_local_APIC();
  173. end_local_APIC_setup();
  174. map_cpu_to_logical_apicid();
  175. setup_portio_remap();
  176. smpboot_setup_io_apic();
  177. setup_boot_clock();
  178. }
  179. /* These are wrappers to interface to the new boot process. Someone
  180. who understands all this stuff should rewrite it properly. --RR 15/Jul/02 */
  181. void __init native_smp_prepare_cpus(unsigned int max_cpus)
  182. {
  183. nmi_watchdog_default();
  184. cpu_callin_map = cpumask_of_cpu(0);
  185. mb();
  186. smp_boot_cpus(max_cpus);
  187. }
  188. void __init native_smp_prepare_boot_cpu(void)
  189. {
  190. unsigned int cpu = smp_processor_id();
  191. init_gdt(cpu);
  192. switch_to_new_gdt();
  193. cpu_set(cpu, cpu_callout_map);
  194. __get_cpu_var(cpu_state) = CPU_ONLINE;
  195. }
  196. extern void impress_friends(void);
  197. extern void smp_checks(void);
  198. void __init native_smp_cpus_done(unsigned int max_cpus)
  199. {
  200. /*
  201. * Cleanup possible dangling ends...
  202. */
  203. smpboot_restore_warm_reset_vector();
  204. Dprintk("Boot done.\n");
  205. impress_friends();
  206. smp_checks();
  207. #ifdef CONFIG_X86_IO_APIC
  208. setup_ioapic_dest();
  209. #endif
  210. check_nmi_watchdog();
  211. zap_low_mappings();
  212. }