smpboot_32.c 32 KB

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