apic.c 32 KB

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