blob: bfc6cb7df7e7ff0a3d00f48bc8221e37e3e54e0d [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;
Thomas Gleixnerad62ca22007-03-22 00:11:21 -080064/* Disable local APIC timer from the kernel commandline or via dmi quirk */
65static int local_apic_timer_disabled;
Thomas Gleixnere585bef2007-03-23 16:08:01 +010066/* Local APIC timer works in C2 */
67int local_apic_timer_c2_ok;
68EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok);
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080069
Eric W. Biederman9635b472005-06-25 14:57:41 -070070/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -080071 * Debug level, exported for io_apic.c
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
73int apic_verbosity;
74
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080075static unsigned int calibration_result;
76
77static int lapic_next_event(unsigned long delta,
78 struct clock_event_device *evt);
79static void lapic_timer_setup(enum clock_event_mode mode,
80 struct clock_event_device *evt);
81static void lapic_timer_broadcast(cpumask_t mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082static void apic_pm_activate(void);
83
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080084/*
85 * The local apic timer can be used for any function which is CPU local.
86 */
87static struct clock_event_device lapic_clockevent = {
88 .name = "lapic",
89 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -080090 | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY,
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -080091 .shift = 32,
92 .set_mode = lapic_timer_setup,
93 .set_next_event = lapic_next_event,
94 .broadcast = lapic_timer_broadcast,
95 .rating = 100,
96 .irq = -1,
97};
98static DEFINE_PER_CPU(struct clock_event_device, lapic_events);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800100/* Local APIC was disabled by the BIOS and enabled by the kernel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101static int enabled_via_apicbase;
102
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800103/*
104 * Get the LAPIC version
105 */
106static inline int lapic_get_version(void)
107{
108 return GET_APIC_VERSION(apic_read(APIC_LVR));
109}
110
111/*
112 * Check, if the APIC is integrated or a seperate chip
113 */
114static inline int lapic_is_integrated(void)
115{
116 return APIC_INTEGRATED(lapic_get_version());
117}
118
119/*
120 * Check, whether this is a modern or a first generation APIC
121 */
122static int modern_apic(void)
123{
124 /* AMD systems use old APIC versions, so check the CPU */
125 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
126 boot_cpu_data.x86 >= 0xf)
127 return 1;
128 return lapic_get_version() >= 0x14;
129}
130
Fernando Luis VazquezCaof2b218d2007-05-02 19:27:17 +0200131void apic_wait_icr_idle(void)
132{
133 while (apic_read(APIC_ICR) & APIC_ICR_BUSY)
134 cpu_relax();
135}
136
137unsigned long safe_apic_wait_icr_idle(void)
138{
139 unsigned long send_status;
140 int timeout;
141
142 timeout = 0;
143 do {
144 send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY;
145 if (!send_status)
146 break;
147 udelay(100);
148 } while (timeout++ < 1000);
149
150 return send_status;
151}
152
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800153/**
154 * enable_NMI_through_LVT0 - enable NMI through local vector table 0
155 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156void enable_NMI_through_LVT0 (void * dummy)
157{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800158 unsigned int v = APIC_DM_NMI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800160 /* Level triggered for 82489DX */
161 if (!lapic_is_integrated())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 v |= APIC_LVT_LEVEL_TRIGGER;
163 apic_write_around(APIC_LVT0, v);
164}
165
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800166/**
167 * get_physical_broadcast - Get number of physical broadcast IDs
168 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169int get_physical_broadcast(void)
170{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800171 return modern_apic() ? 0xff : 0xf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172}
173
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800174/**
175 * lapic_get_maxlvt - get the maximum number of local vector table entries
176 */
177int lapic_get_maxlvt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800179 unsigned int v = apic_read(APIC_LVR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 /* 82489DXs do not report # of LVT entries. */
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800182 return APIC_INTEGRATED(GET_APIC_VERSION(v)) ? GET_APIC_MAXLVT(v) : 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
185/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800186 * Local APIC timer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800189/* Clock divisor is set to 16 */
190#define APIC_DIVISOR 16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192/*
193 * This function sets up the local APIC timer, with a timeout of
194 * 'clocks' APIC bus clock. During calibration we actually call
195 * this function twice on the boot CPU, once with a bogus timeout
196 * value, second time for real. The other (noncalibrating) CPUs
197 * call this function only once, with the real, calibrated value.
198 *
199 * We do reads before writes even if unnecessary, to get around the
200 * P5 APIC double write bug.
201 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800202static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800204 unsigned int lvtt_value, tmp_value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800206 lvtt_value = LOCAL_TIMER_VECTOR;
207 if (!oneshot)
208 lvtt_value |= APIC_LVT_TIMER_PERIODIC;
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800209 if (!lapic_is_integrated())
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV);
Venkatesh Pallipadi6eb0a0f2006-01-11 22:44:21 +0100211
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800212 if (!irqen)
Venkatesh Pallipadi6eb0a0f2006-01-11 22:44:21 +0100213 lvtt_value |= APIC_LVT_MASKED;
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 apic_write_around(APIC_LVTT, lvtt_value);
216
217 /*
218 * Divide PICLK by 16
219 */
220 tmp_value = apic_read(APIC_TDCR);
221 apic_write_around(APIC_TDCR, (tmp_value
222 & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE))
223 | APIC_TDR_DIV_16);
224
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800225 if (!oneshot)
226 apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800229/*
230 * Program the next event, relative to now
231 */
232static int lapic_next_event(unsigned long delta,
233 struct clock_event_device *evt)
234{
235 apic_write_around(APIC_TMICT, delta);
236 return 0;
237}
238
239/*
240 * Setup the lapic timer in periodic or oneshot mode
241 */
242static void lapic_timer_setup(enum clock_event_mode mode,
243 struct clock_event_device *evt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 unsigned long flags;
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800246 unsigned int v;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800248 /* Lapic used for broadcast ? */
249 if (!local_apic_timer_verify_ok)
250 return;
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 local_irq_save(flags);
253
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800254 switch (mode) {
255 case CLOCK_EVT_MODE_PERIODIC:
256 case CLOCK_EVT_MODE_ONESHOT:
257 __setup_APIC_LVTT(calibration_result,
258 mode != CLOCK_EVT_MODE_PERIODIC, 1);
259 break;
260 case CLOCK_EVT_MODE_UNUSED:
261 case CLOCK_EVT_MODE_SHUTDOWN:
262 v = apic_read(APIC_LVTT);
263 v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
264 apic_write_around(APIC_LVTT, v);
265 break;
Thomas Gleixner18de5bc2007-07-21 04:37:34 -0700266 case CLOCK_EVT_MODE_RESUME:
267 /* Nothing to do here */
268 break;
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 local_irq_restore(flags);
272}
273
274/*
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800275 * Local APIC timer broadcast function
276 */
277static void lapic_timer_broadcast(cpumask_t mask)
278{
279#ifdef CONFIG_SMP
280 send_IPI_mask(mask, LOCAL_TIMER_VECTOR);
281#endif
282}
283
284/*
285 * Setup the local APIC timer for this CPU. Copy the initilized values
286 * of the boot CPU and register the clock event in the framework.
287 */
288static void __devinit setup_APIC_timer(void)
289{
290 struct clock_event_device *levt = &__get_cpu_var(lapic_events);
291
292 memcpy(levt, &lapic_clockevent, sizeof(*levt));
293 levt->cpumask = cpumask_of_cpu(smp_processor_id());
294
295 clockevents_register_device(levt);
296}
297
298/*
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800299 * In this functions we calibrate APIC bus clocks to the external timer.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 *
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800301 * We want to do the calibration only once since we want to have local timer
302 * irqs syncron. CPUs connected by the same APIC bus have the very same bus
303 * frequency.
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800304 *
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800305 * This was previously done by reading the PIT/HPET and waiting for a wrap
306 * around to find out, that a tick has elapsed. I have a box, where the PIT
307 * readout is broken, so it never gets out of the wait loop again. This was
308 * also reported by others.
309 *
310 * Monitoring the jiffies value is inaccurate and the clockevents
311 * infrastructure allows us to do a simple substitution of the interrupt
312 * handler.
313 *
314 * The calibration routine also uses the pm_timer when possible, as the PIT
315 * happens to run way too slow (factor 2.3 on my VAIO CoreDuo, which goes
316 * back to normal later in the boot process).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 */
318
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800319#define LAPIC_CAL_LOOPS (HZ/10)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Thomas Gleixnerf5352fd2007-07-21 17:11:32 +0200321static __initdata int lapic_cal_loops = -1;
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800322static __initdata long lapic_cal_t1, lapic_cal_t2;
323static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2;
324static __initdata unsigned long lapic_cal_pm1, lapic_cal_pm2;
325static __initdata unsigned long lapic_cal_j1, lapic_cal_j2;
326
327/*
328 * Temporary interrupt handler.
329 */
330static void __init lapic_cal_handler(struct clock_event_device *dev)
331{
332 unsigned long long tsc = 0;
333 long tapic = apic_read(APIC_TMCCT);
334 unsigned long pm = acpi_pm_read_early();
335
336 if (cpu_has_tsc)
337 rdtscll(tsc);
338
339 switch (lapic_cal_loops++) {
340 case 0:
341 lapic_cal_t1 = tapic;
342 lapic_cal_tsc1 = tsc;
343 lapic_cal_pm1 = pm;
344 lapic_cal_j1 = jiffies;
345 break;
346
347 case LAPIC_CAL_LOOPS:
348 lapic_cal_t2 = tapic;
349 lapic_cal_tsc2 = tsc;
350 if (pm < lapic_cal_pm1)
351 pm += ACPI_PM_OVRRUN;
352 lapic_cal_pm2 = pm;
353 lapic_cal_j2 = jiffies;
354 break;
355 }
356}
357
358/*
359 * Setup the boot APIC
360 *
361 * Calibrate and verify the result.
362 */
363void __init setup_boot_APIC_clock(void)
364{
365 struct clock_event_device *levt = &__get_cpu_var(lapic_events);
366 const long pm_100ms = PMTMR_TICKS_PER_SEC/10;
367 const long pm_thresh = pm_100ms/100;
368 void (*real_handler)(struct clock_event_device *dev);
369 unsigned long deltaj;
370 long delta, deltapm;
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800371 int pm_referenced = 0;
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800372
Andi Kleen3556ddf2007-04-02 12:14:12 +0200373 if (boot_cpu_has(X86_FEATURE_LAPIC_TIMER_BROKEN))
374 local_apic_timer_disabled = 1;
Thomas Gleixnerad62ca22007-03-22 00:11:21 -0800375
376 /*
377 * The local apic timer can be disabled via the kernel
Andi Kleen3556ddf2007-04-02 12:14:12 +0200378 * commandline or from the test above. Register the lapic
Thomas Gleixnerad62ca22007-03-22 00:11:21 -0800379 * timer as a dummy clock event source on SMP systems, so the
380 * broadcast mechanism is used. On UP systems simply ignore it.
381 */
382 if (local_apic_timer_disabled) {
383 /* No broadcast on UP ! */
384 if (num_possible_cpus() > 1)
385 setup_APIC_timer();
386 return;
387 }
388
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800389 apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n"
390 "calibrating APIC timer ...\n");
391
392 local_irq_disable();
393
394 /* Replace the global interrupt handler */
395 real_handler = global_clock_event->event_handler;
396 global_clock_event->event_handler = lapic_cal_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
398 /*
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800399 * Setup the APIC counter to 1e9. There is no way the lapic
400 * can underflow in the 100ms detection time frame
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800402 __setup_APIC_LVTT(1000000000, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800404 /* Let the interrupts run */
405 local_irq_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800407 while (lapic_cal_loops <= LAPIC_CAL_LOOPS)
408 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800410 local_irq_disable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800412 /* Restore the real event handler */
413 global_clock_event->event_handler = real_handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800415 /* Build delta t1-t2 as apic timer counts down */
416 delta = lapic_cal_t1 - lapic_cal_t2;
417 apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800419 /* Check, if the PM timer is available */
420 deltapm = lapic_cal_pm2 - lapic_cal_pm1;
421 apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800423 if (deltapm) {
424 unsigned long mult;
425 u64 res;
426
427 mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC, 22);
428
429 if (deltapm > (pm_100ms - pm_thresh) &&
430 deltapm < (pm_100ms + pm_thresh)) {
431 apic_printk(APIC_VERBOSE, "... PM timer result ok\n");
432 } else {
433 res = (((u64) deltapm) * mult) >> 22;
434 do_div(res, 1000000);
435 printk(KERN_WARNING "APIC calibration not consistent "
436 "with PM Timer: %ldms instead of 100ms\n",
437 (long)res);
438 /* Correct the lapic counter value */
439 res = (((u64) delta ) * pm_100ms);
440 do_div(res, deltapm);
441 printk(KERN_INFO "APIC delta adjusted to PM-Timer: "
442 "%lu (%ld)\n", (unsigned long) res, delta);
443 delta = (long) res;
444 }
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800445 pm_referenced = 1;
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800448 /* Calculate the scaled math multiplication factor */
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800449 lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS, 32);
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800450 lapic_clockevent.max_delta_ns =
451 clockevent_delta2ns(0x7FFFFF, &lapic_clockevent);
452 lapic_clockevent.min_delta_ns =
453 clockevent_delta2ns(0xF, &lapic_clockevent);
454
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800455 calibration_result = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS;
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800456
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800457 apic_printk(APIC_VERBOSE, "..... delta %ld\n", delta);
458 apic_printk(APIC_VERBOSE, "..... mult: %ld\n", lapic_clockevent.mult);
459 apic_printk(APIC_VERBOSE, "..... calibration result: %u\n",
460 calibration_result);
461
462 if (cpu_has_tsc) {
463 delta = (long)(lapic_cal_tsc2 - lapic_cal_tsc1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 apic_printk(APIC_VERBOSE, "..... CPU clock speed is "
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800465 "%ld.%04ld MHz.\n",
466 (delta / LAPIC_CAL_LOOPS) / (1000000 / HZ),
467 (delta / LAPIC_CAL_LOOPS) % (1000000 / HZ));
468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470 apic_printk(APIC_VERBOSE, "..... host bus clock speed is "
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800471 "%u.%04u MHz.\n",
472 calibration_result / (1000000 / HZ),
473 calibration_result % (1000000 / HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800475 local_apic_timer_verify_ok = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800477 /* We trust the pm timer based calibration */
478 if (!pm_referenced) {
479 apic_printk(APIC_VERBOSE, "... verify APIC timer\n");
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800480
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800481 /*
482 * Setup the apic timer manually
483 */
484 levt->event_handler = lapic_cal_handler;
485 lapic_timer_setup(CLOCK_EVT_MODE_PERIODIC, levt);
486 lapic_cal_loops = -1;
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800487
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800488 /* Let the interrupts run */
489 local_irq_enable();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800490
Thomas Gleixnerf5352fd2007-07-21 17:11:32 +0200491 while (lapic_cal_loops <= LAPIC_CAL_LOOPS)
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800492 cpu_relax();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800493
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800494 local_irq_disable();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800495
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800496 /* Stop the lapic timer */
497 lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt);
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800498
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800499 local_irq_enable();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800500
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800501 /* Jiffies delta */
502 deltaj = lapic_cal_j2 - lapic_cal_j1;
503 apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj);
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800504
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800505 /* Check, if the jiffies result is consistent */
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800506 if (deltaj >= LAPIC_CAL_LOOPS-2 && deltaj <= LAPIC_CAL_LOOPS+2)
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800507 apic_printk(APIC_VERBOSE, "... jiffies result ok\n");
Thomas Gleixnerca1b9402007-03-18 01:26:13 -0800508 else
509 local_apic_timer_verify_ok = 0;
Ingo Molnar4edc5db2007-03-22 10:31:19 +0100510 } else
511 local_irq_enable();
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800512
513 if (!local_apic_timer_verify_ok) {
514 printk(KERN_WARNING
515 "APIC timer disabled due to verification failure.\n");
516 /* No broadcast on UP ! */
517 if (num_possible_cpus() == 1)
518 return;
Thomas Gleixnera5f5e432007-03-05 00:30:45 -0800519 } else {
520 /*
521 * If nmi_watchdog is set to IO_APIC, we need the
522 * PIT/HPET going. Otherwise register lapic as a dummy
523 * device.
524 */
525 if (nmi_watchdog != NMI_IO_APIC)
526 lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY;
Ingo Molnar820de5c2007-07-21 04:37:36 -0700527 else
528 printk(KERN_WARNING "APIC timer registered as dummy,"
529 " due to nmi_watchdog=1!\n");
Thomas Gleixnera5f5e432007-03-05 00:30:45 -0800530 }
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800531
532 /* Setup the lapic or request the broadcast */
533 setup_APIC_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534}
535
Li Shaohua0bb31842005-06-25 14:54:55 -0700536void __devinit setup_secondary_APIC_clock(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800538 setup_APIC_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539}
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541/*
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800542 * The guts of the apic timer interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800544static void local_apic_timer_interrupt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800546 int cpu = smp_processor_id();
547 struct clock_event_device *evt = &per_cpu(lapic_events, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 /*
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800550 * Normally we should not be here till LAPIC has been initialized but
551 * in some cases like kdump, its possible that there is a pending LAPIC
552 * timer interrupt from previous kernel's context and is delivered in
553 * new kernel the moment interrupts are enabled.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 *
Thomas Gleixnerd36b49b2007-02-16 01:28:06 -0800555 * Interrupts are enabled early and LAPIC is setup much later, hence
556 * its possible that when we get here evt->event_handler is NULL.
557 * Check for event_handler being NULL and discard the interrupt as
558 * spurious.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800560 if (!evt->event_handler) {
561 printk(KERN_WARNING
562 "Spurious LAPIC timer interrupt on cpu %d\n", cpu);
563 /* Switch it off */
564 lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt);
565 return;
566 }
567
568 per_cpu(irq_stat, cpu).apic_timer_irqs++;
569
570 evt->event_handler(evt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571}
572
573/*
574 * Local APIC timer interrupt. This is the most natural way for doing
575 * local interrupts, but local timer interrupts can be emulated by
576 * broadcast interrupts too. [in case the hw doesn't support APIC timers]
577 *
578 * [ if a single-CPU system runs an SMP kernel then we call the local
579 * interrupt as well. Thus we cannot inline the local irq ... ]
580 */
581
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800582void fastcall smp_apic_timer_interrupt(struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583{
David Howells7d12e782006-10-05 14:55:46 +0100584 struct pt_regs *old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 /*
587 * NOTE! We'd better ACK the irq immediately,
588 * because timer handling can be slow.
589 */
590 ack_APIC_irq();
591 /*
592 * update_process_times() expects us to have done irq_enter().
593 * Besides, if we don't timer interrupts ignore the global
594 * interrupt lock, which is the WrongThing (tm) to do.
595 */
596 irq_enter();
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800597 local_apic_timer_interrupt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 irq_exit();
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -0800599
David Howells7d12e782006-10-05 14:55:46 +0100600 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
Venkatesh Pallipadi5a07a302006-01-11 22:44:18 +0100603int setup_profiling_timer(unsigned int multiplier)
604{
605 return -EINVAL;
606}
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800609 * Local APIC start and shutdown
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800611
612/**
613 * clear_local_APIC - shutdown the local APIC
614 *
615 * This is called, when a CPU is disabled and before rebooting, so the state of
616 * the local APIC has no dangling leftovers. Also used to cleanout any BIOS
617 * leftovers during boot.
618 */
619void clear_local_APIC(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800621 int maxlvt = lapic_get_maxlvt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 unsigned long v;
623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 /*
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800625 * Masking an LVT entry can trigger a local APIC error
626 * if the vector is zero. Mask LVTERR first to prevent this.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800628 if (maxlvt >= 3) {
629 v = ERROR_APIC_VECTOR; /* any non-zero vector will do */
630 apic_write_around(APIC_LVTERR, v | APIC_LVT_MASKED);
631 }
632 /*
633 * Careful: we have to set masks only first to deassert
634 * any level-triggered sources.
635 */
636 v = apic_read(APIC_LVTT);
637 apic_write_around(APIC_LVTT, v | APIC_LVT_MASKED);
638 v = apic_read(APIC_LVT0);
639 apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);
640 v = apic_read(APIC_LVT1);
641 apic_write_around(APIC_LVT1, v | APIC_LVT_MASKED);
642 if (maxlvt >= 4) {
643 v = apic_read(APIC_LVTPC);
644 apic_write_around(APIC_LVTPC, v | APIC_LVT_MASKED);
645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800647 /* lets not touch this if we didn't frob it */
648#ifdef CONFIG_X86_MCE_P4THERMAL
649 if (maxlvt >= 5) {
650 v = apic_read(APIC_LVTTHMR);
651 apic_write_around(APIC_LVTTHMR, v | APIC_LVT_MASKED);
652 }
653#endif
654 /*
655 * Clean APIC state for other OSs:
656 */
657 apic_write_around(APIC_LVTT, APIC_LVT_MASKED);
658 apic_write_around(APIC_LVT0, APIC_LVT_MASKED);
659 apic_write_around(APIC_LVT1, APIC_LVT_MASKED);
660 if (maxlvt >= 3)
661 apic_write_around(APIC_LVTERR, APIC_LVT_MASKED);
662 if (maxlvt >= 4)
663 apic_write_around(APIC_LVTPC, APIC_LVT_MASKED);
664
665#ifdef CONFIG_X86_MCE_P4THERMAL
666 if (maxlvt >= 5)
667 apic_write_around(APIC_LVTTHMR, APIC_LVT_MASKED);
668#endif
669 /* Integrated APIC (!82489DX) ? */
670 if (lapic_is_integrated()) {
671 if (maxlvt > 3)
672 /* Clear ESR due to Pentium errata 3AP and 11AP */
673 apic_write(APIC_ESR, 0);
674 apic_read(APIC_ESR);
675 }
676}
677
678/**
679 * disable_local_APIC - clear and disable the local APIC
680 */
681void disable_local_APIC(void)
682{
683 unsigned long value;
684
685 clear_local_APIC();
686
687 /*
688 * Disable APIC (implies clearing of registers
689 * for 82489DX!).
690 */
691 value = apic_read(APIC_SPIV);
692 value &= ~APIC_SPIV_APIC_ENABLED;
693 apic_write_around(APIC_SPIV, value);
694
695 /*
696 * When LAPIC was disabled by the BIOS and enabled by the kernel,
697 * restore the disabled state.
698 */
699 if (enabled_via_apicbase) {
700 unsigned int l, h;
701
702 rdmsr(MSR_IA32_APICBASE, l, h);
703 l &= ~MSR_IA32_APICBASE_ENABLE;
704 wrmsr(MSR_IA32_APICBASE, l, h);
705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706}
707
708/*
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800709 * If Linux enabled the LAPIC against the BIOS default disable it down before
710 * re-entering the BIOS on shutdown. Otherwise the BIOS may get confused and
711 * not power-off. Additionally clear all LVT entries before disable_local_APIC
712 * for the case where Linux didn't enable the LAPIC.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800714void lapic_shutdown(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800716 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800718 if (!cpu_has_apic)
719 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Thomas Gleixnere05d7232007-02-16 01:27:58 -0800721 local_irq_save(flags);
722 clear_local_APIC();
723
724 if (enabled_via_apicbase)
725 disable_local_APIC();
726
727 local_irq_restore(flags);
728}
729
730/*
731 * This is to verify that we're looking at a real local APIC.
732 * Check these against your board if the CPUs aren't getting
733 * started for no apparent reason.
734 */
735int __init verify_local_APIC(void)
736{
737 unsigned int reg0, reg1;
738
739 /*
740 * The version register is read-only in a real APIC.
741 */
742 reg0 = apic_read(APIC_LVR);
743 apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0);
744 apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK);
745 reg1 = apic_read(APIC_LVR);
746 apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1);
747
748 /*
749 * The two version reads above should print the same
750 * numbers. If the second one is different, then we
751 * poke at a non-APIC.
752 */
753 if (reg1 != reg0)
754 return 0;
755
756 /*
757 * Check if the version looks reasonably.
758 */
759 reg1 = GET_APIC_VERSION(reg0);
760 if (reg1 == 0x00 || reg1 == 0xff)
761 return 0;
762 reg1 = lapic_get_maxlvt();
763 if (reg1 < 0x02 || reg1 == 0xff)
764 return 0;
765
766 /*
767 * The ID register is read/write in a real APIC.
768 */
769 reg0 = apic_read(APIC_ID);
770 apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0);
771
772 /*
773 * The next two are just to see if we have sane values.
774 * They're only really relevant if we're in Virtual Wire
775 * compatibility mode, but most boxes are anymore.
776 */
777 reg0 = apic_read(APIC_LVT0);
778 apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0);
779 reg1 = apic_read(APIC_LVT1);
780 apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1);
781
782 return 1;
783}
784
785/**
786 * sync_Arb_IDs - synchronize APIC bus arbitration IDs
787 */
788void __init sync_Arb_IDs(void)
789{
790 /*
791 * Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 And not
792 * needed on AMD.
793 */
794 if (modern_apic())
795 return;
796 /*
797 * Wait for idle.
798 */
799 apic_wait_icr_idle();
800
801 apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n");
802 apic_write_around(APIC_ICR, APIC_DEST_ALLINC | APIC_INT_LEVELTRIG
803 | APIC_DM_INIT);
804}
805
806/*
807 * An initial setup of the virtual wire mode.
808 */
809void __init init_bsp_APIC(void)
810{
811 unsigned long value;
812
813 /*
814 * Don't do the setup now if we have a SMP BIOS as the
815 * through-I/O-APIC virtual wire mode might be active.
816 */
817 if (smp_found_config || !cpu_has_apic)
818 return;
819
820 /*
821 * Do not trust the local APIC being empty at bootup.
822 */
823 clear_local_APIC();
824
825 /*
826 * Enable APIC.
827 */
828 value = apic_read(APIC_SPIV);
829 value &= ~APIC_VECTOR_MASK;
830 value |= APIC_SPIV_APIC_ENABLED;
831
832 /* This bit is reserved on P4/Xeon and should be cleared */
833 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
834 (boot_cpu_data.x86 == 15))
835 value &= ~APIC_SPIV_FOCUS_DISABLED;
836 else
837 value |= APIC_SPIV_FOCUS_DISABLED;
838 value |= SPURIOUS_APIC_VECTOR;
839 apic_write_around(APIC_SPIV, value);
840
841 /*
842 * Set up the virtual wire mode.
843 */
844 apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
845 value = APIC_DM_NMI;
846 if (!lapic_is_integrated()) /* 82489DX */
847 value |= APIC_LVT_LEVEL_TRIGGER;
848 apic_write_around(APIC_LVT1, value);
849}
850
851/**
852 * setup_local_APIC - setup the local APIC
853 */
854void __devinit setup_local_APIC(void)
855{
856 unsigned long oldvalue, value, maxlvt, integrated;
857 int i, j;
858
859 /* Pound the ESR really hard over the head with a big hammer - mbligh */
860 if (esr_disable) {
861 apic_write(APIC_ESR, 0);
862 apic_write(APIC_ESR, 0);
863 apic_write(APIC_ESR, 0);
864 apic_write(APIC_ESR, 0);
865 }
866
867 integrated = lapic_is_integrated();
868
869 /*
870 * Double-check whether this APIC is really registered.
871 */
872 if (!apic_id_registered())
873 BUG();
874
875 /*
876 * Intel recommends to set DFR, LDR and TPR before enabling
877 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
878 * document number 292116). So here it goes...
879 */
880 init_apic_ldr();
881
882 /*
883 * Set Task Priority to 'accept all'. We never change this
884 * later on.
885 */
886 value = apic_read(APIC_TASKPRI);
887 value &= ~APIC_TPRI_MASK;
888 apic_write_around(APIC_TASKPRI, value);
889
890 /*
891 * After a crash, we no longer service the interrupts and a pending
892 * interrupt from previous kernel might still have ISR bit set.
893 *
894 * Most probably by now CPU has serviced that pending interrupt and
895 * it might not have done the ack_APIC_irq() because it thought,
896 * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it
897 * does not clear the ISR bit and cpu thinks it has already serivced
898 * the interrupt. Hence a vector might get locked. It was noticed
899 * for timer irq (vector 0x31). Issue an extra EOI to clear ISR.
900 */
901 for (i = APIC_ISR_NR - 1; i >= 0; i--) {
902 value = apic_read(APIC_ISR + i*0x10);
903 for (j = 31; j >= 0; j--) {
904 if (value & (1<<j))
905 ack_APIC_irq();
906 }
907 }
908
909 /*
910 * Now that we are all set up, enable the APIC
911 */
912 value = apic_read(APIC_SPIV);
913 value &= ~APIC_VECTOR_MASK;
914 /*
915 * Enable APIC
916 */
917 value |= APIC_SPIV_APIC_ENABLED;
918
919 /*
920 * Some unknown Intel IO/APIC (or APIC) errata is biting us with
921 * certain networking cards. If high frequency interrupts are
922 * happening on a particular IOAPIC pin, plus the IOAPIC routing
923 * entry is masked/unmasked at a high rate as well then sooner or
924 * later IOAPIC line gets 'stuck', no more interrupts are received
925 * from the device. If focus CPU is disabled then the hang goes
926 * away, oh well :-(
927 *
928 * [ This bug can be reproduced easily with a level-triggered
929 * PCI Ne2000 networking cards and PII/PIII processors, dual
930 * BX chipset. ]
931 */
932 /*
933 * Actually disabling the focus CPU check just makes the hang less
934 * frequent as it makes the interrupt distributon model be more
935 * like LRU than MRU (the short-term load is more even across CPUs).
936 * See also the comment in end_level_ioapic_irq(). --macro
937 */
938
939 /* Enable focus processor (bit==0) */
940 value &= ~APIC_SPIV_FOCUS_DISABLED;
941
942 /*
943 * Set spurious IRQ vector
944 */
945 value |= SPURIOUS_APIC_VECTOR;
946 apic_write_around(APIC_SPIV, value);
947
948 /*
949 * Set up LVT0, LVT1:
950 *
951 * set up through-local-APIC on the BP's LINT0. This is not
952 * strictly necessery in pure symmetric-IO mode, but sometimes
953 * we delegate interrupts to the 8259A.
954 */
955 /*
956 * TODO: set up through-local-APIC from through-I/O-APIC? --macro
957 */
958 value = apic_read(APIC_LVT0) & APIC_LVT_MASKED;
959 if (!smp_processor_id() && (pic_mode || !value)) {
960 value = APIC_DM_EXTINT;
961 apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n",
962 smp_processor_id());
963 } else {
964 value = APIC_DM_EXTINT | APIC_LVT_MASKED;
965 apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n",
966 smp_processor_id());
967 }
968 apic_write_around(APIC_LVT0, value);
969
970 /*
971 * only the BP should see the LINT1 NMI signal, obviously.
972 */
973 if (!smp_processor_id())
974 value = APIC_DM_NMI;
975 else
976 value = APIC_DM_NMI | APIC_LVT_MASKED;
977 if (!integrated) /* 82489DX */
978 value |= APIC_LVT_LEVEL_TRIGGER;
979 apic_write_around(APIC_LVT1, value);
980
981 if (integrated && !esr_disable) { /* !82489DX */
982 maxlvt = lapic_get_maxlvt();
983 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
984 apic_write(APIC_ESR, 0);
985 oldvalue = apic_read(APIC_ESR);
986
987 /* enables sending errors */
988 value = ERROR_APIC_VECTOR;
989 apic_write_around(APIC_LVTERR, value);
990 /*
991 * spec says clear errors after enabling vector.
992 */
993 if (maxlvt > 3)
994 apic_write(APIC_ESR, 0);
995 value = apic_read(APIC_ESR);
996 if (value != oldvalue)
997 apic_printk(APIC_VERBOSE, "ESR value before enabling "
998 "vector: 0x%08lx after: 0x%08lx\n",
999 oldvalue, value);
1000 } else {
1001 if (esr_disable)
1002 /*
1003 * Something untraceble is creating bad interrupts on
1004 * secondary quads ... for the moment, just leave the
1005 * ESR disabled - we can't do anything useful with the
1006 * errors anyway - mbligh
1007 */
1008 printk(KERN_INFO "Leaving ESR disabled.\n");
1009 else
1010 printk(KERN_INFO "No ESR for 82489DX.\n");
1011 }
1012
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -08001013 /* Disable the local apic timer */
1014 value = apic_read(APIC_LVTT);
1015 value |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR);
1016 apic_write_around(APIC_LVTT, value);
1017
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001018 setup_apic_nmi_watchdog(NULL);
1019 apic_pm_activate();
1020}
1021
1022/*
1023 * Detect and initialize APIC
1024 */
1025static int __init detect_init_APIC (void)
1026{
1027 u32 h, l, features;
1028
1029 /* Disabled by kernel option? */
1030 if (enable_local_apic < 0)
1031 return -1;
1032
1033 switch (boot_cpu_data.x86_vendor) {
1034 case X86_VENDOR_AMD:
1035 if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model > 1) ||
1036 (boot_cpu_data.x86 == 15))
1037 break;
1038 goto no_apic;
1039 case X86_VENDOR_INTEL:
1040 if (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15 ||
1041 (boot_cpu_data.x86 == 5 && cpu_has_apic))
1042 break;
1043 goto no_apic;
1044 default:
1045 goto no_apic;
1046 }
1047
1048 if (!cpu_has_apic) {
1049 /*
1050 * Over-ride BIOS and try to enable the local APIC only if
1051 * "lapic" specified.
1052 */
1053 if (enable_local_apic <= 0) {
1054 printk(KERN_INFO "Local APIC disabled by BIOS -- "
1055 "you can enable it with \"lapic\"\n");
1056 return -1;
1057 }
1058 /*
1059 * Some BIOSes disable the local APIC in the APIC_BASE
1060 * MSR. This can only be done in software for Intel P6 or later
1061 * and AMD K7 (Model > 1) or later.
1062 */
1063 rdmsr(MSR_IA32_APICBASE, l, h);
1064 if (!(l & MSR_IA32_APICBASE_ENABLE)) {
1065 printk(KERN_INFO
1066 "Local APIC disabled by BIOS -- reenabling.\n");
1067 l &= ~MSR_IA32_APICBASE_BASE;
1068 l |= MSR_IA32_APICBASE_ENABLE | APIC_DEFAULT_PHYS_BASE;
1069 wrmsr(MSR_IA32_APICBASE, l, h);
1070 enabled_via_apicbase = 1;
1071 }
1072 }
1073 /*
1074 * The APIC feature bit should now be enabled
1075 * in `cpuid'
1076 */
1077 features = cpuid_edx(1);
1078 if (!(features & (1 << X86_FEATURE_APIC))) {
1079 printk(KERN_WARNING "Could not enable APIC!\n");
1080 return -1;
1081 }
1082 set_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
1083 mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
1084
1085 /* The BIOS may have set up the APIC at some other address */
1086 rdmsr(MSR_IA32_APICBASE, l, h);
1087 if (l & MSR_IA32_APICBASE_ENABLE)
1088 mp_lapic_addr = l & MSR_IA32_APICBASE_BASE;
1089
1090 if (nmi_watchdog != NMI_NONE)
1091 nmi_watchdog = NMI_LOCAL_APIC;
1092
1093 printk(KERN_INFO "Found and enabled local APIC!\n");
1094
1095 apic_pm_activate();
1096
1097 return 0;
1098
1099no_apic:
1100 printk(KERN_INFO "No local APIC present or hardware disabled\n");
1101 return -1;
1102}
1103
1104/**
1105 * init_apic_mappings - initialize APIC mappings
1106 */
1107void __init init_apic_mappings(void)
1108{
1109 unsigned long apic_phys;
1110
1111 /*
1112 * If no local APIC can be found then set up a fake all
1113 * zeroes page to simulate the local APIC and another
1114 * one for the IO-APIC.
1115 */
1116 if (!smp_found_config && detect_init_APIC()) {
1117 apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
1118 apic_phys = __pa(apic_phys);
1119 } else
1120 apic_phys = mp_lapic_addr;
1121
1122 set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
1123 printk(KERN_DEBUG "mapped APIC to %08lx (%08lx)\n", APIC_BASE,
1124 apic_phys);
1125
1126 /*
1127 * Fetch the APIC ID of the BSP in case we have a
1128 * default configuration (or the MP table is broken).
1129 */
1130 if (boot_cpu_physical_apicid == -1U)
1131 boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
1132
1133#ifdef CONFIG_X86_IO_APIC
1134 {
1135 unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
1136 int i;
1137
1138 for (i = 0; i < nr_ioapics; i++) {
1139 if (smp_found_config) {
1140 ioapic_phys = mp_ioapics[i].mpc_apicaddr;
1141 if (!ioapic_phys) {
1142 printk(KERN_ERR
1143 "WARNING: bogus zero IO-APIC "
1144 "address found in MPTABLE, "
1145 "disabling IO/APIC support!\n");
1146 smp_found_config = 0;
1147 skip_ioapic_setup = 1;
1148 goto fake_ioapic_page;
1149 }
1150 } else {
1151fake_ioapic_page:
1152 ioapic_phys = (unsigned long)
1153 alloc_bootmem_pages(PAGE_SIZE);
1154 ioapic_phys = __pa(ioapic_phys);
1155 }
1156 set_fixmap_nocache(idx, ioapic_phys);
1157 printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
1158 __fix_to_virt(idx), ioapic_phys);
1159 idx++;
1160 }
1161 }
1162#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
1165/*
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001166 * This initializes the IO-APIC and APIC hardware if this is
1167 * a UP kernel.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 */
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001169int __init APIC_init_uniprocessor (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170{
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001171 if (enable_local_apic < 0)
1172 clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
Eric W. Biedermanf2b36db2005-10-30 14:59:41 -08001173
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001174 if (!smp_found_config && !cpu_has_apic)
Eric W. Biedermanf2b36db2005-10-30 14:59:41 -08001175 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 /*
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001178 * Complain if the BIOS pretends there is one.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 */
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001180 if (!cpu_has_apic &&
1181 APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001183 boot_cpu_physical_apicid);
Andi Kleen3777a952006-02-03 21:51:53 +01001184 clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 return -1;
1186 }
1187
1188 verify_local_APIC();
1189
1190 connect_bsp_APIC();
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001191
Vivek Goyalbe0d03f2006-05-20 15:00:21 -07001192 /*
1193 * Hack: In case of kdump, after a crash, kernel might be booting
1194 * on a cpu with non-zero lapic id. But boot_cpu_physical_apicid
1195 * might be zero if read from MP tables. Get it from LAPIC.
1196 */
1197#ifdef CONFIG_CRASH_DUMP
1198 boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
1199#endif
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001200 phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
1201
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 setup_local_APIC();
1203
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204#ifdef CONFIG_X86_IO_APIC
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001205 if (smp_found_config)
1206 if (!skip_ioapic_setup && nr_ioapics)
1207 setup_IO_APIC();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208#endif
Zachary Amsdenbbab4f32007-02-13 13:26:21 +01001209 setup_boot_clock();
Linus Torvalds1e4c85f2005-10-31 19:16:17 -08001210
1211 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
Rusty Russell1a3f2392006-09-26 10:52:32 +02001213
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001214/*
1215 * APIC command line parameters
1216 */
Rusty Russell1a3f2392006-09-26 10:52:32 +02001217static int __init parse_lapic(char *arg)
1218{
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001219 enable_local_apic = 1;
Rusty Russell1a3f2392006-09-26 10:52:32 +02001220 return 0;
1221}
1222early_param("lapic", parse_lapic);
1223
1224static int __init parse_nolapic(char *arg)
1225{
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001226 enable_local_apic = -1;
1227 clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability);
Rusty Russell1a3f2392006-09-26 10:52:32 +02001228 return 0;
1229}
1230early_param("nolapic", parse_nolapic);
1231
Thomas Gleixnerad62ca22007-03-22 00:11:21 -08001232static int __init parse_disable_lapic_timer(char *arg)
1233{
1234 local_apic_timer_disabled = 1;
1235 return 0;
1236}
1237early_param("nolapic_timer", parse_disable_lapic_timer);
1238
Thomas Gleixnere585bef2007-03-23 16:08:01 +01001239static int __init parse_lapic_timer_c2_ok(char *arg)
1240{
1241 local_apic_timer_c2_ok = 1;
1242 return 0;
1243}
1244early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok);
1245
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001246static int __init apic_set_verbosity(char *str)
1247{
1248 if (strcmp("debug", str) == 0)
1249 apic_verbosity = APIC_DEBUG;
1250 else if (strcmp("verbose", str) == 0)
1251 apic_verbosity = APIC_VERBOSE;
1252 return 1;
1253}
1254
1255__setup("apic=", apic_set_verbosity);
1256
1257
1258/*
1259 * Local APIC interrupts
1260 */
1261
1262/*
1263 * This interrupt should _never_ happen with our APIC/SMP architecture
1264 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -08001265void smp_spurious_interrupt(struct pt_regs *regs)
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001266{
1267 unsigned long v;
1268
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001269 irq_enter();
1270 /*
1271 * Check if this really is a spurious interrupt and ACK it
1272 * if it is a vectored one. Just in case...
1273 * Spurious interrupts should not be ACKed.
1274 */
1275 v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1));
1276 if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f)))
1277 ack_APIC_irq();
1278
1279 /* see sw-dev-man vol 3, chapter 7.4.13.5 */
1280 printk(KERN_INFO "spurious APIC interrupt on CPU#%d, "
1281 "should never happen.\n", smp_processor_id());
1282 irq_exit();
1283}
1284
1285/*
1286 * This interrupt should never happen with our APIC/SMP architecture
1287 */
Thomas Gleixnere9e2cdb2007-02-16 01:28:04 -08001288void smp_error_interrupt(struct pt_regs *regs)
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001289{
1290 unsigned long v, v1;
1291
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001292 irq_enter();
1293 /* First tickle the hardware, only then report what went on. -- REW */
1294 v = apic_read(APIC_ESR);
1295 apic_write(APIC_ESR, 0);
1296 v1 = apic_read(APIC_ESR);
1297 ack_APIC_irq();
1298 atomic_inc(&irq_err_count);
1299
1300 /* Here is what the APIC error bits mean:
1301 0: Send CS error
1302 1: Receive CS error
1303 2: Send accept error
1304 3: Receive accept error
1305 4: Reserved
1306 5: Send illegal vector
1307 6: Received illegal vector
1308 7: Illegal register address
1309 */
1310 printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n",
1311 smp_processor_id(), v , v1);
1312 irq_exit();
1313}
1314
1315/*
1316 * Initialize APIC interrupts
1317 */
1318void __init apic_intr_init(void)
1319{
1320#ifdef CONFIG_SMP
1321 smp_intr_init();
1322#endif
1323 /* self generated IPI for local APIC timer */
1324 set_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
1325
1326 /* IPI vectors for APIC spurious and error interrupts */
1327 set_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
1328 set_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
1329
1330 /* thermal monitor LVT interrupt */
1331#ifdef CONFIG_X86_MCE_P4THERMAL
1332 set_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
1333#endif
1334}
1335
1336/**
1337 * connect_bsp_APIC - attach the APIC to the interrupt system
1338 */
1339void __init connect_bsp_APIC(void)
1340{
1341 if (pic_mode) {
1342 /*
1343 * Do not trust the local APIC being empty at bootup.
1344 */
1345 clear_local_APIC();
1346 /*
1347 * PIC mode, enable APIC mode in the IMCR, i.e. connect BSP's
1348 * local APIC to INT and NMI lines.
1349 */
1350 apic_printk(APIC_VERBOSE, "leaving PIC mode, "
1351 "enabling APIC mode.\n");
1352 outb(0x70, 0x22);
1353 outb(0x01, 0x23);
1354 }
1355 enable_apic_mode();
1356}
1357
1358/**
1359 * disconnect_bsp_APIC - detach the APIC from the interrupt system
1360 * @virt_wire_setup: indicates, whether virtual wire mode is selected
1361 *
1362 * Virtual wire mode is necessary to deliver legacy interrupts even when the
1363 * APIC is disabled.
1364 */
1365void disconnect_bsp_APIC(int virt_wire_setup)
1366{
1367 if (pic_mode) {
1368 /*
1369 * Put the board back into PIC mode (has an effect only on
1370 * certain older boards). Note that APIC interrupts, including
1371 * IPIs, won't work beyond this point! The only exception are
1372 * INIT IPIs.
1373 */
1374 apic_printk(APIC_VERBOSE, "disabling APIC mode, "
1375 "entering PIC mode.\n");
1376 outb(0x70, 0x22);
1377 outb(0x00, 0x23);
1378 } else {
1379 /* Go back to Virtual Wire compatibility mode */
1380 unsigned long value;
1381
1382 /* For the spurious interrupt use vector F, and enable it */
1383 value = apic_read(APIC_SPIV);
1384 value &= ~APIC_VECTOR_MASK;
1385 value |= APIC_SPIV_APIC_ENABLED;
1386 value |= 0xf;
1387 apic_write_around(APIC_SPIV, value);
1388
1389 if (!virt_wire_setup) {
1390 /*
1391 * For LVT0 make it edge triggered, active high,
1392 * external and enabled
1393 */
1394 value = apic_read(APIC_LVT0);
1395 value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING |
1396 APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
1397 APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED );
1398 value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
1399 value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT);
1400 apic_write_around(APIC_LVT0, value);
1401 } else {
1402 /* Disable LVT0 */
1403 apic_write_around(APIC_LVT0, APIC_LVT_MASKED);
1404 }
1405
1406 /*
1407 * For LVT1 make it edge triggered, active high, nmi and
1408 * enabled
1409 */
1410 value = apic_read(APIC_LVT1);
1411 value &= ~(
1412 APIC_MODE_MASK | APIC_SEND_PENDING |
1413 APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR |
1414 APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED);
1415 value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING;
1416 value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI);
1417 apic_write_around(APIC_LVT1, value);
1418 }
1419}
1420
1421/*
1422 * Power management
1423 */
1424#ifdef CONFIG_PM
1425
1426static struct {
1427 int active;
1428 /* r/w apic fields */
1429 unsigned int apic_id;
1430 unsigned int apic_taskpri;
1431 unsigned int apic_ldr;
1432 unsigned int apic_dfr;
1433 unsigned int apic_spiv;
1434 unsigned int apic_lvtt;
1435 unsigned int apic_lvtpc;
1436 unsigned int apic_lvt0;
1437 unsigned int apic_lvt1;
1438 unsigned int apic_lvterr;
1439 unsigned int apic_tmict;
1440 unsigned int apic_tdcr;
1441 unsigned int apic_thmr;
1442} apic_pm_state;
1443
1444static int lapic_suspend(struct sys_device *dev, pm_message_t state)
1445{
1446 unsigned long flags;
1447 int maxlvt;
1448
1449 if (!apic_pm_state.active)
1450 return 0;
1451
1452 maxlvt = lapic_get_maxlvt();
1453
1454 apic_pm_state.apic_id = apic_read(APIC_ID);
1455 apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI);
1456 apic_pm_state.apic_ldr = apic_read(APIC_LDR);
1457 apic_pm_state.apic_dfr = apic_read(APIC_DFR);
1458 apic_pm_state.apic_spiv = apic_read(APIC_SPIV);
1459 apic_pm_state.apic_lvtt = apic_read(APIC_LVTT);
1460 if (maxlvt >= 4)
1461 apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC);
1462 apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0);
1463 apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1);
1464 apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR);
1465 apic_pm_state.apic_tmict = apic_read(APIC_TMICT);
1466 apic_pm_state.apic_tdcr = apic_read(APIC_TDCR);
1467#ifdef CONFIG_X86_MCE_P4THERMAL
1468 if (maxlvt >= 5)
1469 apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR);
1470#endif
1471
1472 local_irq_save(flags);
1473 disable_local_APIC();
1474 local_irq_restore(flags);
1475 return 0;
1476}
1477
1478static int lapic_resume(struct sys_device *dev)
1479{
1480 unsigned int l, h;
1481 unsigned long flags;
1482 int maxlvt;
1483
1484 if (!apic_pm_state.active)
1485 return 0;
1486
1487 maxlvt = lapic_get_maxlvt();
1488
1489 local_irq_save(flags);
1490
1491 /*
1492 * Make sure the APICBASE points to the right address
1493 *
1494 * FIXME! This will be wrong if we ever support suspend on
1495 * SMP! We'll need to do this as part of the CPU restore!
1496 */
1497 rdmsr(MSR_IA32_APICBASE, l, h);
1498 l &= ~MSR_IA32_APICBASE_BASE;
1499 l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr;
1500 wrmsr(MSR_IA32_APICBASE, l, h);
1501
1502 apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED);
1503 apic_write(APIC_ID, apic_pm_state.apic_id);
1504 apic_write(APIC_DFR, apic_pm_state.apic_dfr);
1505 apic_write(APIC_LDR, apic_pm_state.apic_ldr);
1506 apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri);
1507 apic_write(APIC_SPIV, apic_pm_state.apic_spiv);
1508 apic_write(APIC_LVT0, apic_pm_state.apic_lvt0);
1509 apic_write(APIC_LVT1, apic_pm_state.apic_lvt1);
1510#ifdef CONFIG_X86_MCE_P4THERMAL
1511 if (maxlvt >= 5)
1512 apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr);
1513#endif
1514 if (maxlvt >= 4)
1515 apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc);
1516 apic_write(APIC_LVTT, apic_pm_state.apic_lvtt);
1517 apic_write(APIC_TDCR, apic_pm_state.apic_tdcr);
1518 apic_write(APIC_TMICT, apic_pm_state.apic_tmict);
1519 apic_write(APIC_ESR, 0);
1520 apic_read(APIC_ESR);
1521 apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr);
1522 apic_write(APIC_ESR, 0);
1523 apic_read(APIC_ESR);
1524 local_irq_restore(flags);
1525 return 0;
1526}
1527
1528/*
1529 * This device has no shutdown method - fully functioning local APICs
1530 * are needed on every CPU up until machine_halt/restart/poweroff.
1531 */
1532
1533static struct sysdev_class lapic_sysclass = {
1534 set_kset_name("lapic"),
1535 .resume = lapic_resume,
1536 .suspend = lapic_suspend,
1537};
1538
1539static struct sys_device device_lapic = {
1540 .id = 0,
1541 .cls = &lapic_sysclass,
1542};
1543
1544static void __devinit apic_pm_activate(void)
1545{
1546 apic_pm_state.active = 1;
1547}
1548
1549static int __init init_lapic_sysfs(void)
1550{
1551 int error;
1552
1553 if (!cpu_has_apic)
1554 return 0;
1555 /* XXX: remove suspend/resume procs if !apic_pm_state.active? */
1556
1557 error = sysdev_class_register(&lapic_sysclass);
1558 if (!error)
1559 error = sysdev_register(&device_lapic);
1560 return error;
1561}
1562device_initcall(init_lapic_sysfs);
1563
1564#else /* CONFIG_PM */
1565
1566static void apic_pm_activate(void) { }
1567
1568#endif /* CONFIG_PM */