smpboot.c 33 KB

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