Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Intel IO-APIC support for multi-Pentium hosts. |
| 3 | * |
| 4 | * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar, Hajnalka Szabo |
| 5 | * |
| 6 | * Many thanks to Stig Venaas for trying out countless experimental |
| 7 | * patches and reporting/debugging problems patiently! |
| 8 | * |
| 9 | * (c) 1999, Multiple IO-APIC support, developed by |
| 10 | * Ken-ichi Yaku <yaku@css1.kbnes.nec.co.jp> and |
| 11 | * Hidemi Kishimoto <kisimoto@css1.kbnes.nec.co.jp>, |
| 12 | * further tested and cleaned up by Zach Brown <zab@redhat.com> |
| 13 | * and Ingo Molnar <mingo@redhat.com> |
| 14 | * |
| 15 | * Fixes |
| 16 | * Maciej W. Rozycki : Bits for genuine 82489DX APICs; |
| 17 | * thanks to Eric Gilmore |
| 18 | * and Rolf G. Tews |
| 19 | * for testing these extensively |
| 20 | * Paul Diefenbaugh : Added full ACPI support |
| 21 | */ |
| 22 | |
| 23 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/sched.h> |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 28 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/mc146818rtc.h> |
| 30 | #include <linux/compiler.h> |
| 31 | #include <linux/acpi.h> |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 32 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/sysdev.h> |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 34 | #include <linux/pci.h> |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 35 | #include <linux/msi.h> |
Eric W. Biederman | 95d7788 | 2006-10-04 02:17:01 -0700 | [diff] [blame] | 36 | #include <linux/htirq.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 37 | #include <linux/freezer.h> |
Eric W. Biederman | f26d6a2 | 2007-05-02 19:27:19 +0200 | [diff] [blame] | 38 | #include <linux/kthread.h> |
Julia Lawall | 1d16b53 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 39 | #include <linux/jiffies.h> /* time_after() */ |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <asm/io.h> |
| 42 | #include <asm/smp.h> |
| 43 | #include <asm/desc.h> |
| 44 | #include <asm/timer.h> |
Ingo Molnar | 306e440 | 2005-06-30 02:58:55 -0700 | [diff] [blame] | 45 | #include <asm/i8259.h> |
Don Zickus | 3e4ff11 | 2006-06-26 13:57:01 +0200 | [diff] [blame] | 46 | #include <asm/nmi.h> |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 47 | #include <asm/msidef.h> |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 48 | #include <asm/hypertransport.h> |
Yinghai Lu | a4dbc34 | 2008-07-25 02:14:28 -0700 | [diff] [blame] | 49 | #include <asm/setup.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #include <mach_apic.h> |
Andi Kleen | 874c4fe | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 52 | #include <mach_apicdef.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 54 | #define __apicdebuginit(type) static type __init |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | int (*ioapic_renumber_irq)(int ioapic, int irq); |
| 57 | atomic_t irq_mis_count; |
| 58 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 59 | /* Where if anywhere is the i8259 connect in external int mode */ |
| 60 | static struct { int pin, apic; } ioapic_i8259 = { -1, -1 }; |
| 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static DEFINE_SPINLOCK(ioapic_lock); |
Eric W. Biederman | d388e5f | 2008-08-09 15:09:02 -0700 | [diff] [blame] | 63 | DEFINE_SPINLOCK(vector_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Maciej W. Rozycki | 35542c5 | 2008-05-21 22:10:22 +0100 | [diff] [blame] | 65 | int timer_through_8259 __initdata; |
Andi Kleen | f9262c1 | 2006-03-08 17:57:25 -0800 | [diff] [blame] | 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | /* |
| 68 | * Is the SiS APIC rmw bug present ? |
| 69 | * -1 = don't know, 0 = no, 1 = yes |
| 70 | */ |
| 71 | int sis_apic_bug = -1; |
| 72 | |
Yinghai Lu | 301e619 | 2008-08-19 20:50:02 -0700 | [diff] [blame] | 73 | int first_free_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | /* |
| 75 | * # of IRQ routing registers |
| 76 | */ |
| 77 | int nr_ioapic_registers[MAX_IO_APICS]; |
| 78 | |
Alexey Starikovskiy | 9f640cc | 2008-04-04 23:41:13 +0400 | [diff] [blame] | 79 | /* I/O APIC entries */ |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 80 | struct mp_config_ioapic mp_ioapics[MAX_IO_APICS]; |
Alexey Starikovskiy | 9f640cc | 2008-04-04 23:41:13 +0400 | [diff] [blame] | 81 | int nr_ioapics; |
| 82 | |
Alexey Starikovskiy | 584f734 | 2008-04-04 23:41:32 +0400 | [diff] [blame] | 83 | /* MP IRQ source entries */ |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 84 | struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES]; |
Alexey Starikovskiy | 584f734 | 2008-04-04 23:41:32 +0400 | [diff] [blame] | 85 | |
| 86 | /* # of MP IRQ source entries */ |
| 87 | int mp_irq_entries; |
| 88 | |
Alexey Starikovskiy | 8732fc4 | 2008-05-19 19:47:16 +0400 | [diff] [blame] | 89 | #if defined (CONFIG_MCA) || defined (CONFIG_EISA) |
| 90 | int mp_bus_id_to_type[MAX_MP_BUSSES]; |
| 91 | #endif |
| 92 | |
| 93 | DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); |
| 94 | |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 95 | static int disable_timer_pin_1 __initdata; |
Chuck Ebbert | 66759a0 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 96 | |
Yinghai Lu | a1420f3 | 2008-08-19 20:50:24 -0700 | [diff] [blame^] | 97 | struct irq_cfg { |
| 98 | u8 vector; |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */ |
| 103 | static struct irq_cfg irq_cfg_legacy[] __initdata = { |
| 104 | [0] = { .vector = FIRST_DEVICE_VECTOR, }, |
| 105 | }; |
| 106 | |
| 107 | static void __init init_work(void *data) |
| 108 | { |
| 109 | struct dyn_array *da = data; |
| 110 | struct irq_cfg *cfg; |
| 111 | int legacy_count; |
| 112 | int i; |
| 113 | |
| 114 | cfg = *da->name; |
| 115 | |
| 116 | legacy_count = sizeof(irq_cfg_legacy)/sizeof(irq_cfg_legacy[0]); |
| 117 | |
| 118 | BUG_ON(legacy_count > nr_irqs); |
| 119 | |
| 120 | memcpy(cfg, irq_cfg_legacy, sizeof(irq_cfg_legacy)); |
| 121 | } |
| 122 | |
| 123 | static struct irq_cfg *irq_cfgx; |
| 124 | DEFINE_DYN_ARRAY(irq_cfgx, sizeof(struct irq_cfg), nr_irqs, PAGE_SIZE, init_work); |
| 125 | |
| 126 | static struct irq_cfg *irq_cfg(unsigned int irq) |
| 127 | { |
| 128 | if (irq >= nr_irqs) |
| 129 | return NULL; |
| 130 | |
| 131 | return &irq_cfgx[irq]; |
| 132 | } |
| 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | /* |
| 135 | * Rough estimation of how many shared IRQs there are, can |
| 136 | * be changed anytime. |
| 137 | */ |
Yinghai Lu | 301e619 | 2008-08-19 20:50:02 -0700 | [diff] [blame] | 138 | int pin_map_size; |
Yinghai Lu | 0799e43 | 2008-08-19 20:49:48 -0700 | [diff] [blame] | 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* |
| 141 | * This is performance-critical, we want to do it O(1) |
| 142 | * |
| 143 | * the indexing order of this array favors 1:1 mappings |
| 144 | * between pins and IRQs. |
| 145 | */ |
| 146 | |
| 147 | static struct irq_pin_list { |
| 148 | int apic, pin, next; |
Yinghai Lu | 301e619 | 2008-08-19 20:50:02 -0700 | [diff] [blame] | 149 | } *irq_2_pin; |
| 150 | |
| 151 | DEFINE_DYN_ARRAY(irq_2_pin, sizeof(struct irq_pin_list), pin_map_size, 16, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 153 | struct io_apic { |
| 154 | unsigned int index; |
| 155 | unsigned int unused[3]; |
| 156 | unsigned int data; |
| 157 | }; |
| 158 | |
| 159 | static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx) |
| 160 | { |
| 161 | return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx) |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 162 | + (mp_ioapics[idx].mp_apicaddr & ~PAGE_MASK); |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg) |
| 166 | { |
| 167 | struct io_apic __iomem *io_apic = io_apic_base(apic); |
| 168 | writel(reg, &io_apic->index); |
| 169 | return readl(&io_apic->data); |
| 170 | } |
| 171 | |
| 172 | static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value) |
| 173 | { |
| 174 | struct io_apic __iomem *io_apic = io_apic_base(apic); |
| 175 | writel(reg, &io_apic->index); |
| 176 | writel(value, &io_apic->data); |
| 177 | } |
| 178 | |
| 179 | /* |
| 180 | * Re-write a value: to be used for read-modify-write |
| 181 | * cycles where the read already set up the index register. |
| 182 | * |
| 183 | * Older SiS APIC requires we rewrite the index register |
| 184 | */ |
| 185 | static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value) |
| 186 | { |
Al Viro | cb46898 | 2007-02-09 16:39:25 +0000 | [diff] [blame] | 187 | volatile struct io_apic __iomem *io_apic = io_apic_base(apic); |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 188 | if (sis_apic_bug) |
| 189 | writel(reg, &io_apic->index); |
| 190 | writel(value, &io_apic->data); |
| 191 | } |
| 192 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 193 | union entry_union { |
| 194 | struct { u32 w1, w2; }; |
| 195 | struct IO_APIC_route_entry entry; |
| 196 | }; |
| 197 | |
| 198 | static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin) |
| 199 | { |
| 200 | union entry_union eu; |
| 201 | unsigned long flags; |
| 202 | spin_lock_irqsave(&ioapic_lock, flags); |
| 203 | eu.w1 = io_apic_read(apic, 0x10 + 2 * pin); |
| 204 | eu.w2 = io_apic_read(apic, 0x11 + 2 * pin); |
| 205 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 206 | return eu.entry; |
| 207 | } |
| 208 | |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 209 | /* |
| 210 | * When we write a new IO APIC routing entry, we need to write the high |
| 211 | * word first! If the mask bit in the low word is clear, we will enable |
| 212 | * the interrupt, and we need to make sure the entry is fully populated |
| 213 | * before that happens. |
| 214 | */ |
Andi Kleen | d15512f | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 215 | static void |
| 216 | __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e) |
| 217 | { |
| 218 | union entry_union eu; |
| 219 | eu.entry = e; |
| 220 | io_apic_write(apic, 0x11 + 2*pin, eu.w2); |
| 221 | io_apic_write(apic, 0x10 + 2*pin, eu.w1); |
| 222 | } |
| 223 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 224 | static void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e) |
| 225 | { |
| 226 | unsigned long flags; |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 227 | spin_lock_irqsave(&ioapic_lock, flags); |
Andi Kleen | d15512f | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 228 | __ioapic_write_entry(apic, pin, e); |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 229 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * When we mask an IO APIC routing entry, we need to write the low |
| 234 | * word first, in order to set the mask bit before we change the |
| 235 | * high bits! |
| 236 | */ |
| 237 | static void ioapic_mask_entry(int apic, int pin) |
| 238 | { |
| 239 | unsigned long flags; |
| 240 | union entry_union eu = { .entry.mask = 1 }; |
| 241 | |
| 242 | spin_lock_irqsave(&ioapic_lock, flags); |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 243 | io_apic_write(apic, 0x10 + 2*pin, eu.w1); |
| 244 | io_apic_write(apic, 0x11 + 2*pin, eu.w2); |
| 245 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 246 | } |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | /* |
| 249 | * The common case is 1:1 IRQ<->pin mappings. Sometimes there are |
| 250 | * shared ISA-space IRQs, so we have to support them. We are super |
| 251 | * fast in the common case, and fast for shared ISA-space IRQs. |
| 252 | */ |
| 253 | static void add_pin_to_irq(unsigned int irq, int apic, int pin) |
| 254 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | struct irq_pin_list *entry = irq_2_pin + irq; |
| 256 | |
| 257 | while (entry->next) |
| 258 | entry = irq_2_pin + entry->next; |
| 259 | |
| 260 | if (entry->pin != -1) { |
| 261 | entry->next = first_free_entry; |
| 262 | entry = irq_2_pin + entry->next; |
Yinghai Lu | 0799e43 | 2008-08-19 20:49:48 -0700 | [diff] [blame] | 263 | if (++first_free_entry >= pin_map_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | panic("io_apic.c: whoops"); |
| 265 | } |
| 266 | entry->apic = apic; |
| 267 | entry->pin = pin; |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | * Reroute an IRQ to a different pin. |
| 272 | */ |
| 273 | static void __init replace_pin_at_irq(unsigned int irq, |
| 274 | int oldapic, int oldpin, |
| 275 | int newapic, int newpin) |
| 276 | { |
| 277 | struct irq_pin_list *entry = irq_2_pin + irq; |
| 278 | |
| 279 | while (1) { |
| 280 | if (entry->apic == oldapic && entry->pin == oldpin) { |
| 281 | entry->apic = newapic; |
| 282 | entry->pin = newpin; |
| 283 | } |
| 284 | if (!entry->next) |
| 285 | break; |
| 286 | entry = irq_2_pin + entry->next; |
| 287 | } |
| 288 | } |
| 289 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 290 | static void __modify_IO_APIC_irq(unsigned int irq, unsigned long enable, unsigned long disable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | { |
| 292 | struct irq_pin_list *entry = irq_2_pin + irq; |
| 293 | unsigned int pin, reg; |
| 294 | |
| 295 | for (;;) { |
| 296 | pin = entry->pin; |
| 297 | if (pin == -1) |
| 298 | break; |
| 299 | reg = io_apic_read(entry->apic, 0x10 + pin*2); |
| 300 | reg &= ~disable; |
| 301 | reg |= enable; |
| 302 | io_apic_modify(entry->apic, 0x10 + pin*2, reg); |
| 303 | if (!entry->next) |
| 304 | break; |
| 305 | entry = irq_2_pin + entry->next; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /* mask = 1 */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 310 | static void __mask_IO_APIC_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | { |
Cyrill Gorcunov | 46b3b4e | 2008-06-07 19:53:57 +0400 | [diff] [blame] | 312 | __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | /* mask = 0 */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 316 | static void __unmask_IO_APIC_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { |
Cyrill Gorcunov | 46b3b4e | 2008-06-07 19:53:57 +0400 | [diff] [blame] | 318 | __modify_IO_APIC_irq(irq, 0, IO_APIC_REDIR_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /* mask = 1, trigger = 0 */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 322 | static void __mask_and_edge_IO_APIC_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Cyrill Gorcunov | 46b3b4e | 2008-06-07 19:53:57 +0400 | [diff] [blame] | 324 | __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED, |
| 325 | IO_APIC_REDIR_LEVEL_TRIGGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* mask = 0, trigger = 1 */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 329 | static void __unmask_and_level_IO_APIC_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
Cyrill Gorcunov | 46b3b4e | 2008-06-07 19:53:57 +0400 | [diff] [blame] | 331 | __modify_IO_APIC_irq(irq, IO_APIC_REDIR_LEVEL_TRIGGER, |
| 332 | IO_APIC_REDIR_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 335 | static void mask_IO_APIC_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
| 337 | unsigned long flags; |
| 338 | |
| 339 | spin_lock_irqsave(&ioapic_lock, flags); |
| 340 | __mask_IO_APIC_irq(irq); |
| 341 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 342 | } |
| 343 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 344 | static void unmask_IO_APIC_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
| 346 | unsigned long flags; |
| 347 | |
| 348 | spin_lock_irqsave(&ioapic_lock, flags); |
| 349 | __unmask_IO_APIC_irq(irq); |
| 350 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 351 | } |
| 352 | |
| 353 | static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin) |
| 354 | { |
| 355 | struct IO_APIC_route_entry entry; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | /* Check delivery_mode to be sure we're not clearing an SMI pin */ |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 358 | entry = ioapic_read_entry(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (entry.delivery_mode == dest_SMI) |
| 360 | return; |
| 361 | |
| 362 | /* |
| 363 | * Disable it in the IO-APIC irq-routing table: |
| 364 | */ |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 365 | ioapic_mask_entry(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 368 | static void clear_IO_APIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | { |
| 370 | int apic, pin; |
| 371 | |
| 372 | for (apic = 0; apic < nr_ioapics; apic++) |
| 373 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) |
| 374 | clear_IO_APIC_pin(apic, pin); |
| 375 | } |
| 376 | |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 377 | #ifdef CONFIG_SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t cpumask) |
| 379 | { |
| 380 | unsigned long flags; |
| 381 | int pin; |
| 382 | struct irq_pin_list *entry = irq_2_pin + irq; |
| 383 | unsigned int apicid_value; |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 384 | cpumask_t tmp; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 385 | struct irq_desc *desc; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 386 | |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 387 | cpus_and(tmp, cpumask, cpu_online_map); |
| 388 | if (cpus_empty(tmp)) |
| 389 | tmp = TARGET_CPUS; |
| 390 | |
| 391 | cpus_and(cpumask, tmp, CPU_MASK_ALL); |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | apicid_value = cpu_mask_to_apicid(cpumask); |
| 394 | /* Prepare to do the io_apic_write */ |
| 395 | apicid_value = apicid_value << 24; |
| 396 | spin_lock_irqsave(&ioapic_lock, flags); |
| 397 | for (;;) { |
| 398 | pin = entry->pin; |
| 399 | if (pin == -1) |
| 400 | break; |
| 401 | io_apic_write(entry->apic, 0x10 + 1 + pin*2, apicid_value); |
| 402 | if (!entry->next) |
| 403 | break; |
| 404 | entry = irq_2_pin + entry->next; |
| 405 | } |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 406 | desc = irq_to_desc(irq); |
| 407 | desc->affinity = cpumask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 409 | } |
| 410 | |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 411 | #endif /* CONFIG_SMP */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | #ifndef CONFIG_SMP |
Harvey Harrison | 75604d7 | 2008-01-30 13:31:17 +0100 | [diff] [blame] | 414 | void send_IPI_self(int vector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | { |
| 416 | unsigned int cfg; |
| 417 | |
| 418 | /* |
| 419 | * Wait for idle. |
| 420 | */ |
| 421 | apic_wait_icr_idle(); |
| 422 | cfg = APIC_DM_FIXED | APIC_DEST_SELF | vector | APIC_DEST_LOGICAL; |
| 423 | /* |
| 424 | * Send the IPI. The write to APIC_ICR fires this off. |
| 425 | */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 426 | apic_write(APIC_ICR, cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | #endif /* !CONFIG_SMP */ |
| 429 | |
| 430 | |
| 431 | /* |
| 432 | * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to |
| 433 | * specific CPU-side IRQs. |
| 434 | */ |
| 435 | |
| 436 | #define MAX_PIRQS 8 |
| 437 | static int pirq_entries [MAX_PIRQS]; |
| 438 | static int pirqs_enabled; |
| 439 | int skip_ioapic_setup; |
| 440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | static int __init ioapic_pirq_setup(char *str) |
| 442 | { |
| 443 | int i, max; |
| 444 | int ints[MAX_PIRQS+1]; |
| 445 | |
| 446 | get_options(str, ARRAY_SIZE(ints), ints); |
| 447 | |
| 448 | for (i = 0; i < MAX_PIRQS; i++) |
| 449 | pirq_entries[i] = -1; |
| 450 | |
| 451 | pirqs_enabled = 1; |
| 452 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 453 | "PIRQ redirection, working around broken MP-BIOS.\n"); |
| 454 | max = MAX_PIRQS; |
| 455 | if (ints[0] < MAX_PIRQS) |
| 456 | max = ints[0]; |
| 457 | |
| 458 | for (i = 0; i < max; i++) { |
| 459 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 460 | "... PIRQ%d -> IRQ %d\n", i, ints[i+1]); |
| 461 | /* |
| 462 | * PIRQs are mapped upside down, usually. |
| 463 | */ |
| 464 | pirq_entries[MAX_PIRQS-i-1] = ints[i+1]; |
| 465 | } |
| 466 | return 1; |
| 467 | } |
| 468 | |
| 469 | __setup("pirq=", ioapic_pirq_setup); |
| 470 | |
| 471 | /* |
| 472 | * Find the IRQ entry number of a certain pin. |
| 473 | */ |
| 474 | static int find_irq_entry(int apic, int pin, int type) |
| 475 | { |
| 476 | int i; |
| 477 | |
| 478 | for (i = 0; i < mp_irq_entries; i++) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 479 | if (mp_irqs[i].mp_irqtype == type && |
| 480 | (mp_irqs[i].mp_dstapic == mp_ioapics[apic].mp_apicid || |
| 481 | mp_irqs[i].mp_dstapic == MP_APIC_ALL) && |
| 482 | mp_irqs[i].mp_dstirq == pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return i; |
| 484 | |
| 485 | return -1; |
| 486 | } |
| 487 | |
| 488 | /* |
| 489 | * Find the pin to which IRQ[irq] (ISA) is connected |
| 490 | */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 491 | static int __init find_isa_irq_pin(int irq, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
| 493 | int i; |
| 494 | |
| 495 | for (i = 0; i < mp_irq_entries; i++) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 496 | int lbus = mp_irqs[i].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Alexey Starikovskiy | d27e2b8 | 2008-03-20 14:54:18 +0300 | [diff] [blame] | 498 | if (test_bit(lbus, mp_bus_not_pci) && |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 499 | (mp_irqs[i].mp_irqtype == type) && |
| 500 | (mp_irqs[i].mp_srcbusirq == irq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 502 | return mp_irqs[i].mp_dstirq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | return -1; |
| 505 | } |
| 506 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 507 | static int __init find_isa_irq_apic(int irq, int type) |
| 508 | { |
| 509 | int i; |
| 510 | |
| 511 | for (i = 0; i < mp_irq_entries; i++) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 512 | int lbus = mp_irqs[i].mp_srcbus; |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 513 | |
Alexey Starikovskiy | 73b2961 | 2008-03-20 14:54:24 +0300 | [diff] [blame] | 514 | if (test_bit(lbus, mp_bus_not_pci) && |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 515 | (mp_irqs[i].mp_irqtype == type) && |
| 516 | (mp_irqs[i].mp_srcbusirq == irq)) |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 517 | break; |
| 518 | } |
| 519 | if (i < mp_irq_entries) { |
| 520 | int apic; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 521 | for (apic = 0; apic < nr_ioapics; apic++) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 522 | if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic) |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 523 | return apic; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | return -1; |
| 528 | } |
| 529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* |
| 531 | * Find a specific PCI IRQ entry. |
| 532 | * Not an __init, possibly needed by modules |
| 533 | */ |
| 534 | static int pin_2_irq(int idx, int apic, int pin); |
| 535 | |
| 536 | int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin) |
| 537 | { |
| 538 | int apic, i, best_guess = -1; |
| 539 | |
| 540 | apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, " |
| 541 | "slot:%d, pin:%d.\n", bus, slot, pin); |
Alexey Starikovskiy | ce6444d | 2008-05-19 19:47:09 +0400 | [diff] [blame] | 542 | if (test_bit(bus, mp_bus_not_pci)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | printk(KERN_WARNING "PCI BIOS passed nonexistent PCI bus %d!\n", bus); |
| 544 | return -1; |
| 545 | } |
| 546 | for (i = 0; i < mp_irq_entries; i++) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 547 | int lbus = mp_irqs[i].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
| 549 | for (apic = 0; apic < nr_ioapics; apic++) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 550 | if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic || |
| 551 | mp_irqs[i].mp_dstapic == MP_APIC_ALL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | break; |
| 553 | |
Alexey Starikovskiy | 47cab82 | 2008-03-20 14:54:30 +0300 | [diff] [blame] | 554 | if (!test_bit(lbus, mp_bus_not_pci) && |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 555 | !mp_irqs[i].mp_irqtype && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | (bus == lbus) && |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 557 | (slot == ((mp_irqs[i].mp_srcbusirq >> 2) & 0x1f))) { |
Ingo Molnar | 3de352b | 2008-07-08 11:14:58 +0200 | [diff] [blame] | 558 | int irq = pin_2_irq(i, apic, mp_irqs[i].mp_dstirq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
| 560 | if (!(apic || IO_APIC_IRQ(irq))) |
| 561 | continue; |
| 562 | |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 563 | if (pin == (mp_irqs[i].mp_srcbusirq & 3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | return irq; |
| 565 | /* |
| 566 | * Use the first all-but-pin matching entry as a |
| 567 | * best-guess fuzzy result for broken mptables. |
| 568 | */ |
| 569 | if (best_guess < 0) |
| 570 | best_guess = irq; |
| 571 | } |
| 572 | } |
| 573 | return best_guess; |
| 574 | } |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 575 | EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 578 | * This function currently is only a helper for the i386 smp boot process where |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | * we need to reprogram the ioredtbls to cater for the cpus which have come online |
| 580 | * so mask in all cases should simply be TARGET_CPUS |
| 581 | */ |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 582 | #ifdef CONFIG_SMP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | void __init setup_ioapic_dest(void) |
| 584 | { |
| 585 | int pin, ioapic, irq, irq_entry; |
| 586 | |
| 587 | if (skip_ioapic_setup == 1) |
| 588 | return; |
| 589 | |
| 590 | for (ioapic = 0; ioapic < nr_ioapics; ioapic++) { |
| 591 | for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) { |
| 592 | irq_entry = find_irq_entry(ioapic, pin, mp_INT); |
| 593 | if (irq_entry == -1) |
| 594 | continue; |
| 595 | irq = pin_2_irq(irq_entry, ioapic, pin); |
| 596 | set_ioapic_affinity_irq(irq, TARGET_CPUS); |
| 597 | } |
| 598 | |
| 599 | } |
| 600 | } |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 601 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 603 | #if defined(CONFIG_EISA) || defined(CONFIG_MCA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | /* |
| 605 | * EISA Edge/Level control register, ELCR |
| 606 | */ |
| 607 | static int EISA_ELCR(unsigned int irq) |
| 608 | { |
| 609 | if (irq < 16) { |
| 610 | unsigned int port = 0x4d0 + (irq >> 3); |
| 611 | return (inb(port) >> (irq & 7)) & 1; |
| 612 | } |
| 613 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 614 | "Broken MPtable reports ISA irq %d\n", irq); |
| 615 | return 0; |
| 616 | } |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 617 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 619 | /* ISA interrupts are always polarity zero edge triggered, |
| 620 | * when listed as conforming in the MP table. */ |
| 621 | |
| 622 | #define default_ISA_trigger(idx) (0) |
| 623 | #define default_ISA_polarity(idx) (0) |
| 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | /* EISA interrupts are always polarity zero and can be edge or level |
| 626 | * trigger depending on the ELCR value. If an interrupt is listed as |
| 627 | * EISA conforming in the MP table, that means its trigger type must |
| 628 | * be read in from the ELCR */ |
| 629 | |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 630 | #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].mp_srcbusirq)) |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 631 | #define default_EISA_polarity(idx) default_ISA_polarity(idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | /* PCI interrupts are always polarity one level triggered, |
| 634 | * when listed as conforming in the MP table. */ |
| 635 | |
| 636 | #define default_PCI_trigger(idx) (1) |
| 637 | #define default_PCI_polarity(idx) (1) |
| 638 | |
| 639 | /* MCA interrupts are always polarity zero level triggered, |
| 640 | * when listed as conforming in the MP table. */ |
| 641 | |
| 642 | #define default_MCA_trigger(idx) (1) |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 643 | #define default_MCA_polarity(idx) default_ISA_polarity(idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 645 | static int MPBIOS_polarity(int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 647 | int bus = mp_irqs[idx].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | int polarity; |
| 649 | |
| 650 | /* |
| 651 | * Determine IRQ line polarity (high active or low active): |
| 652 | */ |
Ingo Molnar | 3de352b | 2008-07-08 11:14:58 +0200 | [diff] [blame] | 653 | switch (mp_irqs[idx].mp_irqflag & 3) { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 654 | case 0: /* conforms, ie. bus-type dependent polarity */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 656 | polarity = test_bit(bus, mp_bus_not_pci)? |
| 657 | default_ISA_polarity(idx): |
| 658 | default_PCI_polarity(idx); |
| 659 | break; |
| 660 | } |
| 661 | case 1: /* high active */ |
| 662 | { |
| 663 | polarity = 0; |
| 664 | break; |
| 665 | } |
| 666 | case 2: /* reserved */ |
| 667 | { |
| 668 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 669 | polarity = 1; |
| 670 | break; |
| 671 | } |
| 672 | case 3: /* low active */ |
| 673 | { |
| 674 | polarity = 1; |
| 675 | break; |
| 676 | } |
| 677 | default: /* invalid */ |
| 678 | { |
| 679 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 680 | polarity = 1; |
| 681 | break; |
| 682 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | return polarity; |
| 685 | } |
| 686 | |
| 687 | static int MPBIOS_trigger(int idx) |
| 688 | { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 689 | int bus = mp_irqs[idx].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | int trigger; |
| 691 | |
| 692 | /* |
| 693 | * Determine IRQ trigger mode (edge or level sensitive): |
| 694 | */ |
Ingo Molnar | 3de352b | 2008-07-08 11:14:58 +0200 | [diff] [blame] | 695 | switch ((mp_irqs[idx].mp_irqflag>>2) & 3) { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 696 | case 0: /* conforms, ie. bus-type dependent */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 698 | trigger = test_bit(bus, mp_bus_not_pci)? |
| 699 | default_ISA_trigger(idx): |
| 700 | default_PCI_trigger(idx); |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 701 | #if defined(CONFIG_EISA) || defined(CONFIG_MCA) |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 702 | switch (mp_bus_id_to_type[bus]) { |
| 703 | case MP_BUS_ISA: /* ISA pin */ |
| 704 | { |
| 705 | /* set before the switch */ |
| 706 | break; |
| 707 | } |
| 708 | case MP_BUS_EISA: /* EISA pin */ |
| 709 | { |
| 710 | trigger = default_EISA_trigger(idx); |
| 711 | break; |
| 712 | } |
| 713 | case MP_BUS_PCI: /* PCI pin */ |
| 714 | { |
| 715 | /* set before the switch */ |
| 716 | break; |
| 717 | } |
| 718 | case MP_BUS_MCA: /* MCA pin */ |
| 719 | { |
| 720 | trigger = default_MCA_trigger(idx); |
| 721 | break; |
| 722 | } |
| 723 | default: |
| 724 | { |
| 725 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 726 | trigger = 1; |
| 727 | break; |
| 728 | } |
| 729 | } |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 730 | #endif |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 731 | break; |
| 732 | } |
| 733 | case 1: /* edge */ |
| 734 | { |
| 735 | trigger = 0; |
| 736 | break; |
| 737 | } |
| 738 | case 2: /* reserved */ |
| 739 | { |
| 740 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 741 | trigger = 1; |
| 742 | break; |
| 743 | } |
| 744 | case 3: /* level */ |
| 745 | { |
| 746 | trigger = 1; |
| 747 | break; |
| 748 | } |
| 749 | default: /* invalid */ |
| 750 | { |
| 751 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 752 | trigger = 0; |
| 753 | break; |
| 754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | return trigger; |
| 757 | } |
| 758 | |
| 759 | static inline int irq_polarity(int idx) |
| 760 | { |
| 761 | return MPBIOS_polarity(idx); |
| 762 | } |
| 763 | |
| 764 | static inline int irq_trigger(int idx) |
| 765 | { |
| 766 | return MPBIOS_trigger(idx); |
| 767 | } |
| 768 | |
| 769 | static int pin_2_irq(int idx, int apic, int pin) |
| 770 | { |
| 771 | int irq, i; |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 772 | int bus = mp_irqs[idx].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
| 774 | /* |
| 775 | * Debugging check, we are in big trouble if this message pops up! |
| 776 | */ |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 777 | if (mp_irqs[idx].mp_dstirq != pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n"); |
| 779 | |
Alexey Starikovskiy | 643befe | 2008-03-20 14:54:49 +0300 | [diff] [blame] | 780 | if (test_bit(bus, mp_bus_not_pci)) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 781 | irq = mp_irqs[idx].mp_srcbusirq; |
Alexey Starikovskiy | 643befe | 2008-03-20 14:54:49 +0300 | [diff] [blame] | 782 | else { |
| 783 | /* |
| 784 | * PCI IRQs are mapped in order |
| 785 | */ |
| 786 | i = irq = 0; |
| 787 | while (i < apic) |
| 788 | irq += nr_ioapic_registers[i++]; |
| 789 | irq += pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
Alexey Starikovskiy | 643befe | 2008-03-20 14:54:49 +0300 | [diff] [blame] | 791 | /* |
| 792 | * For MPS mode, so far only needed by ES7000 platform |
| 793 | */ |
| 794 | if (ioapic_renumber_irq) |
| 795 | irq = ioapic_renumber_irq(apic, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /* |
| 799 | * PCI IRQ command line redirection. Yes, limits are hardcoded. |
| 800 | */ |
| 801 | if ((pin >= 16) && (pin <= 23)) { |
| 802 | if (pirq_entries[pin-16] != -1) { |
| 803 | if (!pirq_entries[pin-16]) { |
| 804 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 805 | "disabling PIRQ%d\n", pin-16); |
| 806 | } else { |
| 807 | irq = pirq_entries[pin-16]; |
| 808 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 809 | "using PIRQ%d -> IRQ %d\n", |
| 810 | pin-16, irq); |
| 811 | } |
| 812 | } |
| 813 | } |
| 814 | return irq; |
| 815 | } |
| 816 | |
| 817 | static inline int IO_APIC_irq_trigger(int irq) |
| 818 | { |
| 819 | int apic, idx, pin; |
| 820 | |
| 821 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 822 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 823 | idx = find_irq_entry(apic, pin, mp_INT); |
| 824 | if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | return irq_trigger(idx); |
| 826 | } |
| 827 | } |
| 828 | /* |
| 829 | * nonexistent IRQs are edge default |
| 830 | */ |
| 831 | return 0; |
| 832 | } |
| 833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 835 | static int __assign_irq_vector(int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 837 | static int current_vector = FIRST_DEVICE_VECTOR, current_offset; |
Rusty Russell | dbeb2be | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 838 | int vector, offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
Yinghai Lu | 301e619 | 2008-08-19 20:50:02 -0700 | [diff] [blame] | 840 | BUG_ON((unsigned)irq >= nr_irqs); |
Jan Beulich | 0a1ad60 | 2006-06-26 13:56:43 +0200 | [diff] [blame] | 841 | |
Yinghai Lu | a1420f3 | 2008-08-19 20:50:24 -0700 | [diff] [blame^] | 842 | if (irq_cfg(irq)->vector > 0) |
| 843 | return irq_cfg(irq)->vector; |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 844 | |
Jan Beulich | 0a1ad60 | 2006-06-26 13:56:43 +0200 | [diff] [blame] | 845 | vector = current_vector; |
Eric W. Biederman | 8339f00 | 2007-01-29 13:19:05 -0700 | [diff] [blame] | 846 | offset = current_offset; |
| 847 | next: |
| 848 | vector += 8; |
Alan Mayer | 305b92a | 2008-04-15 15:36:56 -0500 | [diff] [blame] | 849 | if (vector >= first_system_vector) { |
Eric W. Biederman | 8339f00 | 2007-01-29 13:19:05 -0700 | [diff] [blame] | 850 | offset = (offset + 1) % 8; |
| 851 | vector = FIRST_DEVICE_VECTOR + offset; |
| 852 | } |
| 853 | if (vector == current_vector) |
| 854 | return -ENOSPC; |
Rusty Russell | dbeb2be | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 855 | if (test_and_set_bit(vector, used_vectors)) |
Eric W. Biederman | 8339f00 | 2007-01-29 13:19:05 -0700 | [diff] [blame] | 856 | goto next; |
Eric W. Biederman | 8339f00 | 2007-01-29 13:19:05 -0700 | [diff] [blame] | 857 | |
| 858 | current_vector = vector; |
| 859 | current_offset = offset; |
Yinghai Lu | a1420f3 | 2008-08-19 20:50:24 -0700 | [diff] [blame^] | 860 | irq_cfg(irq)->vector = vector; |
Jan Beulich | 0a1ad60 | 2006-06-26 13:56:43 +0200 | [diff] [blame] | 861 | |
| 862 | return vector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 865 | static int assign_irq_vector(int irq) |
| 866 | { |
| 867 | unsigned long flags; |
| 868 | int vector; |
| 869 | |
| 870 | spin_lock_irqsave(&vector_lock, flags); |
| 871 | vector = __assign_irq_vector(irq); |
| 872 | spin_unlock_irqrestore(&vector_lock, flags); |
| 873 | |
| 874 | return vector; |
| 875 | } |
Glauber Costa | 3fde690 | 2008-05-28 20:34:19 -0700 | [diff] [blame] | 876 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 877 | static struct irq_chip ioapic_chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
| 879 | #define IOAPIC_AUTO -1 |
| 880 | #define IOAPIC_EDGE 0 |
| 881 | #define IOAPIC_LEVEL 1 |
| 882 | |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 883 | static void ioapic_register_intr(int irq, int vector, unsigned long trigger) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 885 | struct irq_desc *desc; |
| 886 | |
| 887 | desc = irq_to_desc(irq); |
Jan Beulich | 6ebcc00 | 2006-06-26 13:56:46 +0200 | [diff] [blame] | 888 | if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) || |
Thomas Gleixner | cc75b92 | 2007-08-12 15:46:36 +0000 | [diff] [blame] | 889 | trigger == IOAPIC_LEVEL) { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 890 | desc->status |= IRQ_LEVEL; |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 891 | set_irq_chip_and_handler_name(irq, &ioapic_chip, |
| 892 | handle_fasteoi_irq, "fasteoi"); |
Thomas Gleixner | cc75b92 | 2007-08-12 15:46:36 +0000 | [diff] [blame] | 893 | } else { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 894 | desc->status &= ~IRQ_LEVEL; |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 895 | set_irq_chip_and_handler_name(irq, &ioapic_chip, |
| 896 | handle_edge_irq, "edge"); |
Thomas Gleixner | cc75b92 | 2007-08-12 15:46:36 +0000 | [diff] [blame] | 897 | } |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 898 | set_intr_gate(vector, interrupt[irq]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | static void __init setup_IO_APIC_irqs(void) |
| 902 | { |
| 903 | struct IO_APIC_route_entry entry; |
| 904 | int apic, pin, idx, irq, first_notcon = 1, vector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
| 906 | apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n"); |
| 907 | |
| 908 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 909 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { |
| 910 | |
| 911 | /* |
| 912 | * add it to the IO-APIC irq-routing table: |
| 913 | */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 914 | memset(&entry, 0, sizeof(entry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | |
| 916 | entry.delivery_mode = INT_DELIVERY_MODE; |
| 917 | entry.dest_mode = INT_DEST_MODE; |
| 918 | entry.mask = 0; /* enable IRQ */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 919 | entry.dest.logical.logical_dest = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | cpu_mask_to_apicid(TARGET_CPUS); |
| 921 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 922 | idx = find_irq_entry(apic, pin, mp_INT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | if (idx == -1) { |
| 924 | if (first_notcon) { |
| 925 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 926 | " IO-APIC (apicid-pin) %d-%d", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 927 | mp_ioapics[apic].mp_apicid, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | pin); |
| 929 | first_notcon = 0; |
| 930 | } else |
| 931 | apic_printk(APIC_VERBOSE, ", %d-%d", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 932 | mp_ioapics[apic].mp_apicid, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | continue; |
| 934 | } |
| 935 | |
Yinghai Lu | 20d225b | 2007-10-17 18:04:41 +0200 | [diff] [blame] | 936 | if (!first_notcon) { |
| 937 | apic_printk(APIC_VERBOSE, " not connected.\n"); |
| 938 | first_notcon = 1; |
| 939 | } |
| 940 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | entry.trigger = irq_trigger(idx); |
| 942 | entry.polarity = irq_polarity(idx); |
| 943 | |
| 944 | if (irq_trigger(idx)) { |
| 945 | entry.trigger = 1; |
| 946 | entry.mask = 1; |
| 947 | } |
| 948 | |
| 949 | irq = pin_2_irq(idx, apic, pin); |
| 950 | /* |
| 951 | * skip adding the timer int on secondary nodes, which causes |
| 952 | * a small but painful rift in the time-space continuum |
| 953 | */ |
| 954 | if (multi_timer_check(apic, irq)) |
| 955 | continue; |
| 956 | else |
| 957 | add_pin_to_irq(irq, apic, pin); |
| 958 | |
| 959 | if (!apic && !IO_APIC_IRQ(irq)) |
| 960 | continue; |
| 961 | |
| 962 | if (IO_APIC_IRQ(irq)) { |
| 963 | vector = assign_irq_vector(irq); |
| 964 | entry.vector = vector; |
| 965 | ioapic_register_intr(irq, vector, IOAPIC_AUTO); |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | if (!apic && (irq < 16)) |
| 968 | disable_8259A_irq(irq); |
| 969 | } |
Akinobu Mita | a2249cb | 2008-04-05 22:39:05 +0900 | [diff] [blame] | 970 | ioapic_write_entry(apic, pin, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
| 974 | if (!first_notcon) |
| 975 | apic_printk(APIC_VERBOSE, " not connected.\n"); |
| 976 | } |
| 977 | |
| 978 | /* |
Maciej W. Rozycki | f7633ce | 2008-05-27 21:19:34 +0100 | [diff] [blame] | 979 | * Set up the timer pin, possibly with the 8259A-master behind. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | */ |
Maciej W. Rozycki | f7633ce | 2008-05-27 21:19:34 +0100 | [diff] [blame] | 981 | static void __init setup_timer_IRQ0_pin(unsigned int apic, unsigned int pin, |
| 982 | int vector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | { |
| 984 | struct IO_APIC_route_entry entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 986 | memset(&entry, 0, sizeof(entry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
| 988 | /* |
| 989 | * We use logical delivery to get the timer IRQ |
| 990 | * to the first CPU. |
| 991 | */ |
| 992 | entry.dest_mode = INT_DEST_MODE; |
Maciej W. Rozycki | 03be750 | 2008-05-27 21:19:45 +0100 | [diff] [blame] | 993 | entry.mask = 1; /* mask IRQ now */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS); |
| 995 | entry.delivery_mode = INT_DELIVERY_MODE; |
| 996 | entry.polarity = 0; |
| 997 | entry.trigger = 0; |
| 998 | entry.vector = vector; |
| 999 | |
| 1000 | /* |
| 1001 | * The timer IRQ doesn't have to know that behind the |
Maciej W. Rozycki | f7633ce | 2008-05-27 21:19:34 +0100 | [diff] [blame] | 1002 | * scene we may have a 8259A-master in AEOI mode ... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | */ |
Maciej W. Rozycki | f082526 | 2008-05-27 21:19:16 +0100 | [diff] [blame] | 1004 | ioapic_register_intr(0, vector, IOAPIC_EDGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
| 1006 | /* |
| 1007 | * Add it to the IO-APIC irq-routing table: |
| 1008 | */ |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1009 | ioapic_write_entry(apic, pin, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1012 | |
| 1013 | __apicdebuginit(void) print_IO_APIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | { |
| 1015 | int apic, i; |
| 1016 | union IO_APIC_reg_00 reg_00; |
| 1017 | union IO_APIC_reg_01 reg_01; |
| 1018 | union IO_APIC_reg_02 reg_02; |
| 1019 | union IO_APIC_reg_03 reg_03; |
| 1020 | unsigned long flags; |
| 1021 | |
| 1022 | if (apic_verbosity == APIC_QUIET) |
| 1023 | return; |
| 1024 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1025 | printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | for (i = 0; i < nr_ioapics; i++) |
| 1027 | printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1028 | mp_ioapics[i].mp_apicid, nr_ioapic_registers[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
| 1030 | /* |
| 1031 | * We are a bit conservative about what we expect. We have to |
| 1032 | * know about every hardware change ASAP. |
| 1033 | */ |
| 1034 | printk(KERN_INFO "testing the IO APIC.......................\n"); |
| 1035 | |
| 1036 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 1037 | |
| 1038 | spin_lock_irqsave(&ioapic_lock, flags); |
| 1039 | reg_00.raw = io_apic_read(apic, 0); |
| 1040 | reg_01.raw = io_apic_read(apic, 1); |
| 1041 | if (reg_01.bits.version >= 0x10) |
| 1042 | reg_02.raw = io_apic_read(apic, 2); |
| 1043 | if (reg_01.bits.version >= 0x20) |
| 1044 | reg_03.raw = io_apic_read(apic, 3); |
| 1045 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 1046 | |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1047 | printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw); |
| 1049 | printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID); |
| 1050 | printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type); |
| 1051 | printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | |
| 1053 | printk(KERN_DEBUG ".... register #01: %08X\n", reg_01.raw); |
| 1054 | printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
| 1056 | printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ); |
| 1057 | printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | |
| 1059 | /* |
| 1060 | * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02, |
| 1061 | * but the value of reg_02 is read as the previous read register |
| 1062 | * value, so ignore it if reg_02 == reg_01. |
| 1063 | */ |
| 1064 | if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) { |
| 1065 | printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw); |
| 1066 | printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /* |
| 1070 | * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02 |
| 1071 | * or reg_03, but the value of reg_0[23] is read as the previous read |
| 1072 | * register value, so ignore it if reg_03 == reg_0[12]. |
| 1073 | */ |
| 1074 | if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw && |
| 1075 | reg_03.raw != reg_01.raw) { |
| 1076 | printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw); |
| 1077 | printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | printk(KERN_DEBUG ".... IRQ redirection table:\n"); |
| 1081 | |
| 1082 | printk(KERN_DEBUG " NR Log Phy Mask Trig IRR Pol" |
| 1083 | " Stat Dest Deli Vect: \n"); |
| 1084 | |
| 1085 | for (i = 0; i <= reg_01.bits.entries; i++) { |
| 1086 | struct IO_APIC_route_entry entry; |
| 1087 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1088 | entry = ioapic_read_entry(apic, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
| 1090 | printk(KERN_DEBUG " %02x %03X %02X ", |
| 1091 | i, |
| 1092 | entry.dest.logical.logical_dest, |
| 1093 | entry.dest.physical.physical_dest |
| 1094 | ); |
| 1095 | |
| 1096 | printk("%1d %1d %1d %1d %1d %1d %1d %02X\n", |
| 1097 | entry.mask, |
| 1098 | entry.trigger, |
| 1099 | entry.irr, |
| 1100 | entry.polarity, |
| 1101 | entry.delivery_status, |
| 1102 | entry.dest_mode, |
| 1103 | entry.delivery_mode, |
| 1104 | entry.vector |
| 1105 | ); |
| 1106 | } |
| 1107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | printk(KERN_DEBUG "IRQ to pin mappings:\n"); |
Yinghai Lu | 0799e43 | 2008-08-19 20:49:48 -0700 | [diff] [blame] | 1109 | for (i = 0; i < nr_irqs; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | struct irq_pin_list *entry = irq_2_pin + i; |
| 1111 | if (entry->pin < 0) |
| 1112 | continue; |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1113 | printk(KERN_DEBUG "IRQ%d ", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | for (;;) { |
| 1115 | printk("-> %d:%d", entry->apic, entry->pin); |
| 1116 | if (!entry->next) |
| 1117 | break; |
| 1118 | entry = irq_2_pin + entry->next; |
| 1119 | } |
| 1120 | printk("\n"); |
| 1121 | } |
| 1122 | |
| 1123 | printk(KERN_INFO ".................................... done.\n"); |
| 1124 | |
| 1125 | return; |
| 1126 | } |
| 1127 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1128 | __apicdebuginit(void) print_APIC_bitfield(int base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | { |
| 1130 | unsigned int v; |
| 1131 | int i, j; |
| 1132 | |
| 1133 | if (apic_verbosity == APIC_QUIET) |
| 1134 | return; |
| 1135 | |
| 1136 | printk(KERN_DEBUG "0123456789abcdef0123456789abcdef\n" KERN_DEBUG); |
| 1137 | for (i = 0; i < 8; i++) { |
| 1138 | v = apic_read(base + i*0x10); |
| 1139 | for (j = 0; j < 32; j++) { |
| 1140 | if (v & (1<<j)) |
| 1141 | printk("1"); |
| 1142 | else |
| 1143 | printk("0"); |
| 1144 | } |
| 1145 | printk("\n"); |
| 1146 | } |
| 1147 | } |
| 1148 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1149 | __apicdebuginit(void) print_local_APIC(void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | { |
| 1151 | unsigned int v, ver, maxlvt; |
Hiroshi Shimamoto | 7ab6af7 | 2008-07-30 17:36:48 -0700 | [diff] [blame] | 1152 | u64 icr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
| 1154 | if (apic_verbosity == APIC_QUIET) |
| 1155 | return; |
| 1156 | |
| 1157 | printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n", |
| 1158 | smp_processor_id(), hard_smp_processor_id()); |
Andreas Herrmann | 6682311 | 2008-06-05 16:35:10 +0200 | [diff] [blame] | 1159 | v = apic_read(APIC_ID); |
Jack Steiner | 05f2d12 | 2008-03-28 14:12:02 -0500 | [diff] [blame] | 1160 | printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 1161 | GET_APIC_ID(v)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | v = apic_read(APIC_LVR); |
| 1163 | printk(KERN_INFO "... APIC VERSION: %08x\n", v); |
| 1164 | ver = GET_APIC_VERSION(v); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1165 | maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
| 1167 | v = apic_read(APIC_TASKPRI); |
| 1168 | printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK); |
| 1169 | |
| 1170 | if (APIC_INTEGRATED(ver)) { /* !82489DX */ |
| 1171 | v = apic_read(APIC_ARBPRI); |
| 1172 | printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v, |
| 1173 | v & APIC_ARBPRI_MASK); |
| 1174 | v = apic_read(APIC_PROCPRI); |
| 1175 | printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v); |
| 1176 | } |
| 1177 | |
| 1178 | v = apic_read(APIC_EOI); |
| 1179 | printk(KERN_DEBUG "... APIC EOI: %08x\n", v); |
| 1180 | v = apic_read(APIC_RRR); |
| 1181 | printk(KERN_DEBUG "... APIC RRR: %08x\n", v); |
| 1182 | v = apic_read(APIC_LDR); |
| 1183 | printk(KERN_DEBUG "... APIC LDR: %08x\n", v); |
| 1184 | v = apic_read(APIC_DFR); |
| 1185 | printk(KERN_DEBUG "... APIC DFR: %08x\n", v); |
| 1186 | v = apic_read(APIC_SPIV); |
| 1187 | printk(KERN_DEBUG "... APIC SPIV: %08x\n", v); |
| 1188 | |
| 1189 | printk(KERN_DEBUG "... APIC ISR field:\n"); |
| 1190 | print_APIC_bitfield(APIC_ISR); |
| 1191 | printk(KERN_DEBUG "... APIC TMR field:\n"); |
| 1192 | print_APIC_bitfield(APIC_TMR); |
| 1193 | printk(KERN_DEBUG "... APIC IRR field:\n"); |
| 1194 | print_APIC_bitfield(APIC_IRR); |
| 1195 | |
| 1196 | if (APIC_INTEGRATED(ver)) { /* !82489DX */ |
| 1197 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
| 1198 | apic_write(APIC_ESR, 0); |
| 1199 | v = apic_read(APIC_ESR); |
| 1200 | printk(KERN_DEBUG "... APIC ESR: %08x\n", v); |
| 1201 | } |
| 1202 | |
Hiroshi Shimamoto | 7ab6af7 | 2008-07-30 17:36:48 -0700 | [diff] [blame] | 1203 | icr = apic_icr_read(); |
| 1204 | printk(KERN_DEBUG "... APIC ICR: %08x\n", icr); |
| 1205 | printk(KERN_DEBUG "... APIC ICR2: %08x\n", icr >> 32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
| 1207 | v = apic_read(APIC_LVTT); |
| 1208 | printk(KERN_DEBUG "... APIC LVTT: %08x\n", v); |
| 1209 | |
| 1210 | if (maxlvt > 3) { /* PC is LVT#4. */ |
| 1211 | v = apic_read(APIC_LVTPC); |
| 1212 | printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v); |
| 1213 | } |
| 1214 | v = apic_read(APIC_LVT0); |
| 1215 | printk(KERN_DEBUG "... APIC LVT0: %08x\n", v); |
| 1216 | v = apic_read(APIC_LVT1); |
| 1217 | printk(KERN_DEBUG "... APIC LVT1: %08x\n", v); |
| 1218 | |
| 1219 | if (maxlvt > 2) { /* ERR is LVT#3. */ |
| 1220 | v = apic_read(APIC_LVTERR); |
| 1221 | printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v); |
| 1222 | } |
| 1223 | |
| 1224 | v = apic_read(APIC_TMICT); |
| 1225 | printk(KERN_DEBUG "... APIC TMICT: %08x\n", v); |
| 1226 | v = apic_read(APIC_TMCCT); |
| 1227 | printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v); |
| 1228 | v = apic_read(APIC_TDCR); |
| 1229 | printk(KERN_DEBUG "... APIC TDCR: %08x\n", v); |
| 1230 | printk("\n"); |
| 1231 | } |
| 1232 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1233 | __apicdebuginit(void) print_all_local_APICs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | { |
Jens Axboe | 15c8b6c | 2008-05-09 09:39:44 +0200 | [diff] [blame] | 1235 | on_each_cpu(print_local_APIC, NULL, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1238 | __apicdebuginit(void) print_PIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | unsigned int v; |
| 1241 | unsigned long flags; |
| 1242 | |
| 1243 | if (apic_verbosity == APIC_QUIET) |
| 1244 | return; |
| 1245 | |
| 1246 | printk(KERN_DEBUG "\nprinting PIC contents\n"); |
| 1247 | |
| 1248 | spin_lock_irqsave(&i8259A_lock, flags); |
| 1249 | |
| 1250 | v = inb(0xa1) << 8 | inb(0x21); |
| 1251 | printk(KERN_DEBUG "... PIC IMR: %04x\n", v); |
| 1252 | |
| 1253 | v = inb(0xa0) << 8 | inb(0x20); |
| 1254 | printk(KERN_DEBUG "... PIC IRR: %04x\n", v); |
| 1255 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1256 | outb(0x0b, 0xa0); |
| 1257 | outb(0x0b, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | v = inb(0xa0) << 8 | inb(0x20); |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1259 | outb(0x0a, 0xa0); |
| 1260 | outb(0x0a, 0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
| 1262 | spin_unlock_irqrestore(&i8259A_lock, flags); |
| 1263 | |
| 1264 | printk(KERN_DEBUG "... PIC ISR: %04x\n", v); |
| 1265 | |
| 1266 | v = inb(0x4d1) << 8 | inb(0x4d0); |
| 1267 | printk(KERN_DEBUG "... PIC ELCR: %04x\n", v); |
| 1268 | } |
| 1269 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1270 | __apicdebuginit(int) print_all_ICs(void) |
| 1271 | { |
| 1272 | print_PIC(); |
| 1273 | print_all_local_APICs(); |
| 1274 | print_IO_APIC(); |
| 1275 | |
| 1276 | return 0; |
| 1277 | } |
| 1278 | |
| 1279 | fs_initcall(print_all_ICs); |
| 1280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | |
| 1282 | static void __init enable_IO_APIC(void) |
| 1283 | { |
| 1284 | union IO_APIC_reg_01 reg_01; |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1285 | int i8259_apic, i8259_pin; |
| 1286 | int i, apic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | unsigned long flags; |
| 1288 | |
Yinghai Lu | 0799e43 | 2008-08-19 20:49:48 -0700 | [diff] [blame] | 1289 | for (i = 0; i < pin_map_size; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | irq_2_pin[i].pin = -1; |
| 1291 | irq_2_pin[i].next = 0; |
| 1292 | } |
| 1293 | if (!pirqs_enabled) |
| 1294 | for (i = 0; i < MAX_PIRQS; i++) |
| 1295 | pirq_entries[i] = -1; |
| 1296 | |
| 1297 | /* |
| 1298 | * The number of IO-APIC IRQ registers (== #pins): |
| 1299 | */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1300 | for (apic = 0; apic < nr_ioapics; apic++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | spin_lock_irqsave(&ioapic_lock, flags); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1302 | reg_01.raw = io_apic_read(apic, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1304 | nr_ioapic_registers[apic] = reg_01.bits.entries+1; |
| 1305 | } |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1306 | for (apic = 0; apic < nr_ioapics; apic++) { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1307 | int pin; |
| 1308 | /* See if any of the pins is in ExtINT mode */ |
Eric W. Biederman | 1008fdd | 2006-01-11 22:46:06 +0100 | [diff] [blame] | 1309 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1310 | struct IO_APIC_route_entry entry; |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1311 | entry = ioapic_read_entry(apic, pin); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1312 | |
| 1313 | |
| 1314 | /* If the interrupt line is enabled and in ExtInt mode |
| 1315 | * I have found the pin where the i8259 is connected. |
| 1316 | */ |
| 1317 | if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) { |
| 1318 | ioapic_i8259.apic = apic; |
| 1319 | ioapic_i8259.pin = pin; |
| 1320 | goto found_i8259; |
| 1321 | } |
| 1322 | } |
| 1323 | } |
| 1324 | found_i8259: |
| 1325 | /* Look to see what if the MP table has reported the ExtINT */ |
| 1326 | /* If we could not find the appropriate pin by looking at the ioapic |
| 1327 | * the i8259 probably is not connected the ioapic but give the |
| 1328 | * mptable a chance anyway. |
| 1329 | */ |
| 1330 | i8259_pin = find_isa_irq_pin(0, mp_ExtINT); |
| 1331 | i8259_apic = find_isa_irq_apic(0, mp_ExtINT); |
| 1332 | /* Trust the MP table if nothing is setup in the hardware */ |
| 1333 | if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) { |
| 1334 | printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n"); |
| 1335 | ioapic_i8259.pin = i8259_pin; |
| 1336 | ioapic_i8259.apic = i8259_apic; |
| 1337 | } |
| 1338 | /* Complain if the MP table and the hardware disagree */ |
| 1339 | if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) && |
| 1340 | (i8259_pin >= 0) && (ioapic_i8259.pin >= 0)) |
| 1341 | { |
| 1342 | printk(KERN_WARNING "ExtINT in hardware and MP table differ\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | /* |
| 1346 | * Do not trust the IO-APIC being empty at bootup |
| 1347 | */ |
| 1348 | clear_IO_APIC(); |
| 1349 | } |
| 1350 | |
| 1351 | /* |
| 1352 | * Not an __init, needed by the reboot code |
| 1353 | */ |
| 1354 | void disable_IO_APIC(void) |
| 1355 | { |
| 1356 | /* |
| 1357 | * Clear the IO-APIC before rebooting: |
| 1358 | */ |
| 1359 | clear_IO_APIC(); |
| 1360 | |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1361 | /* |
Karsten Wiese | 0b968d2 | 2005-09-09 12:59:04 +0200 | [diff] [blame] | 1362 | * If the i8259 is routed through an IOAPIC |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1363 | * Put that IOAPIC in virtual wire mode |
Karsten Wiese | 0b968d2 | 2005-09-09 12:59:04 +0200 | [diff] [blame] | 1364 | * so legacy interrupts can be delivered. |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1365 | */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1366 | if (ioapic_i8259.pin != -1) { |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1367 | struct IO_APIC_route_entry entry; |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1368 | |
| 1369 | memset(&entry, 0, sizeof(entry)); |
| 1370 | entry.mask = 0; /* Enabled */ |
| 1371 | entry.trigger = 0; /* Edge */ |
| 1372 | entry.irr = 0; |
| 1373 | entry.polarity = 0; /* High */ |
| 1374 | entry.delivery_status = 0; |
| 1375 | entry.dest_mode = 0; /* Physical */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1376 | entry.delivery_mode = dest_ExtINT; /* ExtInt */ |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1377 | entry.vector = 0; |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 1378 | entry.dest.physical.physical_dest = read_apic_id(); |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1379 | |
| 1380 | /* |
| 1381 | * Add it to the IO-APIC irq-routing table: |
| 1382 | */ |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1383 | ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry); |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1384 | } |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1385 | disconnect_bsp_APIC(ioapic_i8259.pin != -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | /* |
| 1389 | * function to set the IO-APIC physical IDs based on the |
| 1390 | * values stored in the MPC table. |
| 1391 | * |
| 1392 | * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999 |
| 1393 | */ |
| 1394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | static void __init setup_ioapic_ids_from_mpc(void) |
| 1396 | { |
| 1397 | union IO_APIC_reg_00 reg_00; |
| 1398 | physid_mask_t phys_id_present_map; |
| 1399 | int apic; |
| 1400 | int i; |
| 1401 | unsigned char old_id; |
| 1402 | unsigned long flags; |
| 1403 | |
Yinghai Lu | a4dbc34 | 2008-07-25 02:14:28 -0700 | [diff] [blame] | 1404 | if (x86_quirks->setup_ioapic_ids && x86_quirks->setup_ioapic_ids()) |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 1405 | return; |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 1406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | /* |
Natalie Protasevich | ca05fea | 2005-06-23 00:08:22 -0700 | [diff] [blame] | 1408 | * Don't check I/O APIC IDs for xAPIC systems. They have |
| 1409 | * no meaning without the serial APIC bus. |
| 1410 | */ |
Shaohua Li | 7c5c1e4 | 2006-03-23 02:59:53 -0800 | [diff] [blame] | 1411 | if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) |
| 1412 | || APIC_XAPIC(apic_version[boot_cpu_physical_apicid])) |
Natalie Protasevich | ca05fea | 2005-06-23 00:08:22 -0700 | [diff] [blame] | 1413 | return; |
| 1414 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | * This is broken; anything with a real cpu count has to |
| 1416 | * circumvent this idiocy regardless. |
| 1417 | */ |
| 1418 | phys_id_present_map = ioapic_phys_id_map(phys_cpu_present_map); |
| 1419 | |
| 1420 | /* |
| 1421 | * Set the IOAPIC ID to the value stored in the MPC table. |
| 1422 | */ |
| 1423 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 1424 | |
| 1425 | /* Read the register 0 value */ |
| 1426 | spin_lock_irqsave(&ioapic_lock, flags); |
| 1427 | reg_00.raw = io_apic_read(apic, 0); |
| 1428 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1429 | |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1430 | old_id = mp_ioapics[apic].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1432 | if (mp_ioapics[apic].mp_apicid >= get_physical_broadcast()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1434 | apic, mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n", |
| 1436 | reg_00.bits.ID); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1437 | mp_ioapics[apic].mp_apicid = reg_00.bits.ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | } |
| 1439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | /* |
| 1441 | * Sanity check, is the ID really free? Every APIC in a |
| 1442 | * system must have a unique ID or we get lots of nice |
| 1443 | * 'stuck on smp_invalidate_needed IPI wait' messages. |
| 1444 | */ |
| 1445 | if (check_apicid_used(phys_id_present_map, |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1446 | mp_ioapics[apic].mp_apicid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1448 | apic, mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | for (i = 0; i < get_physical_broadcast(); i++) |
| 1450 | if (!physid_isset(i, phys_id_present_map)) |
| 1451 | break; |
| 1452 | if (i >= get_physical_broadcast()) |
| 1453 | panic("Max APIC ID exceeded!\n"); |
| 1454 | printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n", |
| 1455 | i); |
| 1456 | physid_set(i, phys_id_present_map); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1457 | mp_ioapics[apic].mp_apicid = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | } else { |
| 1459 | physid_mask_t tmp; |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1460 | tmp = apicid_to_cpu_present(mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | apic_printk(APIC_VERBOSE, "Setting %d in the " |
| 1462 | "phys_id_present_map\n", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1463 | mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | physids_or(phys_id_present_map, phys_id_present_map, tmp); |
| 1465 | } |
| 1466 | |
| 1467 | |
| 1468 | /* |
| 1469 | * We need to adjust the IRQ routing table |
| 1470 | * if the ID changed. |
| 1471 | */ |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1472 | if (old_id != mp_ioapics[apic].mp_apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | for (i = 0; i < mp_irq_entries; i++) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 1474 | if (mp_irqs[i].mp_dstapic == old_id) |
| 1475 | mp_irqs[i].mp_dstapic |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1476 | = mp_ioapics[apic].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
| 1478 | /* |
| 1479 | * Read the right value from the MPC table and |
| 1480 | * write it into the ID register. |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1481 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 1483 | "...changing IO-APIC physical APIC ID to %d ...", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1484 | mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1486 | reg_00.bits.ID = mp_ioapics[apic].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | spin_lock_irqsave(&ioapic_lock, flags); |
| 1488 | io_apic_write(apic, 0, reg_00.raw); |
| 1489 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 1490 | |
| 1491 | /* |
| 1492 | * Sanity check |
| 1493 | */ |
| 1494 | spin_lock_irqsave(&ioapic_lock, flags); |
| 1495 | reg_00.raw = io_apic_read(apic, 0); |
| 1496 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1497 | if (reg_00.bits.ID != mp_ioapics[apic].mp_apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | printk("could not set ID!\n"); |
| 1499 | else |
| 1500 | apic_printk(APIC_VERBOSE, " ok.\n"); |
| 1501 | } |
| 1502 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1504 | int no_timer_check __initdata; |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 1505 | |
| 1506 | static int __init notimercheck(char *s) |
| 1507 | { |
| 1508 | no_timer_check = 1; |
| 1509 | return 1; |
| 1510 | } |
| 1511 | __setup("no_timer_check", notimercheck); |
| 1512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | /* |
| 1514 | * There is a nasty bug in some older SMP boards, their mptable lies |
| 1515 | * about the timer IRQ. We do the following to work around the situation: |
| 1516 | * |
| 1517 | * - timer IRQ defaults to IO-APIC IRQ |
| 1518 | * - if this function detects that timer IRQs are defunct, then we fall |
| 1519 | * back to ISA timer IRQs |
| 1520 | */ |
Adrian Bunk | f0a7a5c | 2007-07-21 17:10:29 +0200 | [diff] [blame] | 1521 | static int __init timer_irq_works(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | { |
| 1523 | unsigned long t1 = jiffies; |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1524 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 1526 | if (no_timer_check) |
| 1527 | return 1; |
| 1528 | |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1529 | local_save_flags(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | local_irq_enable(); |
| 1531 | /* Let ten ticks pass... */ |
| 1532 | mdelay((10 * 1000) / HZ); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1533 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
| 1535 | /* |
| 1536 | * Expect a few ticks at least, to be sure some possible |
| 1537 | * glue logic does not lock up after one or two first |
| 1538 | * ticks in a non-ExtINT mode. Also the local APIC |
| 1539 | * might have cached one ExtINT interrupt. Finally, at |
| 1540 | * least one tick may be lost due to delays. |
| 1541 | */ |
Julia Lawall | 1d16b53 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 1542 | if (time_after(jiffies, t1 + 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | return 1; |
| 1544 | |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | /* |
| 1549 | * In the SMP+IOAPIC case it might happen that there are an unspecified |
| 1550 | * number of pending IRQ events unhandled. These cases are very rare, |
| 1551 | * so we 'resend' these IRQs via IPIs, to the same CPU. It's much |
| 1552 | * better to do it this way as thus we do not have to be aware of |
| 1553 | * 'pending' interrupts in the IRQ path, except at this point. |
| 1554 | */ |
| 1555 | /* |
| 1556 | * Edge triggered needs to resend any interrupt |
| 1557 | * that was delayed but this is now handled in the device |
| 1558 | * independent code. |
| 1559 | */ |
| 1560 | |
| 1561 | /* |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1562 | * Startup quirk: |
| 1563 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | * Starting up a edge-triggered IO-APIC interrupt is |
| 1565 | * nasty - we need to make sure that we get the edge. |
| 1566 | * If it is already asserted for some reason, we need |
| 1567 | * return 1 to indicate that is was pending. |
| 1568 | * |
| 1569 | * This is not complete - we should be able to fake |
| 1570 | * an edge even if it isn't on the 8259A... |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1571 | * |
| 1572 | * (We do this for level-triggered IRQs too - it cannot hurt.) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | */ |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1574 | static unsigned int startup_ioapic_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | { |
| 1576 | int was_pending = 0; |
| 1577 | unsigned long flags; |
| 1578 | |
| 1579 | spin_lock_irqsave(&ioapic_lock, flags); |
| 1580 | if (irq < 16) { |
| 1581 | disable_8259A_irq(irq); |
| 1582 | if (i8259A_irq_pending(irq)) |
| 1583 | was_pending = 1; |
| 1584 | } |
| 1585 | __unmask_IO_APIC_irq(irq); |
| 1586 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 1587 | |
| 1588 | return was_pending; |
| 1589 | } |
| 1590 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1591 | static void ack_ioapic_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | { |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1593 | move_native_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | ack_APIC_irq(); |
| 1595 | } |
| 1596 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1597 | static void ack_ioapic_quirk_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | { |
| 1599 | unsigned long v; |
| 1600 | int i; |
| 1601 | |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1602 | move_native_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | /* |
| 1604 | * It appears there is an erratum which affects at least version 0x11 |
| 1605 | * of I/O APIC (that's the 82093AA and cores integrated into various |
| 1606 | * chipsets). Under certain conditions a level-triggered interrupt is |
| 1607 | * erroneously delivered as edge-triggered one but the respective IRR |
| 1608 | * bit gets set nevertheless. As a result the I/O unit expects an EOI |
| 1609 | * message but it will never arrive and further interrupts are blocked |
| 1610 | * from the source. The exact reason is so far unknown, but the |
| 1611 | * phenomenon was observed when two consecutive interrupt requests |
| 1612 | * from a given source get delivered to the same CPU and the source is |
| 1613 | * temporarily disabled in between. |
| 1614 | * |
| 1615 | * A workaround is to simulate an EOI message manually. We achieve it |
| 1616 | * by setting the trigger mode to edge and then to level when the edge |
| 1617 | * trigger mode gets detected in the TMR of a local APIC for a |
| 1618 | * level-triggered interrupt. We mask the source for the time of the |
| 1619 | * operation to prevent an edge-triggered interrupt escaping meanwhile. |
| 1620 | * The idea is from Manfred Spraul. --macro |
| 1621 | */ |
Yinghai Lu | a1420f3 | 2008-08-19 20:50:24 -0700 | [diff] [blame^] | 1622 | i = irq_cfg(irq)->vector; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | |
| 1624 | v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1)); |
| 1625 | |
| 1626 | ack_APIC_irq(); |
| 1627 | |
| 1628 | if (!(v & (1 << (i & 0x1f)))) { |
| 1629 | atomic_inc(&irq_mis_count); |
| 1630 | spin_lock(&ioapic_lock); |
| 1631 | __mask_and_edge_IO_APIC_irq(irq); |
| 1632 | __unmask_and_level_IO_APIC_irq(irq); |
| 1633 | spin_unlock(&ioapic_lock); |
| 1634 | } |
| 1635 | } |
| 1636 | |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1637 | static int ioapic_retrigger_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | { |
Yinghai Lu | a1420f3 | 2008-08-19 20:50:24 -0700 | [diff] [blame^] | 1639 | send_IPI_self(irq_cfg(irq)->vector); |
Ingo Molnar | c0ad90a | 2006-06-29 02:24:44 -0700 | [diff] [blame] | 1640 | |
| 1641 | return 1; |
| 1642 | } |
| 1643 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1644 | static struct irq_chip ioapic_chip __read_mostly = { |
| 1645 | .name = "IO-APIC", |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1646 | .startup = startup_ioapic_irq, |
| 1647 | .mask = mask_IO_APIC_irq, |
| 1648 | .unmask = unmask_IO_APIC_irq, |
| 1649 | .ack = ack_ioapic_irq, |
| 1650 | .eoi = ack_ioapic_quirk_irq, |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 1651 | #ifdef CONFIG_SMP |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1652 | .set_affinity = set_ioapic_affinity_irq, |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 1653 | #endif |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1654 | .retrigger = ioapic_retrigger_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | }; |
| 1656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
| 1658 | static inline void init_IO_APIC_traps(void) |
| 1659 | { |
| 1660 | int irq; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 1661 | struct irq_desc *desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | |
| 1663 | /* |
| 1664 | * NOTE! The local APIC isn't very good at handling |
| 1665 | * multiple interrupts at the same interrupt level. |
| 1666 | * As the interrupt level is determined by taking the |
| 1667 | * vector number and shifting that right by 4, we |
| 1668 | * want to spread these out a bit so that they don't |
| 1669 | * all fall in the same interrupt level. |
| 1670 | * |
| 1671 | * Also, we've got to be careful not to trash gate |
| 1672 | * 0x80, because int 0x80 is hm, kind of importantish. ;) |
| 1673 | */ |
Yinghai Lu | 0799e43 | 2008-08-19 20:49:48 -0700 | [diff] [blame] | 1674 | for (irq = 0; irq < nr_irqs ; irq++) { |
Yinghai Lu | a1420f3 | 2008-08-19 20:50:24 -0700 | [diff] [blame^] | 1675 | if (IO_APIC_IRQ(irq) && !irq_cfg(irq)->vector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | /* |
| 1677 | * Hmm.. We don't have an entry for this, |
| 1678 | * so default to an old-fashioned 8259 |
| 1679 | * interrupt if we can.. |
| 1680 | */ |
| 1681 | if (irq < 16) |
| 1682 | make_8259A_irq(irq); |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 1683 | else { |
| 1684 | desc = irq_to_desc(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | /* Strange. Oh, well.. */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 1686 | desc->chip = &no_irq_chip; |
| 1687 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1692 | /* |
| 1693 | * The local APIC irq-chip implementation: |
| 1694 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1695 | |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 1696 | static void ack_lapic_irq(unsigned int irq) |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1697 | { |
| 1698 | ack_APIC_irq(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | } |
| 1700 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1701 | static void mask_lapic_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | { |
| 1703 | unsigned long v; |
| 1704 | |
| 1705 | v = apic_read(APIC_LVT0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1706 | apic_write(APIC_LVT0, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | } |
| 1708 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1709 | static void unmask_lapic_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | { |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1711 | unsigned long v; |
| 1712 | |
| 1713 | v = apic_read(APIC_LVT0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1714 | apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1717 | static struct irq_chip lapic_chip __read_mostly = { |
Maciej W. Rozycki | 9a1c619 | 2008-05-27 21:19:09 +0100 | [diff] [blame] | 1718 | .name = "local-APIC", |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1719 | .mask = mask_lapic_irq, |
| 1720 | .unmask = unmask_lapic_irq, |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 1721 | .ack = ack_lapic_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | }; |
| 1723 | |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 1724 | static void lapic_register_intr(int irq, int vector) |
| 1725 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 1726 | struct irq_desc *desc; |
| 1727 | |
| 1728 | desc = irq_to_desc(irq); |
| 1729 | desc->status &= ~IRQ_LEVEL; |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 1730 | set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq, |
| 1731 | "edge"); |
| 1732 | set_intr_gate(vector, interrupt[irq]); |
| 1733 | } |
| 1734 | |
Jan Beulich | e942710 | 2008-01-30 13:31:24 +0100 | [diff] [blame] | 1735 | static void __init setup_nmi(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | { |
| 1737 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1738 | * Dirty trick to enable the NMI watchdog ... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | * We put the 8259A master into AEOI mode and |
| 1740 | * unmask on all local APICs LVT0 as NMI. |
| 1741 | * |
| 1742 | * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire') |
| 1743 | * is from Maciej W. Rozycki - so we do not have to EOI from |
| 1744 | * the NMI handler or the timer interrupt. |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1745 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ..."); |
| 1747 | |
Jan Beulich | e942710 | 2008-01-30 13:31:24 +0100 | [diff] [blame] | 1748 | enable_NMI_through_LVT0(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
| 1750 | apic_printk(APIC_VERBOSE, " done.\n"); |
| 1751 | } |
| 1752 | |
| 1753 | /* |
| 1754 | * This looks a bit hackish but it's about the only one way of sending |
| 1755 | * a few INTA cycles to 8259As and any associated glue logic. ICR does |
| 1756 | * not support the ExtINT mode, unfortunately. We need to send these |
| 1757 | * cycles as some i82489DX-based boards have glue logic that keeps the |
| 1758 | * 8259A interrupt line asserted until INTA. --macro |
| 1759 | */ |
Jacek Luczak | 28acf28 | 2008-04-12 17:41:12 +0200 | [diff] [blame] | 1760 | static inline void __init unlock_ExtINT_logic(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1762 | int apic, pin, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | struct IO_APIC_route_entry entry0, entry1; |
| 1764 | unsigned char save_control, save_freq_select; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1766 | pin = find_isa_irq_pin(8, mp_INT); |
Adrian Bunk | 956fb53 | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 1767 | if (pin == -1) { |
| 1768 | WARN_ON_ONCE(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | return; |
Adrian Bunk | 956fb53 | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 1770 | } |
| 1771 | apic = find_isa_irq_apic(8, mp_INT); |
| 1772 | if (apic == -1) { |
| 1773 | WARN_ON_ONCE(1); |
| 1774 | return; |
| 1775 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1777 | entry0 = ioapic_read_entry(apic, pin); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1778 | clear_IO_APIC_pin(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | |
| 1780 | memset(&entry1, 0, sizeof(entry1)); |
| 1781 | |
| 1782 | entry1.dest_mode = 0; /* physical delivery */ |
| 1783 | entry1.mask = 0; /* unmask IRQ now */ |
| 1784 | entry1.dest.physical.physical_dest = hard_smp_processor_id(); |
| 1785 | entry1.delivery_mode = dest_ExtINT; |
| 1786 | entry1.polarity = entry0.polarity; |
| 1787 | entry1.trigger = 0; |
| 1788 | entry1.vector = 0; |
| 1789 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1790 | ioapic_write_entry(apic, pin, entry1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | |
| 1792 | save_control = CMOS_READ(RTC_CONTROL); |
| 1793 | save_freq_select = CMOS_READ(RTC_FREQ_SELECT); |
| 1794 | CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6, |
| 1795 | RTC_FREQ_SELECT); |
| 1796 | CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL); |
| 1797 | |
| 1798 | i = 100; |
| 1799 | while (i-- > 0) { |
| 1800 | mdelay(10); |
| 1801 | if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF) |
| 1802 | i -= 10; |
| 1803 | } |
| 1804 | |
| 1805 | CMOS_WRITE(save_control, RTC_CONTROL); |
| 1806 | CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1807 | clear_IO_APIC_pin(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1809 | ioapic_write_entry(apic, pin, entry0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | /* |
| 1813 | * This code may look a bit paranoid, but it's supposed to cooperate with |
| 1814 | * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ |
| 1815 | * is so screwy. Thanks to Brian Perkins for testing/hacking this beast |
| 1816 | * fanatically on his truly buggy board. |
| 1817 | */ |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 1818 | static inline void __init check_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1820 | int apic1, pin1, apic2, pin2; |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 1821 | int no_pin1 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | int vector; |
Ingo Molnar | 6e90894 | 2008-03-21 14:32:36 +0100 | [diff] [blame] | 1823 | unsigned int ver; |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1824 | unsigned long flags; |
| 1825 | |
| 1826 | local_irq_save(flags); |
Maciej W. Rozycki | d4d25de | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 1827 | |
Ingo Molnar | 6e90894 | 2008-03-21 14:32:36 +0100 | [diff] [blame] | 1828 | ver = apic_read(APIC_LVR); |
| 1829 | ver = GET_APIC_VERSION(ver); |
| 1830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | /* |
| 1832 | * get/set the timer IRQ vector: |
| 1833 | */ |
| 1834 | disable_8259A_irq(0); |
| 1835 | vector = assign_irq_vector(0); |
| 1836 | set_intr_gate(vector, interrupt[0]); |
| 1837 | |
| 1838 | /* |
Maciej W. Rozycki | d11d579 | 2008-05-21 22:09:11 +0100 | [diff] [blame] | 1839 | * As IRQ0 is to be enabled in the 8259A, the virtual |
| 1840 | * wire has to be disabled in the local APIC. Also |
| 1841 | * timer interrupts need to be acknowledged manually in |
| 1842 | * the 8259A for the i82489DX when using the NMI |
| 1843 | * watchdog as that APIC treats NMIs as level-triggered. |
| 1844 | * The AEOI mode will finish them in the 8259A |
| 1845 | * automatically. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1847 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | init_8259A(1); |
Maciej W. Rozycki | d11d579 | 2008-05-21 22:09:11 +0100 | [diff] [blame] | 1849 | timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1851 | pin1 = find_isa_irq_pin(0, mp_INT); |
| 1852 | apic1 = find_isa_irq_apic(0, mp_INT); |
| 1853 | pin2 = ioapic_i8259.pin; |
| 1854 | apic2 = ioapic_i8259.apic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1856 | apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X " |
| 1857 | "apic1=%d pin1=%d apic2=%d pin2=%d\n", |
| 1858 | vector, apic1, pin1, apic2, pin2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 1860 | /* |
| 1861 | * Some BIOS writers are clueless and report the ExtINTA |
| 1862 | * I/O APIC input from the cascaded 8259A as the timer |
| 1863 | * interrupt input. So just in case, if only one pin |
| 1864 | * was found above, try it both directly and through the |
| 1865 | * 8259A. |
| 1866 | */ |
| 1867 | if (pin1 == -1) { |
| 1868 | pin1 = pin2; |
| 1869 | apic1 = apic2; |
| 1870 | no_pin1 = 1; |
| 1871 | } else if (pin2 == -1) { |
| 1872 | pin2 = pin1; |
| 1873 | apic2 = apic1; |
| 1874 | } |
| 1875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | if (pin1 != -1) { |
| 1877 | /* |
| 1878 | * Ok, does IRQ0 through the IOAPIC work? |
| 1879 | */ |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 1880 | if (no_pin1) { |
| 1881 | add_pin_to_irq(0, apic1, pin1); |
| 1882 | setup_timer_IRQ0_pin(apic1, pin1, vector); |
| 1883 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1884 | unmask_IO_APIC_irq(0); |
| 1885 | if (timer_irq_works()) { |
| 1886 | if (nmi_watchdog == NMI_IO_APIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | setup_nmi(); |
| 1888 | enable_8259A_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } |
Chuck Ebbert | 66759a0 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 1890 | if (disable_timer_pin_1 > 0) |
| 1891 | clear_IO_APIC_pin(0, pin1); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1892 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | } |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1894 | clear_IO_APIC_pin(apic1, pin1); |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 1895 | if (!no_pin1) |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1896 | apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: " |
| 1897 | "8254 timer not connected to IO-APIC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1899 | apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer " |
| 1900 | "(IRQ0) through the 8259A ...\n"); |
| 1901 | apic_printk(APIC_QUIET, KERN_INFO |
| 1902 | "..... (found apic %d pin %d) ...\n", apic2, pin2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | /* |
| 1904 | * legacy devices should be connected to IO APIC #0 |
| 1905 | */ |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 1906 | replace_pin_at_irq(0, apic1, pin1, apic2, pin2); |
Maciej W. Rozycki | f7633ce | 2008-05-27 21:19:34 +0100 | [diff] [blame] | 1907 | setup_timer_IRQ0_pin(apic2, pin2, vector); |
Maciej W. Rozycki | 24742ec | 2008-05-27 21:19:40 +0100 | [diff] [blame] | 1908 | unmask_IO_APIC_irq(0); |
Maciej W. Rozycki | ecd2947 | 2008-05-21 22:09:19 +0100 | [diff] [blame] | 1909 | enable_8259A_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1911 | apic_printk(APIC_QUIET, KERN_INFO "....... works.\n"); |
Maciej W. Rozycki | 35542c5 | 2008-05-21 22:10:22 +0100 | [diff] [blame] | 1912 | timer_through_8259 = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | if (nmi_watchdog == NMI_IO_APIC) { |
Maciej W. Rozycki | 60134eb | 2008-05-21 22:09:34 +0100 | [diff] [blame] | 1914 | disable_8259A_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | setup_nmi(); |
Maciej W. Rozycki | 60134eb | 2008-05-21 22:09:34 +0100 | [diff] [blame] | 1916 | enable_8259A_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1918 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | } |
| 1920 | /* |
| 1921 | * Cleanup, just in case ... |
| 1922 | */ |
Maciej W. Rozycki | ecd2947 | 2008-05-21 22:09:19 +0100 | [diff] [blame] | 1923 | disable_8259A_irq(0); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1924 | clear_IO_APIC_pin(apic2, pin2); |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1925 | apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | |
| 1928 | if (nmi_watchdog == NMI_IO_APIC) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1929 | apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work " |
| 1930 | "through the IO-APIC - disabling NMI Watchdog!\n"); |
Cyrill Gorcunov | 067fa0f | 2008-05-29 22:32:30 +0400 | [diff] [blame] | 1931 | nmi_watchdog = NMI_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | } |
Maciej W. Rozycki | d11d579 | 2008-05-21 22:09:11 +0100 | [diff] [blame] | 1933 | timer_ack = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1935 | apic_printk(APIC_QUIET, KERN_INFO |
| 1936 | "...trying to set up timer as Virtual Wire IRQ...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 1938 | lapic_register_intr(0, vector); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1939 | apic_write(APIC_LVT0, APIC_DM_FIXED | vector); /* Fixed mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | enable_8259A_irq(0); |
| 1941 | |
| 1942 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1943 | apic_printk(APIC_QUIET, KERN_INFO "..... works.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1944 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | } |
Maciej W. Rozycki | e67465f | 2008-05-21 22:09:26 +0100 | [diff] [blame] | 1946 | disable_8259A_irq(0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1947 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector); |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1948 | apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1950 | apic_printk(APIC_QUIET, KERN_INFO |
| 1951 | "...trying to set up timer as ExtINT IRQ...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | init_8259A(0); |
| 1954 | make_8259A_irq(0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1955 | apic_write(APIC_LVT0, APIC_DM_EXTINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | |
| 1957 | unlock_ExtINT_logic(); |
| 1958 | |
| 1959 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1960 | apic_printk(APIC_QUIET, KERN_INFO "..... works.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1961 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | } |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1963 | apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a " |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 1965 | "report. Then try booting with the 'noapic' option.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1966 | out: |
| 1967 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | /* |
Maciej W. Rozycki | af17478 | 2008-07-11 19:35:23 +0100 | [diff] [blame] | 1971 | * Traditionally ISA IRQ2 is the cascade IRQ, and is not available |
| 1972 | * to devices. However there may be an I/O APIC pin available for |
| 1973 | * this interrupt regardless. The pin may be left unconnected, but |
| 1974 | * typically it will be reused as an ExtINT cascade interrupt for |
| 1975 | * the master 8259A. In the MPS case such a pin will normally be |
| 1976 | * reported as an ExtINT interrupt in the MP table. With ACPI |
| 1977 | * there is no provision for ExtINT interrupts, and in the absence |
| 1978 | * of an override it would be treated as an ordinary ISA I/O APIC |
| 1979 | * interrupt, that is edge-triggered and unmasked by default. We |
| 1980 | * used to do this, but it caused problems on some systems because |
| 1981 | * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using |
| 1982 | * the same ExtINT cascade interrupt to drive the local APIC of the |
| 1983 | * bootstrap processor. Therefore we refrain from routing IRQ2 to |
| 1984 | * the I/O APIC in all cases now. No actual device should request |
| 1985 | * it anyway. --macro |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | */ |
| 1987 | #define PIC_IRQS (1 << PIC_CASCADE_IR) |
| 1988 | |
| 1989 | void __init setup_IO_APIC(void) |
| 1990 | { |
Rusty Russell | dbeb2be | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 1991 | int i; |
| 1992 | |
| 1993 | /* Reserve all the system vectors. */ |
Alan Mayer | 305b92a | 2008-04-15 15:36:56 -0500 | [diff] [blame] | 1994 | for (i = first_system_vector; i < NR_VECTORS; i++) |
Rusty Russell | dbeb2be | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 1995 | set_bit(i, used_vectors); |
| 1996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | enable_IO_APIC(); |
| 1998 | |
Maciej W. Rozycki | af17478 | 2008-07-11 19:35:23 +0100 | [diff] [blame] | 1999 | io_apic_irqs = ~PIC_IRQS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | |
| 2001 | printk("ENABLING IO-APIC IRQs\n"); |
| 2002 | |
| 2003 | /* |
| 2004 | * Set up IO-APIC IRQ routing. |
| 2005 | */ |
| 2006 | if (!acpi_ioapic) |
| 2007 | setup_ioapic_ids_from_mpc(); |
| 2008 | sync_Arb_IDs(); |
| 2009 | setup_IO_APIC_irqs(); |
| 2010 | init_IO_APIC_traps(); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 2011 | check_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | /* |
| 2015 | * Called after all the initialization is done. If we didnt find any |
| 2016 | * APIC bugs then we can allow the modify fast path |
| 2017 | */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | static int __init io_apic_bug_finalize(void) |
| 2020 | { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2021 | if (sis_apic_bug == -1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | sis_apic_bug = 0; |
| 2023 | return 0; |
| 2024 | } |
| 2025 | |
| 2026 | late_initcall(io_apic_bug_finalize); |
| 2027 | |
| 2028 | struct sysfs_ioapic_data { |
| 2029 | struct sys_device dev; |
| 2030 | struct IO_APIC_route_entry entry[0]; |
| 2031 | }; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2032 | static struct sysfs_ioapic_data *mp_ioapic_data[MAX_IO_APICS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | |
Pavel Machek | 438510f | 2005-04-16 15:25:24 -0700 | [diff] [blame] | 2034 | static int ioapic_suspend(struct sys_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | { |
| 2036 | struct IO_APIC_route_entry *entry; |
| 2037 | struct sysfs_ioapic_data *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | int i; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2039 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | data = container_of(dev, struct sysfs_ioapic_data, dev); |
| 2041 | entry = data->entry; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2042 | for (i = 0; i < nr_ioapic_registers[dev->id]; i++) |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 2043 | entry[i] = ioapic_read_entry(dev->id, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | |
| 2045 | return 0; |
| 2046 | } |
| 2047 | |
| 2048 | static int ioapic_resume(struct sys_device *dev) |
| 2049 | { |
| 2050 | struct IO_APIC_route_entry *entry; |
| 2051 | struct sysfs_ioapic_data *data; |
| 2052 | unsigned long flags; |
| 2053 | union IO_APIC_reg_00 reg_00; |
| 2054 | int i; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | data = container_of(dev, struct sysfs_ioapic_data, dev); |
| 2057 | entry = data->entry; |
| 2058 | |
| 2059 | spin_lock_irqsave(&ioapic_lock, flags); |
| 2060 | reg_00.raw = io_apic_read(dev->id, 0); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 2061 | if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) { |
| 2062 | reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | io_apic_write(dev->id, 0, reg_00.raw); |
| 2064 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2066 | for (i = 0; i < nr_ioapic_registers[dev->id]; i++) |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 2067 | ioapic_write_entry(dev->id, i, entry[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | |
| 2069 | return 0; |
| 2070 | } |
| 2071 | |
| 2072 | static struct sysdev_class ioapic_sysdev_class = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 2073 | .name = "ioapic", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | .suspend = ioapic_suspend, |
| 2075 | .resume = ioapic_resume, |
| 2076 | }; |
| 2077 | |
| 2078 | static int __init ioapic_init_sysfs(void) |
| 2079 | { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2080 | struct sys_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | int i, size, error = 0; |
| 2082 | |
| 2083 | error = sysdev_class_register(&ioapic_sysdev_class); |
| 2084 | if (error) |
| 2085 | return error; |
| 2086 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2087 | for (i = 0; i < nr_ioapics; i++) { |
| 2088 | size = sizeof(struct sys_device) + nr_ioapic_registers[i] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | * sizeof(struct IO_APIC_route_entry); |
Christophe Jaillet | 25556c1 | 2008-06-22 22:13:48 +0200 | [diff] [blame] | 2090 | mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | if (!mp_ioapic_data[i]) { |
| 2092 | printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i); |
| 2093 | continue; |
| 2094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | dev = &mp_ioapic_data[i]->dev; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2096 | dev->id = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | dev->cls = &ioapic_sysdev_class; |
| 2098 | error = sysdev_register(dev); |
| 2099 | if (error) { |
| 2100 | kfree(mp_ioapic_data[i]); |
| 2101 | mp_ioapic_data[i] = NULL; |
| 2102 | printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i); |
| 2103 | continue; |
| 2104 | } |
| 2105 | } |
| 2106 | |
| 2107 | return 0; |
| 2108 | } |
| 2109 | |
| 2110 | device_initcall(ioapic_init_sysfs); |
| 2111 | |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2112 | /* |
Eric W. Biederman | 95d7788 | 2006-10-04 02:17:01 -0700 | [diff] [blame] | 2113 | * Dynamic irq allocate and deallocation |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2114 | */ |
| 2115 | int create_irq(void) |
| 2116 | { |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2117 | /* Allocate an unused irq */ |
Andi Kleen | 306a22c | 2006-12-09 21:33:36 +0100 | [diff] [blame] | 2118 | int irq, new, vector = 0; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2119 | unsigned long flags; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2120 | |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2121 | irq = -ENOSPC; |
| 2122 | spin_lock_irqsave(&vector_lock, flags); |
Yinghai Lu | 0799e43 | 2008-08-19 20:49:48 -0700 | [diff] [blame] | 2123 | for (new = (nr_irqs - 1); new >= 0; new--) { |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2124 | if (platform_legacy_irq(new)) |
| 2125 | continue; |
Yinghai Lu | a1420f3 | 2008-08-19 20:50:24 -0700 | [diff] [blame^] | 2126 | if (irq_cfg(new)->vector != 0) |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2127 | continue; |
| 2128 | vector = __assign_irq_vector(new); |
| 2129 | if (likely(vector > 0)) |
| 2130 | irq = new; |
| 2131 | break; |
| 2132 | } |
| 2133 | spin_unlock_irqrestore(&vector_lock, flags); |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2134 | |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2135 | if (irq >= 0) { |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2136 | set_intr_gate(vector, interrupt[irq]); |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2137 | dynamic_irq_init(irq); |
| 2138 | } |
| 2139 | return irq; |
| 2140 | } |
| 2141 | |
| 2142 | void destroy_irq(unsigned int irq) |
| 2143 | { |
| 2144 | unsigned long flags; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2145 | |
| 2146 | dynamic_irq_cleanup(irq); |
| 2147 | |
| 2148 | spin_lock_irqsave(&vector_lock, flags); |
Yinghai Lu | a1420f3 | 2008-08-19 20:50:24 -0700 | [diff] [blame^] | 2149 | clear_bit(irq_cfg(irq)->vector, used_vectors); |
| 2150 | irq_cfg(irq)->vector = 0; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2151 | spin_unlock_irqrestore(&vector_lock, flags); |
| 2152 | } |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2153 | |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2154 | /* |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 2155 | * MSI message composition |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2156 | */ |
| 2157 | #ifdef CONFIG_PCI_MSI |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2158 | static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_msg *msg) |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2159 | { |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2160 | int vector; |
| 2161 | unsigned dest; |
| 2162 | |
| 2163 | vector = assign_irq_vector(irq); |
| 2164 | if (vector >= 0) { |
| 2165 | dest = cpu_mask_to_apicid(TARGET_CPUS); |
| 2166 | |
| 2167 | msg->address_hi = MSI_ADDR_BASE_HI; |
| 2168 | msg->address_lo = |
| 2169 | MSI_ADDR_BASE_LO | |
| 2170 | ((INT_DEST_MODE == 0) ? |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2171 | MSI_ADDR_DEST_MODE_PHYSICAL: |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2172 | MSI_ADDR_DEST_MODE_LOGICAL) | |
| 2173 | ((INT_DELIVERY_MODE != dest_LowestPrio) ? |
| 2174 | MSI_ADDR_REDIRECTION_CPU: |
| 2175 | MSI_ADDR_REDIRECTION_LOWPRI) | |
| 2176 | MSI_ADDR_DEST_ID(dest); |
| 2177 | |
| 2178 | msg->data = |
| 2179 | MSI_DATA_TRIGGER_EDGE | |
| 2180 | MSI_DATA_LEVEL_ASSERT | |
| 2181 | ((INT_DELIVERY_MODE != dest_LowestPrio) ? |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2182 | MSI_DATA_DELIVERY_FIXED: |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2183 | MSI_DATA_DELIVERY_LOWPRI) | |
| 2184 | MSI_DATA_VECTOR(vector); |
| 2185 | } |
| 2186 | return vector; |
| 2187 | } |
| 2188 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2189 | #ifdef CONFIG_SMP |
| 2190 | static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask) |
| 2191 | { |
| 2192 | struct msi_msg msg; |
| 2193 | unsigned int dest; |
| 2194 | cpumask_t tmp; |
| 2195 | int vector; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 2196 | struct irq_desc *desc; |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2197 | |
| 2198 | cpus_and(tmp, mask, cpu_online_map); |
| 2199 | if (cpus_empty(tmp)) |
| 2200 | tmp = TARGET_CPUS; |
| 2201 | |
| 2202 | vector = assign_irq_vector(irq); |
| 2203 | if (vector < 0) |
| 2204 | return; |
| 2205 | |
| 2206 | dest = cpu_mask_to_apicid(mask); |
| 2207 | |
| 2208 | read_msi_msg(irq, &msg); |
| 2209 | |
| 2210 | msg.data &= ~MSI_DATA_VECTOR_MASK; |
| 2211 | msg.data |= MSI_DATA_VECTOR(vector); |
| 2212 | msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK; |
| 2213 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); |
| 2214 | |
| 2215 | write_msi_msg(irq, &msg); |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 2216 | desc = irq_to_desc(irq); |
| 2217 | desc->affinity = mask; |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2218 | } |
| 2219 | #endif /* CONFIG_SMP */ |
| 2220 | |
| 2221 | /* |
| 2222 | * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices, |
| 2223 | * which implement the MSI or MSI-X Capability Structure. |
| 2224 | */ |
| 2225 | static struct irq_chip msi_chip = { |
| 2226 | .name = "PCI-MSI", |
| 2227 | .unmask = unmask_msi_irq, |
| 2228 | .mask = mask_msi_irq, |
| 2229 | .ack = ack_ioapic_irq, |
| 2230 | #ifdef CONFIG_SMP |
| 2231 | .set_affinity = set_msi_irq_affinity, |
| 2232 | #endif |
| 2233 | .retrigger = ioapic_retrigger_irq, |
| 2234 | }; |
| 2235 | |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 2236 | int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc) |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2237 | { |
| 2238 | struct msi_msg msg; |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 2239 | int irq, ret; |
| 2240 | irq = create_irq(); |
| 2241 | if (irq < 0) |
| 2242 | return irq; |
| 2243 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2244 | ret = msi_compose_msg(dev, irq, &msg); |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 2245 | if (ret < 0) { |
| 2246 | destroy_irq(irq); |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2247 | return ret; |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 2248 | } |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2249 | |
Michael Ellerman | 7fe3730 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 2250 | set_irq_msi(irq, desc); |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2251 | write_msi_msg(irq, &msg); |
| 2252 | |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 2253 | set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, |
| 2254 | "edge"); |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2255 | |
Michael Ellerman | 7fe3730 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 2256 | return 0; |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | void arch_teardown_msi_irq(unsigned int irq) |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2260 | { |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 2261 | destroy_irq(irq); |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2262 | } |
| 2263 | |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 2264 | #endif /* CONFIG_PCI_MSI */ |
| 2265 | |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2266 | /* |
| 2267 | * Hypertransport interrupt support |
| 2268 | */ |
| 2269 | #ifdef CONFIG_HT_IRQ |
| 2270 | |
| 2271 | #ifdef CONFIG_SMP |
| 2272 | |
| 2273 | static void target_ht_irq(unsigned int irq, unsigned int dest) |
| 2274 | { |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 2275 | struct ht_irq_msg msg; |
| 2276 | fetch_ht_irq_msg(irq, &msg); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2277 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 2278 | msg.address_lo &= ~(HT_IRQ_LOW_DEST_ID_MASK); |
| 2279 | msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2280 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 2281 | msg.address_lo |= HT_IRQ_LOW_DEST_ID(dest); |
| 2282 | msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2283 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 2284 | write_ht_irq_msg(irq, &msg); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
| 2287 | static void set_ht_irq_affinity(unsigned int irq, cpumask_t mask) |
| 2288 | { |
| 2289 | unsigned int dest; |
| 2290 | cpumask_t tmp; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 2291 | struct irq_desc *desc; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2292 | |
| 2293 | cpus_and(tmp, mask, cpu_online_map); |
| 2294 | if (cpus_empty(tmp)) |
| 2295 | tmp = TARGET_CPUS; |
| 2296 | |
| 2297 | cpus_and(mask, tmp, CPU_MASK_ALL); |
| 2298 | |
| 2299 | dest = cpu_mask_to_apicid(mask); |
| 2300 | |
| 2301 | target_ht_irq(irq, dest); |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 2302 | desc = irq_to_desc(irq); |
| 2303 | desc->affinity = mask; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2304 | } |
| 2305 | #endif |
| 2306 | |
Aneesh Kumar K.V | c37e108 | 2006-10-11 01:20:43 -0700 | [diff] [blame] | 2307 | static struct irq_chip ht_irq_chip = { |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2308 | .name = "PCI-HT", |
| 2309 | .mask = mask_ht_irq, |
| 2310 | .unmask = unmask_ht_irq, |
| 2311 | .ack = ack_ioapic_irq, |
| 2312 | #ifdef CONFIG_SMP |
| 2313 | .set_affinity = set_ht_irq_affinity, |
| 2314 | #endif |
| 2315 | .retrigger = ioapic_retrigger_irq, |
| 2316 | }; |
| 2317 | |
| 2318 | int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev) |
| 2319 | { |
| 2320 | int vector; |
| 2321 | |
| 2322 | vector = assign_irq_vector(irq); |
| 2323 | if (vector >= 0) { |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 2324 | struct ht_irq_msg msg; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2325 | unsigned dest; |
| 2326 | cpumask_t tmp; |
| 2327 | |
| 2328 | cpus_clear(tmp); |
| 2329 | cpu_set(vector >> 8, tmp); |
| 2330 | dest = cpu_mask_to_apicid(tmp); |
| 2331 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 2332 | msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2333 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 2334 | msg.address_lo = |
| 2335 | HT_IRQ_LOW_BASE | |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2336 | HT_IRQ_LOW_DEST_ID(dest) | |
| 2337 | HT_IRQ_LOW_VECTOR(vector) | |
| 2338 | ((INT_DEST_MODE == 0) ? |
| 2339 | HT_IRQ_LOW_DM_PHYSICAL : |
| 2340 | HT_IRQ_LOW_DM_LOGICAL) | |
| 2341 | HT_IRQ_LOW_RQEOI_EDGE | |
| 2342 | ((INT_DELIVERY_MODE != dest_LowestPrio) ? |
| 2343 | HT_IRQ_LOW_MT_FIXED : |
| 2344 | HT_IRQ_LOW_MT_ARBITRATED) | |
| 2345 | HT_IRQ_LOW_IRQ_MASKED; |
| 2346 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 2347 | write_ht_irq_msg(irq, &msg); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2348 | |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 2349 | set_irq_chip_and_handler_name(irq, &ht_irq_chip, |
| 2350 | handle_edge_irq, "edge"); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 2351 | } |
| 2352 | return vector; |
| 2353 | } |
| 2354 | #endif /* CONFIG_HT_IRQ */ |
| 2355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | /* -------------------------------------------------------------------------- |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2357 | ACPI-based IOAPIC Configuration |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | -------------------------------------------------------------------------- */ |
| 2359 | |
Len Brown | 888ba6c | 2005-08-24 12:07:20 -0400 | [diff] [blame] | 2360 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2362 | int __init io_apic_get_unique_id(int ioapic, int apic_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | { |
| 2364 | union IO_APIC_reg_00 reg_00; |
| 2365 | static physid_mask_t apic_id_map = PHYSID_MASK_NONE; |
| 2366 | physid_mask_t tmp; |
| 2367 | unsigned long flags; |
| 2368 | int i = 0; |
| 2369 | |
| 2370 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2371 | * The P4 platform supports up to 256 APIC IDs on two separate APIC |
| 2372 | * buses (one for LAPICs, one for IOAPICs), where predecessors only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | * supports up to 16 on one shared APIC bus. |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2374 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full |
| 2376 | * advantage of new APIC bus architecture. |
| 2377 | */ |
| 2378 | |
| 2379 | if (physids_empty(apic_id_map)) |
| 2380 | apic_id_map = ioapic_phys_id_map(phys_cpu_present_map); |
| 2381 | |
| 2382 | spin_lock_irqsave(&ioapic_lock, flags); |
| 2383 | reg_00.raw = io_apic_read(ioapic, 0); |
| 2384 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 2385 | |
| 2386 | if (apic_id >= get_physical_broadcast()) { |
| 2387 | printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying " |
| 2388 | "%d\n", ioapic, apic_id, reg_00.bits.ID); |
| 2389 | apic_id = reg_00.bits.ID; |
| 2390 | } |
| 2391 | |
| 2392 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2393 | * Every APIC in a system must have a unique ID or we get lots of nice |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | * 'stuck on smp_invalidate_needed IPI wait' messages. |
| 2395 | */ |
| 2396 | if (check_apicid_used(apic_id_map, apic_id)) { |
| 2397 | |
| 2398 | for (i = 0; i < get_physical_broadcast(); i++) { |
| 2399 | if (!check_apicid_used(apic_id_map, i)) |
| 2400 | break; |
| 2401 | } |
| 2402 | |
| 2403 | if (i == get_physical_broadcast()) |
| 2404 | panic("Max apic_id exceeded!\n"); |
| 2405 | |
| 2406 | printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, " |
| 2407 | "trying %d\n", ioapic, apic_id, i); |
| 2408 | |
| 2409 | apic_id = i; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2410 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | |
| 2412 | tmp = apicid_to_cpu_present(apic_id); |
| 2413 | physids_or(apic_id_map, apic_id_map, tmp); |
| 2414 | |
| 2415 | if (reg_00.bits.ID != apic_id) { |
| 2416 | reg_00.bits.ID = apic_id; |
| 2417 | |
| 2418 | spin_lock_irqsave(&ioapic_lock, flags); |
| 2419 | io_apic_write(ioapic, 0, reg_00.raw); |
| 2420 | reg_00.raw = io_apic_read(ioapic, 0); |
| 2421 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 2422 | |
| 2423 | /* Sanity check */ |
Andreas Deresch | 6070f9e | 2006-02-26 04:18:34 +0100 | [diff] [blame] | 2424 | if (reg_00.bits.ID != apic_id) { |
| 2425 | printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic); |
| 2426 | return -1; |
| 2427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | } |
| 2429 | |
| 2430 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 2431 | "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id); |
| 2432 | |
| 2433 | return apic_id; |
| 2434 | } |
| 2435 | |
| 2436 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2437 | int __init io_apic_get_version(int ioapic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | { |
| 2439 | union IO_APIC_reg_01 reg_01; |
| 2440 | unsigned long flags; |
| 2441 | |
| 2442 | spin_lock_irqsave(&ioapic_lock, flags); |
| 2443 | reg_01.raw = io_apic_read(ioapic, 1); |
| 2444 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 2445 | |
| 2446 | return reg_01.bits.version; |
| 2447 | } |
| 2448 | |
| 2449 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2450 | int __init io_apic_get_redir_entries(int ioapic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | { |
| 2452 | union IO_APIC_reg_01 reg_01; |
| 2453 | unsigned long flags; |
| 2454 | |
| 2455 | spin_lock_irqsave(&ioapic_lock, flags); |
| 2456 | reg_01.raw = io_apic_read(ioapic, 1); |
| 2457 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 2458 | |
| 2459 | return reg_01.bits.entries; |
| 2460 | } |
| 2461 | |
| 2462 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2463 | int io_apic_set_pci_routing(int ioapic, int pin, int irq, int edge_level, int active_high_low) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | { |
| 2465 | struct IO_APIC_route_entry entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | |
| 2467 | if (!IO_APIC_IRQ(irq)) { |
| 2468 | printk(KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n", |
| 2469 | ioapic); |
| 2470 | return -EINVAL; |
| 2471 | } |
| 2472 | |
| 2473 | /* |
| 2474 | * Generate a PCI IRQ routing entry and program the IOAPIC accordingly. |
| 2475 | * Note that we mask (disable) IRQs now -- these get enabled when the |
| 2476 | * corresponding device driver registers for this IRQ. |
| 2477 | */ |
| 2478 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2479 | memset(&entry, 0, sizeof(entry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | |
| 2481 | entry.delivery_mode = INT_DELIVERY_MODE; |
| 2482 | entry.dest_mode = INT_DEST_MODE; |
| 2483 | entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS); |
| 2484 | entry.trigger = edge_level; |
| 2485 | entry.polarity = active_high_low; |
| 2486 | entry.mask = 1; |
| 2487 | |
| 2488 | /* |
| 2489 | * IRQs < 16 are already in the irq_2_pin[] map |
| 2490 | */ |
| 2491 | if (irq >= 16) |
| 2492 | add_pin_to_irq(irq, ioapic, pin); |
| 2493 | |
| 2494 | entry.vector = assign_irq_vector(irq); |
| 2495 | |
| 2496 | apic_printk(APIC_DEBUG, KERN_DEBUG "IOAPIC[%d]: Set PCI routing entry " |
| 2497 | "(%d-%d -> 0x%x -> IRQ %d Mode:%i Active:%i)\n", ioapic, |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 2498 | mp_ioapics[ioapic].mp_apicid, pin, entry.vector, irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | edge_level, active_high_low); |
| 2500 | |
| 2501 | ioapic_register_intr(irq, entry.vector, edge_level); |
| 2502 | |
| 2503 | if (!ioapic && (irq < 16)) |
| 2504 | disable_8259A_irq(irq); |
| 2505 | |
Akinobu Mita | a2249cb | 2008-04-05 22:39:05 +0900 | [diff] [blame] | 2506 | ioapic_write_entry(ioapic, pin, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | |
| 2508 | return 0; |
| 2509 | } |
| 2510 | |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 2511 | int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity) |
| 2512 | { |
| 2513 | int i; |
| 2514 | |
| 2515 | if (skip_ioapic_setup) |
| 2516 | return -1; |
| 2517 | |
| 2518 | for (i = 0; i < mp_irq_entries; i++) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 2519 | if (mp_irqs[i].mp_irqtype == mp_INT && |
| 2520 | mp_irqs[i].mp_srcbusirq == bus_irq) |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 2521 | break; |
| 2522 | if (i >= mp_irq_entries) |
| 2523 | return -1; |
| 2524 | |
| 2525 | *trigger = irq_trigger(i); |
| 2526 | *polarity = irq_polarity(i); |
| 2527 | return 0; |
| 2528 | } |
| 2529 | |
Len Brown | 888ba6c | 2005-08-24 12:07:20 -0400 | [diff] [blame] | 2530 | #endif /* CONFIG_ACPI */ |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 2531 | |
| 2532 | static int __init parse_disable_timer_pin_1(char *arg) |
| 2533 | { |
| 2534 | disable_timer_pin_1 = 1; |
| 2535 | return 0; |
| 2536 | } |
| 2537 | early_param("disable_timer_pin_1", parse_disable_timer_pin_1); |
| 2538 | |
| 2539 | static int __init parse_enable_timer_pin_1(char *arg) |
| 2540 | { |
| 2541 | disable_timer_pin_1 = -1; |
| 2542 | return 0; |
| 2543 | } |
| 2544 | early_param("enable_timer_pin_1", parse_enable_timer_pin_1); |
| 2545 | |
| 2546 | static int __init parse_noapic(char *arg) |
| 2547 | { |
| 2548 | /* disable IO-APIC */ |
| 2549 | disable_ioapic_setup(); |
| 2550 | return 0; |
| 2551 | } |
| 2552 | early_param("noapic", parse_noapic); |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2553 | |
| 2554 | void __init ioapic_init_mappings(void) |
| 2555 | { |
| 2556 | unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0; |
| 2557 | int i; |
| 2558 | |
| 2559 | for (i = 0; i < nr_ioapics; i++) { |
| 2560 | if (smp_found_config) { |
| 2561 | ioapic_phys = mp_ioapics[i].mp_apicaddr; |
| 2562 | if (!ioapic_phys) { |
| 2563 | printk(KERN_ERR |
| 2564 | "WARNING: bogus zero IO-APIC " |
| 2565 | "address found in MPTABLE, " |
| 2566 | "disabling IO/APIC support!\n"); |
| 2567 | smp_found_config = 0; |
| 2568 | skip_ioapic_setup = 1; |
| 2569 | goto fake_ioapic_page; |
| 2570 | } |
| 2571 | } else { |
| 2572 | fake_ioapic_page: |
| 2573 | ioapic_phys = (unsigned long) |
| 2574 | alloc_bootmem_pages(PAGE_SIZE); |
| 2575 | ioapic_phys = __pa(ioapic_phys); |
| 2576 | } |
| 2577 | set_fixmap_nocache(idx, ioapic_phys); |
| 2578 | printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n", |
| 2579 | __fix_to_virt(idx), ioapic_phys); |
| 2580 | idx++; |
| 2581 | } |
| 2582 | } |
| 2583 | |