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