smpboot_32.c 33 KB

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