blob: 420c15842e4407d0a9cc23eccb1bc8e237e2f4c6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/init.h>
18
19#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/delay.h>
21#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/interrupt.h>
23#include <linux/mc146818rtc.h>
24#include <linux/kernel_stat.h>
25#include <linux/sysdev.h>
Zwane Mwaikambof3705132005-06-25 14:54:50 -070026#include <linux/cpu.h>
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080027#include <linux/clockchips.h>
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -080028#include <linux/acpi_pmtmr.h>
Venkatesh Pallipadi6eb0a0f2006-01-11 22:44:21 +010029#include <linux/module.h>
Thomas Gleixnerad62ca22007-03-22 00:11:21 -080030#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32#include <asm/atomic.h>
33#include <asm/smp.h>
34#include <asm/mtrr.h>
35#include <asm/mpspec.h>
36#include <asm/desc.h>
37#include <asm/arch_hooks.h>
38#include <asm/hpet.h>
Ingo Molnar306e4402005-06-30 02:58:55 -070039#include <asm/i8253.h>
Don Zickus3e4ff112006-06-26 13:57:01 +020040#include <asm/nmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#include <mach_apic.h>
Jesper Juhl382dbd02006-03-23 02:59:49 -080043#include <mach_apicdef.h>
Venkatesh Pallipadi6eb0a0f2006-01-11 22:44:21 +010044#include <mach_ipi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46#include "io_ports.h"
47
48/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -080049 * Sanity check
50 */
51#if (SPURIOUS_APIC_VECTOR & 0x0F) != 0x0F
52# error SPURIOUS_APIC_VECTOR definition error
53#endif
54
55/*
Eric W. Biederman9635b472005-06-25 14:57:41 -070056 * Knob to control our willingness to enable the local APIC.
Thomas Gleixnere05d7232007-02-16 01:27:58 -080057 *
58 * -1=force-disable, +1=force-enable
Eric W. Biederman9635b472005-06-25 14:57:41 -070059 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -080060static int enable_local_apic __initdata = 0;
Eric W. Biederman9635b472005-06-25 14:57:41 -070061
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -080062/* Local APIC timer verification ok */
63static int local_apic_timer_verify_ok;
Andi Kleend3f7eae2007-08-10 22:31:07 +020064/* Disable local APIC timer from the kernel commandline or via dmi quirk
65 or using CPU MSR check */
66int local_apic_timer_disabled;
Thomas Gleixnere585bef2007-03-23 16:08:01 +010067/* Local APIC timer works in C2 */
68int local_apic_timer_c2_ok;
69EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok);
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080070
Eric W. Biederman9635b472005-06-25 14:57:41 -070071/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -080072 * Debug level, exported for io_apic.c
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 */
74int apic_verbosity;
75
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080076static unsigned int calibration_result;
77
78static int lapic_next_event(unsigned long delta,
79 struct clock_event_device *evt);
80static void lapic_timer_setup(enum clock_event_mode mode,
81 struct clock_event_device *evt);
82static void lapic_timer_broadcast(cpumask_t mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083static void apic_pm_activate(void);
84
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080085/*
86 * The local apic timer can be used for any function which is CPU local.
87 */
88static struct clock_event_device lapic_clockevent = {
89 .name = "lapic",
90 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -080091 | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY,
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080092 .shift = 32,
93 .set_mode = lapic_timer_setup,
94 .set_next_event = lapic_next_event,
95 .broadcast = lapic_timer_broadcast,
96 .rating = 100,
97 .irq = -1,
98};
99static DEFINE_PER_CPU(struct clock_event_device, lapic_events);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800101/* Local APIC was disabled by the BIOS and enabled by the kernel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102static int enabled_via_apicbase;
103
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800104/*
105 * Get the LAPIC version
106 */
107static inline int lapic_get_version(void)
108{
109 return GET_APIC_VERSION(apic_read(APIC_LVR));
110}
111
112/*
113 * Check, if the APIC is integrated or a seperate chip
114 */
115static inline int lapic_is_integrated(void)
116{
117 return APIC_INTEGRATED(lapic_get_version());
118}
119
120/*
121 * Check, whether this is a modern or a first generation APIC
122 */
123static int modern_apic(void)
124{
125 /* AMD systems use old APIC versions, so check the CPU */
126 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
127 boot_cpu_data.x86 >= 0xf)
128 return 1;
129 return lapic_get_version() >= 0x14;
130}
131
Fernando Luis VazquezCaof2b218d2007-05-02 19:27:17 +0200132void apic_wait_icr_idle(void)
133{
134 while (apic_read(APIC_ICR) & APIC_ICR_BUSY)
135 cpu_relax();
136}
137
Thomas Gleixner42e0a9a2008-01-30 13:30:15 +0100138u32 safe_apic_wait_icr_idle(void)
Fernando Luis VazquezCaof2b218d2007-05-02 19:27:17 +0200139{
Thomas Gleixner42e0a9a2008-01-30 13:30:15 +0100140 u32 send_status;
Fernando Luis VazquezCaof2b218d2007-05-02 19:27:17 +0200141 int timeout;
142
143 timeout = 0;
144 do {
145 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
146 if (!send_status)
147 break;
148 udelay(100);
149 } while (timeout++ < 1000);
150
151 return send_status;
152}
153
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800154/**
155 * enable_NMI_through_LVT0 - enable NMI through local vector table 0
156 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157void enable_NMI_through_LVT0 (void * dummy)
158{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800159 unsigned int v = APIC_DM_NMI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800161 /* Level triggered for 82489DX */
162 if (!lapic_is_integrated())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 v |= APIC_LVT_LEVEL_TRIGGER;
164 apic_write_around(APIC_LVT0, v);
165}
166
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800167/**
168 * get_physical_broadcast - Get number of physical broadcast IDs
169 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170int get_physical_broadcast(void)
171{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800172 return modern_apic() ? 0xff : 0xf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173}
174
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800175/**
176 * lapic_get_maxlvt - get the maximum number of local vector table entries
177 */
178int lapic_get_maxlvt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800180 unsigned int v = apic_read(APIC_LVR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 /* 82489DXs do not report # of LVT entries. */
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800183 return APIC_INTEGRATED(GET_APIC_VERSION(v)) ? GET_APIC_MAXLVT(v) : 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
186/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800187 * Local APIC timer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800190/* Clock divisor is set to 16 */
191#define APIC_DIVISOR 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193/*
194 * This function sets up the local APIC timer, with a timeout of
195 * 'clocks' APIC bus clock. During calibration we actually call
196 * this function twice on the boot CPU, once with a bogus timeout
197 * value, second time for real. The other (noncalibrating) CPUs
198 * call this function only once, with the real, calibrated value.
199 *
200 * We do reads before writes even if unnecessary, to get around the
201 * P5 APIC double write bug.
202 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800203static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800205 unsigned int lvtt_value, tmp_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800207 lvtt_value = LOCAL_TIMER_VECTOR;
208 if (!oneshot)
209 lvtt_value |= APIC_LVT_TIMER_PERIODIC;
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800210 if (!lapic_is_integrated())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
Venkatesh Pallipadi6eb0a0f2006-01-11 22:44:21 +0100212
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800213 if (!irqen)
Venkatesh Pallipadi6eb0a0f2006-01-11 22:44:21 +0100214 lvtt_value |= APIC_LVT_MASKED;
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 apic_write_around(APIC_LVTT, lvtt_value);
217
218 /*
219 * Divide PICLK by 16
220 */
221 tmp_value = apic_read(APIC_TDCR);
222 apic_write_around(APIC_TDCR, (tmp_value
223 & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE))
224 | APIC_TDR_DIV_16);
225
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800226 if (!oneshot)
227 apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800230/*
231 * Program the next event, relative to now
232 */
233static int lapic_next_event(unsigned long delta,
234 struct clock_event_device *evt)
235{
236 apic_write_around(APIC_TMICT, delta);
237 return 0;
238}
239
240/*
241 * Setup the lapic timer in periodic or oneshot mode
242 */
243static void lapic_timer_setup(enum clock_event_mode mode,
244 struct clock_event_device *evt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
246 unsigned long flags;
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800247 unsigned int v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800249 /* Lapic used for broadcast ? */
250 if (!local_apic_timer_verify_ok)
251 return;
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 local_irq_save(flags);
254
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800255 switch (mode) {
256 case CLOCK_EVT_MODE_PERIODIC:
257 case CLOCK_EVT_MODE_ONESHOT:
258 __setup_APIC_LVTT(calibration_result,
259 mode != CLOCK_EVT_MODE_PERIODIC, 1);
260 break;
261 case CLOCK_EVT_MODE_UNUSED:
262 case CLOCK_EVT_MODE_SHUTDOWN:
263 v = apic_read(APIC_LVTT);
264 v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
265 apic_write_around(APIC_LVTT, v);
266 break;
Thomas Gleixner18de5bc2007-07-21 04:37:34 -0700267 case CLOCK_EVT_MODE_RESUME:
268 /* Nothing to do here */
269 break;
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272 local_irq_restore(flags);
273}
274
275/*
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800276 * Local APIC timer broadcast function
277 */
278static void lapic_timer_broadcast(cpumask_t mask)
279{
280#ifdef CONFIG_SMP
281 send_IPI_mask(mask, LOCAL_TIMER_VECTOR);
282#endif
283}
284
285/*
286 * Setup the local APIC timer for this CPU. Copy the initilized values
287 * of the boot CPU and register the clock event in the framework.
288 */
289static void __devinit setup_APIC_timer(void)
290{
291 struct clock_event_device *levt = &__get_cpu_var(lapic_events);
292
293 memcpy(levt, &lapic_clockevent, sizeof(*levt));
294 levt->cpumask = cpumask_of_cpu(smp_processor_id());
295
296 clockevents_register_device(levt);
297}
298
299/*
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800300 * In this functions we calibrate APIC bus clocks to the external timer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 *
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800302 * We want to do the calibration only once since we want to have local timer
303 * irqs syncron. CPUs connected by the same APIC bus have the very same bus
304 * frequency.
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800305 *
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800306 * This was previously done by reading the PIT/HPET and waiting for a wrap
307 * around to find out, that a tick has elapsed. I have a box, where the PIT
308 * readout is broken, so it never gets out of the wait loop again. This was
309 * also reported by others.
310 *
311 * Monitoring the jiffies value is inaccurate and the clockevents
312 * infrastructure allows us to do a simple substitution of the interrupt
313 * handler.
314 *
315 * The calibration routine also uses the pm_timer when possible, as the PIT
316 * happens to run way too slow (factor 2.3 on my VAIO CoreDuo, which goes
317 * back to normal later in the boot process).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 */
319
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800320#define LAPIC_CAL_LOOPS (HZ/10)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Thomas Gleixnerf5352fd2007-07-21 17:11:32 +0200322static __initdata int lapic_cal_loops = -1;
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800323static __initdata long lapic_cal_t1, lapic_cal_t2;
324static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2;
325static __initdata unsigned long lapic_cal_pm1, lapic_cal_pm2;
326static __initdata unsigned long lapic_cal_j1, lapic_cal_j2;
327
328/*
329 * Temporary interrupt handler.
330 */
331static void __init lapic_cal_handler(struct clock_event_device *dev)
332{
333 unsigned long long tsc = 0;
334 long tapic = apic_read(APIC_TMCCT);
335 unsigned long pm = acpi_pm_read_early();
336
337 if (cpu_has_tsc)
338 rdtscll(tsc);
339
340 switch (lapic_cal_loops++) {
341 case 0:
342 lapic_cal_t1 = tapic;
343 lapic_cal_tsc1 = tsc;
344 lapic_cal_pm1 = pm;
345 lapic_cal_j1 = jiffies;
346 break;
347
348 case LAPIC_CAL_LOOPS:
349 lapic_cal_t2 = tapic;
350 lapic_cal_tsc2 = tsc;
351 if (pm < lapic_cal_pm1)
352 pm += ACPI_PM_OVRRUN;
353 lapic_cal_pm2 = pm;
354 lapic_cal_j2 = jiffies;
355 break;
356 }
357}
358
359/*
360 * Setup the boot APIC
361 *
362 * Calibrate and verify the result.
363 */
364void __init setup_boot_APIC_clock(void)
365{
366 struct clock_event_device *levt = &__get_cpu_var(lapic_events);
367 const long pm_100ms = PMTMR_TICKS_PER_SEC/10;
368 const long pm_thresh = pm_100ms/100;
369 void (*real_handler)(struct clock_event_device *dev);
370 unsigned long deltaj;
371 long delta, deltapm;
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800372 int pm_referenced = 0;
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800373
Thomas Gleixnerad62ca22007-03-22 00:11:21 -0800374 /*
375 * The local apic timer can be disabled via the kernel
Andi Kleend3f7eae2007-08-10 22:31:07 +0200376 * commandline or from the CPU detection code. Register the lapic
Thomas Gleixnerad62ca22007-03-22 00:11:21 -0800377 * timer as a dummy clock event source on SMP systems, so the
378 * broadcast mechanism is used. On UP systems simply ignore it.
379 */
380 if (local_apic_timer_disabled) {
381 /* No broadcast on UP ! */
382 if (num_possible_cpus() > 1)
383 setup_APIC_timer();
384 return;
385 }
386
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800387 apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n"
388 "calibrating APIC timer ...\n");
389
390 local_irq_disable();
391
392 /* Replace the global interrupt handler */
393 real_handler = global_clock_event->event_handler;
394 global_clock_event->event_handler = lapic_cal_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
396 /*
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800397 * Setup the APIC counter to 1e9. There is no way the lapic
398 * can underflow in the 100ms detection time frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800400 __setup_APIC_LVTT(1000000000, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800402 /* Let the interrupts run */
403 local_irq_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800405 while (lapic_cal_loops <= LAPIC_CAL_LOOPS)
406 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800408 local_irq_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800410 /* Restore the real event handler */
411 global_clock_event->event_handler = real_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800413 /* Build delta t1-t2 as apic timer counts down */
414 delta = lapic_cal_t1 - lapic_cal_t2;
415 apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800417 /* Check, if the PM timer is available */
418 deltapm = lapic_cal_pm2 - lapic_cal_pm1;
419 apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800421 if (deltapm) {
422 unsigned long mult;
423 u64 res;
424
425 mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC, 22);
426
427 if (deltapm > (pm_100ms - pm_thresh) &&
428 deltapm < (pm_100ms + pm_thresh)) {
429 apic_printk(APIC_VERBOSE, "... PM timer result ok\n");
430 } else {
431 res = (((u64) deltapm) * mult) >> 22;
432 do_div(res, 1000000);
433 printk(KERN_WARNING "APIC calibration not consistent "
434 "with PM Timer: %ldms instead of 100ms\n",
435 (long)res);
436 /* Correct the lapic counter value */
437 res = (((u64) delta ) * pm_100ms);
438 do_div(res, deltapm);
439 printk(KERN_INFO "APIC delta adjusted to PM-Timer: "
440 "%lu (%ld)\n", (unsigned long) res, delta);
441 delta = (long) res;
442 }
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800443 pm_referenced = 1;
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800446 /* Calculate the scaled math multiplication factor */
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800447 lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS, 32);
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800448 lapic_clockevent.max_delta_ns =
449 clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
450 lapic_clockevent.min_delta_ns =
451 clockevent_delta2ns(0xF, &lapic_clockevent);
452
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800453 calibration_result = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS;
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800454
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800455 apic_printk(APIC_VERBOSE, "..... delta %ld\n", delta);
456 apic_printk(APIC_VERBOSE, "..... mult: %ld\n", lapic_clockevent.mult);
457 apic_printk(APIC_VERBOSE, "..... calibration result: %u\n",
458 calibration_result);
459
460 if (cpu_has_tsc) {
461 delta = (long)(lapic_cal_tsc2 - lapic_cal_tsc1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 apic_printk(APIC_VERBOSE, "..... CPU clock speed is "
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800463 "%ld.%04ld MHz.\n",
464 (delta / LAPIC_CAL_LOOPS) / (1000000 / HZ),
465 (delta / LAPIC_CAL_LOOPS) % (1000000 / HZ));
466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 apic_printk(APIC_VERBOSE, "..... host bus clock speed is "
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800469 "%u.%04u MHz.\n",
470 calibration_result / (1000000 / HZ),
471 calibration_result % (1000000 / HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800473 local_apic_timer_verify_ok = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800475 /* We trust the pm timer based calibration */
476 if (!pm_referenced) {
477 apic_printk(APIC_VERBOSE, "... verify APIC timer\n");
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800478
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800479 /*
480 * Setup the apic timer manually
481 */
482 levt->event_handler = lapic_cal_handler;
483 lapic_timer_setup(CLOCK_EVT_MODE_PERIODIC, levt);
484 lapic_cal_loops = -1;
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800485
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800486 /* Let the interrupts run */
487 local_irq_enable();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800488
Thomas Gleixnerf5352fd2007-07-21 17:11:32 +0200489 while (lapic_cal_loops <= LAPIC_CAL_LOOPS)
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800490 cpu_relax();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800491
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800492 local_irq_disable();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800493
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800494 /* Stop the lapic timer */
495 lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt);
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800496
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800497 local_irq_enable();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800498
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800499 /* Jiffies delta */
500 deltaj = lapic_cal_j2 - lapic_cal_j1;
501 apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj);
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800502
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800503 /* Check, if the jiffies result is consistent */
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800504 if (deltaj >= LAPIC_CAL_LOOPS-2 && deltaj <= LAPIC_CAL_LOOPS+2)
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800505 apic_printk(APIC_VERBOSE, "... jiffies result ok\n");
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800506 else
507 local_apic_timer_verify_ok = 0;
Ingo Molnar4edc5db2007-03-22 10:31:19 +0100508 } else
509 local_irq_enable();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800510
511 if (!local_apic_timer_verify_ok) {
512 printk(KERN_WARNING
513 "APIC timer disabled due to verification failure.\n");
514 /* No broadcast on UP ! */
515 if (num_possible_cpus() == 1)
516 return;
Thomas Gleixnera5f5e432007-03-05 00:30:45 -0800517 } else {
518 /*
519 * If nmi_watchdog is set to IO_APIC, we need the
520 * PIT/HPET going. Otherwise register lapic as a dummy
521 * device.
522 */
523 if (nmi_watchdog != NMI_IO_APIC)
524 lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
Ingo Molnar820de5c2007-07-21 04:37:36 -0700525 else
526 printk(KERN_WARNING "APIC timer registered as dummy,"
527 " due to nmi_watchdog=1!\n");
Thomas Gleixnera5f5e432007-03-05 00:30:45 -0800528 }
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800529
530 /* Setup the lapic or request the broadcast */
531 setup_APIC_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
Li Shaohua0bb31842005-06-25 14:54:55 -0700534void __devinit setup_secondary_APIC_clock(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535{
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800536 setup_APIC_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537}
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539/*
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800540 * The guts of the apic timer interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800542static void local_apic_timer_interrupt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800544 int cpu = smp_processor_id();
545 struct clock_event_device *evt = &per_cpu(lapic_events, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 /*
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800548 * Normally we should not be here till LAPIC has been initialized but
549 * in some cases like kdump, its possible that there is a pending LAPIC
550 * timer interrupt from previous kernel's context and is delivered in
551 * new kernel the moment interrupts are enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 *
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800553 * Interrupts are enabled early and LAPIC is setup much later, hence
554 * its possible that when we get here evt->event_handler is NULL.
555 * Check for event_handler being NULL and discard the interrupt as
556 * spurious.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800558 if (!evt->event_handler) {
559 printk(KERN_WARNING
560 "Spurious LAPIC timer interrupt on cpu %d\n", cpu);
561 /* Switch it off */
562 lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt);
563 return;
564 }
565
Thomas Gleixner0e078e22008-01-30 13:30:20 +0100566 /*
567 * the NMI deadlock-detector uses this.
568 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800569 per_cpu(irq_stat, cpu).apic_timer_irqs++;
570
571 evt->event_handler(evt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572}
573
574/*
575 * Local APIC timer interrupt. This is the most natural way for doing
576 * local interrupts, but local timer interrupts can be emulated by
577 * broadcast interrupts too. [in case the hw doesn't support APIC timers]
578 *
579 * [ if a single-CPU system runs an SMP kernel then we call the local
580 * interrupt as well. Thus we cannot inline the local irq ... ]
581 */
582
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800583void fastcall smp_apic_timer_interrupt(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
David Howells7d12e782006-10-05 14:55:46 +0100585 struct pt_regs *old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 /*
588 * NOTE! We'd better ACK the irq immediately,
589 * because timer handling can be slow.
590 */
591 ack_APIC_irq();
592 /*
593 * update_process_times() expects us to have done irq_enter().
594 * Besides, if we don't timer interrupts ignore the global
595 * interrupt lock, which is the WrongThing (tm) to do.
596 */
597 irq_enter();
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800598 local_apic_timer_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 irq_exit();
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800600
David Howells7d12e782006-10-05 14:55:46 +0100601 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602}
603
Venkatesh Pallipadi5a07a302006-01-11 22:44:18 +0100604int setup_profiling_timer(unsigned int multiplier)
605{
606 return -EINVAL;
607}
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800610 * Local APIC start and shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800612
613/**
614 * clear_local_APIC - shutdown the local APIC
615 *
616 * This is called, when a CPU is disabled and before rebooting, so the state of
617 * the local APIC has no dangling leftovers. Also used to cleanout any BIOS
618 * leftovers during boot.
619 */
620void clear_local_APIC(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800622 int maxlvt = lapic_get_maxlvt();
Thomas Gleixner0e078e22008-01-30 13:30:20 +0100623 u32 v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 /*
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800626 * Masking an LVT entry can trigger a local APIC error
627 * if the vector is zero. Mask LVTERR first to prevent this.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800629 if (maxlvt >= 3) {
630 v = ERROR_APIC_VECTOR; /* any non-zero vector will do */
631 apic_write_around(APIC_LVTERR, v | APIC_LVT_MASKED);
632 }
633 /*
634 * Careful: we have to set masks only first to deassert
635 * any level-triggered sources.
636 */
637 v = apic_read(APIC_LVTT);
638 apic_write_around(APIC_LVTT, v | APIC_LVT_MASKED);
639 v = apic_read(APIC_LVT0);
640 apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);
641 v = apic_read(APIC_LVT1);
642 apic_write_around(APIC_LVT1, v | APIC_LVT_MASKED);
643 if (maxlvt >= 4) {
644 v = apic_read(APIC_LVTPC);
645 apic_write_around(APIC_LVTPC, v | APIC_LVT_MASKED);
646 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800648 /* lets not touch this if we didn't frob it */
649#ifdef CONFIG_X86_MCE_P4THERMAL
650 if (maxlvt >= 5) {
651 v = apic_read(APIC_LVTTHMR);
652 apic_write_around(APIC_LVTTHMR, v | APIC_LVT_MASKED);
653 }
654#endif
655 /*
656 * Clean APIC state for other OSs:
657 */
658 apic_write_around(APIC_LVTT, APIC_LVT_MASKED);
659 apic_write_around(APIC_LVT0, APIC_LVT_MASKED);
660 apic_write_around(APIC_LVT1, APIC_LVT_MASKED);
661 if (maxlvt >= 3)
662 apic_write_around(APIC_LVTERR, APIC_LVT_MASKED);
663 if (maxlvt >= 4)
664 apic_write_around(APIC_LVTPC, APIC_LVT_MASKED);
665
666#ifdef CONFIG_X86_MCE_P4THERMAL
667 if (maxlvt >= 5)
668 apic_write_around(APIC_LVTTHMR, APIC_LVT_MASKED);
669#endif
670 /* Integrated APIC (!82489DX) ? */
671 if (lapic_is_integrated()) {
672 if (maxlvt > 3)
673 /* Clear ESR due to Pentium errata 3AP and 11AP */
674 apic_write(APIC_ESR, 0);
675 apic_read(APIC_ESR);
676 }
677}
678
679/**
680 * disable_local_APIC - clear and disable the local APIC
681 */
682void disable_local_APIC(void)
683{
684 unsigned long value;
685
686 clear_local_APIC();
687
688 /*
689 * Disable APIC (implies clearing of registers
690 * for 82489DX!).
691 */
692 value = apic_read(APIC_SPIV);
693 value &= ~APIC_SPIV_APIC_ENABLED;
694 apic_write_around(APIC_SPIV, value);
695
696 /*
697 * When LAPIC was disabled by the BIOS and enabled by the kernel,
698 * restore the disabled state.
699 */
700 if (enabled_via_apicbase) {
701 unsigned int l, h;
702
703 rdmsr(MSR_IA32_APICBASE, l, h);
704 l &= ~MSR_IA32_APICBASE_ENABLE;
705 wrmsr(MSR_IA32_APICBASE, l, h);
706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
709/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800710 * If Linux enabled the LAPIC against the BIOS default disable it down before
711 * re-entering the BIOS on shutdown. Otherwise the BIOS may get confused and
712 * not power-off. Additionally clear all LVT entries before disable_local_APIC
713 * for the case where Linux didn't enable the LAPIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800715void lapic_shutdown(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800717 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800719 if (!cpu_has_apic)
720 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800722 local_irq_save(flags);
723 clear_local_APIC();
724
725 if (enabled_via_apicbase)
726 disable_local_APIC();
727
728 local_irq_restore(flags);
729}
730
731/*
732 * This is to verify that we're looking at a real local APIC.
733 * Check these against your board if the CPUs aren't getting
734 * started for no apparent reason.
735 */
736int __init verify_local_APIC(void)
737{
738 unsigned int reg0, reg1;
739
740 /*
741 * The version register is read-only in a real APIC.
742 */
743 reg0 = apic_read(APIC_LVR);
744 apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0);
745 apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK);
746 reg1 = apic_read(APIC_LVR);
747 apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1);
748
749 /*
750 * The two version reads above should print the same
751 * numbers. If the second one is different, then we
752 * poke at a non-APIC.
753 */
754 if (reg1 != reg0)
755 return 0;
756
757 /*
758 * Check if the version looks reasonably.
759 */
760 reg1 = GET_APIC_VERSION(reg0);
761 if (reg1 == 0x00 || reg1 == 0xff)
762 return 0;
763 reg1 = lapic_get_maxlvt();
764 if (reg1 < 0x02 || reg1 == 0xff)
765 return 0;
766
767 /*
768 * The ID register is read/write in a real APIC.
769 */
770 reg0 = apic_read(APIC_ID);
771 apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0);
772
773 /*
774 * The next two are just to see if we have sane values.
775 * They're only really relevant if we're in Virtual Wire
776 * compatibility mode, but most boxes are anymore.
777 */
778 reg0 = apic_read(APIC_LVT0);
779 apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0);
780 reg1 = apic_read(APIC_LVT1);
781 apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1);
782
783 return 1;
784}
785
786/**
787 * sync_Arb_IDs - synchronize APIC bus arbitration IDs
788 */
789void __init sync_Arb_IDs(void)
790{
791 /*
792 * Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 And not
793 * needed on AMD.
794 */
Ingo Molnarf44d9ef2007-11-26 20:42:20 +0100795 if (modern_apic() || boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800796 return;
797 /*
798 * Wait for idle.
799 */
800 apic_wait_icr_idle();
801
802 apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n");
803 apic_write_around(APIC_ICR, APIC_DEST_ALLINC | APIC_INT_LEVELTRIG
804 | APIC_DM_INIT);
805}
806
807/*
808 * An initial setup of the virtual wire mode.
809 */
810void __init init_bsp_APIC(void)
811{
812 unsigned long value;
813
814 /*
815 * Don't do the setup now if we have a SMP BIOS as the
816 * through-I/O-APIC virtual wire mode might be active.
817 */
818 if (smp_found_config || !cpu_has_apic)
819 return;
820
821 /*
822 * Do not trust the local APIC being empty at bootup.
823 */
824 clear_local_APIC();
825
826 /*
827 * Enable APIC.
828 */
829 value = apic_read(APIC_SPIV);
830 value &= ~APIC_VECTOR_MASK;
831 value |= APIC_SPIV_APIC_ENABLED;
832
833 /* This bit is reserved on P4/Xeon and should be cleared */
834 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
835 (boot_cpu_data.x86 == 15))
836 value &= ~APIC_SPIV_FOCUS_DISABLED;
837 else
838 value |= APIC_SPIV_FOCUS_DISABLED;
839 value |= SPURIOUS_APIC_VECTOR;
840 apic_write_around(APIC_SPIV, value);
841
842 /*
843 * Set up the virtual wire mode.
844 */
845 apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
846 value = APIC_DM_NMI;
847 if (!lapic_is_integrated()) /* 82489DX */
848 value |= APIC_LVT_LEVEL_TRIGGER;
849 apic_write_around(APIC_LVT1, value);
850}
851
852/**
853 * setup_local_APIC - setup the local APIC
854 */
Adrian Bunkd5337982007-12-19 23:20:18 +0100855void __cpuinit setup_local_APIC(void)
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800856{
857 unsigned long oldvalue, value, maxlvt, integrated;
858 int i, j;
859
860 /* Pound the ESR really hard over the head with a big hammer - mbligh */
861 if (esr_disable) {
862 apic_write(APIC_ESR, 0);
863 apic_write(APIC_ESR, 0);
864 apic_write(APIC_ESR, 0);
865 apic_write(APIC_ESR, 0);
866 }
867
868 integrated = lapic_is_integrated();
869
870 /*
871 * Double-check whether this APIC is really registered.
872 */
873 if (!apic_id_registered())
874 BUG();
875
876 /*
877 * Intel recommends to set DFR, LDR and TPR before enabling
878 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
879 * document number 292116). So here it goes...
880 */
881 init_apic_ldr();
882
883 /*
884 * Set Task Priority to 'accept all'. We never change this
885 * later on.
886 */
887 value = apic_read(APIC_TASKPRI);
888 value &= ~APIC_TPRI_MASK;
889 apic_write_around(APIC_TASKPRI, value);
890
891 /*
892 * After a crash, we no longer service the interrupts and a pending
893 * interrupt from previous kernel might still have ISR bit set.
894 *
895 * Most probably by now CPU has serviced that pending interrupt and
896 * it might not have done the ack_APIC_irq() because it thought,
897 * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it
898 * does not clear the ISR bit and cpu thinks it has already serivced
899 * the interrupt. Hence a vector might get locked. It was noticed
900 * for timer irq (vector 0x31). Issue an extra EOI to clear ISR.
901 */
902 for (i = APIC_ISR_NR - 1; i >= 0; i--) {
903 value = apic_read(APIC_ISR + i*0x10);
904 for (j = 31; j >= 0; j--) {
905 if (value & (1<<j))
906 ack_APIC_irq();
907 }
908 }
909
910 /*
911 * Now that we are all set up, enable the APIC
912 */
913 value = apic_read(APIC_SPIV);
914 value &= ~APIC_VECTOR_MASK;
915 /*
916 * Enable APIC
917 */
918 value |= APIC_SPIV_APIC_ENABLED;
919
920 /*
921 * Some unknown Intel IO/APIC (or APIC) errata is biting us with
922 * certain networking cards. If high frequency interrupts are
923 * happening on a particular IOAPIC pin, plus the IOAPIC routing
924 * entry is masked/unmasked at a high rate as well then sooner or
925 * later IOAPIC line gets 'stuck', no more interrupts are received
926 * from the device. If focus CPU is disabled then the hang goes
927 * away, oh well :-(
928 *
929 * [ This bug can be reproduced easily with a level-triggered
930 * PCI Ne2000 networking cards and PII/PIII processors, dual
931 * BX chipset. ]
932 */
933 /*
934 * Actually disabling the focus CPU check just makes the hang less
935 * frequent as it makes the interrupt distributon model be more
936 * like LRU than MRU (the short-term load is more even across CPUs).
937 * See also the comment in end_level_ioapic_irq(). --macro
938 */
939
940 /* Enable focus processor (bit==0) */
941 value &= ~APIC_SPIV_FOCUS_DISABLED;
942
943 /*
944 * Set spurious IRQ vector
945 */
946 value |= SPURIOUS_APIC_VECTOR;
947 apic_write_around(APIC_SPIV, value);
948
949 /*
950 * Set up LVT0, LVT1:
951 *
952 * set up through-local-APIC on the BP's LINT0. This is not
Simon Arlott27b46d72007-10-20 01:13:56 +0200953 * strictly necessary in pure symmetric-IO mode, but sometimes
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800954 * we delegate interrupts to the 8259A.
955 */
956 /*
957 * TODO: set up through-local-APIC from through-I/O-APIC? --macro
958 */
959 value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
960 if (!smp_processor_id() && (pic_mode || !value)) {
961 value = APIC_DM_EXTINT;
962 apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
963 smp_processor_id());
964 } else {
965 value = APIC_DM_EXTINT | APIC_LVT_MASKED;
966 apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n",
967 smp_processor_id());
968 }
969 apic_write_around(APIC_LVT0, value);
970
971 /*
972 * only the BP should see the LINT1 NMI signal, obviously.
973 */
974 if (!smp_processor_id())
975 value = APIC_DM_NMI;
976 else
977 value = APIC_DM_NMI | APIC_LVT_MASKED;
978 if (!integrated) /* 82489DX */
979 value |= APIC_LVT_LEVEL_TRIGGER;
980 apic_write_around(APIC_LVT1, value);
981
982 if (integrated && !esr_disable) { /* !82489DX */
983 maxlvt = lapic_get_maxlvt();
984 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
985 apic_write(APIC_ESR, 0);
986 oldvalue = apic_read(APIC_ESR);
987
988 /* enables sending errors */
989 value = ERROR_APIC_VECTOR;
990 apic_write_around(APIC_LVTERR, value);
991 /*
992 * spec says clear errors after enabling vector.
993 */
994 if (maxlvt > 3)
995 apic_write(APIC_ESR, 0);
996 value = apic_read(APIC_ESR);
997 if (value != oldvalue)
998 apic_printk(APIC_VERBOSE, "ESR value before enabling "
999 "vector: 0x%08lx after: 0x%08lx\n",
1000 oldvalue, value);
1001 } else {
1002 if (esr_disable)
1003 /*
Simon Arlott27b46d72007-10-20 01:13:56 +02001004 * Something untraceable is creating bad interrupts on
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001005 * secondary quads ... for the moment, just leave the
1006 * ESR disabled - we can't do anything useful with the
1007 * errors anyway - mbligh
1008 */
1009 printk(KERN_INFO "Leaving ESR disabled.\n");
1010 else
1011 printk(KERN_INFO "No ESR for 82489DX.\n");
1012 }
1013
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -08001014 /* Disable the local apic timer */
1015 value = apic_read(APIC_LVTT);
1016 value |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
1017 apic_write_around(APIC_LVTT, value);
1018
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001019 setup_apic_nmi_watchdog(NULL);
1020 apic_pm_activate();
1021}
1022
1023/*
1024 * Detect and initialize APIC
1025 */
1026static int __init detect_init_APIC (void)
1027{
1028 u32 h, l, features;
1029
1030 /* Disabled by kernel option? */
1031 if (enable_local_apic < 0)
1032 return -1;
1033
1034 switch (boot_cpu_data.x86_vendor) {
1035 case X86_VENDOR_AMD:
1036 if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model > 1) ||
1037 (boot_cpu_data.x86 == 15))
1038 break;
1039 goto no_apic;
1040 case X86_VENDOR_INTEL:
1041 if (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15 ||
1042 (boot_cpu_data.x86 == 5 && cpu_has_apic))
1043 break;
1044 goto no_apic;
1045 default:
1046 goto no_apic;
1047 }
1048
1049 if (!cpu_has_apic) {
1050 /*
1051 * Over-ride BIOS and try to enable the local APIC only if
1052 * "lapic" specified.
1053 */
1054 if (enable_local_apic <= 0) {
1055 printk(KERN_INFO "Local APIC disabled by BIOS -- "
1056 "you can enable it with \"lapic\"\n");
1057 return -1;
1058 }
1059 /*
1060 * Some BIOSes disable the local APIC in the APIC_BASE
1061 * MSR. This can only be done in software for Intel P6 or later
1062 * and AMD K7 (Model > 1) or later.
1063 */
1064 rdmsr(MSR_IA32_APICBASE, l, h);
1065 if (!(l & MSR_IA32_APICBASE_ENABLE)) {
1066 printk(KERN_INFO
1067 "Local APIC disabled by BIOS -- reenabling.\n");
1068 l &= ~MSR_IA32_APICBASE_BASE;
1069 l |= MSR_IA32_APICBASE_ENABLE | APIC_DEFAULT_PHYS_BASE;
1070 wrmsr(MSR_IA32_APICBASE, l, h);
1071 enabled_via_apicbase = 1;
1072 }
1073 }
1074 /*
1075 * The APIC feature bit should now be enabled
1076 * in `cpuid'
1077 */
1078 features = cpuid_edx(1);
1079 if (!(features & (1 << X86_FEATURE_APIC))) {
1080 printk(KERN_WARNING "Could not enable APIC!\n");
1081 return -1;
1082 }
1083 set_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
1084 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
1085
1086 /* The BIOS may have set up the APIC at some other address */
1087 rdmsr(MSR_IA32_APICBASE, l, h);
1088 if (l & MSR_IA32_APICBASE_ENABLE)
1089 mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
1090
Daniel Gollub0328ece2007-08-15 02:40:35 +02001091 if (nmi_watchdog != NMI_NONE && nmi_watchdog != NMI_DISABLED)
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001092 nmi_watchdog = NMI_LOCAL_APIC;
1093
1094 printk(KERN_INFO "Found and enabled local APIC!\n");
1095
1096 apic_pm_activate();
1097
1098 return 0;
1099
1100no_apic:
1101 printk(KERN_INFO "No local APIC present or hardware disabled\n");
1102 return -1;
1103}
1104
1105/**
1106 * init_apic_mappings - initialize APIC mappings
1107 */
1108void __init init_apic_mappings(void)
1109{
1110 unsigned long apic_phys;
1111
1112 /*
1113 * If no local APIC can be found then set up a fake all
1114 * zeroes page to simulate the local APIC and another
1115 * one for the IO-APIC.
1116 */
1117 if (!smp_found_config && detect_init_APIC()) {
1118 apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
1119 apic_phys = __pa(apic_phys);
1120 } else
1121 apic_phys = mp_lapic_addr;
1122
1123 set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
1124 printk(KERN_DEBUG "mapped APIC to %08lx (%08lx)\n", APIC_BASE,
1125 apic_phys);
1126
1127 /*
1128 * Fetch the APIC ID of the BSP in case we have a
1129 * default configuration (or the MP table is broken).
1130 */
1131 if (boot_cpu_physical_apicid == -1U)
1132 boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
1133
1134#ifdef CONFIG_X86_IO_APIC
1135 {
1136 unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
1137 int i;
1138
1139 for (i = 0; i < nr_ioapics; i++) {
1140 if (smp_found_config) {
1141 ioapic_phys = mp_ioapics[i].mpc_apicaddr;
1142 if (!ioapic_phys) {
1143 printk(KERN_ERR
1144 "WARNING: bogus zero IO-APIC "
1145 "address found in MPTABLE, "
1146 "disabling IO/APIC support!\n");
1147 smp_found_config = 0;
1148 skip_ioapic_setup = 1;
1149 goto fake_ioapic_page;
1150 }
1151 } else {
1152fake_ioapic_page:
1153 ioapic_phys = (unsigned long)
1154 alloc_bootmem_pages(PAGE_SIZE);
1155 ioapic_phys = __pa(ioapic_phys);
1156 }
1157 set_fixmap_nocache(idx, ioapic_phys);
1158 printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
1159 __fix_to_virt(idx), ioapic_phys);
1160 idx++;
1161 }
1162 }
1163#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
1166/*
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001167 * This initializes the IO-APIC and APIC hardware if this is
1168 * a UP kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 */
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001170int __init APIC_init_uniprocessor (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171{
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001172 if (enable_local_apic < 0)
1173 clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
Eric W. Biedermanf2b36db2005-10-30 14:59:41 -08001174
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001175 if (!smp_found_config && !cpu_has_apic)
Eric W. Biedermanf2b36db2005-10-30 14:59:41 -08001176 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 /*
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001179 * Complain if the BIOS pretends there is one.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001181 if (!cpu_has_apic &&
1182 APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001184 boot_cpu_physical_apicid);
Andi Kleen3777a952006-02-03 21:51:53 +01001185 clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 return -1;
1187 }
1188
1189 verify_local_APIC();
1190
1191 connect_bsp_APIC();
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001192
Vivek Goyalbe0d03f2006-05-20 15:00:21 -07001193 /*
1194 * Hack: In case of kdump, after a crash, kernel might be booting
1195 * on a cpu with non-zero lapic id. But boot_cpu_physical_apicid
1196 * might be zero if read from MP tables. Get it from LAPIC.
1197 */
1198#ifdef CONFIG_CRASH_DUMP
1199 boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
1200#endif
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001201 phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
1202
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 setup_local_APIC();
1204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001206 if (smp_found_config)
1207 if (!skip_ioapic_setup && nr_ioapics)
1208 setup_IO_APIC();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209#endif
Zachary Amsdenbbab4f32007-02-13 13:26:21 +01001210 setup_boot_clock();
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001211
1212 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001214
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001215/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001216 * Local APIC interrupts
1217 */
1218
1219/*
1220 * This interrupt should _never_ happen with our APIC/SMP architecture
1221 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -08001222void smp_spurious_interrupt(struct pt_regs *regs)
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001223{
1224 unsigned long v;
1225
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001226 irq_enter();
1227 /*
1228 * Check if this really is a spurious interrupt and ACK it
1229 * if it is a vectored one. Just in case...
1230 * Spurious interrupts should not be ACKed.
1231 */
1232 v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1));
1233 if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f)))
1234 ack_APIC_irq();
1235
1236 /* see sw-dev-man vol 3, chapter 7.4.13.5 */
1237 printk(KERN_INFO "spurious APIC interrupt on CPU#%d, "
1238 "should never happen.\n", smp_processor_id());
Joe Korty38e760a2007-10-17 18:04:40 +02001239 __get_cpu_var(irq_stat).irq_spurious_count++;
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001240 irq_exit();
1241}
1242
1243/*
1244 * This interrupt should never happen with our APIC/SMP architecture
1245 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -08001246void smp_error_interrupt(struct pt_regs *regs)
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001247{
1248 unsigned long v, v1;
1249
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001250 irq_enter();
1251 /* First tickle the hardware, only then report what went on. -- REW */
1252 v = apic_read(APIC_ESR);
1253 apic_write(APIC_ESR, 0);
1254 v1 = apic_read(APIC_ESR);
1255 ack_APIC_irq();
1256 atomic_inc(&irq_err_count);
1257
1258 /* Here is what the APIC error bits mean:
1259 0: Send CS error
1260 1: Receive CS error
1261 2: Send accept error
1262 3: Receive accept error
1263 4: Reserved
1264 5: Send illegal vector
1265 6: Received illegal vector
1266 7: Illegal register address
1267 */
1268 printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
1269 smp_processor_id(), v , v1);
1270 irq_exit();
1271}
1272
1273/*
1274 * Initialize APIC interrupts
1275 */
1276void __init apic_intr_init(void)
1277{
1278#ifdef CONFIG_SMP
1279 smp_intr_init();
1280#endif
1281 /* self generated IPI for local APIC timer */
1282 set_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
1283
1284 /* IPI vectors for APIC spurious and error interrupts */
1285 set_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
1286 set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
1287
1288 /* thermal monitor LVT interrupt */
1289#ifdef CONFIG_X86_MCE_P4THERMAL
1290 set_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
1291#endif
1292}
1293
1294/**
1295 * connect_bsp_APIC - attach the APIC to the interrupt system
1296 */
1297void __init connect_bsp_APIC(void)
1298{
1299 if (pic_mode) {
1300 /*
1301 * Do not trust the local APIC being empty at bootup.
1302 */
1303 clear_local_APIC();
1304 /*
1305 * PIC mode, enable APIC mode in the IMCR, i.e. connect BSP's
1306 * local APIC to INT and NMI lines.
1307 */
1308 apic_printk(APIC_VERBOSE, "leaving PIC mode, "
1309 "enabling APIC mode.\n");
1310 outb(0x70, 0x22);
1311 outb(0x01, 0x23);
1312 }
1313 enable_apic_mode();
1314}
1315
1316/**
1317 * disconnect_bsp_APIC - detach the APIC from the interrupt system
1318 * @virt_wire_setup: indicates, whether virtual wire mode is selected
1319 *
1320 * Virtual wire mode is necessary to deliver legacy interrupts even when the
1321 * APIC is disabled.
1322 */
1323void disconnect_bsp_APIC(int virt_wire_setup)
1324{
1325 if (pic_mode) {
1326 /*
1327 * Put the board back into PIC mode (has an effect only on
1328 * certain older boards). Note that APIC interrupts, including
1329 * IPIs, won't work beyond this point! The only exception are
1330 * INIT IPIs.
1331 */
1332 apic_printk(APIC_VERBOSE, "disabling APIC mode, "
1333 "entering PIC mode.\n");
1334 outb(0x70, 0x22);
1335 outb(0x00, 0x23);
1336 } else {
1337 /* Go back to Virtual Wire compatibility mode */
1338 unsigned long value;
1339
1340 /* For the spurious interrupt use vector F, and enable it */
1341 value = apic_read(APIC_SPIV);
1342 value &= ~APIC_VECTOR_MASK;
1343 value |= APIC_SPIV_APIC_ENABLED;
1344 value |= 0xf;
1345 apic_write_around(APIC_SPIV, value);
1346
1347 if (!virt_wire_setup) {
1348 /*
1349 * For LVT0 make it edge triggered, active high,
1350 * external and enabled
1351 */
1352 value = apic_read(APIC_LVT0);
1353 value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
1354 APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
1355 APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED );
1356 value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
1357 value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT);
1358 apic_write_around(APIC_LVT0, value);
1359 } else {
1360 /* Disable LVT0 */
1361 apic_write_around(APIC_LVT0, APIC_LVT_MASKED);
1362 }
1363
1364 /*
1365 * For LVT1 make it edge triggered, active high, nmi and
1366 * enabled
1367 */
1368 value = apic_read(APIC_LVT1);
1369 value &= ~(
1370 APIC_MODE_MASK | APIC_SEND_PENDING |
1371 APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
1372 APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
1373 value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
1374 value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI);
1375 apic_write_around(APIC_LVT1, value);
1376 }
1377}
1378
1379/*
1380 * Power management
1381 */
1382#ifdef CONFIG_PM
1383
1384static struct {
1385 int active;
1386 /* r/w apic fields */
1387 unsigned int apic_id;
1388 unsigned int apic_taskpri;
1389 unsigned int apic_ldr;
1390 unsigned int apic_dfr;
1391 unsigned int apic_spiv;
1392 unsigned int apic_lvtt;
1393 unsigned int apic_lvtpc;
1394 unsigned int apic_lvt0;
1395 unsigned int apic_lvt1;
1396 unsigned int apic_lvterr;
1397 unsigned int apic_tmict;
1398 unsigned int apic_tdcr;
1399 unsigned int apic_thmr;
1400} apic_pm_state;
1401
1402static int lapic_suspend(struct sys_device *dev, pm_message_t state)
1403{
1404 unsigned long flags;
1405 int maxlvt;
1406
1407 if (!apic_pm_state.active)
1408 return 0;
1409
1410 maxlvt = lapic_get_maxlvt();
1411
1412 apic_pm_state.apic_id = apic_read(APIC_ID);
1413 apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI);
1414 apic_pm_state.apic_ldr = apic_read(APIC_LDR);
1415 apic_pm_state.apic_dfr = apic_read(APIC_DFR);
1416 apic_pm_state.apic_spiv = apic_read(APIC_SPIV);
1417 apic_pm_state.apic_lvtt = apic_read(APIC_LVTT);
1418 if (maxlvt >= 4)
1419 apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC);
1420 apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0);
1421 apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1);
1422 apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR);
1423 apic_pm_state.apic_tmict = apic_read(APIC_TMICT);
1424 apic_pm_state.apic_tdcr = apic_read(APIC_TDCR);
1425#ifdef CONFIG_X86_MCE_P4THERMAL
1426 if (maxlvt >= 5)
1427 apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR);
1428#endif
1429
1430 local_irq_save(flags);
1431 disable_local_APIC();
1432 local_irq_restore(flags);
1433 return 0;
1434}
1435
1436static int lapic_resume(struct sys_device *dev)
1437{
1438 unsigned int l, h;
1439 unsigned long flags;
1440 int maxlvt;
1441
1442 if (!apic_pm_state.active)
1443 return 0;
1444
1445 maxlvt = lapic_get_maxlvt();
1446
1447 local_irq_save(flags);
1448
1449 /*
1450 * Make sure the APICBASE points to the right address
1451 *
1452 * FIXME! This will be wrong if we ever support suspend on
1453 * SMP! We'll need to do this as part of the CPU restore!
1454 */
1455 rdmsr(MSR_IA32_APICBASE, l, h);
1456 l &= ~MSR_IA32_APICBASE_BASE;
1457 l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
1458 wrmsr(MSR_IA32_APICBASE, l, h);
1459
1460 apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED);
1461 apic_write(APIC_ID, apic_pm_state.apic_id);
1462 apic_write(APIC_DFR, apic_pm_state.apic_dfr);
1463 apic_write(APIC_LDR, apic_pm_state.apic_ldr);
1464 apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri);
1465 apic_write(APIC_SPIV, apic_pm_state.apic_spiv);
1466 apic_write(APIC_LVT0, apic_pm_state.apic_lvt0);
1467 apic_write(APIC_LVT1, apic_pm_state.apic_lvt1);
1468#ifdef CONFIG_X86_MCE_P4THERMAL
1469 if (maxlvt >= 5)
1470 apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr);
1471#endif
1472 if (maxlvt >= 4)
1473 apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc);
1474 apic_write(APIC_LVTT, apic_pm_state.apic_lvtt);
1475 apic_write(APIC_TDCR, apic_pm_state.apic_tdcr);
1476 apic_write(APIC_TMICT, apic_pm_state.apic_tmict);
1477 apic_write(APIC_ESR, 0);
1478 apic_read(APIC_ESR);
1479 apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr);
1480 apic_write(APIC_ESR, 0);
1481 apic_read(APIC_ESR);
1482 local_irq_restore(flags);
1483 return 0;
1484}
1485
1486/*
1487 * This device has no shutdown method - fully functioning local APICs
1488 * are needed on every CPU up until machine_halt/restart/poweroff.
1489 */
1490
1491static struct sysdev_class lapic_sysclass = {
Kay Sieversaf5ca3f2007-12-20 02:09:39 +01001492 .name = "lapic",
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001493 .resume = lapic_resume,
1494 .suspend = lapic_suspend,
1495};
1496
1497static struct sys_device device_lapic = {
1498 .id = 0,
1499 .cls = &lapic_sysclass,
1500};
1501
1502static void __devinit apic_pm_activate(void)
1503{
1504 apic_pm_state.active = 1;
1505}
1506
1507static int __init init_lapic_sysfs(void)
1508{
1509 int error;
1510
1511 if (!cpu_has_apic)
1512 return 0;
1513 /* XXX: remove suspend/resume procs if !apic_pm_state.active? */
1514
1515 error = sysdev_class_register(&lapic_sysclass);
1516 if (!error)
1517 error = sysdev_register(&device_lapic);
1518 return error;
1519}
1520device_initcall(init_lapic_sysfs);
1521
1522#else /* CONFIG_PM */
1523
1524static void apic_pm_activate(void) { }
1525
1526#endif /* CONFIG_PM */
Thomas Gleixner0e078e22008-01-30 13:30:20 +01001527
1528/*
1529 * APIC command line parameters
1530 */
1531static int __init parse_lapic(char *arg)
1532{
1533 enable_local_apic = 1;
1534 return 0;
1535}
1536early_param("lapic", parse_lapic);
1537
1538static int __init parse_nolapic(char *arg)
1539{
1540 enable_local_apic = -1;
1541 clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
1542 return 0;
1543}
1544early_param("nolapic", parse_nolapic);
1545
1546static int __init parse_disable_lapic_timer(char *arg)
1547{
1548 local_apic_timer_disabled = 1;
1549 return 0;
1550}
1551early_param("nolapic_timer", parse_disable_lapic_timer);
1552
1553static int __init parse_lapic_timer_c2_ok(char *arg)
1554{
1555 local_apic_timer_c2_ok = 1;
1556 return 0;
1557}
1558early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok);
1559
1560static int __init apic_set_verbosity(char *str)
1561{
1562 if (strcmp("debug", str) == 0)
1563 apic_verbosity = APIC_DEBUG;
1564 else if (strcmp("verbose", str) == 0)
1565 apic_verbosity = APIC_VERBOSE;
1566 return 1;
1567}
1568__setup("apic=", apic_set_verbosity);
1569