apic_64.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  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/init.h>
  17. #include <linux/mm.h>
  18. #include <linux/delay.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/mc146818rtc.h>
  22. #include <linux/kernel_stat.h>
  23. #include <linux/sysdev.h>
  24. #include <linux/ioport.h>
  25. #include <linux/clockchips.h>
  26. #include <linux/acpi_pmtmr.h>
  27. #include <linux/module.h>
  28. #include <linux/dmar.h>
  29. #include <asm/atomic.h>
  30. #include <asm/smp.h>
  31. #include <asm/mtrr.h>
  32. #include <asm/mpspec.h>
  33. #include <asm/desc.h>
  34. #include <asm/hpet.h>
  35. #include <asm/pgalloc.h>
  36. #include <asm/nmi.h>
  37. #include <asm/idle.h>
  38. #include <asm/proto.h>
  39. #include <asm/timex.h>
  40. #include <asm/apic.h>
  41. #include <asm/i8259.h>
  42. #include <mach_ipi.h>
  43. #include <mach_apic.h>
  44. /*
  45. * Sanity check
  46. */
  47. #if ((SPURIOUS_APIC_VECTOR & 0x0F) != 0x0F)
  48. # error SPURIOUS_APIC_VECTOR definition error
  49. #endif
  50. #ifdef CONFIG_X86_32
  51. /*
  52. * Knob to control our willingness to enable the local APIC.
  53. *
  54. * +1=force-enable
  55. */
  56. static int force_enable_local_apic;
  57. /*
  58. * APIC command line parameters
  59. */
  60. static int __init parse_lapic(char *arg)
  61. {
  62. force_enable_local_apic = 1;
  63. return 0;
  64. }
  65. early_param("lapic", parse_lapic);
  66. #endif
  67. #ifdef CONFIG_X86_64
  68. static int apic_calibrate_pmtmr __initdata;
  69. static __init int setup_apicpmtimer(char *s)
  70. {
  71. apic_calibrate_pmtmr = 1;
  72. notsc_setup(NULL);
  73. return 0;
  74. }
  75. __setup("apicpmtimer", setup_apicpmtimer);
  76. #endif
  77. int disable_x2apic;
  78. int x2apic;
  79. /* x2apic enabled before OS handover */
  80. int x2apic_preenabled;
  81. unsigned long mp_lapic_addr;
  82. int disable_apic;
  83. /* Disable local APIC timer from the kernel commandline or via dmi quirk */
  84. static int disable_apic_timer __cpuinitdata;
  85. /* Local APIC timer works in C2 */
  86. int local_apic_timer_c2_ok;
  87. EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok);
  88. int first_system_vector = 0xfe;
  89. char system_vectors[NR_VECTORS] = { [0 ... NR_VECTORS-1] = SYS_VECTOR_FREE};
  90. /*
  91. * Debug level, exported for io_apic.c
  92. */
  93. unsigned int apic_verbosity;
  94. int pic_mode;
  95. /* Have we found an MP table */
  96. int smp_found_config;
  97. static struct resource lapic_resource = {
  98. .name = "Local APIC",
  99. .flags = IORESOURCE_MEM | IORESOURCE_BUSY,
  100. };
  101. static unsigned int calibration_result;
  102. static int lapic_next_event(unsigned long delta,
  103. struct clock_event_device *evt);
  104. static void lapic_timer_setup(enum clock_event_mode mode,
  105. struct clock_event_device *evt);
  106. static void lapic_timer_broadcast(cpumask_t mask);
  107. static void apic_pm_activate(void);
  108. /*
  109. * The local apic timer can be used for any function which is CPU local.
  110. */
  111. static struct clock_event_device lapic_clockevent = {
  112. .name = "lapic",
  113. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT
  114. | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY,
  115. .shift = 32,
  116. .set_mode = lapic_timer_setup,
  117. .set_next_event = lapic_next_event,
  118. .broadcast = lapic_timer_broadcast,
  119. .rating = 100,
  120. .irq = -1,
  121. };
  122. static DEFINE_PER_CPU(struct clock_event_device, lapic_events);
  123. static unsigned long apic_phys;
  124. /*
  125. * Get the LAPIC version
  126. */
  127. static inline int lapic_get_version(void)
  128. {
  129. return GET_APIC_VERSION(apic_read(APIC_LVR));
  130. }
  131. /*
  132. * Check, if the APIC is integrated or a separate chip
  133. */
  134. static inline int lapic_is_integrated(void)
  135. {
  136. #ifdef CONFIG_X86_64
  137. return 1;
  138. #else
  139. return APIC_INTEGRATED(lapic_get_version());
  140. #endif
  141. }
  142. /*
  143. * Check, whether this is a modern or a first generation APIC
  144. */
  145. static int modern_apic(void)
  146. {
  147. /* AMD systems use old APIC versions, so check the CPU */
  148. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
  149. boot_cpu_data.x86 >= 0xf)
  150. return 1;
  151. return lapic_get_version() >= 0x14;
  152. }
  153. /*
  154. * Paravirt kernels also might be using these below ops. So we still
  155. * use generic apic_read()/apic_write(), which might be pointing to different
  156. * ops in PARAVIRT case.
  157. */
  158. void xapic_wait_icr_idle(void)
  159. {
  160. while (apic_read(APIC_ICR) & APIC_ICR_BUSY)
  161. cpu_relax();
  162. }
  163. u32 safe_xapic_wait_icr_idle(void)
  164. {
  165. u32 send_status;
  166. int timeout;
  167. timeout = 0;
  168. do {
  169. send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
  170. if (!send_status)
  171. break;
  172. udelay(100);
  173. } while (timeout++ < 1000);
  174. return send_status;
  175. }
  176. void xapic_icr_write(u32 low, u32 id)
  177. {
  178. apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(id));
  179. apic_write(APIC_ICR, low);
  180. }
  181. u64 xapic_icr_read(void)
  182. {
  183. u32 icr1, icr2;
  184. icr2 = apic_read(APIC_ICR2);
  185. icr1 = apic_read(APIC_ICR);
  186. return icr1 | ((u64)icr2 << 32);
  187. }
  188. static struct apic_ops xapic_ops = {
  189. .read = native_apic_mem_read,
  190. .write = native_apic_mem_write,
  191. .icr_read = xapic_icr_read,
  192. .icr_write = xapic_icr_write,
  193. .wait_icr_idle = xapic_wait_icr_idle,
  194. .safe_wait_icr_idle = safe_xapic_wait_icr_idle,
  195. };
  196. struct apic_ops __read_mostly *apic_ops = &xapic_ops;
  197. EXPORT_SYMBOL_GPL(apic_ops);
  198. static void x2apic_wait_icr_idle(void)
  199. {
  200. /* no need to wait for icr idle in x2apic */
  201. return;
  202. }
  203. static u32 safe_x2apic_wait_icr_idle(void)
  204. {
  205. /* no need to wait for icr idle in x2apic */
  206. return 0;
  207. }
  208. void x2apic_icr_write(u32 low, u32 id)
  209. {
  210. wrmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), ((__u64) id) << 32 | low);
  211. }
  212. u64 x2apic_icr_read(void)
  213. {
  214. unsigned long val;
  215. rdmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), val);
  216. return val;
  217. }
  218. static struct apic_ops x2apic_ops = {
  219. .read = native_apic_msr_read,
  220. .write = native_apic_msr_write,
  221. .icr_read = x2apic_icr_read,
  222. .icr_write = x2apic_icr_write,
  223. .wait_icr_idle = x2apic_wait_icr_idle,
  224. .safe_wait_icr_idle = safe_x2apic_wait_icr_idle,
  225. };
  226. /**
  227. * enable_NMI_through_LVT0 - enable NMI through local vector table 0
  228. */
  229. void __cpuinit enable_NMI_through_LVT0(void)
  230. {
  231. unsigned int v;
  232. /* unmask and set to NMI */
  233. v = APIC_DM_NMI;
  234. /* Level triggered for 82489DX (32bit mode) */
  235. if (!lapic_is_integrated())
  236. v |= APIC_LVT_LEVEL_TRIGGER;
  237. apic_write(APIC_LVT0, v);
  238. }
  239. #ifdef CONFIG_X86_32
  240. /**
  241. * get_physical_broadcast - Get number of physical broadcast IDs
  242. */
  243. int get_physical_broadcast(void)
  244. {
  245. return modern_apic() ? 0xff : 0xf;
  246. }
  247. #endif
  248. /**
  249. * lapic_get_maxlvt - get the maximum number of local vector table entries
  250. */
  251. int lapic_get_maxlvt(void)
  252. {
  253. unsigned int v;
  254. v = apic_read(APIC_LVR);
  255. /*
  256. * - we always have APIC integrated on 64bit mode
  257. * - 82489DXs do not report # of LVT entries
  258. */
  259. return APIC_INTEGRATED(GET_APIC_VERSION(v)) ? GET_APIC_MAXLVT(v) : 2;
  260. }
  261. /*
  262. * Local APIC timer
  263. */
  264. /* Clock divisor */
  265. #ifdef CONFG_X86_64
  266. #define APIC_DIVISOR 1
  267. #else
  268. #define APIC_DIVISOR 16
  269. #endif
  270. /*
  271. * This function sets up the local APIC timer, with a timeout of
  272. * 'clocks' APIC bus clock. During calibration we actually call
  273. * this function twice on the boot CPU, once with a bogus timeout
  274. * value, second time for real. The other (noncalibrating) CPUs
  275. * call this function only once, with the real, calibrated value.
  276. *
  277. * We do reads before writes even if unnecessary, to get around the
  278. * P5 APIC double write bug.
  279. */
  280. static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
  281. {
  282. unsigned int lvtt_value, tmp_value;
  283. lvtt_value = LOCAL_TIMER_VECTOR;
  284. if (!oneshot)
  285. lvtt_value |= APIC_LVT_TIMER_PERIODIC;
  286. if (!lapic_is_integrated())
  287. lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
  288. if (!irqen)
  289. lvtt_value |= APIC_LVT_MASKED;
  290. apic_write(APIC_LVTT, lvtt_value);
  291. /*
  292. * Divide PICLK by 16
  293. */
  294. tmp_value = apic_read(APIC_TDCR);
  295. apic_write(APIC_TDCR,
  296. (tmp_value & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE)) |
  297. APIC_TDR_DIV_16);
  298. if (!oneshot)
  299. apic_write(APIC_TMICT, clocks / APIC_DIVISOR);
  300. }
  301. /*
  302. * Setup extended LVT, AMD specific (K8, family 10h)
  303. *
  304. * Vector mappings are hard coded. On K8 only offset 0 (APIC500) and
  305. * MCE interrupts are supported. Thus MCE offset must be set to 0.
  306. *
  307. * If mask=1, the LVT entry does not generate interrupts while mask=0
  308. * enables the vector. See also the BKDGs.
  309. */
  310. #define APIC_EILVT_LVTOFF_MCE 0
  311. #define APIC_EILVT_LVTOFF_IBS 1
  312. static void setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask)
  313. {
  314. unsigned long reg = (lvt_off << 4) + APIC_EILVT0;
  315. unsigned int v = (mask << 16) | (msg_type << 8) | vector;
  316. apic_write(reg, v);
  317. }
  318. u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask)
  319. {
  320. setup_APIC_eilvt(APIC_EILVT_LVTOFF_MCE, vector, msg_type, mask);
  321. return APIC_EILVT_LVTOFF_MCE;
  322. }
  323. u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask)
  324. {
  325. setup_APIC_eilvt(APIC_EILVT_LVTOFF_IBS, vector, msg_type, mask);
  326. return APIC_EILVT_LVTOFF_IBS;
  327. }
  328. EXPORT_SYMBOL_GPL(setup_APIC_eilvt_ibs);
  329. /*
  330. * Program the next event, relative to now
  331. */
  332. static int lapic_next_event(unsigned long delta,
  333. struct clock_event_device *evt)
  334. {
  335. apic_write(APIC_TMICT, delta);
  336. return 0;
  337. }
  338. /*
  339. * Setup the lapic timer in periodic or oneshot mode
  340. */
  341. static void lapic_timer_setup(enum clock_event_mode mode,
  342. struct clock_event_device *evt)
  343. {
  344. unsigned long flags;
  345. unsigned int v;
  346. /* Lapic used as dummy for broadcast ? */
  347. if (evt->features & CLOCK_EVT_FEAT_DUMMY)
  348. return;
  349. local_irq_save(flags);
  350. switch (mode) {
  351. case CLOCK_EVT_MODE_PERIODIC:
  352. case CLOCK_EVT_MODE_ONESHOT:
  353. __setup_APIC_LVTT(calibration_result,
  354. mode != CLOCK_EVT_MODE_PERIODIC, 1);
  355. break;
  356. case CLOCK_EVT_MODE_UNUSED:
  357. case CLOCK_EVT_MODE_SHUTDOWN:
  358. v = apic_read(APIC_LVTT);
  359. v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
  360. apic_write(APIC_LVTT, v);
  361. break;
  362. case CLOCK_EVT_MODE_RESUME:
  363. /* Nothing to do here */
  364. break;
  365. }
  366. local_irq_restore(flags);
  367. }
  368. /*
  369. * Local APIC timer broadcast function
  370. */
  371. static void lapic_timer_broadcast(cpumask_t mask)
  372. {
  373. #ifdef CONFIG_SMP
  374. send_IPI_mask(mask, LOCAL_TIMER_VECTOR);
  375. #endif
  376. }
  377. /*
  378. * Setup the local APIC timer for this CPU. Copy the initilized values
  379. * of the boot CPU and register the clock event in the framework.
  380. */
  381. static void __cpuinit setup_APIC_timer(void)
  382. {
  383. struct clock_event_device *levt = &__get_cpu_var(lapic_events);
  384. memcpy(levt, &lapic_clockevent, sizeof(*levt));
  385. levt->cpumask = cpumask_of_cpu(smp_processor_id());
  386. clockevents_register_device(levt);
  387. }
  388. /*
  389. * In this function we calibrate APIC bus clocks to the external
  390. * timer. Unfortunately we cannot use jiffies and the timer irq
  391. * to calibrate, since some later bootup code depends on getting
  392. * the first irq? Ugh.
  393. *
  394. * We want to do the calibration only once since we
  395. * want to have local timer irqs syncron. CPUs connected
  396. * by the same APIC bus have the very same bus frequency.
  397. * And we want to have irqs off anyways, no accidental
  398. * APIC irq that way.
  399. */
  400. #define TICK_COUNT 100000000
  401. static int __init calibrate_APIC_clock(void)
  402. {
  403. unsigned apic, apic_start;
  404. unsigned long tsc, tsc_start;
  405. int result;
  406. local_irq_disable();
  407. /*
  408. * Put whatever arbitrary (but long enough) timeout
  409. * value into the APIC clock, we just want to get the
  410. * counter running for calibration.
  411. *
  412. * No interrupt enable !
  413. */
  414. __setup_APIC_LVTT(250000000, 0, 0);
  415. apic_start = apic_read(APIC_TMCCT);
  416. #ifdef CONFIG_X86_PM_TIMER
  417. if (apic_calibrate_pmtmr && pmtmr_ioport) {
  418. pmtimer_wait(5000); /* 5ms wait */
  419. apic = apic_read(APIC_TMCCT);
  420. result = (apic_start - apic) * 1000L / 5;
  421. } else
  422. #endif
  423. {
  424. rdtscll(tsc_start);
  425. do {
  426. apic = apic_read(APIC_TMCCT);
  427. rdtscll(tsc);
  428. } while ((tsc - tsc_start) < TICK_COUNT &&
  429. (apic_start - apic) < TICK_COUNT);
  430. result = (apic_start - apic) * 1000L * tsc_khz /
  431. (tsc - tsc_start);
  432. }
  433. local_irq_enable();
  434. printk(KERN_DEBUG "APIC timer calibration result %d\n", result);
  435. printk(KERN_INFO "Detected %d.%03d MHz APIC timer.\n",
  436. result / 1000 / 1000, result / 1000 % 1000);
  437. /* Calculate the scaled math multiplication factor */
  438. lapic_clockevent.mult = div_sc(result, NSEC_PER_SEC,
  439. lapic_clockevent.shift);
  440. lapic_clockevent.max_delta_ns =
  441. clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
  442. lapic_clockevent.min_delta_ns =
  443. clockevent_delta2ns(0xF, &lapic_clockevent);
  444. calibration_result = (result * APIC_DIVISOR) / HZ;
  445. /*
  446. * Do a sanity check on the APIC calibration result
  447. */
  448. if (calibration_result < (1000000 / HZ)) {
  449. printk(KERN_WARNING
  450. "APIC frequency too slow, disabling apic timer\n");
  451. return -1;
  452. }
  453. return 0;
  454. }
  455. /*
  456. * Setup the boot APIC
  457. *
  458. * Calibrate and verify the result.
  459. */
  460. void __init setup_boot_APIC_clock(void)
  461. {
  462. /*
  463. * The local apic timer can be disabled via the kernel
  464. * commandline or from the CPU detection code. Register the lapic
  465. * timer as a dummy clock event source on SMP systems, so the
  466. * broadcast mechanism is used. On UP systems simply ignore it.
  467. */
  468. if (disable_apic_timer) {
  469. printk(KERN_INFO "Disabling APIC timer\n");
  470. /* No broadcast on UP ! */
  471. if (num_possible_cpus() > 1) {
  472. lapic_clockevent.mult = 1;
  473. setup_APIC_timer();
  474. }
  475. return;
  476. }
  477. apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n"
  478. "calibrating APIC timer ...\n");
  479. if (calibrate_APIC_clock()) {
  480. /* No broadcast on UP ! */
  481. if (num_possible_cpus() > 1)
  482. setup_APIC_timer();
  483. return;
  484. }
  485. /*
  486. * If nmi_watchdog is set to IO_APIC, we need the
  487. * PIT/HPET going. Otherwise register lapic as a dummy
  488. * device.
  489. */
  490. if (nmi_watchdog != NMI_IO_APIC)
  491. lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
  492. else
  493. printk(KERN_WARNING "APIC timer registered as dummy,"
  494. " due to nmi_watchdog=%d!\n", nmi_watchdog);
  495. /* Setup the lapic or request the broadcast */
  496. setup_APIC_timer();
  497. }
  498. void __cpuinit setup_secondary_APIC_clock(void)
  499. {
  500. setup_APIC_timer();
  501. }
  502. /*
  503. * The guts of the apic timer interrupt
  504. */
  505. static void local_apic_timer_interrupt(void)
  506. {
  507. int cpu = smp_processor_id();
  508. struct clock_event_device *evt = &per_cpu(lapic_events, cpu);
  509. /*
  510. * Normally we should not be here till LAPIC has been initialized but
  511. * in some cases like kdump, its possible that there is a pending LAPIC
  512. * timer interrupt from previous kernel's context and is delivered in
  513. * new kernel the moment interrupts are enabled.
  514. *
  515. * Interrupts are enabled early and LAPIC is setup much later, hence
  516. * its possible that when we get here evt->event_handler is NULL.
  517. * Check for event_handler being NULL and discard the interrupt as
  518. * spurious.
  519. */
  520. if (!evt->event_handler) {
  521. printk(KERN_WARNING
  522. "Spurious LAPIC timer interrupt on cpu %d\n", cpu);
  523. /* Switch it off */
  524. lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt);
  525. return;
  526. }
  527. /*
  528. * the NMI deadlock-detector uses this.
  529. */
  530. #ifdef CONFIG_X86_64
  531. add_pda(apic_timer_irqs, 1);
  532. #else
  533. per_cpu(irq_stat, cpu).apic_timer_irqs++;
  534. #endif
  535. evt->event_handler(evt);
  536. }
  537. /*
  538. * Local APIC timer interrupt. This is the most natural way for doing
  539. * local interrupts, but local timer interrupts can be emulated by
  540. * broadcast interrupts too. [in case the hw doesn't support APIC timers]
  541. *
  542. * [ if a single-CPU system runs an SMP kernel then we call the local
  543. * interrupt as well. Thus we cannot inline the local irq ... ]
  544. */
  545. void smp_apic_timer_interrupt(struct pt_regs *regs)
  546. {
  547. struct pt_regs *old_regs = set_irq_regs(regs);
  548. /*
  549. * NOTE! We'd better ACK the irq immediately,
  550. * because timer handling can be slow.
  551. */
  552. ack_APIC_irq();
  553. /*
  554. * update_process_times() expects us to have done irq_enter().
  555. * Besides, if we don't timer interrupts ignore the global
  556. * interrupt lock, which is the WrongThing (tm) to do.
  557. */
  558. #ifdef CONFIG_X86_64
  559. exit_idle();
  560. #endif
  561. irq_enter();
  562. local_apic_timer_interrupt();
  563. irq_exit();
  564. set_irq_regs(old_regs);
  565. }
  566. int setup_profiling_timer(unsigned int multiplier)
  567. {
  568. return -EINVAL;
  569. }
  570. /*
  571. * Local APIC start and shutdown
  572. */
  573. /**
  574. * clear_local_APIC - shutdown the local APIC
  575. *
  576. * This is called, when a CPU is disabled and before rebooting, so the state of
  577. * the local APIC has no dangling leftovers. Also used to cleanout any BIOS
  578. * leftovers during boot.
  579. */
  580. void clear_local_APIC(void)
  581. {
  582. int maxlvt;
  583. u32 v;
  584. /* APIC hasn't been mapped yet */
  585. if (!apic_phys)
  586. return;
  587. maxlvt = lapic_get_maxlvt();
  588. /*
  589. * Masking an LVT entry can trigger a local APIC error
  590. * if the vector is zero. Mask LVTERR first to prevent this.
  591. */
  592. if (maxlvt >= 3) {
  593. v = ERROR_APIC_VECTOR; /* any non-zero vector will do */
  594. apic_write(APIC_LVTERR, v | APIC_LVT_MASKED);
  595. }
  596. /*
  597. * Careful: we have to set masks only first to deassert
  598. * any level-triggered sources.
  599. */
  600. v = apic_read(APIC_LVTT);
  601. apic_write(APIC_LVTT, v | APIC_LVT_MASKED);
  602. v = apic_read(APIC_LVT0);
  603. apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
  604. v = apic_read(APIC_LVT1);
  605. apic_write(APIC_LVT1, v | APIC_LVT_MASKED);
  606. if (maxlvt >= 4) {
  607. v = apic_read(APIC_LVTPC);
  608. apic_write(APIC_LVTPC, v | APIC_LVT_MASKED);
  609. }
  610. /* lets not touch this if we didn't frob it */
  611. #if defined(CONFIG_X86_MCE_P4THERMAL) || defined(X86_MCE_INTEL)
  612. if (maxlvt >= 5) {
  613. v = apic_read(APIC_LVTTHMR);
  614. apic_write(APIC_LVTTHMR, v | APIC_LVT_MASKED);
  615. }
  616. #endif
  617. /*
  618. * Clean APIC state for other OSs:
  619. */
  620. apic_write(APIC_LVTT, APIC_LVT_MASKED);
  621. apic_write(APIC_LVT0, APIC_LVT_MASKED);
  622. apic_write(APIC_LVT1, APIC_LVT_MASKED);
  623. if (maxlvt >= 3)
  624. apic_write(APIC_LVTERR, APIC_LVT_MASKED);
  625. if (maxlvt >= 4)
  626. apic_write(APIC_LVTPC, APIC_LVT_MASKED);
  627. /* Integrated APIC (!82489DX) ? */
  628. if (lapic_is_integrated()) {
  629. if (maxlvt > 3)
  630. /* Clear ESR due to Pentium errata 3AP and 11AP */
  631. apic_write(APIC_ESR, 0);
  632. apic_read(APIC_ESR);
  633. }
  634. }
  635. /**
  636. * disable_local_APIC - clear and disable the local APIC
  637. */
  638. void disable_local_APIC(void)
  639. {
  640. unsigned int value;
  641. clear_local_APIC();
  642. /*
  643. * Disable APIC (implies clearing of registers
  644. * for 82489DX!).
  645. */
  646. value = apic_read(APIC_SPIV);
  647. value &= ~APIC_SPIV_APIC_ENABLED;
  648. apic_write(APIC_SPIV, value);
  649. #ifdef CONFIG_X86_32
  650. /*
  651. * When LAPIC was disabled by the BIOS and enabled by the kernel,
  652. * restore the disabled state.
  653. */
  654. if (enabled_via_apicbase) {
  655. unsigned int l, h;
  656. rdmsr(MSR_IA32_APICBASE, l, h);
  657. l &= ~MSR_IA32_APICBASE_ENABLE;
  658. wrmsr(MSR_IA32_APICBASE, l, h);
  659. }
  660. #endif
  661. }
  662. /*
  663. * If Linux enabled the LAPIC against the BIOS default disable it down before
  664. * re-entering the BIOS on shutdown. Otherwise the BIOS may get confused and
  665. * not power-off. Additionally clear all LVT entries before disable_local_APIC
  666. * for the case where Linux didn't enable the LAPIC.
  667. */
  668. void lapic_shutdown(void)
  669. {
  670. unsigned long flags;
  671. if (!cpu_has_apic)
  672. return;
  673. local_irq_save(flags);
  674. #ifdef CONFIG_X86_32
  675. if (!enabled_via_apicbase)
  676. clear_local_APIC();
  677. else
  678. #endif
  679. disable_local_APIC();
  680. local_irq_restore(flags);
  681. }
  682. /*
  683. * This is to verify that we're looking at a real local APIC.
  684. * Check these against your board if the CPUs aren't getting
  685. * started for no apparent reason.
  686. */
  687. int __init verify_local_APIC(void)
  688. {
  689. unsigned int reg0, reg1;
  690. /*
  691. * The version register is read-only in a real APIC.
  692. */
  693. reg0 = apic_read(APIC_LVR);
  694. apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0);
  695. apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK);
  696. reg1 = apic_read(APIC_LVR);
  697. apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1);
  698. /*
  699. * The two version reads above should print the same
  700. * numbers. If the second one is different, then we
  701. * poke at a non-APIC.
  702. */
  703. if (reg1 != reg0)
  704. return 0;
  705. /*
  706. * Check if the version looks reasonably.
  707. */
  708. reg1 = GET_APIC_VERSION(reg0);
  709. if (reg1 == 0x00 || reg1 == 0xff)
  710. return 0;
  711. reg1 = lapic_get_maxlvt();
  712. if (reg1 < 0x02 || reg1 == 0xff)
  713. return 0;
  714. /*
  715. * The ID register is read/write in a real APIC.
  716. */
  717. reg0 = apic_read(APIC_ID);
  718. apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0);
  719. apic_write(APIC_ID, reg0 ^ APIC_ID_MASK);
  720. reg1 = apic_read(APIC_ID);
  721. apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg1);
  722. apic_write(APIC_ID, reg0);
  723. if (reg1 != (reg0 ^ APIC_ID_MASK))
  724. return 0;
  725. /*
  726. * The next two are just to see if we have sane values.
  727. * They're only really relevant if we're in Virtual Wire
  728. * compatibility mode, but most boxes are anymore.
  729. */
  730. reg0 = apic_read(APIC_LVT0);
  731. apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0);
  732. reg1 = apic_read(APIC_LVT1);
  733. apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1);
  734. return 1;
  735. }
  736. /**
  737. * sync_Arb_IDs - synchronize APIC bus arbitration IDs
  738. */
  739. void __init sync_Arb_IDs(void)
  740. {
  741. /*
  742. * Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 And not
  743. * needed on AMD.
  744. */
  745. if (modern_apic() || boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
  746. return;
  747. /*
  748. * Wait for idle.
  749. */
  750. apic_wait_icr_idle();
  751. apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n");
  752. apic_write(APIC_ICR, APIC_DEST_ALLINC |
  753. APIC_INT_LEVELTRIG | APIC_DM_INIT);
  754. }
  755. /*
  756. * An initial setup of the virtual wire mode.
  757. */
  758. void __init init_bsp_APIC(void)
  759. {
  760. unsigned int value;
  761. /*
  762. * Don't do the setup now if we have a SMP BIOS as the
  763. * through-I/O-APIC virtual wire mode might be active.
  764. */
  765. if (smp_found_config || !cpu_has_apic)
  766. return;
  767. /*
  768. * Do not trust the local APIC being empty at bootup.
  769. */
  770. clear_local_APIC();
  771. /*
  772. * Enable APIC.
  773. */
  774. value = apic_read(APIC_SPIV);
  775. value &= ~APIC_VECTOR_MASK;
  776. value |= APIC_SPIV_APIC_ENABLED;
  777. #ifdef CONFIG_X86_32
  778. /* This bit is reserved on P4/Xeon and should be cleared */
  779. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
  780. (boot_cpu_data.x86 == 15))
  781. value &= ~APIC_SPIV_FOCUS_DISABLED;
  782. else
  783. #endif
  784. value |= APIC_SPIV_FOCUS_DISABLED;
  785. value |= SPURIOUS_APIC_VECTOR;
  786. apic_write(APIC_SPIV, value);
  787. /*
  788. * Set up the virtual wire mode.
  789. */
  790. apic_write(APIC_LVT0, APIC_DM_EXTINT);
  791. value = APIC_DM_NMI;
  792. if (!lapic_is_integrated()) /* 82489DX */
  793. value |= APIC_LVT_LEVEL_TRIGGER;
  794. apic_write(APIC_LVT1, value);
  795. }
  796. static void __cpuinit lapic_setup_esr(void)
  797. {
  798. unsigned long oldvalue, value, maxlvt;
  799. if (lapic_is_integrated() && !esr_disable) {
  800. if (esr_disable) {
  801. /*
  802. * Something untraceable is creating bad interrupts on
  803. * secondary quads ... for the moment, just leave the
  804. * ESR disabled - we can't do anything useful with the
  805. * errors anyway - mbligh
  806. */
  807. printk(KERN_INFO "Leaving ESR disabled.\n");
  808. return;
  809. }
  810. /* !82489DX */
  811. maxlvt = lapic_get_maxlvt();
  812. if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
  813. apic_write(APIC_ESR, 0);
  814. oldvalue = apic_read(APIC_ESR);
  815. /* enables sending errors */
  816. value = ERROR_APIC_VECTOR;
  817. apic_write(APIC_LVTERR, value);
  818. /*
  819. * spec says clear errors after enabling vector.
  820. */
  821. if (maxlvt > 3)
  822. apic_write(APIC_ESR, 0);
  823. value = apic_read(APIC_ESR);
  824. if (value != oldvalue)
  825. apic_printk(APIC_VERBOSE, "ESR value before enabling "
  826. "vector: 0x%08lx after: 0x%08lx\n",
  827. oldvalue, value);
  828. } else {
  829. printk(KERN_INFO "No ESR for 82489DX.\n");
  830. }
  831. }
  832. /**
  833. * setup_local_APIC - setup the local APIC
  834. */
  835. void __cpuinit setup_local_APIC(void)
  836. {
  837. unsigned int value;
  838. int i, j;
  839. #ifdef CONFIG_X86_32
  840. /* Pound the ESR really hard over the head with a big hammer - mbligh */
  841. if (esr_disable) {
  842. apic_write(APIC_ESR, 0);
  843. apic_write(APIC_ESR, 0);
  844. apic_write(APIC_ESR, 0);
  845. apic_write(APIC_ESR, 0);
  846. }
  847. #endif
  848. preempt_disable();
  849. /*
  850. * Double-check whether this APIC is really registered.
  851. * This is meaningless in clustered apic mode, so we skip it.
  852. */
  853. if (!apic_id_registered())
  854. BUG();
  855. /*
  856. * Intel recommends to set DFR, LDR and TPR before enabling
  857. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  858. * document number 292116). So here it goes...
  859. */
  860. init_apic_ldr();
  861. /*
  862. * Set Task Priority to 'accept all'. We never change this
  863. * later on.
  864. */
  865. value = apic_read(APIC_TASKPRI);
  866. value &= ~APIC_TPRI_MASK;
  867. apic_write(APIC_TASKPRI, value);
  868. /*
  869. * After a crash, we no longer service the interrupts and a pending
  870. * interrupt from previous kernel might still have ISR bit set.
  871. *
  872. * Most probably by now CPU has serviced that pending interrupt and
  873. * it might not have done the ack_APIC_irq() because it thought,
  874. * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it
  875. * does not clear the ISR bit and cpu thinks it has already serivced
  876. * the interrupt. Hence a vector might get locked. It was noticed
  877. * for timer irq (vector 0x31). Issue an extra EOI to clear ISR.
  878. */
  879. for (i = APIC_ISR_NR - 1; i >= 0; i--) {
  880. value = apic_read(APIC_ISR + i*0x10);
  881. for (j = 31; j >= 0; j--) {
  882. if (value & (1<<j))
  883. ack_APIC_irq();
  884. }
  885. }
  886. /*
  887. * Now that we are all set up, enable the APIC
  888. */
  889. value = apic_read(APIC_SPIV);
  890. value &= ~APIC_VECTOR_MASK;
  891. /*
  892. * Enable APIC
  893. */
  894. value |= APIC_SPIV_APIC_ENABLED;
  895. #ifdef CONFIG_X86_32
  896. /*
  897. * Some unknown Intel IO/APIC (or APIC) errata is biting us with
  898. * certain networking cards. If high frequency interrupts are
  899. * happening on a particular IOAPIC pin, plus the IOAPIC routing
  900. * entry is masked/unmasked at a high rate as well then sooner or
  901. * later IOAPIC line gets 'stuck', no more interrupts are received
  902. * from the device. If focus CPU is disabled then the hang goes
  903. * away, oh well :-(
  904. *
  905. * [ This bug can be reproduced easily with a level-triggered
  906. * PCI Ne2000 networking cards and PII/PIII processors, dual
  907. * BX chipset. ]
  908. */
  909. /*
  910. * Actually disabling the focus CPU check just makes the hang less
  911. * frequent as it makes the interrupt distributon model be more
  912. * like LRU than MRU (the short-term load is more even across CPUs).
  913. * See also the comment in end_level_ioapic_irq(). --macro
  914. */
  915. /*
  916. * - enable focus processor (bit==0)
  917. * - 64bit mode always use processor focus
  918. * so no need to set it
  919. */
  920. value &= ~APIC_SPIV_FOCUS_DISABLED;
  921. #endif
  922. /*
  923. * Set spurious IRQ vector
  924. */
  925. value |= SPURIOUS_APIC_VECTOR;
  926. apic_write(APIC_SPIV, value);
  927. /*
  928. * Set up LVT0, LVT1:
  929. *
  930. * set up through-local-APIC on the BP's LINT0. This is not
  931. * strictly necessary in pure symmetric-IO mode, but sometimes
  932. * we delegate interrupts to the 8259A.
  933. */
  934. /*
  935. * TODO: set up through-local-APIC from through-I/O-APIC? --macro
  936. */
  937. value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
  938. if (!smp_processor_id() && (pic_mode || !value)) {
  939. value = APIC_DM_EXTINT;
  940. apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
  941. smp_processor_id());
  942. } else {
  943. value = APIC_DM_EXTINT | APIC_LVT_MASKED;
  944. apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n",
  945. smp_processor_id());
  946. }
  947. apic_write(APIC_LVT0, value);
  948. /*
  949. * only the BP should see the LINT1 NMI signal, obviously.
  950. */
  951. if (!smp_processor_id())
  952. value = APIC_DM_NMI;
  953. else
  954. value = APIC_DM_NMI | APIC_LVT_MASKED;
  955. if (!lapic_is_integrated()) /* 82489DX */
  956. value |= APIC_LVT_LEVEL_TRIGGER;
  957. apic_write(APIC_LVT1, value);
  958. preempt_enable();
  959. }
  960. void __cpuinit end_local_APIC_setup(void)
  961. {
  962. lapic_setup_esr();
  963. #ifdef CONFIG_X86_32
  964. {
  965. unsigned int value;
  966. /* Disable the local apic timer */
  967. value = apic_read(APIC_LVTT);
  968. value |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
  969. apic_write(APIC_LVTT, value);
  970. }
  971. #endif
  972. setup_apic_nmi_watchdog(NULL);
  973. apic_pm_activate();
  974. }
  975. void check_x2apic(void)
  976. {
  977. int msr, msr2;
  978. rdmsr(MSR_IA32_APICBASE, msr, msr2);
  979. if (msr & X2APIC_ENABLE) {
  980. printk("x2apic enabled by BIOS, switching to x2apic ops\n");
  981. x2apic_preenabled = x2apic = 1;
  982. apic_ops = &x2apic_ops;
  983. }
  984. }
  985. void enable_x2apic(void)
  986. {
  987. int msr, msr2;
  988. rdmsr(MSR_IA32_APICBASE, msr, msr2);
  989. if (!(msr & X2APIC_ENABLE)) {
  990. printk("Enabling x2apic\n");
  991. wrmsr(MSR_IA32_APICBASE, msr | X2APIC_ENABLE, 0);
  992. }
  993. }
  994. void enable_IR_x2apic(void)
  995. {
  996. #ifdef CONFIG_INTR_REMAP
  997. int ret;
  998. unsigned long flags;
  999. if (!cpu_has_x2apic)
  1000. return;
  1001. if (!x2apic_preenabled && disable_x2apic) {
  1002. printk(KERN_INFO
  1003. "Skipped enabling x2apic and Interrupt-remapping "
  1004. "because of nox2apic\n");
  1005. return;
  1006. }
  1007. if (x2apic_preenabled && disable_x2apic)
  1008. panic("Bios already enabled x2apic, can't enforce nox2apic");
  1009. if (!x2apic_preenabled && skip_ioapic_setup) {
  1010. printk(KERN_INFO
  1011. "Skipped enabling x2apic and Interrupt-remapping "
  1012. "because of skipping io-apic setup\n");
  1013. return;
  1014. }
  1015. ret = dmar_table_init();
  1016. if (ret) {
  1017. printk(KERN_INFO
  1018. "dmar_table_init() failed with %d:\n", ret);
  1019. if (x2apic_preenabled)
  1020. panic("x2apic enabled by bios. But IR enabling failed");
  1021. else
  1022. printk(KERN_INFO
  1023. "Not enabling x2apic,Intr-remapping\n");
  1024. return;
  1025. }
  1026. local_irq_save(flags);
  1027. mask_8259A();
  1028. save_mask_IO_APIC_setup();
  1029. ret = enable_intr_remapping(1);
  1030. if (ret && x2apic_preenabled) {
  1031. local_irq_restore(flags);
  1032. panic("x2apic enabled by bios. But IR enabling failed");
  1033. }
  1034. if (ret)
  1035. goto end;
  1036. if (!x2apic) {
  1037. x2apic = 1;
  1038. apic_ops = &x2apic_ops;
  1039. enable_x2apic();
  1040. }
  1041. end:
  1042. if (ret)
  1043. /*
  1044. * IR enabling failed
  1045. */
  1046. restore_IO_APIC_setup();
  1047. else
  1048. reinit_intr_remapped_IO_APIC(x2apic_preenabled);
  1049. unmask_8259A();
  1050. local_irq_restore(flags);
  1051. if (!ret) {
  1052. if (!x2apic_preenabled)
  1053. printk(KERN_INFO
  1054. "Enabled x2apic and interrupt-remapping\n");
  1055. else
  1056. printk(KERN_INFO
  1057. "Enabled Interrupt-remapping\n");
  1058. } else
  1059. printk(KERN_ERR
  1060. "Failed to enable Interrupt-remapping and x2apic\n");
  1061. #else
  1062. if (!cpu_has_x2apic)
  1063. return;
  1064. if (x2apic_preenabled)
  1065. panic("x2apic enabled prior OS handover,"
  1066. " enable CONFIG_INTR_REMAP");
  1067. printk(KERN_INFO "Enable CONFIG_INTR_REMAP for enabling intr-remapping "
  1068. " and x2apic\n");
  1069. #endif
  1070. return;
  1071. }
  1072. /*
  1073. * Detect and enable local APICs on non-SMP boards.
  1074. * Original code written by Keir Fraser.
  1075. * On AMD64 we trust the BIOS - if it says no APIC it is likely
  1076. * not correctly set up (usually the APIC timer won't work etc.)
  1077. */
  1078. static int __init detect_init_APIC(void)
  1079. {
  1080. if (!cpu_has_apic) {
  1081. printk(KERN_INFO "No local APIC present\n");
  1082. return -1;
  1083. }
  1084. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  1085. boot_cpu_physical_apicid = 0;
  1086. return 0;
  1087. }
  1088. void __init early_init_lapic_mapping(void)
  1089. {
  1090. unsigned long phys_addr;
  1091. /*
  1092. * If no local APIC can be found then go out
  1093. * : it means there is no mpatable and MADT
  1094. */
  1095. if (!smp_found_config)
  1096. return;
  1097. phys_addr = mp_lapic_addr;
  1098. set_fixmap_nocache(FIX_APIC_BASE, phys_addr);
  1099. apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
  1100. APIC_BASE, phys_addr);
  1101. /*
  1102. * Fetch the APIC ID of the BSP in case we have a
  1103. * default configuration (or the MP table is broken).
  1104. */
  1105. boot_cpu_physical_apicid = read_apic_id();
  1106. }
  1107. /**
  1108. * init_apic_mappings - initialize APIC mappings
  1109. */
  1110. void __init init_apic_mappings(void)
  1111. {
  1112. if (x2apic) {
  1113. boot_cpu_physical_apicid = read_apic_id();
  1114. return;
  1115. }
  1116. /*
  1117. * If no local APIC can be found then set up a fake all
  1118. * zeroes page to simulate the local APIC and another
  1119. * one for the IO-APIC.
  1120. */
  1121. if (!smp_found_config && detect_init_APIC()) {
  1122. apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  1123. apic_phys = __pa(apic_phys);
  1124. } else
  1125. apic_phys = mp_lapic_addr;
  1126. set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
  1127. apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
  1128. APIC_BASE, apic_phys);
  1129. /*
  1130. * Fetch the APIC ID of the BSP in case we have a
  1131. * default configuration (or the MP table is broken).
  1132. */
  1133. boot_cpu_physical_apicid = read_apic_id();
  1134. }
  1135. /*
  1136. * This initializes the IO-APIC and APIC hardware if this is
  1137. * a UP kernel.
  1138. */
  1139. int apic_version[MAX_APICS];
  1140. int __init APIC_init_uniprocessor(void)
  1141. {
  1142. if (disable_apic) {
  1143. printk(KERN_INFO "Apic disabled\n");
  1144. return -1;
  1145. }
  1146. if (!cpu_has_apic) {
  1147. disable_apic = 1;
  1148. printk(KERN_INFO "Apic disabled by BIOS\n");
  1149. return -1;
  1150. }
  1151. enable_IR_x2apic();
  1152. setup_apic_routing();
  1153. verify_local_APIC();
  1154. connect_bsp_APIC();
  1155. physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map);
  1156. apic_write(APIC_ID, SET_APIC_ID(boot_cpu_physical_apicid));
  1157. setup_local_APIC();
  1158. /*
  1159. * Now enable IO-APICs, actually call clear_IO_APIC
  1160. * We need clear_IO_APIC before enabling vector on BP
  1161. */
  1162. if (!skip_ioapic_setup && nr_ioapics)
  1163. enable_IO_APIC();
  1164. if (!smp_found_config || skip_ioapic_setup || !nr_ioapics)
  1165. localise_nmi_watchdog();
  1166. end_local_APIC_setup();
  1167. if (smp_found_config && !skip_ioapic_setup && nr_ioapics)
  1168. setup_IO_APIC();
  1169. else
  1170. nr_ioapics = 0;
  1171. setup_boot_APIC_clock();
  1172. check_nmi_watchdog();
  1173. return 0;
  1174. }
  1175. /*
  1176. * Local APIC interrupts
  1177. */
  1178. /*
  1179. * This interrupt should _never_ happen with our APIC/SMP architecture
  1180. */
  1181. asmlinkage void smp_spurious_interrupt(void)
  1182. {
  1183. unsigned int v;
  1184. exit_idle();
  1185. irq_enter();
  1186. /*
  1187. * Check if this really is a spurious interrupt and ACK it
  1188. * if it is a vectored one. Just in case...
  1189. * Spurious interrupts should not be ACKed.
  1190. */
  1191. v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1));
  1192. if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f)))
  1193. ack_APIC_irq();
  1194. add_pda(irq_spurious_count, 1);
  1195. irq_exit();
  1196. }
  1197. /*
  1198. * This interrupt should never happen with our APIC/SMP architecture
  1199. */
  1200. asmlinkage void smp_error_interrupt(void)
  1201. {
  1202. unsigned int v, v1;
  1203. exit_idle();
  1204. irq_enter();
  1205. /* First tickle the hardware, only then report what went on. -- REW */
  1206. v = apic_read(APIC_ESR);
  1207. apic_write(APIC_ESR, 0);
  1208. v1 = apic_read(APIC_ESR);
  1209. ack_APIC_irq();
  1210. atomic_inc(&irq_err_count);
  1211. /* Here is what the APIC error bits mean:
  1212. 0: Send CS error
  1213. 1: Receive CS error
  1214. 2: Send accept error
  1215. 3: Receive accept error
  1216. 4: Reserved
  1217. 5: Send illegal vector
  1218. 6: Received illegal vector
  1219. 7: Illegal register address
  1220. */
  1221. printk(KERN_DEBUG "APIC error on CPU%d: %02x(%02x)\n",
  1222. smp_processor_id(), v , v1);
  1223. irq_exit();
  1224. }
  1225. /**
  1226. * connect_bsp_APIC - attach the APIC to the interrupt system
  1227. */
  1228. void __init connect_bsp_APIC(void)
  1229. {
  1230. #ifdef CONFIG_X86_32
  1231. if (pic_mode) {
  1232. /*
  1233. * Do not trust the local APIC being empty at bootup.
  1234. */
  1235. clear_local_APIC();
  1236. /*
  1237. * PIC mode, enable APIC mode in the IMCR, i.e. connect BSP's
  1238. * local APIC to INT and NMI lines.
  1239. */
  1240. apic_printk(APIC_VERBOSE, "leaving PIC mode, "
  1241. "enabling APIC mode.\n");
  1242. outb(0x70, 0x22);
  1243. outb(0x01, 0x23);
  1244. }
  1245. #endif
  1246. enable_apic_mode();
  1247. }
  1248. /**
  1249. * disconnect_bsp_APIC - detach the APIC from the interrupt system
  1250. * @virt_wire_setup: indicates, whether virtual wire mode is selected
  1251. *
  1252. * Virtual wire mode is necessary to deliver legacy interrupts even when the
  1253. * APIC is disabled.
  1254. */
  1255. void disconnect_bsp_APIC(int virt_wire_setup)
  1256. {
  1257. unsigned int value;
  1258. #ifdef CONFIG_X86_32
  1259. if (pic_mode) {
  1260. /*
  1261. * Put the board back into PIC mode (has an effect only on
  1262. * certain older boards). Note that APIC interrupts, including
  1263. * IPIs, won't work beyond this point! The only exception are
  1264. * INIT IPIs.
  1265. */
  1266. apic_printk(APIC_VERBOSE, "disabling APIC mode, "
  1267. "entering PIC mode.\n");
  1268. outb(0x70, 0x22);
  1269. outb(0x00, 0x23);
  1270. return;
  1271. }
  1272. #endif
  1273. /* Go back to Virtual Wire compatibility mode */
  1274. /* For the spurious interrupt use vector F, and enable it */
  1275. value = apic_read(APIC_SPIV);
  1276. value &= ~APIC_VECTOR_MASK;
  1277. value |= APIC_SPIV_APIC_ENABLED;
  1278. value |= 0xf;
  1279. apic_write(APIC_SPIV, value);
  1280. if (!virt_wire_setup) {
  1281. /*
  1282. * For LVT0 make it edge triggered, active high,
  1283. * external and enabled
  1284. */
  1285. value = apic_read(APIC_LVT0);
  1286. value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
  1287. APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
  1288. APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
  1289. value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
  1290. value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT);
  1291. apic_write(APIC_LVT0, value);
  1292. } else {
  1293. /* Disable LVT0 */
  1294. apic_write(APIC_LVT0, APIC_LVT_MASKED);
  1295. }
  1296. /*
  1297. * For LVT1 make it edge triggered, active high,
  1298. * nmi and enabled
  1299. */
  1300. value = apic_read(APIC_LVT1);
  1301. value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
  1302. APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
  1303. APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
  1304. value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
  1305. value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI);
  1306. apic_write(APIC_LVT1, value);
  1307. }
  1308. void __cpuinit generic_processor_info(int apicid, int version)
  1309. {
  1310. int cpu;
  1311. cpumask_t tmp_map;
  1312. /*
  1313. * Validate version
  1314. */
  1315. if (version == 0x0) {
  1316. printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! "
  1317. "fixing up to 0x10. (tell your hw vendor)\n",
  1318. version);
  1319. version = 0x10;
  1320. }
  1321. apic_version[apicid] = version;
  1322. if (num_processors >= NR_CPUS) {
  1323. printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached."
  1324. " Processor ignored.\n", NR_CPUS);
  1325. return;
  1326. }
  1327. num_processors++;
  1328. cpus_complement(tmp_map, cpu_present_map);
  1329. cpu = first_cpu(tmp_map);
  1330. physid_set(apicid, phys_cpu_present_map);
  1331. if (apicid == boot_cpu_physical_apicid) {
  1332. /*
  1333. * x86_bios_cpu_apicid is required to have processors listed
  1334. * in same order as logical cpu numbers. Hence the first
  1335. * entry is BSP, and so on.
  1336. */
  1337. cpu = 0;
  1338. }
  1339. if (apicid > max_physical_apicid)
  1340. max_physical_apicid = apicid;
  1341. #ifdef CONFIG_X86_32
  1342. /*
  1343. * Would be preferable to switch to bigsmp when CONFIG_HOTPLUG_CPU=y
  1344. * but we need to work other dependencies like SMP_SUSPEND etc
  1345. * before this can be done without some confusion.
  1346. * if (CPU_HOTPLUG_ENABLED || num_processors > 8)
  1347. * - Ashok Raj <ashok.raj@intel.com>
  1348. */
  1349. if (max_physical_apicid >= 8) {
  1350. switch (boot_cpu_data.x86_vendor) {
  1351. case X86_VENDOR_INTEL:
  1352. if (!APIC_XAPIC(version)) {
  1353. def_to_bigsmp = 0;
  1354. break;
  1355. }
  1356. /* If P4 and above fall through */
  1357. case X86_VENDOR_AMD:
  1358. def_to_bigsmp = 1;
  1359. }
  1360. }
  1361. #endif
  1362. #if defined(CONFIG_X86_SMP) || defined(CONFIG_X86_64)
  1363. /* are we being called early in kernel startup? */
  1364. if (early_per_cpu_ptr(x86_cpu_to_apicid)) {
  1365. u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid);
  1366. u16 *bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
  1367. cpu_to_apicid[cpu] = apicid;
  1368. bios_cpu_apicid[cpu] = apicid;
  1369. } else {
  1370. per_cpu(x86_cpu_to_apicid, cpu) = apicid;
  1371. per_cpu(x86_bios_cpu_apicid, cpu) = apicid;
  1372. }
  1373. #endif
  1374. cpu_set(cpu, cpu_possible_map);
  1375. cpu_set(cpu, cpu_present_map);
  1376. }
  1377. int hard_smp_processor_id(void)
  1378. {
  1379. return read_apic_id();
  1380. }
  1381. /*
  1382. * Power management
  1383. */
  1384. #ifdef CONFIG_PM
  1385. static struct {
  1386. /*
  1387. * 'active' is true if the local APIC was enabled by us and
  1388. * not the BIOS; this signifies that we are also responsible
  1389. * for disabling it before entering apm/acpi suspend
  1390. */
  1391. int active;
  1392. /* r/w apic fields */
  1393. unsigned int apic_id;
  1394. unsigned int apic_taskpri;
  1395. unsigned int apic_ldr;
  1396. unsigned int apic_dfr;
  1397. unsigned int apic_spiv;
  1398. unsigned int apic_lvtt;
  1399. unsigned int apic_lvtpc;
  1400. unsigned int apic_lvt0;
  1401. unsigned int apic_lvt1;
  1402. unsigned int apic_lvterr;
  1403. unsigned int apic_tmict;
  1404. unsigned int apic_tdcr;
  1405. unsigned int apic_thmr;
  1406. } apic_pm_state;
  1407. static int lapic_suspend(struct sys_device *dev, pm_message_t state)
  1408. {
  1409. unsigned long flags;
  1410. int maxlvt;
  1411. if (!apic_pm_state.active)
  1412. return 0;
  1413. maxlvt = lapic_get_maxlvt();
  1414. apic_pm_state.apic_id = apic_read(APIC_ID);
  1415. apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI);
  1416. apic_pm_state.apic_ldr = apic_read(APIC_LDR);
  1417. apic_pm_state.apic_dfr = apic_read(APIC_DFR);
  1418. apic_pm_state.apic_spiv = apic_read(APIC_SPIV);
  1419. apic_pm_state.apic_lvtt = apic_read(APIC_LVTT);
  1420. if (maxlvt >= 4)
  1421. apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC);
  1422. apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0);
  1423. apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1);
  1424. apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR);
  1425. apic_pm_state.apic_tmict = apic_read(APIC_TMICT);
  1426. apic_pm_state.apic_tdcr = apic_read(APIC_TDCR);
  1427. #if defined(CONFIG_X86_MCE_P4THERMAL) || defined(CONFIG_X86_MCE_INTEL)
  1428. if (maxlvt >= 5)
  1429. apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR);
  1430. #endif
  1431. local_irq_save(flags);
  1432. disable_local_APIC();
  1433. local_irq_restore(flags);
  1434. return 0;
  1435. }
  1436. static int lapic_resume(struct sys_device *dev)
  1437. {
  1438. unsigned int l, h;
  1439. unsigned long flags;
  1440. int maxlvt;
  1441. if (!apic_pm_state.active)
  1442. return 0;
  1443. maxlvt = lapic_get_maxlvt();
  1444. local_irq_save(flags);
  1445. #ifdef CONFIG_X86_64
  1446. if (x2apic)
  1447. enable_x2apic();
  1448. else
  1449. #endif
  1450. {
  1451. /*
  1452. * Make sure the APICBASE points to the right address
  1453. *
  1454. * FIXME! This will be wrong if we ever support suspend on
  1455. * SMP! We'll need to do this as part of the CPU restore!
  1456. */
  1457. rdmsr(MSR_IA32_APICBASE, l, h);
  1458. l &= ~MSR_IA32_APICBASE_BASE;
  1459. l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
  1460. wrmsr(MSR_IA32_APICBASE, l, h);
  1461. }
  1462. apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED);
  1463. apic_write(APIC_ID, apic_pm_state.apic_id);
  1464. apic_write(APIC_DFR, apic_pm_state.apic_dfr);
  1465. apic_write(APIC_LDR, apic_pm_state.apic_ldr);
  1466. apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri);
  1467. apic_write(APIC_SPIV, apic_pm_state.apic_spiv);
  1468. apic_write(APIC_LVT0, apic_pm_state.apic_lvt0);
  1469. apic_write(APIC_LVT1, apic_pm_state.apic_lvt1);
  1470. #if defined(CONFIG_X86_MCE_P4THERMAL) || defined(CONFIG_X86_MCE_INTEL)
  1471. if (maxlvt >= 5)
  1472. apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr);
  1473. #endif
  1474. if (maxlvt >= 4)
  1475. apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc);
  1476. apic_write(APIC_LVTT, apic_pm_state.apic_lvtt);
  1477. apic_write(APIC_TDCR, apic_pm_state.apic_tdcr);
  1478. apic_write(APIC_TMICT, apic_pm_state.apic_tmict);
  1479. apic_write(APIC_ESR, 0);
  1480. apic_read(APIC_ESR);
  1481. apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr);
  1482. apic_write(APIC_ESR, 0);
  1483. apic_read(APIC_ESR);
  1484. local_irq_restore(flags);
  1485. return 0;
  1486. }
  1487. /*
  1488. * This device has no shutdown method - fully functioning local APICs
  1489. * are needed on every CPU up until machine_halt/restart/poweroff.
  1490. */
  1491. static struct sysdev_class lapic_sysclass = {
  1492. .name = "lapic",
  1493. .resume = lapic_resume,
  1494. .suspend = lapic_suspend,
  1495. };
  1496. static struct sys_device device_lapic = {
  1497. .id = 0,
  1498. .cls = &lapic_sysclass,
  1499. };
  1500. static void __cpuinit apic_pm_activate(void)
  1501. {
  1502. apic_pm_state.active = 1;
  1503. }
  1504. static int __init init_lapic_sysfs(void)
  1505. {
  1506. int error;
  1507. if (!cpu_has_apic)
  1508. return 0;
  1509. /* XXX: remove suspend/resume procs if !apic_pm_state.active? */
  1510. error = sysdev_class_register(&lapic_sysclass);
  1511. if (!error)
  1512. error = sysdev_register(&device_lapic);
  1513. return error;
  1514. }
  1515. device_initcall(init_lapic_sysfs);
  1516. #else /* CONFIG_PM */
  1517. static void apic_pm_activate(void) { }
  1518. #endif /* CONFIG_PM */
  1519. /*
  1520. * apic_is_clustered_box() -- Check if we can expect good TSC
  1521. *
  1522. * Thus far, the major user of this is IBM's Summit2 series:
  1523. *
  1524. * Clustered boxes may have unsynced TSC problems if they are
  1525. * multi-chassis. Use available data to take a good guess.
  1526. * If in doubt, go HPET.
  1527. */
  1528. __cpuinit int apic_is_clustered_box(void)
  1529. {
  1530. int i, clusters, zeros;
  1531. unsigned id;
  1532. u16 *bios_cpu_apicid;
  1533. DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
  1534. /*
  1535. * there is not this kind of box with AMD CPU yet.
  1536. * Some AMD box with quadcore cpu and 8 sockets apicid
  1537. * will be [4, 0x23] or [8, 0x27] could be thought to
  1538. * vsmp box still need checking...
  1539. */
  1540. if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) && !is_vsmp_box())
  1541. return 0;
  1542. bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
  1543. bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
  1544. for (i = 0; i < NR_CPUS; i++) {
  1545. /* are we being called early in kernel startup? */
  1546. if (bios_cpu_apicid) {
  1547. id = bios_cpu_apicid[i];
  1548. }
  1549. else if (i < nr_cpu_ids) {
  1550. if (cpu_present(i))
  1551. id = per_cpu(x86_bios_cpu_apicid, i);
  1552. else
  1553. continue;
  1554. }
  1555. else
  1556. break;
  1557. if (id != BAD_APICID)
  1558. __set_bit(APIC_CLUSTERID(id), clustermap);
  1559. }
  1560. /* Problem: Partially populated chassis may not have CPUs in some of
  1561. * the APIC clusters they have been allocated. Only present CPUs have
  1562. * x86_bios_cpu_apicid entries, thus causing zeroes in the bitmap.
  1563. * Since clusters are allocated sequentially, count zeros only if
  1564. * they are bounded by ones.
  1565. */
  1566. clusters = 0;
  1567. zeros = 0;
  1568. for (i = 0; i < NUM_APIC_CLUSTERS; i++) {
  1569. if (test_bit(i, clustermap)) {
  1570. clusters += 1 + zeros;
  1571. zeros = 0;
  1572. } else
  1573. ++zeros;
  1574. }
  1575. /* ScaleMP vSMPowered boxes have one cluster per board and TSCs are
  1576. * not guaranteed to be synced between boards
  1577. */
  1578. if (is_vsmp_box() && clusters > 1)
  1579. return 1;
  1580. /*
  1581. * If clusters > 2, then should be multi-chassis.
  1582. * May have to revisit this when multi-core + hyperthreaded CPUs come
  1583. * out, but AFAIK this will work even for them.
  1584. */
  1585. return (clusters > 2);
  1586. }
  1587. static __init int setup_nox2apic(char *str)
  1588. {
  1589. disable_x2apic = 1;
  1590. clear_cpu_cap(&boot_cpu_data, X86_FEATURE_X2APIC);
  1591. return 0;
  1592. }
  1593. early_param("nox2apic", setup_nox2apic);
  1594. /*
  1595. * APIC command line parameters
  1596. */
  1597. static int __init setup_disableapic(char *arg)
  1598. {
  1599. disable_apic = 1;
  1600. setup_clear_cpu_cap(X86_FEATURE_APIC);
  1601. return 0;
  1602. }
  1603. early_param("disableapic", setup_disableapic);
  1604. /* same as disableapic, for compatibility */
  1605. static int __init setup_nolapic(char *arg)
  1606. {
  1607. return setup_disableapic(arg);
  1608. }
  1609. early_param("nolapic", setup_nolapic);
  1610. static int __init parse_lapic_timer_c2_ok(char *arg)
  1611. {
  1612. local_apic_timer_c2_ok = 1;
  1613. return 0;
  1614. }
  1615. early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok);
  1616. static int __init parse_disable_apic_timer(char *arg)
  1617. {
  1618. disable_apic_timer = 1;
  1619. return 0;
  1620. }
  1621. early_param("noapictimer", parse_disable_apic_timer);
  1622. static int __init parse_nolapic_timer(char *arg)
  1623. {
  1624. disable_apic_timer = 1;
  1625. return 0;
  1626. }
  1627. early_param("nolapic_timer", parse_nolapic_timer);
  1628. static int __init apic_set_verbosity(char *arg)
  1629. {
  1630. if (!arg) {
  1631. #ifdef CONFIG_X86_64
  1632. skip_ioapic_setup = 0;
  1633. return 0;
  1634. #endif
  1635. return -EINVAL;
  1636. }
  1637. if (strcmp("debug", arg) == 0)
  1638. apic_verbosity = APIC_DEBUG;
  1639. else if (strcmp("verbose", arg) == 0)
  1640. apic_verbosity = APIC_VERBOSE;
  1641. else {
  1642. printk(KERN_WARNING "APIC Verbosity level %s not recognised"
  1643. " use apic=verbose or apic=debug\n", arg);
  1644. return -EINVAL;
  1645. }
  1646. return 0;
  1647. }
  1648. early_param("apic", apic_set_verbosity);
  1649. static int __init lapic_insert_resource(void)
  1650. {
  1651. if (!apic_phys)
  1652. return -1;
  1653. /* Put local APIC into the resource map. */
  1654. lapic_resource.start = apic_phys;
  1655. lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1;
  1656. insert_resource(&iomem_resource, &lapic_resource);
  1657. return 0;
  1658. }
  1659. /*
  1660. * need call insert after e820_reserve_resources()
  1661. * that is using request_resource
  1662. */
  1663. late_initcall(lapic_insert_resource);