apic_64.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  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 <asm/atomic.h>
  29. #include <asm/smp.h>
  30. #include <asm/mtrr.h>
  31. #include <asm/mpspec.h>
  32. #include <asm/hpet.h>
  33. #include <asm/pgalloc.h>
  34. #include <asm/nmi.h>
  35. #include <asm/idle.h>
  36. #include <asm/proto.h>
  37. #include <asm/timex.h>
  38. #include <asm/apic.h>
  39. #include <mach_ipi.h>
  40. #include <mach_apic.h>
  41. int disable_apic_timer __cpuinitdata;
  42. static int apic_calibrate_pmtmr __initdata;
  43. int disable_apic;
  44. /* Local APIC timer works in C2 */
  45. int local_apic_timer_c2_ok;
  46. EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok);
  47. /*
  48. * Debug level, exported for io_apic.c
  49. */
  50. int apic_verbosity;
  51. static struct resource lapic_resource = {
  52. .name = "Local APIC",
  53. .flags = IORESOURCE_MEM | IORESOURCE_BUSY,
  54. };
  55. static unsigned int calibration_result;
  56. static int lapic_next_event(unsigned long delta,
  57. struct clock_event_device *evt);
  58. static void lapic_timer_setup(enum clock_event_mode mode,
  59. struct clock_event_device *evt);
  60. static void lapic_timer_broadcast(cpumask_t mask);
  61. static void apic_pm_activate(void);
  62. static struct clock_event_device lapic_clockevent = {
  63. .name = "lapic",
  64. .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT
  65. | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY,
  66. .shift = 32,
  67. .set_mode = lapic_timer_setup,
  68. .set_next_event = lapic_next_event,
  69. .broadcast = lapic_timer_broadcast,
  70. .rating = 100,
  71. .irq = -1,
  72. };
  73. static DEFINE_PER_CPU(struct clock_event_device, lapic_events);
  74. static unsigned long apic_phys;
  75. /*
  76. * Get the LAPIC version
  77. */
  78. static inline int lapic_get_version(void)
  79. {
  80. return GET_APIC_VERSION(apic_read(APIC_LVR));
  81. }
  82. /*
  83. * Check, if the APIC is integrated or a seperate chip
  84. */
  85. static inline int lapic_is_integrated(void)
  86. {
  87. return 1;
  88. }
  89. /*
  90. * Check, whether this is a modern or a first generation APIC
  91. */
  92. static int modern_apic(void)
  93. {
  94. /* AMD systems use old APIC versions, so check the CPU */
  95. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
  96. boot_cpu_data.x86 >= 0xf)
  97. return 1;
  98. return lapic_get_version() >= 0x14;
  99. }
  100. void apic_wait_icr_idle(void)
  101. {
  102. while (apic_read(APIC_ICR) & APIC_ICR_BUSY)
  103. cpu_relax();
  104. }
  105. u32 safe_apic_wait_icr_idle(void)
  106. {
  107. u32 send_status;
  108. int timeout;
  109. timeout = 0;
  110. do {
  111. send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
  112. if (!send_status)
  113. break;
  114. udelay(100);
  115. } while (timeout++ < 1000);
  116. return send_status;
  117. }
  118. /**
  119. * enable_NMI_through_LVT0 - enable NMI through local vector table 0
  120. */
  121. void __cpuinit enable_NMI_through_LVT0(void)
  122. {
  123. unsigned int v;
  124. /* unmask and set to NMI */
  125. v = APIC_DM_NMI;
  126. apic_write(APIC_LVT0, v);
  127. }
  128. /**
  129. * lapic_get_maxlvt - get the maximum number of local vector table entries
  130. */
  131. int lapic_get_maxlvt(void)
  132. {
  133. unsigned int v, maxlvt;
  134. v = apic_read(APIC_LVR);
  135. maxlvt = GET_APIC_MAXLVT(v);
  136. return maxlvt;
  137. }
  138. /*
  139. * This function sets up the local APIC timer, with a timeout of
  140. * 'clocks' APIC bus clock. During calibration we actually call
  141. * this function twice on the boot CPU, once with a bogus timeout
  142. * value, second time for real. The other (noncalibrating) CPUs
  143. * call this function only once, with the real, calibrated value.
  144. *
  145. * We do reads before writes even if unnecessary, to get around the
  146. * P5 APIC double write bug.
  147. */
  148. static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
  149. {
  150. unsigned int lvtt_value, tmp_value;
  151. lvtt_value = LOCAL_TIMER_VECTOR;
  152. if (!oneshot)
  153. lvtt_value |= APIC_LVT_TIMER_PERIODIC;
  154. if (!irqen)
  155. lvtt_value |= APIC_LVT_MASKED;
  156. apic_write(APIC_LVTT, lvtt_value);
  157. /*
  158. * Divide PICLK by 16
  159. */
  160. tmp_value = apic_read(APIC_TDCR);
  161. apic_write(APIC_TDCR, (tmp_value
  162. & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE))
  163. | APIC_TDR_DIV_16);
  164. if (!oneshot)
  165. apic_write(APIC_TMICT, clocks);
  166. }
  167. /*
  168. * Setup extended LVT, AMD specific (K8, family 10h)
  169. *
  170. * Vector mappings are hard coded. On K8 only offset 0 (APIC500) and
  171. * MCE interrupts are supported. Thus MCE offset must be set to 0.
  172. */
  173. #define APIC_EILVT_LVTOFF_MCE 0
  174. #define APIC_EILVT_LVTOFF_IBS 1
  175. static void setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask)
  176. {
  177. unsigned long reg = (lvt_off << 4) + APIC_EILVT0;
  178. unsigned int v = (mask << 16) | (msg_type << 8) | vector;
  179. apic_write(reg, v);
  180. }
  181. u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask)
  182. {
  183. setup_APIC_eilvt(APIC_EILVT_LVTOFF_MCE, vector, msg_type, mask);
  184. return APIC_EILVT_LVTOFF_MCE;
  185. }
  186. u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask)
  187. {
  188. setup_APIC_eilvt(APIC_EILVT_LVTOFF_IBS, vector, msg_type, mask);
  189. return APIC_EILVT_LVTOFF_IBS;
  190. }
  191. /*
  192. * Program the next event, relative to now
  193. */
  194. static int lapic_next_event(unsigned long delta,
  195. struct clock_event_device *evt)
  196. {
  197. apic_write(APIC_TMICT, delta);
  198. return 0;
  199. }
  200. /*
  201. * Setup the lapic timer in periodic or oneshot mode
  202. */
  203. static void lapic_timer_setup(enum clock_event_mode mode,
  204. struct clock_event_device *evt)
  205. {
  206. unsigned long flags;
  207. unsigned int v;
  208. /* Lapic used as dummy for broadcast ? */
  209. if (evt->features & CLOCK_EVT_FEAT_DUMMY)
  210. return;
  211. local_irq_save(flags);
  212. switch (mode) {
  213. case CLOCK_EVT_MODE_PERIODIC:
  214. case CLOCK_EVT_MODE_ONESHOT:
  215. __setup_APIC_LVTT(calibration_result,
  216. mode != CLOCK_EVT_MODE_PERIODIC, 1);
  217. break;
  218. case CLOCK_EVT_MODE_UNUSED:
  219. case CLOCK_EVT_MODE_SHUTDOWN:
  220. v = apic_read(APIC_LVTT);
  221. v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
  222. apic_write(APIC_LVTT, v);
  223. break;
  224. case CLOCK_EVT_MODE_RESUME:
  225. /* Nothing to do here */
  226. break;
  227. }
  228. local_irq_restore(flags);
  229. }
  230. /*
  231. * Local APIC timer broadcast function
  232. */
  233. static void lapic_timer_broadcast(cpumask_t mask)
  234. {
  235. #ifdef CONFIG_SMP
  236. send_IPI_mask(mask, LOCAL_TIMER_VECTOR);
  237. #endif
  238. }
  239. /*
  240. * Setup the local APIC timer for this CPU. Copy the initilized values
  241. * of the boot CPU and register the clock event in the framework.
  242. */
  243. static void setup_APIC_timer(void)
  244. {
  245. struct clock_event_device *levt = &__get_cpu_var(lapic_events);
  246. memcpy(levt, &lapic_clockevent, sizeof(*levt));
  247. levt->cpumask = cpumask_of_cpu(smp_processor_id());
  248. clockevents_register_device(levt);
  249. }
  250. /*
  251. * In this function we calibrate APIC bus clocks to the external
  252. * timer. Unfortunately we cannot use jiffies and the timer irq
  253. * to calibrate, since some later bootup code depends on getting
  254. * the first irq? Ugh.
  255. *
  256. * We want to do the calibration only once since we
  257. * want to have local timer irqs syncron. CPUs connected
  258. * by the same APIC bus have the very same bus frequency.
  259. * And we want to have irqs off anyways, no accidental
  260. * APIC irq that way.
  261. */
  262. #define TICK_COUNT 100000000
  263. static void __init calibrate_APIC_clock(void)
  264. {
  265. unsigned apic, apic_start;
  266. unsigned long tsc, tsc_start;
  267. int result;
  268. local_irq_disable();
  269. /*
  270. * Put whatever arbitrary (but long enough) timeout
  271. * value into the APIC clock, we just want to get the
  272. * counter running for calibration.
  273. *
  274. * No interrupt enable !
  275. */
  276. __setup_APIC_LVTT(250000000, 0, 0);
  277. apic_start = apic_read(APIC_TMCCT);
  278. #ifdef CONFIG_X86_PM_TIMER
  279. if (apic_calibrate_pmtmr && pmtmr_ioport) {
  280. pmtimer_wait(5000); /* 5ms wait */
  281. apic = apic_read(APIC_TMCCT);
  282. result = (apic_start - apic) * 1000L / 5;
  283. } else
  284. #endif
  285. {
  286. rdtscll(tsc_start);
  287. do {
  288. apic = apic_read(APIC_TMCCT);
  289. rdtscll(tsc);
  290. } while ((tsc - tsc_start) < TICK_COUNT &&
  291. (apic_start - apic) < TICK_COUNT);
  292. result = (apic_start - apic) * 1000L * tsc_khz /
  293. (tsc - tsc_start);
  294. }
  295. local_irq_enable();
  296. printk(KERN_DEBUG "APIC timer calibration result %d\n", result);
  297. printk(KERN_INFO "Detected %d.%03d MHz APIC timer.\n",
  298. result / 1000 / 1000, result / 1000 % 1000);
  299. /* Calculate the scaled math multiplication factor */
  300. lapic_clockevent.mult = div_sc(result, NSEC_PER_SEC, 32);
  301. lapic_clockevent.max_delta_ns =
  302. clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
  303. lapic_clockevent.min_delta_ns =
  304. clockevent_delta2ns(0xF, &lapic_clockevent);
  305. calibration_result = result / HZ;
  306. }
  307. /*
  308. * Setup the boot APIC
  309. *
  310. * Calibrate and verify the result.
  311. */
  312. void __init setup_boot_APIC_clock(void)
  313. {
  314. /*
  315. * The local apic timer can be disabled via the kernel commandline.
  316. * Register the lapic timer as a dummy clock event source on SMP
  317. * systems, so the broadcast mechanism is used. On UP systems simply
  318. * ignore it.
  319. */
  320. if (disable_apic_timer) {
  321. printk(KERN_INFO "Disabling APIC timer\n");
  322. /* No broadcast on UP ! */
  323. if (num_possible_cpus() > 1) {
  324. lapic_clockevent.mult = 1;
  325. setup_APIC_timer();
  326. }
  327. return;
  328. }
  329. printk(KERN_INFO "Using local APIC timer interrupts.\n");
  330. calibrate_APIC_clock();
  331. /*
  332. * Do a sanity check on the APIC calibration result
  333. */
  334. if (calibration_result < (1000000 / HZ)) {
  335. printk(KERN_WARNING
  336. "APIC frequency too slow, disabling apic timer\n");
  337. /* No broadcast on UP ! */
  338. if (num_possible_cpus() > 1)
  339. setup_APIC_timer();
  340. return;
  341. }
  342. /*
  343. * If nmi_watchdog is set to IO_APIC, we need the
  344. * PIT/HPET going. Otherwise register lapic as a dummy
  345. * device.
  346. */
  347. if (nmi_watchdog != NMI_IO_APIC)
  348. lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
  349. else
  350. printk(KERN_WARNING "APIC timer registered as dummy,"
  351. " due to nmi_watchdog=1!\n");
  352. setup_APIC_timer();
  353. }
  354. /*
  355. * AMD C1E enabled CPUs have a real nasty problem: Some BIOSes set the
  356. * C1E flag only in the secondary CPU, so when we detect the wreckage
  357. * we already have enabled the boot CPU local apic timer. Check, if
  358. * disable_apic_timer is set and the DUMMY flag is cleared. If yes,
  359. * set the DUMMY flag again and force the broadcast mode in the
  360. * clockevents layer.
  361. */
  362. void __cpuinit check_boot_apic_timer_broadcast(void)
  363. {
  364. if (!disable_apic_timer ||
  365. (lapic_clockevent.features & CLOCK_EVT_FEAT_DUMMY))
  366. return;
  367. printk(KERN_INFO "AMD C1E detected late. Force timer broadcast.\n");
  368. lapic_clockevent.features |= CLOCK_EVT_FEAT_DUMMY;
  369. local_irq_enable();
  370. clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
  371. &boot_cpu_physical_apicid);
  372. local_irq_disable();
  373. }
  374. void __cpuinit setup_secondary_APIC_clock(void)
  375. {
  376. check_boot_apic_timer_broadcast();
  377. setup_APIC_timer();
  378. }
  379. /*
  380. * The guts of the apic timer interrupt
  381. */
  382. static void local_apic_timer_interrupt(void)
  383. {
  384. int cpu = smp_processor_id();
  385. struct clock_event_device *evt = &per_cpu(lapic_events, cpu);
  386. /*
  387. * Normally we should not be here till LAPIC has been initialized but
  388. * in some cases like kdump, its possible that there is a pending LAPIC
  389. * timer interrupt from previous kernel's context and is delivered in
  390. * new kernel the moment interrupts are enabled.
  391. *
  392. * Interrupts are enabled early and LAPIC is setup much later, hence
  393. * its possible that when we get here evt->event_handler is NULL.
  394. * Check for event_handler being NULL and discard the interrupt as
  395. * spurious.
  396. */
  397. if (!evt->event_handler) {
  398. printk(KERN_WARNING
  399. "Spurious LAPIC timer interrupt on cpu %d\n", cpu);
  400. /* Switch it off */
  401. lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt);
  402. return;
  403. }
  404. /*
  405. * the NMI deadlock-detector uses this.
  406. */
  407. add_pda(apic_timer_irqs, 1);
  408. evt->event_handler(evt);
  409. }
  410. /*
  411. * Local APIC timer interrupt. This is the most natural way for doing
  412. * local interrupts, but local timer interrupts can be emulated by
  413. * broadcast interrupts too. [in case the hw doesn't support APIC timers]
  414. *
  415. * [ if a single-CPU system runs an SMP kernel then we call the local
  416. * interrupt as well. Thus we cannot inline the local irq ... ]
  417. */
  418. void smp_apic_timer_interrupt(struct pt_regs *regs)
  419. {
  420. struct pt_regs *old_regs = set_irq_regs(regs);
  421. /*
  422. * NOTE! We'd better ACK the irq immediately,
  423. * because timer handling can be slow.
  424. */
  425. ack_APIC_irq();
  426. /*
  427. * update_process_times() expects us to have done irq_enter().
  428. * Besides, if we don't timer interrupts ignore the global
  429. * interrupt lock, which is the WrongThing (tm) to do.
  430. */
  431. exit_idle();
  432. irq_enter();
  433. local_apic_timer_interrupt();
  434. irq_exit();
  435. set_irq_regs(old_regs);
  436. }
  437. int setup_profiling_timer(unsigned int multiplier)
  438. {
  439. return -EINVAL;
  440. }
  441. /*
  442. * Local APIC start and shutdown
  443. */
  444. /**
  445. * clear_local_APIC - shutdown the local APIC
  446. *
  447. * This is called, when a CPU is disabled and before rebooting, so the state of
  448. * the local APIC has no dangling leftovers. Also used to cleanout any BIOS
  449. * leftovers during boot.
  450. */
  451. void clear_local_APIC(void)
  452. {
  453. int maxlvt = lapic_get_maxlvt();
  454. u32 v;
  455. /* APIC hasn't been mapped yet */
  456. if (!apic_phys)
  457. return;
  458. maxlvt = lapic_get_maxlvt();
  459. /*
  460. * Masking an LVT entry can trigger a local APIC error
  461. * if the vector is zero. Mask LVTERR first to prevent this.
  462. */
  463. if (maxlvt >= 3) {
  464. v = ERROR_APIC_VECTOR; /* any non-zero vector will do */
  465. apic_write(APIC_LVTERR, v | APIC_LVT_MASKED);
  466. }
  467. /*
  468. * Careful: we have to set masks only first to deassert
  469. * any level-triggered sources.
  470. */
  471. v = apic_read(APIC_LVTT);
  472. apic_write(APIC_LVTT, v | APIC_LVT_MASKED);
  473. v = apic_read(APIC_LVT0);
  474. apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
  475. v = apic_read(APIC_LVT1);
  476. apic_write(APIC_LVT1, v | APIC_LVT_MASKED);
  477. if (maxlvt >= 4) {
  478. v = apic_read(APIC_LVTPC);
  479. apic_write(APIC_LVTPC, v | APIC_LVT_MASKED);
  480. }
  481. /*
  482. * Clean APIC state for other OSs:
  483. */
  484. apic_write(APIC_LVTT, APIC_LVT_MASKED);
  485. apic_write(APIC_LVT0, APIC_LVT_MASKED);
  486. apic_write(APIC_LVT1, APIC_LVT_MASKED);
  487. if (maxlvt >= 3)
  488. apic_write(APIC_LVTERR, APIC_LVT_MASKED);
  489. if (maxlvt >= 4)
  490. apic_write(APIC_LVTPC, APIC_LVT_MASKED);
  491. apic_write(APIC_ESR, 0);
  492. apic_read(APIC_ESR);
  493. }
  494. /**
  495. * disable_local_APIC - clear and disable the local APIC
  496. */
  497. void disable_local_APIC(void)
  498. {
  499. unsigned int value;
  500. clear_local_APIC();
  501. /*
  502. * Disable APIC (implies clearing of registers
  503. * for 82489DX!).
  504. */
  505. value = apic_read(APIC_SPIV);
  506. value &= ~APIC_SPIV_APIC_ENABLED;
  507. apic_write(APIC_SPIV, value);
  508. }
  509. void lapic_shutdown(void)
  510. {
  511. unsigned long flags;
  512. if (!cpu_has_apic)
  513. return;
  514. local_irq_save(flags);
  515. disable_local_APIC();
  516. local_irq_restore(flags);
  517. }
  518. /*
  519. * This is to verify that we're looking at a real local APIC.
  520. * Check these against your board if the CPUs aren't getting
  521. * started for no apparent reason.
  522. */
  523. int __init verify_local_APIC(void)
  524. {
  525. unsigned int reg0, reg1;
  526. /*
  527. * The version register is read-only in a real APIC.
  528. */
  529. reg0 = apic_read(APIC_LVR);
  530. apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0);
  531. apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK);
  532. reg1 = apic_read(APIC_LVR);
  533. apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1);
  534. /*
  535. * The two version reads above should print the same
  536. * numbers. If the second one is different, then we
  537. * poke at a non-APIC.
  538. */
  539. if (reg1 != reg0)
  540. return 0;
  541. /*
  542. * Check if the version looks reasonably.
  543. */
  544. reg1 = GET_APIC_VERSION(reg0);
  545. if (reg1 == 0x00 || reg1 == 0xff)
  546. return 0;
  547. reg1 = lapic_get_maxlvt();
  548. if (reg1 < 0x02 || reg1 == 0xff)
  549. return 0;
  550. /*
  551. * The ID register is read/write in a real APIC.
  552. */
  553. reg0 = apic_read(APIC_ID);
  554. apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0);
  555. apic_write(APIC_ID, reg0 ^ APIC_ID_MASK);
  556. reg1 = apic_read(APIC_ID);
  557. apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg1);
  558. apic_write(APIC_ID, reg0);
  559. if (reg1 != (reg0 ^ APIC_ID_MASK))
  560. return 0;
  561. /*
  562. * The next two are just to see if we have sane values.
  563. * They're only really relevant if we're in Virtual Wire
  564. * compatibility mode, but most boxes are anymore.
  565. */
  566. reg0 = apic_read(APIC_LVT0);
  567. apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0);
  568. reg1 = apic_read(APIC_LVT1);
  569. apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1);
  570. return 1;
  571. }
  572. /**
  573. * sync_Arb_IDs - synchronize APIC bus arbitration IDs
  574. */
  575. void __init sync_Arb_IDs(void)
  576. {
  577. /* Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 */
  578. if (modern_apic())
  579. return;
  580. /*
  581. * Wait for idle.
  582. */
  583. apic_wait_icr_idle();
  584. apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n");
  585. apic_write(APIC_ICR, APIC_DEST_ALLINC | APIC_INT_LEVELTRIG
  586. | APIC_DM_INIT);
  587. }
  588. /*
  589. * An initial setup of the virtual wire mode.
  590. */
  591. void __init init_bsp_APIC(void)
  592. {
  593. unsigned int value;
  594. /*
  595. * Don't do the setup now if we have a SMP BIOS as the
  596. * through-I/O-APIC virtual wire mode might be active.
  597. */
  598. if (smp_found_config || !cpu_has_apic)
  599. return;
  600. value = apic_read(APIC_LVR);
  601. /*
  602. * Do not trust the local APIC being empty at bootup.
  603. */
  604. clear_local_APIC();
  605. /*
  606. * Enable APIC.
  607. */
  608. value = apic_read(APIC_SPIV);
  609. value &= ~APIC_VECTOR_MASK;
  610. value |= APIC_SPIV_APIC_ENABLED;
  611. value |= APIC_SPIV_FOCUS_DISABLED;
  612. value |= SPURIOUS_APIC_VECTOR;
  613. apic_write(APIC_SPIV, value);
  614. /*
  615. * Set up the virtual wire mode.
  616. */
  617. apic_write(APIC_LVT0, APIC_DM_EXTINT);
  618. value = APIC_DM_NMI;
  619. apic_write(APIC_LVT1, value);
  620. }
  621. /**
  622. * setup_local_APIC - setup the local APIC
  623. */
  624. void __cpuinit setup_local_APIC(void)
  625. {
  626. unsigned int value;
  627. int i, j;
  628. value = apic_read(APIC_LVR);
  629. BUILD_BUG_ON((SPURIOUS_APIC_VECTOR & 0x0f) != 0x0f);
  630. /*
  631. * Double-check whether this APIC is really registered.
  632. * This is meaningless in clustered apic mode, so we skip it.
  633. */
  634. if (!apic_id_registered())
  635. BUG();
  636. /*
  637. * Intel recommends to set DFR, LDR and TPR before enabling
  638. * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
  639. * document number 292116). So here it goes...
  640. */
  641. init_apic_ldr();
  642. /*
  643. * Set Task Priority to 'accept all'. We never change this
  644. * later on.
  645. */
  646. value = apic_read(APIC_TASKPRI);
  647. value &= ~APIC_TPRI_MASK;
  648. apic_write(APIC_TASKPRI, value);
  649. /*
  650. * After a crash, we no longer service the interrupts and a pending
  651. * interrupt from previous kernel might still have ISR bit set.
  652. *
  653. * Most probably by now CPU has serviced that pending interrupt and
  654. * it might not have done the ack_APIC_irq() because it thought,
  655. * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it
  656. * does not clear the ISR bit and cpu thinks it has already serivced
  657. * the interrupt. Hence a vector might get locked. It was noticed
  658. * for timer irq (vector 0x31). Issue an extra EOI to clear ISR.
  659. */
  660. for (i = APIC_ISR_NR - 1; i >= 0; i--) {
  661. value = apic_read(APIC_ISR + i*0x10);
  662. for (j = 31; j >= 0; j--) {
  663. if (value & (1<<j))
  664. ack_APIC_irq();
  665. }
  666. }
  667. /*
  668. * Now that we are all set up, enable the APIC
  669. */
  670. value = apic_read(APIC_SPIV);
  671. value &= ~APIC_VECTOR_MASK;
  672. /*
  673. * Enable APIC
  674. */
  675. value |= APIC_SPIV_APIC_ENABLED;
  676. /* We always use processor focus */
  677. /*
  678. * Set spurious IRQ vector
  679. */
  680. value |= SPURIOUS_APIC_VECTOR;
  681. apic_write(APIC_SPIV, value);
  682. /*
  683. * Set up LVT0, LVT1:
  684. *
  685. * set up through-local-APIC on the BP's LINT0. This is not
  686. * strictly necessary in pure symmetric-IO mode, but sometimes
  687. * we delegate interrupts to the 8259A.
  688. */
  689. /*
  690. * TODO: set up through-local-APIC from through-I/O-APIC? --macro
  691. */
  692. value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
  693. if (!smp_processor_id() && !value) {
  694. value = APIC_DM_EXTINT;
  695. apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
  696. smp_processor_id());
  697. } else {
  698. value = APIC_DM_EXTINT | APIC_LVT_MASKED;
  699. apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n",
  700. smp_processor_id());
  701. }
  702. apic_write(APIC_LVT0, value);
  703. /*
  704. * only the BP should see the LINT1 NMI signal, obviously.
  705. */
  706. if (!smp_processor_id())
  707. value = APIC_DM_NMI;
  708. else
  709. value = APIC_DM_NMI | APIC_LVT_MASKED;
  710. apic_write(APIC_LVT1, value);
  711. }
  712. void __cpuinit lapic_setup_esr(void)
  713. {
  714. unsigned maxlvt = lapic_get_maxlvt();
  715. apic_write(APIC_LVTERR, ERROR_APIC_VECTOR);
  716. /*
  717. * spec says clear errors after enabling vector.
  718. */
  719. if (maxlvt > 3)
  720. apic_write(APIC_ESR, 0);
  721. }
  722. void __cpuinit end_local_APIC_setup(void)
  723. {
  724. lapic_setup_esr();
  725. nmi_watchdog_default();
  726. setup_apic_nmi_watchdog(NULL);
  727. apic_pm_activate();
  728. }
  729. /*
  730. * Detect and enable local APICs on non-SMP boards.
  731. * Original code written by Keir Fraser.
  732. * On AMD64 we trust the BIOS - if it says no APIC it is likely
  733. * not correctly set up (usually the APIC timer won't work etc.)
  734. */
  735. static int __init detect_init_APIC(void)
  736. {
  737. if (!cpu_has_apic) {
  738. printk(KERN_INFO "No local APIC present\n");
  739. return -1;
  740. }
  741. mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
  742. boot_cpu_physical_apicid = 0;
  743. return 0;
  744. }
  745. void __init early_init_lapic_mapping(void)
  746. {
  747. unsigned long apic_phys;
  748. /*
  749. * If no local APIC can be found then go out
  750. * : it means there is no mpatable and MADT
  751. */
  752. if (!smp_found_config)
  753. return;
  754. apic_phys = mp_lapic_addr;
  755. set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
  756. apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
  757. APIC_BASE, apic_phys);
  758. /*
  759. * Fetch the APIC ID of the BSP in case we have a
  760. * default configuration (or the MP table is broken).
  761. */
  762. boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  763. }
  764. /**
  765. * init_apic_mappings - initialize APIC mappings
  766. */
  767. void __init init_apic_mappings(void)
  768. {
  769. /*
  770. * If no local APIC can be found then set up a fake all
  771. * zeroes page to simulate the local APIC and another
  772. * one for the IO-APIC.
  773. */
  774. if (!smp_found_config && detect_init_APIC()) {
  775. apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  776. apic_phys = __pa(apic_phys);
  777. } else
  778. apic_phys = mp_lapic_addr;
  779. set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
  780. apic_printk(APIC_VERBOSE, "mapped APIC to %16lx (%16lx)\n",
  781. APIC_BASE, apic_phys);
  782. /*
  783. * Fetch the APIC ID of the BSP in case we have a
  784. * default configuration (or the MP table is broken).
  785. */
  786. boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  787. }
  788. /*
  789. * This initializes the IO-APIC and APIC hardware if this is
  790. * a UP kernel.
  791. */
  792. int __init APIC_init_uniprocessor(void)
  793. {
  794. if (disable_apic) {
  795. printk(KERN_INFO "Apic disabled\n");
  796. return -1;
  797. }
  798. if (!cpu_has_apic) {
  799. disable_apic = 1;
  800. printk(KERN_INFO "Apic disabled by BIOS\n");
  801. return -1;
  802. }
  803. verify_local_APIC();
  804. phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
  805. apic_write(APIC_ID, SET_APIC_ID(boot_cpu_physical_apicid));
  806. setup_local_APIC();
  807. /*
  808. * Now enable IO-APICs, actually call clear_IO_APIC
  809. * We need clear_IO_APIC before enabling vector on BP
  810. */
  811. if (!skip_ioapic_setup && nr_ioapics)
  812. enable_IO_APIC();
  813. end_local_APIC_setup();
  814. if (smp_found_config && !skip_ioapic_setup && nr_ioapics)
  815. setup_IO_APIC();
  816. else
  817. nr_ioapics = 0;
  818. setup_boot_APIC_clock();
  819. check_nmi_watchdog();
  820. return 0;
  821. }
  822. /*
  823. * Local APIC interrupts
  824. */
  825. /*
  826. * This interrupt should _never_ happen with our APIC/SMP architecture
  827. */
  828. asmlinkage void smp_spurious_interrupt(void)
  829. {
  830. unsigned int v;
  831. exit_idle();
  832. irq_enter();
  833. /*
  834. * Check if this really is a spurious interrupt and ACK it
  835. * if it is a vectored one. Just in case...
  836. * Spurious interrupts should not be ACKed.
  837. */
  838. v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1));
  839. if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f)))
  840. ack_APIC_irq();
  841. add_pda(irq_spurious_count, 1);
  842. irq_exit();
  843. }
  844. /*
  845. * This interrupt should never happen with our APIC/SMP architecture
  846. */
  847. asmlinkage void smp_error_interrupt(void)
  848. {
  849. unsigned int v, v1;
  850. exit_idle();
  851. irq_enter();
  852. /* First tickle the hardware, only then report what went on. -- REW */
  853. v = apic_read(APIC_ESR);
  854. apic_write(APIC_ESR, 0);
  855. v1 = apic_read(APIC_ESR);
  856. ack_APIC_irq();
  857. atomic_inc(&irq_err_count);
  858. /* Here is what the APIC error bits mean:
  859. 0: Send CS error
  860. 1: Receive CS error
  861. 2: Send accept error
  862. 3: Receive accept error
  863. 4: Reserved
  864. 5: Send illegal vector
  865. 6: Received illegal vector
  866. 7: Illegal register address
  867. */
  868. printk(KERN_DEBUG "APIC error on CPU%d: %02x(%02x)\n",
  869. smp_processor_id(), v , v1);
  870. irq_exit();
  871. }
  872. void disconnect_bsp_APIC(int virt_wire_setup)
  873. {
  874. /* Go back to Virtual Wire compatibility mode */
  875. unsigned long value;
  876. /* For the spurious interrupt use vector F, and enable it */
  877. value = apic_read(APIC_SPIV);
  878. value &= ~APIC_VECTOR_MASK;
  879. value |= APIC_SPIV_APIC_ENABLED;
  880. value |= 0xf;
  881. apic_write(APIC_SPIV, value);
  882. if (!virt_wire_setup) {
  883. /*
  884. * For LVT0 make it edge triggered, active high,
  885. * external and enabled
  886. */
  887. value = apic_read(APIC_LVT0);
  888. value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
  889. APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
  890. APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
  891. value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
  892. value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT);
  893. apic_write(APIC_LVT0, value);
  894. } else {
  895. /* Disable LVT0 */
  896. apic_write(APIC_LVT0, APIC_LVT_MASKED);
  897. }
  898. /* For LVT1 make it edge triggered, active high, nmi and enabled */
  899. value = apic_read(APIC_LVT1);
  900. value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
  901. APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
  902. APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
  903. value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
  904. value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI);
  905. apic_write(APIC_LVT1, value);
  906. }
  907. /*
  908. * Power management
  909. */
  910. #ifdef CONFIG_PM
  911. static struct {
  912. /* 'active' is true if the local APIC was enabled by us and
  913. not the BIOS; this signifies that we are also responsible
  914. for disabling it before entering apm/acpi suspend */
  915. int active;
  916. /* r/w apic fields */
  917. unsigned int apic_id;
  918. unsigned int apic_taskpri;
  919. unsigned int apic_ldr;
  920. unsigned int apic_dfr;
  921. unsigned int apic_spiv;
  922. unsigned int apic_lvtt;
  923. unsigned int apic_lvtpc;
  924. unsigned int apic_lvt0;
  925. unsigned int apic_lvt1;
  926. unsigned int apic_lvterr;
  927. unsigned int apic_tmict;
  928. unsigned int apic_tdcr;
  929. unsigned int apic_thmr;
  930. } apic_pm_state;
  931. static int lapic_suspend(struct sys_device *dev, pm_message_t state)
  932. {
  933. unsigned long flags;
  934. int maxlvt;
  935. if (!apic_pm_state.active)
  936. return 0;
  937. maxlvt = lapic_get_maxlvt();
  938. apic_pm_state.apic_id = apic_read(APIC_ID);
  939. apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI);
  940. apic_pm_state.apic_ldr = apic_read(APIC_LDR);
  941. apic_pm_state.apic_dfr = apic_read(APIC_DFR);
  942. apic_pm_state.apic_spiv = apic_read(APIC_SPIV);
  943. apic_pm_state.apic_lvtt = apic_read(APIC_LVTT);
  944. if (maxlvt >= 4)
  945. apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC);
  946. apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0);
  947. apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1);
  948. apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR);
  949. apic_pm_state.apic_tmict = apic_read(APIC_TMICT);
  950. apic_pm_state.apic_tdcr = apic_read(APIC_TDCR);
  951. #ifdef CONFIG_X86_MCE_INTEL
  952. if (maxlvt >= 5)
  953. apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR);
  954. #endif
  955. local_irq_save(flags);
  956. disable_local_APIC();
  957. local_irq_restore(flags);
  958. return 0;
  959. }
  960. static int lapic_resume(struct sys_device *dev)
  961. {
  962. unsigned int l, h;
  963. unsigned long flags;
  964. int maxlvt;
  965. if (!apic_pm_state.active)
  966. return 0;
  967. maxlvt = lapic_get_maxlvt();
  968. local_irq_save(flags);
  969. rdmsr(MSR_IA32_APICBASE, l, h);
  970. l &= ~MSR_IA32_APICBASE_BASE;
  971. l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
  972. wrmsr(MSR_IA32_APICBASE, l, h);
  973. apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED);
  974. apic_write(APIC_ID, apic_pm_state.apic_id);
  975. apic_write(APIC_DFR, apic_pm_state.apic_dfr);
  976. apic_write(APIC_LDR, apic_pm_state.apic_ldr);
  977. apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri);
  978. apic_write(APIC_SPIV, apic_pm_state.apic_spiv);
  979. apic_write(APIC_LVT0, apic_pm_state.apic_lvt0);
  980. apic_write(APIC_LVT1, apic_pm_state.apic_lvt1);
  981. #ifdef CONFIG_X86_MCE_INTEL
  982. if (maxlvt >= 5)
  983. apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr);
  984. #endif
  985. if (maxlvt >= 4)
  986. apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc);
  987. apic_write(APIC_LVTT, apic_pm_state.apic_lvtt);
  988. apic_write(APIC_TDCR, apic_pm_state.apic_tdcr);
  989. apic_write(APIC_TMICT, apic_pm_state.apic_tmict);
  990. apic_write(APIC_ESR, 0);
  991. apic_read(APIC_ESR);
  992. apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr);
  993. apic_write(APIC_ESR, 0);
  994. apic_read(APIC_ESR);
  995. local_irq_restore(flags);
  996. return 0;
  997. }
  998. static struct sysdev_class lapic_sysclass = {
  999. .name = "lapic",
  1000. .resume = lapic_resume,
  1001. .suspend = lapic_suspend,
  1002. };
  1003. static struct sys_device device_lapic = {
  1004. .id = 0,
  1005. .cls = &lapic_sysclass,
  1006. };
  1007. static void __cpuinit apic_pm_activate(void)
  1008. {
  1009. apic_pm_state.active = 1;
  1010. }
  1011. static int __init init_lapic_sysfs(void)
  1012. {
  1013. int error;
  1014. if (!cpu_has_apic)
  1015. return 0;
  1016. /* XXX: remove suspend/resume procs if !apic_pm_state.active? */
  1017. error = sysdev_class_register(&lapic_sysclass);
  1018. if (!error)
  1019. error = sysdev_register(&device_lapic);
  1020. return error;
  1021. }
  1022. device_initcall(init_lapic_sysfs);
  1023. #else /* CONFIG_PM */
  1024. static void apic_pm_activate(void) { }
  1025. #endif /* CONFIG_PM */
  1026. /*
  1027. * apic_is_clustered_box() -- Check if we can expect good TSC
  1028. *
  1029. * Thus far, the major user of this is IBM's Summit2 series:
  1030. *
  1031. * Clustered boxes may have unsynced TSC problems if they are
  1032. * multi-chassis. Use available data to take a good guess.
  1033. * If in doubt, go HPET.
  1034. */
  1035. __cpuinit int apic_is_clustered_box(void)
  1036. {
  1037. int i, clusters, zeros;
  1038. unsigned id;
  1039. u16 *bios_cpu_apicid;
  1040. DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS);
  1041. /*
  1042. * there is not this kind of box with AMD CPU yet.
  1043. * Some AMD box with quadcore cpu and 8 sockets apicid
  1044. * will be [4, 0x23] or [8, 0x27] could be thought to
  1045. * vsmp box still need checking...
  1046. */
  1047. if ((boot_cpu_data.x86_vendor == X86_VENDOR_AMD) && !is_vsmp_box())
  1048. return 0;
  1049. bios_cpu_apicid = x86_bios_cpu_apicid_early_ptr;
  1050. bitmap_zero(clustermap, NUM_APIC_CLUSTERS);
  1051. for (i = 0; i < NR_CPUS; i++) {
  1052. /* are we being called early in kernel startup? */
  1053. if (bios_cpu_apicid) {
  1054. id = bios_cpu_apicid[i];
  1055. }
  1056. else if (i < nr_cpu_ids) {
  1057. if (cpu_present(i))
  1058. id = per_cpu(x86_bios_cpu_apicid, i);
  1059. else
  1060. continue;
  1061. }
  1062. else
  1063. break;
  1064. if (id != BAD_APICID)
  1065. __set_bit(APIC_CLUSTERID(id), clustermap);
  1066. }
  1067. /* Problem: Partially populated chassis may not have CPUs in some of
  1068. * the APIC clusters they have been allocated. Only present CPUs have
  1069. * x86_bios_cpu_apicid entries, thus causing zeroes in the bitmap.
  1070. * Since clusters are allocated sequentially, count zeros only if
  1071. * they are bounded by ones.
  1072. */
  1073. clusters = 0;
  1074. zeros = 0;
  1075. for (i = 0; i < NUM_APIC_CLUSTERS; i++) {
  1076. if (test_bit(i, clustermap)) {
  1077. clusters += 1 + zeros;
  1078. zeros = 0;
  1079. } else
  1080. ++zeros;
  1081. }
  1082. /* ScaleMP vSMPowered boxes have one cluster per board and TSCs are
  1083. * not guaranteed to be synced between boards
  1084. */
  1085. if (is_vsmp_box() && clusters > 1)
  1086. return 1;
  1087. /*
  1088. * If clusters > 2, then should be multi-chassis.
  1089. * May have to revisit this when multi-core + hyperthreaded CPUs come
  1090. * out, but AFAIK this will work even for them.
  1091. */
  1092. return (clusters > 2);
  1093. }
  1094. /*
  1095. * APIC command line parameters
  1096. */
  1097. static int __init apic_set_verbosity(char *str)
  1098. {
  1099. if (str == NULL) {
  1100. skip_ioapic_setup = 0;
  1101. ioapic_force = 1;
  1102. return 0;
  1103. }
  1104. if (strcmp("debug", str) == 0)
  1105. apic_verbosity = APIC_DEBUG;
  1106. else if (strcmp("verbose", str) == 0)
  1107. apic_verbosity = APIC_VERBOSE;
  1108. else {
  1109. printk(KERN_WARNING "APIC Verbosity level %s not recognised"
  1110. " use apic=verbose or apic=debug\n", str);
  1111. return -EINVAL;
  1112. }
  1113. return 0;
  1114. }
  1115. early_param("apic", apic_set_verbosity);
  1116. static __init int setup_disableapic(char *str)
  1117. {
  1118. disable_apic = 1;
  1119. clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
  1120. return 0;
  1121. }
  1122. early_param("disableapic", setup_disableapic);
  1123. /* same as disableapic, for compatibility */
  1124. static __init int setup_nolapic(char *str)
  1125. {
  1126. return setup_disableapic(str);
  1127. }
  1128. early_param("nolapic", setup_nolapic);
  1129. static int __init parse_lapic_timer_c2_ok(char *arg)
  1130. {
  1131. local_apic_timer_c2_ok = 1;
  1132. return 0;
  1133. }
  1134. early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok);
  1135. static __init int setup_noapictimer(char *str)
  1136. {
  1137. if (str[0] != ' ' && str[0] != 0)
  1138. return 0;
  1139. disable_apic_timer = 1;
  1140. return 1;
  1141. }
  1142. __setup("noapictimer", setup_noapictimer);
  1143. static __init int setup_apicpmtimer(char *s)
  1144. {
  1145. apic_calibrate_pmtmr = 1;
  1146. notsc_setup(NULL);
  1147. return 0;
  1148. }
  1149. __setup("apicpmtimer", setup_apicpmtimer);
  1150. static int __init lapic_insert_resource(void)
  1151. {
  1152. if (!apic_phys)
  1153. return -1;
  1154. /* Put local APIC into the resource map. */
  1155. lapic_resource.start = apic_phys;
  1156. lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1;
  1157. insert_resource(&iomem_resource, &lapic_resource);
  1158. return 0;
  1159. }
  1160. /*
  1161. * need call insert after e820_reserve_resources()
  1162. * that is using request_resource
  1163. */
  1164. late_initcall(lapic_insert_resource);