apic.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517
  1. /*
  2. * Local APIC handling, local APIC timers
  3. *
  4. * (c) 1999, 2000, 2009 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/perf_event.h>
  17. #include <linux/kernel_stat.h>
  18. #include <linux/mc146818rtc.h>
  19. #include <linux/acpi_pmtmr.h>
  20. #include <linux/clockchips.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/ftrace.h>
  24. #include <linux/ioport.h>
  25. #include <linux/module.h>
  26. #include <linux/syscore_ops.h>
  27. #include <linux/delay.h>
  28. #include <linux/timex.h>
  29. #include <linux/i8253.h>
  30. #include <linux/dmar.h>
  31. #include <linux/init.h>
  32. #include <linux/cpu.h>
  33. #include <linux/dmi.h>
  34. #include <linux/smp.h>
  35. #include <linux/mm.h>
  36. #include <asm/irq_remapping.h>
  37. #include <asm/perf_event.h>
  38. #include <asm/x86_init.h>
  39. #include <asm/pgalloc.h>
  40. #include <linux/atomic.h>
  41. #include <asm/mpspec.h>
  42. #include <asm/i8259.h>
  43. #include <asm/proto.h>
  44. #include <asm/apic.h>
  45. #include <asm/io_apic.h>
  46. #include <asm/desc.h>
  47. #include <asm/hpet.h>
  48. #include <asm/idle.h>
  49. #include <asm/mtrr.h>
  50. #include <asm/time.h>
  51. #include <asm/smp.h>
  52. #include <asm/mce.h>
  53. #include <asm/tsc.h>
  54. #include <asm/hypervisor.h>
  55. unsigned int num_processors;
  56. unsigned disabled_cpus __cpuinitdata;
  57. /* Processor that is doing the boot up */
  58. unsigned int boot_cpu_physical_apicid = -1U;
  59. /*
  60. * The highest APIC ID seen during enumeration.
  61. */
  62. unsigned int max_physical_apicid;
  63. /*
  64. * Bitmask of physically existing CPUs:
  65. */
  66. physid_mask_t phys_cpu_present_map;
  67. /*
  68. * Map cpu index to physical APIC ID
  69. */
  70. DEFINE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid, BAD_APICID);
  71. DEFINE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid, BAD_APICID);
  72. EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid);
  73. EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
  74. #ifdef CONFIG_X86_32
  75. /*
  76. * On x86_32, the mapping between cpu and logical apicid may vary
  77. * depending on apic in use. The following early percpu variable is
  78. * used for the mapping. This is where the behaviors of x86_64 and 32
  79. * actually diverge. Let's keep it ugly for now.
  80. */
  81. DEFINE_EARLY_PER_CPU_READ_MOSTLY(int, x86_cpu_to_logical_apicid, BAD_APICID);
  82. /*
  83. * Knob to control our willingness to enable the local APIC.
  84. *
  85. * +1=force-enable
  86. */
  87. static int force_enable_local_apic __initdata;
  88. /*
  89. * APIC command line parameters
  90. */
  91. static int __init parse_lapic(char *arg)
  92. {
  93. force_enable_local_apic = 1;
  94. return 0;
  95. }
  96. early_param("lapic", parse_lapic);
  97. /* Local APIC was disabled by the BIOS and enabled by the kernel */
  98. static int enabled_via_apicbase;
  99. /*
  100. * Handle interrupt mode configuration register (IMCR).
  101. * This register controls whether the interrupt signals
  102. * that reach the BSP come from the master PIC or from the
  103. * local APIC. Before entering Symmetric I/O Mode, either
  104. * the BIOS or the operating system must switch out of
  105. * PIC Mode by changing the IMCR.
  106. */
  107. static inline void imcr_pic_to_apic(void)
  108. {
  109. /* select IMCR register */
  110. outb(0x70, 0x22);
  111. /* NMI and 8259 INTR go through APIC */
  112. outb(0x01, 0x23);
  113. }
  114. static inline void imcr_apic_to_pic(void)
  115. {
  116. /* select IMCR register */
  117. outb(0x70, 0x22);
  118. /* NMI and 8259 INTR go directly to BSP */
  119. outb(0x00, 0x23);
  120. }
  121. #endif
  122. #ifdef CONFIG_X86_64
  123. static int apic_calibrate_pmtmr __initdata;
  124. static __init int setup_apicpmtimer(char *s)
  125. {
  126. apic_calibrate_pmtmr = 1;
  127. notsc_setup(NULL);
  128. return 0;
  129. }
  130. __setup("apicpmtimer", setup_apicpmtimer);
  131. #endif
  132. int x2apic_mode;
  133. #ifdef CONFIG_X86_X2APIC
  134. /* x2apic enabled before OS handover */
  135. int x2apic_preenabled;
  136. static int x2apic_disabled;
  137. static int nox2apic;
  138. static __init int setup_nox2apic(char *str)
  139. {
  140. if (x2apic_enabled()) {
  141. int apicid = native_apic_msr_read(APIC_ID);
  142. if (apicid >= 255) {
  143. pr_warning("Apicid: %08x, cannot enforce nox2apic\n",
  144. apicid);
  145. return 0;
  146. }
  147. pr_warning("x2apic already enabled. will disable it\n");
  148. } else
  149. setup_clear_cpu_cap(X86_FEATURE_X2APIC);
  150. nox2apic = 1;
  151. return 0;
  152. }
  153. early_param("nox2apic", setup_nox2apic);
  154. #endif
  155. unsigned long mp_lapic_addr;
  156. int disable_apic;
  157. /* Disable local APIC timer from the kernel commandline or via dmi quirk */
  158. static int disable_apic_timer __initdata;
  159. /* Local APIC timer works in C2 */
  160. int local_apic_timer_c2_ok;
  161. EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok);
  162. int first_system_vector = 0xfe;
  163. /*
  164. * Debug level, exported for io_apic.c
  165. */
  166. unsigned int apic_verbosity;
  167. int pic_mode;
  168. /* Have we found an MP table */
  169. int smp_found_config;
  170. static struct resource lapic_resource = {
  171. .name = "Local APIC",
  172. .flags = IORESOURCE_MEM | IORESOURCE_BUSY,
  173. };
  174. unsigned int lapic_timer_frequency = 0;
  175. static void apic_pm_activate(void);
  176. static unsigned long apic_phys;
  177. /*
  178. * Get the LAPIC version
  179. */
  180. static inline int lapic_get_version(void)
  181. {
  182. return GET_APIC_VERSION(apic_read(APIC_LVR));
  183. }
  184. /*
  185. * Check, if the APIC is integrated or a separate chip
  186. */
  187. static inline int lapic_is_integrated(void)
  188. {
  189. #ifdef CONFIG_X86_64
  190. return 1;
  191. #else
  192. return APIC_INTEGRATED(lapic_get_version());
  193. #endif
  194. }
  195. /*
  196. * Check, whether this is a modern or a first generation APIC
  197. */
  198. static int modern_apic(void)
  199. {
  200. /* AMD systems use old APIC versions, so check the CPU */
  201. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
  202. boot_cpu_data.x86 >= 0xf)
  203. return 1;
  204. return lapic_get_version() >= 0x14;
  205. }
  206. /*
  207. * right after this call apic become NOOP driven
  208. * so apic->write/read doesn't do anything
  209. */
  210. static void __init apic_disable(void)
  211. {
  212. pr_info("APIC: switched to apic NOOP\n");
  213. apic = &apic_noop;
  214. }
  215. void native_apic_wait_icr_idle(void)
  216. {
  217. while (apic_read(APIC_ICR) & APIC_ICR_BUSY)
  218. cpu_relax();
  219. }
  220. u32 native_safe_apic_wait_icr_idle(void)
  221. {
  222. u32 send_status;
  223. int timeout;
  224. timeout = 0;
  225. do {
  226. send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
  227. if (!send_status)
  228. break;
  229. inc_irq_stat(icr_read_retry_count);
  230. udelay(100);
  231. } while (timeout++ < 1000);
  232. return send_status;
  233. }
  234. void native_apic_icr_write(u32 low, u32 id)
  235. {
  236. apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(id));
  237. apic_write(APIC_ICR, low);
  238. }
  239. u64 native_apic_icr_read(void)
  240. {
  241. u32 icr1, icr2;
  242. icr2 = apic_read(APIC_ICR2);
  243. icr1 = apic_read(APIC_ICR);
  244. return icr1 | ((u64)icr2 << 32);
  245. }
  246. #ifdef CONFIG_X86_32
  247. /**
  248. * get_physical_broadcast - Get number of physical broadcast IDs
  249. */
  250. int get_physical_broadcast(void)
  251. {
  252. return modern_apic() ? 0xff : 0xf;
  253. }
  254. #endif
  255. /**
  256. * lapic_get_maxlvt - get the maximum number of local vector table entries
  257. */
  258. int lapic_get_maxlvt(void)
  259. {
  260. unsigned int v;
  261. v = apic_read(APIC_LVR);
  262. /*
  263. * - we always have APIC integrated on 64bit mode
  264. * - 82489DXs do not report # of LVT entries
  265. */
  266. return APIC_INTEGRATED(GET_APIC_VERSION(v)) ? GET_APIC_MAXLVT(v) : 2;
  267. }
  268. /*
  269. * Local APIC timer
  270. */
  271. /* Clock divisor */
  272. #define APIC_DIVISOR 16
  273. /*
  274. * This function sets up the local APIC timer, with a timeout of
  275. * 'clocks' APIC bus clock. During calibration we actually call
  276. * this function twice on the boot CPU, once with a bogus timeout
  277. * value, second time for real. The other (noncalibrating) CPUs
  278. * call this function only once, with the real, calibrated value.
  279. *
  280. * We do reads before writes even if unnecessary, to get around the
  281. * P5 APIC double write bug.
  282. */
  283. static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
  284. {
  285. unsigned int lvtt_value, tmp_value;
  286. lvtt_value = LOCAL_TIMER_VECTOR;
  287. if (!oneshot)
  288. lvtt_value |= APIC_LVT_TIMER_PERIODIC;
  289. if (!lapic_is_integrated())
  290. lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
  291. if (!irqen)
  292. lvtt_value |= APIC_LVT_MASKED;
  293. apic_write(APIC_LVTT, lvtt_value);
  294. /*
  295. * Divide PICLK by 16
  296. */
  297. tmp_value = apic_read(APIC_TDCR);
  298. apic_write(APIC_TDCR,
  299. (tmp_value & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE)) |
  300. APIC_TDR_DIV_16);
  301. if (!oneshot)
  302. apic_write(APIC_TMICT, clocks / APIC_DIVISOR);
  303. }
  304. /*
  305. * Setup extended LVT, AMD specific
  306. *
  307. * Software should use the LVT offsets the BIOS provides. The offsets
  308. * are determined by the subsystems using it like those for MCE
  309. * threshold or IBS. On K8 only offset 0 (APIC500) and MCE interrupts
  310. * are supported. Beginning with family 10h at least 4 offsets are
  311. * available.
  312. *
  313. * Since the offsets must be consistent for all cores, we keep track
  314. * of the LVT offsets in software and reserve the offset for the same
  315. * vector also to be used on other cores. An offset is freed by
  316. * setting the entry to APIC_EILVT_MASKED.
  317. *
  318. * If the BIOS is right, there should be no conflicts. Otherwise a
  319. * "[Firmware Bug]: ..." error message is generated. However, if
  320. * software does not properly determines the offsets, it is not
  321. * necessarily a BIOS bug.
  322. */
  323. static atomic_t eilvt_offsets[APIC_EILVT_NR_MAX];
  324. static inline int eilvt_entry_is_changeable(unsigned int old, unsigned int new)
  325. {
  326. return (old & APIC_EILVT_MASKED)
  327. || (new == APIC_EILVT_MASKED)
  328. || ((new & ~APIC_EILVT_MASKED) == old);
  329. }
  330. static unsigned int reserve_eilvt_offset(int offset, unsigned int new)
  331. {
  332. unsigned int rsvd, vector;
  333. if (offset >= APIC_EILVT_NR_MAX)
  334. return ~0;
  335. rsvd = atomic_read(&eilvt_offsets[offset]);
  336. do {
  337. vector = rsvd & ~APIC_EILVT_MASKED; /* 0: unassigned */
  338. if (vector && !eilvt_entry_is_changeable(vector, new))
  339. /* may not change if vectors are different */
  340. return rsvd;
  341. rsvd = atomic_cmpxchg(&eilvt_offsets[offset], rsvd, new);
  342. } while (rsvd != new);
  343. rsvd &= ~APIC_EILVT_MASKED;
  344. if (rsvd && rsvd != vector)
  345. pr_info("LVT offset %d assigned for vector 0x%02x\n",
  346. offset, rsvd);
  347. return new;
  348. }
  349. /*
  350. * If mask=1, the LVT entry does not generate interrupts while mask=0
  351. * enables the vector. See also the BKDGs. Must be called with
  352. * preemption disabled.
  353. */
  354. int setup_APIC_eilvt(u8 offset, u8 vector, u8 msg_type, u8 mask)
  355. {
  356. unsigned long reg = APIC_EILVTn(offset);
  357. unsigned int new, old, reserved;
  358. new = (mask << 16) | (msg_type << 8) | vector;
  359. old = apic_read(reg);
  360. reserved = reserve_eilvt_offset(offset, new);
  361. if (reserved != new) {
  362. pr_err(FW_BUG "cpu %d, try to use APIC%lX (LVT offset %d) for "
  363. "vector 0x%x, but the register is already in use for "
  364. "vector 0x%x on another cpu\n",
  365. smp_processor_id(), reg, offset, new, reserved);
  366. return -EINVAL;
  367. }
  368. if (!eilvt_entry_is_changeable(old, new)) {
  369. pr_err(FW_BUG "cpu %d, try to use APIC%lX (LVT offset %d) for "
  370. "vector 0x%x, but the register is already in use for "
  371. "vector 0x%x on this cpu\n",
  372. smp_processor_id(), reg, offset, new, old);
  373. return -EBUSY;
  374. }
  375. apic_write(reg, new);
  376. return 0;
  377. }
  378. EXPORT_SYMBOL_GPL(setup_APIC_eilvt);
  379. /*
  380. * Program the next event, relative to now
  381. */
  382. static int lapic_next_event(unsigned long delta,
  383. struct clock_event_device *evt)
  384. {
  385. apic_write(APIC_TMICT, delta);
  386. return 0;
  387. }
  388. /*
  389. * Setup the lapic timer in periodic or oneshot mode
  390. */
  391. static void lapic_timer_setup(enum clock_event_mode mode,
  392. struct clock_event_device *evt)
  393. {
  394. unsigned long flags;
  395. unsigned int v;
  396. /* Lapic used as dummy for broadcast ? */
  397. if (evt->features & CLOCK_EVT_FEAT_DUMMY)
  398. return;
  399. local_irq_save(flags);
  400. switch (mode) {
  401. case CLOCK_EVT_MODE_PERIODIC:
  402. case CLOCK_EVT_MODE_ONESHOT:
  403. __setup_APIC_LVTT(lapic_timer_frequency,
  404. mode != CLOCK_EVT_MODE_PERIODIC, 1);
  405. break;
  406. case CLOCK_EVT_MODE_UNUSED:
  407. case CLOCK_EVT_MODE_SHUTDOWN:
  408. v = apic_read(APIC_LVTT);
  409. v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
  410. apic_write(APIC_LVTT, v);
  411. apic_write(APIC_TMICT, 0);
  412. break;
  413. case CLOCK_EVT_MODE_RESUME:
  414. /* Nothing to do here */
  415. break;
  416. }
  417. local_irq_restore(flags);
  418. }
  419. /*
  420. * Local APIC timer broadcast function
  421. */
  422. static void lapic_timer_broadcast(const struct cpumask *mask)
  423. {
  424. #ifdef CONFIG_SMP
  425. apic->send_IPI_mask(mask, LOCAL_TIMER_VECTOR);
  426. #endif
  427. }
  428. /*
  429. * The local apic timer can be used for any function which is CPU local.
  430. */
  431. static struct clock_event_device lapic_clockevent = {
  432. .name = "lapic",
  433. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT
  434. | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY,
  435. .shift = 32,
  436. .set_mode = lapic_timer_setup,
  437. .set_next_event = lapic_next_event,
  438. .broadcast = lapic_timer_broadcast,
  439. .rating = 100,
  440. .irq = -1,
  441. };
  442. static DEFINE_PER_CPU(struct clock_event_device, lapic_events);
  443. /*
  444. * Setup the local APIC timer for this CPU. Copy the initialized values
  445. * of the boot CPU and register the clock event in the framework.
  446. */
  447. static void __cpuinit setup_APIC_timer(void)
  448. {
  449. struct clock_event_device *levt = &__get_cpu_var(lapic_events);
  450. if (this_cpu_has(X86_FEATURE_ARAT)) {
  451. lapic_clockevent.features &= ~CLOCK_EVT_FEAT_C3STOP;
  452. /* Make LAPIC timer preferrable over percpu HPET */
  453. lapic_clockevent.rating = 150;
  454. }
  455. memcpy(levt, &lapic_clockevent, sizeof(*levt));
  456. levt->cpumask = cpumask_of(smp_processor_id());
  457. clockevents_register_device(levt);
  458. }
  459. /*
  460. * In this functions we calibrate APIC bus clocks to the external timer.
  461. *
  462. * We want to do the calibration only once since we want to have local timer
  463. * irqs syncron. CPUs connected by the same APIC bus have the very same bus
  464. * frequency.
  465. *
  466. * This was previously done by reading the PIT/HPET and waiting for a wrap
  467. * around to find out, that a tick has elapsed. I have a box, where the PIT
  468. * readout is broken, so it never gets out of the wait loop again. This was
  469. * also reported by others.
  470. *
  471. * Monitoring the jiffies value is inaccurate and the clockevents
  472. * infrastructure allows us to do a simple substitution of the interrupt
  473. * handler.
  474. *
  475. * The calibration routine also uses the pm_timer when possible, as the PIT
  476. * happens to run way too slow (factor 2.3 on my VAIO CoreDuo, which goes
  477. * back to normal later in the boot process).
  478. */
  479. #define LAPIC_CAL_LOOPS (HZ/10)
  480. static __initdata int lapic_cal_loops = -1;
  481. static __initdata long lapic_cal_t1, lapic_cal_t2;
  482. static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2;
  483. static __initdata unsigned long lapic_cal_pm1, lapic_cal_pm2;
  484. static __initdata unsigned long lapic_cal_j1, lapic_cal_j2;
  485. /*
  486. * Temporary interrupt handler.
  487. */
  488. static void __init lapic_cal_handler(struct clock_event_device *dev)
  489. {
  490. unsigned long long tsc = 0;
  491. long tapic = apic_read(APIC_TMCCT);
  492. unsigned long pm = acpi_pm_read_early();
  493. if (cpu_has_tsc)
  494. rdtscll(tsc);
  495. switch (lapic_cal_loops++) {
  496. case 0:
  497. lapic_cal_t1 = tapic;
  498. lapic_cal_tsc1 = tsc;
  499. lapic_cal_pm1 = pm;
  500. lapic_cal_j1 = jiffies;
  501. break;
  502. case LAPIC_CAL_LOOPS:
  503. lapic_cal_t2 = tapic;
  504. lapic_cal_tsc2 = tsc;
  505. if (pm < lapic_cal_pm1)
  506. pm += ACPI_PM_OVRRUN;
  507. lapic_cal_pm2 = pm;
  508. lapic_cal_j2 = jiffies;
  509. break;
  510. }
  511. }
  512. static int __init
  513. calibrate_by_pmtimer(long deltapm, long *delta, long *deltatsc)
  514. {
  515. const long pm_100ms = PMTMR_TICKS_PER_SEC / 10;
  516. const long pm_thresh = pm_100ms / 100;
  517. unsigned long mult;
  518. u64 res;
  519. #ifndef CONFIG_X86_PM_TIMER
  520. return -1;
  521. #endif
  522. apic_printk(APIC_VERBOSE, "... PM-Timer delta = %ld\n", deltapm);
  523. /* Check, if the PM timer is available */
  524. if (!deltapm)
  525. return -1;
  526. mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC, 22);
  527. if (deltapm > (pm_100ms - pm_thresh) &&
  528. deltapm < (pm_100ms + pm_thresh)) {
  529. apic_printk(APIC_VERBOSE, "... PM-Timer result ok\n");
  530. return 0;
  531. }
  532. res = (((u64)deltapm) * mult) >> 22;
  533. do_div(res, 1000000);
  534. pr_warning("APIC calibration not consistent "
  535. "with PM-Timer: %ldms instead of 100ms\n",(long)res);
  536. /* Correct the lapic counter value */
  537. res = (((u64)(*delta)) * pm_100ms);
  538. do_div(res, deltapm);
  539. pr_info("APIC delta adjusted to PM-Timer: "
  540. "%lu (%ld)\n", (unsigned long)res, *delta);
  541. *delta = (long)res;
  542. /* Correct the tsc counter value */
  543. if (cpu_has_tsc) {
  544. res = (((u64)(*deltatsc)) * pm_100ms);
  545. do_div(res, deltapm);
  546. apic_printk(APIC_VERBOSE, "TSC delta adjusted to "
  547. "PM-Timer: %lu (%ld)\n",
  548. (unsigned long)res, *deltatsc);
  549. *deltatsc = (long)res;
  550. }
  551. return 0;
  552. }
  553. static int __init calibrate_APIC_clock(void)
  554. {
  555. struct clock_event_device *levt = &__get_cpu_var(lapic_events);
  556. void (*real_handler)(struct clock_event_device *dev);
  557. unsigned long deltaj;
  558. long delta, deltatsc;
  559. int pm_referenced = 0;
  560. /**
  561. * check if lapic timer has already been calibrated by platform
  562. * specific routine, such as tsc calibration code. if so, we just fill
  563. * in the clockevent structure and return.
  564. */
  565. if (lapic_timer_frequency) {
  566. apic_printk(APIC_VERBOSE, "lapic timer already calibrated %d\n",
  567. lapic_timer_frequency);
  568. lapic_clockevent.mult = div_sc(lapic_timer_frequency/APIC_DIVISOR,
  569. TICK_NSEC, lapic_clockevent.shift);
  570. lapic_clockevent.max_delta_ns =
  571. clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
  572. lapic_clockevent.min_delta_ns =
  573. clockevent_delta2ns(0xF, &lapic_clockevent);
  574. lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
  575. return 0;
  576. }
  577. local_irq_disable();
  578. /* Replace the global interrupt handler */
  579. real_handler = global_clock_event->event_handler;
  580. global_clock_event->event_handler = lapic_cal_handler;
  581. /*
  582. * Setup the APIC counter to maximum. There is no way the lapic
  583. * can underflow in the 100ms detection time frame
  584. */
  585. __setup_APIC_LVTT(0xffffffff, 0, 0);
  586. /* Let the interrupts run */
  587. local_irq_enable();
  588. while (lapic_cal_loops <= LAPIC_CAL_LOOPS)
  589. cpu_relax();
  590. local_irq_disable();
  591. /* Restore the real event handler */
  592. global_clock_event->event_handler = real_handler;
  593. /* Build delta t1-t2 as apic timer counts down */
  594. delta = lapic_cal_t1 - lapic_cal_t2;
  595. apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
  596. deltatsc = (long)(lapic_cal_tsc2 - lapic_cal_tsc1);
  597. /* we trust the PM based calibration if possible */
  598. pm_referenced = !calibrate_by_pmtimer(lapic_cal_pm2 - lapic_cal_pm1,
  599. &delta, &deltatsc);
  600. /* Calculate the scaled math multiplication factor */
  601. lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS,
  602. lapic_clockevent.shift);
  603. lapic_clockevent.max_delta_ns =
  604. clockevent_delta2ns(0x7FFFFFFF, &lapic_clockevent);
  605. lapic_clockevent.min_delta_ns =
  606. clockevent_delta2ns(0xF, &lapic_clockevent);
  607. lapic_timer_frequency = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS;
  608. apic_printk(APIC_VERBOSE, "..... delta %ld\n", delta);
  609. apic_printk(APIC_VERBOSE, "..... mult: %u\n", lapic_clockevent.mult);
  610. apic_printk(APIC_VERBOSE, "..... calibration result: %u\n",
  611. lapic_timer_frequency);
  612. if (cpu_has_tsc) {
  613. apic_printk(APIC_VERBOSE, "..... CPU clock speed is "
  614. "%ld.%04ld MHz.\n",
  615. (deltatsc / LAPIC_CAL_LOOPS) / (1000000 / HZ),
  616. (deltatsc / LAPIC_CAL_LOOPS) % (1000000 / HZ));
  617. }
  618. apic_printk(APIC_VERBOSE, "..... host bus clock speed is "
  619. "%u.%04u MHz.\n",
  620. lapic_timer_frequency / (1000000 / HZ),
  621. lapic_timer_frequency % (1000000 / HZ));
  622. /*
  623. * Do a sanity check on the APIC calibration result
  624. */
  625. if (lapic_timer_frequency < (1000000 / HZ)) {
  626. local_irq_enable();
  627. pr_warning("APIC frequency too slow, disabling apic timer\n");
  628. return -1;
  629. }
  630. levt->features &= ~CLOCK_EVT_FEAT_DUMMY;
  631. /*
  632. * PM timer calibration failed or not turned on
  633. * so lets try APIC timer based calibration
  634. */
  635. if (!pm_referenced) {
  636. apic_printk(APIC_VERBOSE, "... verify APIC timer\n");
  637. /*
  638. * Setup the apic timer manually
  639. */
  640. levt->event_handler = lapic_cal_handler;
  641. lapic_timer_setup(CLOCK_EVT_MODE_PERIODIC, levt);
  642. lapic_cal_loops = -1;
  643. /* Let the interrupts run */
  644. local_irq_enable();
  645. while (lapic_cal_loops <= LAPIC_CAL_LOOPS)
  646. cpu_relax();
  647. /* Stop the lapic timer */
  648. lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt);
  649. /* Jiffies delta */
  650. deltaj = lapic_cal_j2 - lapic_cal_j1;
  651. apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj);
  652. /* Check, if the jiffies result is consistent */
  653. if (deltaj >= LAPIC_CAL_LOOPS-2 && deltaj <= LAPIC_CAL_LOOPS+2)
  654. apic_printk(APIC_VERBOSE, "... jiffies result ok\n");
  655. else
  656. levt->features |= CLOCK_EVT_FEAT_DUMMY;
  657. } else
  658. local_irq_enable();
  659. if (levt->features & CLOCK_EVT_FEAT_DUMMY) {
  660. pr_warning("APIC timer disabled due to verification failure\n");
  661. return -1;
  662. }
  663. return 0;
  664. }
  665. /*
  666. * Setup the boot APIC
  667. *
  668. * Calibrate and verify the result.
  669. */
  670. void __init setup_boot_APIC_clock(void)
  671. {
  672. /*
  673. * The local apic timer can be disabled via the kernel
  674. * commandline or from the CPU detection code. Register the lapic
  675. * timer as a dummy clock event source on SMP systems, so the
  676. * broadcast mechanism is used. On UP systems simply ignore it.
  677. */
  678. if (disable_apic_timer) {
  679. pr_info("Disabling APIC timer\n");
  680. /* No broadcast on UP ! */
  681. if (num_possible_cpus() > 1) {
  682. lapic_clockevent.mult = 1;
  683. setup_APIC_timer();
  684. }
  685. return;
  686. }
  687. apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n"
  688. "calibrating APIC timer ...\n");
  689. if (calibrate_APIC_clock()) {
  690. /* No broadcast on UP ! */
  691. if (num_possible_cpus() > 1)
  692. setup_APIC_timer();
  693. return;
  694. }
  695. /*
  696. * If nmi_watchdog is set to IO_APIC, we need the
  697. * PIT/HPET going. Otherwise register lapic as a dummy
  698. * device.
  699. */
  700. lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
  701. /* Setup the lapic or request the broadcast */
  702. setup_APIC_timer();
  703. }
  704. void __cpuinit setup_secondary_APIC_clock(void)
  705. {
  706. setup_APIC_timer();
  707. }
  708. /*
  709. * The guts of the apic timer interrupt
  710. */
  711. static void local_apic_timer_interrupt(void)
  712. {
  713. int cpu = smp_processor_id();
  714. struct clock_event_device *evt = &per_cpu(lapic_events, cpu);
  715. /*
  716. * Normally we should not be here till LAPIC has been initialized but
  717. * in some cases like kdump, its possible that there is a pending LAPIC
  718. * timer interrupt from previous kernel's context and is delivered in
  719. * new kernel the moment interrupts are enabled.
  720. *
  721. * Interrupts are enabled early and LAPIC is setup much later, hence
  722. * its possible that when we get here evt->event_handler is NULL.
  723. * Check for event_handler being NULL and discard the interrupt as
  724. * spurious.
  725. */
  726. if (!evt->event_handler) {
  727. pr_warning("Spurious LAPIC timer interrupt on cpu %d\n", cpu);
  728. /* Switch it off */
  729. lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt);
  730. return;
  731. }
  732. /*
  733. * the NMI deadlock-detector uses this.
  734. */
  735. inc_irq_stat(apic_timer_irqs);
  736. evt->event_handler(evt);
  737. }
  738. /*
  739. * Local APIC timer interrupt. This is the most natural way for doing
  740. * local interrupts, but local timer interrupts can be emulated by
  741. * broadcast interrupts too. [in case the hw doesn't support APIC timers]
  742. *
  743. * [ if a single-CPU system runs an SMP kernel then we call the local
  744. * interrupt as well. Thus we cannot inline the local irq ... ]
  745. */
  746. void __irq_entry smp_apic_timer_interrupt(struct pt_regs *regs)
  747. {
  748. struct pt_regs *old_regs = set_irq_regs(regs);
  749. /*
  750. * NOTE! We'd better ACK the irq immediately,
  751. * because timer handling can be slow.
  752. */
  753. ack_APIC_irq();
  754. /*
  755. * update_process_times() expects us to have done irq_enter().
  756. * Besides, if we don't timer interrupts ignore the global
  757. * interrupt lock, which is the WrongThing (tm) to do.
  758. */
  759. irq_enter();
  760. exit_idle();
  761. local_apic_timer_interrupt();
  762. irq_exit();
  763. set_irq_regs(old_regs);
  764. }
  765. int setup_profiling_timer(unsigned int multiplier)
  766. {
  767. return -EINVAL;
  768. }
  769. /*
  770. * Local APIC start and shutdown
  771. */
  772. /**
  773. * clear_local_APIC - shutdown the local APIC
  774. *
  775. * This is called, when a CPU is disabled and before rebooting, so the state of
  776. * the local APIC has no dangling leftovers. Also used to cleanout any BIOS
  777. * leftovers during boot.
  778. */
  779. void clear_local_APIC(void)
  780. {
  781. int maxlvt;
  782. u32 v;
  783. /* APIC hasn't been mapped yet */
  784. if (!x2apic_mode && !apic_phys)
  785. return;
  786. maxlvt = lapic_get_maxlvt();
  787. /*
  788. * Masking an LVT entry can trigger a local APIC error
  789. * if the vector is zero. Mask LVTERR first to prevent this.
  790. */
  791. if (maxlvt >= 3) {
  792. v = ERROR_APIC_VECTOR; /* any non-zero vector will do */
  793. apic_write(APIC_LVTERR, v | APIC_LVT_MASKED);
  794. }
  795. /*
  796. * Careful: we have to set masks only first to deassert
  797. * any level-triggered sources.
  798. */
  799. v = apic_read(APIC_LVTT);
  800. apic_write(APIC_LVTT, v | APIC_LVT_MASKED);
  801. v = apic_read(APIC_LVT0);
  802. apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
  803. v = apic_read(APIC_LVT1);
  804. apic_write(APIC_LVT1, v | APIC_LVT_MASKED);
  805. if (maxlvt >= 4) {
  806. v = apic_read(APIC_LVTPC);
  807. apic_write(APIC_LVTPC, v | APIC_LVT_MASKED);
  808. }
  809. /* lets not touch this if we didn't frob it */
  810. #ifdef CONFIG_X86_THERMAL_VECTOR
  811. if (maxlvt >= 5) {
  812. v = apic_read(APIC_LVTTHMR);
  813. apic_write(APIC_LVTTHMR, v | APIC_LVT_MASKED);
  814. }
  815. #endif
  816. #ifdef CONFIG_X86_MCE_INTEL
  817. if (maxlvt >= 6) {
  818. v = apic_read(APIC_LVTCMCI);
  819. if (!(v & APIC_LVT_MASKED))
  820. apic_write(APIC_LVTCMCI, v | APIC_LVT_MASKED);
  821. }
  822. #endif
  823. /*
  824. * Clean APIC state for other OSs:
  825. */
  826. apic_write(APIC_LVTT, APIC_LVT_MASKED);
  827. apic_write(APIC_LVT0, APIC_LVT_MASKED);
  828. apic_write(APIC_LVT1, APIC_LVT_MASKED);
  829. if (maxlvt >= 3)
  830. apic_write(APIC_LVTERR, APIC_LVT_MASKED);
  831. if (maxlvt >= 4)
  832. apic_write(APIC_LVTPC, APIC_LVT_MASKED);
  833. /* Integrated APIC (!82489DX) ? */
  834. if (lapic_is_integrated()) {
  835. if (maxlvt > 3)
  836. /* Clear ESR due to Pentium errata 3AP and 11AP */
  837. apic_write(APIC_ESR, 0);
  838. apic_read(APIC_ESR);
  839. }
  840. }
  841. /**
  842. * disable_local_APIC - clear and disable the local APIC
  843. */
  844. void disable_local_APIC(void)
  845. {
  846. unsigned int value;
  847. /* APIC hasn't been mapped yet */
  848. if (!x2apic_mode && !apic_phys)
  849. return;
  850. clear_local_APIC();
  851. /*
  852. * Disable APIC (implies clearing of registers
  853. * for 82489DX!).
  854. */
  855. value = apic_read(APIC_SPIV);
  856. value &= ~APIC_SPIV_APIC_ENABLED;
  857. apic_write(APIC_SPIV, value);
  858. #ifdef CONFIG_X86_32
  859. /*
  860. * When LAPIC was disabled by the BIOS and enabled by the kernel,
  861. * restore the disabled state.
  862. */
  863. if (enabled_via_apicbase) {
  864. unsigned int l, h;
  865. rdmsr(MSR_IA32_APICBASE, l, h);
  866. l &= ~MSR_IA32_APICBASE_ENABLE;
  867. wrmsr(MSR_IA32_APICBASE, l, h);
  868. }
  869. #endif
  870. }
  871. /*
  872. * If Linux enabled the LAPIC against the BIOS default disable it down before
  873. * re-entering the BIOS on shutdown. Otherwise the BIOS may get confused and
  874. * not power-off. Additionally clear all LVT entries before disable_local_APIC
  875. * for the case where Linux didn't enable the LAPIC.
  876. */
  877. void lapic_shutdown(void)
  878. {
  879. unsigned long flags;
  880. if (!cpu_has_apic && !apic_from_smp_config())
  881. return;
  882. local_irq_save(flags);
  883. #ifdef CONFIG_X86_32
  884. if (!enabled_via_apicbase)
  885. clear_local_APIC();
  886. else
  887. #endif
  888. disable_local_APIC();
  889. local_irq_restore(flags);
  890. }
  891. /*
  892. * This is to verify that we're looking at a real local APIC.
  893. * Check these against your board if the CPUs aren't getting
  894. * started for no apparent reason.
  895. */
  896. int __init verify_local_APIC(void)
  897. {
  898. unsigned int reg0, reg1;
  899. /*
  900. * The version register is read-only in a real APIC.
  901. */
  902. reg0 = apic_read(APIC_LVR);
  903. apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0);
  904. apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK);
  905. reg1 = apic_read(APIC_LVR);
  906. apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1);
  907. /*
  908. * The two version reads above should print the same
  909. * numbers. If the second one is different, then we
  910. * poke at a non-APIC.
  911. */
  912. if (reg1 != reg0)
  913. return 0;
  914. /*
  915. * Check if the version looks reasonably.
  916. */
  917. reg1 = GET_APIC_VERSION(reg0);
  918. if (reg1 == 0x00 || reg1 == 0xff)
  919. return 0;
  920. reg1 = lapic_get_maxlvt();
  921. if (reg1 < 0x02 || reg1 == 0xff)
  922. return 0;
  923. /*
  924. * The ID register is read/write in a real APIC.
  925. */
  926. reg0 = apic_read(APIC_ID);
  927. apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0);
  928. apic_write(APIC_ID, reg0 ^ apic->apic_id_mask);
  929. reg1 = apic_read(APIC_ID);
  930. apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg1);
  931. apic_write(APIC_ID, reg0);
  932. if (reg1 != (reg0 ^ apic->apic_id_mask))
  933. return 0;
  934. /*
  935. * The next two are just to see if we have sane values.
  936. * They're only really relevant if we're in Virtual Wire
  937. * compatibility mode, but most boxes are anymore.
  938. */
  939. reg0 = apic_read(APIC_LVT0);
  940. apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0);
  941. reg1 = apic_read(APIC_LVT1);
  942. apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1);
  943. return 1;
  944. }
  945. /**
  946. * sync_Arb_IDs - synchronize APIC bus arbitration IDs
  947. */
  948. void __init sync_Arb_IDs(void)
  949. {
  950. /*
  951. * Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 And not
  952. * needed on AMD.
  953. */
  954. if (modern_apic() || boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
  955. return;
  956. /*
  957. * Wait for idle.
  958. */
  959. apic_wait_icr_idle();
  960. apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n");
  961. apic_write(APIC_ICR, APIC_DEST_ALLINC |
  962. APIC_INT_LEVELTRIG | APIC_DM_INIT);
  963. }
  964. /*
  965. * An initial setup of the virtual wire mode.
  966. */
  967. void __init init_bsp_APIC(void)
  968. {
  969. unsigned int value;
  970. /*
  971. * Don't do the setup now if we have a SMP BIOS as the
  972. * through-I/O-APIC virtual wire mode might be active.
  973. */
  974. if (smp_found_config || !cpu_has_apic)
  975. return;
  976. /*
  977. * Do not trust the local APIC being empty at bootup.
  978. */
  979. clear_local_APIC();
  980. /*
  981. * Enable APIC.
  982. */
  983. value = apic_read(APIC_SPIV);
  984. value &= ~APIC_VECTOR_MASK;
  985. value |= APIC_SPIV_APIC_ENABLED;
  986. #ifdef CONFIG_X86_32
  987. /* This bit is reserved on P4/Xeon and should be cleared */
  988. if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
  989. (boot_cpu_data.x86 == 15))
  990. value &= ~APIC_SPIV_FOCUS_DISABLED;
  991. else
  992. #endif
  993. value |= APIC_SPIV_FOCUS_DISABLED;
  994. value |= SPURIOUS_APIC_VECTOR;
  995. apic_write(APIC_SPIV, value);
  996. /*
  997. * Set up the virtual wire mode.
  998. */
  999. apic_write(APIC_LVT0, APIC_DM_EXTINT);
  1000. value = APIC_DM_NMI;
  1001. if (!lapic_is_integrated()) /* 82489DX */
  1002. value |= APIC_LVT_LEVEL_TRIGGER;
  1003. apic_write(APIC_LVT1, value);
  1004. }
  1005. static void __cpuinit lapic_setup_esr(void)
  1006. {
  1007. unsigned int oldvalue, value, maxlvt;
  1008. if (!lapic_is_integrated()) {
  1009. pr_info("No ESR for 82489DX.\n");
  1010. return;
  1011. }
  1012. if (apic->disable_esr) {
  1013. /*
  1014. * Something untraceable is creating bad interrupts on
  1015. * secondary quads ... for the moment, just leave the
  1016. * ESR disabled - we can't do anything useful with the
  1017. * errors anyway - mbligh
  1018. */
  1019. pr_info("Leaving ESR disabled.\n");
  1020. return;
  1021. }
  1022. maxlvt = lapic_get_maxlvt();
  1023. if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
  1024. apic_write(APIC_ESR, 0);
  1025. oldvalue = apic_read(APIC_ESR);
  1026. /* enables sending errors */
  1027. value = ERROR_APIC_VECTOR;
  1028. apic_write(APIC_LVTERR, value);
  1029. /*
  1030. * spec says clear errors after enabling vector.
  1031. */
  1032. if (maxlvt > 3)
  1033. apic_write(APIC_ESR, 0);
  1034. value = apic_read(APIC_ESR);
  1035. if (value != oldvalue)
  1036. apic_printk(APIC_VERBOSE, "ESR value before enabling "
  1037. "vector: 0x%08x after: 0x%08x\n",
  1038. oldvalue, value);
  1039. }
  1040. /**
  1041. * setup_local_APIC - setup the local APIC
  1042. *
  1043. * Used to setup local APIC while initializing BSP or bringin up APs.
  1044. * Always called with preemption disabled.
  1045. */
  1046. void __cpuinit setup_local_APIC(void)
  1047. {
  1048. int cpu = smp_processor_id();
  1049. unsigned int value, queued;
  1050. int i, j, acked = 0;
  1051. unsigned long long tsc = 0, ntsc;
  1052. long long max_loops = cpu_khz;
  1053. if (cpu_has_tsc)
  1054. rdtscll(tsc);
  1055. if (disable_apic) {
  1056. disable_ioapic_support();
  1057. return;
  1058. }
  1059. #ifdef CONFIG_X86_32
  1060. /* Pound the ESR really hard over the head with a big hammer - mbligh */
  1061. if (lapic_is_integrated() && apic->disable_esr) {
  1062. apic_write(APIC_ESR, 0);
  1063. apic_write(APIC_ESR, 0);
  1064. apic_write(APIC_ESR, 0);
  1065. apic_write(APIC_ESR, 0);
  1066. }
  1067. #endif
  1068. perf_events_lapic_init();
  1069. /*
  1070. * Double-check whether this APIC is really registered.
  1071. * This is meaningless in clustered apic mode, so we skip it.
  1072. */
  1073. BUG_ON(!apic->apic_id_registered());
  1074. /*
  1075. * Intel recommends to set DFR, LDR and TPR before enabling
  1076. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  1077. * document number 292116). So here it goes...
  1078. */
  1079. apic->init_apic_ldr();
  1080. #ifdef CONFIG_X86_32
  1081. /*
  1082. * APIC LDR is initialized. If logical_apicid mapping was
  1083. * initialized during get_smp_config(), make sure it matches the
  1084. * actual value.
  1085. */
  1086. i = early_per_cpu(x86_cpu_to_logical_apicid, cpu);
  1087. WARN_ON(i != BAD_APICID && i != logical_smp_processor_id());
  1088. /* always use the value from LDR */
  1089. early_per_cpu(x86_cpu_to_logical_apicid, cpu) =
  1090. logical_smp_processor_id();
  1091. /*
  1092. * Some NUMA implementations (NUMAQ) don't initialize apicid to
  1093. * node mapping during NUMA init. Now that logical apicid is
  1094. * guaranteed to be known, give it another chance. This is already
  1095. * a bit too late - percpu allocation has already happened without
  1096. * proper NUMA affinity.
  1097. */
  1098. if (apic->x86_32_numa_cpu_node)
  1099. set_apicid_to_node(early_per_cpu(x86_cpu_to_apicid, cpu),
  1100. apic->x86_32_numa_cpu_node(cpu));
  1101. #endif
  1102. /*
  1103. * Set Task Priority to 'accept all'. We never change this
  1104. * later on.
  1105. */
  1106. value = apic_read(APIC_TASKPRI);
  1107. value &= ~APIC_TPRI_MASK;
  1108. apic_write(APIC_TASKPRI, value);
  1109. /*
  1110. * After a crash, we no longer service the interrupts and a pending
  1111. * interrupt from previous kernel might still have ISR bit set.
  1112. *
  1113. * Most probably by now CPU has serviced that pending interrupt and
  1114. * it might not have done the ack_APIC_irq() because it thought,
  1115. * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it
  1116. * does not clear the ISR bit and cpu thinks it has already serivced
  1117. * the interrupt. Hence a vector might get locked. It was noticed
  1118. * for timer irq (vector 0x31). Issue an extra EOI to clear ISR.
  1119. */
  1120. do {
  1121. queued = 0;
  1122. for (i = APIC_ISR_NR - 1; i >= 0; i--)
  1123. queued |= apic_read(APIC_IRR + i*0x10);
  1124. for (i = APIC_ISR_NR - 1; i >= 0; i--) {
  1125. value = apic_read(APIC_ISR + i*0x10);
  1126. for (j = 31; j >= 0; j--) {
  1127. if (value & (1<<j)) {
  1128. ack_APIC_irq();
  1129. acked++;
  1130. }
  1131. }
  1132. }
  1133. if (acked > 256) {
  1134. printk(KERN_ERR "LAPIC pending interrupts after %d EOI\n",
  1135. acked);
  1136. break;
  1137. }
  1138. if (queued) {
  1139. if (cpu_has_tsc) {
  1140. rdtscll(ntsc);
  1141. max_loops = (cpu_khz << 10) - (ntsc - tsc);
  1142. } else
  1143. max_loops--;
  1144. }
  1145. } while (queued && max_loops > 0);
  1146. WARN_ON(max_loops <= 0);
  1147. /*
  1148. * Now that we are all set up, enable the APIC
  1149. */
  1150. value = apic_read(APIC_SPIV);
  1151. value &= ~APIC_VECTOR_MASK;
  1152. /*
  1153. * Enable APIC
  1154. */
  1155. value |= APIC_SPIV_APIC_ENABLED;
  1156. #ifdef CONFIG_X86_32
  1157. /*
  1158. * Some unknown Intel IO/APIC (or APIC) errata is biting us with
  1159. * certain networking cards. If high frequency interrupts are
  1160. * happening on a particular IOAPIC pin, plus the IOAPIC routing
  1161. * entry is masked/unmasked at a high rate as well then sooner or
  1162. * later IOAPIC line gets 'stuck', no more interrupts are received
  1163. * from the device. If focus CPU is disabled then the hang goes
  1164. * away, oh well :-(
  1165. *
  1166. * [ This bug can be reproduced easily with a level-triggered
  1167. * PCI Ne2000 networking cards and PII/PIII processors, dual
  1168. * BX chipset. ]
  1169. */
  1170. /*
  1171. * Actually disabling the focus CPU check just makes the hang less
  1172. * frequent as it makes the interrupt distributon model be more
  1173. * like LRU than MRU (the short-term load is more even across CPUs).
  1174. * See also the comment in end_level_ioapic_irq(). --macro
  1175. */
  1176. /*
  1177. * - enable focus processor (bit==0)
  1178. * - 64bit mode always use processor focus
  1179. * so no need to set it
  1180. */
  1181. value &= ~APIC_SPIV_FOCUS_DISABLED;
  1182. #endif
  1183. /*
  1184. * Set spurious IRQ vector
  1185. */
  1186. value |= SPURIOUS_APIC_VECTOR;
  1187. apic_write(APIC_SPIV, value);
  1188. /*
  1189. * Set up LVT0, LVT1:
  1190. *
  1191. * set up through-local-APIC on the BP's LINT0. This is not
  1192. * strictly necessary in pure symmetric-IO mode, but sometimes
  1193. * we delegate interrupts to the 8259A.
  1194. */
  1195. /*
  1196. * TODO: set up through-local-APIC from through-I/O-APIC? --macro
  1197. */
  1198. value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
  1199. if (!cpu && (pic_mode || !value)) {
  1200. value = APIC_DM_EXTINT;
  1201. apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", cpu);
  1202. } else {
  1203. value = APIC_DM_EXTINT | APIC_LVT_MASKED;
  1204. apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", cpu);
  1205. }
  1206. apic_write(APIC_LVT0, value);
  1207. /*
  1208. * only the BP should see the LINT1 NMI signal, obviously.
  1209. */
  1210. if (!cpu)
  1211. value = APIC_DM_NMI;
  1212. else
  1213. value = APIC_DM_NMI | APIC_LVT_MASKED;
  1214. if (!lapic_is_integrated()) /* 82489DX */
  1215. value |= APIC_LVT_LEVEL_TRIGGER;
  1216. apic_write(APIC_LVT1, value);
  1217. #ifdef CONFIG_X86_MCE_INTEL
  1218. /* Recheck CMCI information after local APIC is up on CPU #0 */
  1219. if (!cpu)
  1220. cmci_recheck();
  1221. #endif
  1222. }
  1223. void __cpuinit end_local_APIC_setup(void)
  1224. {
  1225. lapic_setup_esr();
  1226. #ifdef CONFIG_X86_32
  1227. {
  1228. unsigned int value;
  1229. /* Disable the local apic timer */
  1230. value = apic_read(APIC_LVTT);
  1231. value |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
  1232. apic_write(APIC_LVTT, value);
  1233. }
  1234. #endif
  1235. apic_pm_activate();
  1236. }
  1237. void __init bsp_end_local_APIC_setup(void)
  1238. {
  1239. end_local_APIC_setup();
  1240. /*
  1241. * Now that local APIC setup is completed for BP, configure the fault
  1242. * handling for interrupt remapping.
  1243. */
  1244. if (irq_remapping_enabled)
  1245. irq_remap_enable_fault_handling();
  1246. }
  1247. #ifdef CONFIG_X86_X2APIC
  1248. /*
  1249. * Need to disable xapic and x2apic at the same time and then enable xapic mode
  1250. */
  1251. static inline void __disable_x2apic(u64 msr)
  1252. {
  1253. wrmsrl(MSR_IA32_APICBASE,
  1254. msr & ~(X2APIC_ENABLE | XAPIC_ENABLE));
  1255. wrmsrl(MSR_IA32_APICBASE, msr & ~X2APIC_ENABLE);
  1256. }
  1257. static __init void disable_x2apic(void)
  1258. {
  1259. u64 msr;
  1260. if (!cpu_has_x2apic)
  1261. return;
  1262. rdmsrl(MSR_IA32_APICBASE, msr);
  1263. if (msr & X2APIC_ENABLE) {
  1264. u32 x2apic_id = read_apic_id();
  1265. if (x2apic_id >= 255)
  1266. panic("Cannot disable x2apic, id: %08x\n", x2apic_id);
  1267. pr_info("Disabling x2apic\n");
  1268. __disable_x2apic(msr);
  1269. if (nox2apic) {
  1270. clear_cpu_cap(&cpu_data(0), X86_FEATURE_X2APIC);
  1271. setup_clear_cpu_cap(X86_FEATURE_X2APIC);
  1272. }
  1273. x2apic_disabled = 1;
  1274. x2apic_mode = 0;
  1275. register_lapic_address(mp_lapic_addr);
  1276. }
  1277. }
  1278. void check_x2apic(void)
  1279. {
  1280. if (x2apic_enabled()) {
  1281. pr_info("x2apic enabled by BIOS, switching to x2apic ops\n");
  1282. x2apic_preenabled = x2apic_mode = 1;
  1283. }
  1284. }
  1285. void enable_x2apic(void)
  1286. {
  1287. u64 msr;
  1288. rdmsrl(MSR_IA32_APICBASE, msr);
  1289. if (x2apic_disabled) {
  1290. __disable_x2apic(msr);
  1291. return;
  1292. }
  1293. if (!x2apic_mode)
  1294. return;
  1295. if (!(msr & X2APIC_ENABLE)) {
  1296. printk_once(KERN_INFO "Enabling x2apic\n");
  1297. wrmsrl(MSR_IA32_APICBASE, msr | X2APIC_ENABLE);
  1298. }
  1299. }
  1300. #endif /* CONFIG_X86_X2APIC */
  1301. int __init enable_IR(void)
  1302. {
  1303. #ifdef CONFIG_IRQ_REMAP
  1304. if (!irq_remapping_supported()) {
  1305. pr_debug("intr-remapping not supported\n");
  1306. return -1;
  1307. }
  1308. if (!x2apic_preenabled && skip_ioapic_setup) {
  1309. pr_info("Skipped enabling intr-remap because of skipping "
  1310. "io-apic setup\n");
  1311. return -1;
  1312. }
  1313. return irq_remapping_enable();
  1314. #endif
  1315. return -1;
  1316. }
  1317. void __init enable_IR_x2apic(void)
  1318. {
  1319. unsigned long flags;
  1320. int ret, x2apic_enabled = 0;
  1321. int hardware_init_ret;
  1322. /* Make sure irq_remap_ops are initialized */
  1323. setup_irq_remapping_ops();
  1324. hardware_init_ret = irq_remapping_prepare();
  1325. if (hardware_init_ret && !x2apic_supported())
  1326. return;
  1327. ret = save_ioapic_entries();
  1328. if (ret) {
  1329. pr_info("Saving IO-APIC state failed: %d\n", ret);
  1330. return;
  1331. }
  1332. local_irq_save(flags);
  1333. legacy_pic->mask_all();
  1334. mask_ioapic_entries();
  1335. if (x2apic_preenabled && nox2apic)
  1336. disable_x2apic();
  1337. if (hardware_init_ret)
  1338. ret = -1;
  1339. else
  1340. ret = enable_IR();
  1341. if (!x2apic_supported())
  1342. goto skip_x2apic;
  1343. if (ret < 0) {
  1344. /* IR is required if there is APIC ID > 255 even when running
  1345. * under KVM
  1346. */
  1347. if (max_physical_apicid > 255 ||
  1348. !hypervisor_x2apic_available()) {
  1349. if (x2apic_preenabled)
  1350. disable_x2apic();
  1351. goto skip_x2apic;
  1352. }
  1353. /*
  1354. * without IR all CPUs can be addressed by IOAPIC/MSI
  1355. * only in physical mode
  1356. */
  1357. x2apic_force_phys();
  1358. }
  1359. if (ret == IRQ_REMAP_XAPIC_MODE) {
  1360. pr_info("x2apic not enabled, IRQ remapping is in xapic mode\n");
  1361. goto skip_x2apic;
  1362. }
  1363. x2apic_enabled = 1;
  1364. if (x2apic_supported() && !x2apic_mode) {
  1365. x2apic_mode = 1;
  1366. enable_x2apic();
  1367. pr_info("Enabled x2apic\n");
  1368. }
  1369. skip_x2apic:
  1370. if (ret < 0) /* IR enabling failed */
  1371. restore_ioapic_entries();
  1372. legacy_pic->restore_mask();
  1373. local_irq_restore(flags);
  1374. }
  1375. #ifdef CONFIG_X86_64
  1376. /*
  1377. * Detect and enable local APICs on non-SMP boards.
  1378. * Original code written by Keir Fraser.
  1379. * On AMD64 we trust the BIOS - if it says no APIC it is likely
  1380. * not correctly set up (usually the APIC timer won't work etc.)
  1381. */
  1382. static int __init detect_init_APIC(void)
  1383. {
  1384. if (!cpu_has_apic) {
  1385. pr_info("No local APIC present\n");
  1386. return -1;
  1387. }
  1388. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  1389. return 0;
  1390. }
  1391. #else
  1392. static int __init apic_verify(void)
  1393. {
  1394. u32 features, h, l;
  1395. /*
  1396. * The APIC feature bit should now be enabled
  1397. * in `cpuid'
  1398. */
  1399. features = cpuid_edx(1);
  1400. if (!(features & (1 << X86_FEATURE_APIC))) {
  1401. pr_warning("Could not enable APIC!\n");
  1402. return -1;
  1403. }
  1404. set_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
  1405. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  1406. /* The BIOS may have set up the APIC at some other address */
  1407. if (boot_cpu_data.x86 >= 6) {
  1408. rdmsr(MSR_IA32_APICBASE, l, h);
  1409. if (l & MSR_IA32_APICBASE_ENABLE)
  1410. mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
  1411. }
  1412. pr_info("Found and enabled local APIC!\n");
  1413. return 0;
  1414. }
  1415. int __init apic_force_enable(unsigned long addr)
  1416. {
  1417. u32 h, l;
  1418. if (disable_apic)
  1419. return -1;
  1420. /*
  1421. * Some BIOSes disable the local APIC in the APIC_BASE
  1422. * MSR. This can only be done in software for Intel P6 or later
  1423. * and AMD K7 (Model > 1) or later.
  1424. */
  1425. if (boot_cpu_data.x86 >= 6) {
  1426. rdmsr(MSR_IA32_APICBASE, l, h);
  1427. if (!(l & MSR_IA32_APICBASE_ENABLE)) {
  1428. pr_info("Local APIC disabled by BIOS -- reenabling.\n");
  1429. l &= ~MSR_IA32_APICBASE_BASE;
  1430. l |= MSR_IA32_APICBASE_ENABLE | addr;
  1431. wrmsr(MSR_IA32_APICBASE, l, h);
  1432. enabled_via_apicbase = 1;
  1433. }
  1434. }
  1435. return apic_verify();
  1436. }
  1437. /*
  1438. * Detect and initialize APIC
  1439. */
  1440. static int __init detect_init_APIC(void)
  1441. {
  1442. /* Disabled by kernel option? */
  1443. if (disable_apic)
  1444. return -1;
  1445. switch (boot_cpu_data.x86_vendor) {
  1446. case X86_VENDOR_AMD:
  1447. if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model > 1) ||
  1448. (boot_cpu_data.x86 >= 15))
  1449. break;
  1450. goto no_apic;
  1451. case X86_VENDOR_INTEL:
  1452. if (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15 ||
  1453. (boot_cpu_data.x86 == 5 && cpu_has_apic))
  1454. break;
  1455. goto no_apic;
  1456. default:
  1457. goto no_apic;
  1458. }
  1459. if (!cpu_has_apic) {
  1460. /*
  1461. * Over-ride BIOS and try to enable the local APIC only if
  1462. * "lapic" specified.
  1463. */
  1464. if (!force_enable_local_apic) {
  1465. pr_info("Local APIC disabled by BIOS -- "
  1466. "you can enable it with \"lapic\"\n");
  1467. return -1;
  1468. }
  1469. if (apic_force_enable(APIC_DEFAULT_PHYS_BASE))
  1470. return -1;
  1471. } else {
  1472. if (apic_verify())
  1473. return -1;
  1474. }
  1475. apic_pm_activate();
  1476. return 0;
  1477. no_apic:
  1478. pr_info("No local APIC present or hardware disabled\n");
  1479. return -1;
  1480. }
  1481. #endif
  1482. /**
  1483. * init_apic_mappings - initialize APIC mappings
  1484. */
  1485. void __init init_apic_mappings(void)
  1486. {
  1487. unsigned int new_apicid;
  1488. if (x2apic_mode) {
  1489. boot_cpu_physical_apicid = read_apic_id();
  1490. return;
  1491. }
  1492. /* If no local APIC can be found return early */
  1493. if (!smp_found_config && detect_init_APIC()) {
  1494. /* lets NOP'ify apic operations */
  1495. pr_info("APIC: disable apic facility\n");
  1496. apic_disable();
  1497. } else {
  1498. apic_phys = mp_lapic_addr;
  1499. /*
  1500. * acpi lapic path already maps that address in
  1501. * acpi_register_lapic_address()
  1502. */
  1503. if (!acpi_lapic && !smp_found_config)
  1504. register_lapic_address(apic_phys);
  1505. }
  1506. /*
  1507. * Fetch the APIC ID of the BSP in case we have a
  1508. * default configuration (or the MP table is broken).
  1509. */
  1510. new_apicid = read_apic_id();
  1511. if (boot_cpu_physical_apicid != new_apicid) {
  1512. boot_cpu_physical_apicid = new_apicid;
  1513. /*
  1514. * yeah -- we lie about apic_version
  1515. * in case if apic was disabled via boot option
  1516. * but it's not a problem for SMP compiled kernel
  1517. * since smp_sanity_check is prepared for such a case
  1518. * and disable smp mode
  1519. */
  1520. apic_version[new_apicid] =
  1521. GET_APIC_VERSION(apic_read(APIC_LVR));
  1522. }
  1523. }
  1524. void __init register_lapic_address(unsigned long address)
  1525. {
  1526. mp_lapic_addr = address;
  1527. if (!x2apic_mode) {
  1528. set_fixmap_nocache(FIX_APIC_BASE, address);
  1529. apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
  1530. APIC_BASE, mp_lapic_addr);
  1531. }
  1532. if (boot_cpu_physical_apicid == -1U) {
  1533. boot_cpu_physical_apicid = read_apic_id();
  1534. apic_version[boot_cpu_physical_apicid] =
  1535. GET_APIC_VERSION(apic_read(APIC_LVR));
  1536. }
  1537. }
  1538. /*
  1539. * This initializes the IO-APIC and APIC hardware if this is
  1540. * a UP kernel.
  1541. */
  1542. int apic_version[MAX_LOCAL_APIC];
  1543. int __init APIC_init_uniprocessor(void)
  1544. {
  1545. if (disable_apic) {
  1546. pr_info("Apic disabled\n");
  1547. return -1;
  1548. }
  1549. #ifdef CONFIG_X86_64
  1550. if (!cpu_has_apic) {
  1551. disable_apic = 1;
  1552. pr_info("Apic disabled by BIOS\n");
  1553. return -1;
  1554. }
  1555. #else
  1556. if (!smp_found_config && !cpu_has_apic)
  1557. return -1;
  1558. /*
  1559. * Complain if the BIOS pretends there is one.
  1560. */
  1561. if (!cpu_has_apic &&
  1562. APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
  1563. pr_err("BIOS bug, local APIC 0x%x not detected!...\n",
  1564. boot_cpu_physical_apicid);
  1565. return -1;
  1566. }
  1567. #endif
  1568. default_setup_apic_routing();
  1569. verify_local_APIC();
  1570. connect_bsp_APIC();
  1571. #ifdef CONFIG_X86_64
  1572. apic_write(APIC_ID, SET_APIC_ID(boot_cpu_physical_apicid));
  1573. #else
  1574. /*
  1575. * Hack: In case of kdump, after a crash, kernel might be booting
  1576. * on a cpu with non-zero lapic id. But boot_cpu_physical_apicid
  1577. * might be zero if read from MP tables. Get it from LAPIC.
  1578. */
  1579. # ifdef CONFIG_CRASH_DUMP
  1580. boot_cpu_physical_apicid = read_apic_id();
  1581. # endif
  1582. #endif
  1583. physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map);
  1584. setup_local_APIC();
  1585. #ifdef CONFIG_X86_IO_APIC
  1586. /*
  1587. * Now enable IO-APICs, actually call clear_IO_APIC
  1588. * We need clear_IO_APIC before enabling error vector
  1589. */
  1590. if (!skip_ioapic_setup && nr_ioapics)
  1591. enable_IO_APIC();
  1592. #endif
  1593. bsp_end_local_APIC_setup();
  1594. #ifdef CONFIG_X86_IO_APIC
  1595. if (smp_found_config && !skip_ioapic_setup && nr_ioapics)
  1596. setup_IO_APIC();
  1597. else {
  1598. nr_ioapics = 0;
  1599. }
  1600. #endif
  1601. x86_init.timers.setup_percpu_clockev();
  1602. return 0;
  1603. }
  1604. /*
  1605. * Local APIC interrupts
  1606. */
  1607. /*
  1608. * This interrupt should _never_ happen with our APIC/SMP architecture
  1609. */
  1610. void smp_spurious_interrupt(struct pt_regs *regs)
  1611. {
  1612. u32 v;
  1613. irq_enter();
  1614. exit_idle();
  1615. /*
  1616. * Check if this really is a spurious interrupt and ACK it
  1617. * if it is a vectored one. Just in case...
  1618. * Spurious interrupts should not be ACKed.
  1619. */
  1620. v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1));
  1621. if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f)))
  1622. ack_APIC_irq();
  1623. inc_irq_stat(irq_spurious_count);
  1624. /* see sw-dev-man vol 3, chapter 7.4.13.5 */
  1625. pr_info("spurious APIC interrupt on CPU#%d, "
  1626. "should never happen.\n", smp_processor_id());
  1627. irq_exit();
  1628. }
  1629. /*
  1630. * This interrupt should never happen with our APIC/SMP architecture
  1631. */
  1632. void smp_error_interrupt(struct pt_regs *regs)
  1633. {
  1634. u32 v0, v1;
  1635. u32 i = 0;
  1636. static const char * const error_interrupt_reason[] = {
  1637. "Send CS error", /* APIC Error Bit 0 */
  1638. "Receive CS error", /* APIC Error Bit 1 */
  1639. "Send accept error", /* APIC Error Bit 2 */
  1640. "Receive accept error", /* APIC Error Bit 3 */
  1641. "Redirectable IPI", /* APIC Error Bit 4 */
  1642. "Send illegal vector", /* APIC Error Bit 5 */
  1643. "Received illegal vector", /* APIC Error Bit 6 */
  1644. "Illegal register address", /* APIC Error Bit 7 */
  1645. };
  1646. irq_enter();
  1647. exit_idle();
  1648. /* First tickle the hardware, only then report what went on. -- REW */
  1649. v0 = apic_read(APIC_ESR);
  1650. apic_write(APIC_ESR, 0);
  1651. v1 = apic_read(APIC_ESR);
  1652. ack_APIC_irq();
  1653. atomic_inc(&irq_err_count);
  1654. apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
  1655. smp_processor_id(), v0 , v1);
  1656. v1 = v1 & 0xff;
  1657. while (v1) {
  1658. if (v1 & 0x1)
  1659. apic_printk(APIC_DEBUG, KERN_CONT " : %s", error_interrupt_reason[i]);
  1660. i++;
  1661. v1 >>= 1;
  1662. }
  1663. apic_printk(APIC_DEBUG, KERN_CONT "\n");
  1664. irq_exit();
  1665. }
  1666. /**
  1667. * connect_bsp_APIC - attach the APIC to the interrupt system
  1668. */
  1669. void __init connect_bsp_APIC(void)
  1670. {
  1671. #ifdef CONFIG_X86_32
  1672. if (pic_mode) {
  1673. /*
  1674. * Do not trust the local APIC being empty at bootup.
  1675. */
  1676. clear_local_APIC();
  1677. /*
  1678. * PIC mode, enable APIC mode in the IMCR, i.e. connect BSP's
  1679. * local APIC to INT and NMI lines.
  1680. */
  1681. apic_printk(APIC_VERBOSE, "leaving PIC mode, "
  1682. "enabling APIC mode.\n");
  1683. imcr_pic_to_apic();
  1684. }
  1685. #endif
  1686. if (apic->enable_apic_mode)
  1687. apic->enable_apic_mode();
  1688. }
  1689. /**
  1690. * disconnect_bsp_APIC - detach the APIC from the interrupt system
  1691. * @virt_wire_setup: indicates, whether virtual wire mode is selected
  1692. *
  1693. * Virtual wire mode is necessary to deliver legacy interrupts even when the
  1694. * APIC is disabled.
  1695. */
  1696. void disconnect_bsp_APIC(int virt_wire_setup)
  1697. {
  1698. unsigned int value;
  1699. #ifdef CONFIG_X86_32
  1700. if (pic_mode) {
  1701. /*
  1702. * Put the board back into PIC mode (has an effect only on
  1703. * certain older boards). Note that APIC interrupts, including
  1704. * IPIs, won't work beyond this point! The only exception are
  1705. * INIT IPIs.
  1706. */
  1707. apic_printk(APIC_VERBOSE, "disabling APIC mode, "
  1708. "entering PIC mode.\n");
  1709. imcr_apic_to_pic();
  1710. return;
  1711. }
  1712. #endif
  1713. /* Go back to Virtual Wire compatibility mode */
  1714. /* For the spurious interrupt use vector F, and enable it */
  1715. value = apic_read(APIC_SPIV);
  1716. value &= ~APIC_VECTOR_MASK;
  1717. value |= APIC_SPIV_APIC_ENABLED;
  1718. value |= 0xf;
  1719. apic_write(APIC_SPIV, value);
  1720. if (!virt_wire_setup) {
  1721. /*
  1722. * For LVT0 make it edge triggered, active high,
  1723. * external and enabled
  1724. */
  1725. value = apic_read(APIC_LVT0);
  1726. value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
  1727. APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
  1728. APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
  1729. value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
  1730. value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT);
  1731. apic_write(APIC_LVT0, value);
  1732. } else {
  1733. /* Disable LVT0 */
  1734. apic_write(APIC_LVT0, APIC_LVT_MASKED);
  1735. }
  1736. /*
  1737. * For LVT1 make it edge triggered, active high,
  1738. * nmi and enabled
  1739. */
  1740. value = apic_read(APIC_LVT1);
  1741. value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
  1742. APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
  1743. APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
  1744. value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
  1745. value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI);
  1746. apic_write(APIC_LVT1, value);
  1747. }
  1748. void __cpuinit generic_processor_info(int apicid, int version)
  1749. {
  1750. int cpu, max = nr_cpu_ids;
  1751. bool boot_cpu_detected = physid_isset(boot_cpu_physical_apicid,
  1752. phys_cpu_present_map);
  1753. /*
  1754. * If boot cpu has not been detected yet, then only allow upto
  1755. * nr_cpu_ids - 1 processors and keep one slot free for boot cpu
  1756. */
  1757. if (!boot_cpu_detected && num_processors >= nr_cpu_ids - 1 &&
  1758. apicid != boot_cpu_physical_apicid) {
  1759. int thiscpu = max + disabled_cpus - 1;
  1760. pr_warning(
  1761. "ACPI: NR_CPUS/possible_cpus limit of %i almost"
  1762. " reached. Keeping one slot for boot cpu."
  1763. " Processor %d/0x%x ignored.\n", max, thiscpu, apicid);
  1764. disabled_cpus++;
  1765. return;
  1766. }
  1767. if (num_processors >= nr_cpu_ids) {
  1768. int thiscpu = max + disabled_cpus;
  1769. pr_warning(
  1770. "ACPI: NR_CPUS/possible_cpus limit of %i reached."
  1771. " Processor %d/0x%x ignored.\n", max, thiscpu, apicid);
  1772. disabled_cpus++;
  1773. return;
  1774. }
  1775. num_processors++;
  1776. if (apicid == boot_cpu_physical_apicid) {
  1777. /*
  1778. * x86_bios_cpu_apicid is required to have processors listed
  1779. * in same order as logical cpu numbers. Hence the first
  1780. * entry is BSP, and so on.
  1781. * boot_cpu_init() already hold bit 0 in cpu_present_mask
  1782. * for BSP.
  1783. */
  1784. cpu = 0;
  1785. } else
  1786. cpu = cpumask_next_zero(-1, cpu_present_mask);
  1787. /*
  1788. * Validate version
  1789. */
  1790. if (version == 0x0) {
  1791. pr_warning("BIOS bug: APIC version is 0 for CPU %d/0x%x, fixing up to 0x10\n",
  1792. cpu, apicid);
  1793. version = 0x10;
  1794. }
  1795. apic_version[apicid] = version;
  1796. if (version != apic_version[boot_cpu_physical_apicid]) {
  1797. pr_warning("BIOS bug: APIC version mismatch, boot CPU: %x, CPU %d: version %x\n",
  1798. apic_version[boot_cpu_physical_apicid], cpu, version);
  1799. }
  1800. physid_set(apicid, phys_cpu_present_map);
  1801. if (apicid > max_physical_apicid)
  1802. max_physical_apicid = apicid;
  1803. #if defined(CONFIG_SMP) || defined(CONFIG_X86_64)
  1804. early_per_cpu(x86_cpu_to_apicid, cpu) = apicid;
  1805. early_per_cpu(x86_bios_cpu_apicid, cpu) = apicid;
  1806. #endif
  1807. #ifdef CONFIG_X86_32
  1808. early_per_cpu(x86_cpu_to_logical_apicid, cpu) =
  1809. apic->x86_32_early_logical_apicid(cpu);
  1810. #endif
  1811. set_cpu_possible(cpu, true);
  1812. set_cpu_present(cpu, true);
  1813. }
  1814. int hard_smp_processor_id(void)
  1815. {
  1816. return read_apic_id();
  1817. }
  1818. void default_init_apic_ldr(void)
  1819. {
  1820. unsigned long val;
  1821. apic_write(APIC_DFR, APIC_DFR_VALUE);
  1822. val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
  1823. val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
  1824. apic_write(APIC_LDR, val);
  1825. }
  1826. int default_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
  1827. const struct cpumask *andmask,
  1828. unsigned int *apicid)
  1829. {
  1830. unsigned int cpu;
  1831. for_each_cpu_and(cpu, cpumask, andmask) {
  1832. if (cpumask_test_cpu(cpu, cpu_online_mask))
  1833. break;
  1834. }
  1835. if (likely(cpu < nr_cpu_ids)) {
  1836. *apicid = per_cpu(x86_cpu_to_apicid, cpu);
  1837. return 0;
  1838. }
  1839. return -EINVAL;
  1840. }
  1841. /*
  1842. * Override the generic EOI implementation with an optimized version.
  1843. * Only called during early boot when only one CPU is active and with
  1844. * interrupts disabled, so we know this does not race with actual APIC driver
  1845. * use.
  1846. */
  1847. void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
  1848. {
  1849. struct apic **drv;
  1850. for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
  1851. /* Should happen once for each apic */
  1852. WARN_ON((*drv)->eoi_write == eoi_write);
  1853. (*drv)->eoi_write = eoi_write;
  1854. }
  1855. }
  1856. /*
  1857. * Power management
  1858. */
  1859. #ifdef CONFIG_PM
  1860. static struct {
  1861. /*
  1862. * 'active' is true if the local APIC was enabled by us and
  1863. * not the BIOS; this signifies that we are also responsible
  1864. * for disabling it before entering apm/acpi suspend
  1865. */
  1866. int active;
  1867. /* r/w apic fields */
  1868. unsigned int apic_id;
  1869. unsigned int apic_taskpri;
  1870. unsigned int apic_ldr;
  1871. unsigned int apic_dfr;
  1872. unsigned int apic_spiv;
  1873. unsigned int apic_lvtt;
  1874. unsigned int apic_lvtpc;
  1875. unsigned int apic_lvt0;
  1876. unsigned int apic_lvt1;
  1877. unsigned int apic_lvterr;
  1878. unsigned int apic_tmict;
  1879. unsigned int apic_tdcr;
  1880. unsigned int apic_thmr;
  1881. } apic_pm_state;
  1882. static int lapic_suspend(void)
  1883. {
  1884. unsigned long flags;
  1885. int maxlvt;
  1886. if (!apic_pm_state.active)
  1887. return 0;
  1888. maxlvt = lapic_get_maxlvt();
  1889. apic_pm_state.apic_id = apic_read(APIC_ID);
  1890. apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI);
  1891. apic_pm_state.apic_ldr = apic_read(APIC_LDR);
  1892. apic_pm_state.apic_dfr = apic_read(APIC_DFR);
  1893. apic_pm_state.apic_spiv = apic_read(APIC_SPIV);
  1894. apic_pm_state.apic_lvtt = apic_read(APIC_LVTT);
  1895. if (maxlvt >= 4)
  1896. apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC);
  1897. apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0);
  1898. apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1);
  1899. apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR);
  1900. apic_pm_state.apic_tmict = apic_read(APIC_TMICT);
  1901. apic_pm_state.apic_tdcr = apic_read(APIC_TDCR);
  1902. #ifdef CONFIG_X86_THERMAL_VECTOR
  1903. if (maxlvt >= 5)
  1904. apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR);
  1905. #endif
  1906. local_irq_save(flags);
  1907. disable_local_APIC();
  1908. if (irq_remapping_enabled)
  1909. irq_remapping_disable();
  1910. local_irq_restore(flags);
  1911. return 0;
  1912. }
  1913. static void lapic_resume(void)
  1914. {
  1915. unsigned int l, h;
  1916. unsigned long flags;
  1917. int maxlvt;
  1918. if (!apic_pm_state.active)
  1919. return;
  1920. local_irq_save(flags);
  1921. if (irq_remapping_enabled) {
  1922. /*
  1923. * IO-APIC and PIC have their own resume routines.
  1924. * We just mask them here to make sure the interrupt
  1925. * subsystem is completely quiet while we enable x2apic
  1926. * and interrupt-remapping.
  1927. */
  1928. mask_ioapic_entries();
  1929. legacy_pic->mask_all();
  1930. }
  1931. if (x2apic_mode)
  1932. enable_x2apic();
  1933. else {
  1934. /*
  1935. * Make sure the APICBASE points to the right address
  1936. *
  1937. * FIXME! This will be wrong if we ever support suspend on
  1938. * SMP! We'll need to do this as part of the CPU restore!
  1939. */
  1940. if (boot_cpu_data.x86 >= 6) {
  1941. rdmsr(MSR_IA32_APICBASE, l, h);
  1942. l &= ~MSR_IA32_APICBASE_BASE;
  1943. l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
  1944. wrmsr(MSR_IA32_APICBASE, l, h);
  1945. }
  1946. }
  1947. maxlvt = lapic_get_maxlvt();
  1948. apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED);
  1949. apic_write(APIC_ID, apic_pm_state.apic_id);
  1950. apic_write(APIC_DFR, apic_pm_state.apic_dfr);
  1951. apic_write(APIC_LDR, apic_pm_state.apic_ldr);
  1952. apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri);
  1953. apic_write(APIC_SPIV, apic_pm_state.apic_spiv);
  1954. apic_write(APIC_LVT0, apic_pm_state.apic_lvt0);
  1955. apic_write(APIC_LVT1, apic_pm_state.apic_lvt1);
  1956. #if defined(CONFIG_X86_MCE_P4THERMAL) || defined(CONFIG_X86_MCE_INTEL)
  1957. if (maxlvt >= 5)
  1958. apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr);
  1959. #endif
  1960. if (maxlvt >= 4)
  1961. apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc);
  1962. apic_write(APIC_LVTT, apic_pm_state.apic_lvtt);
  1963. apic_write(APIC_TDCR, apic_pm_state.apic_tdcr);
  1964. apic_write(APIC_TMICT, apic_pm_state.apic_tmict);
  1965. apic_write(APIC_ESR, 0);
  1966. apic_read(APIC_ESR);
  1967. apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr);
  1968. apic_write(APIC_ESR, 0);
  1969. apic_read(APIC_ESR);
  1970. if (irq_remapping_enabled)
  1971. irq_remapping_reenable(x2apic_mode);
  1972. local_irq_restore(flags);
  1973. }
  1974. /*
  1975. * This device has no shutdown method - fully functioning local APICs
  1976. * are needed on every CPU up until machine_halt/restart/poweroff.
  1977. */
  1978. static struct syscore_ops lapic_syscore_ops = {
  1979. .resume = lapic_resume,
  1980. .suspend = lapic_suspend,
  1981. };
  1982. static void __cpuinit apic_pm_activate(void)
  1983. {
  1984. apic_pm_state.active = 1;
  1985. }
  1986. static int __init init_lapic_sysfs(void)
  1987. {
  1988. /* XXX: remove suspend/resume procs if !apic_pm_state.active? */
  1989. if (cpu_has_apic)
  1990. register_syscore_ops(&lapic_syscore_ops);
  1991. return 0;
  1992. }
  1993. /* local apic needs to resume before other devices access its registers. */
  1994. core_initcall(init_lapic_sysfs);
  1995. #else /* CONFIG_PM */
  1996. static void apic_pm_activate(void) { }
  1997. #endif /* CONFIG_PM */
  1998. #ifdef CONFIG_X86_64
  1999. static int __cpuinit apic_cluster_num(void)
  2000. {
  2001. int i, clusters, zeros;
  2002. unsigned id;
  2003. u16 *bios_cpu_apicid;
  2004. DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
  2005. bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid);
  2006. bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
  2007. for (i = 0; i < nr_cpu_ids; i++) {
  2008. /* are we being called early in kernel startup? */
  2009. if (bios_cpu_apicid) {
  2010. id = bios_cpu_apicid[i];
  2011. } else if (i < nr_cpu_ids) {
  2012. if (cpu_present(i))
  2013. id = per_cpu(x86_bios_cpu_apicid, i);
  2014. else
  2015. continue;
  2016. } else
  2017. break;
  2018. if (id != BAD_APICID)
  2019. __set_bit(APIC_CLUSTERID(id), clustermap);
  2020. }
  2021. /* Problem: Partially populated chassis may not have CPUs in some of
  2022. * the APIC clusters they have been allocated. Only present CPUs have
  2023. * x86_bios_cpu_apicid entries, thus causing zeroes in the bitmap.
  2024. * Since clusters are allocated sequentially, count zeros only if
  2025. * they are bounded by ones.
  2026. */
  2027. clusters = 0;
  2028. zeros = 0;
  2029. for (i = 0; i < NUM_APIC_CLUSTERS; i++) {
  2030. if (test_bit(i, clustermap)) {
  2031. clusters += 1 + zeros;
  2032. zeros = 0;
  2033. } else
  2034. ++zeros;
  2035. }
  2036. return clusters;
  2037. }
  2038. static int __cpuinitdata multi_checked;
  2039. static int __cpuinitdata multi;
  2040. static int __cpuinit set_multi(const struct dmi_system_id *d)
  2041. {
  2042. if (multi)
  2043. return 0;
  2044. pr_info("APIC: %s detected, Multi Chassis\n", d->ident);
  2045. multi = 1;
  2046. return 0;
  2047. }
  2048. static const __cpuinitconst struct dmi_system_id multi_dmi_table[] = {
  2049. {
  2050. .callback = set_multi,
  2051. .ident = "IBM System Summit2",
  2052. .matches = {
  2053. DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
  2054. DMI_MATCH(DMI_PRODUCT_NAME, "Summit2"),
  2055. },
  2056. },
  2057. {}
  2058. };
  2059. static void __cpuinit dmi_check_multi(void)
  2060. {
  2061. if (multi_checked)
  2062. return;
  2063. dmi_check_system(multi_dmi_table);
  2064. multi_checked = 1;
  2065. }
  2066. /*
  2067. * apic_is_clustered_box() -- Check if we can expect good TSC
  2068. *
  2069. * Thus far, the major user of this is IBM's Summit2 series:
  2070. * Clustered boxes may have unsynced TSC problems if they are
  2071. * multi-chassis.
  2072. * Use DMI to check them
  2073. */
  2074. __cpuinit int apic_is_clustered_box(void)
  2075. {
  2076. dmi_check_multi();
  2077. if (multi)
  2078. return 1;
  2079. if (!is_vsmp_box())
  2080. return 0;
  2081. /*
  2082. * ScaleMP vSMPowered boxes have one cluster per board and TSCs are
  2083. * not guaranteed to be synced between boards
  2084. */
  2085. if (apic_cluster_num() > 1)
  2086. return 1;
  2087. return 0;
  2088. }
  2089. #endif
  2090. /*
  2091. * APIC command line parameters
  2092. */
  2093. static int __init setup_disableapic(char *arg)
  2094. {
  2095. disable_apic = 1;
  2096. setup_clear_cpu_cap(X86_FEATURE_APIC);
  2097. return 0;
  2098. }
  2099. early_param("disableapic", setup_disableapic);
  2100. /* same as disableapic, for compatibility */
  2101. static int __init setup_nolapic(char *arg)
  2102. {
  2103. return setup_disableapic(arg);
  2104. }
  2105. early_param("nolapic", setup_nolapic);
  2106. static int __init parse_lapic_timer_c2_ok(char *arg)
  2107. {
  2108. local_apic_timer_c2_ok = 1;
  2109. return 0;
  2110. }
  2111. early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok);
  2112. static int __init parse_disable_apic_timer(char *arg)
  2113. {
  2114. disable_apic_timer = 1;
  2115. return 0;
  2116. }
  2117. early_param("noapictimer", parse_disable_apic_timer);
  2118. static int __init parse_nolapic_timer(char *arg)
  2119. {
  2120. disable_apic_timer = 1;
  2121. return 0;
  2122. }
  2123. early_param("nolapic_timer", parse_nolapic_timer);
  2124. static int __init apic_set_verbosity(char *arg)
  2125. {
  2126. if (!arg) {
  2127. #ifdef CONFIG_X86_64
  2128. skip_ioapic_setup = 0;
  2129. return 0;
  2130. #endif
  2131. return -EINVAL;
  2132. }
  2133. if (strcmp("debug", arg) == 0)
  2134. apic_verbosity = APIC_DEBUG;
  2135. else if (strcmp("verbose", arg) == 0)
  2136. apic_verbosity = APIC_VERBOSE;
  2137. else {
  2138. pr_warning("APIC Verbosity level %s not recognised"
  2139. " use apic=verbose or apic=debug\n", arg);
  2140. return -EINVAL;
  2141. }
  2142. return 0;
  2143. }
  2144. early_param("apic", apic_set_verbosity);
  2145. static int __init lapic_insert_resource(void)
  2146. {
  2147. if (!apic_phys)
  2148. return -1;
  2149. /* Put local APIC into the resource map. */
  2150. lapic_resource.start = apic_phys;
  2151. lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1;
  2152. insert_resource(&iomem_resource, &lapic_resource);
  2153. return 0;
  2154. }
  2155. /*
  2156. * need call insert after e820_reserve_resources()
  2157. * that is using request_resource
  2158. */
  2159. late_initcall(lapic_insert_resource);