apic_64.c 32 KB

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