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> |
| 22 | #include <linux/smp_lock.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/mc146818rtc.h> |
| 25 | #include <linux/kernel_stat.h> |
| 26 | #include <linux/sysdev.h> |
Venkatesh Pallipadi | d25bf7e | 2006-01-11 22:44:24 +0100 | [diff] [blame] | 27 | #include <linux/module.h> |
Aaron Durbin | 3992872 | 2006-12-07 02:14:01 +0100 | [diff] [blame^] | 28 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <asm/atomic.h> |
| 31 | #include <asm/smp.h> |
| 32 | #include <asm/mtrr.h> |
| 33 | #include <asm/mpspec.h> |
| 34 | #include <asm/pgalloc.h> |
| 35 | #include <asm/mach_apic.h> |
Andi Kleen | 7515211 | 2005-05-16 21:53:34 -0700 | [diff] [blame] | 36 | #include <asm/nmi.h> |
Andi Kleen | 95833c8 | 2006-01-11 22:44:36 +0100 | [diff] [blame] | 37 | #include <asm/idle.h> |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 38 | #include <asm/proto.h> |
| 39 | #include <asm/timex.h> |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 40 | #include <asm/apic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Andi Kleen | b7f5e3c | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 42 | int apic_mapped; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | int apic_verbosity; |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 44 | int apic_runs_main_timer; |
Andi Kleen | 0c3749c | 2006-02-03 21:51:41 +0100 | [diff] [blame] | 45 | int apic_calibrate_pmtmr __initdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | int disable_apic_timer __initdata; |
| 48 | |
Aaron Durbin | 3992872 | 2006-12-07 02:14:01 +0100 | [diff] [blame^] | 49 | static struct resource *ioapic_resources; |
| 50 | static struct resource lapic_resource = { |
| 51 | .name = "Local APIC", |
| 52 | .flags = IORESOURCE_MEM | IORESOURCE_BUSY, |
| 53 | }; |
| 54 | |
Venkatesh Pallipadi | d25bf7e | 2006-01-11 22:44:24 +0100 | [diff] [blame] | 55 | /* |
| 56 | * cpu_mask that denotes the CPUs that needs timer interrupt coming in as |
| 57 | * IPIs in place of local APIC timers |
| 58 | */ |
| 59 | static cpumask_t timer_interrupt_broadcast_ipi_mask; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* Using APIC to generate smp_local_timer_interrupt? */ |
Andreas Mohr | acae9d3 | 2006-06-23 02:04:25 -0700 | [diff] [blame] | 62 | int using_apic_timer __read_mostly = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static void apic_pm_activate(void); |
| 65 | |
| 66 | void enable_NMI_through_LVT0 (void * dummy) |
| 67 | { |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 68 | unsigned int v; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | v = APIC_DM_NMI; /* unmask and set to NMI */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 71 | apic_write(APIC_LVT0, v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | int get_maxlvt(void) |
| 75 | { |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 76 | unsigned int v, maxlvt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | v = apic_read(APIC_LVR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | maxlvt = GET_APIC_MAXLVT(v); |
| 80 | return maxlvt; |
| 81 | } |
| 82 | |
Andi Kleen | 3777a95 | 2006-02-03 21:51:53 +0100 | [diff] [blame] | 83 | /* |
| 84 | * 'what should we do if we get a hw irq event on an illegal vector'. |
| 85 | * each architecture has to answer this themselves. |
| 86 | */ |
| 87 | void ack_bad_irq(unsigned int irq) |
| 88 | { |
| 89 | printk("unexpected IRQ trap at vector %02x\n", irq); |
| 90 | /* |
| 91 | * Currently unexpected vectors happen only on SMP and APIC. |
| 92 | * We _must_ ack these because every local APIC has only N |
| 93 | * irq slots per priority level, and a 'hanging, unacked' IRQ |
| 94 | * holds up an irq slot - in excessive cases (when multiple |
| 95 | * unexpected vectors occur) that might lock up the APIC |
| 96 | * completely. |
| 97 | * But don't ack when the APIC is disabled. -AK |
| 98 | */ |
| 99 | if (!disable_apic) |
| 100 | ack_APIC_irq(); |
| 101 | } |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | void clear_local_APIC(void) |
| 104 | { |
| 105 | int maxlvt; |
| 106 | unsigned int v; |
| 107 | |
| 108 | maxlvt = get_maxlvt(); |
| 109 | |
| 110 | /* |
Siddha, Suresh B | 704fc59 | 2006-06-26 13:59:53 +0200 | [diff] [blame] | 111 | * Masking an LVT entry can trigger a local APIC error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * if the vector is zero. Mask LVTERR first to prevent this. |
| 113 | */ |
| 114 | if (maxlvt >= 3) { |
| 115 | v = ERROR_APIC_VECTOR; /* any non-zero vector will do */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 116 | apic_write(APIC_LVTERR, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | /* |
| 119 | * Careful: we have to set masks only first to deassert |
| 120 | * any level-triggered sources. |
| 121 | */ |
| 122 | v = apic_read(APIC_LVTT); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 123 | apic_write(APIC_LVTT, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | v = apic_read(APIC_LVT0); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 125 | apic_write(APIC_LVT0, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | v = apic_read(APIC_LVT1); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 127 | apic_write(APIC_LVT1, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | if (maxlvt >= 4) { |
| 129 | v = apic_read(APIC_LVTPC); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 130 | apic_write(APIC_LVTPC, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /* |
| 134 | * Clean APIC state for other OSs: |
| 135 | */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 136 | apic_write(APIC_LVTT, APIC_LVT_MASKED); |
| 137 | apic_write(APIC_LVT0, APIC_LVT_MASKED); |
| 138 | apic_write(APIC_LVT1, APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | if (maxlvt >= 3) |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 140 | apic_write(APIC_LVTERR, APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | if (maxlvt >= 4) |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 142 | apic_write(APIC_LVTPC, APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | v = GET_APIC_VERSION(apic_read(APIC_LVR)); |
Andi Kleen | 5a40b7c | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 144 | apic_write(APIC_ESR, 0); |
| 145 | apic_read(APIC_ESR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Eric W. Biederman | 208fb93 | 2005-06-25 14:57:45 -0700 | [diff] [blame] | 148 | void disconnect_bsp_APIC(int virt_wire_setup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | { |
Andi Kleen | a8fcf1a | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 150 | /* Go back to Virtual Wire compatibility mode */ |
| 151 | unsigned long value; |
| 152 | |
| 153 | /* For the spurious interrupt use vector F, and enable it */ |
| 154 | value = apic_read(APIC_SPIV); |
| 155 | value &= ~APIC_VECTOR_MASK; |
| 156 | value |= APIC_SPIV_APIC_ENABLED; |
| 157 | value |= 0xf; |
| 158 | apic_write(APIC_SPIV, value); |
| 159 | |
| 160 | if (!virt_wire_setup) { |
| 161 | /* For LVT0 make it edge triggered, active high, external and enabled */ |
| 162 | value = apic_read(APIC_LVT0); |
| 163 | value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING | |
| 164 | APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR | |
| 165 | APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED ); |
| 166 | value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING; |
| 167 | value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_EXTINT); |
| 168 | apic_write(APIC_LVT0, value); |
| 169 | } else { |
| 170 | /* Disable LVT0 */ |
| 171 | apic_write(APIC_LVT0, APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
Eric W. Biederman | 208fb93 | 2005-06-25 14:57:45 -0700 | [diff] [blame] | 173 | |
Andi Kleen | a8fcf1a | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 174 | /* For LVT1 make it edge triggered, active high, nmi and enabled */ |
| 175 | value = apic_read(APIC_LVT1); |
| 176 | value &= ~(APIC_MODE_MASK | APIC_SEND_PENDING | |
Eric W. Biederman | 208fb93 | 2005-06-25 14:57:45 -0700 | [diff] [blame] | 177 | APIC_INPUT_POLARITY | APIC_LVT_REMOTE_IRR | |
| 178 | APIC_LVT_LEVEL_TRIGGER | APIC_LVT_MASKED); |
Andi Kleen | a8fcf1a | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 179 | value |= APIC_LVT_REMOTE_IRR | APIC_SEND_PENDING; |
| 180 | value = SET_APIC_DELIVERY_MODE(value, APIC_MODE_NMI); |
| 181 | apic_write(APIC_LVT1, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | void disable_local_APIC(void) |
| 185 | { |
| 186 | unsigned int value; |
| 187 | |
| 188 | clear_local_APIC(); |
| 189 | |
| 190 | /* |
| 191 | * Disable APIC (implies clearing of registers |
| 192 | * for 82489DX!). |
| 193 | */ |
| 194 | value = apic_read(APIC_SPIV); |
| 195 | value &= ~APIC_SPIV_APIC_ENABLED; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 196 | apic_write(APIC_SPIV, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* |
| 200 | * This is to verify that we're looking at a real local APIC. |
| 201 | * Check these against your board if the CPUs aren't getting |
| 202 | * started for no apparent reason. |
| 203 | */ |
| 204 | int __init verify_local_APIC(void) |
| 205 | { |
| 206 | unsigned int reg0, reg1; |
| 207 | |
| 208 | /* |
| 209 | * The version register is read-only in a real APIC. |
| 210 | */ |
| 211 | reg0 = apic_read(APIC_LVR); |
| 212 | apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg0); |
| 213 | apic_write(APIC_LVR, reg0 ^ APIC_LVR_MASK); |
| 214 | reg1 = apic_read(APIC_LVR); |
| 215 | apic_printk(APIC_DEBUG, "Getting VERSION: %x\n", reg1); |
| 216 | |
| 217 | /* |
| 218 | * The two version reads above should print the same |
| 219 | * numbers. If the second one is different, then we |
| 220 | * poke at a non-APIC. |
| 221 | */ |
| 222 | if (reg1 != reg0) |
| 223 | return 0; |
| 224 | |
| 225 | /* |
| 226 | * Check if the version looks reasonably. |
| 227 | */ |
| 228 | reg1 = GET_APIC_VERSION(reg0); |
| 229 | if (reg1 == 0x00 || reg1 == 0xff) |
| 230 | return 0; |
| 231 | reg1 = get_maxlvt(); |
| 232 | if (reg1 < 0x02 || reg1 == 0xff) |
| 233 | return 0; |
| 234 | |
| 235 | /* |
| 236 | * The ID register is read/write in a real APIC. |
| 237 | */ |
| 238 | reg0 = apic_read(APIC_ID); |
| 239 | apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg0); |
| 240 | apic_write(APIC_ID, reg0 ^ APIC_ID_MASK); |
| 241 | reg1 = apic_read(APIC_ID); |
| 242 | apic_printk(APIC_DEBUG, "Getting ID: %x\n", reg1); |
| 243 | apic_write(APIC_ID, reg0); |
| 244 | if (reg1 != (reg0 ^ APIC_ID_MASK)) |
| 245 | return 0; |
| 246 | |
| 247 | /* |
| 248 | * The next two are just to see if we have sane values. |
| 249 | * They're only really relevant if we're in Virtual Wire |
| 250 | * compatibility mode, but most boxes are anymore. |
| 251 | */ |
| 252 | reg0 = apic_read(APIC_LVT0); |
| 253 | apic_printk(APIC_DEBUG,"Getting LVT0: %x\n", reg0); |
| 254 | reg1 = apic_read(APIC_LVT1); |
| 255 | apic_printk(APIC_DEBUG, "Getting LVT1: %x\n", reg1); |
| 256 | |
| 257 | return 1; |
| 258 | } |
| 259 | |
| 260 | void __init sync_Arb_IDs(void) |
| 261 | { |
| 262 | /* Unsupported on P4 - see Intel Dev. Manual Vol. 3, Ch. 8.6.1 */ |
| 263 | unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR)); |
| 264 | if (ver >= 0x14) /* P4 or higher */ |
| 265 | return; |
| 266 | |
| 267 | /* |
| 268 | * Wait for idle. |
| 269 | */ |
| 270 | apic_wait_icr_idle(); |
| 271 | |
| 272 | apic_printk(APIC_DEBUG, "Synchronizing Arb IDs.\n"); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 273 | apic_write(APIC_ICR, APIC_DEST_ALLINC | APIC_INT_LEVELTRIG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | | APIC_DM_INIT); |
| 275 | } |
| 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /* |
| 278 | * An initial setup of the virtual wire mode. |
| 279 | */ |
| 280 | void __init init_bsp_APIC(void) |
| 281 | { |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 282 | unsigned int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | /* |
| 285 | * Don't do the setup now if we have a SMP BIOS as the |
| 286 | * through-I/O-APIC virtual wire mode might be active. |
| 287 | */ |
| 288 | if (smp_found_config || !cpu_has_apic) |
| 289 | return; |
| 290 | |
| 291 | value = apic_read(APIC_LVR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | /* |
| 294 | * Do not trust the local APIC being empty at bootup. |
| 295 | */ |
| 296 | clear_local_APIC(); |
| 297 | |
| 298 | /* |
| 299 | * Enable APIC. |
| 300 | */ |
| 301 | value = apic_read(APIC_SPIV); |
| 302 | value &= ~APIC_VECTOR_MASK; |
| 303 | value |= APIC_SPIV_APIC_ENABLED; |
| 304 | value |= APIC_SPIV_FOCUS_DISABLED; |
| 305 | value |= SPURIOUS_APIC_VECTOR; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 306 | apic_write(APIC_SPIV, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | /* |
| 309 | * Set up the virtual wire mode. |
| 310 | */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 311 | apic_write(APIC_LVT0, APIC_DM_EXTINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | value = APIC_DM_NMI; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 313 | apic_write(APIC_LVT1, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 316 | void __cpuinit setup_local_APIC (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 318 | unsigned int value, maxlvt; |
Vivek Goyal | da7ed9f | 2006-03-25 16:31:16 +0100 | [diff] [blame] | 319 | int i, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | value = apic_read(APIC_LVR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Andi Kleen | fe7414a | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 323 | BUILD_BUG_ON((SPURIOUS_APIC_VECTOR & 0x0f) != 0x0f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | /* |
| 326 | * Double-check whether this APIC is really registered. |
| 327 | * This is meaningless in clustered apic mode, so we skip it. |
| 328 | */ |
| 329 | if (!apic_id_registered()) |
| 330 | BUG(); |
| 331 | |
| 332 | /* |
| 333 | * Intel recommends to set DFR, LDR and TPR before enabling |
| 334 | * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
| 335 | * document number 292116). So here it goes... |
| 336 | */ |
| 337 | init_apic_ldr(); |
| 338 | |
| 339 | /* |
| 340 | * Set Task Priority to 'accept all'. We never change this |
| 341 | * later on. |
| 342 | */ |
| 343 | value = apic_read(APIC_TASKPRI); |
| 344 | value &= ~APIC_TPRI_MASK; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 345 | apic_write(APIC_TASKPRI, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
| 347 | /* |
Vivek Goyal | da7ed9f | 2006-03-25 16:31:16 +0100 | [diff] [blame] | 348 | * After a crash, we no longer service the interrupts and a pending |
| 349 | * interrupt from previous kernel might still have ISR bit set. |
| 350 | * |
| 351 | * Most probably by now CPU has serviced that pending interrupt and |
| 352 | * it might not have done the ack_APIC_irq() because it thought, |
| 353 | * interrupt came from i8259 as ExtInt. LAPIC did not get EOI so it |
| 354 | * does not clear the ISR bit and cpu thinks it has already serivced |
| 355 | * the interrupt. Hence a vector might get locked. It was noticed |
| 356 | * for timer irq (vector 0x31). Issue an extra EOI to clear ISR. |
| 357 | */ |
| 358 | for (i = APIC_ISR_NR - 1; i >= 0; i--) { |
| 359 | value = apic_read(APIC_ISR + i*0x10); |
| 360 | for (j = 31; j >= 0; j--) { |
| 361 | if (value & (1<<j)) |
| 362 | ack_APIC_irq(); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | * Now that we are all set up, enable the APIC |
| 368 | */ |
| 369 | value = apic_read(APIC_SPIV); |
| 370 | value &= ~APIC_VECTOR_MASK; |
| 371 | /* |
| 372 | * Enable APIC |
| 373 | */ |
| 374 | value |= APIC_SPIV_APIC_ENABLED; |
| 375 | |
Andi Kleen | 3f14c74 | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 376 | /* We always use processor focus */ |
| 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* |
| 379 | * Set spurious IRQ vector |
| 380 | */ |
| 381 | value |= SPURIOUS_APIC_VECTOR; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 382 | apic_write(APIC_SPIV, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
| 384 | /* |
| 385 | * Set up LVT0, LVT1: |
| 386 | * |
| 387 | * set up through-local-APIC on the BP's LINT0. This is not |
| 388 | * strictly necessary in pure symmetric-IO mode, but sometimes |
| 389 | * we delegate interrupts to the 8259A. |
| 390 | */ |
| 391 | /* |
| 392 | * TODO: set up through-local-APIC from through-I/O-APIC? --macro |
| 393 | */ |
| 394 | value = apic_read(APIC_LVT0) & APIC_LVT_MASKED; |
Andi Kleen | a8fcf1a | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 395 | if (!smp_processor_id() && !value) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | value = APIC_DM_EXTINT; |
| 397 | apic_printk(APIC_VERBOSE, "enabled ExtINT on CPU#%d\n", smp_processor_id()); |
| 398 | } else { |
| 399 | value = APIC_DM_EXTINT | APIC_LVT_MASKED; |
| 400 | apic_printk(APIC_VERBOSE, "masked ExtINT on CPU#%d\n", smp_processor_id()); |
| 401 | } |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 402 | apic_write(APIC_LVT0, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | /* |
| 405 | * only the BP should see the LINT1 NMI signal, obviously. |
| 406 | */ |
| 407 | if (!smp_processor_id()) |
| 408 | value = APIC_DM_NMI; |
| 409 | else |
| 410 | value = APIC_DM_NMI | APIC_LVT_MASKED; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 411 | apic_write(APIC_LVT1, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Andi Kleen | 61c1134 | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 413 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | unsigned oldvalue; |
| 415 | maxlvt = get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | oldvalue = apic_read(APIC_ESR); |
| 417 | value = ERROR_APIC_VECTOR; // enables sending errors |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 418 | apic_write(APIC_LVTERR, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | /* |
| 420 | * spec says clear errors after enabling vector. |
| 421 | */ |
| 422 | if (maxlvt > 3) |
| 423 | apic_write(APIC_ESR, 0); |
| 424 | value = apic_read(APIC_ESR); |
| 425 | if (value != oldvalue) |
| 426 | apic_printk(APIC_VERBOSE, |
| 427 | "ESR value after enabling vector: %08x, after %08x\n", |
| 428 | oldvalue, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | nmi_watchdog_default(); |
Don Zickus | f2802e7 | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 432 | setup_apic_nmi_watchdog(NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | apic_pm_activate(); |
| 434 | } |
| 435 | |
| 436 | #ifdef CONFIG_PM |
| 437 | |
| 438 | static struct { |
| 439 | /* 'active' is true if the local APIC was enabled by us and |
| 440 | not the BIOS; this signifies that we are also responsible |
| 441 | for disabling it before entering apm/acpi suspend */ |
| 442 | int active; |
| 443 | /* r/w apic fields */ |
| 444 | unsigned int apic_id; |
| 445 | unsigned int apic_taskpri; |
| 446 | unsigned int apic_ldr; |
| 447 | unsigned int apic_dfr; |
| 448 | unsigned int apic_spiv; |
| 449 | unsigned int apic_lvtt; |
| 450 | unsigned int apic_lvtpc; |
| 451 | unsigned int apic_lvt0; |
| 452 | unsigned int apic_lvt1; |
| 453 | unsigned int apic_lvterr; |
| 454 | unsigned int apic_tmict; |
| 455 | unsigned int apic_tdcr; |
| 456 | unsigned int apic_thmr; |
| 457 | } apic_pm_state; |
| 458 | |
Pavel Machek | 0b9c33a | 2005-04-16 15:25:31 -0700 | [diff] [blame] | 459 | static int lapic_suspend(struct sys_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
| 461 | unsigned long flags; |
| 462 | |
| 463 | if (!apic_pm_state.active) |
| 464 | return 0; |
| 465 | |
| 466 | apic_pm_state.apic_id = apic_read(APIC_ID); |
| 467 | apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI); |
| 468 | apic_pm_state.apic_ldr = apic_read(APIC_LDR); |
| 469 | apic_pm_state.apic_dfr = apic_read(APIC_DFR); |
| 470 | apic_pm_state.apic_spiv = apic_read(APIC_SPIV); |
| 471 | apic_pm_state.apic_lvtt = apic_read(APIC_LVTT); |
| 472 | apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC); |
| 473 | apic_pm_state.apic_lvt0 = apic_read(APIC_LVT0); |
| 474 | apic_pm_state.apic_lvt1 = apic_read(APIC_LVT1); |
| 475 | apic_pm_state.apic_lvterr = apic_read(APIC_LVTERR); |
| 476 | apic_pm_state.apic_tmict = apic_read(APIC_TMICT); |
| 477 | apic_pm_state.apic_tdcr = apic_read(APIC_TDCR); |
| 478 | apic_pm_state.apic_thmr = apic_read(APIC_LVTTHMR); |
Fernando Luis Vázquez Cao | 2b94ab2 | 2006-09-26 10:52:33 +0200 | [diff] [blame] | 479 | local_irq_save(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | disable_local_APIC(); |
| 481 | local_irq_restore(flags); |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static int lapic_resume(struct sys_device *dev) |
| 486 | { |
| 487 | unsigned int l, h; |
| 488 | unsigned long flags; |
| 489 | |
| 490 | if (!apic_pm_state.active) |
| 491 | return 0; |
| 492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | local_irq_save(flags); |
| 494 | rdmsr(MSR_IA32_APICBASE, l, h); |
| 495 | l &= ~MSR_IA32_APICBASE_BASE; |
Shaohua Li | 5b74357 | 2006-01-16 01:56:45 +0100 | [diff] [blame] | 496 | l |= MSR_IA32_APICBASE_ENABLE | mp_lapic_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | wrmsr(MSR_IA32_APICBASE, l, h); |
| 498 | apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED); |
| 499 | apic_write(APIC_ID, apic_pm_state.apic_id); |
| 500 | apic_write(APIC_DFR, apic_pm_state.apic_dfr); |
| 501 | apic_write(APIC_LDR, apic_pm_state.apic_ldr); |
| 502 | apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri); |
| 503 | apic_write(APIC_SPIV, apic_pm_state.apic_spiv); |
| 504 | apic_write(APIC_LVT0, apic_pm_state.apic_lvt0); |
| 505 | apic_write(APIC_LVT1, apic_pm_state.apic_lvt1); |
| 506 | apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr); |
| 507 | apic_write(APIC_LVTPC, apic_pm_state.apic_lvtpc); |
| 508 | apic_write(APIC_LVTT, apic_pm_state.apic_lvtt); |
| 509 | apic_write(APIC_TDCR, apic_pm_state.apic_tdcr); |
| 510 | apic_write(APIC_TMICT, apic_pm_state.apic_tmict); |
| 511 | apic_write(APIC_ESR, 0); |
| 512 | apic_read(APIC_ESR); |
| 513 | apic_write(APIC_LVTERR, apic_pm_state.apic_lvterr); |
| 514 | apic_write(APIC_ESR, 0); |
| 515 | apic_read(APIC_ESR); |
| 516 | local_irq_restore(flags); |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static struct sysdev_class lapic_sysclass = { |
| 521 | set_kset_name("lapic"), |
| 522 | .resume = lapic_resume, |
| 523 | .suspend = lapic_suspend, |
| 524 | }; |
| 525 | |
| 526 | static struct sys_device device_lapic = { |
| 527 | .id = 0, |
| 528 | .cls = &lapic_sysclass, |
| 529 | }; |
| 530 | |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 531 | static void __cpuinit apic_pm_activate(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
| 533 | apic_pm_state.active = 1; |
| 534 | } |
| 535 | |
| 536 | static int __init init_lapic_sysfs(void) |
| 537 | { |
| 538 | int error; |
| 539 | if (!cpu_has_apic) |
| 540 | return 0; |
| 541 | /* XXX: remove suspend/resume procs if !apic_pm_state.active? */ |
| 542 | error = sysdev_class_register(&lapic_sysclass); |
| 543 | if (!error) |
| 544 | error = sysdev_register(&device_lapic); |
| 545 | return error; |
| 546 | } |
| 547 | device_initcall(init_lapic_sysfs); |
| 548 | |
| 549 | #else /* CONFIG_PM */ |
| 550 | |
| 551 | static void apic_pm_activate(void) { } |
| 552 | |
| 553 | #endif /* CONFIG_PM */ |
| 554 | |
| 555 | static int __init apic_set_verbosity(char *str) |
| 556 | { |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 557 | if (str == NULL) { |
| 558 | skip_ioapic_setup = 0; |
| 559 | ioapic_force = 1; |
| 560 | return 0; |
| 561 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | if (strcmp("debug", str) == 0) |
| 563 | apic_verbosity = APIC_DEBUG; |
| 564 | else if (strcmp("verbose", str) == 0) |
| 565 | apic_verbosity = APIC_VERBOSE; |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 566 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | printk(KERN_WARNING "APIC Verbosity level %s not recognised" |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 568 | " use apic=verbose or apic=debug\n", str); |
| 569 | return -EINVAL; |
| 570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 572 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | } |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 574 | early_param("apic", apic_set_verbosity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | /* |
| 577 | * Detect and enable local APICs on non-SMP boards. |
| 578 | * Original code written by Keir Fraser. |
| 579 | * On AMD64 we trust the BIOS - if it says no APIC it is likely |
| 580 | * not correctly set up (usually the APIC timer won't work etc.) |
| 581 | */ |
| 582 | |
| 583 | static int __init detect_init_APIC (void) |
| 584 | { |
| 585 | if (!cpu_has_apic) { |
| 586 | printk(KERN_INFO "No local APIC present\n"); |
| 587 | return -1; |
| 588 | } |
| 589 | |
| 590 | mp_lapic_addr = APIC_DEFAULT_PHYS_BASE; |
| 591 | boot_cpu_id = 0; |
| 592 | return 0; |
| 593 | } |
| 594 | |
Aaron Durbin | 3992872 | 2006-12-07 02:14:01 +0100 | [diff] [blame^] | 595 | #ifdef CONFIG_X86_IO_APIC |
| 596 | static struct resource * __init ioapic_setup_resources(void) |
| 597 | { |
| 598 | #define IOAPIC_RESOURCE_NAME_SIZE 11 |
| 599 | unsigned long n; |
| 600 | struct resource *res; |
| 601 | char *mem; |
| 602 | int i; |
| 603 | |
| 604 | if (nr_ioapics <= 0) |
| 605 | return NULL; |
| 606 | |
| 607 | n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource); |
| 608 | n *= nr_ioapics; |
| 609 | |
| 610 | mem = alloc_bootmem(n); |
| 611 | res = (void *)mem; |
| 612 | |
| 613 | if (mem != NULL) { |
| 614 | memset(mem, 0, n); |
| 615 | mem += sizeof(struct resource) * nr_ioapics; |
| 616 | |
| 617 | for (i = 0; i < nr_ioapics; i++) { |
| 618 | res[i].name = mem; |
| 619 | res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
| 620 | sprintf(mem, "IOAPIC %u", i); |
| 621 | mem += IOAPIC_RESOURCE_NAME_SIZE; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | ioapic_resources = res; |
| 626 | |
| 627 | return res; |
| 628 | } |
| 629 | |
| 630 | static int __init ioapic_insert_resources(void) |
| 631 | { |
| 632 | int i; |
| 633 | struct resource *r = ioapic_resources; |
| 634 | |
| 635 | if (!r) { |
| 636 | printk("IO APIC resources could be not be allocated.\n"); |
| 637 | return -1; |
| 638 | } |
| 639 | |
| 640 | for (i = 0; i < nr_ioapics; i++) { |
| 641 | insert_resource(&iomem_resource, r); |
| 642 | r++; |
| 643 | } |
| 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | /* Insert the IO APIC resources after PCI initialization has occured to handle |
| 649 | * IO APICS that are mapped in on a BAR in PCI space. */ |
| 650 | late_initcall(ioapic_insert_resources); |
| 651 | #endif |
| 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | void __init init_apic_mappings(void) |
| 654 | { |
| 655 | unsigned long apic_phys; |
| 656 | |
| 657 | /* |
| 658 | * If no local APIC can be found then set up a fake all |
| 659 | * zeroes page to simulate the local APIC and another |
| 660 | * one for the IO-APIC. |
| 661 | */ |
| 662 | if (!smp_found_config && detect_init_APIC()) { |
| 663 | apic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE); |
| 664 | apic_phys = __pa(apic_phys); |
| 665 | } else |
| 666 | apic_phys = mp_lapic_addr; |
| 667 | |
| 668 | set_fixmap_nocache(FIX_APIC_BASE, apic_phys); |
Andi Kleen | b7f5e3c | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 669 | apic_mapped = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | apic_printk(APIC_VERBOSE,"mapped APIC to %16lx (%16lx)\n", APIC_BASE, apic_phys); |
| 671 | |
Aaron Durbin | 3992872 | 2006-12-07 02:14:01 +0100 | [diff] [blame^] | 672 | /* Put local APIC into the resource map. */ |
| 673 | lapic_resource.start = apic_phys; |
| 674 | lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1; |
| 675 | insert_resource(&iomem_resource, &lapic_resource); |
| 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | /* |
| 678 | * Fetch the APIC ID of the BSP in case we have a |
| 679 | * default configuration (or the MP table is broken). |
| 680 | */ |
Andi Kleen | 1d3fbbf | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 681 | boot_cpu_id = GET_APIC_ID(apic_read(APIC_ID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | { |
| 684 | unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0; |
| 685 | int i; |
Aaron Durbin | 3992872 | 2006-12-07 02:14:01 +0100 | [diff] [blame^] | 686 | struct resource *ioapic_res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
Aaron Durbin | 3992872 | 2006-12-07 02:14:01 +0100 | [diff] [blame^] | 688 | ioapic_res = ioapic_setup_resources(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | for (i = 0; i < nr_ioapics; i++) { |
| 690 | if (smp_found_config) { |
| 691 | ioapic_phys = mp_ioapics[i].mpc_apicaddr; |
| 692 | } else { |
| 693 | ioapic_phys = (unsigned long) alloc_bootmem_pages(PAGE_SIZE); |
| 694 | ioapic_phys = __pa(ioapic_phys); |
| 695 | } |
| 696 | set_fixmap_nocache(idx, ioapic_phys); |
| 697 | apic_printk(APIC_VERBOSE,"mapped IOAPIC to %016lx (%016lx)\n", |
| 698 | __fix_to_virt(idx), ioapic_phys); |
| 699 | idx++; |
Aaron Durbin | 3992872 | 2006-12-07 02:14:01 +0100 | [diff] [blame^] | 700 | |
| 701 | if (ioapic_res != NULL) { |
| 702 | ioapic_res->start = ioapic_phys; |
| 703 | ioapic_res->end = ioapic_phys + (4 * 1024) - 1; |
| 704 | ioapic_res++; |
| 705 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /* |
| 711 | * This function sets up the local APIC timer, with a timeout of |
| 712 | * 'clocks' APIC bus clock. During calibration we actually call |
| 713 | * this function twice on the boot CPU, once with a bogus timeout |
| 714 | * value, second time for real. The other (noncalibrating) CPUs |
| 715 | * call this function only once, with the real, calibrated value. |
| 716 | * |
| 717 | * We do reads before writes even if unnecessary, to get around the |
| 718 | * P5 APIC double write bug. |
| 719 | */ |
| 720 | |
| 721 | #define APIC_DIVISOR 16 |
| 722 | |
| 723 | static void __setup_APIC_LVTT(unsigned int clocks) |
| 724 | { |
| 725 | unsigned int lvtt_value, tmp_value, ver; |
Venkatesh Pallipadi | d25bf7e | 2006-01-11 22:44:24 +0100 | [diff] [blame] | 726 | int cpu = smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
| 728 | ver = GET_APIC_VERSION(apic_read(APIC_LVR)); |
| 729 | lvtt_value = APIC_LVT_TIMER_PERIODIC | LOCAL_TIMER_VECTOR; |
Venkatesh Pallipadi | d25bf7e | 2006-01-11 22:44:24 +0100 | [diff] [blame] | 730 | |
| 731 | if (cpu_isset(cpu, timer_interrupt_broadcast_ipi_mask)) |
| 732 | lvtt_value |= APIC_LVT_MASKED; |
| 733 | |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 734 | apic_write(APIC_LVTT, lvtt_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
| 736 | /* |
| 737 | * Divide PICLK by 16 |
| 738 | */ |
| 739 | tmp_value = apic_read(APIC_TDCR); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 740 | apic_write(APIC_TDCR, (tmp_value |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | & ~(APIC_TDR_DIV_1 | APIC_TDR_DIV_TMBASE)) |
| 742 | | APIC_TDR_DIV_16); |
| 743 | |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 744 | apic_write(APIC_TMICT, clocks/APIC_DIVISOR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static void setup_APIC_timer(unsigned int clocks) |
| 748 | { |
| 749 | unsigned long flags; |
| 750 | |
| 751 | local_irq_save(flags); |
| 752 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | /* wait for irq slice */ |
Chris McDermott | 33042a9 | 2006-02-11 17:55:50 -0800 | [diff] [blame] | 754 | if (vxtime.hpet_address && hpet_use_timer) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | int trigger = hpet_readl(HPET_T0_CMP); |
| 756 | while (hpet_readl(HPET_COUNTER) >= trigger) |
| 757 | /* do nothing */ ; |
| 758 | while (hpet_readl(HPET_COUNTER) < trigger) |
| 759 | /* do nothing */ ; |
| 760 | } else { |
| 761 | int c1, c2; |
| 762 | outb_p(0x00, 0x43); |
| 763 | c2 = inb_p(0x40); |
| 764 | c2 |= inb_p(0x40) << 8; |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 765 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | c1 = c2; |
| 767 | outb_p(0x00, 0x43); |
| 768 | c2 = inb_p(0x40); |
| 769 | c2 |= inb_p(0x40) << 8; |
| 770 | } while (c2 - c1 < 300); |
| 771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | __setup_APIC_LVTT(clocks); |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 773 | /* Turn off PIT interrupt if we use APIC timer as main timer. |
| 774 | Only works with the PM timer right now |
| 775 | TBD fix it for HPET too. */ |
| 776 | if (vxtime.mode == VXTIME_PMTMR && |
| 777 | smp_processor_id() == boot_cpu_id && |
| 778 | apic_runs_main_timer == 1 && |
| 779 | !cpu_isset(boot_cpu_id, timer_interrupt_broadcast_ipi_mask)) { |
| 780 | stop_timer_interrupt(); |
| 781 | apic_runs_main_timer++; |
| 782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | local_irq_restore(flags); |
| 784 | } |
| 785 | |
| 786 | /* |
| 787 | * In this function we calibrate APIC bus clocks to the external |
| 788 | * timer. Unfortunately we cannot use jiffies and the timer irq |
| 789 | * to calibrate, since some later bootup code depends on getting |
| 790 | * the first irq? Ugh. |
| 791 | * |
| 792 | * We want to do the calibration only once since we |
| 793 | * want to have local timer irqs syncron. CPUs connected |
| 794 | * by the same APIC bus have the very same bus frequency. |
| 795 | * And we want to have irqs off anyways, no accidental |
| 796 | * APIC irq that way. |
| 797 | */ |
| 798 | |
| 799 | #define TICK_COUNT 100000000 |
| 800 | |
| 801 | static int __init calibrate_APIC_clock(void) |
| 802 | { |
| 803 | int apic, apic_start, tsc, tsc_start; |
| 804 | int result; |
| 805 | /* |
| 806 | * Put whatever arbitrary (but long enough) timeout |
| 807 | * value into the APIC clock, we just want to get the |
| 808 | * counter running for calibration. |
| 809 | */ |
| 810 | __setup_APIC_LVTT(1000000000); |
| 811 | |
| 812 | apic_start = apic_read(APIC_TMCCT); |
Andi Kleen | 0c3749c | 2006-02-03 21:51:41 +0100 | [diff] [blame] | 813 | #ifdef CONFIG_X86_PM_TIMER |
| 814 | if (apic_calibrate_pmtmr && pmtmr_ioport) { |
| 815 | pmtimer_wait(5000); /* 5ms wait */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | apic = apic_read(APIC_TMCCT); |
Andi Kleen | 0c3749c | 2006-02-03 21:51:41 +0100 | [diff] [blame] | 817 | result = (apic_start - apic) * 1000L / 5; |
| 818 | } else |
| 819 | #endif |
| 820 | { |
| 821 | rdtscl(tsc_start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
Andi Kleen | 0c3749c | 2006-02-03 21:51:41 +0100 | [diff] [blame] | 823 | do { |
| 824 | apic = apic_read(APIC_TMCCT); |
| 825 | rdtscl(tsc); |
| 826 | } while ((tsc - tsc_start) < TICK_COUNT && |
| 827 | (apic - apic_start) < TICK_COUNT); |
| 828 | |
| 829 | result = (apic_start - apic) * 1000L * cpu_khz / |
| 830 | (tsc - tsc_start); |
| 831 | } |
| 832 | printk("result %d\n", result); |
| 833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
| 835 | printk(KERN_INFO "Detected %d.%03d MHz APIC timer.\n", |
| 836 | result / 1000 / 1000, result / 1000 % 1000); |
| 837 | |
| 838 | return result * APIC_DIVISOR / HZ; |
| 839 | } |
| 840 | |
| 841 | static unsigned int calibration_result; |
| 842 | |
| 843 | void __init setup_boot_APIC_clock (void) |
| 844 | { |
| 845 | if (disable_apic_timer) { |
| 846 | printk(KERN_INFO "Disabling APIC timer\n"); |
| 847 | return; |
| 848 | } |
| 849 | |
| 850 | printk(KERN_INFO "Using local APIC timer interrupts.\n"); |
| 851 | using_apic_timer = 1; |
| 852 | |
| 853 | local_irq_disable(); |
| 854 | |
| 855 | calibration_result = calibrate_APIC_clock(); |
| 856 | /* |
| 857 | * Now set up the timer for real. |
| 858 | */ |
| 859 | setup_APIC_timer(calibration_result); |
| 860 | |
| 861 | local_irq_enable(); |
| 862 | } |
| 863 | |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 864 | void __cpuinit setup_secondary_APIC_clock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
| 866 | local_irq_disable(); /* FIXME: Do we need this? --RR */ |
| 867 | setup_APIC_timer(calibration_result); |
| 868 | local_irq_enable(); |
| 869 | } |
| 870 | |
Venkatesh Pallipadi | d25bf7e | 2006-01-11 22:44:24 +0100 | [diff] [blame] | 871 | void disable_APIC_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | { |
| 873 | if (using_apic_timer) { |
| 874 | unsigned long v; |
| 875 | |
| 876 | v = apic_read(APIC_LVTT); |
Siddha, Suresh B | 704fc59 | 2006-06-26 13:59:53 +0200 | [diff] [blame] | 877 | /* |
| 878 | * When an illegal vector value (0-15) is written to an LVT |
| 879 | * entry and delivery mode is Fixed, the APIC may signal an |
| 880 | * illegal vector error, with out regard to whether the mask |
| 881 | * bit is set or whether an interrupt is actually seen on input. |
| 882 | * |
| 883 | * Boot sequence might call this function when the LVTT has |
| 884 | * '0' vector value. So make sure vector field is set to |
| 885 | * valid value. |
| 886 | */ |
| 887 | v |= (APIC_LVT_MASKED | LOCAL_TIMER_VECTOR); |
| 888 | apic_write(APIC_LVTT, v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | |
| 892 | void enable_APIC_timer(void) |
| 893 | { |
Venkatesh Pallipadi | d25bf7e | 2006-01-11 22:44:24 +0100 | [diff] [blame] | 894 | int cpu = smp_processor_id(); |
| 895 | |
| 896 | if (using_apic_timer && |
| 897 | !cpu_isset(cpu, timer_interrupt_broadcast_ipi_mask)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | unsigned long v; |
| 899 | |
| 900 | v = apic_read(APIC_LVTT); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 901 | apic_write(APIC_LVTT, v & ~APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
Venkatesh Pallipadi | d25bf7e | 2006-01-11 22:44:24 +0100 | [diff] [blame] | 905 | void switch_APIC_timer_to_ipi(void *cpumask) |
| 906 | { |
| 907 | cpumask_t mask = *(cpumask_t *)cpumask; |
| 908 | int cpu = smp_processor_id(); |
| 909 | |
| 910 | if (cpu_isset(cpu, mask) && |
| 911 | !cpu_isset(cpu, timer_interrupt_broadcast_ipi_mask)) { |
| 912 | disable_APIC_timer(); |
| 913 | cpu_set(cpu, timer_interrupt_broadcast_ipi_mask); |
| 914 | } |
| 915 | } |
| 916 | EXPORT_SYMBOL(switch_APIC_timer_to_ipi); |
| 917 | |
| 918 | void smp_send_timer_broadcast_ipi(void) |
| 919 | { |
| 920 | cpumask_t mask; |
| 921 | |
| 922 | cpus_and(mask, cpu_online_map, timer_interrupt_broadcast_ipi_mask); |
| 923 | if (!cpus_empty(mask)) { |
| 924 | send_IPI_mask(mask, LOCAL_TIMER_VECTOR); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | void switch_ipi_to_APIC_timer(void *cpumask) |
| 929 | { |
| 930 | cpumask_t mask = *(cpumask_t *)cpumask; |
| 931 | int cpu = smp_processor_id(); |
| 932 | |
| 933 | if (cpu_isset(cpu, mask) && |
| 934 | cpu_isset(cpu, timer_interrupt_broadcast_ipi_mask)) { |
| 935 | cpu_clear(cpu, timer_interrupt_broadcast_ipi_mask); |
| 936 | enable_APIC_timer(); |
| 937 | } |
| 938 | } |
| 939 | EXPORT_SYMBOL(switch_ipi_to_APIC_timer); |
| 940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | int setup_profiling_timer(unsigned int multiplier) |
| 942 | { |
Venkatesh Pallipadi | 5a07a30 | 2006-01-11 22:44:18 +0100 | [diff] [blame] | 943 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Jacob Shin | 17fc14f | 2006-06-26 13:58:47 +0200 | [diff] [blame] | 946 | void setup_APIC_extened_lvt(unsigned char lvt_off, unsigned char vector, |
| 947 | unsigned char msg_type, unsigned char mask) |
Jacob Shin | 89b831e | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 948 | { |
Jacob Shin | 17fc14f | 2006-06-26 13:58:47 +0200 | [diff] [blame] | 949 | unsigned long reg = (lvt_off << 4) + K8_APIC_EXT_LVT_BASE; |
| 950 | unsigned int v = (mask << 16) | (msg_type << 8) | vector; |
Jacob Shin | 89b831e | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 951 | apic_write(reg, v); |
| 952 | } |
Jacob Shin | 89b831e | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | #undef APIC_DIVISOR |
| 955 | |
| 956 | /* |
| 957 | * Local timer interrupt handler. It does both profiling and |
| 958 | * process statistics/rescheduling. |
| 959 | * |
| 960 | * We do profiling in every local tick, statistics/rescheduling |
| 961 | * happen only every 'profiling multiplier' ticks. The default |
| 962 | * multiplier is 1 and it can be changed by writing the new multiplier |
| 963 | * value into /proc/profile. |
| 964 | */ |
| 965 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 966 | void smp_local_timer_interrupt(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 968 | profile_tick(CPU_PROFILING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | #ifdef CONFIG_SMP |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 970 | update_process_times(user_mode(get_irq_regs())); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | #endif |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 972 | if (apic_runs_main_timer > 1 && smp_processor_id() == boot_cpu_id) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 973 | main_timer_handler(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | /* |
| 975 | * We take the 'long' return path, and there every subsystem |
| 976 | * grabs the appropriate locks (kernel lock/ irq lock). |
| 977 | * |
Adam Henley | d5d9ca6 | 2006-09-26 10:52:28 +0200 | [diff] [blame] | 978 | * We might want to decouple profiling from the 'long path', |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | * and do the profiling totally in assembly. |
| 980 | * |
| 981 | * Currently this isn't too much of an issue (performance wise), |
| 982 | * we can take more than 100K local irqs per second on a 100 MHz P5. |
| 983 | */ |
| 984 | } |
| 985 | |
| 986 | /* |
| 987 | * Local APIC timer interrupt. This is the most natural way for doing |
| 988 | * local interrupts, but local timer interrupts can be emulated by |
| 989 | * broadcast interrupts too. [in case the hw doesn't support APIC timers] |
| 990 | * |
| 991 | * [ if a single-CPU system runs an SMP kernel then we call the local |
| 992 | * interrupt as well. Thus we cannot inline the local irq ... ] |
| 993 | */ |
Andrew Morton | d150ad7 | 2006-10-06 13:28:09 -0700 | [diff] [blame] | 994 | void smp_apic_timer_interrupt(struct pt_regs *regs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | { |
Andrew Morton | d150ad7 | 2006-10-06 13:28:09 -0700 | [diff] [blame] | 996 | struct pt_regs *old_regs = set_irq_regs(regs); |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | /* |
| 999 | * the NMI deadlock-detector uses this. |
| 1000 | */ |
| 1001 | add_pda(apic_timer_irqs, 1); |
| 1002 | |
| 1003 | /* |
| 1004 | * NOTE! We'd better ACK the irq immediately, |
| 1005 | * because timer handling can be slow. |
| 1006 | */ |
| 1007 | ack_APIC_irq(); |
| 1008 | /* |
| 1009 | * update_process_times() expects us to have done irq_enter(). |
| 1010 | * Besides, if we don't timer interrupts ignore the global |
| 1011 | * interrupt lock, which is the WrongThing (tm) to do. |
| 1012 | */ |
Andi Kleen | 95833c8 | 2006-01-11 22:44:36 +0100 | [diff] [blame] | 1013 | exit_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | irq_enter(); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1015 | smp_local_timer_interrupt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | irq_exit(); |
Andrew Morton | d150ad7 | 2006-10-06 13:28:09 -0700 | [diff] [blame] | 1017 | set_irq_regs(old_regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | /* |
Vojtech Pavlik | f8bf3c6 | 2006-06-26 13:58:23 +0200 | [diff] [blame] | 1021 | * apic_is_clustered_box() -- Check if we can expect good TSC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | * |
| 1023 | * Thus far, the major user of this is IBM's Summit2 series: |
| 1024 | * |
Linus Torvalds | 637029c | 2006-02-27 20:41:56 -0800 | [diff] [blame] | 1025 | * Clustered boxes may have unsynced TSC problems if they are |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | * multi-chassis. Use available data to take a good guess. |
| 1027 | * If in doubt, go HPET. |
| 1028 | */ |
Vojtech Pavlik | f8bf3c6 | 2006-06-26 13:58:23 +0200 | [diff] [blame] | 1029 | __cpuinit int apic_is_clustered_box(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { |
| 1031 | int i, clusters, zeros; |
| 1032 | unsigned id; |
| 1033 | DECLARE_BITMAP(clustermap, NUM_APIC_CLUSTERS); |
| 1034 | |
Suresh Siddha | 376ec33 | 2005-05-16 21:53:32 -0700 | [diff] [blame] | 1035 | bitmap_zero(clustermap, NUM_APIC_CLUSTERS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | |
| 1037 | for (i = 0; i < NR_CPUS; i++) { |
| 1038 | id = bios_cpu_apicid[i]; |
| 1039 | if (id != BAD_APICID) |
| 1040 | __set_bit(APIC_CLUSTERID(id), clustermap); |
| 1041 | } |
| 1042 | |
| 1043 | /* Problem: Partially populated chassis may not have CPUs in some of |
| 1044 | * the APIC clusters they have been allocated. Only present CPUs have |
| 1045 | * bios_cpu_apicid entries, thus causing zeroes in the bitmap. Since |
| 1046 | * clusters are allocated sequentially, count zeros only if they are |
| 1047 | * bounded by ones. |
| 1048 | */ |
| 1049 | clusters = 0; |
| 1050 | zeros = 0; |
| 1051 | for (i = 0; i < NUM_APIC_CLUSTERS; i++) { |
| 1052 | if (test_bit(i, clustermap)) { |
| 1053 | clusters += 1 + zeros; |
| 1054 | zeros = 0; |
| 1055 | } else |
| 1056 | ++zeros; |
| 1057 | } |
| 1058 | |
| 1059 | /* |
Vojtech Pavlik | f8bf3c6 | 2006-06-26 13:58:23 +0200 | [diff] [blame] | 1060 | * If clusters > 2, then should be multi-chassis. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | * May have to revisit this when multi-core + hyperthreaded CPUs come |
| 1062 | * out, but AFAIK this will work even for them. |
| 1063 | */ |
| 1064 | return (clusters > 2); |
| 1065 | } |
| 1066 | |
| 1067 | /* |
| 1068 | * This interrupt should _never_ happen with our APIC/SMP architecture |
| 1069 | */ |
| 1070 | asmlinkage void smp_spurious_interrupt(void) |
| 1071 | { |
| 1072 | unsigned int v; |
Andi Kleen | 95833c8 | 2006-01-11 22:44:36 +0100 | [diff] [blame] | 1073 | exit_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | irq_enter(); |
| 1075 | /* |
| 1076 | * Check if this really is a spurious interrupt and ACK it |
| 1077 | * if it is a vectored one. Just in case... |
| 1078 | * Spurious interrupts should not be ACKed. |
| 1079 | */ |
| 1080 | v = apic_read(APIC_ISR + ((SPURIOUS_APIC_VECTOR & ~0x1f) >> 1)); |
| 1081 | if (v & (1 << (SPURIOUS_APIC_VECTOR & 0x1f))) |
| 1082 | ack_APIC_irq(); |
| 1083 | |
| 1084 | #if 0 |
| 1085 | static unsigned long last_warning; |
| 1086 | static unsigned long skipped; |
| 1087 | |
| 1088 | /* see sw-dev-man vol 3, chapter 7.4.13.5 */ |
| 1089 | if (time_before(last_warning+30*HZ,jiffies)) { |
| 1090 | printk(KERN_INFO "spurious APIC interrupt on CPU#%d, %ld skipped.\n", |
| 1091 | smp_processor_id(), skipped); |
| 1092 | last_warning = jiffies; |
| 1093 | skipped = 0; |
| 1094 | } else { |
| 1095 | skipped++; |
| 1096 | } |
| 1097 | #endif |
| 1098 | irq_exit(); |
| 1099 | } |
| 1100 | |
| 1101 | /* |
| 1102 | * This interrupt should never happen with our APIC/SMP architecture |
| 1103 | */ |
| 1104 | |
| 1105 | asmlinkage void smp_error_interrupt(void) |
| 1106 | { |
| 1107 | unsigned int v, v1; |
| 1108 | |
Andi Kleen | 95833c8 | 2006-01-11 22:44:36 +0100 | [diff] [blame] | 1109 | exit_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | irq_enter(); |
| 1111 | /* First tickle the hardware, only then report what went on. -- REW */ |
| 1112 | v = apic_read(APIC_ESR); |
| 1113 | apic_write(APIC_ESR, 0); |
| 1114 | v1 = apic_read(APIC_ESR); |
| 1115 | ack_APIC_irq(); |
| 1116 | atomic_inc(&irq_err_count); |
| 1117 | |
| 1118 | /* Here is what the APIC error bits mean: |
| 1119 | 0: Send CS error |
| 1120 | 1: Receive CS error |
| 1121 | 2: Send accept error |
| 1122 | 3: Receive accept error |
| 1123 | 4: Reserved |
| 1124 | 5: Send illegal vector |
| 1125 | 6: Received illegal vector |
| 1126 | 7: Illegal register address |
| 1127 | */ |
| 1128 | printk (KERN_DEBUG "APIC error on CPU%d: %02x(%02x)\n", |
| 1129 | smp_processor_id(), v , v1); |
| 1130 | irq_exit(); |
| 1131 | } |
| 1132 | |
| 1133 | int disable_apic; |
| 1134 | |
| 1135 | /* |
| 1136 | * This initializes the IO-APIC and APIC hardware if this is |
| 1137 | * a UP kernel. |
| 1138 | */ |
| 1139 | int __init APIC_init_uniprocessor (void) |
| 1140 | { |
| 1141 | if (disable_apic) { |
| 1142 | printk(KERN_INFO "Apic disabled\n"); |
| 1143 | return -1; |
| 1144 | } |
| 1145 | if (!cpu_has_apic) { |
| 1146 | disable_apic = 1; |
| 1147 | printk(KERN_INFO "Apic disabled by BIOS\n"); |
| 1148 | return -1; |
| 1149 | } |
| 1150 | |
| 1151 | verify_local_APIC(); |
| 1152 | |
Andi Kleen | 357e11d | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 1153 | phys_cpu_present_map = physid_mask_of_physid(boot_cpu_id); |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 1154 | apic_write(APIC_ID, SET_APIC_ID(boot_cpu_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | |
| 1156 | setup_local_APIC(); |
| 1157 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | if (smp_found_config && !skip_ioapic_setup && nr_ioapics) |
Andi Kleen | 7f11d8a | 2006-09-26 10:52:29 +0200 | [diff] [blame] | 1159 | setup_IO_APIC(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | else |
| 1161 | nr_ioapics = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | setup_boot_APIC_clock(); |
Andi Kleen | 7515211 | 2005-05-16 21:53:34 -0700 | [diff] [blame] | 1163 | check_nmi_watchdog(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | static __init int setup_disableapic(char *str) |
| 1168 | { |
| 1169 | disable_apic = 1; |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1170 | clear_bit(X86_FEATURE_APIC, boot_cpu_data.x86_capability); |
| 1171 | return 0; |
| 1172 | } |
| 1173 | early_param("disableapic", setup_disableapic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1175 | /* same as disableapic, for compatibility */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | static __init int setup_nolapic(char *str) |
| 1177 | { |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1178 | return setup_disableapic(str); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | } |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1180 | early_param("nolapic", setup_nolapic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | |
| 1182 | static __init int setup_noapictimer(char *str) |
| 1183 | { |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 1184 | if (str[0] != ' ' && str[0] != 0) |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1185 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | disable_apic_timer = 1; |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1187 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 1190 | static __init int setup_apicmaintimer(char *str) |
| 1191 | { |
| 1192 | apic_runs_main_timer = 1; |
| 1193 | nohpet = 1; |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1194 | return 1; |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 1195 | } |
| 1196 | __setup("apicmaintimer", setup_apicmaintimer); |
| 1197 | |
| 1198 | static __init int setup_noapicmaintimer(char *str) |
| 1199 | { |
| 1200 | apic_runs_main_timer = -1; |
OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 1201 | return 1; |
Andi Kleen | 73dea47 | 2006-02-03 21:50:50 +0100 | [diff] [blame] | 1202 | } |
| 1203 | __setup("noapicmaintimer", setup_noapicmaintimer); |
| 1204 | |
Andi Kleen | 0c3749c | 2006-02-03 21:51:41 +0100 | [diff] [blame] | 1205 | static __init int setup_apicpmtimer(char *s) |
| 1206 | { |
| 1207 | apic_calibrate_pmtmr = 1; |
Andi Kleen | 7fd6784 | 2006-02-16 23:42:07 +0100 | [diff] [blame] | 1208 | notsc_setup(NULL); |
Andi Kleen | 0c3749c | 2006-02-03 21:51:41 +0100 | [diff] [blame] | 1209 | return setup_apicmaintimer(NULL); |
| 1210 | } |
| 1211 | __setup("apicpmtimer", setup_apicpmtimer); |
| 1212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | __setup("noapictimer", setup_noapictimer); |
| 1214 | |