apic_64.c 32 KB

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