smpboot_32.c 32 KB

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