smpboot_32.c 33 KB

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