apic_64.c 45 KB

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