smpboot.c 33 KB

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