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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 47 | * Sanity check |
| 48 | */ |
Hiroshi Shimamoto | ff8a03a | 2008-01-30 13:32:36 +0100 | [diff] [blame] | 49 | #if ((SPURIOUS_APIC_VECTOR & 0x0F) != 0x0F) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 50 | # error SPURIOUS_APIC_VECTOR definition error |
| 51 | #endif |
| 52 | |
Alexey Starikovskiy | 8f6e2ca | 2008-03-27 23:54:38 +0300 | [diff] [blame] | 53 | unsigned long mp_lapic_addr; |
| 54 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 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 | * |
Yinghai Lu | 914bebf | 2008-06-29 00:06:37 -0700 | [diff] [blame] | 58 | * +1=force-enable |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 59 | */ |
Yinghai Lu | 914bebf | 2008-06-29 00:06:37 -0700 | [diff] [blame] | 60 | static int force_enable_local_apic; |
| 61 | int disable_apic; |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 62 | |
Thomas Gleixner | aa276e1 | 2008-06-09 19:15:00 +0200 | [diff] [blame] | 63 | /* Disable local APIC timer from the kernel commandline or via dmi quirk */ |
Cyrill Gorcunov | 36fef09 | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 64 | static int disable_apic_timer __cpuinitdata; |
Thomas Gleixner | e585bef | 2007-03-23 16:08:01 +0100 | [diff] [blame] | 65 | /* Local APIC timer works in C2 */ |
| 66 | int local_apic_timer_c2_ok; |
| 67 | EXPORT_SYMBOL_GPL(local_apic_timer_c2_ok); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 68 | |
Alan Mayer | ce17833 | 2008-04-16 15:17:20 -0500 | [diff] [blame] | 69 | int first_system_vector = 0xfe; |
| 70 | |
| 71 | char system_vectors[NR_VECTORS] = { [0 ... NR_VECTORS-1] = SYS_VECTOR_FREE}; |
| 72 | |
Eric W. Biederman | 9635b47 | 2005-06-25 14:57:41 -0700 | [diff] [blame] | 73 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 74 | * Debug level, exported for io_apic.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | */ |
Maciej W. Rozycki | baa1318 | 2008-07-14 18:44:51 +0100 | [diff] [blame] | 76 | unsigned int apic_verbosity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Alexey Starikovskiy | f391835 | 2008-05-23 01:54:51 +0400 | [diff] [blame] | 78 | int pic_mode; |
| 79 | |
Alexey Starikovskiy | bab4b27 | 2008-05-19 19:47:03 +0400 | [diff] [blame] | 80 | /* Have we found an MP table */ |
| 81 | int smp_found_config; |
| 82 | |
Cyrill Gorcunov | 746f2eb | 2008-07-01 21:43:52 +0400 | [diff] [blame] | 83 | static struct resource lapic_resource = { |
| 84 | .name = "Local APIC", |
| 85 | .flags = IORESOURCE_MEM | IORESOURCE_BUSY, |
| 86 | }; |
| 87 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 88 | static unsigned int calibration_result; |
| 89 | |
| 90 | static int lapic_next_event(unsigned long delta, |
| 91 | struct clock_event_device *evt); |
| 92 | static void lapic_timer_setup(enum clock_event_mode mode, |
| 93 | struct clock_event_device *evt); |
| 94 | static void lapic_timer_broadcast(cpumask_t mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static void apic_pm_activate(void); |
| 96 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 97 | /* |
| 98 | * The local apic timer can be used for any function which is CPU local. |
| 99 | */ |
| 100 | static struct clock_event_device lapic_clockevent = { |
| 101 | .name = "lapic", |
| 102 | .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 103 | | CLOCK_EVT_FEAT_C3STOP | CLOCK_EVT_FEAT_DUMMY, |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 104 | .shift = 32, |
| 105 | .set_mode = lapic_timer_setup, |
| 106 | .set_next_event = lapic_next_event, |
| 107 | .broadcast = lapic_timer_broadcast, |
| 108 | .rating = 100, |
| 109 | .irq = -1, |
| 110 | }; |
| 111 | static DEFINE_PER_CPU(struct clock_event_device, lapic_events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 113 | /* Local APIC was disabled by the BIOS and enabled by the kernel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static int enabled_via_apicbase; |
| 115 | |
Andi Kleen | d343289 | 2008-01-30 13:33:17 +0100 | [diff] [blame] | 116 | static unsigned long apic_phys; |
| 117 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 118 | /* |
| 119 | * Get the LAPIC version |
| 120 | */ |
| 121 | static inline int lapic_get_version(void) |
| 122 | { |
| 123 | return GET_APIC_VERSION(apic_read(APIC_LVR)); |
| 124 | } |
| 125 | |
| 126 | /* |
Joe Perches | ab4a574 | 2008-01-30 13:31:42 +0100 | [diff] [blame] | 127 | * Check, if the APIC is integrated or a separate chip |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 128 | */ |
| 129 | static inline int lapic_is_integrated(void) |
| 130 | { |
| 131 | return APIC_INTEGRATED(lapic_get_version()); |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Check, whether this is a modern or a first generation APIC |
| 136 | */ |
| 137 | static int modern_apic(void) |
| 138 | { |
| 139 | /* AMD systems use old APIC versions, so check the CPU */ |
| 140 | if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD && |
| 141 | boot_cpu_data.x86 >= 0xf) |
| 142 | return 1; |
| 143 | return lapic_get_version() >= 0x14; |
| 144 | } |
| 145 | |
Suresh Siddha | 9a8f0e6 | 2008-07-18 09:59:40 -0700 | [diff] [blame] | 146 | /* |
| 147 | * Paravirt kernels also might be using these below ops. So we still |
| 148 | * use generic apic_read()/apic_write(), which might be pointing to different |
| 149 | * ops in PARAVIRT case. |
| 150 | */ |
Yinghai Lu | c535b6a | 2008-07-11 18:41:54 -0700 | [diff] [blame] | 151 | void xapic_wait_icr_idle(void) |
Fernando Luis VazquezCao | f2b218d | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 152 | { |
| 153 | while (apic_read(APIC_ICR) & APIC_ICR_BUSY) |
| 154 | cpu_relax(); |
| 155 | } |
| 156 | |
Yinghai Lu | c535b6a | 2008-07-11 18:41:54 -0700 | [diff] [blame] | 157 | u32 safe_xapic_wait_icr_idle(void) |
Fernando Luis VazquezCao | f2b218d | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 158 | { |
Thomas Gleixner | 42e0a9a | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 159 | u32 send_status; |
Fernando Luis VazquezCao | f2b218d | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 160 | int timeout; |
| 161 | |
| 162 | timeout = 0; |
| 163 | do { |
| 164 | send_status = apic_read(APIC_ICR) & APIC_ICR_BUSY; |
| 165 | if (!send_status) |
| 166 | break; |
| 167 | udelay(100); |
| 168 | } while (timeout++ < 1000); |
| 169 | |
| 170 | return send_status; |
| 171 | } |
| 172 | |
Yinghai Lu | c535b6a | 2008-07-11 18:41:54 -0700 | [diff] [blame] | 173 | void xapic_icr_write(u32 low, u32 id) |
| 174 | { |
Suresh Siddha | f586bf7 | 2008-07-18 15:58:35 -0700 | [diff] [blame] | 175 | apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(id)); |
| 176 | apic_write(APIC_ICR, low); |
Yinghai Lu | c535b6a | 2008-07-11 18:41:54 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | u64 xapic_icr_read(void) |
| 180 | { |
| 181 | u32 icr1, icr2; |
| 182 | |
| 183 | icr2 = apic_read(APIC_ICR2); |
| 184 | icr1 = apic_read(APIC_ICR); |
| 185 | |
| 186 | return icr1 | ((u64)icr2 << 32); |
| 187 | } |
| 188 | |
| 189 | static struct apic_ops xapic_ops = { |
| 190 | .read = native_apic_mem_read, |
| 191 | .write = native_apic_mem_write, |
Yinghai Lu | c535b6a | 2008-07-11 18:41:54 -0700 | [diff] [blame] | 192 | .icr_read = xapic_icr_read, |
| 193 | .icr_write = xapic_icr_write, |
| 194 | .wait_icr_idle = xapic_wait_icr_idle, |
| 195 | .safe_wait_icr_idle = safe_xapic_wait_icr_idle, |
| 196 | }; |
| 197 | |
| 198 | struct apic_ops __read_mostly *apic_ops = &xapic_ops; |
| 199 | EXPORT_SYMBOL_GPL(apic_ops); |
| 200 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 201 | /** |
| 202 | * enable_NMI_through_LVT0 - enable NMI through local vector table 0 |
| 203 | */ |
Jan Beulich | e942710 | 2008-01-30 13:31:24 +0100 | [diff] [blame] | 204 | void __cpuinit enable_NMI_through_LVT0(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
Cyrill Gorcunov | d4c63ec | 2008-07-24 13:52:29 +0200 | [diff] [blame] | 206 | unsigned int v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Cyrill Gorcunov | d4c63ec | 2008-07-24 13:52:29 +0200 | [diff] [blame] | 208 | /* unmask and set to NMI */ |
| 209 | v = APIC_DM_NMI; |
| 210 | |
| 211 | /* Level triggered for 82489DX (32bit mode) */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 212 | if (!lapic_is_integrated()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | v |= APIC_LVT_LEVEL_TRIGGER; |
Cyrill Gorcunov | d4c63ec | 2008-07-24 13:52:29 +0200 | [diff] [blame] | 214 | |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 215 | apic_write(APIC_LVT0, v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 218 | /** |
| 219 | * get_physical_broadcast - Get number of physical broadcast IDs |
| 220 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | int get_physical_broadcast(void) |
| 222 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 223 | return modern_apic() ? 0xff : 0xf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 226 | /** |
| 227 | * lapic_get_maxlvt - get the maximum number of local vector table entries |
| 228 | */ |
| 229 | int lapic_get_maxlvt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Cyrill Gorcunov | 36a028d | 2008-07-24 13:52:28 +0200 | [diff] [blame] | 231 | unsigned int v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Cyrill Gorcunov | 36a028d | 2008-07-24 13:52:28 +0200 | [diff] [blame] | 233 | v = apic_read(APIC_LVR); |
| 234 | /* |
| 235 | * - we always have APIC integrated on 64bit mode |
| 236 | * - 82489DXs do not report # of LVT entries |
| 237 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 238 | return APIC_INTEGRATED(GET_APIC_VERSION(v)) ? GET_APIC_MAXLVT(v) : 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 242 | * Local APIC timer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 245 | /* Clock divisor is set to 16 */ |
| 246 | #define APIC_DIVISOR 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | /* |
| 249 | * This function sets up the local APIC timer, with a timeout of |
| 250 | * 'clocks' APIC bus clock. During calibration we actually call |
| 251 | * this function twice on the boot CPU, once with a bogus timeout |
| 252 | * value, second time for real. The other (noncalibrating) CPUs |
| 253 | * call this function only once, with the real, calibrated value. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 255 | static void __setup_APIC_LVTT(unsigned int clocks, int oneshot, int irqen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 257 | unsigned int lvtt_value, tmp_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 259 | lvtt_value = LOCAL_TIMER_VECTOR; |
| 260 | if (!oneshot) |
| 261 | lvtt_value |= APIC_LVT_TIMER_PERIODIC; |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 262 | if (!lapic_is_integrated()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | lvtt_value |= SET_APIC_TIMER_BASE(APIC_TIMER_BASE_DIV); |
Venkatesh Pallipadi | 6eb0a0f | 2006-01-11 22:44:21 +0100 | [diff] [blame] | 264 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 265 | if (!irqen) |
Venkatesh Pallipadi | 6eb0a0f | 2006-01-11 22:44:21 +0100 | [diff] [blame] | 266 | lvtt_value |= APIC_LVT_MASKED; |
| 267 | |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 268 | apic_write(APIC_LVTT, lvtt_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
| 270 | /* |
| 271 | * Divide PICLK by 16 |
| 272 | */ |
| 273 | tmp_value = apic_read(APIC_TDCR); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 274 | apic_write(APIC_TDCR, |
| 275 | (tmp_value & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE)) | |
| 276 | APIC_TDR_DIV_16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 278 | if (!oneshot) |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 279 | apic_write(APIC_TMICT, clocks / APIC_DIVISOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 282 | /* |
| 283 | * Program the next event, relative to now |
| 284 | */ |
| 285 | static int lapic_next_event(unsigned long delta, |
| 286 | struct clock_event_device *evt) |
| 287 | { |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 288 | apic_write(APIC_TMICT, delta); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Setup the lapic timer in periodic or oneshot mode |
| 294 | */ |
| 295 | static void lapic_timer_setup(enum clock_event_mode mode, |
| 296 | struct clock_event_device *evt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | { |
| 298 | unsigned long flags; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 299 | unsigned int v; |
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 | /* Lapic used for broadcast ? */ |
Cyrill Gorcunov | 64e474d | 2008-08-15 13:51:22 +0200 | [diff] [blame] | 302 | if (evt->features & CLOCK_EVT_FEAT_DUMMY) |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 303 | return; |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | local_irq_save(flags); |
| 306 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 307 | switch (mode) { |
| 308 | case CLOCK_EVT_MODE_PERIODIC: |
| 309 | case CLOCK_EVT_MODE_ONESHOT: |
| 310 | __setup_APIC_LVTT(calibration_result, |
| 311 | mode != CLOCK_EVT_MODE_PERIODIC, 1); |
| 312 | break; |
| 313 | case CLOCK_EVT_MODE_UNUSED: |
| 314 | case CLOCK_EVT_MODE_SHUTDOWN: |
| 315 | v = apic_read(APIC_LVTT); |
| 316 | v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 317 | apic_write(APIC_LVTT, v); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 318 | break; |
Thomas Gleixner | 18de5bc | 2007-07-21 04:37:34 -0700 | [diff] [blame] | 319 | case CLOCK_EVT_MODE_RESUME: |
| 320 | /* Nothing to do here */ |
| 321 | break; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | local_irq_restore(flags); |
| 325 | } |
| 326 | |
| 327 | /* |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 328 | * Local APIC timer broadcast function |
| 329 | */ |
| 330 | static void lapic_timer_broadcast(cpumask_t mask) |
| 331 | { |
| 332 | #ifdef CONFIG_SMP |
| 333 | send_IPI_mask(mask, LOCAL_TIMER_VECTOR); |
| 334 | #endif |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | * Setup the local APIC timer for this CPU. Copy the initilized values |
| 339 | * of the boot CPU and register the clock event in the framework. |
| 340 | */ |
| 341 | static void __devinit setup_APIC_timer(void) |
| 342 | { |
| 343 | struct clock_event_device *levt = &__get_cpu_var(lapic_events); |
| 344 | |
| 345 | memcpy(levt, &lapic_clockevent, sizeof(*levt)); |
| 346 | levt->cpumask = cpumask_of_cpu(smp_processor_id()); |
| 347 | |
| 348 | clockevents_register_device(levt); |
| 349 | } |
| 350 | |
| 351 | /* |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 352 | * In this functions we calibrate APIC bus clocks to the external timer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | * |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 354 | * We want to do the calibration only once since we want to have local timer |
| 355 | * irqs syncron. CPUs connected by the same APIC bus have the very same bus |
| 356 | * frequency. |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 357 | * |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 358 | * This was previously done by reading the PIT/HPET and waiting for a wrap |
| 359 | * around to find out, that a tick has elapsed. I have a box, where the PIT |
| 360 | * readout is broken, so it never gets out of the wait loop again. This was |
| 361 | * also reported by others. |
| 362 | * |
| 363 | * Monitoring the jiffies value is inaccurate and the clockevents |
| 364 | * infrastructure allows us to do a simple substitution of the interrupt |
| 365 | * handler. |
| 366 | * |
| 367 | * The calibration routine also uses the pm_timer when possible, as the PIT |
| 368 | * happens to run way too slow (factor 2.3 on my VAIO CoreDuo, which goes |
| 369 | * back to normal later in the boot process). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | */ |
| 371 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 372 | #define LAPIC_CAL_LOOPS (HZ/10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Thomas Gleixner | f5352fd | 2007-07-21 17:11:32 +0200 | [diff] [blame] | 374 | static __initdata int lapic_cal_loops = -1; |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 375 | static __initdata long lapic_cal_t1, lapic_cal_t2; |
| 376 | static __initdata unsigned long long lapic_cal_tsc1, lapic_cal_tsc2; |
| 377 | static __initdata unsigned long lapic_cal_pm1, lapic_cal_pm2; |
| 378 | static __initdata unsigned long lapic_cal_j1, lapic_cal_j2; |
| 379 | |
| 380 | /* |
| 381 | * Temporary interrupt handler. |
| 382 | */ |
| 383 | static void __init lapic_cal_handler(struct clock_event_device *dev) |
| 384 | { |
| 385 | unsigned long long tsc = 0; |
| 386 | long tapic = apic_read(APIC_TMCCT); |
| 387 | unsigned long pm = acpi_pm_read_early(); |
| 388 | |
| 389 | if (cpu_has_tsc) |
| 390 | rdtscll(tsc); |
| 391 | |
| 392 | switch (lapic_cal_loops++) { |
| 393 | case 0: |
| 394 | lapic_cal_t1 = tapic; |
| 395 | lapic_cal_tsc1 = tsc; |
| 396 | lapic_cal_pm1 = pm; |
| 397 | lapic_cal_j1 = jiffies; |
| 398 | break; |
| 399 | |
| 400 | case LAPIC_CAL_LOOPS: |
| 401 | lapic_cal_t2 = tapic; |
| 402 | lapic_cal_tsc2 = tsc; |
| 403 | if (pm < lapic_cal_pm1) |
| 404 | pm += ACPI_PM_OVRRUN; |
| 405 | lapic_cal_pm2 = pm; |
| 406 | lapic_cal_j2 = jiffies; |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | |
Cyrill Gorcunov | 836c129 | 2008-07-15 21:02:55 +0400 | [diff] [blame] | 411 | static int __init calibrate_APIC_clock(void) |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 412 | { |
| 413 | struct clock_event_device *levt = &__get_cpu_var(lapic_events); |
| 414 | const long pm_100ms = PMTMR_TICKS_PER_SEC/10; |
| 415 | const long pm_thresh = pm_100ms/100; |
| 416 | void (*real_handler)(struct clock_event_device *dev); |
| 417 | unsigned long deltaj; |
| 418 | long delta, deltapm; |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 419 | int pm_referenced = 0; |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 420 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 421 | local_irq_disable(); |
| 422 | |
| 423 | /* Replace the global interrupt handler */ |
| 424 | real_handler = global_clock_event->event_handler; |
| 425 | global_clock_event->event_handler = lapic_cal_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | /* |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 428 | * Setup the APIC counter to 1e9. There is no way the lapic |
| 429 | * can underflow in the 100ms detection time frame |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 431 | __setup_APIC_LVTT(1000000000, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 433 | /* Let the interrupts run */ |
| 434 | local_irq_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 436 | while (lapic_cal_loops <= LAPIC_CAL_LOOPS) |
| 437 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 439 | local_irq_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 441 | /* Restore the real event handler */ |
| 442 | global_clock_event->event_handler = real_handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 444 | /* Build delta t1-t2 as apic timer counts down */ |
| 445 | delta = lapic_cal_t1 - lapic_cal_t2; |
| 446 | apic_printk(APIC_VERBOSE, "... lapic delta = %ld\n", delta); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 448 | /* Check, if the PM timer is available */ |
| 449 | deltapm = lapic_cal_pm2 - lapic_cal_pm1; |
| 450 | apic_printk(APIC_VERBOSE, "... PM timer delta = %ld\n", deltapm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 452 | if (deltapm) { |
| 453 | unsigned long mult; |
| 454 | u64 res; |
| 455 | |
| 456 | mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC, 22); |
| 457 | |
| 458 | if (deltapm > (pm_100ms - pm_thresh) && |
| 459 | deltapm < (pm_100ms + pm_thresh)) { |
| 460 | apic_printk(APIC_VERBOSE, "... PM timer result ok\n"); |
| 461 | } else { |
| 462 | res = (((u64) deltapm) * mult) >> 22; |
| 463 | do_div(res, 1000000); |
| 464 | printk(KERN_WARNING "APIC calibration not consistent " |
| 465 | "with PM Timer: %ldms instead of 100ms\n", |
| 466 | (long)res); |
| 467 | /* Correct the lapic counter value */ |
Hiroshi Shimamoto | ff8a03a | 2008-01-30 13:32:36 +0100 | [diff] [blame] | 468 | res = (((u64) delta) * pm_100ms); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 469 | do_div(res, deltapm); |
| 470 | printk(KERN_INFO "APIC delta adjusted to PM-Timer: " |
| 471 | "%lu (%ld)\n", (unsigned long) res, delta); |
| 472 | delta = (long) res; |
| 473 | } |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 474 | pm_referenced = 1; |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 477 | /* Calculate the scaled math multiplication factor */ |
Akinobu Mita | 877084f | 2008-04-19 23:55:16 +0900 | [diff] [blame] | 478 | lapic_clockevent.mult = div_sc(delta, TICK_NSEC * LAPIC_CAL_LOOPS, |
| 479 | lapic_clockevent.shift); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 480 | lapic_clockevent.max_delta_ns = |
| 481 | clockevent_delta2ns(0x7FFFFF, &lapic_clockevent); |
| 482 | lapic_clockevent.min_delta_ns = |
| 483 | clockevent_delta2ns(0xF, &lapic_clockevent); |
| 484 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 485 | calibration_result = (delta * APIC_DIVISOR) / LAPIC_CAL_LOOPS; |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 486 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 487 | apic_printk(APIC_VERBOSE, "..... delta %ld\n", delta); |
| 488 | apic_printk(APIC_VERBOSE, "..... mult: %ld\n", lapic_clockevent.mult); |
| 489 | apic_printk(APIC_VERBOSE, "..... calibration result: %u\n", |
| 490 | calibration_result); |
| 491 | |
| 492 | if (cpu_has_tsc) { |
| 493 | delta = (long)(lapic_cal_tsc2 - lapic_cal_tsc1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | apic_printk(APIC_VERBOSE, "..... CPU clock speed is " |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 495 | "%ld.%04ld MHz.\n", |
| 496 | (delta / LAPIC_CAL_LOOPS) / (1000000 / HZ), |
| 497 | (delta / LAPIC_CAL_LOOPS) % (1000000 / HZ)); |
| 498 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | apic_printk(APIC_VERBOSE, "..... host bus clock speed is " |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 501 | "%u.%04u MHz.\n", |
| 502 | calibration_result / (1000000 / HZ), |
| 503 | calibration_result % (1000000 / HZ)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
Thomas Gleixner | c2b84b3 | 2008-01-30 13:33:04 +0100 | [diff] [blame] | 505 | /* |
| 506 | * Do a sanity check on the APIC calibration result |
| 507 | */ |
| 508 | if (calibration_result < (1000000 / HZ)) { |
| 509 | local_irq_enable(); |
| 510 | printk(KERN_WARNING |
| 511 | "APIC frequency too slow, disabling apic timer\n"); |
Cyrill Gorcunov | 836c129 | 2008-07-15 21:02:55 +0400 | [diff] [blame] | 512 | return -1; |
Thomas Gleixner | c2b84b3 | 2008-01-30 13:33:04 +0100 | [diff] [blame] | 513 | } |
| 514 | |
Cyrill Gorcunov | 64e474d | 2008-08-15 13:51:22 +0200 | [diff] [blame] | 515 | levt->features &= ~CLOCK_EVT_FEAT_DUMMY; |
Cyrill Gorcunov | 836c129 | 2008-07-15 21:02:55 +0400 | [diff] [blame] | 516 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 517 | /* We trust the pm timer based calibration */ |
| 518 | if (!pm_referenced) { |
| 519 | apic_printk(APIC_VERBOSE, "... verify APIC timer\n"); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 520 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 521 | /* |
| 522 | * Setup the apic timer manually |
| 523 | */ |
| 524 | levt->event_handler = lapic_cal_handler; |
| 525 | lapic_timer_setup(CLOCK_EVT_MODE_PERIODIC, levt); |
| 526 | lapic_cal_loops = -1; |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 527 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 528 | /* Let the interrupts run */ |
| 529 | local_irq_enable(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 530 | |
Thomas Gleixner | f5352fd | 2007-07-21 17:11:32 +0200 | [diff] [blame] | 531 | while (lapic_cal_loops <= LAPIC_CAL_LOOPS) |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 532 | cpu_relax(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 533 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 534 | local_irq_disable(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 535 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 536 | /* Stop the lapic timer */ |
| 537 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, levt); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 538 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 539 | local_irq_enable(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 540 | |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 541 | /* Jiffies delta */ |
| 542 | deltaj = lapic_cal_j2 - lapic_cal_j1; |
| 543 | apic_printk(APIC_VERBOSE, "... jiffies delta = %lu\n", deltaj); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 544 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 545 | /* Check, if the jiffies result is consistent */ |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 546 | if (deltaj >= LAPIC_CAL_LOOPS-2 && deltaj <= LAPIC_CAL_LOOPS+2) |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 547 | apic_printk(APIC_VERBOSE, "... jiffies result ok\n"); |
Thomas Gleixner | ca1b940 | 2007-03-18 01:26:13 -0800 | [diff] [blame] | 548 | else |
Cyrill Gorcunov | 64e474d | 2008-08-15 13:51:22 +0200 | [diff] [blame] | 549 | levt->features |= CLOCK_EVT_FEAT_DUMMY; |
Ingo Molnar | 4edc5db | 2007-03-22 10:31:19 +0100 | [diff] [blame] | 550 | } else |
| 551 | local_irq_enable(); |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 552 | |
Cyrill Gorcunov | 64e474d | 2008-08-15 13:51:22 +0200 | [diff] [blame] | 553 | if (levt->features & CLOCK_EVT_FEAT_DUMMY) { |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 554 | printk(KERN_WARNING |
| 555 | "APIC timer disabled due to verification failure.\n"); |
Cyrill Gorcunov | 836c129 | 2008-07-15 21:02:55 +0400 | [diff] [blame] | 556 | return -1; |
Thomas Gleixner | a5f5e43 | 2007-03-05 00:30:45 -0800 | [diff] [blame] | 557 | } |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 558 | |
Cyrill Gorcunov | 836c129 | 2008-07-15 21:02:55 +0400 | [diff] [blame] | 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * Setup the boot APIC |
| 564 | * |
| 565 | * Calibrate and verify the result. |
| 566 | */ |
| 567 | void __init setup_boot_APIC_clock(void) |
| 568 | { |
| 569 | /* |
| 570 | * The local apic timer can be disabled via the kernel |
| 571 | * commandline or from the CPU detection code. Register the lapic |
| 572 | * timer as a dummy clock event source on SMP systems, so the |
| 573 | * broadcast mechanism is used. On UP systems simply ignore it. |
| 574 | */ |
Cyrill Gorcunov | 36fef09 | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 575 | if (disable_apic_timer) { |
Cyrill Gorcunov | 836c129 | 2008-07-15 21:02:55 +0400 | [diff] [blame] | 576 | /* No broadcast on UP ! */ |
| 577 | if (num_possible_cpus() > 1) { |
| 578 | lapic_clockevent.mult = 1; |
| 579 | setup_APIC_timer(); |
| 580 | } |
| 581 | return; |
| 582 | } |
| 583 | |
| 584 | apic_printk(APIC_VERBOSE, "Using local APIC timer interrupts.\n" |
| 585 | "calibrating APIC timer ...\n"); |
| 586 | |
| 587 | if (calibrate_APIC_clock()) { |
| 588 | /* No broadcast on UP ! */ |
| 589 | if (num_possible_cpus() > 1) |
| 590 | setup_APIC_timer(); |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * If nmi_watchdog is set to IO_APIC, we need the |
| 596 | * PIT/HPET going. Otherwise register lapic as a dummy |
| 597 | * device. |
| 598 | */ |
| 599 | if (nmi_watchdog != NMI_IO_APIC) |
| 600 | lapic_clockevent.features &= ~CLOCK_EVT_FEAT_DUMMY; |
| 601 | else |
| 602 | printk(KERN_WARNING "APIC timer registered as dummy," |
| 603 | " due to nmi_watchdog=%d!\n", nmi_watchdog); |
| 604 | |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 605 | /* Setup the lapic or request the broadcast */ |
| 606 | setup_APIC_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Li Shaohua | 0bb3184 | 2005-06-25 14:54:55 -0700 | [diff] [blame] | 609 | void __devinit setup_secondary_APIC_clock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 611 | setup_APIC_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | /* |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 615 | * The guts of the apic timer interrupt |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 617 | static void local_apic_timer_interrupt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 619 | int cpu = smp_processor_id(); |
| 620 | struct clock_event_device *evt = &per_cpu(lapic_events, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | /* |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 623 | * Normally we should not be here till LAPIC has been initialized but |
| 624 | * in some cases like kdump, its possible that there is a pending LAPIC |
| 625 | * timer interrupt from previous kernel's context and is delivered in |
| 626 | * new kernel the moment interrupts are enabled. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | * |
Thomas Gleixner | d36b49b | 2007-02-16 01:28:06 -0800 | [diff] [blame] | 628 | * Interrupts are enabled early and LAPIC is setup much later, hence |
| 629 | * its possible that when we get here evt->event_handler is NULL. |
| 630 | * Check for event_handler being NULL and discard the interrupt as |
| 631 | * spurious. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 633 | if (!evt->event_handler) { |
| 634 | printk(KERN_WARNING |
| 635 | "Spurious LAPIC timer interrupt on cpu %d\n", cpu); |
| 636 | /* Switch it off */ |
| 637 | lapic_timer_setup(CLOCK_EVT_MODE_SHUTDOWN, evt); |
| 638 | return; |
| 639 | } |
| 640 | |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 641 | /* |
| 642 | * the NMI deadlock-detector uses this. |
| 643 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 644 | per_cpu(irq_stat, cpu).apic_timer_irqs++; |
| 645 | |
| 646 | evt->event_handler(evt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /* |
| 650 | * Local APIC timer interrupt. This is the most natural way for doing |
| 651 | * local interrupts, but local timer interrupts can be emulated by |
| 652 | * broadcast interrupts too. [in case the hw doesn't support APIC timers] |
| 653 | * |
| 654 | * [ if a single-CPU system runs an SMP kernel then we call the local |
| 655 | * interrupt as well. Thus we cannot inline the local irq ... ] |
| 656 | */ |
Harvey Harrison | 75604d7 | 2008-01-30 13:31:17 +0100 | [diff] [blame] | 657 | void smp_apic_timer_interrupt(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 659 | struct pt_regs *old_regs = set_irq_regs(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | /* |
| 662 | * NOTE! We'd better ACK the irq immediately, |
| 663 | * because timer handling can be slow. |
| 664 | */ |
| 665 | ack_APIC_irq(); |
| 666 | /* |
| 667 | * update_process_times() expects us to have done irq_enter(). |
| 668 | * Besides, if we don't timer interrupts ignore the global |
| 669 | * interrupt lock, which is the WrongThing (tm) to do. |
| 670 | */ |
| 671 | irq_enter(); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 672 | local_apic_timer_interrupt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | irq_exit(); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 674 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 675 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | |
Venkatesh Pallipadi | 5a07a30 | 2006-01-11 22:44:18 +0100 | [diff] [blame] | 678 | int setup_profiling_timer(unsigned int multiplier) |
| 679 | { |
| 680 | return -EINVAL; |
| 681 | } |
| 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | /* |
Robert Richter | e319e76 | 2008-02-13 16:19:36 +0100 | [diff] [blame] | 684 | * Setup extended LVT, AMD specific (K8, family 10h) |
| 685 | * |
| 686 | * Vector mappings are hard coded. On K8 only offset 0 (APIC500) and |
| 687 | * MCE interrupts are supported. Thus MCE offset must be set to 0. |
| 688 | */ |
| 689 | |
| 690 | #define APIC_EILVT_LVTOFF_MCE 0 |
| 691 | #define APIC_EILVT_LVTOFF_IBS 1 |
| 692 | |
| 693 | static void setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask) |
| 694 | { |
| 695 | unsigned long reg = (lvt_off << 4) + APIC_EILVT0; |
| 696 | unsigned int v = (mask << 16) | (msg_type << 8) | vector; |
| 697 | apic_write(reg, v); |
| 698 | } |
| 699 | |
| 700 | u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask) |
| 701 | { |
| 702 | setup_APIC_eilvt(APIC_EILVT_LVTOFF_MCE, vector, msg_type, mask); |
| 703 | return APIC_EILVT_LVTOFF_MCE; |
| 704 | } |
| 705 | |
| 706 | u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask) |
| 707 | { |
| 708 | setup_APIC_eilvt(APIC_EILVT_LVTOFF_IBS, vector, msg_type, mask); |
| 709 | return APIC_EILVT_LVTOFF_IBS; |
| 710 | } |
| 711 | |
| 712 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 713 | * Local APIC start and shutdown |
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 | |
| 716 | /** |
| 717 | * clear_local_APIC - shutdown the local APIC |
| 718 | * |
| 719 | * This is called, when a CPU is disabled and before rebooting, so the state of |
| 720 | * the local APIC has no dangling leftovers. Also used to cleanout any BIOS |
| 721 | * leftovers during boot. |
| 722 | */ |
| 723 | void clear_local_APIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { |
Andi Kleen | d343289 | 2008-01-30 13:33:17 +0100 | [diff] [blame] | 725 | int maxlvt; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 726 | u32 v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Andi Kleen | d343289 | 2008-01-30 13:33:17 +0100 | [diff] [blame] | 728 | /* APIC hasn't been mapped yet */ |
| 729 | if (!apic_phys) |
| 730 | return; |
| 731 | |
| 732 | maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 734 | * Masking an LVT entry can trigger a local APIC error |
| 735 | * if the vector is zero. Mask LVTERR first to prevent this. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 737 | if (maxlvt >= 3) { |
| 738 | v = ERROR_APIC_VECTOR; /* any non-zero vector will do */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 739 | apic_write(APIC_LVTERR, v | APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 740 | } |
| 741 | /* |
| 742 | * Careful: we have to set masks only first to deassert |
| 743 | * any level-triggered sources. |
| 744 | */ |
| 745 | v = apic_read(APIC_LVTT); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 746 | apic_write(APIC_LVTT, v | APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 747 | v = apic_read(APIC_LVT0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 748 | apic_write(APIC_LVT0, v | APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 749 | v = apic_read(APIC_LVT1); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 750 | apic_write(APIC_LVT1, v | APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 751 | if (maxlvt >= 4) { |
| 752 | v = apic_read(APIC_LVTPC); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 753 | apic_write(APIC_LVTPC, v | APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 756 | /* lets not touch this if we didn't frob it */ |
| 757 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 758 | if (maxlvt >= 5) { |
| 759 | v = apic_read(APIC_LVTTHMR); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 760 | apic_write(APIC_LVTTHMR, v | APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 761 | } |
| 762 | #endif |
| 763 | /* |
| 764 | * Clean APIC state for other OSs: |
| 765 | */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 766 | apic_write(APIC_LVTT, APIC_LVT_MASKED); |
| 767 | apic_write(APIC_LVT0, APIC_LVT_MASKED); |
| 768 | apic_write(APIC_LVT1, APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 769 | if (maxlvt >= 3) |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 770 | apic_write(APIC_LVTERR, APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 771 | if (maxlvt >= 4) |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 772 | apic_write(APIC_LVTPC, APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 773 | |
| 774 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 775 | if (maxlvt >= 5) |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 776 | apic_write(APIC_LVTTHMR, APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 777 | #endif |
| 778 | /* Integrated APIC (!82489DX) ? */ |
| 779 | if (lapic_is_integrated()) { |
| 780 | if (maxlvt > 3) |
| 781 | /* Clear ESR due to Pentium errata 3AP and 11AP */ |
| 782 | apic_write(APIC_ESR, 0); |
| 783 | apic_read(APIC_ESR); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * disable_local_APIC - clear and disable the local APIC |
| 789 | */ |
| 790 | void disable_local_APIC(void) |
| 791 | { |
| 792 | unsigned long value; |
| 793 | |
| 794 | clear_local_APIC(); |
| 795 | |
| 796 | /* |
| 797 | * Disable APIC (implies clearing of registers |
| 798 | * for 82489DX!). |
| 799 | */ |
| 800 | value = apic_read(APIC_SPIV); |
| 801 | value &= ~APIC_SPIV_APIC_ENABLED; |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 802 | apic_write(APIC_SPIV, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 803 | |
| 804 | /* |
| 805 | * When LAPIC was disabled by the BIOS and enabled by the kernel, |
| 806 | * restore the disabled state. |
| 807 | */ |
| 808 | if (enabled_via_apicbase) { |
| 809 | unsigned int l, h; |
| 810 | |
| 811 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 812 | l &= ~MSR_IA32_APICBASE_ENABLE; |
| 813 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 814 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 818 | * If Linux enabled the LAPIC against the BIOS default disable it down before |
| 819 | * re-entering the BIOS on shutdown. Otherwise the BIOS may get confused and |
| 820 | * not power-off. Additionally clear all LVT entries before disable_local_APIC |
| 821 | * for the case where Linux didn't enable the LAPIC. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 823 | void lapic_shutdown(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 825 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 827 | if (!cpu_has_apic) |
| 828 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 830 | local_irq_save(flags); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 831 | |
| 832 | if (enabled_via_apicbase) |
| 833 | disable_local_APIC(); |
Cyrill Gorcunov | 9ce122c | 2008-08-15 13:51:21 +0200 | [diff] [blame] | 834 | else |
| 835 | clear_local_APIC(); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 836 | |
| 837 | local_irq_restore(flags); |
| 838 | } |
| 839 | |
| 840 | /* |
| 841 | * This is to verify that we're looking at a real local APIC. |
| 842 | * Check these against your board if the CPUs aren't getting |
| 843 | * started for no apparent reason. |
| 844 | */ |
| 845 | int __init verify_local_APIC(void) |
| 846 | { |
| 847 | unsigned int reg0, reg1; |
| 848 | |
| 849 | /* |
| 850 | * The version register is read-only in a real APIC. |
| 851 | */ |
| 852 | reg0 = apic_read(APIC_LVR); |
| 853 | apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0); |
| 854 | apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK); |
| 855 | reg1 = apic_read(APIC_LVR); |
| 856 | apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1); |
| 857 | |
| 858 | /* |
| 859 | * The two version reads above should print the same |
| 860 | * numbers. If the second one is different, then we |
| 861 | * poke at a non-APIC. |
| 862 | */ |
| 863 | if (reg1 != reg0) |
| 864 | return 0; |
| 865 | |
| 866 | /* |
| 867 | * Check if the version looks reasonably. |
| 868 | */ |
| 869 | reg1 = GET_APIC_VERSION(reg0); |
| 870 | if (reg1 == 0x00 || reg1 == 0xff) |
| 871 | return 0; |
| 872 | reg1 = lapic_get_maxlvt(); |
| 873 | if (reg1 < 0x02 || reg1 == 0xff) |
| 874 | return 0; |
| 875 | |
| 876 | /* |
| 877 | * The ID register is read/write in a real APIC. |
| 878 | */ |
| 879 | reg0 = apic_read(APIC_ID); |
| 880 | apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0); |
Cyrill Gorcunov | c93baa1 | 2008-08-15 13:51:22 +0200 | [diff] [blame^] | 881 | apic_write(APIC_ID, reg0 ^ APIC_ID_MASK); |
| 882 | reg1 = apic_read(APIC_ID); |
| 883 | apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg1); |
| 884 | apic_write(APIC_ID, reg0); |
| 885 | if (reg1 != (reg0 ^ APIC_ID_MASK)) |
| 886 | return 0; |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 887 | |
| 888 | /* |
| 889 | * The next two are just to see if we have sane values. |
| 890 | * They're only really relevant if we're in Virtual Wire |
| 891 | * compatibility mode, but most boxes are anymore. |
| 892 | */ |
| 893 | reg0 = apic_read(APIC_LVT0); |
| 894 | apic_printk(APIC_DEBUG, "Getting LVT0: %x\n", reg0); |
| 895 | reg1 = apic_read(APIC_LVT1); |
| 896 | apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1); |
| 897 | |
| 898 | return 1; |
| 899 | } |
| 900 | |
| 901 | /** |
| 902 | * sync_Arb_IDs - synchronize APIC bus arbitration IDs |
| 903 | */ |
| 904 | void __init sync_Arb_IDs(void) |
| 905 | { |
| 906 | /* |
| 907 | * Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 And not |
| 908 | * needed on AMD. |
| 909 | */ |
Ingo Molnar | f44d9ef | 2007-11-26 20:42:20 +0100 | [diff] [blame] | 910 | if (modern_apic() || boot_cpu_data.x86_vendor == X86_VENDOR_AMD) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 911 | return; |
| 912 | /* |
| 913 | * Wait for idle. |
| 914 | */ |
| 915 | apic_wait_icr_idle(); |
| 916 | |
| 917 | apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n"); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 918 | apic_write(APIC_ICR, |
| 919 | APIC_DEST_ALLINC | APIC_INT_LEVELTRIG | APIC_DM_INIT); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | /* |
| 923 | * An initial setup of the virtual wire mode. |
| 924 | */ |
| 925 | void __init init_bsp_APIC(void) |
| 926 | { |
| 927 | unsigned long value; |
| 928 | |
| 929 | /* |
| 930 | * Don't do the setup now if we have a SMP BIOS as the |
| 931 | * through-I/O-APIC virtual wire mode might be active. |
| 932 | */ |
| 933 | if (smp_found_config || !cpu_has_apic) |
| 934 | return; |
| 935 | |
| 936 | /* |
| 937 | * Do not trust the local APIC being empty at bootup. |
| 938 | */ |
| 939 | clear_local_APIC(); |
| 940 | |
| 941 | /* |
| 942 | * Enable APIC. |
| 943 | */ |
| 944 | value = apic_read(APIC_SPIV); |
| 945 | value &= ~APIC_VECTOR_MASK; |
| 946 | value |= APIC_SPIV_APIC_ENABLED; |
| 947 | |
| 948 | /* This bit is reserved on P4/Xeon and should be cleared */ |
| 949 | if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) && |
| 950 | (boot_cpu_data.x86 == 15)) |
| 951 | value &= ~APIC_SPIV_FOCUS_DISABLED; |
| 952 | else |
| 953 | value |= APIC_SPIV_FOCUS_DISABLED; |
| 954 | value |= SPURIOUS_APIC_VECTOR; |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 955 | apic_write(APIC_SPIV, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 956 | |
| 957 | /* |
| 958 | * Set up the virtual wire mode. |
| 959 | */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 960 | apic_write(APIC_LVT0, APIC_DM_EXTINT); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 961 | value = APIC_DM_NMI; |
| 962 | if (!lapic_is_integrated()) /* 82489DX */ |
| 963 | value |= APIC_LVT_LEVEL_TRIGGER; |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 964 | apic_write(APIC_LVT1, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 965 | } |
| 966 | |
Ingo Molnar | a4928cf | 2008-04-23 13:20:56 +0200 | [diff] [blame] | 967 | static void __cpuinit lapic_setup_esr(void) |
Glauber de Oliveira Costa | df7939a | 2008-03-19 14:25:48 -0300 | [diff] [blame] | 968 | { |
| 969 | unsigned long oldvalue, value, maxlvt; |
| 970 | if (lapic_is_integrated() && !esr_disable) { |
| 971 | /* !82489DX */ |
| 972 | maxlvt = lapic_get_maxlvt(); |
| 973 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
| 974 | apic_write(APIC_ESR, 0); |
| 975 | oldvalue = apic_read(APIC_ESR); |
| 976 | |
| 977 | /* enables sending errors */ |
| 978 | value = ERROR_APIC_VECTOR; |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 979 | apic_write(APIC_LVTERR, value); |
Glauber de Oliveira Costa | df7939a | 2008-03-19 14:25:48 -0300 | [diff] [blame] | 980 | /* |
| 981 | * spec says clear errors after enabling vector. |
| 982 | */ |
| 983 | if (maxlvt > 3) |
| 984 | apic_write(APIC_ESR, 0); |
| 985 | value = apic_read(APIC_ESR); |
| 986 | if (value != oldvalue) |
| 987 | apic_printk(APIC_VERBOSE, "ESR value before enabling " |
| 988 | "vector: 0x%08lx after: 0x%08lx\n", |
| 989 | oldvalue, value); |
| 990 | } else { |
| 991 | if (esr_disable) |
| 992 | /* |
| 993 | * Something untraceable is creating bad interrupts on |
| 994 | * secondary quads ... for the moment, just leave the |
| 995 | * ESR disabled - we can't do anything useful with the |
| 996 | * errors anyway - mbligh |
| 997 | */ |
| 998 | printk(KERN_INFO "Leaving ESR disabled.\n"); |
| 999 | else |
| 1000 | printk(KERN_INFO "No ESR for 82489DX.\n"); |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1005 | /** |
| 1006 | * setup_local_APIC - setup the local APIC |
| 1007 | */ |
Adrian Bunk | d533798 | 2007-12-19 23:20:18 +0100 | [diff] [blame] | 1008 | void __cpuinit setup_local_APIC(void) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1009 | { |
Glauber de Oliveira Costa | df7939a | 2008-03-19 14:25:48 -0300 | [diff] [blame] | 1010 | unsigned long value, integrated; |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1011 | int i, j; |
| 1012 | |
| 1013 | /* Pound the ESR really hard over the head with a big hammer - mbligh */ |
| 1014 | if (esr_disable) { |
| 1015 | apic_write(APIC_ESR, 0); |
| 1016 | apic_write(APIC_ESR, 0); |
| 1017 | apic_write(APIC_ESR, 0); |
| 1018 | apic_write(APIC_ESR, 0); |
| 1019 | } |
| 1020 | |
| 1021 | integrated = lapic_is_integrated(); |
| 1022 | |
| 1023 | /* |
| 1024 | * Double-check whether this APIC is really registered. |
| 1025 | */ |
| 1026 | if (!apic_id_registered()) |
Ingo Molnar | 22d5c67 | 2008-07-10 16:29:28 +0200 | [diff] [blame] | 1027 | WARN_ON_ONCE(1); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1028 | |
| 1029 | /* |
| 1030 | * Intel recommends to set DFR, LDR and TPR before enabling |
| 1031 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
| 1032 | * document number 292116). So here it goes... |
| 1033 | */ |
| 1034 | init_apic_ldr(); |
| 1035 | |
| 1036 | /* |
| 1037 | * Set Task Priority to 'accept all'. We never change this |
| 1038 | * later on. |
| 1039 | */ |
| 1040 | value = apic_read(APIC_TASKPRI); |
| 1041 | value &= ~APIC_TPRI_MASK; |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1042 | apic_write(APIC_TASKPRI, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1043 | |
| 1044 | /* |
| 1045 | * After a crash, we no longer service the interrupts and a pending |
| 1046 | * interrupt from previous kernel might still have ISR bit set. |
| 1047 | * |
| 1048 | * Most probably by now CPU has serviced that pending interrupt and |
| 1049 | * it might not have done the ack_APIC_irq() because it thought, |
| 1050 | * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it |
| 1051 | * does not clear the ISR bit and cpu thinks it has already serivced |
| 1052 | * the interrupt. Hence a vector might get locked. It was noticed |
| 1053 | * for timer irq (vector 0x31). Issue an extra EOI to clear ISR. |
| 1054 | */ |
| 1055 | for (i = APIC_ISR_NR - 1; i >= 0; i--) { |
| 1056 | value = apic_read(APIC_ISR + i*0x10); |
| 1057 | for (j = 31; j >= 0; j--) { |
| 1058 | if (value & (1<<j)) |
| 1059 | ack_APIC_irq(); |
| 1060 | } |
| 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | * Now that we are all set up, enable the APIC |
| 1065 | */ |
| 1066 | value = apic_read(APIC_SPIV); |
| 1067 | value &= ~APIC_VECTOR_MASK; |
| 1068 | /* |
| 1069 | * Enable APIC |
| 1070 | */ |
| 1071 | value |= APIC_SPIV_APIC_ENABLED; |
| 1072 | |
| 1073 | /* |
| 1074 | * Some unknown Intel IO/APIC (or APIC) errata is biting us with |
| 1075 | * certain networking cards. If high frequency interrupts are |
| 1076 | * happening on a particular IOAPIC pin, plus the IOAPIC routing |
| 1077 | * entry is masked/unmasked at a high rate as well then sooner or |
| 1078 | * later IOAPIC line gets 'stuck', no more interrupts are received |
| 1079 | * from the device. If focus CPU is disabled then the hang goes |
| 1080 | * away, oh well :-( |
| 1081 | * |
| 1082 | * [ This bug can be reproduced easily with a level-triggered |
| 1083 | * PCI Ne2000 networking cards and PII/PIII processors, dual |
| 1084 | * BX chipset. ] |
| 1085 | */ |
| 1086 | /* |
| 1087 | * Actually disabling the focus CPU check just makes the hang less |
| 1088 | * frequent as it makes the interrupt distributon model be more |
| 1089 | * like LRU than MRU (the short-term load is more even across CPUs). |
| 1090 | * See also the comment in end_level_ioapic_irq(). --macro |
| 1091 | */ |
| 1092 | |
| 1093 | /* Enable focus processor (bit==0) */ |
| 1094 | value &= ~APIC_SPIV_FOCUS_DISABLED; |
| 1095 | |
| 1096 | /* |
| 1097 | * Set spurious IRQ vector |
| 1098 | */ |
| 1099 | value |= SPURIOUS_APIC_VECTOR; |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1100 | apic_write(APIC_SPIV, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1101 | |
| 1102 | /* |
| 1103 | * Set up LVT0, LVT1: |
| 1104 | * |
| 1105 | * set up through-local-APIC on the BP's LINT0. This is not |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 1106 | * strictly necessary in pure symmetric-IO mode, but sometimes |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1107 | * we delegate interrupts to the 8259A. |
| 1108 | */ |
| 1109 | /* |
| 1110 | * TODO: set up through-local-APIC from through-I/O-APIC? --macro |
| 1111 | */ |
| 1112 | value = apic_read(APIC_LVT0) & APIC_LVT_MASKED; |
| 1113 | if (!smp_processor_id() && (pic_mode || !value)) { |
| 1114 | value = APIC_DM_EXTINT; |
| 1115 | apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", |
| 1116 | smp_processor_id()); |
| 1117 | } else { |
| 1118 | value = APIC_DM_EXTINT | APIC_LVT_MASKED; |
| 1119 | apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", |
| 1120 | smp_processor_id()); |
| 1121 | } |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1122 | apic_write(APIC_LVT0, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1123 | |
| 1124 | /* |
| 1125 | * only the BP should see the LINT1 NMI signal, obviously. |
| 1126 | */ |
| 1127 | if (!smp_processor_id()) |
| 1128 | value = APIC_DM_NMI; |
| 1129 | else |
| 1130 | value = APIC_DM_NMI | APIC_LVT_MASKED; |
| 1131 | if (!integrated) /* 82489DX */ |
| 1132 | value |= APIC_LVT_LEVEL_TRIGGER; |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1133 | apic_write(APIC_LVT1, value); |
Glauber de Oliveira Costa | ac60aae | 2008-03-19 14:25:49 -0300 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | void __cpuinit end_local_APIC_setup(void) |
| 1137 | { |
| 1138 | unsigned long value; |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1139 | |
Glauber de Oliveira Costa | df7939a | 2008-03-19 14:25:48 -0300 | [diff] [blame] | 1140 | lapic_setup_esr(); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1141 | /* Disable the local apic timer */ |
| 1142 | value = apic_read(APIC_LVTT); |
| 1143 | value |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1144 | apic_write(APIC_LVTT, value); |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1145 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1146 | setup_apic_nmi_watchdog(NULL); |
| 1147 | apic_pm_activate(); |
| 1148 | } |
| 1149 | |
| 1150 | /* |
| 1151 | * Detect and initialize APIC |
| 1152 | */ |
Hiroshi Shimamoto | e83a5fd | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 1153 | static int __init detect_init_APIC(void) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1154 | { |
| 1155 | u32 h, l, features; |
| 1156 | |
| 1157 | /* Disabled by kernel option? */ |
Yinghai Lu | 914bebf | 2008-06-29 00:06:37 -0700 | [diff] [blame] | 1158 | if (disable_apic) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1159 | return -1; |
| 1160 | |
| 1161 | switch (boot_cpu_data.x86_vendor) { |
| 1162 | case X86_VENDOR_AMD: |
| 1163 | if ((boot_cpu_data.x86 == 6 && boot_cpu_data.x86_model > 1) || |
| 1164 | (boot_cpu_data.x86 == 15)) |
| 1165 | break; |
| 1166 | goto no_apic; |
| 1167 | case X86_VENDOR_INTEL: |
| 1168 | if (boot_cpu_data.x86 == 6 || boot_cpu_data.x86 == 15 || |
| 1169 | (boot_cpu_data.x86 == 5 && cpu_has_apic)) |
| 1170 | break; |
| 1171 | goto no_apic; |
| 1172 | default: |
| 1173 | goto no_apic; |
| 1174 | } |
| 1175 | |
| 1176 | if (!cpu_has_apic) { |
| 1177 | /* |
| 1178 | * Over-ride BIOS and try to enable the local APIC only if |
| 1179 | * "lapic" specified. |
| 1180 | */ |
Yinghai Lu | 914bebf | 2008-06-29 00:06:37 -0700 | [diff] [blame] | 1181 | if (!force_enable_local_apic) { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1182 | printk(KERN_INFO "Local APIC disabled by BIOS -- " |
| 1183 | "you can enable it with \"lapic\"\n"); |
| 1184 | return -1; |
| 1185 | } |
| 1186 | /* |
| 1187 | * Some BIOSes disable the local APIC in the APIC_BASE |
| 1188 | * MSR. This can only be done in software for Intel P6 or later |
| 1189 | * and AMD K7 (Model > 1) or later. |
| 1190 | */ |
| 1191 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1192 | if (!(l & MSR_IA32_APICBASE_ENABLE)) { |
| 1193 | printk(KERN_INFO |
| 1194 | "Local APIC disabled by BIOS -- reenabling.\n"); |
| 1195 | l &= ~MSR_IA32_APICBASE_BASE; |
| 1196 | l |= MSR_IA32_APICBASE_ENABLE | APIC_DEFAULT_PHYS_BASE; |
| 1197 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 1198 | enabled_via_apicbase = 1; |
| 1199 | } |
| 1200 | } |
| 1201 | /* |
| 1202 | * The APIC feature bit should now be enabled |
| 1203 | * in `cpuid' |
| 1204 | */ |
| 1205 | features = cpuid_edx(1); |
| 1206 | if (!(features & (1 << X86_FEATURE_APIC))) { |
| 1207 | printk(KERN_WARNING "Could not enable APIC!\n"); |
| 1208 | return -1; |
| 1209 | } |
Jeremy Fitzhardinge | 53756d3 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 1210 | set_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1211 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 1212 | |
| 1213 | /* The BIOS may have set up the APIC at some other address */ |
| 1214 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1215 | if (l & MSR_IA32_APICBASE_ENABLE) |
| 1216 | mp_lapic_addr = l & MSR_IA32_APICBASE_BASE; |
| 1217 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1218 | printk(KERN_INFO "Found and enabled local APIC!\n"); |
| 1219 | |
| 1220 | apic_pm_activate(); |
| 1221 | |
| 1222 | return 0; |
| 1223 | |
| 1224 | no_apic: |
| 1225 | printk(KERN_INFO "No local APIC present or hardware disabled\n"); |
| 1226 | return -1; |
| 1227 | } |
| 1228 | |
| 1229 | /** |
| 1230 | * init_apic_mappings - initialize APIC mappings |
| 1231 | */ |
| 1232 | void __init init_apic_mappings(void) |
| 1233 | { |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1234 | /* |
| 1235 | * If no local APIC can be found then set up a fake all |
| 1236 | * zeroes page to simulate the local APIC and another |
| 1237 | * one for the IO-APIC. |
| 1238 | */ |
| 1239 | if (!smp_found_config && detect_init_APIC()) { |
| 1240 | apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE); |
| 1241 | apic_phys = __pa(apic_phys); |
| 1242 | } else |
| 1243 | apic_phys = mp_lapic_addr; |
| 1244 | |
| 1245 | set_fixmap_nocache(FIX_APIC_BASE, apic_phys); |
| 1246 | printk(KERN_DEBUG "mapped APIC to %08lx (%08lx)\n", APIC_BASE, |
| 1247 | apic_phys); |
| 1248 | |
| 1249 | /* |
| 1250 | * Fetch the APIC ID of the BSP in case we have a |
| 1251 | * default configuration (or the MP table is broken). |
| 1252 | */ |
| 1253 | if (boot_cpu_physical_apicid == -1U) |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 1254 | boot_cpu_physical_apicid = read_apic_id(); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | /* |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1259 | * This initializes the IO-APIC and APIC hardware if this is |
| 1260 | * a UP kernel. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | */ |
Alexey Starikovskiy | e81b2c6 | 2008-03-27 23:54:31 +0300 | [diff] [blame] | 1262 | |
| 1263 | int apic_version[MAX_APICS]; |
| 1264 | |
Hiroshi Shimamoto | e83a5fd | 2008-01-30 13:32:35 +0100 | [diff] [blame] | 1265 | int __init APIC_init_uniprocessor(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | { |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1267 | if (!smp_found_config && !cpu_has_apic) |
Eric W. Biederman | f2b36db | 2005-10-30 14:59:41 -0800 | [diff] [blame] | 1268 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
| 1270 | /* |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1271 | * Complain if the BIOS pretends there is one. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1273 | if (!cpu_has_apic && |
| 1274 | APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n", |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1276 | boot_cpu_physical_apicid); |
Jeremy Fitzhardinge | 53756d3 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 1277 | clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | return -1; |
| 1279 | } |
| 1280 | |
| 1281 | verify_local_APIC(); |
| 1282 | |
| 1283 | connect_bsp_APIC(); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1284 | |
Vivek Goyal | be0d03f | 2006-05-20 15:00:21 -0700 | [diff] [blame] | 1285 | /* |
| 1286 | * Hack: In case of kdump, after a crash, kernel might be booting |
| 1287 | * on a cpu with non-zero lapic id. But boot_cpu_physical_apicid |
| 1288 | * might be zero if read from MP tables. Get it from LAPIC. |
| 1289 | */ |
| 1290 | #ifdef CONFIG_CRASH_DUMP |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 1291 | boot_cpu_physical_apicid = read_apic_id(); |
Vivek Goyal | be0d03f | 2006-05-20 15:00:21 -0700 | [diff] [blame] | 1292 | #endif |
Jack Steiner | b6df1b8 | 2008-06-19 21:51:05 -0500 | [diff] [blame] | 1293 | physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | setup_local_APIC(); |
| 1296 | |
Maciej W. Rozycki | acae7d9 | 2008-06-06 03:27:49 +0100 | [diff] [blame] | 1297 | #ifdef CONFIG_X86_IO_APIC |
| 1298 | if (!smp_found_config || skip_ioapic_setup || !nr_ioapics) |
| 1299 | #endif |
| 1300 | localise_nmi_watchdog(); |
Glauber de Oliveira Costa | ac60aae | 2008-03-19 14:25:49 -0300 | [diff] [blame] | 1301 | end_local_APIC_setup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | #ifdef CONFIG_X86_IO_APIC |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1303 | if (smp_found_config) |
| 1304 | if (!skip_ioapic_setup && nr_ioapics) |
| 1305 | setup_IO_APIC(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | #endif |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1307 | setup_boot_clock(); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 1308 | |
| 1309 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | } |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1311 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1312 | /* |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1313 | * Local APIC interrupts |
| 1314 | */ |
| 1315 | |
| 1316 | /* |
| 1317 | * This interrupt should _never_ happen with our APIC/SMP architecture |
| 1318 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1319 | void smp_spurious_interrupt(struct pt_regs *regs) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1320 | { |
| 1321 | unsigned long v; |
| 1322 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1323 | irq_enter(); |
| 1324 | /* |
| 1325 | * Check if this really is a spurious interrupt and ACK it |
| 1326 | * if it is a vectored one. Just in case... |
| 1327 | * Spurious interrupts should not be ACKed. |
| 1328 | */ |
| 1329 | v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1)); |
| 1330 | if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f))) |
| 1331 | ack_APIC_irq(); |
| 1332 | |
| 1333 | /* see sw-dev-man vol 3, chapter 7.4.13.5 */ |
| 1334 | printk(KERN_INFO "spurious APIC interrupt on CPU#%d, " |
| 1335 | "should never happen.\n", smp_processor_id()); |
Joe Korty | 38e760a | 2007-10-17 18:04:40 +0200 | [diff] [blame] | 1336 | __get_cpu_var(irq_stat).irq_spurious_count++; |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1337 | irq_exit(); |
| 1338 | } |
| 1339 | |
| 1340 | /* |
| 1341 | * This interrupt should never happen with our APIC/SMP architecture |
| 1342 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 1343 | void smp_error_interrupt(struct pt_regs *regs) |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1344 | { |
| 1345 | unsigned long v, v1; |
| 1346 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1347 | irq_enter(); |
| 1348 | /* First tickle the hardware, only then report what went on. -- REW */ |
| 1349 | v = apic_read(APIC_ESR); |
| 1350 | apic_write(APIC_ESR, 0); |
| 1351 | v1 = apic_read(APIC_ESR); |
| 1352 | ack_APIC_irq(); |
| 1353 | atomic_inc(&irq_err_count); |
| 1354 | |
| 1355 | /* Here is what the APIC error bits mean: |
| 1356 | 0: Send CS error |
| 1357 | 1: Receive CS error |
| 1358 | 2: Send accept error |
| 1359 | 3: Receive accept error |
| 1360 | 4: Reserved |
| 1361 | 5: Send illegal vector |
| 1362 | 6: Received illegal vector |
| 1363 | 7: Illegal register address |
| 1364 | */ |
Hiroshi Shimamoto | ff8a03a | 2008-01-30 13:32:36 +0100 | [diff] [blame] | 1365 | printk(KERN_DEBUG "APIC error on CPU%d: %02lx(%02lx)\n", |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1366 | smp_processor_id(), v , v1); |
| 1367 | irq_exit(); |
| 1368 | } |
| 1369 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1370 | /** |
| 1371 | * connect_bsp_APIC - attach the APIC to the interrupt system |
| 1372 | */ |
| 1373 | void __init connect_bsp_APIC(void) |
| 1374 | { |
| 1375 | if (pic_mode) { |
| 1376 | /* |
| 1377 | * Do not trust the local APIC being empty at bootup. |
| 1378 | */ |
| 1379 | clear_local_APIC(); |
| 1380 | /* |
| 1381 | * PIC mode, enable APIC mode in the IMCR, i.e. connect BSP's |
| 1382 | * local APIC to INT and NMI lines. |
| 1383 | */ |
| 1384 | apic_printk(APIC_VERBOSE, "leaving PIC mode, " |
| 1385 | "enabling APIC mode.\n"); |
| 1386 | outb(0x70, 0x22); |
| 1387 | outb(0x01, 0x23); |
| 1388 | } |
| 1389 | enable_apic_mode(); |
| 1390 | } |
| 1391 | |
| 1392 | /** |
| 1393 | * disconnect_bsp_APIC - detach the APIC from the interrupt system |
| 1394 | * @virt_wire_setup: indicates, whether virtual wire mode is selected |
| 1395 | * |
| 1396 | * Virtual wire mode is necessary to deliver legacy interrupts even when the |
| 1397 | * APIC is disabled. |
| 1398 | */ |
| 1399 | void disconnect_bsp_APIC(int virt_wire_setup) |
| 1400 | { |
| 1401 | if (pic_mode) { |
| 1402 | /* |
| 1403 | * Put the board back into PIC mode (has an effect only on |
| 1404 | * certain older boards). Note that APIC interrupts, including |
| 1405 | * IPIs, won't work beyond this point! The only exception are |
| 1406 | * INIT IPIs. |
| 1407 | */ |
| 1408 | apic_printk(APIC_VERBOSE, "disabling APIC mode, " |
| 1409 | "entering PIC mode.\n"); |
| 1410 | outb(0x70, 0x22); |
| 1411 | outb(0x00, 0x23); |
| 1412 | } else { |
| 1413 | /* Go back to Virtual Wire compatibility mode */ |
| 1414 | unsigned long value; |
| 1415 | |
| 1416 | /* For the spurious interrupt use vector F, and enable it */ |
| 1417 | value = apic_read(APIC_SPIV); |
| 1418 | value &= ~APIC_VECTOR_MASK; |
| 1419 | value |= APIC_SPIV_APIC_ENABLED; |
| 1420 | value |= 0xf; |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1421 | apic_write(APIC_SPIV, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1422 | |
| 1423 | if (!virt_wire_setup) { |
| 1424 | /* |
| 1425 | * For LVT0 make it edge triggered, active high, |
| 1426 | * external and enabled |
| 1427 | */ |
| 1428 | value = apic_read(APIC_LVT0); |
| 1429 | value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING | |
| 1430 | APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR | |
Hiroshi Shimamoto | ff8a03a | 2008-01-30 13:32:36 +0100 | [diff] [blame] | 1431 | APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1432 | value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING; |
| 1433 | value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1434 | apic_write(APIC_LVT0, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1435 | } else { |
| 1436 | /* Disable LVT0 */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1437 | apic_write(APIC_LVT0, APIC_LVT_MASKED); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /* |
| 1441 | * For LVT1 make it edge triggered, active high, nmi and |
| 1442 | * enabled |
| 1443 | */ |
| 1444 | value = apic_read(APIC_LVT1); |
| 1445 | value &= ~( |
| 1446 | APIC_MODE_MASK | APIC_SEND_PENDING | |
| 1447 | APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR | |
| 1448 | APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED); |
| 1449 | value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING; |
| 1450 | value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1451 | apic_write(APIC_LVT1, value); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
Alexey Starikovskiy | 903dcb5 | 2008-03-27 23:55:22 +0300 | [diff] [blame] | 1455 | unsigned int __cpuinitdata maxcpus = NR_CPUS; |
| 1456 | |
| 1457 | void __cpuinit generic_processor_info(int apicid, int version) |
| 1458 | { |
| 1459 | int cpu; |
| 1460 | cpumask_t tmp_map; |
| 1461 | physid_mask_t phys_cpu; |
| 1462 | |
| 1463 | /* |
| 1464 | * Validate version |
| 1465 | */ |
| 1466 | if (version == 0x0) { |
| 1467 | printk(KERN_WARNING "BIOS bug, APIC version is 0 for CPU#%d! " |
| 1468 | "fixing up to 0x10. (tell your hw vendor)\n", |
| 1469 | version); |
| 1470 | version = 0x10; |
| 1471 | } |
| 1472 | apic_version[apicid] = version; |
| 1473 | |
| 1474 | phys_cpu = apicid_to_cpu_present(apicid); |
| 1475 | physids_or(phys_cpu_present_map, phys_cpu_present_map, phys_cpu); |
| 1476 | |
| 1477 | if (num_processors >= NR_CPUS) { |
| 1478 | printk(KERN_WARNING "WARNING: NR_CPUS limit of %i reached." |
| 1479 | " Processor ignored.\n", NR_CPUS); |
| 1480 | return; |
| 1481 | } |
| 1482 | |
| 1483 | if (num_processors >= maxcpus) { |
| 1484 | printk(KERN_WARNING "WARNING: maxcpus limit of %i reached." |
| 1485 | " Processor ignored.\n", maxcpus); |
| 1486 | return; |
| 1487 | } |
| 1488 | |
| 1489 | num_processors++; |
| 1490 | cpus_complement(tmp_map, cpu_present_map); |
| 1491 | cpu = first_cpu(tmp_map); |
| 1492 | |
| 1493 | if (apicid == boot_cpu_physical_apicid) |
| 1494 | /* |
| 1495 | * x86_bios_cpu_apicid is required to have processors listed |
| 1496 | * in same order as logical cpu numbers. Hence the first |
| 1497 | * entry is BSP, and so on. |
| 1498 | */ |
| 1499 | cpu = 0; |
| 1500 | |
Yinghai Lu | e0da336 | 2008-06-08 18:29:22 -0700 | [diff] [blame] | 1501 | if (apicid > max_physical_apicid) |
| 1502 | max_physical_apicid = apicid; |
| 1503 | |
Alexey Starikovskiy | 903dcb5 | 2008-03-27 23:55:22 +0300 | [diff] [blame] | 1504 | /* |
| 1505 | * Would be preferable to switch to bigsmp when CONFIG_HOTPLUG_CPU=y |
| 1506 | * but we need to work other dependencies like SMP_SUSPEND etc |
| 1507 | * before this can be done without some confusion. |
| 1508 | * if (CPU_HOTPLUG_ENABLED || num_processors > 8) |
| 1509 | * - Ashok Raj <ashok.raj@intel.com> |
| 1510 | */ |
Yinghai Lu | e0da336 | 2008-06-08 18:29:22 -0700 | [diff] [blame] | 1511 | if (max_physical_apicid >= 8) { |
Alexey Starikovskiy | 903dcb5 | 2008-03-27 23:55:22 +0300 | [diff] [blame] | 1512 | switch (boot_cpu_data.x86_vendor) { |
| 1513 | case X86_VENDOR_INTEL: |
| 1514 | if (!APIC_XAPIC(version)) { |
| 1515 | def_to_bigsmp = 0; |
| 1516 | break; |
| 1517 | } |
| 1518 | /* If P4 and above fall through */ |
| 1519 | case X86_VENDOR_AMD: |
| 1520 | def_to_bigsmp = 1; |
| 1521 | } |
| 1522 | } |
| 1523 | #ifdef CONFIG_SMP |
| 1524 | /* are we being called early in kernel startup? */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 1525 | if (early_per_cpu_ptr(x86_cpu_to_apicid)) { |
| 1526 | u16 *cpu_to_apicid = early_per_cpu_ptr(x86_cpu_to_apicid); |
| 1527 | u16 *bios_cpu_apicid = early_per_cpu_ptr(x86_bios_cpu_apicid); |
Alexey Starikovskiy | 903dcb5 | 2008-03-27 23:55:22 +0300 | [diff] [blame] | 1528 | |
| 1529 | cpu_to_apicid[cpu] = apicid; |
| 1530 | bios_cpu_apicid[cpu] = apicid; |
| 1531 | } else { |
| 1532 | per_cpu(x86_cpu_to_apicid, cpu) = apicid; |
| 1533 | per_cpu(x86_bios_cpu_apicid, cpu) = apicid; |
| 1534 | } |
| 1535 | #endif |
| 1536 | cpu_set(cpu, cpu_possible_map); |
| 1537 | cpu_set(cpu, cpu_present_map); |
| 1538 | } |
| 1539 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1540 | /* |
| 1541 | * Power management |
| 1542 | */ |
| 1543 | #ifdef CONFIG_PM |
| 1544 | |
| 1545 | static struct { |
| 1546 | int active; |
| 1547 | /* r/w apic fields */ |
| 1548 | unsigned int apic_id; |
| 1549 | unsigned int apic_taskpri; |
| 1550 | unsigned int apic_ldr; |
| 1551 | unsigned int apic_dfr; |
| 1552 | unsigned int apic_spiv; |
| 1553 | unsigned int apic_lvtt; |
| 1554 | unsigned int apic_lvtpc; |
| 1555 | unsigned int apic_lvt0; |
| 1556 | unsigned int apic_lvt1; |
| 1557 | unsigned int apic_lvterr; |
| 1558 | unsigned int apic_tmict; |
| 1559 | unsigned int apic_tdcr; |
| 1560 | unsigned int apic_thmr; |
| 1561 | } apic_pm_state; |
| 1562 | |
| 1563 | static int lapic_suspend(struct sys_device *dev, pm_message_t state) |
| 1564 | { |
| 1565 | unsigned long flags; |
| 1566 | int maxlvt; |
| 1567 | |
| 1568 | if (!apic_pm_state.active) |
| 1569 | return 0; |
| 1570 | |
| 1571 | maxlvt = lapic_get_maxlvt(); |
| 1572 | |
| 1573 | apic_pm_state.apic_id = apic_read(APIC_ID); |
| 1574 | apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI); |
| 1575 | apic_pm_state.apic_ldr = apic_read(APIC_LDR); |
| 1576 | apic_pm_state.apic_dfr = apic_read(APIC_DFR); |
| 1577 | apic_pm_state.apic_spiv = apic_read(APIC_SPIV); |
| 1578 | apic_pm_state.apic_lvtt = apic_read(APIC_LVTT); |
| 1579 | if (maxlvt >= 4) |
| 1580 | apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC); |
| 1581 | apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0); |
| 1582 | apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1); |
| 1583 | apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR); |
| 1584 | apic_pm_state.apic_tmict = apic_read(APIC_TMICT); |
| 1585 | apic_pm_state.apic_tdcr = apic_read(APIC_TDCR); |
| 1586 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 1587 | if (maxlvt >= 5) |
| 1588 | apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR); |
| 1589 | #endif |
| 1590 | |
| 1591 | local_irq_save(flags); |
| 1592 | disable_local_APIC(); |
| 1593 | local_irq_restore(flags); |
| 1594 | return 0; |
| 1595 | } |
| 1596 | |
| 1597 | static int lapic_resume(struct sys_device *dev) |
| 1598 | { |
| 1599 | unsigned int l, h; |
| 1600 | unsigned long flags; |
| 1601 | int maxlvt; |
| 1602 | |
| 1603 | if (!apic_pm_state.active) |
| 1604 | return 0; |
| 1605 | |
| 1606 | maxlvt = lapic_get_maxlvt(); |
| 1607 | |
| 1608 | local_irq_save(flags); |
| 1609 | |
| 1610 | /* |
| 1611 | * Make sure the APICBASE points to the right address |
| 1612 | * |
| 1613 | * FIXME! This will be wrong if we ever support suspend on |
| 1614 | * SMP! We'll need to do this as part of the CPU restore! |
| 1615 | */ |
| 1616 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 1617 | l &= ~MSR_IA32_APICBASE_BASE; |
| 1618 | l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr; |
| 1619 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 1620 | |
| 1621 | apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED); |
| 1622 | apic_write(APIC_ID, apic_pm_state.apic_id); |
| 1623 | apic_write(APIC_DFR, apic_pm_state.apic_dfr); |
| 1624 | apic_write(APIC_LDR, apic_pm_state.apic_ldr); |
| 1625 | apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri); |
| 1626 | apic_write(APIC_SPIV, apic_pm_state.apic_spiv); |
| 1627 | apic_write(APIC_LVT0, apic_pm_state.apic_lvt0); |
| 1628 | apic_write(APIC_LVT1, apic_pm_state.apic_lvt1); |
| 1629 | #ifdef CONFIG_X86_MCE_P4THERMAL |
| 1630 | if (maxlvt >= 5) |
| 1631 | apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr); |
| 1632 | #endif |
| 1633 | if (maxlvt >= 4) |
| 1634 | apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc); |
| 1635 | apic_write(APIC_LVTT, apic_pm_state.apic_lvtt); |
| 1636 | apic_write(APIC_TDCR, apic_pm_state.apic_tdcr); |
| 1637 | apic_write(APIC_TMICT, apic_pm_state.apic_tmict); |
| 1638 | apic_write(APIC_ESR, 0); |
| 1639 | apic_read(APIC_ESR); |
| 1640 | apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr); |
| 1641 | apic_write(APIC_ESR, 0); |
| 1642 | apic_read(APIC_ESR); |
| 1643 | local_irq_restore(flags); |
| 1644 | return 0; |
| 1645 | } |
| 1646 | |
| 1647 | /* |
| 1648 | * This device has no shutdown method - fully functioning local APICs |
| 1649 | * are needed on every CPU up until machine_halt/restart/poweroff. |
| 1650 | */ |
| 1651 | |
| 1652 | static struct sysdev_class lapic_sysclass = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 1653 | .name = "lapic", |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1654 | .resume = lapic_resume, |
| 1655 | .suspend = lapic_suspend, |
| 1656 | }; |
| 1657 | |
| 1658 | static struct sys_device device_lapic = { |
| 1659 | .id = 0, |
| 1660 | .cls = &lapic_sysclass, |
| 1661 | }; |
| 1662 | |
| 1663 | static void __devinit apic_pm_activate(void) |
| 1664 | { |
| 1665 | apic_pm_state.active = 1; |
| 1666 | } |
| 1667 | |
| 1668 | static int __init init_lapic_sysfs(void) |
| 1669 | { |
| 1670 | int error; |
| 1671 | |
| 1672 | if (!cpu_has_apic) |
| 1673 | return 0; |
| 1674 | /* XXX: remove suspend/resume procs if !apic_pm_state.active? */ |
| 1675 | |
| 1676 | error = sysdev_class_register(&lapic_sysclass); |
| 1677 | if (!error) |
| 1678 | error = sysdev_register(&device_lapic); |
| 1679 | return error; |
| 1680 | } |
| 1681 | device_initcall(init_lapic_sysfs); |
| 1682 | |
| 1683 | #else /* CONFIG_PM */ |
| 1684 | |
| 1685 | static void apic_pm_activate(void) { } |
| 1686 | |
| 1687 | #endif /* CONFIG_PM */ |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1688 | |
| 1689 | /* |
| 1690 | * APIC command line parameters |
| 1691 | */ |
| 1692 | static int __init parse_lapic(char *arg) |
| 1693 | { |
Yinghai Lu | 914bebf | 2008-06-29 00:06:37 -0700 | [diff] [blame] | 1694 | force_enable_local_apic = 1; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1695 | return 0; |
| 1696 | } |
| 1697 | early_param("lapic", parse_lapic); |
| 1698 | |
| 1699 | static int __init parse_nolapic(char *arg) |
| 1700 | { |
Yinghai Lu | 914bebf | 2008-06-29 00:06:37 -0700 | [diff] [blame] | 1701 | disable_apic = 1; |
Yinghai Lu | 9175fc0 | 2008-07-21 01:38:14 -0700 | [diff] [blame] | 1702 | setup_clear_cpu_cap(X86_FEATURE_APIC); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1703 | return 0; |
| 1704 | } |
| 1705 | early_param("nolapic", parse_nolapic); |
| 1706 | |
Cyrill Gorcunov | 36fef09 | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 1707 | static int __init parse_disable_apic_timer(char *arg) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1708 | { |
Cyrill Gorcunov | 36fef09 | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 1709 | disable_apic_timer = 1; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1710 | return 0; |
| 1711 | } |
Cyrill Gorcunov | 36fef09 | 2008-08-15 13:51:20 +0200 | [diff] [blame] | 1712 | early_param("noapictimer", parse_disable_apic_timer); |
| 1713 | |
| 1714 | static int __init parse_nolapic_timer(char *arg) |
| 1715 | { |
| 1716 | disable_apic_timer = 1; |
| 1717 | return 0; |
| 1718 | } |
| 1719 | early_param("nolapic_timer", parse_nolapic_timer); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1720 | |
| 1721 | static int __init parse_lapic_timer_c2_ok(char *arg) |
| 1722 | { |
| 1723 | local_apic_timer_c2_ok = 1; |
| 1724 | return 0; |
| 1725 | } |
| 1726 | early_param("lapic_timer_c2_ok", parse_lapic_timer_c2_ok); |
| 1727 | |
Rene Herman | 48d97cb | 2008-08-11 19:20:17 +0200 | [diff] [blame] | 1728 | static int __init apic_set_verbosity(char *arg) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1729 | { |
Rene Herman | 48d97cb | 2008-08-11 19:20:17 +0200 | [diff] [blame] | 1730 | if (!arg) |
| 1731 | return -EINVAL; |
| 1732 | |
| 1733 | if (strcmp(arg, "debug") == 0) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1734 | apic_verbosity = APIC_DEBUG; |
Rene Herman | 48d97cb | 2008-08-11 19:20:17 +0200 | [diff] [blame] | 1735 | else if (strcmp(arg, "verbose") == 0) |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1736 | apic_verbosity = APIC_VERBOSE; |
Rene Herman | 48d97cb | 2008-08-11 19:20:17 +0200 | [diff] [blame] | 1737 | |
Rene Herman | fb6bef8 | 2008-08-11 17:45:53 +0200 | [diff] [blame] | 1738 | return 0; |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1739 | } |
Rene Herman | fb6bef8 | 2008-08-11 17:45:53 +0200 | [diff] [blame] | 1740 | early_param("apic", apic_set_verbosity); |
Thomas Gleixner | 0e078e2 | 2008-01-30 13:30:20 +0100 | [diff] [blame] | 1741 | |
Cyrill Gorcunov | 746f2eb | 2008-07-01 21:43:52 +0400 | [diff] [blame] | 1742 | static int __init lapic_insert_resource(void) |
| 1743 | { |
| 1744 | if (!apic_phys) |
| 1745 | return -1; |
| 1746 | |
| 1747 | /* Put local APIC into the resource map. */ |
| 1748 | lapic_resource.start = apic_phys; |
| 1749 | lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1; |
| 1750 | insert_resource(&iomem_resource, &lapic_resource); |
| 1751 | |
| 1752 | return 0; |
| 1753 | } |
| 1754 | |
| 1755 | /* |
| 1756 | * need call insert after e820_reserve_resources() |
| 1757 | * that is using request_resource |
| 1758 | */ |
| 1759 | late_initcall(lapic_insert_resource); |