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