apic.c 34 KB

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