Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Local APIC handling, local APIC timers |
| 3 | * |
| 4 | * (c) 1999, 2000 Ingo Molnar <mingo@redhat.com> |
| 5 | * |
| 6 | * Fixes |
| 7 | * Maciej W. Rozycki : Bits for genuine 82489DX APICs; |
| 8 | * thanks to Eric Gilmore |
| 9 | * and Rolf G. Tews |
| 10 | * for testing these extensively. |
| 11 | * Maciej W. Rozycki : Various updates and fixes. |
| 12 | * Mikael Pettersson : Power Management for UP-APIC. |
| 13 | * Pavel Machek and |
| 14 | * Mikael Pettersson : PM converted to driver model. |
| 15 | */ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/init.h> |
| 18 | |
| 19 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/delay.h> |
| 21 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/mc146818rtc.h> |
| 24 | #include <linux/kernel_stat.h> |
| 25 | #include <linux/sysdev.h> |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 26 | #include <linux/cpu.h> |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 27 | #include <linux/clockchips.h> |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 28 | #include <linux/acpi_pmtmr.h> |
Venkatesh Pallipadi | 6eb0a0f | 2006-01-11 22:44:21 +0100 | [diff] [blame] | 29 | #include <linux/module.h> |
Thomas Gleixner | ad62ca2 | 2007-03-22 00:11:21 -0800 | [diff] [blame] | 30 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 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 Molnar | 306e440 | 2005-06-30 02:58:55 -0700 | [diff] [blame] | 39 | #include <asm/i8253.h> |
Don Zickus | 3e4ff11 | 2006-06-26 13:57:01 +0200 | [diff] [blame] | 40 | #include <asm/nmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | #include <mach_apic.h> |
Jesper Juhl | 382dbd0 | 2006-03-23 02:59:49 -0800 | [diff] [blame] | 43 | #include <mach_apicdef.h> |
Venkatesh Pallipadi | 6eb0a0f | 2006-01-11 22:44:21 +0100 | [diff] [blame] | 44 | #include <mach_ipi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #include "io_ports.h" |
| 47 | |
| 48 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 49 | * Sanity check |
| 50 | */ |
| 51 | #if (SPURIOUS_APIC_VECTOR & 0x0F) != 0x0F |
| 52 | # error SPURIOUS_APIC_VECTOR definition error |
| 53 | #endif |
| 54 | |
| 55 | /* |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 56 | * Knob to control our willingness to enable the local APIC. |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 57 | * |
| 58 | * -1=force-disable, +1=force-enable |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 59 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 60 | static int enable_local_apic __initdata = 0; |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 61 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 62 | /* Local APIC timer verification ok */ |
| 63 | static int local_apic_timer_verify_ok; |
Thomas Gleixner | ad62ca2 | 2007-03-22 00:11:21 -0800 | [diff] [blame] | 64 | /* Disable local APIC timer from the kernel commandline or via dmi quirk */ |
| 65 | static int local_apic_timer_disabled; |
Thomas Gleixner | e585bef | 2007-03-23 16:08:01 +0100 | [diff] [blame] | 66 | /* Local APIC timer works in C2 */ |
| 67 | int local_apic_timer_c2_ok; |
| 68 | EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 69 | |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 70 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 71 | * Debug level, exported for io_apic.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | */ |
| 73 | int apic_verbosity; |
| 74 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 75 | static unsigned int calibration_result; |
| 76 | |
| 77 | static int lapic_next_event(unsigned long delta, |
| 78 | struct clock_event_device *evt); |
| 79 | static void lapic_timer_setup(enum clock_event_mode mode, |
| 80 | struct clock_event_device *evt); |
| 81 | static void lapic_timer_broadcast(cpumask_t mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | static void apic_pm_activate(void); |
| 83 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 84 | /* |
| 85 | * The local apic timer can be used for any function which is CPU local. |
| 86 | */ |
| 87 | static struct clock_event_device lapic_clockevent = { |
| 88 | .name = "lapic", |
| 89 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 90 | | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY, |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 91 | .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 | }; |
| 98 | static DEFINE_PER_CPU(struct clock_event_device, lapic_events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 100 | /* Local APIC was disabled by the BIOS and enabled by the kernel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | static int enabled_via_apicbase; |
| 102 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 103 | /* |
| 104 | * Get the LAPIC version |
| 105 | */ |
| 106 | static 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 | */ |
| 114 | static 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 | */ |
| 122 | static 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 VazquezCao | f2b218d | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 131 | void apic_wait_icr_idle(void) |
| 132 | { |
| 133 | while (apic_read(APIC_ICR) & APIC_ICR_BUSY) |
| 134 | cpu_relax(); |
| 135 | } |
| 136 | |
| 137 | unsigned 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 Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 153 | /** |
| 154 | * enable_NMI_through_LVT0 - enable NMI through local vector table 0 |
| 155 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | void enable_NMI_through_LVT0 (void * dummy) |
| 157 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 158 | unsigned int v = APIC_DM_NMI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 160 | /* Level triggered for 82489DX */ |
| 161 | if (!lapic_is_integrated()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | v |= APIC_LVT_LEVEL_TRIGGER; |
| 163 | apic_write_around(APIC_LVT0, v); |
| 164 | } |
| 165 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 166 | /** |
| 167 | * get_physical_broadcast - Get number of physical broadcast IDs |
| 168 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | int get_physical_broadcast(void) |
| 170 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 171 | return modern_apic() ? 0xff : 0xf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 174 | /** |
| 175 | * lapic_get_maxlvt - get the maximum number of local vector table entries |
| 176 | */ |
| 177 | int lapic_get_maxlvt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 179 | unsigned int v = apic_read(APIC_LVR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | /* 82489DXs do not report # of LVT entries. */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 182 | return APIC_INTEGRATED(GET_APIC_VERSION(v)) ? GET_APIC_MAXLVT(v) : 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 186 | * Local APIC timer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 189 | /* Clock divisor is set to 16 */ |
| 190 | #define APIC_DIVISOR 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 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 Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 202 | static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 204 | unsigned int lvtt_value, tmp_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 206 | lvtt_value = LOCAL_TIMER_VECTOR; |
| 207 | if (!oneshot) |
| 208 | lvtt_value |= APIC_LVT_TIMER_PERIODIC; |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 209 | if (!lapic_is_integrated()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV); |
Venkatesh Pallipadi | 6eb0a0f | 2006-01-11 22:44:21 +0100 | [diff] [blame] | 211 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 212 | if (!irqen) |
Venkatesh Pallipadi | 6eb0a0f | 2006-01-11 22:44:21 +0100 | [diff] [blame] | 213 | lvtt_value |= APIC_LVT_MASKED; |
| 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | 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 Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 225 | if (!oneshot) |
| 226 | apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 229 | /* |
| 230 | * Program the next event, relative to now |
| 231 | */ |
| 232 | static 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 | */ |
| 242 | static void lapic_timer_setup(enum clock_event_mode mode, |
| 243 | struct clock_event_device *evt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | { |
| 245 | unsigned long flags; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 246 | unsigned int v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 248 | /* Lapic used for broadcast ? */ |
| 249 | if (!local_apic_timer_verify_ok) |
| 250 | return; |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | local_irq_save(flags); |
| 253 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 254 | 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 Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame^] | 266 | case CLOCK_EVT_MODE_RESUME: |
| 267 | /* Nothing to do here */ |
| 268 | break; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 269 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | local_irq_restore(flags); |
| 272 | } |
| 273 | |
| 274 | /* |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 275 | * Local APIC timer broadcast function |
| 276 | */ |
| 277 | static 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 | */ |
| 288 | static 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 Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 299 | * In this functions we calibrate APIC bus clocks to the external timer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | * |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 301 | * 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 Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 304 | * |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 305 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | */ |
| 318 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 319 | #define LAPIC_CAL_LOOPS (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 321 | static __initdata volatile int lapic_cal_loops = -1; |
| 322 | static __initdata long lapic_cal_t1, lapic_cal_t2; |
| 323 | static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2; |
| 324 | static __initdata unsigned long lapic_cal_pm1, lapic_cal_pm2; |
| 325 | static __initdata unsigned long lapic_cal_j1, lapic_cal_j2; |
| 326 | |
| 327 | /* |
| 328 | * Temporary interrupt handler. |
| 329 | */ |
| 330 | static 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 | */ |
| 363 | void __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 Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 371 | int pm_referenced = 0; |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 372 | |
Andi Kleen | 3556ddf | 2007-04-02 12:14:12 +0200 | [diff] [blame] | 373 | if (boot_cpu_has(X86_FEATURE_LAPIC_TIMER_BROKEN)) |
| 374 | local_apic_timer_disabled = 1; |
Thomas Gleixner | ad62ca2 | 2007-03-22 00:11:21 -0800 | [diff] [blame] | 375 | |
| 376 | /* |
| 377 | * The local apic timer can be disabled via the kernel |
Andi Kleen | 3556ddf | 2007-04-02 12:14:12 +0200 | [diff] [blame] | 378 | * commandline or from the test above. Register the lapic |
Thomas Gleixner | ad62ca2 | 2007-03-22 00:11:21 -0800 | [diff] [blame] | 379 | * 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 Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 389 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | /* |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 399 | * Setup the APIC counter to 1e9. There is no way the lapic |
| 400 | * can underflow in the 100ms detection time frame |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 402 | __setup_APIC_LVTT(1000000000, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 404 | /* Let the interrupts run */ |
| 405 | local_irq_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 407 | while (lapic_cal_loops <= LAPIC_CAL_LOOPS) |
| 408 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 410 | local_irq_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 412 | /* Restore the real event handler */ |
| 413 | global_clock_event->event_handler = real_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 415 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 419 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 423 | 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 Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 445 | pm_referenced = 1; |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 448 | /* Calculate the scaled math multiplication factor */ |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 449 | lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS, 32); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 450 | 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 Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 455 | calibration_result = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 456 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 457 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | apic_printk(APIC_VERBOSE, "..... CPU clock speed is " |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 465 | "%ld.%04ld MHz.\n", |
| 466 | (delta / LAPIC_CAL_LOOPS) / (1000000 / HZ), |
| 467 | (delta / LAPIC_CAL_LOOPS) % (1000000 / HZ)); |
| 468 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | apic_printk(APIC_VERBOSE, "..... host bus clock speed is " |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 471 | "%u.%04u MHz.\n", |
| 472 | calibration_result / (1000000 / HZ), |
| 473 | calibration_result % (1000000 / HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 475 | local_apic_timer_verify_ok = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 477 | /* We trust the pm timer based calibration */ |
| 478 | if (!pm_referenced) { |
| 479 | apic_printk(APIC_VERBOSE, "... verify APIC timer\n"); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 480 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 481 | /* |
| 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 Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 487 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 488 | /* Let the interrupts run */ |
| 489 | local_irq_enable(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 490 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 491 | while(lapic_cal_loops <= LAPIC_CAL_LOOPS) |
| 492 | cpu_relax(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 493 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 494 | local_irq_disable(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 495 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 496 | /* Stop the lapic timer */ |
| 497 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 498 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 499 | local_irq_enable(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 500 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 501 | /* Jiffies delta */ |
| 502 | deltaj = lapic_cal_j2 - lapic_cal_j1; |
| 503 | apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 504 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 505 | /* Check, if the jiffies result is consistent */ |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 506 | if (deltaj >= LAPIC_CAL_LOOPS-2 && deltaj <= LAPIC_CAL_LOOPS+2) |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 507 | apic_printk(APIC_VERBOSE, "... jiffies result ok\n"); |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 508 | else |
| 509 | local_apic_timer_verify_ok = 0; |
Ingo Molnar | 4edc5db | 2007-03-22 10:31:19 +0100 | [diff] [blame] | 510 | } else |
| 511 | local_irq_enable(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 512 | |
| 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 Gleixner | a5f5e43 | 2007-03-05 00:30:45 -0800 | [diff] [blame] | 519 | } 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; |
| 527 | } |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 528 | |
| 529 | /* Setup the lapic or request the broadcast */ |
| 530 | setup_APIC_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Li Shaohua | 0bb3184 | 2005-06-25 14:54:55 -0700 | [diff] [blame] | 533 | void __devinit setup_secondary_APIC_clock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | { |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 535 | setup_APIC_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | /* |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 539 | * The guts of the apic timer interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 541 | static void local_apic_timer_interrupt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | { |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 543 | int cpu = smp_processor_id(); |
| 544 | struct clock_event_device *evt = &per_cpu(lapic_events, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
| 546 | /* |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 547 | * Normally we should not be here till LAPIC has been initialized but |
| 548 | * in some cases like kdump, its possible that there is a pending LAPIC |
| 549 | * timer interrupt from previous kernel's context and is delivered in |
| 550 | * new kernel the moment interrupts are enabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | * |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 552 | * Interrupts are enabled early and LAPIC is setup much later, hence |
| 553 | * its possible that when we get here evt->event_handler is NULL. |
| 554 | * Check for event_handler being NULL and discard the interrupt as |
| 555 | * spurious. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 557 | if (!evt->event_handler) { |
| 558 | printk(KERN_WARNING |
| 559 | "Spurious LAPIC timer interrupt on cpu %d\n", cpu); |
| 560 | /* Switch it off */ |
| 561 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt); |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | per_cpu(irq_stat, cpu).apic_timer_irqs++; |
| 566 | |
| 567 | evt->event_handler(evt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Local APIC timer interrupt. This is the most natural way for doing |
| 572 | * local interrupts, but local timer interrupts can be emulated by |
| 573 | * broadcast interrupts too. [in case the hw doesn't support APIC timers] |
| 574 | * |
| 575 | * [ if a single-CPU system runs an SMP kernel then we call the local |
| 576 | * interrupt as well. Thus we cannot inline the local irq ... ] |
| 577 | */ |
| 578 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 579 | void fastcall smp_apic_timer_interrupt(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 581 | struct pt_regs *old_regs = set_irq_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | /* |
| 584 | * NOTE! We'd better ACK the irq immediately, |
| 585 | * because timer handling can be slow. |
| 586 | */ |
| 587 | ack_APIC_irq(); |
| 588 | /* |
| 589 | * update_process_times() expects us to have done irq_enter(). |
| 590 | * Besides, if we don't timer interrupts ignore the global |
| 591 | * interrupt lock, which is the WrongThing (tm) to do. |
| 592 | */ |
| 593 | irq_enter(); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 594 | local_apic_timer_interrupt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | irq_exit(); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 596 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 597 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Venkatesh Pallipadi | 5a07a30 | 2006-01-11 22:44:18 +0100 | [diff] [blame] | 600 | int setup_profiling_timer(unsigned int multiplier) |
| 601 | { |
| 602 | return -EINVAL; |
| 603 | } |
| 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 606 | * Local APIC start and shutdown |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 608 | |
| 609 | /** |
| 610 | * clear_local_APIC - shutdown the local APIC |
| 611 | * |
| 612 | * This is called, when a CPU is disabled and before rebooting, so the state of |
| 613 | * the local APIC has no dangling leftovers. Also used to cleanout any BIOS |
| 614 | * leftovers during boot. |
| 615 | */ |
| 616 | void clear_local_APIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 618 | int maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | unsigned long v; |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 622 | * Masking an LVT entry can trigger a local APIC error |
| 623 | * if the vector is zero. Mask LVTERR first to prevent this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 625 | if (maxlvt >= 3) { |
| 626 | v = ERROR_APIC_VECTOR; /* any non-zero vector will do */ |
| 627 | apic_write_around(APIC_LVTERR, v | APIC_LVT_MASKED); |
| 628 | } |
| 629 | /* |
| 630 | * Careful: we have to set masks only first to deassert |
| 631 | * any level-triggered sources. |
| 632 | */ |
| 633 | v = apic_read(APIC_LVTT); |
| 634 | apic_write_around(APIC_LVTT, v | APIC_LVT_MASKED); |
| 635 | v = apic_read(APIC_LVT0); |
| 636 | apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED); |
| 637 | v = apic_read(APIC_LVT1); |
| 638 | apic_write_around(APIC_LVT1, v | APIC_LVT_MASKED); |
| 639 | if (maxlvt >= 4) { |
| 640 | v = apic_read(APIC_LVTPC); |
| 641 | apic_write_around(APIC_LVTPC, v | APIC_LVT_MASKED); |
| 642 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 644 | /* lets not touch this if we didn't frob it */ |
| 645 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 646 | if (maxlvt >= 5) { |
| 647 | v = apic_read(APIC_LVTTHMR); |
| 648 | apic_write_around(APIC_LVTTHMR, v | APIC_LVT_MASKED); |
| 649 | } |
| 650 | #endif |
| 651 | /* |
| 652 | * Clean APIC state for other OSs: |
| 653 | */ |
| 654 | apic_write_around(APIC_LVTT, APIC_LVT_MASKED); |
| 655 | apic_write_around(APIC_LVT0, APIC_LVT_MASKED); |
| 656 | apic_write_around(APIC_LVT1, APIC_LVT_MASKED); |
| 657 | if (maxlvt >= 3) |
| 658 | apic_write_around(APIC_LVTERR, APIC_LVT_MASKED); |
| 659 | if (maxlvt >= 4) |
| 660 | apic_write_around(APIC_LVTPC, APIC_LVT_MASKED); |
| 661 | |
| 662 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 663 | if (maxlvt >= 5) |
| 664 | apic_write_around(APIC_LVTTHMR, APIC_LVT_MASKED); |
| 665 | #endif |
| 666 | /* Integrated APIC (!82489DX) ? */ |
| 667 | if (lapic_is_integrated()) { |
| 668 | if (maxlvt > 3) |
| 669 | /* Clear ESR due to Pentium errata 3AP and 11AP */ |
| 670 | apic_write(APIC_ESR, 0); |
| 671 | apic_read(APIC_ESR); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | /** |
| 676 | * disable_local_APIC - clear and disable the local APIC |
| 677 | */ |
| 678 | void disable_local_APIC(void) |
| 679 | { |
| 680 | unsigned long value; |
| 681 | |
| 682 | clear_local_APIC(); |
| 683 | |
| 684 | /* |
| 685 | * Disable APIC (implies clearing of registers |
| 686 | * for 82489DX!). |
| 687 | */ |
| 688 | value = apic_read(APIC_SPIV); |
| 689 | value &= ~APIC_SPIV_APIC_ENABLED; |
| 690 | apic_write_around(APIC_SPIV, value); |
| 691 | |
| 692 | /* |
| 693 | * When LAPIC was disabled by the BIOS and enabled by the kernel, |
| 694 | * restore the disabled state. |
| 695 | */ |
| 696 | if (enabled_via_apicbase) { |
| 697 | unsigned int l, h; |
| 698 | |
| 699 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 700 | l &= ~MSR_IA32_APICBASE_ENABLE; |
| 701 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 706 | * If Linux enabled the LAPIC against the BIOS default disable it down before |
| 707 | * re-entering the BIOS on shutdown. Otherwise the BIOS may get confused and |
| 708 | * not power-off. Additionally clear all LVT entries before disable_local_APIC |
| 709 | * for the case where Linux didn't enable the LAPIC. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 711 | void lapic_shutdown(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 713 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 715 | if (!cpu_has_apic) |
| 716 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 718 | local_irq_save(flags); |
| 719 | clear_local_APIC(); |
| 720 | |
| 721 | if (enabled_via_apicbase) |
| 722 | disable_local_APIC(); |
| 723 | |
| 724 | local_irq_restore(flags); |
| 725 | } |
| 726 | |
| 727 | /* |
| 728 | * This is to verify that we're looking at a real local APIC. |
| 729 | * Check these against your board if the CPUs aren't getting |
| 730 | * started for no apparent reason. |
| 731 | */ |
| 732 | int __init verify_local_APIC(void) |
| 733 | { |
| 734 | unsigned int reg0, reg1; |
| 735 | |
| 736 | /* |
| 737 | * The version register is read-only in a real APIC. |
| 738 | */ |
| 739 | reg0 = apic_read(APIC_LVR); |
| 740 | apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0); |
| 741 | apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK); |
| 742 | reg1 = apic_read(APIC_LVR); |
| 743 | apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1); |
| 744 | |
| 745 | /* |
| 746 | * The two version reads above should print the same |
| 747 | * numbers. If the second one is different, then we |
| 748 | * poke at a non-APIC. |
| 749 | */ |
| 750 | if (reg1 != reg0) |
| 751 | return 0; |
| 752 | |
| 753 | /* |
| 754 | * Check if the version looks reasonably. |
| 755 | */ |
| 756 | reg1 = GET_APIC_VERSION(reg0); |
| 757 | if (reg1 == 0x00 || reg1 == 0xff) |
| 758 | return 0; |
| 759 | reg1 = lapic_get_maxlvt(); |
| 760 | if (reg1 < 0x02 || reg1 == 0xff) |
| 761 | return 0; |
| 762 | |
| 763 | /* |
| 764 | * The ID register is read/write in a real APIC. |
| 765 | */ |
| 766 | reg0 = apic_read(APIC_ID); |
| 767 | apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0); |
| 768 | |
| 769 | /* |
| 770 | * The next two are just to see if we have sane values. |
| 771 | * They're only really relevant if we're in Virtual Wire |
| 772 | * compatibility mode, but most boxes are anymore. |
| 773 | */ |
| 774 | reg0 = apic_read(APIC_LVT0); |
| 775 | apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0); |
| 776 | reg1 = apic_read(APIC_LVT1); |
| 777 | apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1); |
| 778 | |
| 779 | return 1; |
| 780 | } |
| 781 | |
| 782 | /** |
| 783 | * sync_Arb_IDs - synchronize APIC bus arbitration IDs |
| 784 | */ |
| 785 | void __init sync_Arb_IDs(void) |
| 786 | { |
| 787 | /* |
| 788 | * Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 And not |
| 789 | * needed on AMD. |
| 790 | */ |
| 791 | if (modern_apic()) |
| 792 | return; |
| 793 | /* |
| 794 | * Wait for idle. |
| 795 | */ |
| 796 | apic_wait_icr_idle(); |
| 797 | |
| 798 | apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n"); |
| 799 | apic_write_around(APIC_ICR, APIC_DEST_ALLINC | APIC_INT_LEVELTRIG |
| 800 | | APIC_DM_INIT); |
| 801 | } |
| 802 | |
| 803 | /* |
| 804 | * An initial setup of the virtual wire mode. |
| 805 | */ |
| 806 | void __init init_bsp_APIC(void) |
| 807 | { |
| 808 | unsigned long value; |
| 809 | |
| 810 | /* |
| 811 | * Don't do the setup now if we have a SMP BIOS as the |
| 812 | * through-I/O-APIC virtual wire mode might be active. |
| 813 | */ |
| 814 | if (smp_found_config || !cpu_has_apic) |
| 815 | return; |
| 816 | |
| 817 | /* |
| 818 | * Do not trust the local APIC being empty at bootup. |
| 819 | */ |
| 820 | clear_local_APIC(); |
| 821 | |
| 822 | /* |
| 823 | * Enable APIC. |
| 824 | */ |
| 825 | value = apic_read(APIC_SPIV); |
| 826 | value &= ~APIC_VECTOR_MASK; |
| 827 | value |= APIC_SPIV_APIC_ENABLED; |
| 828 | |
| 829 | /* This bit is reserved on P4/Xeon and should be cleared */ |
| 830 | if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) && |
| 831 | (boot_cpu_data.x86 == 15)) |
| 832 | value &= ~APIC_SPIV_FOCUS_DISABLED; |
| 833 | else |
| 834 | value |= APIC_SPIV_FOCUS_DISABLED; |
| 835 | value |= SPURIOUS_APIC_VECTOR; |
| 836 | apic_write_around(APIC_SPIV, value); |
| 837 | |
| 838 | /* |
| 839 | * Set up the virtual wire mode. |
| 840 | */ |
| 841 | apic_write_around(APIC_LVT0, APIC_DM_EXTINT); |
| 842 | value = APIC_DM_NMI; |
| 843 | if (!lapic_is_integrated()) /* 82489DX */ |
| 844 | value |= APIC_LVT_LEVEL_TRIGGER; |
| 845 | apic_write_around(APIC_LVT1, value); |
| 846 | } |
| 847 | |
| 848 | /** |
| 849 | * setup_local_APIC - setup the local APIC |
| 850 | */ |
| 851 | void __devinit setup_local_APIC(void) |
| 852 | { |
| 853 | unsigned long oldvalue, value, maxlvt, integrated; |
| 854 | int i, j; |
| 855 | |
| 856 | /* Pound the ESR really hard over the head with a big hammer - mbligh */ |
| 857 | if (esr_disable) { |
| 858 | apic_write(APIC_ESR, 0); |
| 859 | apic_write(APIC_ESR, 0); |
| 860 | apic_write(APIC_ESR, 0); |
| 861 | apic_write(APIC_ESR, 0); |
| 862 | } |
| 863 | |
| 864 | integrated = lapic_is_integrated(); |
| 865 | |
| 866 | /* |
| 867 | * Double-check whether this APIC is really registered. |
| 868 | */ |
| 869 | if (!apic_id_registered()) |
| 870 | BUG(); |
| 871 | |
| 872 | /* |
| 873 | * Intel recommends to set DFR, LDR and TPR before enabling |
| 874 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
| 875 | * document number 292116). So here it goes... |
| 876 | */ |
| 877 | init_apic_ldr(); |
| 878 | |
| 879 | /* |
| 880 | * Set Task Priority to 'accept all'. We never change this |
| 881 | * later on. |
| 882 | */ |
| 883 | value = apic_read(APIC_TASKPRI); |
| 884 | value &= ~APIC_TPRI_MASK; |
| 885 | apic_write_around(APIC_TASKPRI, value); |
| 886 | |
| 887 | /* |
| 888 | * After a crash, we no longer service the interrupts and a pending |
| 889 | * interrupt from previous kernel might still have ISR bit set. |
| 890 | * |
| 891 | * Most probably by now CPU has serviced that pending interrupt and |
| 892 | * it might not have done the ack_APIC_irq() because it thought, |
| 893 | * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it |
| 894 | * does not clear the ISR bit and cpu thinks it has already serivced |
| 895 | * the interrupt. Hence a vector might get locked. It was noticed |
| 896 | * for timer irq (vector 0x31). Issue an extra EOI to clear ISR. |
| 897 | */ |
| 898 | for (i = APIC_ISR_NR - 1; i >= 0; i--) { |
| 899 | value = apic_read(APIC_ISR + i*0x10); |
| 900 | for (j = 31; j >= 0; j--) { |
| 901 | if (value & (1<<j)) |
| 902 | ack_APIC_irq(); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | /* |
| 907 | * Now that we are all set up, enable the APIC |
| 908 | */ |
| 909 | value = apic_read(APIC_SPIV); |
| 910 | value &= ~APIC_VECTOR_MASK; |
| 911 | /* |
| 912 | * Enable APIC |
| 913 | */ |
| 914 | value |= APIC_SPIV_APIC_ENABLED; |
| 915 | |
| 916 | /* |
| 917 | * Some unknown Intel IO/APIC (or APIC) errata is biting us with |
| 918 | * certain networking cards. If high frequency interrupts are |
| 919 | * happening on a particular IOAPIC pin, plus the IOAPIC routing |
| 920 | * entry is masked/unmasked at a high rate as well then sooner or |
| 921 | * later IOAPIC line gets 'stuck', no more interrupts are received |
| 922 | * from the device. If focus CPU is disabled then the hang goes |
| 923 | * away, oh well :-( |
| 924 | * |
| 925 | * [ This bug can be reproduced easily with a level-triggered |
| 926 | * PCI Ne2000 networking cards and PII/PIII processors, dual |
| 927 | * BX chipset. ] |
| 928 | */ |
| 929 | /* |
| 930 | * Actually disabling the focus CPU check just makes the hang less |
| 931 | * frequent as it makes the interrupt distributon model be more |
| 932 | * like LRU than MRU (the short-term load is more even across CPUs). |
| 933 | * See also the comment in end_level_ioapic_irq(). --macro |
| 934 | */ |
| 935 | |
| 936 | /* Enable focus processor (bit==0) */ |
| 937 | value &= ~APIC_SPIV_FOCUS_DISABLED; |
| 938 | |
| 939 | /* |
| 940 | * Set spurious IRQ vector |
| 941 | */ |
| 942 | value |= SPURIOUS_APIC_VECTOR; |
| 943 | apic_write_around(APIC_SPIV, value); |
| 944 | |
| 945 | /* |
| 946 | * Set up LVT0, LVT1: |
| 947 | * |
| 948 | * set up through-local-APIC on the BP's LINT0. This is not |
| 949 | * strictly necessery in pure symmetric-IO mode, but sometimes |
| 950 | * we delegate interrupts to the 8259A. |
| 951 | */ |
| 952 | /* |
| 953 | * TODO: set up through-local-APIC from through-I/O-APIC? --macro |
| 954 | */ |
| 955 | value = apic_read(APIC_LVT0) & APIC_LVT_MASKED; |
| 956 | if (!smp_processor_id() && (pic_mode || !value)) { |
| 957 | value = APIC_DM_EXTINT; |
| 958 | apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", |
| 959 | smp_processor_id()); |
| 960 | } else { |
| 961 | value = APIC_DM_EXTINT | APIC_LVT_MASKED; |
| 962 | apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", |
| 963 | smp_processor_id()); |
| 964 | } |
| 965 | apic_write_around(APIC_LVT0, value); |
| 966 | |
| 967 | /* |
| 968 | * only the BP should see the LINT1 NMI signal, obviously. |
| 969 | */ |
| 970 | if (!smp_processor_id()) |
| 971 | value = APIC_DM_NMI; |
| 972 | else |
| 973 | value = APIC_DM_NMI | APIC_LVT_MASKED; |
| 974 | if (!integrated) /* 82489DX */ |
| 975 | value |= APIC_LVT_LEVEL_TRIGGER; |
| 976 | apic_write_around(APIC_LVT1, value); |
| 977 | |
| 978 | if (integrated && !esr_disable) { /* !82489DX */ |
| 979 | maxlvt = lapic_get_maxlvt(); |
| 980 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
| 981 | apic_write(APIC_ESR, 0); |
| 982 | oldvalue = apic_read(APIC_ESR); |
| 983 | |
| 984 | /* enables sending errors */ |
| 985 | value = ERROR_APIC_VECTOR; |
| 986 | apic_write_around(APIC_LVTERR, value); |
| 987 | /* |
| 988 | * spec says clear errors after enabling vector. |
| 989 | */ |
| 990 | if (maxlvt > 3) |
| 991 | apic_write(APIC_ESR, 0); |
| 992 | value = apic_read(APIC_ESR); |
| 993 | if (value != oldvalue) |
| 994 | apic_printk(APIC_VERBOSE, "ESR value before enabling " |
| 995 | "vector: 0x%08lx after: 0x%08lx\n", |
| 996 | oldvalue, value); |
| 997 | } else { |
| 998 | if (esr_disable) |
| 999 | /* |
| 1000 | * Something untraceble is creating bad interrupts on |
| 1001 | * secondary quads ... for the moment, just leave the |
| 1002 | * ESR disabled - we can't do anything useful with the |
| 1003 | * errors anyway - mbligh |
| 1004 | */ |
| 1005 | printk(KERN_INFO "Leaving ESR disabled.\n"); |
| 1006 | else |
| 1007 | printk(KERN_INFO "No ESR for 82489DX.\n"); |
| 1008 | } |
| 1009 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1010 | /* Disable the local apic timer */ |
| 1011 | value = apic_read(APIC_LVTT); |
| 1012 | value |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); |
| 1013 | apic_write_around(APIC_LVTT, value); |
| 1014 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1015 | setup_apic_nmi_watchdog(NULL); |
| 1016 | apic_pm_activate(); |
| 1017 | } |
| 1018 | |
| 1019 | /* |
| 1020 | * Detect and initialize APIC |
| 1021 | */ |
| 1022 | static int __init detect_init_APIC (void) |
| 1023 | { |
| 1024 | u32 h, l, features; |
| 1025 | |
| 1026 | /* Disabled by kernel option? */ |
| 1027 | if (enable_local_apic < 0) |
| 1028 | return -1; |
| 1029 | |
| 1030 | switch (boot_cpu_data.x86_vendor) { |
| 1031 | case X86_VENDOR_AMD: |
| 1032 | if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model > 1) || |
| 1033 | (boot_cpu_data.x86 == 15)) |
| 1034 | break; |
| 1035 | goto no_apic; |
| 1036 | case X86_VENDOR_INTEL: |
| 1037 | if (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15 || |
| 1038 | (boot_cpu_data.x86 == 5 && cpu_has_apic)) |
| 1039 | break; |
| 1040 | goto no_apic; |
| 1041 | default: |
| 1042 | goto no_apic; |
| 1043 | } |
| 1044 | |
| 1045 | if (!cpu_has_apic) { |
| 1046 | /* |
| 1047 | * Over-ride BIOS and try to enable the local APIC only if |
| 1048 | * "lapic" specified. |
| 1049 | */ |
| 1050 | if (enable_local_apic <= 0) { |
| 1051 | printk(KERN_INFO "Local APIC disabled by BIOS -- " |
| 1052 | "you can enable it with \"lapic\"\n"); |
| 1053 | return -1; |
| 1054 | } |
| 1055 | /* |
| 1056 | * Some BIOSes disable the local APIC in the APIC_BASE |
| 1057 | * MSR. This can only be done in software for Intel P6 or later |
| 1058 | * and AMD K7 (Model > 1) or later. |
| 1059 | */ |
| 1060 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1061 | if (!(l & MSR_IA32_APICBASE_ENABLE)) { |
| 1062 | printk(KERN_INFO |
| 1063 | "Local APIC disabled by BIOS -- reenabling.\n"); |
| 1064 | l &= ~MSR_IA32_APICBASE_BASE; |
| 1065 | l |= MSR_IA32_APICBASE_ENABLE | APIC_DEFAULT_PHYS_BASE; |
| 1066 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 1067 | enabled_via_apicbase = 1; |
| 1068 | } |
| 1069 | } |
| 1070 | /* |
| 1071 | * The APIC feature bit should now be enabled |
| 1072 | * in `cpuid' |
| 1073 | */ |
| 1074 | features = cpuid_edx(1); |
| 1075 | if (!(features & (1 << X86_FEATURE_APIC))) { |
| 1076 | printk(KERN_WARNING "Could not enable APIC!\n"); |
| 1077 | return -1; |
| 1078 | } |
| 1079 | set_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability); |
| 1080 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 1081 | |
| 1082 | /* The BIOS may have set up the APIC at some other address */ |
| 1083 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1084 | if (l & MSR_IA32_APICBASE_ENABLE) |
| 1085 | mp_lapic_addr = l & MSR_IA32_APICBASE_BASE; |
| 1086 | |
| 1087 | if (nmi_watchdog != NMI_NONE) |
| 1088 | nmi_watchdog = NMI_LOCAL_APIC; |
| 1089 | |
| 1090 | printk(KERN_INFO "Found and enabled local APIC!\n"); |
| 1091 | |
| 1092 | apic_pm_activate(); |
| 1093 | |
| 1094 | return 0; |
| 1095 | |
| 1096 | no_apic: |
| 1097 | printk(KERN_INFO "No local APIC present or hardware disabled\n"); |
| 1098 | return -1; |
| 1099 | } |
| 1100 | |
| 1101 | /** |
| 1102 | * init_apic_mappings - initialize APIC mappings |
| 1103 | */ |
| 1104 | void __init init_apic_mappings(void) |
| 1105 | { |
| 1106 | unsigned long apic_phys; |
| 1107 | |
| 1108 | /* |
| 1109 | * If no local APIC can be found then set up a fake all |
| 1110 | * zeroes page to simulate the local APIC and another |
| 1111 | * one for the IO-APIC. |
| 1112 | */ |
| 1113 | if (!smp_found_config && detect_init_APIC()) { |
| 1114 | apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE); |
| 1115 | apic_phys = __pa(apic_phys); |
| 1116 | } else |
| 1117 | apic_phys = mp_lapic_addr; |
| 1118 | |
| 1119 | set_fixmap_nocache(FIX_APIC_BASE, apic_phys); |
| 1120 | printk(KERN_DEBUG "mapped APIC to %08lx (%08lx)\n", APIC_BASE, |
| 1121 | apic_phys); |
| 1122 | |
| 1123 | /* |
| 1124 | * Fetch the APIC ID of the BSP in case we have a |
| 1125 | * default configuration (or the MP table is broken). |
| 1126 | */ |
| 1127 | if (boot_cpu_physical_apicid == -1U) |
| 1128 | boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID)); |
| 1129 | |
| 1130 | #ifdef CONFIG_X86_IO_APIC |
| 1131 | { |
| 1132 | unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0; |
| 1133 | int i; |
| 1134 | |
| 1135 | for (i = 0; i < nr_ioapics; i++) { |
| 1136 | if (smp_found_config) { |
| 1137 | ioapic_phys = mp_ioapics[i].mpc_apicaddr; |
| 1138 | if (!ioapic_phys) { |
| 1139 | printk(KERN_ERR |
| 1140 | "WARNING: bogus zero IO-APIC " |
| 1141 | "address found in MPTABLE, " |
| 1142 | "disabling IO/APIC support!\n"); |
| 1143 | smp_found_config = 0; |
| 1144 | skip_ioapic_setup = 1; |
| 1145 | goto fake_ioapic_page; |
| 1146 | } |
| 1147 | } else { |
| 1148 | fake_ioapic_page: |
| 1149 | ioapic_phys = (unsigned long) |
| 1150 | alloc_bootmem_pages(PAGE_SIZE); |
| 1151 | ioapic_phys = __pa(ioapic_phys); |
| 1152 | } |
| 1153 | set_fixmap_nocache(idx, ioapic_phys); |
| 1154 | printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n", |
| 1155 | __fix_to_virt(idx), ioapic_phys); |
| 1156 | idx++; |
| 1157 | } |
| 1158 | } |
| 1159 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | /* |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1163 | * This initializes the IO-APIC and APIC hardware if this is |
| 1164 | * a UP kernel. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | */ |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1166 | int __init APIC_init_uniprocessor (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | { |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1168 | if (enable_local_apic < 0) |
| 1169 | clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability); |
Eric W. Biederman | f2b36db | 2005-10-30 14:59:41 -0800 | [diff] [blame] | 1170 | |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1171 | if (!smp_found_config && !cpu_has_apic) |
Eric W. Biederman | f2b36db | 2005-10-30 14:59:41 -0800 | [diff] [blame] | 1172 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | |
| 1174 | /* |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1175 | * Complain if the BIOS pretends there is one. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1177 | if (!cpu_has_apic && |
| 1178 | APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n", |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1180 | boot_cpu_physical_apicid); |
Andi Kleen | 3777a95 | 2006-02-03 21:51:53 +0100 | [diff] [blame] | 1181 | clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | return -1; |
| 1183 | } |
| 1184 | |
| 1185 | verify_local_APIC(); |
| 1186 | |
| 1187 | connect_bsp_APIC(); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1188 | |
Vivek Goyal | be0d03f | 2006-05-20 15:00:21 -0700 | [diff] [blame] | 1189 | /* |
| 1190 | * Hack: In case of kdump, after a crash, kernel might be booting |
| 1191 | * on a cpu with non-zero lapic id. But boot_cpu_physical_apicid |
| 1192 | * might be zero if read from MP tables. Get it from LAPIC. |
| 1193 | */ |
| 1194 | #ifdef CONFIG_CRASH_DUMP |
| 1195 | boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID)); |
| 1196 | #endif |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1197 | phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid); |
| 1198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | setup_local_APIC(); |
| 1200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | #ifdef CONFIG_X86_IO_APIC |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1202 | if (smp_found_config) |
| 1203 | if (!skip_ioapic_setup && nr_ioapics) |
| 1204 | setup_IO_APIC(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | #endif |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1206 | setup_boot_clock(); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1207 | |
| 1208 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1210 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1211 | /* |
| 1212 | * APIC command line parameters |
| 1213 | */ |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1214 | static int __init parse_lapic(char *arg) |
| 1215 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1216 | enable_local_apic = 1; |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1217 | return 0; |
| 1218 | } |
| 1219 | early_param("lapic", parse_lapic); |
| 1220 | |
| 1221 | static int __init parse_nolapic(char *arg) |
| 1222 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1223 | enable_local_apic = -1; |
| 1224 | clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability); |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1225 | return 0; |
| 1226 | } |
| 1227 | early_param("nolapic", parse_nolapic); |
| 1228 | |
Thomas Gleixner | ad62ca2 | 2007-03-22 00:11:21 -0800 | [diff] [blame] | 1229 | static int __init parse_disable_lapic_timer(char *arg) |
| 1230 | { |
| 1231 | local_apic_timer_disabled = 1; |
| 1232 | return 0; |
| 1233 | } |
| 1234 | early_param("nolapic_timer", parse_disable_lapic_timer); |
| 1235 | |
Thomas Gleixner | e585bef | 2007-03-23 16:08:01 +0100 | [diff] [blame] | 1236 | static int __init parse_lapic_timer_c2_ok(char *arg) |
| 1237 | { |
| 1238 | local_apic_timer_c2_ok = 1; |
| 1239 | return 0; |
| 1240 | } |
| 1241 | early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok); |
| 1242 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1243 | static int __init apic_set_verbosity(char *str) |
| 1244 | { |
| 1245 | if (strcmp("debug", str) == 0) |
| 1246 | apic_verbosity = APIC_DEBUG; |
| 1247 | else if (strcmp("verbose", str) == 0) |
| 1248 | apic_verbosity = APIC_VERBOSE; |
| 1249 | return 1; |
| 1250 | } |
| 1251 | |
| 1252 | __setup("apic=", apic_set_verbosity); |
| 1253 | |
| 1254 | |
| 1255 | /* |
| 1256 | * Local APIC interrupts |
| 1257 | */ |
| 1258 | |
| 1259 | /* |
| 1260 | * This interrupt should _never_ happen with our APIC/SMP architecture |
| 1261 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1262 | void smp_spurious_interrupt(struct pt_regs *regs) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1263 | { |
| 1264 | unsigned long v; |
| 1265 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1266 | irq_enter(); |
| 1267 | /* |
| 1268 | * Check if this really is a spurious interrupt and ACK it |
| 1269 | * if it is a vectored one. Just in case... |
| 1270 | * Spurious interrupts should not be ACKed. |
| 1271 | */ |
| 1272 | v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1)); |
| 1273 | if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f))) |
| 1274 | ack_APIC_irq(); |
| 1275 | |
| 1276 | /* see sw-dev-man vol 3, chapter 7.4.13.5 */ |
| 1277 | printk(KERN_INFO "spurious APIC interrupt on CPU#%d, " |
| 1278 | "should never happen.\n", smp_processor_id()); |
| 1279 | irq_exit(); |
| 1280 | } |
| 1281 | |
| 1282 | /* |
| 1283 | * This interrupt should never happen with our APIC/SMP architecture |
| 1284 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1285 | void smp_error_interrupt(struct pt_regs *regs) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1286 | { |
| 1287 | unsigned long v, v1; |
| 1288 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1289 | irq_enter(); |
| 1290 | /* First tickle the hardware, only then report what went on. -- REW */ |
| 1291 | v = apic_read(APIC_ESR); |
| 1292 | apic_write(APIC_ESR, 0); |
| 1293 | v1 = apic_read(APIC_ESR); |
| 1294 | ack_APIC_irq(); |
| 1295 | atomic_inc(&irq_err_count); |
| 1296 | |
| 1297 | /* Here is what the APIC error bits mean: |
| 1298 | 0: Send CS error |
| 1299 | 1: Receive CS error |
| 1300 | 2: Send accept error |
| 1301 | 3: Receive accept error |
| 1302 | 4: Reserved |
| 1303 | 5: Send illegal vector |
| 1304 | 6: Received illegal vector |
| 1305 | 7: Illegal register address |
| 1306 | */ |
| 1307 | printk (KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n", |
| 1308 | smp_processor_id(), v , v1); |
| 1309 | irq_exit(); |
| 1310 | } |
| 1311 | |
| 1312 | /* |
| 1313 | * Initialize APIC interrupts |
| 1314 | */ |
| 1315 | void __init apic_intr_init(void) |
| 1316 | { |
| 1317 | #ifdef CONFIG_SMP |
| 1318 | smp_intr_init(); |
| 1319 | #endif |
| 1320 | /* self generated IPI for local APIC timer */ |
| 1321 | set_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt); |
| 1322 | |
| 1323 | /* IPI vectors for APIC spurious and error interrupts */ |
| 1324 | set_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt); |
| 1325 | set_intr_gate(ERROR_APIC_VECTOR, error_interrupt); |
| 1326 | |
| 1327 | /* thermal monitor LVT interrupt */ |
| 1328 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 1329 | set_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt); |
| 1330 | #endif |
| 1331 | } |
| 1332 | |
| 1333 | /** |
| 1334 | * connect_bsp_APIC - attach the APIC to the interrupt system |
| 1335 | */ |
| 1336 | void __init connect_bsp_APIC(void) |
| 1337 | { |
| 1338 | if (pic_mode) { |
| 1339 | /* |
| 1340 | * Do not trust the local APIC being empty at bootup. |
| 1341 | */ |
| 1342 | clear_local_APIC(); |
| 1343 | /* |
| 1344 | * PIC mode, enable APIC mode in the IMCR, i.e. connect BSP's |
| 1345 | * local APIC to INT and NMI lines. |
| 1346 | */ |
| 1347 | apic_printk(APIC_VERBOSE, "leaving PIC mode, " |
| 1348 | "enabling APIC mode.\n"); |
| 1349 | outb(0x70, 0x22); |
| 1350 | outb(0x01, 0x23); |
| 1351 | } |
| 1352 | enable_apic_mode(); |
| 1353 | } |
| 1354 | |
| 1355 | /** |
| 1356 | * disconnect_bsp_APIC - detach the APIC from the interrupt system |
| 1357 | * @virt_wire_setup: indicates, whether virtual wire mode is selected |
| 1358 | * |
| 1359 | * Virtual wire mode is necessary to deliver legacy interrupts even when the |
| 1360 | * APIC is disabled. |
| 1361 | */ |
| 1362 | void disconnect_bsp_APIC(int virt_wire_setup) |
| 1363 | { |
| 1364 | if (pic_mode) { |
| 1365 | /* |
| 1366 | * Put the board back into PIC mode (has an effect only on |
| 1367 | * certain older boards). Note that APIC interrupts, including |
| 1368 | * IPIs, won't work beyond this point! The only exception are |
| 1369 | * INIT IPIs. |
| 1370 | */ |
| 1371 | apic_printk(APIC_VERBOSE, "disabling APIC mode, " |
| 1372 | "entering PIC mode.\n"); |
| 1373 | outb(0x70, 0x22); |
| 1374 | outb(0x00, 0x23); |
| 1375 | } else { |
| 1376 | /* Go back to Virtual Wire compatibility mode */ |
| 1377 | unsigned long value; |
| 1378 | |
| 1379 | /* For the spurious interrupt use vector F, and enable it */ |
| 1380 | value = apic_read(APIC_SPIV); |
| 1381 | value &= ~APIC_VECTOR_MASK; |
| 1382 | value |= APIC_SPIV_APIC_ENABLED; |
| 1383 | value |= 0xf; |
| 1384 | apic_write_around(APIC_SPIV, value); |
| 1385 | |
| 1386 | if (!virt_wire_setup) { |
| 1387 | /* |
| 1388 | * For LVT0 make it edge triggered, active high, |
| 1389 | * external and enabled |
| 1390 | */ |
| 1391 | value = apic_read(APIC_LVT0); |
| 1392 | value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING | |
| 1393 | APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR | |
| 1394 | APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED ); |
| 1395 | value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING; |
| 1396 | value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT); |
| 1397 | apic_write_around(APIC_LVT0, value); |
| 1398 | } else { |
| 1399 | /* Disable LVT0 */ |
| 1400 | apic_write_around(APIC_LVT0, APIC_LVT_MASKED); |
| 1401 | } |
| 1402 | |
| 1403 | /* |
| 1404 | * For LVT1 make it edge triggered, active high, nmi and |
| 1405 | * enabled |
| 1406 | */ |
| 1407 | value = apic_read(APIC_LVT1); |
| 1408 | value &= ~( |
| 1409 | APIC_MODE_MASK | APIC_SEND_PENDING | |
| 1410 | APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR | |
| 1411 | APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED); |
| 1412 | value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING; |
| 1413 | value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI); |
| 1414 | apic_write_around(APIC_LVT1, value); |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | /* |
| 1419 | * Power management |
| 1420 | */ |
| 1421 | #ifdef CONFIG_PM |
| 1422 | |
| 1423 | static struct { |
| 1424 | int active; |
| 1425 | /* r/w apic fields */ |
| 1426 | unsigned int apic_id; |
| 1427 | unsigned int apic_taskpri; |
| 1428 | unsigned int apic_ldr; |
| 1429 | unsigned int apic_dfr; |
| 1430 | unsigned int apic_spiv; |
| 1431 | unsigned int apic_lvtt; |
| 1432 | unsigned int apic_lvtpc; |
| 1433 | unsigned int apic_lvt0; |
| 1434 | unsigned int apic_lvt1; |
| 1435 | unsigned int apic_lvterr; |
| 1436 | unsigned int apic_tmict; |
| 1437 | unsigned int apic_tdcr; |
| 1438 | unsigned int apic_thmr; |
| 1439 | } apic_pm_state; |
| 1440 | |
| 1441 | static int lapic_suspend(struct sys_device *dev, pm_message_t state) |
| 1442 | { |
| 1443 | unsigned long flags; |
| 1444 | int maxlvt; |
| 1445 | |
| 1446 | if (!apic_pm_state.active) |
| 1447 | return 0; |
| 1448 | |
| 1449 | maxlvt = lapic_get_maxlvt(); |
| 1450 | |
| 1451 | apic_pm_state.apic_id = apic_read(APIC_ID); |
| 1452 | apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI); |
| 1453 | apic_pm_state.apic_ldr = apic_read(APIC_LDR); |
| 1454 | apic_pm_state.apic_dfr = apic_read(APIC_DFR); |
| 1455 | apic_pm_state.apic_spiv = apic_read(APIC_SPIV); |
| 1456 | apic_pm_state.apic_lvtt = apic_read(APIC_LVTT); |
| 1457 | if (maxlvt >= 4) |
| 1458 | apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC); |
| 1459 | apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0); |
| 1460 | apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1); |
| 1461 | apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR); |
| 1462 | apic_pm_state.apic_tmict = apic_read(APIC_TMICT); |
| 1463 | apic_pm_state.apic_tdcr = apic_read(APIC_TDCR); |
| 1464 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 1465 | if (maxlvt >= 5) |
| 1466 | apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR); |
| 1467 | #endif |
| 1468 | |
| 1469 | local_irq_save(flags); |
| 1470 | disable_local_APIC(); |
| 1471 | local_irq_restore(flags); |
| 1472 | return 0; |
| 1473 | } |
| 1474 | |
| 1475 | static int lapic_resume(struct sys_device *dev) |
| 1476 | { |
| 1477 | unsigned int l, h; |
| 1478 | unsigned long flags; |
| 1479 | int maxlvt; |
| 1480 | |
| 1481 | if (!apic_pm_state.active) |
| 1482 | return 0; |
| 1483 | |
| 1484 | maxlvt = lapic_get_maxlvt(); |
| 1485 | |
| 1486 | local_irq_save(flags); |
| 1487 | |
| 1488 | /* |
| 1489 | * Make sure the APICBASE points to the right address |
| 1490 | * |
| 1491 | * FIXME! This will be wrong if we ever support suspend on |
| 1492 | * SMP! We'll need to do this as part of the CPU restore! |
| 1493 | */ |
| 1494 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1495 | l &= ~MSR_IA32_APICBASE_BASE; |
| 1496 | l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr; |
| 1497 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 1498 | |
| 1499 | apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED); |
| 1500 | apic_write(APIC_ID, apic_pm_state.apic_id); |
| 1501 | apic_write(APIC_DFR, apic_pm_state.apic_dfr); |
| 1502 | apic_write(APIC_LDR, apic_pm_state.apic_ldr); |
| 1503 | apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri); |
| 1504 | apic_write(APIC_SPIV, apic_pm_state.apic_spiv); |
| 1505 | apic_write(APIC_LVT0, apic_pm_state.apic_lvt0); |
| 1506 | apic_write(APIC_LVT1, apic_pm_state.apic_lvt1); |
| 1507 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 1508 | if (maxlvt >= 5) |
| 1509 | apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr); |
| 1510 | #endif |
| 1511 | if (maxlvt >= 4) |
| 1512 | apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc); |
| 1513 | apic_write(APIC_LVTT, apic_pm_state.apic_lvtt); |
| 1514 | apic_write(APIC_TDCR, apic_pm_state.apic_tdcr); |
| 1515 | apic_write(APIC_TMICT, apic_pm_state.apic_tmict); |
| 1516 | apic_write(APIC_ESR, 0); |
| 1517 | apic_read(APIC_ESR); |
| 1518 | apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr); |
| 1519 | apic_write(APIC_ESR, 0); |
| 1520 | apic_read(APIC_ESR); |
| 1521 | local_irq_restore(flags); |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
| 1525 | /* |
| 1526 | * This device has no shutdown method - fully functioning local APICs |
| 1527 | * are needed on every CPU up until machine_halt/restart/poweroff. |
| 1528 | */ |
| 1529 | |
| 1530 | static struct sysdev_class lapic_sysclass = { |
| 1531 | set_kset_name("lapic"), |
| 1532 | .resume = lapic_resume, |
| 1533 | .suspend = lapic_suspend, |
| 1534 | }; |
| 1535 | |
| 1536 | static struct sys_device device_lapic = { |
| 1537 | .id = 0, |
| 1538 | .cls = &lapic_sysclass, |
| 1539 | }; |
| 1540 | |
| 1541 | static void __devinit apic_pm_activate(void) |
| 1542 | { |
| 1543 | apic_pm_state.active = 1; |
| 1544 | } |
| 1545 | |
| 1546 | static int __init init_lapic_sysfs(void) |
| 1547 | { |
| 1548 | int error; |
| 1549 | |
| 1550 | if (!cpu_has_apic) |
| 1551 | return 0; |
| 1552 | /* XXX: remove suspend/resume procs if !apic_pm_state.active? */ |
| 1553 | |
| 1554 | error = sysdev_class_register(&lapic_sysclass); |
| 1555 | if (!error) |
| 1556 | error = sysdev_register(&device_lapic); |
| 1557 | return error; |
| 1558 | } |
| 1559 | device_initcall(init_lapic_sysfs); |
| 1560 | |
| 1561 | #else /* CONFIG_PM */ |
| 1562 | |
| 1563 | static void apic_pm_activate(void) { } |
| 1564 | |
| 1565 | #endif /* CONFIG_PM */ |