smpboot_32.c 33 KB

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