apic.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. /*
  2. * Local APIC handling, local APIC timers
  3. *
  4. * (c) 1999, 2000 Ingo Molnar <mingo@redhat.com>
  5. *
  6. * Fixes
  7. * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
  8. * thanks to Eric Gilmore
  9. * and Rolf G. Tews
  10. * for testing these extensively.
  11. * Maciej W. Rozycki : Various updates and fixes.
  12. * Mikael Pettersson : Power Management for UP-APIC.
  13. * Pavel Machek and
  14. * Mikael Pettersson : PM converted to driver model.
  15. */
  16. #include <linux/config.h>
  17. #include <linux/init.h>
  18. #include <linux/mm.h>
  19. #include <linux/delay.h>
  20. #include <linux/bootmem.h>
  21. #include <linux/smp_lock.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/mc146818rtc.h>
  24. #include <linux/kernel_stat.h>
  25. #include <linux/sysdev.h>
  26. #include <linux/cpu.h>
  27. #include <asm/atomic.h>
  28. #include <asm/smp.h>
  29. #include <asm/mtrr.h>
  30. #include <asm/mpspec.h>
  31. #include <asm/desc.h>
  32. #include <asm/arch_hooks.h>
  33. #include <asm/hpet.h>
  34. #include <asm/i8253.h>
  35. #include <mach_apic.h>
  36. #include "io_ports.h"
  37. /*
  38. * Knob to control our willingness to enable the local APIC.
  39. */
  40. int enable_local_apic __initdata = 0; /* -1=force-disable, +1=force-enable */
  41. /*
  42. * Debug level
  43. */
  44. int apic_verbosity;
  45. static void apic_pm_activate(void);
  46. /*
  47. * 'what should we do if we get a hw irq event on an illegal vector'.
  48. * each architecture has to answer this themselves.
  49. */
  50. void ack_bad_irq(unsigned int irq)
  51. {
  52. printk("unexpected IRQ trap at vector %02x\n", irq);
  53. /*
  54. * Currently unexpected vectors happen only on SMP and APIC.
  55. * We _must_ ack these because every local APIC has only N
  56. * irq slots per priority level, and a 'hanging, unacked' IRQ
  57. * holds up an irq slot - in excessive cases (when multiple
  58. * unexpected vectors occur) that might lock up the APIC
  59. * completely.
  60. */
  61. ack_APIC_irq();
  62. }
  63. void __init apic_intr_init(void)
  64. {
  65. #ifdef CONFIG_SMP
  66. smp_intr_init();
  67. #endif
  68. /* self generated IPI for local APIC timer */
  69. set_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
  70. /* IPI vectors for APIC spurious and error interrupts */
  71. set_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
  72. set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
  73. /* thermal monitor LVT interrupt */
  74. #ifdef CONFIG_X86_MCE_P4THERMAL
  75. set_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
  76. #endif
  77. }
  78. /* Using APIC to generate smp_local_timer_interrupt? */
  79. int using_apic_timer = 0;
  80. static DEFINE_PER_CPU(int, prof_multiplier) = 1;
  81. static DEFINE_PER_CPU(int, prof_old_multiplier) = 1;
  82. static DEFINE_PER_CPU(int, prof_counter) = 1;
  83. static int enabled_via_apicbase;
  84. void enable_NMI_through_LVT0 (void * dummy)
  85. {
  86. unsigned int v, ver;
  87. ver = apic_read(APIC_LVR);
  88. ver = GET_APIC_VERSION(ver);
  89. v = APIC_DM_NMI; /* unmask and set to NMI */
  90. if (!APIC_INTEGRATED(ver)) /* 82489DX */
  91. v |= APIC_LVT_LEVEL_TRIGGER;
  92. apic_write_around(APIC_LVT0, v);
  93. }
  94. int get_physical_broadcast(void)
  95. {
  96. unsigned int lvr, version;
  97. lvr = apic_read(APIC_LVR);
  98. version = GET_APIC_VERSION(lvr);
  99. if (!APIC_INTEGRATED(version) || version >= 0x14)
  100. return 0xff;
  101. else
  102. return 0xf;
  103. }
  104. int get_maxlvt(void)
  105. {
  106. unsigned int v, ver, maxlvt;
  107. v = apic_read(APIC_LVR);
  108. ver = GET_APIC_VERSION(v);
  109. /* 82489DXs do not report # of LVT entries. */
  110. maxlvt = APIC_INTEGRATED(ver) ? GET_APIC_MAXLVT(v) : 2;
  111. return maxlvt;
  112. }
  113. void clear_local_APIC(void)
  114. {
  115. int maxlvt;
  116. unsigned long v;
  117. maxlvt = get_maxlvt();
  118. /*
  119. * Masking an LVT entry on a P6 can trigger a local APIC error
  120. * if the vector is zero. Mask LVTERR first to prevent this.
  121. */
  122. if (maxlvt >= 3) {
  123. v = ERROR_APIC_VECTOR; /* any non-zero vector will do */
  124. apic_write_around(APIC_LVTERR, v | APIC_LVT_MASKED);
  125. }
  126. /*
  127. * Careful: we have to set masks only first to deassert
  128. * any level-triggered sources.
  129. */
  130. v = apic_read(APIC_LVTT);
  131. apic_write_around(APIC_LVTT, v | APIC_LVT_MASKED);
  132. v = apic_read(APIC_LVT0);
  133. apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);
  134. v = apic_read(APIC_LVT1);
  135. apic_write_around(APIC_LVT1, v | APIC_LVT_MASKED);
  136. if (maxlvt >= 4) {
  137. v = apic_read(APIC_LVTPC);
  138. apic_write_around(APIC_LVTPC, v | APIC_LVT_MASKED);
  139. }
  140. /* lets not touch this if we didn't frob it */
  141. #ifdef CONFIG_X86_MCE_P4THERMAL
  142. if (maxlvt >= 5) {
  143. v = apic_read(APIC_LVTTHMR);
  144. apic_write_around(APIC_LVTTHMR, v | APIC_LVT_MASKED);
  145. }
  146. #endif
  147. /*
  148. * Clean APIC state for other OSs:
  149. */
  150. apic_write_around(APIC_LVTT, APIC_LVT_MASKED);
  151. apic_write_around(APIC_LVT0, APIC_LVT_MASKED);
  152. apic_write_around(APIC_LVT1, APIC_LVT_MASKED);
  153. if (maxlvt >= 3)
  154. apic_write_around(APIC_LVTERR, APIC_LVT_MASKED);
  155. if (maxlvt >= 4)
  156. apic_write_around(APIC_LVTPC, APIC_LVT_MASKED);
  157. #ifdef CONFIG_X86_MCE_P4THERMAL
  158. if (maxlvt >= 5)
  159. apic_write_around(APIC_LVTTHMR, APIC_LVT_MASKED);
  160. #endif
  161. v = GET_APIC_VERSION(apic_read(APIC_LVR));
  162. if (APIC_INTEGRATED(v)) { /* !82489DX */
  163. if (maxlvt > 3) /* Due to Pentium errata 3AP and 11AP. */
  164. apic_write(APIC_ESR, 0);
  165. apic_read(APIC_ESR);
  166. }
  167. }
  168. void __init connect_bsp_APIC(void)
  169. {
  170. if (pic_mode) {
  171. /*
  172. * Do not trust the local APIC being empty at bootup.
  173. */
  174. clear_local_APIC();
  175. /*
  176. * PIC mode, enable APIC mode in the IMCR, i.e.
  177. * connect BSP's local APIC to INT and NMI lines.
  178. */
  179. apic_printk(APIC_VERBOSE, "leaving PIC mode, "
  180. "enabling APIC mode.\n");
  181. outb(0x70, 0x22);
  182. outb(0x01, 0x23);
  183. }
  184. enable_apic_mode();
  185. }
  186. void disconnect_bsp_APIC(int virt_wire_setup)
  187. {
  188. if (pic_mode) {
  189. /*
  190. * Put the board back into PIC mode (has an effect
  191. * only on certain older boards). Note that APIC
  192. * interrupts, including IPIs, won't work beyond
  193. * this point! The only exception are INIT IPIs.
  194. */
  195. apic_printk(APIC_VERBOSE, "disabling APIC mode, "
  196. "entering PIC mode.\n");
  197. outb(0x70, 0x22);
  198. outb(0x00, 0x23);
  199. }
  200. else {
  201. /* Go back to Virtual Wire compatibility mode */
  202. unsigned long value;
  203. /* For the spurious interrupt use vector F, and enable it */
  204. value = apic_read(APIC_SPIV);
  205. value &= ~APIC_VECTOR_MASK;
  206. value |= APIC_SPIV_APIC_ENABLED;
  207. value |= 0xf;
  208. apic_write_around(APIC_SPIV, value);
  209. if (!virt_wire_setup) {
  210. /* For LVT0 make it edge triggered, active high, external and enabled */
  211. value = apic_read(APIC_LVT0);
  212. value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
  213. APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
  214. APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED );
  215. value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
  216. value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT);
  217. apic_write_around(APIC_LVT0, value);
  218. }
  219. else {
  220. /* Disable LVT0 */
  221. apic_write_around(APIC_LVT0, APIC_LVT_MASKED);
  222. }
  223. /* For LVT1 make it edge triggered, active high, nmi and enabled */
  224. value = apic_read(APIC_LVT1);
  225. value &= ~(
  226. APIC_MODE_MASK | APIC_SEND_PENDING |
  227. APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
  228. APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
  229. value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
  230. value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI);
  231. apic_write_around(APIC_LVT1, value);
  232. }
  233. }
  234. void disable_local_APIC(void)
  235. {
  236. unsigned long value;
  237. clear_local_APIC();
  238. /*
  239. * Disable APIC (implies clearing of registers
  240. * for 82489DX!).
  241. */
  242. value = apic_read(APIC_SPIV);
  243. value &= ~APIC_SPIV_APIC_ENABLED;
  244. apic_write_around(APIC_SPIV, value);
  245. if (enabled_via_apicbase) {
  246. unsigned int l, h;
  247. rdmsr(MSR_IA32_APICBASE, l, h);
  248. l &= ~MSR_IA32_APICBASE_ENABLE;
  249. wrmsr(MSR_IA32_APICBASE, l, h);
  250. }
  251. }
  252. /*
  253. * This is to verify that we're looking at a real local APIC.
  254. * Check these against your board if the CPUs aren't getting
  255. * started for no apparent reason.
  256. */
  257. int __init verify_local_APIC(void)
  258. {
  259. unsigned int reg0, reg1;
  260. /*
  261. * The version register is read-only in a real APIC.
  262. */
  263. reg0 = apic_read(APIC_LVR);
  264. apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0);
  265. apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK);
  266. reg1 = apic_read(APIC_LVR);
  267. apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1);
  268. /*
  269. * The two version reads above should print the same
  270. * numbers. If the second one is different, then we
  271. * poke at a non-APIC.
  272. */
  273. if (reg1 != reg0)
  274. return 0;
  275. /*
  276. * Check if the version looks reasonably.
  277. */
  278. reg1 = GET_APIC_VERSION(reg0);
  279. if (reg1 == 0x00 || reg1 == 0xff)
  280. return 0;
  281. reg1 = get_maxlvt();
  282. if (reg1 < 0x02 || reg1 == 0xff)
  283. return 0;
  284. /*
  285. * The ID register is read/write in a real APIC.
  286. */
  287. reg0 = apic_read(APIC_ID);
  288. apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0);
  289. /*
  290. * The next two are just to see if we have sane values.
  291. * They're only really relevant if we're in Virtual Wire
  292. * compatibility mode, but most boxes are anymore.
  293. */
  294. reg0 = apic_read(APIC_LVT0);
  295. apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0);
  296. reg1 = apic_read(APIC_LVT1);
  297. apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1);
  298. return 1;
  299. }
  300. void __init sync_Arb_IDs(void)
  301. {
  302. /* Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 */
  303. unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR));
  304. if (ver >= 0x14) /* P4 or higher */
  305. return;
  306. /*
  307. * Wait for idle.
  308. */
  309. apic_wait_icr_idle();
  310. apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n");
  311. apic_write_around(APIC_ICR, APIC_DEST_ALLINC | APIC_INT_LEVELTRIG
  312. | APIC_DM_INIT);
  313. }
  314. extern void __error_in_apic_c (void);
  315. /*
  316. * An initial setup of the virtual wire mode.
  317. */
  318. void __init init_bsp_APIC(void)
  319. {
  320. unsigned long value, ver;
  321. /*
  322. * Don't do the setup now if we have a SMP BIOS as the
  323. * through-I/O-APIC virtual wire mode might be active.
  324. */
  325. if (smp_found_config || !cpu_has_apic)
  326. return;
  327. value = apic_read(APIC_LVR);
  328. ver = GET_APIC_VERSION(value);
  329. /*
  330. * Do not trust the local APIC being empty at bootup.
  331. */
  332. clear_local_APIC();
  333. /*
  334. * Enable APIC.
  335. */
  336. value = apic_read(APIC_SPIV);
  337. value &= ~APIC_VECTOR_MASK;
  338. value |= APIC_SPIV_APIC_ENABLED;
  339. /* This bit is reserved on P4/Xeon and should be cleared */
  340. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) && (boot_cpu_data.x86 == 15))
  341. value &= ~APIC_SPIV_FOCUS_DISABLED;
  342. else
  343. value |= APIC_SPIV_FOCUS_DISABLED;
  344. value |= SPURIOUS_APIC_VECTOR;
  345. apic_write_around(APIC_SPIV, value);
  346. /*
  347. * Set up the virtual wire mode.
  348. */
  349. apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
  350. value = APIC_DM_NMI;
  351. if (!APIC_INTEGRATED(ver)) /* 82489DX */
  352. value |= APIC_LVT_LEVEL_TRIGGER;
  353. apic_write_around(APIC_LVT1, value);
  354. }
  355. void __devinit setup_local_APIC(void)
  356. {
  357. unsigned long oldvalue, value, ver, maxlvt;
  358. /* Pound the ESR really hard over the head with a big hammer - mbligh */
  359. if (esr_disable) {
  360. apic_write(APIC_ESR, 0);
  361. apic_write(APIC_ESR, 0);
  362. apic_write(APIC_ESR, 0);
  363. apic_write(APIC_ESR, 0);
  364. }
  365. value = apic_read(APIC_LVR);
  366. ver = GET_APIC_VERSION(value);
  367. if ((SPURIOUS_APIC_VECTOR & 0x0f) != 0x0f)
  368. __error_in_apic_c();
  369. /*
  370. * Double-check whether this APIC is really registered.
  371. */
  372. if (!apic_id_registered())
  373. BUG();
  374. /*
  375. * Intel recommends to set DFR, LDR and TPR before enabling
  376. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  377. * document number 292116). So here it goes...
  378. */
  379. init_apic_ldr();
  380. /*
  381. * Set Task Priority to 'accept all'. We never change this
  382. * later on.
  383. */
  384. value = apic_read(APIC_TASKPRI);
  385. value &= ~APIC_TPRI_MASK;
  386. apic_write_around(APIC_TASKPRI, value);
  387. /*
  388. * Now that we are all set up, enable the APIC
  389. */
  390. value = apic_read(APIC_SPIV);
  391. value &= ~APIC_VECTOR_MASK;
  392. /*
  393. * Enable APIC
  394. */
  395. value |= APIC_SPIV_APIC_ENABLED;
  396. /*
  397. * Some unknown Intel IO/APIC (or APIC) errata is biting us with
  398. * certain networking cards. If high frequency interrupts are
  399. * happening on a particular IOAPIC pin, plus the IOAPIC routing
  400. * entry is masked/unmasked at a high rate as well then sooner or
  401. * later IOAPIC line gets 'stuck', no more interrupts are received
  402. * from the device. If focus CPU is disabled then the hang goes
  403. * away, oh well :-(
  404. *
  405. * [ This bug can be reproduced easily with a level-triggered
  406. * PCI Ne2000 networking cards and PII/PIII processors, dual
  407. * BX chipset. ]
  408. */
  409. /*
  410. * Actually disabling the focus CPU check just makes the hang less
  411. * frequent as it makes the interrupt distributon model be more
  412. * like LRU than MRU (the short-term load is more even across CPUs).
  413. * See also the comment in end_level_ioapic_irq(). --macro
  414. */
  415. #if 1
  416. /* Enable focus processor (bit==0) */
  417. value &= ~APIC_SPIV_FOCUS_DISABLED;
  418. #else
  419. /* Disable focus processor (bit==1) */
  420. value |= APIC_SPIV_FOCUS_DISABLED;
  421. #endif
  422. /*
  423. * Set spurious IRQ vector
  424. */
  425. value |= SPURIOUS_APIC_VECTOR;
  426. apic_write_around(APIC_SPIV, value);
  427. /*
  428. * Set up LVT0, LVT1:
  429. *
  430. * set up through-local-APIC on the BP's LINT0. This is not
  431. * strictly necessery in pure symmetric-IO mode, but sometimes
  432. * we delegate interrupts to the 8259A.
  433. */
  434. /*
  435. * TODO: set up through-local-APIC from through-I/O-APIC? --macro
  436. */
  437. value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
  438. if (!smp_processor_id() && (pic_mode || !value)) {
  439. value = APIC_DM_EXTINT;
  440. apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
  441. smp_processor_id());
  442. } else {
  443. value = APIC_DM_EXTINT | APIC_LVT_MASKED;
  444. apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n",
  445. smp_processor_id());
  446. }
  447. apic_write_around(APIC_LVT0, value);
  448. /*
  449. * only the BP should see the LINT1 NMI signal, obviously.
  450. */
  451. if (!smp_processor_id())
  452. value = APIC_DM_NMI;
  453. else
  454. value = APIC_DM_NMI | APIC_LVT_MASKED;
  455. if (!APIC_INTEGRATED(ver)) /* 82489DX */
  456. value |= APIC_LVT_LEVEL_TRIGGER;
  457. apic_write_around(APIC_LVT1, value);
  458. if (APIC_INTEGRATED(ver) && !esr_disable) { /* !82489DX */
  459. maxlvt = get_maxlvt();
  460. if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
  461. apic_write(APIC_ESR, 0);
  462. oldvalue = apic_read(APIC_ESR);
  463. value = ERROR_APIC_VECTOR; // enables sending errors
  464. apic_write_around(APIC_LVTERR, value);
  465. /*
  466. * spec says clear errors after enabling vector.
  467. */
  468. if (maxlvt > 3)
  469. apic_write(APIC_ESR, 0);
  470. value = apic_read(APIC_ESR);
  471. if (value != oldvalue)
  472. apic_printk(APIC_VERBOSE, "ESR value before enabling "
  473. "vector: 0x%08lx after: 0x%08lx\n",
  474. oldvalue, value);
  475. } else {
  476. if (esr_disable)
  477. /*
  478. * Something untraceble is creating bad interrupts on
  479. * secondary quads ... for the moment, just leave the
  480. * ESR disabled - we can't do anything useful with the
  481. * errors anyway - mbligh
  482. */
  483. printk("Leaving ESR disabled.\n");
  484. else
  485. printk("No ESR for 82489DX.\n");
  486. }
  487. if (nmi_watchdog == NMI_LOCAL_APIC)
  488. setup_apic_nmi_watchdog();
  489. apic_pm_activate();
  490. }
  491. /*
  492. * If Linux enabled the LAPIC against the BIOS default
  493. * disable it down before re-entering the BIOS on shutdown.
  494. * Otherwise the BIOS may get confused and not power-off.
  495. */
  496. void lapic_shutdown(void)
  497. {
  498. if (!cpu_has_apic || !enabled_via_apicbase)
  499. return;
  500. local_irq_disable();
  501. disable_local_APIC();
  502. local_irq_enable();
  503. }
  504. #ifdef CONFIG_PM
  505. static struct {
  506. int active;
  507. /* r/w apic fields */
  508. unsigned int apic_id;
  509. unsigned int apic_taskpri;
  510. unsigned int apic_ldr;
  511. unsigned int apic_dfr;
  512. unsigned int apic_spiv;
  513. unsigned int apic_lvtt;
  514. unsigned int apic_lvtpc;
  515. unsigned int apic_lvt0;
  516. unsigned int apic_lvt1;
  517. unsigned int apic_lvterr;
  518. unsigned int apic_tmict;
  519. unsigned int apic_tdcr;
  520. unsigned int apic_thmr;
  521. } apic_pm_state;
  522. static int lapic_suspend(struct sys_device *dev, pm_message_t state)
  523. {
  524. unsigned long flags;
  525. if (!apic_pm_state.active)
  526. return 0;
  527. apic_pm_state.apic_id = apic_read(APIC_ID);
  528. apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI);
  529. apic_pm_state.apic_ldr = apic_read(APIC_LDR);
  530. apic_pm_state.apic_dfr = apic_read(APIC_DFR);
  531. apic_pm_state.apic_spiv = apic_read(APIC_SPIV);
  532. apic_pm_state.apic_lvtt = apic_read(APIC_LVTT);
  533. apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC);
  534. apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0);
  535. apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1);
  536. apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR);
  537. apic_pm_state.apic_tmict = apic_read(APIC_TMICT);
  538. apic_pm_state.apic_tdcr = apic_read(APIC_TDCR);
  539. apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR);
  540. local_irq_save(flags);
  541. disable_local_APIC();
  542. local_irq_restore(flags);
  543. return 0;
  544. }
  545. static int lapic_resume(struct sys_device *dev)
  546. {
  547. unsigned int l, h;
  548. unsigned long flags;
  549. if (!apic_pm_state.active)
  550. return 0;
  551. local_irq_save(flags);
  552. /*
  553. * Make sure the APICBASE points to the right address
  554. *
  555. * FIXME! This will be wrong if we ever support suspend on
  556. * SMP! We'll need to do this as part of the CPU restore!
  557. */
  558. rdmsr(MSR_IA32_APICBASE, l, h);
  559. l &= ~MSR_IA32_APICBASE_BASE;
  560. l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
  561. wrmsr(MSR_IA32_APICBASE, l, h);
  562. apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED);
  563. apic_write(APIC_ID, apic_pm_state.apic_id);
  564. apic_write(APIC_DFR, apic_pm_state.apic_dfr);
  565. apic_write(APIC_LDR, apic_pm_state.apic_ldr);
  566. apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri);
  567. apic_write(APIC_SPIV, apic_pm_state.apic_spiv);
  568. apic_write(APIC_LVT0, apic_pm_state.apic_lvt0);
  569. apic_write(APIC_LVT1, apic_pm_state.apic_lvt1);
  570. apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr);
  571. apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc);
  572. apic_write(APIC_LVTT, apic_pm_state.apic_lvtt);
  573. apic_write(APIC_TDCR, apic_pm_state.apic_tdcr);
  574. apic_write(APIC_TMICT, apic_pm_state.apic_tmict);
  575. apic_write(APIC_ESR, 0);
  576. apic_read(APIC_ESR);
  577. apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr);
  578. apic_write(APIC_ESR, 0);
  579. apic_read(APIC_ESR);
  580. local_irq_restore(flags);
  581. return 0;
  582. }
  583. /*
  584. * This device has no shutdown method - fully functioning local APICs
  585. * are needed on every CPU up until machine_halt/restart/poweroff.
  586. */
  587. static struct sysdev_class lapic_sysclass = {
  588. set_kset_name("lapic"),
  589. .resume = lapic_resume,
  590. .suspend = lapic_suspend,
  591. };
  592. static struct sys_device device_lapic = {
  593. .id = 0,
  594. .cls = &lapic_sysclass,
  595. };
  596. static void __devinit apic_pm_activate(void)
  597. {
  598. apic_pm_state.active = 1;
  599. }
  600. static int __init init_lapic_sysfs(void)
  601. {
  602. int error;
  603. if (!cpu_has_apic)
  604. return 0;
  605. /* XXX: remove suspend/resume procs if !apic_pm_state.active? */
  606. error = sysdev_class_register(&lapic_sysclass);
  607. if (!error)
  608. error = sysdev_register(&device_lapic);
  609. return error;
  610. }
  611. device_initcall(init_lapic_sysfs);
  612. #else /* CONFIG_PM */
  613. static void apic_pm_activate(void) { }
  614. #endif /* CONFIG_PM */
  615. /*
  616. * Detect and enable local APICs on non-SMP boards.
  617. * Original code written by Keir Fraser.
  618. */
  619. static int __init apic_set_verbosity(char *str)
  620. {
  621. if (strcmp("debug", str) == 0)
  622. apic_verbosity = APIC_DEBUG;
  623. else if (strcmp("verbose", str) == 0)
  624. apic_verbosity = APIC_VERBOSE;
  625. else
  626. printk(KERN_WARNING "APIC Verbosity level %s not recognised"
  627. " use apic=verbose or apic=debug", str);
  628. return 0;
  629. }
  630. __setup("apic=", apic_set_verbosity);
  631. static int __init detect_init_APIC (void)
  632. {
  633. u32 h, l, features;
  634. /* Disabled by kernel option? */
  635. if (enable_local_apic < 0)
  636. return -1;
  637. switch (boot_cpu_data.x86_vendor) {
  638. case X86_VENDOR_AMD:
  639. if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model > 1) ||
  640. (boot_cpu_data.x86 == 15))
  641. break;
  642. goto no_apic;
  643. case X86_VENDOR_INTEL:
  644. if (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15 ||
  645. (boot_cpu_data.x86 == 5 && cpu_has_apic))
  646. break;
  647. goto no_apic;
  648. default:
  649. goto no_apic;
  650. }
  651. if (!cpu_has_apic) {
  652. /*
  653. * Over-ride BIOS and try to enable the local
  654. * APIC only if "lapic" specified.
  655. */
  656. if (enable_local_apic <= 0) {
  657. printk("Local APIC disabled by BIOS -- "
  658. "you can enable it with \"lapic\"\n");
  659. return -1;
  660. }
  661. /*
  662. * Some BIOSes disable the local APIC in the
  663. * APIC_BASE MSR. This can only be done in
  664. * software for Intel P6 or later and AMD K7
  665. * (Model > 1) or later.
  666. */
  667. rdmsr(MSR_IA32_APICBASE, l, h);
  668. if (!(l & MSR_IA32_APICBASE_ENABLE)) {
  669. printk("Local APIC disabled by BIOS -- reenabling.\n");
  670. l &= ~MSR_IA32_APICBASE_BASE;
  671. l |= MSR_IA32_APICBASE_ENABLE | APIC_DEFAULT_PHYS_BASE;
  672. wrmsr(MSR_IA32_APICBASE, l, h);
  673. enabled_via_apicbase = 1;
  674. }
  675. }
  676. /*
  677. * The APIC feature bit should now be enabled
  678. * in `cpuid'
  679. */
  680. features = cpuid_edx(1);
  681. if (!(features & (1 << X86_FEATURE_APIC))) {
  682. printk("Could not enable APIC!\n");
  683. return -1;
  684. }
  685. set_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
  686. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  687. /* The BIOS may have set up the APIC at some other address */
  688. rdmsr(MSR_IA32_APICBASE, l, h);
  689. if (l & MSR_IA32_APICBASE_ENABLE)
  690. mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
  691. if (nmi_watchdog != NMI_NONE)
  692. nmi_watchdog = NMI_LOCAL_APIC;
  693. printk("Found and enabled local APIC!\n");
  694. apic_pm_activate();
  695. return 0;
  696. no_apic:
  697. printk("No local APIC present or hardware disabled\n");
  698. return -1;
  699. }
  700. void __init init_apic_mappings(void)
  701. {
  702. unsigned long apic_phys;
  703. /*
  704. * If no local APIC can be found then set up a fake all
  705. * zeroes page to simulate the local APIC and another
  706. * one for the IO-APIC.
  707. */
  708. if (!smp_found_config && detect_init_APIC()) {
  709. apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  710. apic_phys = __pa(apic_phys);
  711. } else
  712. apic_phys = mp_lapic_addr;
  713. set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
  714. printk(KERN_DEBUG "mapped APIC to %08lx (%08lx)\n", APIC_BASE,
  715. apic_phys);
  716. /*
  717. * Fetch the APIC ID of the BSP in case we have a
  718. * default configuration (or the MP table is broken).
  719. */
  720. if (boot_cpu_physical_apicid == -1U)
  721. boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  722. #ifdef CONFIG_X86_IO_APIC
  723. {
  724. unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
  725. int i;
  726. for (i = 0; i < nr_ioapics; i++) {
  727. if (smp_found_config) {
  728. ioapic_phys = mp_ioapics[i].mpc_apicaddr;
  729. if (!ioapic_phys) {
  730. printk(KERN_ERR
  731. "WARNING: bogus zero IO-APIC "
  732. "address found in MPTABLE, "
  733. "disabling IO/APIC support!\n");
  734. smp_found_config = 0;
  735. skip_ioapic_setup = 1;
  736. goto fake_ioapic_page;
  737. }
  738. } else {
  739. fake_ioapic_page:
  740. ioapic_phys = (unsigned long)
  741. alloc_bootmem_pages(PAGE_SIZE);
  742. ioapic_phys = __pa(ioapic_phys);
  743. }
  744. set_fixmap_nocache(idx, ioapic_phys);
  745. printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
  746. __fix_to_virt(idx), ioapic_phys);
  747. idx++;
  748. }
  749. }
  750. #endif
  751. }
  752. /*
  753. * This part sets up the APIC 32 bit clock in LVTT1, with HZ interrupts
  754. * per second. We assume that the caller has already set up the local
  755. * APIC.
  756. *
  757. * The APIC timer is not exactly sync with the external timer chip, it
  758. * closely follows bus clocks.
  759. */
  760. /*
  761. * The timer chip is already set up at HZ interrupts per second here,
  762. * but we do not accept timer interrupts yet. We only allow the BP
  763. * to calibrate.
  764. */
  765. static unsigned int __devinit get_8254_timer_count(void)
  766. {
  767. unsigned long flags;
  768. unsigned int count;
  769. spin_lock_irqsave(&i8253_lock, flags);
  770. outb_p(0x00, PIT_MODE);
  771. count = inb_p(PIT_CH0);
  772. count |= inb_p(PIT_CH0) << 8;
  773. spin_unlock_irqrestore(&i8253_lock, flags);
  774. return count;
  775. }
  776. /* next tick in 8254 can be caught by catching timer wraparound */
  777. static void __devinit wait_8254_wraparound(void)
  778. {
  779. unsigned int curr_count, prev_count;
  780. curr_count = get_8254_timer_count();
  781. do {
  782. prev_count = curr_count;
  783. curr_count = get_8254_timer_count();
  784. /* workaround for broken Mercury/Neptune */
  785. if (prev_count >= curr_count + 0x100)
  786. curr_count = get_8254_timer_count();
  787. } while (prev_count >= curr_count);
  788. }
  789. /*
  790. * Default initialization for 8254 timers. If we use other timers like HPET,
  791. * we override this later
  792. */
  793. void (*wait_timer_tick)(void) __devinitdata = wait_8254_wraparound;
  794. /*
  795. * This function sets up the local APIC timer, with a timeout of
  796. * 'clocks' APIC bus clock. During calibration we actually call
  797. * this function twice on the boot CPU, once with a bogus timeout
  798. * value, second time for real. The other (noncalibrating) CPUs
  799. * call this function only once, with the real, calibrated value.
  800. *
  801. * We do reads before writes even if unnecessary, to get around the
  802. * P5 APIC double write bug.
  803. */
  804. #define APIC_DIVISOR 16
  805. static void __setup_APIC_LVTT(unsigned int clocks)
  806. {
  807. unsigned int lvtt_value, tmp_value, ver;
  808. ver = GET_APIC_VERSION(apic_read(APIC_LVR));
  809. lvtt_value = APIC_LVT_TIMER_PERIODIC | LOCAL_TIMER_VECTOR;
  810. if (!APIC_INTEGRATED(ver))
  811. lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
  812. apic_write_around(APIC_LVTT, lvtt_value);
  813. /*
  814. * Divide PICLK by 16
  815. */
  816. tmp_value = apic_read(APIC_TDCR);
  817. apic_write_around(APIC_TDCR, (tmp_value
  818. & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE))
  819. | APIC_TDR_DIV_16);
  820. apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR);
  821. }
  822. static void __devinit setup_APIC_timer(unsigned int clocks)
  823. {
  824. unsigned long flags;
  825. local_irq_save(flags);
  826. /*
  827. * Wait for IRQ0's slice:
  828. */
  829. wait_timer_tick();
  830. __setup_APIC_LVTT(clocks);
  831. local_irq_restore(flags);
  832. }
  833. /*
  834. * In this function we calibrate APIC bus clocks to the external
  835. * timer. Unfortunately we cannot use jiffies and the timer irq
  836. * to calibrate, since some later bootup code depends on getting
  837. * the first irq? Ugh.
  838. *
  839. * We want to do the calibration only once since we
  840. * want to have local timer irqs syncron. CPUs connected
  841. * by the same APIC bus have the very same bus frequency.
  842. * And we want to have irqs off anyways, no accidental
  843. * APIC irq that way.
  844. */
  845. static int __init calibrate_APIC_clock(void)
  846. {
  847. unsigned long long t1 = 0, t2 = 0;
  848. long tt1, tt2;
  849. long result;
  850. int i;
  851. const int LOOPS = HZ/10;
  852. apic_printk(APIC_VERBOSE, "calibrating APIC timer ...\n");
  853. /*
  854. * Put whatever arbitrary (but long enough) timeout
  855. * value into the APIC clock, we just want to get the
  856. * counter running for calibration.
  857. */
  858. __setup_APIC_LVTT(1000000000);
  859. /*
  860. * The timer chip counts down to zero. Let's wait
  861. * for a wraparound to start exact measurement:
  862. * (the current tick might have been already half done)
  863. */
  864. wait_timer_tick();
  865. /*
  866. * We wrapped around just now. Let's start:
  867. */
  868. if (cpu_has_tsc)
  869. rdtscll(t1);
  870. tt1 = apic_read(APIC_TMCCT);
  871. /*
  872. * Let's wait LOOPS wraprounds:
  873. */
  874. for (i = 0; i < LOOPS; i++)
  875. wait_timer_tick();
  876. tt2 = apic_read(APIC_TMCCT);
  877. if (cpu_has_tsc)
  878. rdtscll(t2);
  879. /*
  880. * The APIC bus clock counter is 32 bits only, it
  881. * might have overflown, but note that we use signed
  882. * longs, thus no extra care needed.
  883. *
  884. * underflown to be exact, as the timer counts down ;)
  885. */
  886. result = (tt1-tt2)*APIC_DIVISOR/LOOPS;
  887. if (cpu_has_tsc)
  888. apic_printk(APIC_VERBOSE, "..... CPU clock speed is "
  889. "%ld.%04ld MHz.\n",
  890. ((long)(t2-t1)/LOOPS)/(1000000/HZ),
  891. ((long)(t2-t1)/LOOPS)%(1000000/HZ));
  892. apic_printk(APIC_VERBOSE, "..... host bus clock speed is "
  893. "%ld.%04ld MHz.\n",
  894. result/(1000000/HZ),
  895. result%(1000000/HZ));
  896. return result;
  897. }
  898. static unsigned int calibration_result;
  899. void __init setup_boot_APIC_clock(void)
  900. {
  901. apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n");
  902. using_apic_timer = 1;
  903. local_irq_disable();
  904. calibration_result = calibrate_APIC_clock();
  905. /*
  906. * Now set up the timer for real.
  907. */
  908. setup_APIC_timer(calibration_result);
  909. local_irq_enable();
  910. }
  911. void __devinit setup_secondary_APIC_clock(void)
  912. {
  913. setup_APIC_timer(calibration_result);
  914. }
  915. void __devinit disable_APIC_timer(void)
  916. {
  917. if (using_apic_timer) {
  918. unsigned long v;
  919. v = apic_read(APIC_LVTT);
  920. apic_write_around(APIC_LVTT, v | APIC_LVT_MASKED);
  921. }
  922. }
  923. void enable_APIC_timer(void)
  924. {
  925. if (using_apic_timer) {
  926. unsigned long v;
  927. v = apic_read(APIC_LVTT);
  928. apic_write_around(APIC_LVTT, v & ~APIC_LVT_MASKED);
  929. }
  930. }
  931. /*
  932. * the frequency of the profiling timer can be changed
  933. * by writing a multiplier value into /proc/profile.
  934. */
  935. int setup_profiling_timer(unsigned int multiplier)
  936. {
  937. int i;
  938. /*
  939. * Sanity check. [at least 500 APIC cycles should be
  940. * between APIC interrupts as a rule of thumb, to avoid
  941. * irqs flooding us]
  942. */
  943. if ( (!multiplier) || (calibration_result/multiplier < 500))
  944. return -EINVAL;
  945. /*
  946. * Set the new multiplier for each CPU. CPUs don't start using the
  947. * new values until the next timer interrupt in which they do process
  948. * accounting. At that time they also adjust their APIC timers
  949. * accordingly.
  950. */
  951. for (i = 0; i < NR_CPUS; ++i)
  952. per_cpu(prof_multiplier, i) = multiplier;
  953. return 0;
  954. }
  955. #undef APIC_DIVISOR
  956. /*
  957. * Local timer interrupt handler. It does both profiling and
  958. * process statistics/rescheduling.
  959. *
  960. * We do profiling in every local tick, statistics/rescheduling
  961. * happen only every 'profiling multiplier' ticks. The default
  962. * multiplier is 1 and it can be changed by writing the new multiplier
  963. * value into /proc/profile.
  964. */
  965. inline void smp_local_timer_interrupt(struct pt_regs * regs)
  966. {
  967. int cpu = smp_processor_id();
  968. profile_tick(CPU_PROFILING, regs);
  969. if (--per_cpu(prof_counter, cpu) <= 0) {
  970. /*
  971. * The multiplier may have changed since the last time we got
  972. * to this point as a result of the user writing to
  973. * /proc/profile. In this case we need to adjust the APIC
  974. * timer accordingly.
  975. *
  976. * Interrupts are already masked off at this point.
  977. */
  978. per_cpu(prof_counter, cpu) = per_cpu(prof_multiplier, cpu);
  979. if (per_cpu(prof_counter, cpu) !=
  980. per_cpu(prof_old_multiplier, cpu)) {
  981. __setup_APIC_LVTT(
  982. calibration_result/
  983. per_cpu(prof_counter, cpu));
  984. per_cpu(prof_old_multiplier, cpu) =
  985. per_cpu(prof_counter, cpu);
  986. }
  987. #ifdef CONFIG_SMP
  988. update_process_times(user_mode_vm(regs));
  989. #endif
  990. }
  991. /*
  992. * We take the 'long' return path, and there every subsystem
  993. * grabs the apropriate locks (kernel lock/ irq lock).
  994. *
  995. * we might want to decouple profiling from the 'long path',
  996. * and do the profiling totally in assembly.
  997. *
  998. * Currently this isn't too much of an issue (performance wise),
  999. * we can take more than 100K local irqs per second on a 100 MHz P5.
  1000. */
  1001. }
  1002. /*
  1003. * Local APIC timer interrupt. This is the most natural way for doing
  1004. * local interrupts, but local timer interrupts can be emulated by
  1005. * broadcast interrupts too. [in case the hw doesn't support APIC timers]
  1006. *
  1007. * [ if a single-CPU system runs an SMP kernel then we call the local
  1008. * interrupt as well. Thus we cannot inline the local irq ... ]
  1009. */
  1010. fastcall void smp_apic_timer_interrupt(struct pt_regs *regs)
  1011. {
  1012. int cpu = smp_processor_id();
  1013. /*
  1014. * the NMI deadlock-detector uses this.
  1015. */
  1016. per_cpu(irq_stat, cpu).apic_timer_irqs++;
  1017. /*
  1018. * NOTE! We'd better ACK the irq immediately,
  1019. * because timer handling can be slow.
  1020. */
  1021. ack_APIC_irq();
  1022. /*
  1023. * update_process_times() expects us to have done irq_enter().
  1024. * Besides, if we don't timer interrupts ignore the global
  1025. * interrupt lock, which is the WrongThing (tm) to do.
  1026. */
  1027. irq_enter();
  1028. smp_local_timer_interrupt(regs);
  1029. irq_exit();
  1030. }
  1031. /*
  1032. * This interrupt should _never_ happen with our APIC/SMP architecture
  1033. */
  1034. fastcall void smp_spurious_interrupt(struct pt_regs *regs)
  1035. {
  1036. unsigned long v;
  1037. irq_enter();
  1038. /*
  1039. * Check if this really is a spurious interrupt and ACK it
  1040. * if it is a vectored one. Just in case...
  1041. * Spurious interrupts should not be ACKed.
  1042. */
  1043. v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1));
  1044. if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f)))
  1045. ack_APIC_irq();
  1046. /* see sw-dev-man vol 3, chapter 7.4.13.5 */
  1047. printk(KERN_INFO "spurious APIC interrupt on CPU#%d, should never happen.\n",
  1048. smp_processor_id());
  1049. irq_exit();
  1050. }
  1051. /*
  1052. * This interrupt should never happen with our APIC/SMP architecture
  1053. */
  1054. fastcall void smp_error_interrupt(struct pt_regs *regs)
  1055. {
  1056. unsigned long v, v1;
  1057. irq_enter();
  1058. /* First tickle the hardware, only then report what went on. -- REW */
  1059. v = apic_read(APIC_ESR);
  1060. apic_write(APIC_ESR, 0);
  1061. v1 = apic_read(APIC_ESR);
  1062. ack_APIC_irq();
  1063. atomic_inc(&irq_err_count);
  1064. /* Here is what the APIC error bits mean:
  1065. 0: Send CS error
  1066. 1: Receive CS error
  1067. 2: Send accept error
  1068. 3: Receive accept error
  1069. 4: Reserved
  1070. 5: Send illegal vector
  1071. 6: Received illegal vector
  1072. 7: Illegal register address
  1073. */
  1074. printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
  1075. smp_processor_id(), v , v1);
  1076. irq_exit();
  1077. }
  1078. /*
  1079. * This initializes the IO-APIC and APIC hardware if this is
  1080. * a UP kernel.
  1081. */
  1082. int __init APIC_init_uniprocessor (void)
  1083. {
  1084. if (enable_local_apic < 0)
  1085. clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
  1086. if (!smp_found_config && !cpu_has_apic)
  1087. return -1;
  1088. /*
  1089. * Complain if the BIOS pretends there is one.
  1090. */
  1091. if (!cpu_has_apic && APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
  1092. printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
  1093. boot_cpu_physical_apicid);
  1094. return -1;
  1095. }
  1096. verify_local_APIC();
  1097. connect_bsp_APIC();
  1098. phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
  1099. setup_local_APIC();
  1100. #ifdef CONFIG_X86_IO_APIC
  1101. if (smp_found_config)
  1102. if (!skip_ioapic_setup && nr_ioapics)
  1103. setup_IO_APIC();
  1104. #endif
  1105. setup_boot_APIC_clock();
  1106. return 0;
  1107. }