apic.c 61 KB

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