smpboot.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362
  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/smp_lock.h>
  42. #include <linux/bootmem.h>
  43. #include <linux/notifier.h>
  44. #include <linux/cpu.h>
  45. #include <linux/percpu.h>
  46. #include <linux/nmi.h>
  47. #include <linux/delay.h>
  48. #include <linux/mc146818rtc.h>
  49. #include <asm/tlbflush.h>
  50. #include <asm/desc.h>
  51. #include <asm/arch_hooks.h>
  52. #include <asm/nmi.h>
  53. #include <mach_apic.h>
  54. #include <mach_wakecpu.h>
  55. #include <smpboot_hooks.h>
  56. #include <asm/vmi.h>
  57. #include <asm/mtrr.h>
  58. /* Set if we find a B stepping CPU */
  59. static int __devinitdata smp_b_stepping;
  60. /* Number of siblings per CPU package */
  61. int smp_num_siblings = 1;
  62. EXPORT_SYMBOL(smp_num_siblings);
  63. /* Last level cache ID of each logical CPU */
  64. int cpu_llc_id[NR_CPUS] __cpuinitdata = {[0 ... NR_CPUS-1] = BAD_APICID};
  65. /* representing HT siblings of each logical CPU */
  66. cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly;
  67. EXPORT_SYMBOL(cpu_sibling_map);
  68. /* representing HT and core siblings of each logical CPU */
  69. cpumask_t cpu_core_map[NR_CPUS] __read_mostly;
  70. EXPORT_SYMBOL(cpu_core_map);
  71. /* bitmap of online cpus */
  72. cpumask_t cpu_online_map __read_mostly;
  73. EXPORT_SYMBOL(cpu_online_map);
  74. cpumask_t cpu_callin_map;
  75. cpumask_t cpu_callout_map;
  76. EXPORT_SYMBOL(cpu_callout_map);
  77. cpumask_t cpu_possible_map;
  78. EXPORT_SYMBOL(cpu_possible_map);
  79. static cpumask_t smp_commenced_mask;
  80. /* Per CPU bogomips and other parameters */
  81. struct cpuinfo_x86 cpu_data[NR_CPUS] __cacheline_aligned;
  82. EXPORT_SYMBOL(cpu_data);
  83. u8 x86_cpu_to_apicid[NR_CPUS] __read_mostly =
  84. { [0 ... NR_CPUS-1] = 0xff };
  85. EXPORT_SYMBOL(x86_cpu_to_apicid);
  86. u8 apicid_2_node[MAX_APICID];
  87. DEFINE_PER_CPU(unsigned long, this_cpu_off);
  88. EXPORT_PER_CPU_SYMBOL(this_cpu_off);
  89. /*
  90. * Trampoline 80x86 program as an array.
  91. */
  92. extern unsigned char trampoline_data [];
  93. extern unsigned char trampoline_end [];
  94. static unsigned char *trampoline_base;
  95. static int trampoline_exec;
  96. static void map_cpu_to_logical_apicid(void);
  97. /* State of each CPU. */
  98. DEFINE_PER_CPU(int, cpu_state) = { 0 };
  99. /*
  100. * Currently trivial. Write the real->protected mode
  101. * bootstrap into the page concerned. The caller
  102. * has made sure it's suitably aligned.
  103. */
  104. static unsigned long __devinit setup_trampoline(void)
  105. {
  106. memcpy(trampoline_base, trampoline_data, trampoline_end - trampoline_data);
  107. return virt_to_phys(trampoline_base);
  108. }
  109. /*
  110. * We are called very early to get the low memory for the
  111. * SMP bootup trampoline page.
  112. */
  113. void __init smp_alloc_memory(void)
  114. {
  115. trampoline_base = (void *) alloc_bootmem_low_pages(PAGE_SIZE);
  116. /*
  117. * Has to be in very low memory so we can execute
  118. * real-mode AP code.
  119. */
  120. if (__pa(trampoline_base) >= 0x9F000)
  121. BUG();
  122. /*
  123. * Make the SMP trampoline executable:
  124. */
  125. trampoline_exec = set_kernel_exec((unsigned long)trampoline_base, 1);
  126. }
  127. /*
  128. * The bootstrap kernel entry code has set these up. Save them for
  129. * a given CPU
  130. */
  131. static void __cpuinit smp_store_cpu_info(int id)
  132. {
  133. struct cpuinfo_x86 *c = cpu_data + id;
  134. *c = boot_cpu_data;
  135. if (id!=0)
  136. identify_secondary_cpu(c);
  137. /*
  138. * Mask B, Pentium, but not Pentium MMX
  139. */
  140. if (c->x86_vendor == X86_VENDOR_INTEL &&
  141. c->x86 == 5 &&
  142. c->x86_mask >= 1 && c->x86_mask <= 4 &&
  143. c->x86_model <= 3)
  144. /*
  145. * Remember we have B step Pentia with bugs
  146. */
  147. smp_b_stepping = 1;
  148. /*
  149. * Certain Athlons might work (for various values of 'work') in SMP
  150. * but they are not certified as MP capable.
  151. */
  152. if ((c->x86_vendor == X86_VENDOR_AMD) && (c->x86 == 6)) {
  153. if (num_possible_cpus() == 1)
  154. goto valid_k7;
  155. /* Athlon 660/661 is valid. */
  156. if ((c->x86_model==6) && ((c->x86_mask==0) || (c->x86_mask==1)))
  157. goto valid_k7;
  158. /* Duron 670 is valid */
  159. if ((c->x86_model==7) && (c->x86_mask==0))
  160. goto valid_k7;
  161. /*
  162. * Athlon 662, Duron 671, and Athlon >model 7 have capability bit.
  163. * It's worth noting that the A5 stepping (662) of some Athlon XP's
  164. * have the MP bit set.
  165. * See http://www.heise.de/newsticker/data/jow-18.10.01-000 for more.
  166. */
  167. if (((c->x86_model==6) && (c->x86_mask>=2)) ||
  168. ((c->x86_model==7) && (c->x86_mask>=1)) ||
  169. (c->x86_model> 7))
  170. if (cpu_has_mp)
  171. goto valid_k7;
  172. /* If we get here, it's not a certified SMP capable AMD system. */
  173. add_taint(TAINT_UNSAFE_SMP);
  174. }
  175. valid_k7:
  176. ;
  177. }
  178. extern void calibrate_delay(void);
  179. static atomic_t init_deasserted;
  180. static void __cpuinit smp_callin(void)
  181. {
  182. int cpuid, phys_id;
  183. unsigned long timeout;
  184. /*
  185. * If waken up by an INIT in an 82489DX configuration
  186. * we may get here before an INIT-deassert IPI reaches
  187. * our local APIC. We have to wait for the IPI or we'll
  188. * lock up on an APIC access.
  189. */
  190. wait_for_init_deassert(&init_deasserted);
  191. /*
  192. * (This works even if the APIC is not enabled.)
  193. */
  194. phys_id = GET_APIC_ID(apic_read(APIC_ID));
  195. cpuid = smp_processor_id();
  196. if (cpu_isset(cpuid, cpu_callin_map)) {
  197. printk("huh, phys CPU#%d, CPU#%d already present??\n",
  198. phys_id, cpuid);
  199. BUG();
  200. }
  201. Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id);
  202. /*
  203. * STARTUP IPIs are fragile beasts as they might sometimes
  204. * trigger some glue motherboard logic. Complete APIC bus
  205. * silence for 1 second, this overestimates the time the
  206. * boot CPU is spending to send the up to 2 STARTUP IPIs
  207. * by a factor of two. This should be enough.
  208. */
  209. /*
  210. * Waiting 2s total for startup (udelay is not yet working)
  211. */
  212. timeout = jiffies + 2*HZ;
  213. while (time_before(jiffies, timeout)) {
  214. /*
  215. * Has the boot CPU finished it's STARTUP sequence?
  216. */
  217. if (cpu_isset(cpuid, cpu_callout_map))
  218. break;
  219. rep_nop();
  220. }
  221. if (!time_before(jiffies, timeout)) {
  222. printk("BUG: CPU%d started up but did not get a callout!\n",
  223. cpuid);
  224. BUG();
  225. }
  226. /*
  227. * the boot CPU has finished the init stage and is spinning
  228. * on callin_map until we finish. We are free to set up this
  229. * CPU, first the APIC. (this is probably redundant on most
  230. * boards)
  231. */
  232. Dprintk("CALLIN, before setup_local_APIC().\n");
  233. smp_callin_clear_local_apic();
  234. setup_local_APIC();
  235. map_cpu_to_logical_apicid();
  236. /*
  237. * Get our bogomips.
  238. */
  239. calibrate_delay();
  240. Dprintk("Stack at about %p\n",&cpuid);
  241. /*
  242. * Save our processor parameters
  243. */
  244. smp_store_cpu_info(cpuid);
  245. /*
  246. * Allow the master to continue.
  247. */
  248. cpu_set(cpuid, cpu_callin_map);
  249. }
  250. static int cpucount;
  251. /* maps the cpu to the sched domain representing multi-core */
  252. cpumask_t cpu_coregroup_map(int cpu)
  253. {
  254. struct cpuinfo_x86 *c = cpu_data + cpu;
  255. /*
  256. * For perf, we return last level cache shared map.
  257. * And for power savings, we return cpu_core_map
  258. */
  259. if (sched_mc_power_savings || sched_smt_power_savings)
  260. return cpu_core_map[cpu];
  261. else
  262. return c->llc_shared_map;
  263. }
  264. /* representing cpus for which sibling maps can be computed */
  265. static cpumask_t cpu_sibling_setup_map;
  266. static inline void
  267. set_cpu_sibling_map(int cpu)
  268. {
  269. int i;
  270. struct cpuinfo_x86 *c = cpu_data;
  271. cpu_set(cpu, cpu_sibling_setup_map);
  272. if (smp_num_siblings > 1) {
  273. for_each_cpu_mask(i, cpu_sibling_setup_map) {
  274. if (c[cpu].phys_proc_id == c[i].phys_proc_id &&
  275. c[cpu].cpu_core_id == c[i].cpu_core_id) {
  276. cpu_set(i, cpu_sibling_map[cpu]);
  277. cpu_set(cpu, cpu_sibling_map[i]);
  278. cpu_set(i, cpu_core_map[cpu]);
  279. cpu_set(cpu, cpu_core_map[i]);
  280. cpu_set(i, c[cpu].llc_shared_map);
  281. cpu_set(cpu, c[i].llc_shared_map);
  282. }
  283. }
  284. } else {
  285. cpu_set(cpu, cpu_sibling_map[cpu]);
  286. }
  287. cpu_set(cpu, c[cpu].llc_shared_map);
  288. if (current_cpu_data.x86_max_cores == 1) {
  289. cpu_core_map[cpu] = cpu_sibling_map[cpu];
  290. c[cpu].booted_cores = 1;
  291. return;
  292. }
  293. for_each_cpu_mask(i, cpu_sibling_setup_map) {
  294. if (cpu_llc_id[cpu] != BAD_APICID &&
  295. cpu_llc_id[cpu] == cpu_llc_id[i]) {
  296. cpu_set(i, c[cpu].llc_shared_map);
  297. cpu_set(cpu, c[i].llc_shared_map);
  298. }
  299. if (c[cpu].phys_proc_id == c[i].phys_proc_id) {
  300. cpu_set(i, cpu_core_map[cpu]);
  301. cpu_set(cpu, cpu_core_map[i]);
  302. /*
  303. * Does this new cpu bringup a new core?
  304. */
  305. if (cpus_weight(cpu_sibling_map[cpu]) == 1) {
  306. /*
  307. * for each core in package, increment
  308. * the booted_cores for this new cpu
  309. */
  310. if (first_cpu(cpu_sibling_map[i]) == i)
  311. c[cpu].booted_cores++;
  312. /*
  313. * increment the core count for all
  314. * the other cpus in this package
  315. */
  316. if (i != cpu)
  317. c[i].booted_cores++;
  318. } else if (i != cpu && !c[cpu].booted_cores)
  319. c[cpu].booted_cores = c[i].booted_cores;
  320. }
  321. }
  322. }
  323. /*
  324. * Activate a secondary processor.
  325. */
  326. static void __cpuinit start_secondary(void *unused)
  327. {
  328. /*
  329. * Don't put *anything* before cpu_init(), SMP booting is too
  330. * fragile that we want to limit the things done here to the
  331. * most necessary things.
  332. */
  333. #ifdef CONFIG_VMI
  334. vmi_bringup();
  335. #endif
  336. cpu_init();
  337. preempt_disable();
  338. smp_callin();
  339. while (!cpu_isset(smp_processor_id(), smp_commenced_mask))
  340. rep_nop();
  341. /*
  342. * Check TSC synchronization with the BP:
  343. */
  344. check_tsc_sync_target();
  345. setup_secondary_clock();
  346. if (nmi_watchdog == NMI_IO_APIC) {
  347. disable_8259A_irq(0);
  348. enable_NMI_through_LVT0(NULL);
  349. enable_8259A_irq(0);
  350. }
  351. /*
  352. * low-memory mappings have been cleared, flush them from
  353. * the local TLBs too.
  354. */
  355. local_flush_tlb();
  356. /* This must be done before setting cpu_online_map */
  357. set_cpu_sibling_map(raw_smp_processor_id());
  358. wmb();
  359. /*
  360. * We need to hold call_lock, so there is no inconsistency
  361. * between the time smp_call_function() determines number of
  362. * IPI receipients, and the time when the determination is made
  363. * for which cpus receive the IPI. Holding this
  364. * lock helps us to not include this cpu in a currently in progress
  365. * smp_call_function().
  366. */
  367. lock_ipi_call_lock();
  368. cpu_set(smp_processor_id(), cpu_online_map);
  369. unlock_ipi_call_lock();
  370. per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
  371. /* We can take interrupts now: we're officially "up". */
  372. local_irq_enable();
  373. wmb();
  374. cpu_idle();
  375. }
  376. /*
  377. * Everything has been set up for the secondary
  378. * CPUs - they just need to reload everything
  379. * from the task structure
  380. * This function must not return.
  381. */
  382. void __devinit initialize_secondary(void)
  383. {
  384. /*
  385. * We don't actually need to load the full TSS,
  386. * basically just the stack pointer and the eip.
  387. */
  388. asm volatile(
  389. "movl %0,%%esp\n\t"
  390. "jmp *%1"
  391. :
  392. :"m" (current->thread.esp),"m" (current->thread.eip));
  393. }
  394. /* Static state in head.S used to set up a CPU */
  395. extern struct {
  396. void * esp;
  397. unsigned short ss;
  398. } stack_start;
  399. #ifdef CONFIG_NUMA
  400. /* which logical CPUs are on which nodes */
  401. cpumask_t node_2_cpu_mask[MAX_NUMNODES] __read_mostly =
  402. { [0 ... MAX_NUMNODES-1] = CPU_MASK_NONE };
  403. EXPORT_SYMBOL(node_2_cpu_mask);
  404. /* which node each logical CPU is on */
  405. int cpu_2_node[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = 0 };
  406. EXPORT_SYMBOL(cpu_2_node);
  407. /* set up a mapping between cpu and node. */
  408. static inline void map_cpu_to_node(int cpu, int node)
  409. {
  410. printk("Mapping cpu %d to node %d\n", cpu, node);
  411. cpu_set(cpu, node_2_cpu_mask[node]);
  412. cpu_2_node[cpu] = node;
  413. }
  414. /* undo a mapping between cpu and node. */
  415. static inline void unmap_cpu_to_node(int cpu)
  416. {
  417. int node;
  418. printk("Unmapping cpu %d from all nodes\n", cpu);
  419. for (node = 0; node < MAX_NUMNODES; node ++)
  420. cpu_clear(cpu, node_2_cpu_mask[node]);
  421. cpu_2_node[cpu] = 0;
  422. }
  423. #else /* !CONFIG_NUMA */
  424. #define map_cpu_to_node(cpu, node) ({})
  425. #define unmap_cpu_to_node(cpu) ({})
  426. #endif /* CONFIG_NUMA */
  427. u8 cpu_2_logical_apicid[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID };
  428. static void map_cpu_to_logical_apicid(void)
  429. {
  430. int cpu = smp_processor_id();
  431. int apicid = logical_smp_processor_id();
  432. int node = apicid_to_node(apicid);
  433. if (!node_online(node))
  434. node = first_online_node;
  435. cpu_2_logical_apicid[cpu] = apicid;
  436. map_cpu_to_node(cpu, node);
  437. }
  438. static void unmap_cpu_to_logical_apicid(int cpu)
  439. {
  440. cpu_2_logical_apicid[cpu] = BAD_APICID;
  441. unmap_cpu_to_node(cpu);
  442. }
  443. #if APIC_DEBUG
  444. static inline void __inquire_remote_apic(int apicid)
  445. {
  446. int i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 };
  447. char *names[] = { "ID", "VERSION", "SPIV" };
  448. int timeout;
  449. unsigned long status;
  450. printk("Inquiring remote APIC #%d...\n", apicid);
  451. for (i = 0; i < ARRAY_SIZE(regs); i++) {
  452. printk("... APIC #%d %s: ", apicid, names[i]);
  453. /*
  454. * Wait for idle.
  455. */
  456. status = safe_apic_wait_icr_idle();
  457. if (status)
  458. printk("a previous APIC delivery may have failed\n");
  459. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
  460. apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]);
  461. timeout = 0;
  462. do {
  463. udelay(100);
  464. status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK;
  465. } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000);
  466. switch (status) {
  467. case APIC_ICR_RR_VALID:
  468. status = apic_read(APIC_RRR);
  469. printk("%08x\n", status);
  470. break;
  471. default:
  472. printk("failed\n");
  473. }
  474. }
  475. }
  476. #endif
  477. #ifdef WAKE_SECONDARY_VIA_NMI
  478. /*
  479. * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal
  480. * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this
  481. * won't ... remember to clear down the APIC, etc later.
  482. */
  483. static int __devinit
  484. wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
  485. {
  486. unsigned long send_status, accept_status = 0;
  487. int maxlvt;
  488. /* Target chip */
  489. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(logical_apicid));
  490. /* Boot on the stack */
  491. /* Kick the second */
  492. apic_write_around(APIC_ICR, APIC_DM_NMI | APIC_DEST_LOGICAL);
  493. Dprintk("Waiting for send to finish...\n");
  494. send_status = safe_apic_wait_icr_idle();
  495. /*
  496. * Give the other CPU some time to accept the IPI.
  497. */
  498. udelay(200);
  499. /*
  500. * Due to the Pentium erratum 3AP.
  501. */
  502. maxlvt = lapic_get_maxlvt();
  503. if (maxlvt > 3) {
  504. apic_read_around(APIC_SPIV);
  505. apic_write(APIC_ESR, 0);
  506. }
  507. accept_status = (apic_read(APIC_ESR) & 0xEF);
  508. Dprintk("NMI sent.\n");
  509. if (send_status)
  510. printk("APIC never delivered???\n");
  511. if (accept_status)
  512. printk("APIC delivery error (%lx).\n", accept_status);
  513. return (send_status | accept_status);
  514. }
  515. #endif /* WAKE_SECONDARY_VIA_NMI */
  516. #ifdef WAKE_SECONDARY_VIA_INIT
  517. static int __devinit
  518. wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
  519. {
  520. unsigned long send_status, accept_status = 0;
  521. int maxlvt, num_starts, j;
  522. /*
  523. * Be paranoid about clearing APIC errors.
  524. */
  525. if (APIC_INTEGRATED(apic_version[phys_apicid])) {
  526. apic_read_around(APIC_SPIV);
  527. apic_write(APIC_ESR, 0);
  528. apic_read(APIC_ESR);
  529. }
  530. Dprintk("Asserting INIT.\n");
  531. /*
  532. * Turn INIT on target chip
  533. */
  534. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  535. /*
  536. * Send IPI
  537. */
  538. apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
  539. | APIC_DM_INIT);
  540. Dprintk("Waiting for send to finish...\n");
  541. send_status = safe_apic_wait_icr_idle();
  542. mdelay(10);
  543. Dprintk("Deasserting INIT.\n");
  544. /* Target chip */
  545. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  546. /* Send IPI */
  547. apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
  548. Dprintk("Waiting for send to finish...\n");
  549. send_status = safe_apic_wait_icr_idle();
  550. atomic_set(&init_deasserted, 1);
  551. /*
  552. * Should we send STARTUP IPIs ?
  553. *
  554. * Determine this based on the APIC version.
  555. * If we don't have an integrated APIC, don't send the STARTUP IPIs.
  556. */
  557. if (APIC_INTEGRATED(apic_version[phys_apicid]))
  558. num_starts = 2;
  559. else
  560. num_starts = 0;
  561. /*
  562. * Paravirt / VMI wants a startup IPI hook here to set up the
  563. * target processor state.
  564. */
  565. startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
  566. (unsigned long) stack_start.esp);
  567. /*
  568. * Run STARTUP IPI loop.
  569. */
  570. Dprintk("#startup loops: %d.\n", num_starts);
  571. maxlvt = lapic_get_maxlvt();
  572. for (j = 1; j <= num_starts; j++) {
  573. Dprintk("Sending STARTUP #%d.\n",j);
  574. apic_read_around(APIC_SPIV);
  575. apic_write(APIC_ESR, 0);
  576. apic_read(APIC_ESR);
  577. Dprintk("After apic_write.\n");
  578. /*
  579. * STARTUP IPI
  580. */
  581. /* Target chip */
  582. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  583. /* Boot on the stack */
  584. /* Kick the second */
  585. apic_write_around(APIC_ICR, APIC_DM_STARTUP
  586. | (start_eip >> 12));
  587. /*
  588. * Give the other CPU some time to accept the IPI.
  589. */
  590. udelay(300);
  591. Dprintk("Startup point 1.\n");
  592. Dprintk("Waiting for send to finish...\n");
  593. send_status = safe_apic_wait_icr_idle();
  594. /*
  595. * Give the other CPU some time to accept the IPI.
  596. */
  597. udelay(200);
  598. /*
  599. * Due to the Pentium erratum 3AP.
  600. */
  601. if (maxlvt > 3) {
  602. apic_read_around(APIC_SPIV);
  603. apic_write(APIC_ESR, 0);
  604. }
  605. accept_status = (apic_read(APIC_ESR) & 0xEF);
  606. if (send_status || accept_status)
  607. break;
  608. }
  609. Dprintk("After Startup.\n");
  610. if (send_status)
  611. printk("APIC never delivered???\n");
  612. if (accept_status)
  613. printk("APIC delivery error (%lx).\n", accept_status);
  614. return (send_status | accept_status);
  615. }
  616. #endif /* WAKE_SECONDARY_VIA_INIT */
  617. extern cpumask_t cpu_initialized;
  618. static inline int alloc_cpu_id(void)
  619. {
  620. cpumask_t tmp_map;
  621. int cpu;
  622. cpus_complement(tmp_map, cpu_present_map);
  623. cpu = first_cpu(tmp_map);
  624. if (cpu >= NR_CPUS)
  625. return -ENODEV;
  626. return cpu;
  627. }
  628. #ifdef CONFIG_HOTPLUG_CPU
  629. static struct task_struct * __devinitdata cpu_idle_tasks[NR_CPUS];
  630. static inline struct task_struct * alloc_idle_task(int cpu)
  631. {
  632. struct task_struct *idle;
  633. if ((idle = cpu_idle_tasks[cpu]) != NULL) {
  634. /* initialize thread_struct. we really want to avoid destroy
  635. * idle tread
  636. */
  637. idle->thread.esp = (unsigned long)task_pt_regs(idle);
  638. init_idle(idle, cpu);
  639. return idle;
  640. }
  641. idle = fork_idle(cpu);
  642. if (!IS_ERR(idle))
  643. cpu_idle_tasks[cpu] = idle;
  644. return idle;
  645. }
  646. #else
  647. #define alloc_idle_task(cpu) fork_idle(cpu)
  648. #endif
  649. /* Initialize the CPU's GDT. This is either the boot CPU doing itself
  650. (still using the master per-cpu area), or a CPU doing it for a
  651. secondary which will soon come up. */
  652. static __cpuinit void init_gdt(int cpu)
  653. {
  654. struct desc_struct *gdt = get_cpu_gdt_table(cpu);
  655. pack_descriptor((u32 *)&gdt[GDT_ENTRY_PERCPU].a,
  656. (u32 *)&gdt[GDT_ENTRY_PERCPU].b,
  657. __per_cpu_offset[cpu], 0xFFFFF,
  658. 0x80 | DESCTYPE_S | 0x2, 0x8);
  659. per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu];
  660. per_cpu(cpu_number, cpu) = cpu;
  661. }
  662. /* Defined in head.S */
  663. extern struct Xgt_desc_struct early_gdt_descr;
  664. static int __cpuinit do_boot_cpu(int apicid, int cpu)
  665. /*
  666. * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
  667. * (ie clustered apic addressing mode), this is a LOGICAL apic ID.
  668. * Returns zero if CPU booted OK, else error code from wakeup_secondary_cpu.
  669. */
  670. {
  671. struct task_struct *idle;
  672. unsigned long boot_error;
  673. int timeout;
  674. unsigned long start_eip;
  675. unsigned short nmi_high = 0, nmi_low = 0;
  676. /*
  677. * Save current MTRR state in case it was changed since early boot
  678. * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync:
  679. */
  680. mtrr_save_state();
  681. /*
  682. * We can't use kernel_thread since we must avoid to
  683. * reschedule the child.
  684. */
  685. idle = alloc_idle_task(cpu);
  686. if (IS_ERR(idle))
  687. panic("failed fork for CPU %d", cpu);
  688. init_gdt(cpu);
  689. per_cpu(current_task, cpu) = idle;
  690. early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
  691. idle->thread.eip = (unsigned long) start_secondary;
  692. /* start_eip had better be page-aligned! */
  693. start_eip = setup_trampoline();
  694. ++cpucount;
  695. alternatives_smp_switch(1);
  696. /* So we see what's up */
  697. printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
  698. /* Stack for startup_32 can be just as for start_secondary onwards */
  699. stack_start.esp = (void *) idle->thread.esp;
  700. irq_ctx_init(cpu);
  701. x86_cpu_to_apicid[cpu] = apicid;
  702. /*
  703. * This grunge runs the startup process for
  704. * the targeted processor.
  705. */
  706. atomic_set(&init_deasserted, 0);
  707. Dprintk("Setting warm reset code and vector.\n");
  708. store_NMI_vector(&nmi_high, &nmi_low);
  709. smpboot_setup_warm_reset_vector(start_eip);
  710. /*
  711. * Starting actual IPI sequence...
  712. */
  713. boot_error = wakeup_secondary_cpu(apicid, start_eip);
  714. if (!boot_error) {
  715. /*
  716. * allow APs to start initializing.
  717. */
  718. Dprintk("Before Callout %d.\n", cpu);
  719. cpu_set(cpu, cpu_callout_map);
  720. Dprintk("After Callout %d.\n", cpu);
  721. /*
  722. * Wait 5s total for a response
  723. */
  724. for (timeout = 0; timeout < 50000; timeout++) {
  725. if (cpu_isset(cpu, cpu_callin_map))
  726. break; /* It has booted */
  727. udelay(100);
  728. }
  729. if (cpu_isset(cpu, cpu_callin_map)) {
  730. /* number CPUs logically, starting from 1 (BSP is 0) */
  731. Dprintk("OK.\n");
  732. printk("CPU%d: ", cpu);
  733. print_cpu_info(&cpu_data[cpu]);
  734. Dprintk("CPU has booted.\n");
  735. } else {
  736. boot_error= 1;
  737. if (*((volatile unsigned char *)trampoline_base)
  738. == 0xA5)
  739. /* trampoline started but...? */
  740. printk("Stuck ??\n");
  741. else
  742. /* trampoline code not run */
  743. printk("Not responding.\n");
  744. inquire_remote_apic(apicid);
  745. }
  746. }
  747. if (boot_error) {
  748. /* Try to put things back the way they were before ... */
  749. unmap_cpu_to_logical_apicid(cpu);
  750. cpu_clear(cpu, cpu_callout_map); /* was set here (do_boot_cpu()) */
  751. cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */
  752. cpucount--;
  753. } else {
  754. x86_cpu_to_apicid[cpu] = apicid;
  755. cpu_set(cpu, cpu_present_map);
  756. }
  757. /* mark "stuck" area as not stuck */
  758. *((volatile unsigned long *)trampoline_base) = 0;
  759. return boot_error;
  760. }
  761. #ifdef CONFIG_HOTPLUG_CPU
  762. void cpu_exit_clear(void)
  763. {
  764. int cpu = raw_smp_processor_id();
  765. idle_task_exit();
  766. cpucount --;
  767. cpu_uninit();
  768. irq_ctx_exit(cpu);
  769. cpu_clear(cpu, cpu_callout_map);
  770. cpu_clear(cpu, cpu_callin_map);
  771. cpu_clear(cpu, smp_commenced_mask);
  772. unmap_cpu_to_logical_apicid(cpu);
  773. }
  774. struct warm_boot_cpu_info {
  775. struct completion *complete;
  776. struct work_struct task;
  777. int apicid;
  778. int cpu;
  779. };
  780. static void __cpuinit do_warm_boot_cpu(struct work_struct *work)
  781. {
  782. struct warm_boot_cpu_info *info =
  783. container_of(work, struct warm_boot_cpu_info, task);
  784. do_boot_cpu(info->apicid, info->cpu);
  785. complete(info->complete);
  786. }
  787. static int __cpuinit __smp_prepare_cpu(int cpu)
  788. {
  789. DECLARE_COMPLETION_ONSTACK(done);
  790. struct warm_boot_cpu_info info;
  791. int apicid, ret;
  792. apicid = x86_cpu_to_apicid[cpu];
  793. if (apicid == BAD_APICID) {
  794. ret = -ENODEV;
  795. goto exit;
  796. }
  797. info.complete = &done;
  798. info.apicid = apicid;
  799. info.cpu = cpu;
  800. INIT_WORK(&info.task, do_warm_boot_cpu);
  801. /* init low mem mapping */
  802. clone_pgd_range(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS,
  803. min_t(unsigned long, KERNEL_PGD_PTRS, USER_PGD_PTRS));
  804. flush_tlb_all();
  805. schedule_work(&info.task);
  806. wait_for_completion(&done);
  807. zap_low_mappings();
  808. ret = 0;
  809. exit:
  810. return ret;
  811. }
  812. #endif
  813. static void smp_tune_scheduling(void)
  814. {
  815. unsigned long cachesize; /* kB */
  816. if (cpu_khz) {
  817. cachesize = boot_cpu_data.x86_cache_size;
  818. if (cachesize > 0)
  819. max_cache_size = cachesize * 1024;
  820. }
  821. }
  822. /*
  823. * Cycle through the processors sending APIC IPIs to boot each.
  824. */
  825. static int boot_cpu_logical_apicid;
  826. /* Where the IO area was mapped on multiquad, always 0 otherwise */
  827. void *xquad_portio;
  828. #ifdef CONFIG_X86_NUMAQ
  829. EXPORT_SYMBOL(xquad_portio);
  830. #endif
  831. static void __init smp_boot_cpus(unsigned int max_cpus)
  832. {
  833. int apicid, cpu, bit, kicked;
  834. unsigned long bogosum = 0;
  835. /*
  836. * Setup boot CPU information
  837. */
  838. smp_store_cpu_info(0); /* Final full version of the data */
  839. printk("CPU%d: ", 0);
  840. print_cpu_info(&cpu_data[0]);
  841. boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  842. boot_cpu_logical_apicid = logical_smp_processor_id();
  843. x86_cpu_to_apicid[0] = boot_cpu_physical_apicid;
  844. current_thread_info()->cpu = 0;
  845. smp_tune_scheduling();
  846. set_cpu_sibling_map(0);
  847. /*
  848. * If we couldn't find an SMP configuration at boot time,
  849. * get out of here now!
  850. */
  851. if (!smp_found_config && !acpi_lapic) {
  852. printk(KERN_NOTICE "SMP motherboard not detected.\n");
  853. smpboot_clear_io_apic_irqs();
  854. phys_cpu_present_map = physid_mask_of_physid(0);
  855. if (APIC_init_uniprocessor())
  856. printk(KERN_NOTICE "Local APIC not detected."
  857. " Using dummy APIC emulation.\n");
  858. map_cpu_to_logical_apicid();
  859. cpu_set(0, cpu_sibling_map[0]);
  860. cpu_set(0, cpu_core_map[0]);
  861. return;
  862. }
  863. /*
  864. * Should not be necessary because the MP table should list the boot
  865. * CPU too, but we do it for the sake of robustness anyway.
  866. * Makes no sense to do this check in clustered apic mode, so skip it
  867. */
  868. if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
  869. printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
  870. boot_cpu_physical_apicid);
  871. physid_set(hard_smp_processor_id(), phys_cpu_present_map);
  872. }
  873. /*
  874. * If we couldn't find a local APIC, then get out of here now!
  875. */
  876. if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && !cpu_has_apic) {
  877. printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
  878. boot_cpu_physical_apicid);
  879. printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
  880. smpboot_clear_io_apic_irqs();
  881. phys_cpu_present_map = physid_mask_of_physid(0);
  882. cpu_set(0, cpu_sibling_map[0]);
  883. cpu_set(0, cpu_core_map[0]);
  884. return;
  885. }
  886. verify_local_APIC();
  887. /*
  888. * If SMP should be disabled, then really disable it!
  889. */
  890. if (!max_cpus) {
  891. smp_found_config = 0;
  892. printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
  893. smpboot_clear_io_apic_irqs();
  894. phys_cpu_present_map = physid_mask_of_physid(0);
  895. cpu_set(0, cpu_sibling_map[0]);
  896. cpu_set(0, cpu_core_map[0]);
  897. return;
  898. }
  899. connect_bsp_APIC();
  900. setup_local_APIC();
  901. map_cpu_to_logical_apicid();
  902. setup_portio_remap();
  903. /*
  904. * Scan the CPU present map and fire up the other CPUs via do_boot_cpu
  905. *
  906. * In clustered apic mode, phys_cpu_present_map is a constructed thus:
  907. * bits 0-3 are quad0, 4-7 are quad1, etc. A perverse twist on the
  908. * clustered apic ID.
  909. */
  910. Dprintk("CPU present map: %lx\n", physids_coerce(phys_cpu_present_map));
  911. kicked = 1;
  912. for (bit = 0; kicked < NR_CPUS && bit < MAX_APICS; bit++) {
  913. apicid = cpu_present_to_apicid(bit);
  914. /*
  915. * Don't even attempt to start the boot CPU!
  916. */
  917. if ((apicid == boot_cpu_apicid) || (apicid == BAD_APICID))
  918. continue;
  919. if (!check_apicid_present(bit))
  920. continue;
  921. if (max_cpus <= cpucount+1)
  922. continue;
  923. if (((cpu = alloc_cpu_id()) <= 0) || do_boot_cpu(apicid, cpu))
  924. printk("CPU #%d not responding - cannot use it.\n",
  925. apicid);
  926. else
  927. ++kicked;
  928. }
  929. /*
  930. * Cleanup possible dangling ends...
  931. */
  932. smpboot_restore_warm_reset_vector();
  933. /*
  934. * Allow the user to impress friends.
  935. */
  936. Dprintk("Before bogomips.\n");
  937. for (cpu = 0; cpu < NR_CPUS; cpu++)
  938. if (cpu_isset(cpu, cpu_callout_map))
  939. bogosum += cpu_data[cpu].loops_per_jiffy;
  940. printk(KERN_INFO
  941. "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
  942. cpucount+1,
  943. bogosum/(500000/HZ),
  944. (bogosum/(5000/HZ))%100);
  945. Dprintk("Before bogocount - setting activated=1.\n");
  946. if (smp_b_stepping)
  947. printk(KERN_WARNING "WARNING: SMP operation may be unreliable with B stepping processors.\n");
  948. /*
  949. * Don't taint if we are running SMP kernel on a single non-MP
  950. * approved Athlon
  951. */
  952. if (tainted & TAINT_UNSAFE_SMP) {
  953. if (cpucount)
  954. printk (KERN_INFO "WARNING: This combination of AMD processors is not suitable for SMP.\n");
  955. else
  956. tainted &= ~TAINT_UNSAFE_SMP;
  957. }
  958. Dprintk("Boot done.\n");
  959. /*
  960. * construct cpu_sibling_map[], so that we can tell sibling CPUs
  961. * efficiently.
  962. */
  963. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  964. cpus_clear(cpu_sibling_map[cpu]);
  965. cpus_clear(cpu_core_map[cpu]);
  966. }
  967. cpu_set(0, cpu_sibling_map[0]);
  968. cpu_set(0, cpu_core_map[0]);
  969. smpboot_setup_io_apic();
  970. setup_boot_clock();
  971. }
  972. /* These are wrappers to interface to the new boot process. Someone
  973. who understands all this stuff should rewrite it properly. --RR 15/Jul/02 */
  974. void __init native_smp_prepare_cpus(unsigned int max_cpus)
  975. {
  976. smp_commenced_mask = cpumask_of_cpu(0);
  977. cpu_callin_map = cpumask_of_cpu(0);
  978. mb();
  979. smp_boot_cpus(max_cpus);
  980. }
  981. void __init native_smp_prepare_boot_cpu(void)
  982. {
  983. unsigned int cpu = smp_processor_id();
  984. init_gdt(cpu);
  985. switch_to_new_gdt();
  986. cpu_set(cpu, cpu_online_map);
  987. cpu_set(cpu, cpu_callout_map);
  988. cpu_set(cpu, cpu_present_map);
  989. cpu_set(cpu, cpu_possible_map);
  990. __get_cpu_var(cpu_state) = CPU_ONLINE;
  991. }
  992. #ifdef CONFIG_HOTPLUG_CPU
  993. static void
  994. remove_siblinginfo(int cpu)
  995. {
  996. int sibling;
  997. struct cpuinfo_x86 *c = cpu_data;
  998. for_each_cpu_mask(sibling, cpu_core_map[cpu]) {
  999. cpu_clear(cpu, cpu_core_map[sibling]);
  1000. /*
  1001. * last thread sibling in this cpu core going down
  1002. */
  1003. if (cpus_weight(cpu_sibling_map[cpu]) == 1)
  1004. c[sibling].booted_cores--;
  1005. }
  1006. for_each_cpu_mask(sibling, cpu_sibling_map[cpu])
  1007. cpu_clear(cpu, cpu_sibling_map[sibling]);
  1008. cpus_clear(cpu_sibling_map[cpu]);
  1009. cpus_clear(cpu_core_map[cpu]);
  1010. c[cpu].phys_proc_id = 0;
  1011. c[cpu].cpu_core_id = 0;
  1012. cpu_clear(cpu, cpu_sibling_setup_map);
  1013. }
  1014. int __cpu_disable(void)
  1015. {
  1016. cpumask_t map = cpu_online_map;
  1017. int cpu = smp_processor_id();
  1018. /*
  1019. * Perhaps use cpufreq to drop frequency, but that could go
  1020. * into generic code.
  1021. *
  1022. * We won't take down the boot processor on i386 due to some
  1023. * interrupts only being able to be serviced by the BSP.
  1024. * Especially so if we're not using an IOAPIC -zwane
  1025. */
  1026. if (cpu == 0)
  1027. return -EBUSY;
  1028. if (nmi_watchdog == NMI_LOCAL_APIC)
  1029. stop_apic_nmi_watchdog(NULL);
  1030. clear_local_APIC();
  1031. /* Allow any queued timer interrupts to get serviced */
  1032. local_irq_enable();
  1033. mdelay(1);
  1034. local_irq_disable();
  1035. remove_siblinginfo(cpu);
  1036. cpu_clear(cpu, map);
  1037. fixup_irqs(map);
  1038. /* It's now safe to remove this processor from the online map */
  1039. cpu_clear(cpu, cpu_online_map);
  1040. return 0;
  1041. }
  1042. void __cpu_die(unsigned int cpu)
  1043. {
  1044. /* We don't do anything here: idle task is faking death itself. */
  1045. unsigned int i;
  1046. for (i = 0; i < 10; i++) {
  1047. /* They ack this in play_dead by setting CPU_DEAD */
  1048. if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
  1049. printk ("CPU %d is now offline\n", cpu);
  1050. if (1 == num_online_cpus())
  1051. alternatives_smp_switch(0);
  1052. return;
  1053. }
  1054. msleep(100);
  1055. }
  1056. printk(KERN_ERR "CPU %u didn't die...\n", cpu);
  1057. }
  1058. #else /* ... !CONFIG_HOTPLUG_CPU */
  1059. int __cpu_disable(void)
  1060. {
  1061. return -ENOSYS;
  1062. }
  1063. void __cpu_die(unsigned int cpu)
  1064. {
  1065. /* We said "no" in __cpu_disable */
  1066. BUG();
  1067. }
  1068. #endif /* CONFIG_HOTPLUG_CPU */
  1069. int __cpuinit native_cpu_up(unsigned int cpu)
  1070. {
  1071. unsigned long flags;
  1072. #ifdef CONFIG_HOTPLUG_CPU
  1073. int ret = 0;
  1074. /*
  1075. * We do warm boot only on cpus that had booted earlier
  1076. * Otherwise cold boot is all handled from smp_boot_cpus().
  1077. * cpu_callin_map is set during AP kickstart process. Its reset
  1078. * when a cpu is taken offline from cpu_exit_clear().
  1079. */
  1080. if (!cpu_isset(cpu, cpu_callin_map))
  1081. ret = __smp_prepare_cpu(cpu);
  1082. if (ret)
  1083. return -EIO;
  1084. #endif
  1085. /* In case one didn't come up */
  1086. if (!cpu_isset(cpu, cpu_callin_map)) {
  1087. printk(KERN_DEBUG "skipping cpu%d, didn't come online\n", cpu);
  1088. return -EIO;
  1089. }
  1090. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  1091. /* Unleash the CPU! */
  1092. cpu_set(cpu, smp_commenced_mask);
  1093. /*
  1094. * Check TSC synchronization with the AP (keep irqs disabled
  1095. * while doing so):
  1096. */
  1097. local_irq_save(flags);
  1098. check_tsc_sync_source(cpu);
  1099. local_irq_restore(flags);
  1100. while (!cpu_isset(cpu, cpu_online_map)) {
  1101. cpu_relax();
  1102. touch_nmi_watchdog();
  1103. }
  1104. return 0;
  1105. }
  1106. void __init native_smp_cpus_done(unsigned int max_cpus)
  1107. {
  1108. #ifdef CONFIG_X86_IO_APIC
  1109. setup_ioapic_dest();
  1110. #endif
  1111. zap_low_mappings();
  1112. #ifndef CONFIG_HOTPLUG_CPU
  1113. /*
  1114. * Disable executability of the SMP trampoline:
  1115. */
  1116. set_kernel_exec((unsigned long)trampoline_base, trampoline_exec);
  1117. #endif
  1118. }
  1119. void __init smp_intr_init(void)
  1120. {
  1121. /*
  1122. * IRQ0 must be given a fixed assignment and initialized,
  1123. * because it's used before the IO-APIC is set up.
  1124. */
  1125. set_intr_gate(FIRST_DEVICE_VECTOR, interrupt[0]);
  1126. /*
  1127. * The reschedule interrupt is a CPU-to-CPU reschedule-helper
  1128. * IPI, driven by wakeup.
  1129. */
  1130. set_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
  1131. /* IPI for invalidation */
  1132. set_intr_gate(INVALIDATE_TLB_VECTOR, invalidate_interrupt);
  1133. /* IPI for generic function call */
  1134. set_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
  1135. }
  1136. /*
  1137. * If the BIOS enumerates physical processors before logical,
  1138. * maxcpus=N at enumeration-time can be used to disable HT.
  1139. */
  1140. static int __init parse_maxcpus(char *arg)
  1141. {
  1142. extern unsigned int maxcpus;
  1143. maxcpus = simple_strtoul(arg, NULL, 0);
  1144. return 0;
  1145. }
  1146. early_param("maxcpus", parse_maxcpus);