smpboot.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  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 <asm/pda.h>
  54. #include <asm/genapic.h>
  55. #include <mach_apic.h>
  56. #include <mach_wakecpu.h>
  57. #include <smpboot_hooks.h>
  58. #include <asm/vmi.h>
  59. /* Set if we find a B stepping CPU */
  60. static int __devinitdata smp_b_stepping;
  61. /* Number of siblings per CPU package */
  62. int smp_num_siblings = 1;
  63. EXPORT_SYMBOL(smp_num_siblings);
  64. /* Last level cache ID of each logical CPU */
  65. int cpu_llc_id[NR_CPUS] __cpuinitdata = {[0 ... NR_CPUS-1] = BAD_APICID};
  66. /* representing HT siblings of each logical CPU */
  67. cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly;
  68. EXPORT_SYMBOL(cpu_sibling_map);
  69. /* representing HT and core siblings of each logical CPU */
  70. cpumask_t cpu_core_map[NR_CPUS] __read_mostly;
  71. EXPORT_SYMBOL(cpu_core_map);
  72. /* bitmap of online cpus */
  73. cpumask_t cpu_online_map __read_mostly;
  74. EXPORT_SYMBOL(cpu_online_map);
  75. cpumask_t cpu_callin_map;
  76. cpumask_t cpu_callout_map;
  77. EXPORT_SYMBOL(cpu_callout_map);
  78. cpumask_t cpu_possible_map;
  79. EXPORT_SYMBOL(cpu_possible_map);
  80. static cpumask_t smp_commenced_mask;
  81. /* Per CPU bogomips and other parameters */
  82. struct cpuinfo_x86 cpu_data[NR_CPUS] __cacheline_aligned;
  83. EXPORT_SYMBOL(cpu_data);
  84. u8 x86_cpu_to_apicid[NR_CPUS] __read_mostly =
  85. { [0 ... NR_CPUS-1] = 0xff };
  86. EXPORT_SYMBOL(x86_cpu_to_apicid);
  87. u8 apicid_2_node[MAX_APICID];
  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_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 secondary_cpu_init(), SMP
  329. * booting is too fragile that we want to limit the
  330. * things done here to the most necessary things.
  331. */
  332. #ifdef CONFIG_VMI
  333. vmi_bringup();
  334. #endif
  335. secondary_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. * switch to the per CPU GDT we already set up
  385. * in do_boot_cpu()
  386. */
  387. cpu_set_gdt(current_thread_info()->cpu);
  388. /*
  389. * We don't actually need to load the full TSS,
  390. * basically just the stack pointer and the eip.
  391. */
  392. asm volatile(
  393. "movl %0,%%esp\n\t"
  394. "jmp *%1"
  395. :
  396. :"m" (current->thread.esp),"m" (current->thread.eip));
  397. }
  398. /* Static state in head.S used to set up a CPU */
  399. extern struct {
  400. void * esp;
  401. unsigned short ss;
  402. } stack_start;
  403. extern struct i386_pda *start_pda;
  404. #ifdef CONFIG_NUMA
  405. /* which logical CPUs are on which nodes */
  406. cpumask_t node_2_cpu_mask[MAX_NUMNODES] __read_mostly =
  407. { [0 ... MAX_NUMNODES-1] = CPU_MASK_NONE };
  408. EXPORT_SYMBOL(node_2_cpu_mask);
  409. /* which node each logical CPU is on */
  410. int cpu_2_node[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = 0 };
  411. EXPORT_SYMBOL(cpu_2_node);
  412. /* set up a mapping between cpu and node. */
  413. static inline void map_cpu_to_node(int cpu, int node)
  414. {
  415. printk("Mapping cpu %d to node %d\n", cpu, node);
  416. cpu_set(cpu, node_2_cpu_mask[node]);
  417. cpu_2_node[cpu] = node;
  418. }
  419. /* undo a mapping between cpu and node. */
  420. static inline void unmap_cpu_to_node(int cpu)
  421. {
  422. int node;
  423. printk("Unmapping cpu %d from all nodes\n", cpu);
  424. for (node = 0; node < MAX_NUMNODES; node ++)
  425. cpu_clear(cpu, node_2_cpu_mask[node]);
  426. cpu_2_node[cpu] = 0;
  427. }
  428. #else /* !CONFIG_NUMA */
  429. #define map_cpu_to_node(cpu, node) ({})
  430. #define unmap_cpu_to_node(cpu) ({})
  431. #endif /* CONFIG_NUMA */
  432. u8 cpu_2_logical_apicid[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID };
  433. static void map_cpu_to_logical_apicid(void)
  434. {
  435. int cpu = smp_processor_id();
  436. int apicid = logical_smp_processor_id();
  437. int node = apicid_to_node(apicid);
  438. if (!node_online(node))
  439. node = first_online_node;
  440. cpu_2_logical_apicid[cpu] = apicid;
  441. map_cpu_to_node(cpu, node);
  442. }
  443. static void unmap_cpu_to_logical_apicid(int cpu)
  444. {
  445. cpu_2_logical_apicid[cpu] = BAD_APICID;
  446. unmap_cpu_to_node(cpu);
  447. }
  448. #if APIC_DEBUG
  449. static inline void __inquire_remote_apic(int apicid)
  450. {
  451. int i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 };
  452. char *names[] = { "ID", "VERSION", "SPIV" };
  453. int timeout, status;
  454. printk("Inquiring remote APIC #%d...\n", apicid);
  455. for (i = 0; i < ARRAY_SIZE(regs); i++) {
  456. printk("... APIC #%d %s: ", apicid, names[i]);
  457. /*
  458. * Wait for idle.
  459. */
  460. apic_wait_icr_idle();
  461. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
  462. apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]);
  463. timeout = 0;
  464. do {
  465. udelay(100);
  466. status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK;
  467. } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000);
  468. switch (status) {
  469. case APIC_ICR_RR_VALID:
  470. status = apic_read(APIC_RRR);
  471. printk("%08x\n", status);
  472. break;
  473. default:
  474. printk("failed\n");
  475. }
  476. }
  477. }
  478. #endif
  479. #ifdef WAKE_SECONDARY_VIA_NMI
  480. /*
  481. * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal
  482. * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this
  483. * won't ... remember to clear down the APIC, etc later.
  484. */
  485. static int __devinit
  486. wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
  487. {
  488. unsigned long send_status = 0, accept_status = 0;
  489. int timeout, maxlvt;
  490. /* Target chip */
  491. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(logical_apicid));
  492. /* Boot on the stack */
  493. /* Kick the second */
  494. apic_write_around(APIC_ICR, APIC_DM_NMI | APIC_DEST_LOGICAL);
  495. Dprintk("Waiting for send to finish...\n");
  496. timeout = 0;
  497. do {
  498. Dprintk("+");
  499. udelay(100);
  500. send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
  501. } while (send_status && (timeout++ < 1000));
  502. /*
  503. * Give the other CPU some time to accept the IPI.
  504. */
  505. udelay(200);
  506. /*
  507. * Due to the Pentium erratum 3AP.
  508. */
  509. maxlvt = lapic_get_maxlvt();
  510. if (maxlvt > 3) {
  511. apic_read_around(APIC_SPIV);
  512. apic_write(APIC_ESR, 0);
  513. }
  514. accept_status = (apic_read(APIC_ESR) & 0xEF);
  515. Dprintk("NMI sent.\n");
  516. if (send_status)
  517. printk("APIC never delivered???\n");
  518. if (accept_status)
  519. printk("APIC delivery error (%lx).\n", accept_status);
  520. return (send_status | accept_status);
  521. }
  522. #endif /* WAKE_SECONDARY_VIA_NMI */
  523. #ifdef WAKE_SECONDARY_VIA_INIT
  524. static int __devinit
  525. wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
  526. {
  527. unsigned long send_status = 0, accept_status = 0;
  528. int maxlvt, timeout, num_starts, j;
  529. /*
  530. * Be paranoid about clearing APIC errors.
  531. */
  532. if (APIC_INTEGRATED(apic_version[phys_apicid])) {
  533. apic_read_around(APIC_SPIV);
  534. apic_write(APIC_ESR, 0);
  535. apic_read(APIC_ESR);
  536. }
  537. Dprintk("Asserting INIT.\n");
  538. /*
  539. * Turn INIT on target chip
  540. */
  541. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  542. /*
  543. * Send IPI
  544. */
  545. apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
  546. | APIC_DM_INIT);
  547. Dprintk("Waiting for send to finish...\n");
  548. timeout = 0;
  549. do {
  550. Dprintk("+");
  551. udelay(100);
  552. send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
  553. } while (send_status && (timeout++ < 1000));
  554. mdelay(10);
  555. Dprintk("Deasserting INIT.\n");
  556. /* Target chip */
  557. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  558. /* Send IPI */
  559. apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
  560. Dprintk("Waiting for send to finish...\n");
  561. timeout = 0;
  562. do {
  563. Dprintk("+");
  564. udelay(100);
  565. send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
  566. } while (send_status && (timeout++ < 1000));
  567. atomic_set(&init_deasserted, 1);
  568. /*
  569. * Should we send STARTUP IPIs ?
  570. *
  571. * Determine this based on the APIC version.
  572. * If we don't have an integrated APIC, don't send the STARTUP IPIs.
  573. */
  574. if (APIC_INTEGRATED(apic_version[phys_apicid]))
  575. num_starts = 2;
  576. else
  577. num_starts = 0;
  578. /*
  579. * Paravirt / VMI wants a startup IPI hook here to set up the
  580. * target processor state.
  581. */
  582. startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
  583. (unsigned long) stack_start.esp);
  584. /*
  585. * Run STARTUP IPI loop.
  586. */
  587. Dprintk("#startup loops: %d.\n", num_starts);
  588. maxlvt = lapic_get_maxlvt();
  589. for (j = 1; j <= num_starts; j++) {
  590. Dprintk("Sending STARTUP #%d.\n",j);
  591. apic_read_around(APIC_SPIV);
  592. apic_write(APIC_ESR, 0);
  593. apic_read(APIC_ESR);
  594. Dprintk("After apic_write.\n");
  595. /*
  596. * STARTUP IPI
  597. */
  598. /* Target chip */
  599. apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
  600. /* Boot on the stack */
  601. /* Kick the second */
  602. apic_write_around(APIC_ICR, APIC_DM_STARTUP
  603. | (start_eip >> 12));
  604. /*
  605. * Give the other CPU some time to accept the IPI.
  606. */
  607. udelay(300);
  608. Dprintk("Startup point 1.\n");
  609. Dprintk("Waiting for send to finish...\n");
  610. timeout = 0;
  611. do {
  612. Dprintk("+");
  613. udelay(100);
  614. send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
  615. } while (send_status && (timeout++ < 1000));
  616. /*
  617. * Give the other CPU some time to accept the IPI.
  618. */
  619. udelay(200);
  620. /*
  621. * Due to the Pentium erratum 3AP.
  622. */
  623. if (maxlvt > 3) {
  624. apic_read_around(APIC_SPIV);
  625. apic_write(APIC_ESR, 0);
  626. }
  627. accept_status = (apic_read(APIC_ESR) & 0xEF);
  628. if (send_status || accept_status)
  629. break;
  630. }
  631. Dprintk("After Startup.\n");
  632. if (send_status)
  633. printk("APIC never delivered???\n");
  634. if (accept_status)
  635. printk("APIC delivery error (%lx).\n", accept_status);
  636. return (send_status | accept_status);
  637. }
  638. #endif /* WAKE_SECONDARY_VIA_INIT */
  639. extern cpumask_t cpu_initialized;
  640. static inline int alloc_cpu_id(void)
  641. {
  642. cpumask_t tmp_map;
  643. int cpu;
  644. cpus_complement(tmp_map, cpu_present_map);
  645. cpu = first_cpu(tmp_map);
  646. if (cpu >= NR_CPUS)
  647. return -ENODEV;
  648. return cpu;
  649. }
  650. #ifdef CONFIG_HOTPLUG_CPU
  651. static struct task_struct * __devinitdata cpu_idle_tasks[NR_CPUS];
  652. static inline struct task_struct * alloc_idle_task(int cpu)
  653. {
  654. struct task_struct *idle;
  655. if ((idle = cpu_idle_tasks[cpu]) != NULL) {
  656. /* initialize thread_struct. we really want to avoid destroy
  657. * idle tread
  658. */
  659. idle->thread.esp = (unsigned long)task_pt_regs(idle);
  660. init_idle(idle, cpu);
  661. return idle;
  662. }
  663. idle = fork_idle(cpu);
  664. if (!IS_ERR(idle))
  665. cpu_idle_tasks[cpu] = idle;
  666. return idle;
  667. }
  668. #else
  669. #define alloc_idle_task(cpu) fork_idle(cpu)
  670. #endif
  671. static int __cpuinit do_boot_cpu(int apicid, int cpu)
  672. /*
  673. * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
  674. * (ie clustered apic addressing mode), this is a LOGICAL apic ID.
  675. * Returns zero if CPU booted OK, else error code from wakeup_secondary_cpu.
  676. */
  677. {
  678. struct task_struct *idle;
  679. unsigned long boot_error;
  680. int timeout;
  681. unsigned long start_eip;
  682. unsigned short nmi_high = 0, nmi_low = 0;
  683. /*
  684. * We can't use kernel_thread since we must avoid to
  685. * reschedule the child.
  686. */
  687. idle = alloc_idle_task(cpu);
  688. if (IS_ERR(idle))
  689. panic("failed fork for CPU %d", cpu);
  690. /* Pre-allocate and initialize the CPU's GDT and PDA so it
  691. doesn't have to do any memory allocation during the
  692. delicate CPU-bringup phase. */
  693. if (!init_gdt(cpu, idle)) {
  694. printk(KERN_INFO "Couldn't allocate GDT/PDA for CPU %d\n", cpu);
  695. return -1; /* ? */
  696. }
  697. idle->thread.eip = (unsigned long) start_secondary;
  698. /* start_eip had better be page-aligned! */
  699. start_eip = setup_trampoline();
  700. ++cpucount;
  701. alternatives_smp_switch(1);
  702. /* So we see what's up */
  703. printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
  704. /* Stack for startup_32 can be just as for start_secondary onwards */
  705. stack_start.esp = (void *) idle->thread.esp;
  706. irq_ctx_init(cpu);
  707. x86_cpu_to_apicid[cpu] = apicid;
  708. /*
  709. * This grunge runs the startup process for
  710. * the targeted processor.
  711. */
  712. atomic_set(&init_deasserted, 0);
  713. Dprintk("Setting warm reset code and vector.\n");
  714. store_NMI_vector(&nmi_high, &nmi_low);
  715. smpboot_setup_warm_reset_vector(start_eip);
  716. /*
  717. * Starting actual IPI sequence...
  718. */
  719. boot_error = wakeup_secondary_cpu(apicid, start_eip);
  720. if (!boot_error) {
  721. /*
  722. * allow APs to start initializing.
  723. */
  724. Dprintk("Before Callout %d.\n", cpu);
  725. cpu_set(cpu, cpu_callout_map);
  726. Dprintk("After Callout %d.\n", cpu);
  727. /*
  728. * Wait 5s total for a response
  729. */
  730. for (timeout = 0; timeout < 50000; timeout++) {
  731. if (cpu_isset(cpu, cpu_callin_map))
  732. break; /* It has booted */
  733. udelay(100);
  734. }
  735. if (cpu_isset(cpu, cpu_callin_map)) {
  736. /* number CPUs logically, starting from 1 (BSP is 0) */
  737. Dprintk("OK.\n");
  738. printk("CPU%d: ", cpu);
  739. print_cpu_info(&cpu_data[cpu]);
  740. Dprintk("CPU has booted.\n");
  741. } else {
  742. boot_error= 1;
  743. if (*((volatile unsigned char *)trampoline_base)
  744. == 0xA5)
  745. /* trampoline started but...? */
  746. printk("Stuck ??\n");
  747. else
  748. /* trampoline code not run */
  749. printk("Not responding.\n");
  750. inquire_remote_apic(apicid);
  751. }
  752. }
  753. if (boot_error) {
  754. /* Try to put things back the way they were before ... */
  755. unmap_cpu_to_logical_apicid(cpu);
  756. cpu_clear(cpu, cpu_callout_map); /* was set here (do_boot_cpu()) */
  757. cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */
  758. cpucount--;
  759. } else {
  760. x86_cpu_to_apicid[cpu] = apicid;
  761. cpu_set(cpu, cpu_present_map);
  762. }
  763. /* mark "stuck" area as not stuck */
  764. *((volatile unsigned long *)trampoline_base) = 0;
  765. return boot_error;
  766. }
  767. #ifdef CONFIG_HOTPLUG_CPU
  768. void cpu_exit_clear(void)
  769. {
  770. int cpu = raw_smp_processor_id();
  771. idle_task_exit();
  772. cpucount --;
  773. cpu_uninit();
  774. irq_ctx_exit(cpu);
  775. cpu_clear(cpu, cpu_callout_map);
  776. cpu_clear(cpu, cpu_callin_map);
  777. cpu_clear(cpu, smp_commenced_mask);
  778. unmap_cpu_to_logical_apicid(cpu);
  779. }
  780. struct warm_boot_cpu_info {
  781. struct completion *complete;
  782. struct work_struct task;
  783. int apicid;
  784. int cpu;
  785. };
  786. static void __cpuinit do_warm_boot_cpu(struct work_struct *work)
  787. {
  788. struct warm_boot_cpu_info *info =
  789. container_of(work, struct warm_boot_cpu_info, task);
  790. do_boot_cpu(info->apicid, info->cpu);
  791. complete(info->complete);
  792. }
  793. static int __cpuinit __smp_prepare_cpu(int cpu)
  794. {
  795. DECLARE_COMPLETION_ONSTACK(done);
  796. struct warm_boot_cpu_info info;
  797. int apicid, ret;
  798. struct Xgt_desc_struct *cpu_gdt_descr = &per_cpu(cpu_gdt_descr, cpu);
  799. apicid = x86_cpu_to_apicid[cpu];
  800. if (apicid == BAD_APICID) {
  801. ret = -ENODEV;
  802. goto exit;
  803. }
  804. /*
  805. * the CPU isn't initialized at boot time, allocate gdt table here.
  806. * cpu_init will initialize it
  807. */
  808. if (!cpu_gdt_descr->address) {
  809. cpu_gdt_descr->address = get_zeroed_page(GFP_KERNEL);
  810. if (!cpu_gdt_descr->address)
  811. printk(KERN_CRIT "CPU%d failed to allocate GDT\n", cpu);
  812. ret = -ENOMEM;
  813. goto exit;
  814. }
  815. info.complete = &done;
  816. info.apicid = apicid;
  817. info.cpu = cpu;
  818. INIT_WORK(&info.task, do_warm_boot_cpu);
  819. /* init low mem mapping */
  820. clone_pgd_range(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS,
  821. min_t(unsigned long, KERNEL_PGD_PTRS, USER_PGD_PTRS));
  822. flush_tlb_all();
  823. schedule_work(&info.task);
  824. wait_for_completion(&done);
  825. zap_low_mappings();
  826. ret = 0;
  827. exit:
  828. return ret;
  829. }
  830. #endif
  831. static void smp_tune_scheduling(void)
  832. {
  833. unsigned long cachesize; /* kB */
  834. if (cpu_khz) {
  835. cachesize = boot_cpu_data.x86_cache_size;
  836. if (cachesize > 0)
  837. max_cache_size = cachesize * 1024;
  838. }
  839. }
  840. /*
  841. * Cycle through the processors sending APIC IPIs to boot each.
  842. */
  843. static int boot_cpu_logical_apicid;
  844. /* Where the IO area was mapped on multiquad, always 0 otherwise */
  845. void *xquad_portio;
  846. #ifdef CONFIG_X86_NUMAQ
  847. EXPORT_SYMBOL(xquad_portio);
  848. #endif
  849. static void __init smp_boot_cpus(unsigned int max_cpus)
  850. {
  851. int apicid, cpu, bit, kicked;
  852. unsigned long bogosum = 0;
  853. /*
  854. * Setup boot CPU information
  855. */
  856. smp_store_cpu_info(0); /* Final full version of the data */
  857. printk("CPU%d: ", 0);
  858. print_cpu_info(&cpu_data[0]);
  859. boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  860. boot_cpu_logical_apicid = logical_smp_processor_id();
  861. x86_cpu_to_apicid[0] = boot_cpu_physical_apicid;
  862. current_thread_info()->cpu = 0;
  863. smp_tune_scheduling();
  864. set_cpu_sibling_map(0);
  865. /*
  866. * If we couldn't find an SMP configuration at boot time,
  867. * get out of here now!
  868. */
  869. if (!smp_found_config && !acpi_lapic) {
  870. printk(KERN_NOTICE "SMP motherboard not detected.\n");
  871. smpboot_clear_io_apic_irqs();
  872. phys_cpu_present_map = physid_mask_of_physid(0);
  873. if (APIC_init_uniprocessor())
  874. printk(KERN_NOTICE "Local APIC not detected."
  875. " Using dummy APIC emulation.\n");
  876. map_cpu_to_logical_apicid();
  877. cpu_set(0, cpu_sibling_map[0]);
  878. cpu_set(0, cpu_core_map[0]);
  879. return;
  880. }
  881. /*
  882. * Should not be necessary because the MP table should list the boot
  883. * CPU too, but we do it for the sake of robustness anyway.
  884. * Makes no sense to do this check in clustered apic mode, so skip it
  885. */
  886. if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
  887. printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
  888. boot_cpu_physical_apicid);
  889. physid_set(hard_smp_processor_id(), phys_cpu_present_map);
  890. }
  891. /*
  892. * If we couldn't find a local APIC, then get out of here now!
  893. */
  894. if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && !cpu_has_apic) {
  895. printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
  896. boot_cpu_physical_apicid);
  897. printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
  898. smpboot_clear_io_apic_irqs();
  899. phys_cpu_present_map = physid_mask_of_physid(0);
  900. cpu_set(0, cpu_sibling_map[0]);
  901. cpu_set(0, cpu_core_map[0]);
  902. return;
  903. }
  904. verify_local_APIC();
  905. /*
  906. * If SMP should be disabled, then really disable it!
  907. */
  908. if (!max_cpus) {
  909. smp_found_config = 0;
  910. printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
  911. smpboot_clear_io_apic_irqs();
  912. phys_cpu_present_map = physid_mask_of_physid(0);
  913. cpu_set(0, cpu_sibling_map[0]);
  914. cpu_set(0, cpu_core_map[0]);
  915. return;
  916. }
  917. connect_bsp_APIC();
  918. setup_local_APIC();
  919. map_cpu_to_logical_apicid();
  920. setup_portio_remap();
  921. /*
  922. * Scan the CPU present map and fire up the other CPUs via do_boot_cpu
  923. *
  924. * In clustered apic mode, phys_cpu_present_map is a constructed thus:
  925. * bits 0-3 are quad0, 4-7 are quad1, etc. A perverse twist on the
  926. * clustered apic ID.
  927. */
  928. Dprintk("CPU present map: %lx\n", physids_coerce(phys_cpu_present_map));
  929. kicked = 1;
  930. for (bit = 0; kicked < NR_CPUS && bit < MAX_APICS; bit++) {
  931. apicid = cpu_present_to_apicid(bit);
  932. /*
  933. * Don't even attempt to start the boot CPU!
  934. */
  935. if ((apicid == boot_cpu_apicid) || (apicid == BAD_APICID))
  936. continue;
  937. if (!check_apicid_present(bit))
  938. continue;
  939. if (max_cpus <= cpucount+1)
  940. continue;
  941. if (((cpu = alloc_cpu_id()) <= 0) || do_boot_cpu(apicid, cpu))
  942. printk("CPU #%d not responding - cannot use it.\n",
  943. apicid);
  944. else
  945. ++kicked;
  946. }
  947. /*
  948. * Cleanup possible dangling ends...
  949. */
  950. smpboot_restore_warm_reset_vector();
  951. /*
  952. * Allow the user to impress friends.
  953. */
  954. Dprintk("Before bogomips.\n");
  955. for (cpu = 0; cpu < NR_CPUS; cpu++)
  956. if (cpu_isset(cpu, cpu_callout_map))
  957. bogosum += cpu_data[cpu].loops_per_jiffy;
  958. printk(KERN_INFO
  959. "Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
  960. cpucount+1,
  961. bogosum/(500000/HZ),
  962. (bogosum/(5000/HZ))%100);
  963. Dprintk("Before bogocount - setting activated=1.\n");
  964. if (smp_b_stepping)
  965. printk(KERN_WARNING "WARNING: SMP operation may be unreliable with B stepping processors.\n");
  966. /*
  967. * Don't taint if we are running SMP kernel on a single non-MP
  968. * approved Athlon
  969. */
  970. if (tainted & TAINT_UNSAFE_SMP) {
  971. if (cpucount)
  972. printk (KERN_INFO "WARNING: This combination of AMD processors is not suitable for SMP.\n");
  973. else
  974. tainted &= ~TAINT_UNSAFE_SMP;
  975. }
  976. Dprintk("Boot done.\n");
  977. /*
  978. * construct cpu_sibling_map[], so that we can tell sibling CPUs
  979. * efficiently.
  980. */
  981. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  982. cpus_clear(cpu_sibling_map[cpu]);
  983. cpus_clear(cpu_core_map[cpu]);
  984. }
  985. cpu_set(0, cpu_sibling_map[0]);
  986. cpu_set(0, cpu_core_map[0]);
  987. smpboot_setup_io_apic();
  988. setup_boot_clock();
  989. }
  990. /* These are wrappers to interface to the new boot process. Someone
  991. who understands all this stuff should rewrite it properly. --RR 15/Jul/02 */
  992. void __init smp_prepare_cpus(unsigned int max_cpus)
  993. {
  994. smp_commenced_mask = cpumask_of_cpu(0);
  995. cpu_callin_map = cpumask_of_cpu(0);
  996. mb();
  997. smp_boot_cpus(max_cpus);
  998. }
  999. void __devinit smp_prepare_boot_cpu(void)
  1000. {
  1001. cpu_set(smp_processor_id(), cpu_online_map);
  1002. cpu_set(smp_processor_id(), cpu_callout_map);
  1003. cpu_set(smp_processor_id(), cpu_present_map);
  1004. cpu_set(smp_processor_id(), cpu_possible_map);
  1005. per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
  1006. }
  1007. #ifdef CONFIG_HOTPLUG_CPU
  1008. static void
  1009. remove_siblinginfo(int cpu)
  1010. {
  1011. int sibling;
  1012. struct cpuinfo_x86 *c = cpu_data;
  1013. for_each_cpu_mask(sibling, cpu_core_map[cpu]) {
  1014. cpu_clear(cpu, cpu_core_map[sibling]);
  1015. /*
  1016. * last thread sibling in this cpu core going down
  1017. */
  1018. if (cpus_weight(cpu_sibling_map[cpu]) == 1)
  1019. c[sibling].booted_cores--;
  1020. }
  1021. for_each_cpu_mask(sibling, cpu_sibling_map[cpu])
  1022. cpu_clear(cpu, cpu_sibling_map[sibling]);
  1023. cpus_clear(cpu_sibling_map[cpu]);
  1024. cpus_clear(cpu_core_map[cpu]);
  1025. c[cpu].phys_proc_id = 0;
  1026. c[cpu].cpu_core_id = 0;
  1027. cpu_clear(cpu, cpu_sibling_setup_map);
  1028. }
  1029. int __cpu_disable(void)
  1030. {
  1031. cpumask_t map = cpu_online_map;
  1032. int cpu = smp_processor_id();
  1033. /*
  1034. * Perhaps use cpufreq to drop frequency, but that could go
  1035. * into generic code.
  1036. *
  1037. * We won't take down the boot processor on i386 due to some
  1038. * interrupts only being able to be serviced by the BSP.
  1039. * Especially so if we're not using an IOAPIC -zwane
  1040. */
  1041. if (cpu == 0)
  1042. return -EBUSY;
  1043. if (nmi_watchdog == NMI_LOCAL_APIC)
  1044. stop_apic_nmi_watchdog(NULL);
  1045. clear_local_APIC();
  1046. /* Allow any queued timer interrupts to get serviced */
  1047. local_irq_enable();
  1048. mdelay(1);
  1049. local_irq_disable();
  1050. remove_siblinginfo(cpu);
  1051. cpu_clear(cpu, map);
  1052. fixup_irqs(map);
  1053. /* It's now safe to remove this processor from the online map */
  1054. cpu_clear(cpu, cpu_online_map);
  1055. return 0;
  1056. }
  1057. void __cpu_die(unsigned int cpu)
  1058. {
  1059. /* We don't do anything here: idle task is faking death itself. */
  1060. unsigned int i;
  1061. for (i = 0; i < 10; i++) {
  1062. /* They ack this in play_dead by setting CPU_DEAD */
  1063. if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
  1064. printk ("CPU %d is now offline\n", cpu);
  1065. if (1 == num_online_cpus())
  1066. alternatives_smp_switch(0);
  1067. return;
  1068. }
  1069. msleep(100);
  1070. }
  1071. printk(KERN_ERR "CPU %u didn't die...\n", cpu);
  1072. }
  1073. #else /* ... !CONFIG_HOTPLUG_CPU */
  1074. int __cpu_disable(void)
  1075. {
  1076. return -ENOSYS;
  1077. }
  1078. void __cpu_die(unsigned int cpu)
  1079. {
  1080. /* We said "no" in __cpu_disable */
  1081. BUG();
  1082. }
  1083. #endif /* CONFIG_HOTPLUG_CPU */
  1084. int __cpuinit __cpu_up(unsigned int cpu)
  1085. {
  1086. unsigned long flags;
  1087. #ifdef CONFIG_HOTPLUG_CPU
  1088. int ret = 0;
  1089. /*
  1090. * We do warm boot only on cpus that had booted earlier
  1091. * Otherwise cold boot is all handled from smp_boot_cpus().
  1092. * cpu_callin_map is set during AP kickstart process. Its reset
  1093. * when a cpu is taken offline from cpu_exit_clear().
  1094. */
  1095. if (!cpu_isset(cpu, cpu_callin_map))
  1096. ret = __smp_prepare_cpu(cpu);
  1097. if (ret)
  1098. return -EIO;
  1099. #endif
  1100. /* In case one didn't come up */
  1101. if (!cpu_isset(cpu, cpu_callin_map)) {
  1102. printk(KERN_DEBUG "skipping cpu%d, didn't come online\n", cpu);
  1103. return -EIO;
  1104. }
  1105. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  1106. /* Unleash the CPU! */
  1107. cpu_set(cpu, smp_commenced_mask);
  1108. /*
  1109. * Check TSC synchronization with the AP (keep irqs disabled
  1110. * while doing so):
  1111. */
  1112. local_irq_save(flags);
  1113. check_tsc_sync_source(cpu);
  1114. local_irq_restore(flags);
  1115. while (!cpu_isset(cpu, cpu_online_map)) {
  1116. cpu_relax();
  1117. touch_nmi_watchdog();
  1118. }
  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);