smpboot_32.c 32 KB

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