smpboot_64.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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. /* State of each CPU */
  65. DEFINE_PER_CPU(int, cpu_state) = { 0 };
  66. /*
  67. * Store all idle threads, this can be reused instead of creating
  68. * a new thread. Also avoids complicated thread destroy functionality
  69. * for idle threads.
  70. */
  71. #ifdef CONFIG_HOTPLUG_CPU
  72. /*
  73. * Needed only for CONFIG_HOTPLUG_CPU because __cpuinitdata is
  74. * removed after init for !CONFIG_HOTPLUG_CPU.
  75. */
  76. static DEFINE_PER_CPU(struct task_struct *, idle_thread_array);
  77. #define get_idle_for_cpu(x) (per_cpu(idle_thread_array, x))
  78. #define set_idle_for_cpu(x,p) (per_cpu(idle_thread_array, x) = (p))
  79. #else
  80. struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;
  81. #define get_idle_for_cpu(x) (idle_thread_array[(x)])
  82. #define set_idle_for_cpu(x,p) (idle_thread_array[(x)] = (p))
  83. #endif
  84. static atomic_t init_deasserted __cpuinitdata;
  85. #define smp_callin_clear_local_apic() do {} while (0)
  86. #define map_cpu_to_logical_apicid() do {} while (0)
  87. /*
  88. * Report back to the Boot Processor.
  89. * Running on AP.
  90. */
  91. void __cpuinit smp_callin(void)
  92. {
  93. int cpuid, phys_id;
  94. unsigned long timeout;
  95. /*
  96. * If waken up by an INIT in an 82489DX configuration
  97. * we may get here before an INIT-deassert IPI reaches
  98. * our local APIC. We have to wait for the IPI or we'll
  99. * lock up on an APIC access.
  100. */
  101. wait_for_init_deassert(&init_deasserted);
  102. /*
  103. * (This works even if the APIC is not enabled.)
  104. */
  105. phys_id = GET_APIC_ID(apic_read(APIC_ID));
  106. cpuid = smp_processor_id();
  107. if (cpu_isset(cpuid, cpu_callin_map)) {
  108. panic("smp_callin: phys CPU#%d, CPU#%d already present??\n",
  109. phys_id, cpuid);
  110. }
  111. Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id);
  112. /*
  113. * STARTUP IPIs are fragile beasts as they might sometimes
  114. * trigger some glue motherboard logic. Complete APIC bus
  115. * silence for 1 second, this overestimates the time the
  116. * boot CPU is spending to send the up to 2 STARTUP IPIs
  117. * by a factor of two. This should be enough.
  118. */
  119. /*
  120. * Waiting 2s total for startup (udelay is not yet working)
  121. */
  122. timeout = jiffies + 2*HZ;
  123. while (time_before(jiffies, timeout)) {
  124. /*
  125. * Has the boot CPU finished it's STARTUP sequence?
  126. */
  127. if (cpu_isset(cpuid, cpu_callout_map))
  128. break;
  129. cpu_relax();
  130. }
  131. if (!time_before(jiffies, timeout)) {
  132. panic("smp_callin: CPU%d started up but did not get a callout!\n",
  133. cpuid);
  134. }
  135. /*
  136. * the boot CPU has finished the init stage and is spinning
  137. * on callin_map until we finish. We are free to set up this
  138. * CPU, first the APIC. (this is probably redundant on most
  139. * boards)
  140. */
  141. Dprintk("CALLIN, before setup_local_APIC().\n");
  142. smp_callin_clear_local_apic();
  143. setup_local_APIC();
  144. end_local_APIC_setup();
  145. map_cpu_to_logical_apicid();
  146. /*
  147. * Get our bogomips.
  148. *
  149. * Need to enable IRQs because it can take longer and then
  150. * the NMI watchdog might kill us.
  151. */
  152. local_irq_enable();
  153. calibrate_delay();
  154. local_irq_disable();
  155. Dprintk("Stack at about %p\n",&cpuid);
  156. /*
  157. * Save our processor parameters
  158. */
  159. smp_store_cpu_info(cpuid);
  160. /*
  161. * Allow the master to continue.
  162. */
  163. cpu_set(cpuid, cpu_callin_map);
  164. }
  165. /*
  166. * Setup code on secondary processor (after comming out of the trampoline)
  167. */
  168. void __cpuinit start_secondary(void)
  169. {
  170. /*
  171. * Dont put anything before smp_callin(), SMP
  172. * booting is too fragile that we want to limit the
  173. * things done here to the most necessary things.
  174. */
  175. cpu_init();
  176. preempt_disable();
  177. smp_callin();
  178. /* otherwise gcc will move up the smp_processor_id before the cpu_init */
  179. barrier();
  180. /*
  181. * Check TSC sync first:
  182. */
  183. check_tsc_sync_target();
  184. if (nmi_watchdog == NMI_IO_APIC) {
  185. disable_8259A_irq(0);
  186. enable_NMI_through_LVT0();
  187. enable_8259A_irq(0);
  188. }
  189. /*
  190. * The sibling maps must be set before turing the online map on for
  191. * this cpu
  192. */
  193. set_cpu_sibling_map(smp_processor_id());
  194. /*
  195. * We need to hold call_lock, so there is no inconsistency
  196. * between the time smp_call_function() determines number of
  197. * IPI recipients, and the time when the determination is made
  198. * for which cpus receive the IPI in genapic_flat.c. Holding this
  199. * lock helps us to not include this cpu in a currently in progress
  200. * smp_call_function().
  201. */
  202. lock_ipi_call_lock();
  203. spin_lock(&vector_lock);
  204. /* Setup the per cpu irq handling data structures */
  205. __setup_vector_irq(smp_processor_id());
  206. /*
  207. * Allow the master to continue.
  208. */
  209. spin_unlock(&vector_lock);
  210. cpu_set(smp_processor_id(), cpu_online_map);
  211. unlock_ipi_call_lock();
  212. per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
  213. setup_secondary_clock();
  214. wmb();
  215. cpu_idle();
  216. }
  217. extern volatile unsigned long init_rsp;
  218. extern void (*initial_code)(void);
  219. #ifdef APIC_DEBUG
  220. static void __inquire_remote_apic(int apicid)
  221. {
  222. unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 };
  223. char *names[] = { "ID", "VERSION", "SPIV" };
  224. int timeout;
  225. u32 status;
  226. printk(KERN_INFO "Inquiring remote APIC #%d...\n", apicid);
  227. for (i = 0; i < ARRAY_SIZE(regs); i++) {
  228. printk(KERN_INFO "... APIC #%d %s: ", apicid, names[i]);
  229. /*
  230. * Wait for idle.
  231. */
  232. status = safe_apic_wait_icr_idle();
  233. if (status)
  234. printk(KERN_CONT
  235. "a previous APIC delivery may have failed\n");
  236. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
  237. apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]);
  238. timeout = 0;
  239. do {
  240. udelay(100);
  241. status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK;
  242. } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000);
  243. switch (status) {
  244. case APIC_ICR_RR_VALID:
  245. status = apic_read(APIC_RRR);
  246. printk(KERN_CONT "%08x\n", status);
  247. break;
  248. default:
  249. printk(KERN_CONT "failed\n");
  250. }
  251. }
  252. }
  253. #endif
  254. /*
  255. * Kick the secondary to wake up.
  256. */
  257. static int __cpuinit wakeup_secondary_cpu(int phys_apicid,
  258. unsigned int start_rip)
  259. {
  260. unsigned long send_status, accept_status = 0;
  261. int maxlvt, num_starts, j;
  262. /*
  263. * Be paranoid about clearing APIC errors.
  264. */
  265. if (APIC_INTEGRATED(apic_version[phys_apicid])) {
  266. apic_read_around(APIC_SPIV);
  267. apic_write(APIC_ESR, 0);
  268. apic_read(APIC_ESR);
  269. }
  270. Dprintk("Asserting INIT.\n");
  271. /*
  272. * Turn INIT on target chip
  273. */
  274. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  275. /*
  276. * Send IPI
  277. */
  278. apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
  279. | APIC_DM_INIT);
  280. Dprintk("Waiting for send to finish...\n");
  281. send_status = safe_apic_wait_icr_idle();
  282. mdelay(10);
  283. Dprintk("Deasserting INIT.\n");
  284. /* Target chip */
  285. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  286. /* Send IPI */
  287. apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
  288. Dprintk("Waiting for send to finish...\n");
  289. send_status = safe_apic_wait_icr_idle();
  290. mb();
  291. atomic_set(&init_deasserted, 1);
  292. if (APIC_INTEGRATED(apic_version[phys_apicid]))
  293. num_starts = 2;
  294. else
  295. num_starts = 0;
  296. /*
  297. * Paravirt / VMI wants a startup IPI hook here to set up the
  298. * target processor state.
  299. */
  300. startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
  301. (unsigned long) init_rsp);
  302. /*
  303. * Run STARTUP IPI loop.
  304. */
  305. Dprintk("#startup loops: %d.\n", num_starts);
  306. maxlvt = lapic_get_maxlvt();
  307. for (j = 1; j <= num_starts; j++) {
  308. Dprintk("Sending STARTUP #%d.\n",j);
  309. apic_read_around(APIC_SPIV);
  310. apic_write(APIC_ESR, 0);
  311. apic_read(APIC_ESR);
  312. Dprintk("After apic_write.\n");
  313. /*
  314. * STARTUP IPI
  315. */
  316. /* Target chip */
  317. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  318. /* Boot on the stack */
  319. /* Kick the second */
  320. apic_write_around(APIC_ICR, APIC_DM_STARTUP | (start_rip>>12));
  321. /*
  322. * Give the other CPU some time to accept the IPI.
  323. */
  324. udelay(300);
  325. Dprintk("Startup point 1.\n");
  326. Dprintk("Waiting for send to finish...\n");
  327. send_status = safe_apic_wait_icr_idle();
  328. /*
  329. * Give the other CPU some time to accept the IPI.
  330. */
  331. udelay(200);
  332. /*
  333. * Due to the Pentium erratum 3AP.
  334. */
  335. if (maxlvt > 3) {
  336. apic_read_around(APIC_SPIV);
  337. apic_write(APIC_ESR, 0);
  338. }
  339. accept_status = (apic_read(APIC_ESR) & 0xEF);
  340. if (send_status || accept_status)
  341. break;
  342. }
  343. Dprintk("After Startup.\n");
  344. if (send_status)
  345. printk(KERN_ERR "APIC never delivered???\n");
  346. if (accept_status)
  347. printk(KERN_ERR "APIC delivery error (%lx).\n", accept_status);
  348. return (send_status | accept_status);
  349. }
  350. struct create_idle {
  351. struct work_struct work;
  352. struct task_struct *idle;
  353. struct completion done;
  354. int cpu;
  355. };
  356. static void __cpuinit do_fork_idle(struct work_struct *work)
  357. {
  358. struct create_idle *c_idle =
  359. container_of(work, struct create_idle, work);
  360. c_idle->idle = fork_idle(c_idle->cpu);
  361. complete(&c_idle->done);
  362. }
  363. /*
  364. * Boot one CPU.
  365. */
  366. static int __cpuinit do_boot_cpu(int cpu, int apicid)
  367. {
  368. unsigned long boot_error = 0;
  369. int timeout;
  370. unsigned long start_rip;
  371. struct create_idle c_idle = {
  372. .cpu = cpu,
  373. .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
  374. };
  375. INIT_WORK(&c_idle.work, do_fork_idle);
  376. /* allocate memory for gdts of secondary cpus. Hotplug is considered */
  377. if (!cpu_gdt_descr[cpu].address &&
  378. !(cpu_gdt_descr[cpu].address = get_zeroed_page(GFP_KERNEL))) {
  379. printk(KERN_ERR "Failed to allocate GDT for CPU %d\n", cpu);
  380. return -1;
  381. }
  382. /* Allocate node local memory for AP pdas */
  383. if (cpu_pda(cpu) == &boot_cpu_pda[cpu]) {
  384. struct x8664_pda *newpda, *pda;
  385. int node = cpu_to_node(cpu);
  386. pda = cpu_pda(cpu);
  387. newpda = kmalloc_node(sizeof (struct x8664_pda), GFP_ATOMIC,
  388. node);
  389. if (newpda) {
  390. memcpy(newpda, pda, sizeof (struct x8664_pda));
  391. cpu_pda(cpu) = newpda;
  392. } else
  393. printk(KERN_ERR
  394. "Could not allocate node local PDA for CPU %d on node %d\n",
  395. cpu, node);
  396. }
  397. alternatives_smp_switch(1);
  398. c_idle.idle = get_idle_for_cpu(cpu);
  399. if (c_idle.idle) {
  400. c_idle.idle->thread.sp = (unsigned long) (((struct pt_regs *)
  401. (THREAD_SIZE + task_stack_page(c_idle.idle))) - 1);
  402. init_idle(c_idle.idle, cpu);
  403. goto do_rest;
  404. }
  405. /*
  406. * During cold boot process, keventd thread is not spun up yet.
  407. * When we do cpu hot-add, we create idle threads on the fly, we should
  408. * not acquire any attributes from the calling context. Hence the clean
  409. * way to create kernel_threads() is to do that from keventd().
  410. * We do the current_is_keventd() due to the fact that ACPI notifier
  411. * was also queuing to keventd() and when the caller is already running
  412. * in context of keventd(), we would end up with locking up the keventd
  413. * thread.
  414. */
  415. if (!keventd_up() || current_is_keventd())
  416. c_idle.work.func(&c_idle.work);
  417. else {
  418. schedule_work(&c_idle.work);
  419. wait_for_completion(&c_idle.done);
  420. }
  421. if (IS_ERR(c_idle.idle)) {
  422. printk("failed fork for CPU %d\n", cpu);
  423. return PTR_ERR(c_idle.idle);
  424. }
  425. set_idle_for_cpu(cpu, c_idle.idle);
  426. do_rest:
  427. cpu_pda(cpu)->pcurrent = c_idle.idle;
  428. start_rip = setup_trampoline();
  429. init_rsp = c_idle.idle->thread.sp;
  430. load_sp0(&per_cpu(init_tss, cpu), &c_idle.idle->thread);
  431. initial_code = start_secondary;
  432. clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
  433. printk(KERN_INFO "Booting processor %d/%d APIC 0x%x\n", cpu,
  434. cpus_weight(cpu_present_map),
  435. apicid);
  436. /*
  437. * This grunge runs the startup process for
  438. * the targeted processor.
  439. */
  440. atomic_set(&init_deasserted, 0);
  441. Dprintk("Setting warm reset code and vector.\n");
  442. smpboot_setup_warm_reset_vector(start_rip);
  443. /*
  444. * Be paranoid about clearing APIC errors.
  445. */
  446. apic_write(APIC_ESR, 0);
  447. apic_read(APIC_ESR);
  448. /*
  449. * Starting actual IPI sequence...
  450. */
  451. boot_error = wakeup_secondary_cpu(apicid, start_rip);
  452. if (!boot_error) {
  453. /*
  454. * allow APs to start initializing.
  455. */
  456. Dprintk("Before Callout %d.\n", cpu);
  457. cpu_set(cpu, cpu_callout_map);
  458. Dprintk("After Callout %d.\n", cpu);
  459. /*
  460. * Wait 5s total for a response
  461. */
  462. for (timeout = 0; timeout < 50000; timeout++) {
  463. if (cpu_isset(cpu, cpu_callin_map))
  464. break; /* It has booted */
  465. udelay(100);
  466. }
  467. if (cpu_isset(cpu, cpu_callin_map)) {
  468. /* number CPUs logically, starting from 1 (BSP is 0) */
  469. Dprintk("CPU has booted.\n");
  470. printk(KERN_INFO "CPU%d: ", cpu);
  471. print_cpu_info(&cpu_data(cpu));
  472. } else {
  473. boot_error = 1;
  474. if (*((volatile unsigned char *)trampoline_base)
  475. == 0xA5)
  476. /* trampoline started but...? */
  477. printk("Stuck ??\n");
  478. else
  479. /* trampoline code not run */
  480. printk("Not responding.\n");
  481. #ifdef APIC_DEBUG
  482. inquire_remote_apic(apicid);
  483. #endif
  484. }
  485. }
  486. if (boot_error) {
  487. cpu_clear(cpu, cpu_callout_map); /* was set here (do_boot_cpu()) */
  488. clear_bit(cpu, (unsigned long *)&cpu_initialized); /* was set by cpu_init() */
  489. clear_node_cpumask(cpu); /* was set by numa_add_cpu */
  490. cpu_clear(cpu, cpu_present_map);
  491. cpu_clear(cpu, cpu_possible_map);
  492. per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID;
  493. }
  494. /* mark "stuck" area as not stuck */
  495. *((volatile unsigned long *)trampoline_base) = 0;
  496. return boot_error;
  497. }
  498. cycles_t cacheflush_time;
  499. unsigned long cache_decay_ticks;
  500. /*
  501. * Fall back to non SMP mode after errors.
  502. *
  503. * RED-PEN audit/test this more. I bet there is more state messed up here.
  504. */
  505. static __init void disable_smp(void)
  506. {
  507. cpu_present_map = cpumask_of_cpu(0);
  508. cpu_possible_map = cpumask_of_cpu(0);
  509. if (smp_found_config)
  510. phys_cpu_present_map = physid_mask_of_physid(boot_cpu_id);
  511. else
  512. phys_cpu_present_map = physid_mask_of_physid(0);
  513. cpu_set(0, per_cpu(cpu_sibling_map, 0));
  514. cpu_set(0, per_cpu(cpu_core_map, 0));
  515. }
  516. /*
  517. * Various sanity checks.
  518. */
  519. static int __init smp_sanity_check(unsigned max_cpus)
  520. {
  521. if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
  522. printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
  523. hard_smp_processor_id());
  524. physid_set(hard_smp_processor_id(), phys_cpu_present_map);
  525. }
  526. /*
  527. * If we couldn't find an SMP configuration at boot time,
  528. * get out of here now!
  529. */
  530. if (!smp_found_config) {
  531. printk(KERN_NOTICE "SMP motherboard not detected.\n");
  532. disable_smp();
  533. if (APIC_init_uniprocessor())
  534. printk(KERN_NOTICE "Local APIC not detected."
  535. " Using dummy APIC emulation.\n");
  536. return -1;
  537. }
  538. /*
  539. * Should not be necessary because the MP table should list the boot
  540. * CPU too, but we do it for the sake of robustness anyway.
  541. */
  542. if (!physid_isset(boot_cpu_id, phys_cpu_present_map)) {
  543. printk(KERN_NOTICE "weird, boot CPU (#%d) not listed by the BIOS.\n",
  544. boot_cpu_id);
  545. physid_set(hard_smp_processor_id(), phys_cpu_present_map);
  546. }
  547. /*
  548. * If we couldn't find a local APIC, then get out of here now!
  549. */
  550. if (!cpu_has_apic) {
  551. printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
  552. boot_cpu_id);
  553. printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
  554. nr_ioapics = 0;
  555. return -1;
  556. }
  557. /*
  558. * If SMP should be disabled, then really disable it!
  559. */
  560. if (!max_cpus) {
  561. printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
  562. nr_ioapics = 0;
  563. return -1;
  564. }
  565. return 0;
  566. }
  567. static void __init smp_cpu_index_default(void)
  568. {
  569. int i;
  570. struct cpuinfo_x86 *c;
  571. for_each_cpu_mask(i, cpu_possible_map) {
  572. c = &cpu_data(i);
  573. /* mark all to hotplug */
  574. c->cpu_index = NR_CPUS;
  575. }
  576. }
  577. /*
  578. * Prepare for SMP bootup. The MP table or ACPI has been read
  579. * earlier. Just do some sanity checking here and enable APIC mode.
  580. */
  581. void __init native_smp_prepare_cpus(unsigned int max_cpus)
  582. {
  583. nmi_watchdog_default();
  584. smp_cpu_index_default();
  585. current_cpu_data = boot_cpu_data;
  586. current_thread_info()->cpu = 0; /* needed? */
  587. set_cpu_sibling_map(0);
  588. if (smp_sanity_check(max_cpus) < 0) {
  589. printk(KERN_INFO "SMP disabled\n");
  590. disable_smp();
  591. return;
  592. }
  593. /*
  594. * Switch from PIC to APIC mode.
  595. */
  596. setup_local_APIC();
  597. /*
  598. * Enable IO APIC before setting up error vector
  599. */
  600. if (!skip_ioapic_setup && nr_ioapics)
  601. enable_IO_APIC();
  602. end_local_APIC_setup();
  603. if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_id) {
  604. panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
  605. GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_id);
  606. /* Or can we switch back to PIC here? */
  607. }
  608. /*
  609. * Now start the IO-APICs
  610. */
  611. if (!skip_ioapic_setup && nr_ioapics)
  612. setup_IO_APIC();
  613. else
  614. nr_ioapics = 0;
  615. /*
  616. * Set up local APIC timer on boot CPU.
  617. */
  618. setup_boot_clock();
  619. printk(KERN_INFO "CPU%d: ", 0);
  620. print_cpu_info(&cpu_data(0));
  621. }
  622. /*
  623. * Early setup to make printk work.
  624. */
  625. void __init native_smp_prepare_boot_cpu(void)
  626. {
  627. int me = smp_processor_id();
  628. /* already set me in cpu_online_map in boot_cpu_init() */
  629. cpu_set(me, cpu_callout_map);
  630. per_cpu(cpu_state, me) = CPU_ONLINE;
  631. }
  632. /*
  633. * Entry point to boot a CPU.
  634. */
  635. int __cpuinit native_cpu_up(unsigned int cpu)
  636. {
  637. int apicid = cpu_present_to_apicid(cpu);
  638. unsigned long flags;
  639. int err;
  640. WARN_ON(irqs_disabled());
  641. Dprintk("++++++++++++++++++++=_---CPU UP %u\n", cpu);
  642. if (apicid == BAD_APICID || apicid == boot_cpu_id ||
  643. !physid_isset(apicid, phys_cpu_present_map)) {
  644. printk("__cpu_up: bad cpu %d\n", cpu);
  645. return -EINVAL;
  646. }
  647. /*
  648. * Already booted CPU?
  649. */
  650. if (cpu_isset(cpu, cpu_callin_map)) {
  651. Dprintk("do_boot_cpu %d Already started\n", cpu);
  652. return -ENOSYS;
  653. }
  654. /*
  655. * Save current MTRR state in case it was changed since early boot
  656. * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync:
  657. */
  658. mtrr_save_state();
  659. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  660. /* Boot it! */
  661. err = do_boot_cpu(cpu, apicid);
  662. if (err < 0) {
  663. Dprintk("do_boot_cpu failed %d\n", err);
  664. return err;
  665. }
  666. /* Unleash the CPU! */
  667. Dprintk("waiting for cpu %d\n", cpu);
  668. /*
  669. * Make sure and check TSC sync:
  670. */
  671. local_irq_save(flags);
  672. check_tsc_sync_source(cpu);
  673. local_irq_restore(flags);
  674. while (!cpu_isset(cpu, cpu_online_map))
  675. cpu_relax();
  676. err = 0;
  677. return err;
  678. }
  679. extern void impress_friends(void);
  680. extern void smp_checks(void);
  681. /*
  682. * Finish the SMP boot.
  683. */
  684. void __init native_smp_cpus_done(unsigned int max_cpus)
  685. {
  686. smpboot_restore_warm_reset_vector();
  687. Dprintk("Boot done.\n");
  688. impress_friends();
  689. smp_checks();
  690. setup_ioapic_dest();
  691. check_nmi_watchdog();
  692. }