smpboot.c 33 KB

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