apic.c 33 KB

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