apic.c 33 KB

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