apic.c 32 KB

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