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 | d4057bd | 2008-08-19 20:50:38 -0700 | [diff] [blame] | 28 | #include <linux/pci.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 | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 34 | #include <linux/msi.h> |
Eric W. Biederman | 95d7788 | 2006-10-04 02:17:01 -0700 | [diff] [blame] | 35 | #include <linux/htirq.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 36 | #include <linux/freezer.h> |
Eric W. Biederman | f26d6a2 | 2007-05-02 19:27:19 +0200 | [diff] [blame] | 37 | #include <linux/kthread.h> |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 38 | #include <linux/jiffies.h> /* time_after() */ |
Yinghai Lu | d4057bd | 2008-08-19 20:50:38 -0700 | [diff] [blame] | 39 | #ifdef CONFIG_ACPI |
| 40 | #include <acpi/acpi_bus.h> |
| 41 | #endif |
| 42 | #include <linux/bootmem.h> |
| 43 | #include <linux/dmar.h> |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 44 | #include <linux/hpet.h> |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 45 | |
Yinghai Lu | d4057bd | 2008-08-19 20:50:38 -0700 | [diff] [blame] | 46 | #include <asm/idle.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <asm/io.h> |
| 48 | #include <asm/smp.h> |
| 49 | #include <asm/desc.h> |
Yinghai Lu | d4057bd | 2008-08-19 20:50:38 -0700 | [diff] [blame] | 50 | #include <asm/proto.h> |
| 51 | #include <asm/acpi.h> |
| 52 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/timer.h> |
Ingo Molnar | 306e440 | 2005-06-30 02:58:55 -0700 | [diff] [blame] | 54 | #include <asm/i8259.h> |
Don Zickus | 3e4ff11 | 2006-06-26 13:57:01 +0200 | [diff] [blame] | 55 | #include <asm/nmi.h> |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 56 | #include <asm/msidef.h> |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 57 | #include <asm/hypertransport.h> |
Yinghai Lu | a4dbc34 | 2008-07-25 02:14:28 -0700 | [diff] [blame] | 58 | #include <asm/setup.h> |
Yinghai Lu | d4057bd | 2008-08-19 20:50:38 -0700 | [diff] [blame] | 59 | #include <asm/irq_remapping.h> |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 60 | #include <asm/hpet.h> |
Dean Nelson | 4173a0e | 2008-10-02 12:18:21 -0500 | [diff] [blame] | 61 | #include <asm/uv/uv_hub.h> |
| 62 | #include <asm/uv/uv_irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 64 | #include <mach_ipi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include <mach_apic.h> |
Andi Kleen | 874c4fe | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 66 | #include <mach_apicdef.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 68 | #define __apicdebuginit(type) static type __init |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 71 | * Is the SiS APIC rmw bug present ? |
| 72 | * -1 = don't know, 0 = no, 1 = yes |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | */ |
| 74 | int sis_apic_bug = -1; |
| 75 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 76 | static DEFINE_SPINLOCK(ioapic_lock); |
| 77 | static DEFINE_SPINLOCK(vector_lock); |
| 78 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 79 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | * # of IRQ routing registers |
| 81 | */ |
| 82 | int nr_ioapic_registers[MAX_IO_APICS]; |
| 83 | |
Alexey Starikovskiy | 9f640cc | 2008-04-04 23:41:13 +0400 | [diff] [blame] | 84 | /* I/O APIC entries */ |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 85 | struct mp_config_ioapic mp_ioapics[MAX_IO_APICS]; |
Alexey Starikovskiy | 9f640cc | 2008-04-04 23:41:13 +0400 | [diff] [blame] | 86 | int nr_ioapics; |
| 87 | |
Alexey Starikovskiy | 584f734 | 2008-04-04 23:41:32 +0400 | [diff] [blame] | 88 | /* MP IRQ source entries */ |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 89 | struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES]; |
Alexey Starikovskiy | 584f734 | 2008-04-04 23:41:32 +0400 | [diff] [blame] | 90 | |
| 91 | /* # of MP IRQ source entries */ |
| 92 | int mp_irq_entries; |
| 93 | |
Alexey Starikovskiy | 8732fc4 | 2008-05-19 19:47:16 +0400 | [diff] [blame] | 94 | #if defined (CONFIG_MCA) || defined (CONFIG_EISA) |
| 95 | int mp_bus_id_to_type[MAX_MP_BUSSES]; |
| 96 | #endif |
| 97 | |
| 98 | DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); |
| 99 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 100 | int skip_ioapic_setup; |
| 101 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 102 | static int __init parse_noapic(char *str) |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 103 | { |
| 104 | /* disable IO-APIC */ |
| 105 | disable_ioapic_setup(); |
| 106 | return 0; |
| 107 | } |
| 108 | early_param("noapic", parse_noapic); |
Chuck Ebbert | 66759a0 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 109 | |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 110 | struct irq_pin_list; |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 111 | |
| 112 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * This is performance-critical, we want to do it O(1) |
| 114 | * |
| 115 | * the indexing order of this array favors 1:1 mappings |
| 116 | * between pins and IRQs. |
| 117 | */ |
| 118 | |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 119 | struct irq_pin_list { |
| 120 | int apic, pin; |
| 121 | struct irq_pin_list *next; |
| 122 | }; |
Yinghai Lu | 301e619 | 2008-08-19 20:50:02 -0700 | [diff] [blame] | 123 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 124 | static struct irq_pin_list *get_one_free_irq_2_pin(int cpu) |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 125 | { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 126 | struct irq_pin_list *pin; |
| 127 | int node; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 128 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 129 | node = cpu_to_node(cpu); |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 130 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 131 | pin = kzalloc_node(sizeof(*pin), GFP_ATOMIC, node); |
| 132 | printk(KERN_DEBUG " alloc irq_2_pin on cpu %d node %d\n", cpu, node); |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 133 | |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 134 | return pin; |
| 135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 137 | struct irq_cfg { |
| 138 | struct irq_pin_list *irq_2_pin; |
| 139 | cpumask_t domain; |
| 140 | cpumask_t old_domain; |
| 141 | unsigned move_cleanup_count; |
| 142 | u8 vector; |
| 143 | u8 move_in_progress : 1; |
| 144 | }; |
| 145 | |
| 146 | /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */ |
| 147 | #ifdef CONFIG_SPARSE_IRQ |
| 148 | static struct irq_cfg irq_cfgx[] = { |
| 149 | #else |
| 150 | static struct irq_cfg irq_cfgx[NR_IRQS] = { |
| 151 | #endif |
| 152 | [0] = { .domain = CPU_MASK_ALL, .vector = IRQ0_VECTOR, }, |
| 153 | [1] = { .domain = CPU_MASK_ALL, .vector = IRQ1_VECTOR, }, |
| 154 | [2] = { .domain = CPU_MASK_ALL, .vector = IRQ2_VECTOR, }, |
| 155 | [3] = { .domain = CPU_MASK_ALL, .vector = IRQ3_VECTOR, }, |
| 156 | [4] = { .domain = CPU_MASK_ALL, .vector = IRQ4_VECTOR, }, |
| 157 | [5] = { .domain = CPU_MASK_ALL, .vector = IRQ5_VECTOR, }, |
| 158 | [6] = { .domain = CPU_MASK_ALL, .vector = IRQ6_VECTOR, }, |
| 159 | [7] = { .domain = CPU_MASK_ALL, .vector = IRQ7_VECTOR, }, |
| 160 | [8] = { .domain = CPU_MASK_ALL, .vector = IRQ8_VECTOR, }, |
| 161 | [9] = { .domain = CPU_MASK_ALL, .vector = IRQ9_VECTOR, }, |
| 162 | [10] = { .domain = CPU_MASK_ALL, .vector = IRQ10_VECTOR, }, |
| 163 | [11] = { .domain = CPU_MASK_ALL, .vector = IRQ11_VECTOR, }, |
| 164 | [12] = { .domain = CPU_MASK_ALL, .vector = IRQ12_VECTOR, }, |
| 165 | [13] = { .domain = CPU_MASK_ALL, .vector = IRQ13_VECTOR, }, |
| 166 | [14] = { .domain = CPU_MASK_ALL, .vector = IRQ14_VECTOR, }, |
| 167 | [15] = { .domain = CPU_MASK_ALL, .vector = IRQ15_VECTOR, }, |
| 168 | }; |
| 169 | |
| 170 | void __init arch_early_irq_init(void) |
| 171 | { |
| 172 | struct irq_cfg *cfg; |
| 173 | struct irq_desc *desc; |
| 174 | int count; |
| 175 | int i; |
| 176 | |
| 177 | cfg = irq_cfgx; |
| 178 | count = ARRAY_SIZE(irq_cfgx); |
| 179 | |
| 180 | for (i = 0; i < count; i++) { |
| 181 | desc = irq_to_desc(i); |
| 182 | desc->chip_data = &cfg[i]; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | #ifdef CONFIG_SPARSE_IRQ |
| 187 | static struct irq_cfg *irq_cfg(unsigned int irq) |
| 188 | { |
| 189 | struct irq_cfg *cfg = NULL; |
| 190 | struct irq_desc *desc; |
| 191 | |
| 192 | desc = irq_to_desc(irq); |
| 193 | if (desc) |
| 194 | cfg = desc->chip_data; |
| 195 | |
| 196 | return cfg; |
| 197 | } |
| 198 | |
| 199 | static struct irq_cfg *get_one_free_irq_cfg(int cpu) |
| 200 | { |
| 201 | struct irq_cfg *cfg; |
| 202 | int node; |
| 203 | |
| 204 | node = cpu_to_node(cpu); |
| 205 | |
| 206 | cfg = kzalloc_node(sizeof(*cfg), GFP_ATOMIC, node); |
| 207 | printk(KERN_DEBUG " alloc irq_cfg on cpu %d node %d\n", cpu, node); |
| 208 | |
| 209 | return cfg; |
| 210 | } |
| 211 | |
| 212 | void arch_init_chip_data(struct irq_desc *desc, int cpu) |
| 213 | { |
| 214 | struct irq_cfg *cfg; |
| 215 | |
| 216 | cfg = desc->chip_data; |
| 217 | if (!cfg) { |
| 218 | desc->chip_data = get_one_free_irq_cfg(cpu); |
| 219 | if (!desc->chip_data) { |
| 220 | printk(KERN_ERR "can not alloc irq_cfg\n"); |
| 221 | BUG_ON(1); |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | #else |
| 227 | static struct irq_cfg *irq_cfg(unsigned int irq) |
| 228 | { |
| 229 | return irq < nr_irqs ? irq_cfgx + irq : NULL; |
| 230 | } |
| 231 | |
| 232 | #endif |
| 233 | |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 234 | struct io_apic { |
| 235 | unsigned int index; |
| 236 | unsigned int unused[3]; |
| 237 | unsigned int data; |
| 238 | }; |
| 239 | |
| 240 | static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx) |
| 241 | { |
| 242 | return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx) |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 243 | + (mp_ioapics[idx].mp_apicaddr & ~PAGE_MASK); |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg) |
| 247 | { |
| 248 | struct io_apic __iomem *io_apic = io_apic_base(apic); |
| 249 | writel(reg, &io_apic->index); |
| 250 | return readl(&io_apic->data); |
| 251 | } |
| 252 | |
| 253 | static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value) |
| 254 | { |
| 255 | struct io_apic __iomem *io_apic = io_apic_base(apic); |
| 256 | writel(reg, &io_apic->index); |
| 257 | writel(value, &io_apic->data); |
| 258 | } |
| 259 | |
| 260 | /* |
| 261 | * Re-write a value: to be used for read-modify-write |
| 262 | * cycles where the read already set up the index register. |
| 263 | * |
| 264 | * Older SiS APIC requires we rewrite the index register |
| 265 | */ |
| 266 | static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value) |
| 267 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 268 | struct io_apic __iomem *io_apic = io_apic_base(apic); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 269 | |
| 270 | if (sis_apic_bug) |
| 271 | writel(reg, &io_apic->index); |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 272 | writel(value, &io_apic->data); |
| 273 | } |
| 274 | |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 275 | static bool io_apic_level_ack_pending(unsigned int irq) |
| 276 | { |
| 277 | struct irq_pin_list *entry; |
| 278 | unsigned long flags; |
| 279 | struct irq_cfg *cfg = irq_cfg(irq); |
| 280 | |
| 281 | spin_lock_irqsave(&ioapic_lock, flags); |
| 282 | entry = cfg->irq_2_pin; |
| 283 | for (;;) { |
| 284 | unsigned int reg; |
| 285 | int pin; |
| 286 | |
| 287 | if (!entry) |
| 288 | break; |
| 289 | pin = entry->pin; |
| 290 | reg = io_apic_read(entry->apic, 0x10 + pin*2); |
| 291 | /* Is the remote IRR bit set? */ |
| 292 | if (reg & IO_APIC_REDIR_REMOTE_IRR) { |
| 293 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 294 | return true; |
| 295 | } |
| 296 | if (!entry->next) |
| 297 | break; |
| 298 | entry = entry->next; |
| 299 | } |
| 300 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 301 | |
| 302 | return false; |
| 303 | } |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 304 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 305 | union entry_union { |
| 306 | struct { u32 w1, w2; }; |
| 307 | struct IO_APIC_route_entry entry; |
| 308 | }; |
| 309 | |
| 310 | static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin) |
| 311 | { |
| 312 | union entry_union eu; |
| 313 | unsigned long flags; |
| 314 | spin_lock_irqsave(&ioapic_lock, flags); |
| 315 | eu.w1 = io_apic_read(apic, 0x10 + 2 * pin); |
| 316 | eu.w2 = io_apic_read(apic, 0x11 + 2 * pin); |
| 317 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 318 | return eu.entry; |
| 319 | } |
| 320 | |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 321 | /* |
| 322 | * When we write a new IO APIC routing entry, we need to write the high |
| 323 | * word first! If the mask bit in the low word is clear, we will enable |
| 324 | * the interrupt, and we need to make sure the entry is fully populated |
| 325 | * before that happens. |
| 326 | */ |
Andi Kleen | d15512f | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 327 | static void |
| 328 | __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e) |
| 329 | { |
| 330 | union entry_union eu; |
| 331 | eu.entry = e; |
| 332 | io_apic_write(apic, 0x11 + 2*pin, eu.w2); |
| 333 | io_apic_write(apic, 0x10 + 2*pin, eu.w1); |
| 334 | } |
| 335 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 336 | static void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e) |
| 337 | { |
| 338 | unsigned long flags; |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 339 | spin_lock_irqsave(&ioapic_lock, flags); |
Andi Kleen | d15512f | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 340 | __ioapic_write_entry(apic, pin, e); |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 341 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * When we mask an IO APIC routing entry, we need to write the low |
| 346 | * word first, in order to set the mask bit before we change the |
| 347 | * high bits! |
| 348 | */ |
| 349 | static void ioapic_mask_entry(int apic, int pin) |
| 350 | { |
| 351 | unsigned long flags; |
| 352 | union entry_union eu = { .entry.mask = 1 }; |
| 353 | |
| 354 | spin_lock_irqsave(&ioapic_lock, flags); |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 355 | io_apic_write(apic, 0x10 + 2*pin, eu.w1); |
| 356 | io_apic_write(apic, 0x11 + 2*pin, eu.w2); |
| 357 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 358 | } |
| 359 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 360 | #ifdef CONFIG_SMP |
| 361 | static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, u8 vector) |
| 362 | { |
| 363 | int apic, pin; |
| 364 | struct irq_cfg *cfg; |
| 365 | struct irq_pin_list *entry; |
| 366 | |
| 367 | cfg = irq_cfg(irq); |
| 368 | entry = cfg->irq_2_pin; |
| 369 | for (;;) { |
| 370 | unsigned int reg; |
| 371 | |
| 372 | if (!entry) |
| 373 | break; |
| 374 | |
| 375 | apic = entry->apic; |
| 376 | pin = entry->pin; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 377 | #ifdef CONFIG_INTR_REMAP |
| 378 | /* |
| 379 | * With interrupt-remapping, destination information comes |
| 380 | * from interrupt-remapping table entry. |
| 381 | */ |
| 382 | if (!irq_remapped(irq)) |
| 383 | io_apic_write(apic, 0x11 + pin*2, dest); |
| 384 | #else |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 385 | io_apic_write(apic, 0x11 + pin*2, dest); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 386 | #endif |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 387 | reg = io_apic_read(apic, 0x10 + pin*2); |
| 388 | reg &= ~IO_APIC_REDIR_VECTOR_MASK; |
| 389 | reg |= vector; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 390 | io_apic_modify(apic, 0x10 + pin*2, reg); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 391 | if (!entry->next) |
| 392 | break; |
| 393 | entry = entry->next; |
| 394 | } |
| 395 | } |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 396 | |
| 397 | static int assign_irq_vector(int irq, cpumask_t mask); |
| 398 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 399 | static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t mask) |
| 400 | { |
| 401 | struct irq_cfg *cfg; |
| 402 | unsigned long flags; |
| 403 | unsigned int dest; |
| 404 | cpumask_t tmp; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 405 | struct irq_desc *desc; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 406 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 407 | cpus_and(tmp, mask, cpu_online_map); |
| 408 | if (cpus_empty(tmp)) |
| 409 | return; |
| 410 | |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 411 | cfg = irq_cfg(irq); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 412 | if (assign_irq_vector(irq, mask)) |
| 413 | return; |
| 414 | |
| 415 | cpus_and(tmp, cfg->domain, mask); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 416 | dest = cpu_mask_to_apicid(tmp); |
| 417 | /* |
| 418 | * Only the high 8 bits are valid. |
| 419 | */ |
| 420 | dest = SET_APIC_LOGICAL_ID(dest); |
| 421 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 422 | desc = irq_to_desc(irq); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 423 | spin_lock_irqsave(&ioapic_lock, flags); |
| 424 | __target_IO_APIC_irq(irq, dest, cfg->vector); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 425 | desc->affinity = mask; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 426 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 427 | } |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 428 | #endif /* CONFIG_SMP */ |
| 429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | /* |
| 431 | * The common case is 1:1 IRQ<->pin mappings. Sometimes there are |
| 432 | * shared ISA-space IRQs, so we have to support them. We are super |
| 433 | * fast in the common case, and fast for shared ISA-space IRQs. |
| 434 | */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 435 | static void add_pin_to_irq_cpu(unsigned int irq, int cpu, int apic, int pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 437 | struct irq_pin_list *entry; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 438 | struct irq_cfg *cfg = irq_cfg(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 440 | entry = cfg->irq_2_pin; |
| 441 | if (!entry) { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 442 | entry = get_one_free_irq_2_pin(cpu); |
| 443 | if (!entry) { |
| 444 | printk(KERN_ERR "can not alloc irq_2_pin to add %d - %d\n", |
| 445 | apic, pin); |
| 446 | return; |
| 447 | } |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 448 | cfg->irq_2_pin = entry; |
| 449 | entry->apic = apic; |
| 450 | entry->pin = pin; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 451 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 453 | |
| 454 | while (entry->next) { |
| 455 | /* not again, please */ |
| 456 | if (entry->apic == apic && entry->pin == pin) |
| 457 | return; |
| 458 | |
| 459 | entry = entry->next; |
| 460 | } |
| 461 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 462 | entry->next = get_one_free_irq_2_pin(cpu); |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 463 | entry = entry->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | entry->apic = apic; |
| 465 | entry->pin = pin; |
| 466 | } |
| 467 | |
| 468 | /* |
| 469 | * Reroute an IRQ to a different pin. |
| 470 | */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 471 | static void __init replace_pin_at_irq(unsigned int irq, int cpu, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | int oldapic, int oldpin, |
| 473 | int newapic, int newpin) |
| 474 | { |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 475 | struct irq_cfg *cfg = irq_cfg(irq); |
| 476 | struct irq_pin_list *entry = cfg->irq_2_pin; |
| 477 | int replaced = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 479 | while (entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | if (entry->apic == oldapic && entry->pin == oldpin) { |
| 481 | entry->apic = newapic; |
| 482 | entry->pin = newpin; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 483 | replaced = 1; |
| 484 | /* every one is different, right? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | break; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 486 | } |
| 487 | entry = entry->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 489 | |
| 490 | /* why? call replace before add? */ |
| 491 | if (!replaced) |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 492 | add_pin_to_irq_cpu(irq, cpu, newapic, newpin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 495 | static inline void io_apic_modify_irq(unsigned int irq, |
| 496 | int mask_and, int mask_or, |
| 497 | void (*final)(struct irq_pin_list *entry)) |
| 498 | { |
| 499 | int pin; |
| 500 | struct irq_cfg *cfg; |
| 501 | struct irq_pin_list *entry; |
| 502 | |
| 503 | cfg = irq_cfg(irq); |
| 504 | for (entry = cfg->irq_2_pin; entry != NULL; entry = entry->next) { |
| 505 | unsigned int reg; |
| 506 | pin = entry->pin; |
| 507 | reg = io_apic_read(entry->apic, 0x10 + pin * 2); |
| 508 | reg &= mask_and; |
| 509 | reg |= mask_or; |
| 510 | io_apic_modify(entry->apic, 0x10 + pin * 2, reg); |
| 511 | if (final) |
| 512 | final(entry); |
| 513 | } |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 516 | static void __unmask_IO_APIC_irq(unsigned int irq) |
| 517 | { |
| 518 | io_apic_modify_irq(irq, ~IO_APIC_REDIR_MASKED, 0, NULL); |
| 519 | } |
Yinghai Lu | 4e738e2 | 2008-08-19 20:50:47 -0700 | [diff] [blame] | 520 | |
| 521 | #ifdef CONFIG_X86_64 |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 522 | void io_apic_sync(struct irq_pin_list *entry) |
Yinghai Lu | 4e738e2 | 2008-08-19 20:50:47 -0700 | [diff] [blame] | 523 | { |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 524 | /* |
| 525 | * Synchronize the IO-APIC and the CPU by doing |
| 526 | * a dummy read from the IO-APIC |
| 527 | */ |
| 528 | struct io_apic __iomem *io_apic; |
| 529 | io_apic = io_apic_base(entry->apic); |
Yinghai Lu | 4e738e2 | 2008-08-19 20:50:47 -0700 | [diff] [blame] | 530 | readl(&io_apic->data); |
| 531 | } |
| 532 | |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 533 | static void __mask_IO_APIC_irq(unsigned int irq) |
| 534 | { |
| 535 | io_apic_modify_irq(irq, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync); |
| 536 | } |
| 537 | #else /* CONFIG_X86_32 */ |
| 538 | static void __mask_IO_APIC_irq(unsigned int irq) |
| 539 | { |
| 540 | io_apic_modify_irq(irq, ~0, IO_APIC_REDIR_MASKED, NULL); |
| 541 | } |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 542 | |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 543 | static void __mask_and_edge_IO_APIC_irq(unsigned int irq) |
| 544 | { |
| 545 | io_apic_modify_irq(irq, ~IO_APIC_REDIR_LEVEL_TRIGGER, |
| 546 | IO_APIC_REDIR_MASKED, NULL); |
| 547 | } |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 548 | |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 549 | static void __unmask_and_level_IO_APIC_irq(unsigned int irq) |
| 550 | { |
| 551 | io_apic_modify_irq(irq, ~IO_APIC_REDIR_MASKED, |
| 552 | IO_APIC_REDIR_LEVEL_TRIGGER, NULL); |
| 553 | } |
| 554 | #endif /* CONFIG_X86_32 */ |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 555 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 556 | static void mask_IO_APIC_irq (unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { |
| 558 | unsigned long flags; |
| 559 | |
| 560 | spin_lock_irqsave(&ioapic_lock, flags); |
| 561 | __mask_IO_APIC_irq(irq); |
| 562 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 563 | } |
| 564 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 565 | static void unmask_IO_APIC_irq (unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | { |
| 567 | unsigned long flags; |
| 568 | |
| 569 | spin_lock_irqsave(&ioapic_lock, flags); |
| 570 | __unmask_IO_APIC_irq(irq); |
| 571 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 572 | } |
| 573 | |
| 574 | static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin) |
| 575 | { |
| 576 | struct IO_APIC_route_entry entry; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | /* 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] | 579 | entry = ioapic_read_entry(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | if (entry.delivery_mode == dest_SMI) |
| 581 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* |
| 583 | * Disable it in the IO-APIC irq-routing table: |
| 584 | */ |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 585 | ioapic_mask_entry(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 588 | static void clear_IO_APIC (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
| 590 | int apic, pin; |
| 591 | |
| 592 | for (apic = 0; apic < nr_ioapics; apic++) |
| 593 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) |
| 594 | clear_IO_APIC_pin(apic, pin); |
| 595 | } |
| 596 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 597 | #if !defined(CONFIG_SMP) && defined(CONFIG_X86_32) |
Harvey Harrison | 75604d7 | 2008-01-30 13:31:17 +0100 | [diff] [blame] | 598 | void send_IPI_self(int vector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | { |
| 600 | unsigned int cfg; |
| 601 | |
| 602 | /* |
| 603 | * Wait for idle. |
| 604 | */ |
| 605 | apic_wait_icr_idle(); |
| 606 | cfg = APIC_DM_FIXED | APIC_DEST_SELF | vector | APIC_DEST_LOGICAL; |
| 607 | /* |
| 608 | * Send the IPI. The write to APIC_ICR fires this off. |
| 609 | */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 610 | apic_write(APIC_ICR, cfg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 612 | #endif /* !CONFIG_SMP && CONFIG_X86_32*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 614 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | /* |
| 616 | * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to |
| 617 | * specific CPU-side IRQs. |
| 618 | */ |
| 619 | |
| 620 | #define MAX_PIRQS 8 |
| 621 | static int pirq_entries [MAX_PIRQS]; |
| 622 | static int pirqs_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | static int __init ioapic_pirq_setup(char *str) |
| 625 | { |
| 626 | int i, max; |
| 627 | int ints[MAX_PIRQS+1]; |
| 628 | |
| 629 | get_options(str, ARRAY_SIZE(ints), ints); |
| 630 | |
| 631 | for (i = 0; i < MAX_PIRQS; i++) |
| 632 | pirq_entries[i] = -1; |
| 633 | |
| 634 | pirqs_enabled = 1; |
| 635 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 636 | "PIRQ redirection, working around broken MP-BIOS.\n"); |
| 637 | max = MAX_PIRQS; |
| 638 | if (ints[0] < MAX_PIRQS) |
| 639 | max = ints[0]; |
| 640 | |
| 641 | for (i = 0; i < max; i++) { |
| 642 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 643 | "... PIRQ%d -> IRQ %d\n", i, ints[i+1]); |
| 644 | /* |
| 645 | * PIRQs are mapped upside down, usually. |
| 646 | */ |
| 647 | pirq_entries[MAX_PIRQS-i-1] = ints[i+1]; |
| 648 | } |
| 649 | return 1; |
| 650 | } |
| 651 | |
| 652 | __setup("pirq=", ioapic_pirq_setup); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 653 | #endif /* CONFIG_X86_32 */ |
| 654 | |
| 655 | #ifdef CONFIG_INTR_REMAP |
| 656 | /* I/O APIC RTE contents at the OS boot up */ |
| 657 | static struct IO_APIC_route_entry *early_ioapic_entries[MAX_IO_APICS]; |
| 658 | |
| 659 | /* |
| 660 | * Saves and masks all the unmasked IO-APIC RTE's |
| 661 | */ |
| 662 | int save_mask_IO_APIC_setup(void) |
| 663 | { |
| 664 | union IO_APIC_reg_01 reg_01; |
| 665 | unsigned long flags; |
| 666 | int apic, pin; |
| 667 | |
| 668 | /* |
| 669 | * The number of IO-APIC IRQ registers (== #pins): |
| 670 | */ |
| 671 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 672 | spin_lock_irqsave(&ioapic_lock, flags); |
| 673 | reg_01.raw = io_apic_read(apic, 1); |
| 674 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 675 | nr_ioapic_registers[apic] = reg_01.bits.entries+1; |
| 676 | } |
| 677 | |
| 678 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 679 | early_ioapic_entries[apic] = |
| 680 | kzalloc(sizeof(struct IO_APIC_route_entry) * |
| 681 | nr_ioapic_registers[apic], GFP_KERNEL); |
| 682 | if (!early_ioapic_entries[apic]) |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 683 | goto nomem; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | for (apic = 0; apic < nr_ioapics; apic++) |
| 687 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { |
| 688 | struct IO_APIC_route_entry entry; |
| 689 | |
| 690 | entry = early_ioapic_entries[apic][pin] = |
| 691 | ioapic_read_entry(apic, pin); |
| 692 | if (!entry.mask) { |
| 693 | entry.mask = 1; |
| 694 | ioapic_write_entry(apic, pin, entry); |
| 695 | } |
| 696 | } |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 697 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 698 | return 0; |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 699 | |
| 700 | nomem: |
Cyrill Gorcunov | c1370b4 | 2008-09-23 23:00:02 +0400 | [diff] [blame] | 701 | while (apic >= 0) |
| 702 | kfree(early_ioapic_entries[apic--]); |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 703 | memset(early_ioapic_entries, 0, |
| 704 | ARRAY_SIZE(early_ioapic_entries)); |
| 705 | |
| 706 | return -ENOMEM; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 707 | } |
| 708 | |
| 709 | void restore_IO_APIC_setup(void) |
| 710 | { |
| 711 | int apic, pin; |
| 712 | |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 713 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 714 | if (!early_ioapic_entries[apic]) |
| 715 | break; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 716 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) |
| 717 | ioapic_write_entry(apic, pin, |
| 718 | early_ioapic_entries[apic][pin]); |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 719 | kfree(early_ioapic_entries[apic]); |
| 720 | early_ioapic_entries[apic] = NULL; |
| 721 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | void reinit_intr_remapped_IO_APIC(int intr_remapping) |
| 725 | { |
| 726 | /* |
| 727 | * for now plain restore of previous settings. |
| 728 | * TBD: In the case of OS enabling interrupt-remapping, |
| 729 | * IO-APIC RTE's need to be setup to point to interrupt-remapping |
| 730 | * table entries. for now, do a plain restore, and wait for |
| 731 | * the setup_IO_APIC_irqs() to do proper initialization. |
| 732 | */ |
| 733 | restore_IO_APIC_setup(); |
| 734 | } |
| 735 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | /* |
| 738 | * Find the IRQ entry number of a certain pin. |
| 739 | */ |
| 740 | static int find_irq_entry(int apic, int pin, int type) |
| 741 | { |
| 742 | int i; |
| 743 | |
| 744 | for (i = 0; i < mp_irq_entries; i++) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 745 | if (mp_irqs[i].mp_irqtype == type && |
| 746 | (mp_irqs[i].mp_dstapic == mp_ioapics[apic].mp_apicid || |
| 747 | mp_irqs[i].mp_dstapic == MP_APIC_ALL) && |
| 748 | mp_irqs[i].mp_dstirq == pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | return i; |
| 750 | |
| 751 | return -1; |
| 752 | } |
| 753 | |
| 754 | /* |
| 755 | * Find the pin to which IRQ[irq] (ISA) is connected |
| 756 | */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 757 | static int __init find_isa_irq_pin(int irq, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | { |
| 759 | int i; |
| 760 | |
| 761 | for (i = 0; i < mp_irq_entries; i++) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 762 | int lbus = mp_irqs[i].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Alexey Starikovskiy | d27e2b8 | 2008-03-20 14:54:18 +0300 | [diff] [blame] | 764 | if (test_bit(lbus, mp_bus_not_pci) && |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 765 | (mp_irqs[i].mp_irqtype == type) && |
| 766 | (mp_irqs[i].mp_srcbusirq == irq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 768 | return mp_irqs[i].mp_dstirq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | return -1; |
| 771 | } |
| 772 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 773 | static int __init find_isa_irq_apic(int irq, int type) |
| 774 | { |
| 775 | int i; |
| 776 | |
| 777 | for (i = 0; i < mp_irq_entries; i++) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 778 | int lbus = mp_irqs[i].mp_srcbus; |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 779 | |
Alexey Starikovskiy | 73b2961 | 2008-03-20 14:54:24 +0300 | [diff] [blame] | 780 | if (test_bit(lbus, mp_bus_not_pci) && |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 781 | (mp_irqs[i].mp_irqtype == type) && |
| 782 | (mp_irqs[i].mp_srcbusirq == irq)) |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 783 | break; |
| 784 | } |
| 785 | if (i < mp_irq_entries) { |
| 786 | int apic; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 787 | for(apic = 0; apic < nr_ioapics; apic++) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 788 | if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic) |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 789 | return apic; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | return -1; |
| 794 | } |
| 795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | /* |
| 797 | * Find a specific PCI IRQ entry. |
| 798 | * Not an __init, possibly needed by modules |
| 799 | */ |
| 800 | static int pin_2_irq(int idx, int apic, int pin); |
| 801 | |
| 802 | int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin) |
| 803 | { |
| 804 | int apic, i, best_guess = -1; |
| 805 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 806 | apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n", |
| 807 | bus, slot, pin); |
Alexey Starikovskiy | ce6444d | 2008-05-19 19:47:09 +0400 | [diff] [blame] | 808 | if (test_bit(bus, mp_bus_not_pci)) { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 809 | apic_printk(APIC_VERBOSE, "PCI BIOS passed nonexistent PCI bus %d!\n", bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | return -1; |
| 811 | } |
| 812 | for (i = 0; i < mp_irq_entries; i++) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 813 | int lbus = mp_irqs[i].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | |
| 815 | for (apic = 0; apic < nr_ioapics; apic++) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 816 | if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic || |
| 817 | mp_irqs[i].mp_dstapic == MP_APIC_ALL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | break; |
| 819 | |
Alexey Starikovskiy | 47cab82 | 2008-03-20 14:54:30 +0300 | [diff] [blame] | 820 | if (!test_bit(lbus, mp_bus_not_pci) && |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 821 | !mp_irqs[i].mp_irqtype && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | (bus == lbus) && |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 823 | (slot == ((mp_irqs[i].mp_srcbusirq >> 2) & 0x1f))) { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 824 | int irq = pin_2_irq(i,apic,mp_irqs[i].mp_dstirq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
| 826 | if (!(apic || IO_APIC_IRQ(irq))) |
| 827 | continue; |
| 828 | |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 829 | if (pin == (mp_irqs[i].mp_srcbusirq & 3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | return irq; |
| 831 | /* |
| 832 | * Use the first all-but-pin matching entry as a |
| 833 | * best-guess fuzzy result for broken mptables. |
| 834 | */ |
| 835 | if (best_guess < 0) |
| 836 | best_guess = irq; |
| 837 | } |
| 838 | } |
| 839 | return best_guess; |
| 840 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 841 | |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 842 | EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 844 | #if defined(CONFIG_EISA) || defined(CONFIG_MCA) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | /* |
| 846 | * EISA Edge/Level control register, ELCR |
| 847 | */ |
| 848 | static int EISA_ELCR(unsigned int irq) |
| 849 | { |
Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame^] | 850 | if (irq < NR_IRQS_LEGACY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | unsigned int port = 0x4d0 + (irq >> 3); |
| 852 | return (inb(port) >> (irq & 7)) & 1; |
| 853 | } |
| 854 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 855 | "Broken MPtable reports ISA irq %d\n", irq); |
| 856 | return 0; |
| 857 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 858 | |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 859 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 861 | /* ISA interrupts are always polarity zero edge triggered, |
| 862 | * when listed as conforming in the MP table. */ |
| 863 | |
| 864 | #define default_ISA_trigger(idx) (0) |
| 865 | #define default_ISA_polarity(idx) (0) |
| 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | /* EISA interrupts are always polarity zero and can be edge or level |
| 868 | * trigger depending on the ELCR value. If an interrupt is listed as |
| 869 | * EISA conforming in the MP table, that means its trigger type must |
| 870 | * be read in from the ELCR */ |
| 871 | |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 872 | #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].mp_srcbusirq)) |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 873 | #define default_EISA_polarity(idx) default_ISA_polarity(idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | |
| 875 | /* PCI interrupts are always polarity one level triggered, |
| 876 | * when listed as conforming in the MP table. */ |
| 877 | |
| 878 | #define default_PCI_trigger(idx) (1) |
| 879 | #define default_PCI_polarity(idx) (1) |
| 880 | |
| 881 | /* MCA interrupts are always polarity zero level triggered, |
| 882 | * when listed as conforming in the MP table. */ |
| 883 | |
| 884 | #define default_MCA_trigger(idx) (1) |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 885 | #define default_MCA_polarity(idx) default_ISA_polarity(idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 887 | static int MPBIOS_polarity(int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 889 | int bus = mp_irqs[idx].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | int polarity; |
| 891 | |
| 892 | /* |
| 893 | * Determine IRQ line polarity (high active or low active): |
| 894 | */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 895 | switch (mp_irqs[idx].mp_irqflag & 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 897 | case 0: /* conforms, ie. bus-type dependent polarity */ |
| 898 | if (test_bit(bus, mp_bus_not_pci)) |
| 899 | polarity = default_ISA_polarity(idx); |
| 900 | else |
| 901 | polarity = default_PCI_polarity(idx); |
| 902 | break; |
| 903 | case 1: /* high active */ |
| 904 | { |
| 905 | polarity = 0; |
| 906 | break; |
| 907 | } |
| 908 | case 2: /* reserved */ |
| 909 | { |
| 910 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 911 | polarity = 1; |
| 912 | break; |
| 913 | } |
| 914 | case 3: /* low active */ |
| 915 | { |
| 916 | polarity = 1; |
| 917 | break; |
| 918 | } |
| 919 | default: /* invalid */ |
| 920 | { |
| 921 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 922 | polarity = 1; |
| 923 | break; |
| 924 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | } |
| 926 | return polarity; |
| 927 | } |
| 928 | |
| 929 | static int MPBIOS_trigger(int idx) |
| 930 | { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 931 | int bus = mp_irqs[idx].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | int trigger; |
| 933 | |
| 934 | /* |
| 935 | * Determine IRQ trigger mode (edge or level sensitive): |
| 936 | */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 937 | switch ((mp_irqs[idx].mp_irqflag>>2) & 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 939 | case 0: /* conforms, ie. bus-type dependent */ |
| 940 | if (test_bit(bus, mp_bus_not_pci)) |
| 941 | trigger = default_ISA_trigger(idx); |
| 942 | else |
| 943 | trigger = default_PCI_trigger(idx); |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 944 | #if defined(CONFIG_EISA) || defined(CONFIG_MCA) |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 945 | switch (mp_bus_id_to_type[bus]) { |
| 946 | case MP_BUS_ISA: /* ISA pin */ |
| 947 | { |
| 948 | /* set before the switch */ |
| 949 | break; |
| 950 | } |
| 951 | case MP_BUS_EISA: /* EISA pin */ |
| 952 | { |
| 953 | trigger = default_EISA_trigger(idx); |
| 954 | break; |
| 955 | } |
| 956 | case MP_BUS_PCI: /* PCI pin */ |
| 957 | { |
| 958 | /* set before the switch */ |
| 959 | break; |
| 960 | } |
| 961 | case MP_BUS_MCA: /* MCA pin */ |
| 962 | { |
| 963 | trigger = default_MCA_trigger(idx); |
| 964 | break; |
| 965 | } |
| 966 | default: |
| 967 | { |
| 968 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 969 | trigger = 1; |
| 970 | break; |
| 971 | } |
| 972 | } |
| 973 | #endif |
| 974 | break; |
| 975 | case 1: /* edge */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 976 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 977 | trigger = 0; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 978 | break; |
| 979 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 980 | case 2: /* reserved */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 981 | { |
| 982 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 983 | trigger = 1; |
| 984 | break; |
| 985 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 986 | case 3: /* level */ |
| 987 | { |
| 988 | trigger = 1; |
| 989 | break; |
| 990 | } |
| 991 | default: /* invalid */ |
| 992 | { |
| 993 | printk(KERN_WARNING "broken BIOS!!\n"); |
| 994 | trigger = 0; |
| 995 | break; |
| 996 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | } |
| 998 | return trigger; |
| 999 | } |
| 1000 | |
| 1001 | static inline int irq_polarity(int idx) |
| 1002 | { |
| 1003 | return MPBIOS_polarity(idx); |
| 1004 | } |
| 1005 | |
| 1006 | static inline int irq_trigger(int idx) |
| 1007 | { |
| 1008 | return MPBIOS_trigger(idx); |
| 1009 | } |
| 1010 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 1011 | int (*ioapic_renumber_irq)(int ioapic, int irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | static int pin_2_irq(int idx, int apic, int pin) |
| 1013 | { |
| 1014 | int irq, i; |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 1015 | int bus = mp_irqs[idx].mp_srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
| 1017 | /* |
| 1018 | * Debugging check, we are in big trouble if this message pops up! |
| 1019 | */ |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 1020 | if (mp_irqs[idx].mp_dstirq != pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n"); |
| 1022 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1023 | if (test_bit(bus, mp_bus_not_pci)) { |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 1024 | irq = mp_irqs[idx].mp_srcbusirq; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1025 | } else { |
Alexey Starikovskiy | 643befe | 2008-03-20 14:54:49 +0300 | [diff] [blame] | 1026 | /* |
| 1027 | * PCI IRQs are mapped in order |
| 1028 | */ |
| 1029 | i = irq = 0; |
| 1030 | while (i < apic) |
| 1031 | irq += nr_ioapic_registers[i++]; |
| 1032 | irq += pin; |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1033 | /* |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1034 | * For MPS mode, so far only needed by ES7000 platform |
| 1035 | */ |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1036 | if (ioapic_renumber_irq) |
| 1037 | irq = ioapic_renumber_irq(apic, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1040 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | /* |
| 1042 | * PCI IRQ command line redirection. Yes, limits are hardcoded. |
| 1043 | */ |
| 1044 | if ((pin >= 16) && (pin <= 23)) { |
| 1045 | if (pirq_entries[pin-16] != -1) { |
| 1046 | if (!pirq_entries[pin-16]) { |
| 1047 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 1048 | "disabling PIRQ%d\n", pin-16); |
| 1049 | } else { |
| 1050 | irq = pirq_entries[pin-16]; |
| 1051 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 1052 | "using PIRQ%d -> IRQ %d\n", |
| 1053 | pin-16, irq); |
| 1054 | } |
| 1055 | } |
| 1056 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1057 | #endif |
| 1058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | return irq; |
| 1060 | } |
| 1061 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1062 | void lock_vector_lock(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1064 | /* Used to the online set of cpus does not change |
| 1065 | * during assign_irq_vector. |
| 1066 | */ |
| 1067 | spin_lock(&vector_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | } |
| 1069 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1070 | void unlock_vector_lock(void) |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1071 | { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1072 | spin_unlock(&vector_lock); |
| 1073 | } |
| 1074 | |
| 1075 | static int __assign_irq_vector(int irq, cpumask_t mask) |
| 1076 | { |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1077 | /* |
| 1078 | * NOTE! The local APIC isn't very good at handling |
| 1079 | * multiple interrupts at the same interrupt level. |
| 1080 | * As the interrupt level is determined by taking the |
| 1081 | * vector number and shifting that right by 4, we |
| 1082 | * want to spread these out a bit so that they don't |
| 1083 | * all fall in the same interrupt level. |
| 1084 | * |
| 1085 | * Also, we've got to be careful not to trash gate |
| 1086 | * 0x80, because int 0x80 is hm, kind of importantish. ;) |
| 1087 | */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1088 | static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0; |
| 1089 | unsigned int old_vector; |
| 1090 | int cpu; |
| 1091 | struct irq_cfg *cfg; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1092 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1093 | cfg = irq_cfg(irq); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1094 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1095 | /* Only try and allocate irqs on cpus that are present */ |
| 1096 | cpus_and(mask, mask, cpu_online_map); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1097 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1098 | if ((cfg->move_in_progress) || cfg->move_cleanup_count) |
| 1099 | return -EBUSY; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1100 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1101 | old_vector = cfg->vector; |
| 1102 | if (old_vector) { |
| 1103 | cpumask_t tmp; |
| 1104 | cpus_and(tmp, cfg->domain, mask); |
| 1105 | if (!cpus_empty(tmp)) |
| 1106 | return 0; |
| 1107 | } |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1108 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1109 | for_each_cpu_mask_nr(cpu, mask) { |
| 1110 | cpumask_t domain, new_mask; |
| 1111 | int new_cpu; |
| 1112 | int vector, offset; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1113 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1114 | domain = vector_allocation_domain(cpu); |
| 1115 | cpus_and(new_mask, domain, cpu_online_map); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1116 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1117 | vector = current_vector; |
| 1118 | offset = current_offset; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1119 | next: |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1120 | vector += 8; |
| 1121 | if (vector >= first_system_vector) { |
| 1122 | /* If we run out of vectors on large boxen, must share them. */ |
| 1123 | offset = (offset + 1) % 8; |
| 1124 | vector = FIRST_DEVICE_VECTOR + offset; |
Yinghai Lu | 7a959cf | 2008-08-19 20:50:32 -0700 | [diff] [blame] | 1125 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1126 | if (unlikely(current_vector == vector)) |
| 1127 | continue; |
| 1128 | #ifdef CONFIG_X86_64 |
| 1129 | if (vector == IA32_SYSCALL_VECTOR) |
| 1130 | goto next; |
| 1131 | #else |
| 1132 | if (vector == SYSCALL_VECTOR) |
| 1133 | goto next; |
| 1134 | #endif |
| 1135 | for_each_cpu_mask_nr(new_cpu, new_mask) |
| 1136 | if (per_cpu(vector_irq, new_cpu)[vector] != -1) |
| 1137 | goto next; |
| 1138 | /* Found one! */ |
| 1139 | current_vector = vector; |
| 1140 | current_offset = offset; |
| 1141 | if (old_vector) { |
| 1142 | cfg->move_in_progress = 1; |
| 1143 | cfg->old_domain = cfg->domain; |
| 1144 | } |
| 1145 | for_each_cpu_mask_nr(new_cpu, new_mask) |
| 1146 | per_cpu(vector_irq, new_cpu)[vector] = irq; |
| 1147 | cfg->vector = vector; |
| 1148 | cfg->domain = domain; |
| 1149 | return 0; |
| 1150 | } |
| 1151 | return -ENOSPC; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | static int assign_irq_vector(int irq, cpumask_t mask) |
| 1155 | { |
| 1156 | int err; |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1157 | unsigned long flags; |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1158 | |
| 1159 | spin_lock_irqsave(&vector_lock, flags); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1160 | err = __assign_irq_vector(irq, mask); |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1161 | spin_unlock_irqrestore(&vector_lock, flags); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1162 | return err; |
| 1163 | } |
| 1164 | |
| 1165 | static void __clear_irq_vector(int irq) |
| 1166 | { |
| 1167 | struct irq_cfg *cfg; |
| 1168 | cpumask_t mask; |
| 1169 | int cpu, vector; |
| 1170 | |
| 1171 | cfg = irq_cfg(irq); |
| 1172 | BUG_ON(!cfg->vector); |
| 1173 | |
| 1174 | vector = cfg->vector; |
| 1175 | cpus_and(mask, cfg->domain, cpu_online_map); |
| 1176 | for_each_cpu_mask_nr(cpu, mask) |
| 1177 | per_cpu(vector_irq, cpu)[vector] = -1; |
| 1178 | |
| 1179 | cfg->vector = 0; |
| 1180 | cpus_clear(cfg->domain); |
Matthew Wilcox | 0ca4b6b | 2008-11-20 14:09:33 -0700 | [diff] [blame] | 1181 | |
| 1182 | if (likely(!cfg->move_in_progress)) |
| 1183 | return; |
| 1184 | cpus_and(mask, cfg->old_domain, cpu_online_map); |
| 1185 | for_each_cpu_mask_nr(cpu, mask) { |
| 1186 | for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; |
| 1187 | vector++) { |
| 1188 | if (per_cpu(vector_irq, cpu)[vector] != irq) |
| 1189 | continue; |
| 1190 | per_cpu(vector_irq, cpu)[vector] = -1; |
| 1191 | break; |
| 1192 | } |
| 1193 | } |
| 1194 | cfg->move_in_progress = 0; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | void __setup_vector_irq(int cpu) |
| 1198 | { |
| 1199 | /* Initialize vector_irq on a new cpu */ |
| 1200 | /* This function must be called with vector_lock held */ |
| 1201 | int irq, vector; |
| 1202 | struct irq_cfg *cfg; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1203 | struct irq_desc *desc; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1204 | |
| 1205 | /* Mark the inuse vectors */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1206 | for_each_irq_desc(irq, desc) { |
| 1207 | if (!desc) |
| 1208 | continue; |
| 1209 | cfg = desc->chip_data; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1210 | if (!cpu_isset(cpu, cfg->domain)) |
| 1211 | continue; |
| 1212 | vector = cfg->vector; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1213 | per_cpu(vector_irq, cpu)[vector] = irq; |
| 1214 | } |
| 1215 | /* Mark the free vectors */ |
| 1216 | for (vector = 0; vector < NR_VECTORS; ++vector) { |
| 1217 | irq = per_cpu(vector_irq, cpu)[vector]; |
| 1218 | if (irq < 0) |
| 1219 | continue; |
| 1220 | |
| 1221 | cfg = irq_cfg(irq); |
| 1222 | if (!cpu_isset(cpu, cfg->domain)) |
| 1223 | per_cpu(vector_irq, cpu)[vector] = -1; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1224 | } |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 1225 | } |
Glauber Costa | 3fde690 | 2008-05-28 20:34:19 -0700 | [diff] [blame] | 1226 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1227 | static struct irq_chip ioapic_chip; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1228 | #ifdef CONFIG_INTR_REMAP |
| 1229 | static struct irq_chip ir_ioapic_chip; |
| 1230 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1232 | #define IOAPIC_AUTO -1 |
| 1233 | #define IOAPIC_EDGE 0 |
| 1234 | #define IOAPIC_LEVEL 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1236 | #ifdef CONFIG_X86_32 |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1237 | static inline int IO_APIC_irq_trigger(int irq) |
| 1238 | { |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1239 | int apic, idx, pin; |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1240 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1241 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 1242 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { |
| 1243 | idx = find_irq_entry(apic, pin, mp_INT); |
| 1244 | if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin))) |
| 1245 | return irq_trigger(idx); |
| 1246 | } |
| 1247 | } |
| 1248 | /* |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1249 | * nonexistent IRQs are edge default |
| 1250 | */ |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1251 | return 0; |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1252 | } |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1253 | #else |
| 1254 | static inline int IO_APIC_irq_trigger(int irq) |
| 1255 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1256 | return 1; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1257 | } |
| 1258 | #endif |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1259 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1260 | static void ioapic_register_intr(int irq, unsigned long trigger) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 1262 | struct irq_desc *desc; |
| 1263 | |
Thomas Gleixner | ee32c97 | 2008-10-15 14:34:09 +0200 | [diff] [blame] | 1264 | desc = irq_to_desc(irq); |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 1265 | |
Jan Beulich | 6ebcc00 | 2006-06-26 13:56:46 +0200 | [diff] [blame] | 1266 | if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) || |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1267 | trigger == IOAPIC_LEVEL) |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 1268 | desc->status |= IRQ_LEVEL; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1269 | else |
| 1270 | desc->status &= ~IRQ_LEVEL; |
| 1271 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1272 | #ifdef CONFIG_INTR_REMAP |
| 1273 | if (irq_remapped(irq)) { |
| 1274 | desc->status |= IRQ_MOVE_PCNTXT; |
| 1275 | if (trigger) |
| 1276 | set_irq_chip_and_handler_name(irq, &ir_ioapic_chip, |
| 1277 | handle_fasteoi_irq, |
| 1278 | "fasteoi"); |
| 1279 | else |
| 1280 | set_irq_chip_and_handler_name(irq, &ir_ioapic_chip, |
| 1281 | handle_edge_irq, "edge"); |
| 1282 | return; |
| 1283 | } |
| 1284 | #endif |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1285 | if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) || |
| 1286 | trigger == IOAPIC_LEVEL) |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 1287 | set_irq_chip_and_handler_name(irq, &ioapic_chip, |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1288 | handle_fasteoi_irq, |
| 1289 | "fasteoi"); |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1290 | else |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 1291 | set_irq_chip_and_handler_name(irq, &ioapic_chip, |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1292 | handle_edge_irq, "edge"); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | static int setup_ioapic_entry(int apic, int irq, |
| 1296 | struct IO_APIC_route_entry *entry, |
| 1297 | unsigned int destination, int trigger, |
| 1298 | int polarity, int vector) |
| 1299 | { |
| 1300 | /* |
| 1301 | * add it to the IO-APIC irq-routing table: |
| 1302 | */ |
| 1303 | memset(entry,0,sizeof(*entry)); |
| 1304 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1305 | #ifdef CONFIG_INTR_REMAP |
| 1306 | if (intr_remapping_enabled) { |
| 1307 | struct intel_iommu *iommu = map_ioapic_to_ir(apic); |
| 1308 | struct irte irte; |
| 1309 | struct IR_IO_APIC_route_entry *ir_entry = |
| 1310 | (struct IR_IO_APIC_route_entry *) entry; |
| 1311 | int index; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1312 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1313 | if (!iommu) |
| 1314 | panic("No mapping iommu for ioapic %d\n", apic); |
| 1315 | |
| 1316 | index = alloc_irte(iommu, irq, 1); |
| 1317 | if (index < 0) |
| 1318 | panic("Failed to allocate IRTE for ioapic %d\n", apic); |
| 1319 | |
| 1320 | memset(&irte, 0, sizeof(irte)); |
| 1321 | |
| 1322 | irte.present = 1; |
| 1323 | irte.dst_mode = INT_DEST_MODE; |
| 1324 | irte.trigger_mode = trigger; |
| 1325 | irte.dlvry_mode = INT_DELIVERY_MODE; |
| 1326 | irte.vector = vector; |
| 1327 | irte.dest_id = IRTE_DEST(destination); |
| 1328 | |
| 1329 | modify_irte(irq, &irte); |
| 1330 | |
| 1331 | ir_entry->index2 = (index >> 15) & 0x1; |
| 1332 | ir_entry->zero = 0; |
| 1333 | ir_entry->format = 1; |
| 1334 | ir_entry->index = (index & 0x7fff); |
| 1335 | } else |
| 1336 | #endif |
| 1337 | { |
| 1338 | entry->delivery_mode = INT_DELIVERY_MODE; |
| 1339 | entry->dest_mode = INT_DEST_MODE; |
| 1340 | entry->dest = destination; |
| 1341 | } |
| 1342 | |
| 1343 | entry->mask = 0; /* enable IRQ */ |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1344 | entry->trigger = trigger; |
| 1345 | entry->polarity = polarity; |
| 1346 | entry->vector = vector; |
| 1347 | |
| 1348 | /* Mask level triggered irqs. |
| 1349 | * Use IRQ_DELAYED_DISABLE for edge triggered irqs. |
| 1350 | */ |
| 1351 | if (trigger) |
| 1352 | entry->mask = 1; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | static void setup_IO_APIC_irq(int apic, int pin, unsigned int irq, |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1357 | int trigger, int polarity) |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1358 | { |
| 1359 | struct irq_cfg *cfg; |
| 1360 | struct IO_APIC_route_entry entry; |
| 1361 | cpumask_t mask; |
| 1362 | |
| 1363 | if (!IO_APIC_IRQ(irq)) |
| 1364 | return; |
| 1365 | |
| 1366 | cfg = irq_cfg(irq); |
| 1367 | |
| 1368 | mask = TARGET_CPUS; |
| 1369 | if (assign_irq_vector(irq, mask)) |
| 1370 | return; |
| 1371 | |
| 1372 | cpus_and(mask, cfg->domain, mask); |
| 1373 | |
| 1374 | apic_printk(APIC_VERBOSE,KERN_DEBUG |
| 1375 | "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> " |
| 1376 | "IRQ %d Mode:%i Active:%i)\n", |
| 1377 | apic, mp_ioapics[apic].mp_apicid, pin, cfg->vector, |
| 1378 | irq, trigger, polarity); |
| 1379 | |
| 1380 | |
| 1381 | if (setup_ioapic_entry(mp_ioapics[apic].mp_apicid, irq, &entry, |
| 1382 | cpu_mask_to_apicid(mask), trigger, polarity, |
| 1383 | cfg->vector)) { |
| 1384 | printk("Failed to setup ioapic entry for ioapic %d, pin %d\n", |
| 1385 | mp_ioapics[apic].mp_apicid, pin); |
| 1386 | __clear_irq_vector(irq); |
| 1387 | return; |
| 1388 | } |
| 1389 | |
| 1390 | ioapic_register_intr(irq, trigger); |
Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame^] | 1391 | if (irq < NR_IRQS_LEGACY) |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 1392 | disable_8259A_irq(irq); |
| 1393 | |
| 1394 | ioapic_write_entry(apic, pin, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | static void __init setup_IO_APIC_irqs(void) |
| 1398 | { |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1399 | int apic, pin, idx, irq; |
| 1400 | int notcon = 0; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1401 | struct irq_desc *desc; |
| 1402 | int cpu = boot_cpu_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
| 1404 | apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n"); |
| 1405 | |
| 1406 | for (apic = 0; apic < nr_ioapics; apic++) { |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1407 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1409 | idx = find_irq_entry(apic, pin, mp_INT); |
| 1410 | if (idx == -1) { |
Cyrill Gorcunov | 2a554fb | 2008-09-08 19:38:06 +0400 | [diff] [blame] | 1411 | if (!notcon) { |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1412 | notcon = 1; |
Cyrill Gorcunov | 2a554fb | 2008-09-08 19:38:06 +0400 | [diff] [blame] | 1413 | apic_printk(APIC_VERBOSE, |
| 1414 | KERN_DEBUG " %d-%d", |
| 1415 | mp_ioapics[apic].mp_apicid, |
| 1416 | pin); |
| 1417 | } else |
| 1418 | apic_printk(APIC_VERBOSE, " %d-%d", |
| 1419 | mp_ioapics[apic].mp_apicid, |
| 1420 | pin); |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1421 | continue; |
| 1422 | } |
Cyrill Gorcunov | 56ffa1a | 2008-09-13 13:11:16 +0400 | [diff] [blame] | 1423 | if (notcon) { |
| 1424 | apic_printk(APIC_VERBOSE, |
| 1425 | " (apicid-pin) not connected\n"); |
| 1426 | notcon = 0; |
| 1427 | } |
Yinghai Lu | 20d225b | 2007-10-17 18:04:41 +0200 | [diff] [blame] | 1428 | |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1429 | irq = pin_2_irq(idx, apic, pin); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1430 | #ifdef CONFIG_X86_32 |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1431 | if (multi_timer_check(apic, irq)) |
| 1432 | continue; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1433 | #endif |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1434 | desc = irq_to_desc_alloc_cpu(irq, cpu); |
| 1435 | if (!desc) { |
| 1436 | printk(KERN_INFO "can not get irq_desc for %d\n", irq); |
| 1437 | continue; |
| 1438 | } |
| 1439 | add_pin_to_irq_cpu(irq, cpu, apic, pin); |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1440 | |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1441 | setup_IO_APIC_irq(apic, pin, irq, |
| 1442 | irq_trigger(idx), irq_polarity(idx)); |
| 1443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Cyrill Gorcunov | 3c2cbd2 | 2008-09-06 14:15:33 +0400 | [diff] [blame] | 1446 | if (notcon) |
| 1447 | apic_printk(APIC_VERBOSE, |
Cyrill Gorcunov | 2a554fb | 2008-09-08 19:38:06 +0400 | [diff] [blame] | 1448 | " (apicid-pin) not connected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | /* |
Maciej W. Rozycki | f7633ce | 2008-05-27 21:19:34 +0100 | [diff] [blame] | 1452 | * Set up the timer pin, possibly with the 8259A-master behind. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | */ |
Maciej W. Rozycki | f7633ce | 2008-05-27 21:19:34 +0100 | [diff] [blame] | 1454 | static void __init setup_timer_IRQ0_pin(unsigned int apic, unsigned int pin, |
| 1455 | int vector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | { |
| 1457 | struct IO_APIC_route_entry entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1459 | #ifdef CONFIG_INTR_REMAP |
| 1460 | if (intr_remapping_enabled) |
| 1461 | return; |
| 1462 | #endif |
| 1463 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1464 | memset(&entry, 0, sizeof(entry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | |
| 1466 | /* |
| 1467 | * We use logical delivery to get the timer IRQ |
| 1468 | * to the first CPU. |
| 1469 | */ |
| 1470 | entry.dest_mode = INT_DEST_MODE; |
Maciej W. Rozycki | 03be750 | 2008-05-27 21:19:45 +0100 | [diff] [blame] | 1471 | entry.mask = 1; /* mask IRQ now */ |
Yinghai Lu | d83e94a | 2008-08-19 20:50:33 -0700 | [diff] [blame] | 1472 | entry.dest = cpu_mask_to_apicid(TARGET_CPUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | entry.delivery_mode = INT_DELIVERY_MODE; |
| 1474 | entry.polarity = 0; |
| 1475 | entry.trigger = 0; |
| 1476 | entry.vector = vector; |
| 1477 | |
| 1478 | /* |
| 1479 | * The timer IRQ doesn't have to know that behind the |
Maciej W. Rozycki | f7633ce | 2008-05-27 21:19:34 +0100 | [diff] [blame] | 1480 | * scene we may have a 8259A-master in AEOI mode ... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1482 | set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | |
| 1484 | /* |
| 1485 | * Add it to the IO-APIC irq-routing table: |
| 1486 | */ |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1487 | ioapic_write_entry(apic, pin, entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1490 | |
| 1491 | __apicdebuginit(void) print_IO_APIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | { |
| 1493 | int apic, i; |
| 1494 | union IO_APIC_reg_00 reg_00; |
| 1495 | union IO_APIC_reg_01 reg_01; |
| 1496 | union IO_APIC_reg_02 reg_02; |
| 1497 | union IO_APIC_reg_03 reg_03; |
| 1498 | unsigned long flags; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 1499 | struct irq_cfg *cfg; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1500 | struct irq_desc *desc; |
Yinghai Lu | 8f09cd2 | 2008-08-19 20:50:51 -0700 | [diff] [blame] | 1501 | unsigned int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | |
| 1503 | if (apic_verbosity == APIC_QUIET) |
| 1504 | return; |
| 1505 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1506 | 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] | 1507 | for (i = 0; i < nr_ioapics; i++) |
| 1508 | printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1509 | mp_ioapics[i].mp_apicid, nr_ioapic_registers[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | |
| 1511 | /* |
| 1512 | * We are a bit conservative about what we expect. We have to |
| 1513 | * know about every hardware change ASAP. |
| 1514 | */ |
| 1515 | printk(KERN_INFO "testing the IO APIC.......................\n"); |
| 1516 | |
| 1517 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 1518 | |
| 1519 | spin_lock_irqsave(&ioapic_lock, flags); |
| 1520 | reg_00.raw = io_apic_read(apic, 0); |
| 1521 | reg_01.raw = io_apic_read(apic, 1); |
| 1522 | if (reg_01.bits.version >= 0x10) |
| 1523 | reg_02.raw = io_apic_read(apic, 2); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1524 | if (reg_01.bits.version >= 0x20) |
| 1525 | reg_03.raw = io_apic_read(apic, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 1527 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1528 | printk("\n"); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1529 | printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw); |
| 1531 | printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID); |
| 1532 | printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type); |
| 1533 | printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1535 | printk(KERN_DEBUG ".... register #01: %08X\n", *(int *)®_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | |
| 1538 | printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ); |
| 1539 | printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
| 1541 | /* |
| 1542 | * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02, |
| 1543 | * but the value of reg_02 is read as the previous read register |
| 1544 | * value, so ignore it if reg_02 == reg_01. |
| 1545 | */ |
| 1546 | if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) { |
| 1547 | printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw); |
| 1548 | printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | /* |
| 1552 | * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02 |
| 1553 | * or reg_03, but the value of reg_0[23] is read as the previous read |
| 1554 | * register value, so ignore it if reg_03 == reg_0[12]. |
| 1555 | */ |
| 1556 | if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw && |
| 1557 | reg_03.raw != reg_01.raw) { |
| 1558 | printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw); |
| 1559 | printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | printk(KERN_DEBUG ".... IRQ redirection table:\n"); |
| 1563 | |
Yinghai Lu | d83e94a | 2008-08-19 20:50:33 -0700 | [diff] [blame] | 1564 | printk(KERN_DEBUG " NR Dst Mask Trig IRR Pol" |
| 1565 | " Stat Dmod Deli Vect: \n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
| 1567 | for (i = 0; i <= reg_01.bits.entries; i++) { |
| 1568 | struct IO_APIC_route_entry entry; |
| 1569 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1570 | entry = ioapic_read_entry(apic, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1572 | printk(KERN_DEBUG " %02x %03X ", |
| 1573 | i, |
| 1574 | entry.dest |
| 1575 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | |
| 1577 | printk("%1d %1d %1d %1d %1d %1d %1d %02X\n", |
| 1578 | entry.mask, |
| 1579 | entry.trigger, |
| 1580 | entry.irr, |
| 1581 | entry.polarity, |
| 1582 | entry.delivery_status, |
| 1583 | entry.dest_mode, |
| 1584 | entry.delivery_mode, |
| 1585 | entry.vector |
| 1586 | ); |
| 1587 | } |
| 1588 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | printk(KERN_DEBUG "IRQ to pin mappings:\n"); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1590 | for_each_irq_desc(irq, desc) { |
| 1591 | struct irq_pin_list *entry; |
| 1592 | |
| 1593 | if (!desc) |
| 1594 | continue; |
| 1595 | cfg = desc->chip_data; |
| 1596 | entry = cfg->irq_2_pin; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 1597 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | continue; |
Yinghai Lu | 8f09cd2 | 2008-08-19 20:50:51 -0700 | [diff] [blame] | 1599 | printk(KERN_DEBUG "IRQ%d ", irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | for (;;) { |
| 1601 | printk("-> %d:%d", entry->apic, entry->pin); |
| 1602 | if (!entry->next) |
| 1603 | break; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 1604 | entry = entry->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | } |
| 1606 | printk("\n"); |
| 1607 | } |
| 1608 | |
| 1609 | printk(KERN_INFO ".................................... done.\n"); |
| 1610 | |
| 1611 | return; |
| 1612 | } |
| 1613 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1614 | __apicdebuginit(void) print_APIC_bitfield(int base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | { |
| 1616 | unsigned int v; |
| 1617 | int i, j; |
| 1618 | |
| 1619 | if (apic_verbosity == APIC_QUIET) |
| 1620 | return; |
| 1621 | |
| 1622 | printk(KERN_DEBUG "0123456789abcdef0123456789abcdef\n" KERN_DEBUG); |
| 1623 | for (i = 0; i < 8; i++) { |
| 1624 | v = apic_read(base + i*0x10); |
| 1625 | for (j = 0; j < 32; j++) { |
| 1626 | if (v & (1<<j)) |
| 1627 | printk("1"); |
| 1628 | else |
| 1629 | printk("0"); |
| 1630 | } |
| 1631 | printk("\n"); |
| 1632 | } |
| 1633 | } |
| 1634 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1635 | __apicdebuginit(void) print_local_APIC(void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | { |
| 1637 | unsigned int v, ver, maxlvt; |
Hiroshi Shimamoto | 7ab6af7 | 2008-07-30 17:36:48 -0700 | [diff] [blame] | 1638 | u64 icr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | |
| 1640 | if (apic_verbosity == APIC_QUIET) |
| 1641 | return; |
| 1642 | |
| 1643 | printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n", |
| 1644 | smp_processor_id(), hard_smp_processor_id()); |
Andreas Herrmann | 6682311 | 2008-06-05 16:35:10 +0200 | [diff] [blame] | 1645 | v = apic_read(APIC_ID); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1646 | printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, read_apic_id()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | v = apic_read(APIC_LVR); |
| 1648 | printk(KERN_INFO "... APIC VERSION: %08x\n", v); |
| 1649 | ver = GET_APIC_VERSION(v); |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 1650 | maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | |
| 1652 | v = apic_read(APIC_TASKPRI); |
| 1653 | printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK); |
| 1654 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1655 | if (APIC_INTEGRATED(ver)) { /* !82489DX */ |
Yinghai Lu | a11b5ab | 2008-09-03 16:58:31 -0700 | [diff] [blame] | 1656 | if (!APIC_XAPIC(ver)) { |
| 1657 | v = apic_read(APIC_ARBPRI); |
| 1658 | printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v, |
| 1659 | v & APIC_ARBPRI_MASK); |
| 1660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | v = apic_read(APIC_PROCPRI); |
| 1662 | printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v); |
| 1663 | } |
| 1664 | |
Yinghai Lu | a11b5ab | 2008-09-03 16:58:31 -0700 | [diff] [blame] | 1665 | /* |
| 1666 | * Remote read supported only in the 82489DX and local APIC for |
| 1667 | * Pentium processors. |
| 1668 | */ |
| 1669 | if (!APIC_INTEGRATED(ver) || maxlvt == 3) { |
| 1670 | v = apic_read(APIC_RRR); |
| 1671 | printk(KERN_DEBUG "... APIC RRR: %08x\n", v); |
| 1672 | } |
| 1673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | v = apic_read(APIC_LDR); |
| 1675 | printk(KERN_DEBUG "... APIC LDR: %08x\n", v); |
Yinghai Lu | a11b5ab | 2008-09-03 16:58:31 -0700 | [diff] [blame] | 1676 | if (!x2apic_enabled()) { |
| 1677 | v = apic_read(APIC_DFR); |
| 1678 | printk(KERN_DEBUG "... APIC DFR: %08x\n", v); |
| 1679 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | v = apic_read(APIC_SPIV); |
| 1681 | printk(KERN_DEBUG "... APIC SPIV: %08x\n", v); |
| 1682 | |
| 1683 | printk(KERN_DEBUG "... APIC ISR field:\n"); |
| 1684 | print_APIC_bitfield(APIC_ISR); |
| 1685 | printk(KERN_DEBUG "... APIC TMR field:\n"); |
| 1686 | print_APIC_bitfield(APIC_TMR); |
| 1687 | printk(KERN_DEBUG "... APIC IRR field:\n"); |
| 1688 | print_APIC_bitfield(APIC_IRR); |
| 1689 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1690 | if (APIC_INTEGRATED(ver)) { /* !82489DX */ |
| 1691 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | apic_write(APIC_ESR, 0); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | v = apic_read(APIC_ESR); |
| 1695 | printk(KERN_DEBUG "... APIC ESR: %08x\n", v); |
| 1696 | } |
| 1697 | |
Hiroshi Shimamoto | 7ab6af7 | 2008-07-30 17:36:48 -0700 | [diff] [blame] | 1698 | icr = apic_icr_read(); |
Ingo Molnar | 0c425ce | 2008-08-18 13:04:26 +0200 | [diff] [blame] | 1699 | printk(KERN_DEBUG "... APIC ICR: %08x\n", (u32)icr); |
| 1700 | printk(KERN_DEBUG "... APIC ICR2: %08x\n", (u32)(icr >> 32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
| 1702 | v = apic_read(APIC_LVTT); |
| 1703 | printk(KERN_DEBUG "... APIC LVTT: %08x\n", v); |
| 1704 | |
| 1705 | if (maxlvt > 3) { /* PC is LVT#4. */ |
| 1706 | v = apic_read(APIC_LVTPC); |
| 1707 | printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v); |
| 1708 | } |
| 1709 | v = apic_read(APIC_LVT0); |
| 1710 | printk(KERN_DEBUG "... APIC LVT0: %08x\n", v); |
| 1711 | v = apic_read(APIC_LVT1); |
| 1712 | printk(KERN_DEBUG "... APIC LVT1: %08x\n", v); |
| 1713 | |
| 1714 | if (maxlvt > 2) { /* ERR is LVT#3. */ |
| 1715 | v = apic_read(APIC_LVTERR); |
| 1716 | printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v); |
| 1717 | } |
| 1718 | |
| 1719 | v = apic_read(APIC_TMICT); |
| 1720 | printk(KERN_DEBUG "... APIC TMICT: %08x\n", v); |
| 1721 | v = apic_read(APIC_TMCCT); |
| 1722 | printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v); |
| 1723 | v = apic_read(APIC_TDCR); |
| 1724 | printk(KERN_DEBUG "... APIC TDCR: %08x\n", v); |
| 1725 | printk("\n"); |
| 1726 | } |
| 1727 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1728 | __apicdebuginit(void) print_all_local_APICs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | { |
Yinghai Lu | ffd5aae | 2008-08-19 20:50:50 -0700 | [diff] [blame] | 1730 | int cpu; |
| 1731 | |
| 1732 | preempt_disable(); |
| 1733 | for_each_online_cpu(cpu) |
| 1734 | smp_call_function_single(cpu, print_local_APIC, NULL, 1); |
| 1735 | preempt_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
| 1737 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1738 | __apicdebuginit(void) print_PIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | unsigned int v; |
| 1741 | unsigned long flags; |
| 1742 | |
| 1743 | if (apic_verbosity == APIC_QUIET) |
| 1744 | return; |
| 1745 | |
| 1746 | printk(KERN_DEBUG "\nprinting PIC contents\n"); |
| 1747 | |
| 1748 | spin_lock_irqsave(&i8259A_lock, flags); |
| 1749 | |
| 1750 | v = inb(0xa1) << 8 | inb(0x21); |
| 1751 | printk(KERN_DEBUG "... PIC IMR: %04x\n", v); |
| 1752 | |
| 1753 | v = inb(0xa0) << 8 | inb(0x20); |
| 1754 | printk(KERN_DEBUG "... PIC IRR: %04x\n", v); |
| 1755 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1756 | outb(0x0b,0xa0); |
| 1757 | outb(0x0b,0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | v = inb(0xa0) << 8 | inb(0x20); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1759 | outb(0x0a,0xa0); |
| 1760 | outb(0x0a,0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | |
| 1762 | spin_unlock_irqrestore(&i8259A_lock, flags); |
| 1763 | |
| 1764 | printk(KERN_DEBUG "... PIC ISR: %04x\n", v); |
| 1765 | |
| 1766 | v = inb(0x4d1) << 8 | inb(0x4d0); |
| 1767 | printk(KERN_DEBUG "... PIC ELCR: %04x\n", v); |
| 1768 | } |
| 1769 | |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 1770 | __apicdebuginit(int) print_all_ICs(void) |
| 1771 | { |
| 1772 | print_PIC(); |
| 1773 | print_all_local_APICs(); |
| 1774 | print_IO_APIC(); |
| 1775 | |
| 1776 | return 0; |
| 1777 | } |
| 1778 | |
| 1779 | fs_initcall(print_all_ICs); |
| 1780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 1782 | /* Where if anywhere is the i8259 connect in external int mode */ |
| 1783 | static struct { int pin, apic; } ioapic_i8259 = { -1, -1 }; |
| 1784 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1785 | void __init enable_IO_APIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | { |
| 1787 | union IO_APIC_reg_01 reg_01; |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1788 | int i8259_apic, i8259_pin; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1789 | int apic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | unsigned long flags; |
| 1791 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1792 | #ifdef CONFIG_X86_32 |
| 1793 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | if (!pirqs_enabled) |
| 1795 | for (i = 0; i < MAX_PIRQS; i++) |
| 1796 | pirq_entries[i] = -1; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1797 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | |
| 1799 | /* |
| 1800 | * The number of IO-APIC IRQ registers (== #pins): |
| 1801 | */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1802 | for (apic = 0; apic < nr_ioapics; apic++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | spin_lock_irqsave(&ioapic_lock, flags); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1804 | reg_01.raw = io_apic_read(apic, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1806 | nr_ioapic_registers[apic] = reg_01.bits.entries+1; |
| 1807 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1808 | for(apic = 0; apic < nr_ioapics; apic++) { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1809 | int pin; |
| 1810 | /* See if any of the pins is in ExtINT mode */ |
Eric W. Biederman | 1008fdd | 2006-01-11 22:46:06 +0100 | [diff] [blame] | 1811 | for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1812 | struct IO_APIC_route_entry entry; |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1813 | entry = ioapic_read_entry(apic, pin); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1814 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1815 | /* If the interrupt line is enabled and in ExtInt mode |
| 1816 | * I have found the pin where the i8259 is connected. |
| 1817 | */ |
| 1818 | if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) { |
| 1819 | ioapic_i8259.apic = apic; |
| 1820 | ioapic_i8259.pin = pin; |
| 1821 | goto found_i8259; |
| 1822 | } |
| 1823 | } |
| 1824 | } |
| 1825 | found_i8259: |
| 1826 | /* Look to see what if the MP table has reported the ExtINT */ |
| 1827 | /* If we could not find the appropriate pin by looking at the ioapic |
| 1828 | * the i8259 probably is not connected the ioapic but give the |
| 1829 | * mptable a chance anyway. |
| 1830 | */ |
| 1831 | i8259_pin = find_isa_irq_pin(0, mp_ExtINT); |
| 1832 | i8259_apic = find_isa_irq_apic(0, mp_ExtINT); |
| 1833 | /* Trust the MP table if nothing is setup in the hardware */ |
| 1834 | if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) { |
| 1835 | printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n"); |
| 1836 | ioapic_i8259.pin = i8259_pin; |
| 1837 | ioapic_i8259.apic = i8259_apic; |
| 1838 | } |
| 1839 | /* Complain if the MP table and the hardware disagree */ |
| 1840 | if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) && |
| 1841 | (i8259_pin >= 0) && (ioapic_i8259.pin >= 0)) |
| 1842 | { |
| 1843 | printk(KERN_WARNING "ExtINT in hardware and MP table differ\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | /* |
| 1847 | * Do not trust the IO-APIC being empty at bootup |
| 1848 | */ |
| 1849 | clear_IO_APIC(); |
| 1850 | } |
| 1851 | |
| 1852 | /* |
| 1853 | * Not an __init, needed by the reboot code |
| 1854 | */ |
| 1855 | void disable_IO_APIC(void) |
| 1856 | { |
| 1857 | /* |
| 1858 | * Clear the IO-APIC before rebooting: |
| 1859 | */ |
| 1860 | clear_IO_APIC(); |
| 1861 | |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1862 | /* |
Karsten Wiese | 0b968d2 | 2005-09-09 12:59:04 +0200 | [diff] [blame] | 1863 | * If the i8259 is routed through an IOAPIC |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1864 | * Put that IOAPIC in virtual wire mode |
Karsten Wiese | 0b968d2 | 2005-09-09 12:59:04 +0200 | [diff] [blame] | 1865 | * so legacy interrupts can be delivered. |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1866 | */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1867 | if (ioapic_i8259.pin != -1) { |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1868 | struct IO_APIC_route_entry entry; |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1869 | |
| 1870 | memset(&entry, 0, sizeof(entry)); |
| 1871 | entry.mask = 0; /* Enabled */ |
| 1872 | entry.trigger = 0; /* Edge */ |
| 1873 | entry.irr = 0; |
| 1874 | entry.polarity = 0; /* High */ |
| 1875 | entry.delivery_status = 0; |
| 1876 | entry.dest_mode = 0; /* Physical */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1877 | entry.delivery_mode = dest_ExtINT; /* ExtInt */ |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1878 | entry.vector = 0; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1879 | entry.dest = read_apic_id(); |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1880 | |
| 1881 | /* |
| 1882 | * Add it to the IO-APIC irq-routing table: |
| 1883 | */ |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1884 | ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry); |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1885 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1886 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1887 | disconnect_bsp_APIC(ioapic_i8259.pin != -1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1890 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | /* |
| 1892 | * function to set the IO-APIC physical IDs based on the |
| 1893 | * values stored in the MPC table. |
| 1894 | * |
| 1895 | * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999 |
| 1896 | */ |
| 1897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | static void __init setup_ioapic_ids_from_mpc(void) |
| 1899 | { |
| 1900 | union IO_APIC_reg_00 reg_00; |
| 1901 | physid_mask_t phys_id_present_map; |
| 1902 | int apic; |
| 1903 | int i; |
| 1904 | unsigned char old_id; |
| 1905 | unsigned long flags; |
| 1906 | |
Yinghai Lu | a4dbc34 | 2008-07-25 02:14:28 -0700 | [diff] [blame] | 1907 | if (x86_quirks->setup_ioapic_ids && x86_quirks->setup_ioapic_ids()) |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 1908 | return; |
Yinghai Lu | d49c428 | 2008-06-08 18:31:54 -0700 | [diff] [blame] | 1909 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | /* |
Natalie Protasevich | ca05fea | 2005-06-23 00:08:22 -0700 | [diff] [blame] | 1911 | * Don't check I/O APIC IDs for xAPIC systems. They have |
| 1912 | * no meaning without the serial APIC bus. |
| 1913 | */ |
Shaohua Li | 7c5c1e4 | 2006-03-23 02:59:53 -0800 | [diff] [blame] | 1914 | if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) |
| 1915 | || APIC_XAPIC(apic_version[boot_cpu_physical_apicid])) |
Natalie Protasevich | ca05fea | 2005-06-23 00:08:22 -0700 | [diff] [blame] | 1916 | return; |
| 1917 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | * This is broken; anything with a real cpu count has to |
| 1919 | * circumvent this idiocy regardless. |
| 1920 | */ |
| 1921 | phys_id_present_map = ioapic_phys_id_map(phys_cpu_present_map); |
| 1922 | |
| 1923 | /* |
| 1924 | * Set the IOAPIC ID to the value stored in the MPC table. |
| 1925 | */ |
| 1926 | for (apic = 0; apic < nr_ioapics; apic++) { |
| 1927 | |
| 1928 | /* Read the register 0 value */ |
| 1929 | spin_lock_irqsave(&ioapic_lock, flags); |
| 1930 | reg_00.raw = io_apic_read(apic, 0); |
| 1931 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1932 | |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1933 | old_id = mp_ioapics[apic].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1935 | if (mp_ioapics[apic].mp_apicid >= get_physical_broadcast()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | 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] | 1937 | apic, mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n", |
| 1939 | reg_00.bits.ID); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1940 | mp_ioapics[apic].mp_apicid = reg_00.bits.ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | } |
| 1942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | /* |
| 1944 | * Sanity check, is the ID really free? Every APIC in a |
| 1945 | * system must have a unique ID or we get lots of nice |
| 1946 | * 'stuck on smp_invalidate_needed IPI wait' messages. |
| 1947 | */ |
| 1948 | if (check_apicid_used(phys_id_present_map, |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1949 | mp_ioapics[apic].mp_apicid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | 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] | 1951 | apic, mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | for (i = 0; i < get_physical_broadcast(); i++) |
| 1953 | if (!physid_isset(i, phys_id_present_map)) |
| 1954 | break; |
| 1955 | if (i >= get_physical_broadcast()) |
| 1956 | panic("Max APIC ID exceeded!\n"); |
| 1957 | printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n", |
| 1958 | i); |
| 1959 | physid_set(i, phys_id_present_map); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1960 | mp_ioapics[apic].mp_apicid = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | } else { |
| 1962 | physid_mask_t tmp; |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1963 | tmp = apicid_to_cpu_present(mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | apic_printk(APIC_VERBOSE, "Setting %d in the " |
| 1965 | "phys_id_present_map\n", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1966 | mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | physids_or(phys_id_present_map, phys_id_present_map, tmp); |
| 1968 | } |
| 1969 | |
| 1970 | |
| 1971 | /* |
| 1972 | * We need to adjust the IRQ routing table |
| 1973 | * if the ID changed. |
| 1974 | */ |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1975 | if (old_id != mp_ioapics[apic].mp_apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | for (i = 0; i < mp_irq_entries; i++) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 1977 | if (mp_irqs[i].mp_dstapic == old_id) |
| 1978 | mp_irqs[i].mp_dstapic |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1979 | = mp_ioapics[apic].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
| 1981 | /* |
| 1982 | * Read the right value from the MPC table and |
| 1983 | * write it into the ID register. |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1984 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 1986 | "...changing IO-APIC physical APIC ID to %d ...", |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1987 | mp_ioapics[apic].mp_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 1989 | reg_00.bits.ID = mp_ioapics[apic].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | spin_lock_irqsave(&ioapic_lock, flags); |
Yinghai Lu | a2d332f | 2008-08-21 12:56:32 -0700 | [diff] [blame] | 1991 | io_apic_write(apic, 0, reg_00.raw); |
| 1992 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
| 1994 | /* |
| 1995 | * Sanity check |
| 1996 | */ |
| 1997 | spin_lock_irqsave(&ioapic_lock, flags); |
| 1998 | reg_00.raw = io_apic_read(apic, 0); |
| 1999 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 2000 | if (reg_00.bits.ID != mp_ioapics[apic].mp_apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | printk("could not set ID!\n"); |
| 2002 | else |
| 2003 | apic_printk(APIC_VERBOSE, " ok.\n"); |
| 2004 | } |
| 2005 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2006 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 2008 | int no_timer_check __initdata; |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 2009 | |
| 2010 | static int __init notimercheck(char *s) |
| 2011 | { |
| 2012 | no_timer_check = 1; |
| 2013 | return 1; |
| 2014 | } |
| 2015 | __setup("no_timer_check", notimercheck); |
| 2016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | /* |
| 2018 | * There is a nasty bug in some older SMP boards, their mptable lies |
| 2019 | * about the timer IRQ. We do the following to work around the situation: |
| 2020 | * |
| 2021 | * - timer IRQ defaults to IO-APIC IRQ |
| 2022 | * - if this function detects that timer IRQs are defunct, then we fall |
| 2023 | * back to ISA timer IRQs |
| 2024 | */ |
Adrian Bunk | f0a7a5c | 2007-07-21 17:10:29 +0200 | [diff] [blame] | 2025 | static int __init timer_irq_works(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | { |
| 2027 | unsigned long t1 = jiffies; |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2028 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 2030 | if (no_timer_check) |
| 2031 | return 1; |
| 2032 | |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2033 | local_save_flags(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | local_irq_enable(); |
| 2035 | /* Let ten ticks pass... */ |
| 2036 | mdelay((10 * 1000) / HZ); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2037 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | |
| 2039 | /* |
| 2040 | * Expect a few ticks at least, to be sure some possible |
| 2041 | * glue logic does not lock up after one or two first |
| 2042 | * ticks in a non-ExtINT mode. Also the local APIC |
| 2043 | * might have cached one ExtINT interrupt. Finally, at |
| 2044 | * least one tick may be lost due to delays. |
| 2045 | */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2046 | |
| 2047 | /* jiffies wrap? */ |
Julia Lawall | 1d16b53 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 2048 | if (time_after(jiffies, t1 + 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | return 0; |
| 2051 | } |
| 2052 | |
| 2053 | /* |
| 2054 | * In the SMP+IOAPIC case it might happen that there are an unspecified |
| 2055 | * number of pending IRQ events unhandled. These cases are very rare, |
| 2056 | * so we 'resend' these IRQs via IPIs, to the same CPU. It's much |
| 2057 | * better to do it this way as thus we do not have to be aware of |
| 2058 | * 'pending' interrupts in the IRQ path, except at this point. |
| 2059 | */ |
| 2060 | /* |
| 2061 | * Edge triggered needs to resend any interrupt |
| 2062 | * that was delayed but this is now handled in the device |
| 2063 | * independent code. |
| 2064 | */ |
| 2065 | |
| 2066 | /* |
| 2067 | * Starting up a edge-triggered IO-APIC interrupt is |
| 2068 | * nasty - we need to make sure that we get the edge. |
| 2069 | * If it is already asserted for some reason, we need |
| 2070 | * return 1 to indicate that is was pending. |
| 2071 | * |
| 2072 | * This is not complete - we should be able to fake |
| 2073 | * an edge even if it isn't on the 8259A... |
| 2074 | */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2075 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 2076 | static unsigned int startup_ioapic_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | { |
| 2078 | int was_pending = 0; |
| 2079 | unsigned long flags; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2080 | struct irq_cfg *cfg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | |
| 2082 | spin_lock_irqsave(&ioapic_lock, flags); |
Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame^] | 2083 | if (irq < NR_IRQS_LEGACY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | disable_8259A_irq(irq); |
| 2085 | if (i8259A_irq_pending(irq)) |
| 2086 | was_pending = 1; |
| 2087 | } |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2088 | cfg = irq_cfg(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | __unmask_IO_APIC_irq(irq); |
| 2090 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 2091 | |
| 2092 | return was_pending; |
| 2093 | } |
| 2094 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2095 | #ifdef CONFIG_X86_64 |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2096 | static int ioapic_retrigger_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2098 | |
| 2099 | struct irq_cfg *cfg = irq_cfg(irq); |
| 2100 | unsigned long flags; |
| 2101 | |
| 2102 | spin_lock_irqsave(&vector_lock, flags); |
| 2103 | send_IPI_mask(cpumask_of_cpu(first_cpu(cfg->domain)), cfg->vector); |
| 2104 | spin_unlock_irqrestore(&vector_lock, flags); |
Ingo Molnar | c0ad90a | 2006-06-29 02:24:44 -0700 | [diff] [blame] | 2105 | |
| 2106 | return 1; |
| 2107 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2108 | #else |
| 2109 | static int ioapic_retrigger_irq(unsigned int irq) |
| 2110 | { |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2111 | send_IPI_self(irq_cfg(irq)->vector); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2112 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2113 | return 1; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2114 | } |
| 2115 | #endif |
| 2116 | |
| 2117 | /* |
| 2118 | * Level and edge triggered IO-APIC interrupts need different handling, |
| 2119 | * so we use two separate IRQ descriptors. Edge triggered IRQs can be |
| 2120 | * handled with the level-triggered descriptor, but that one has slightly |
| 2121 | * more overhead. Level-triggered interrupts cannot be handled with the |
| 2122 | * edge-triggered handler, without risking IRQ storms and other ugly |
| 2123 | * races. |
| 2124 | */ |
Ingo Molnar | c0ad90a | 2006-06-29 02:24:44 -0700 | [diff] [blame] | 2125 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2126 | #ifdef CONFIG_SMP |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2127 | |
| 2128 | #ifdef CONFIG_INTR_REMAP |
| 2129 | static void ir_irq_migration(struct work_struct *work); |
| 2130 | |
| 2131 | static DECLARE_DELAYED_WORK(ir_migration_work, ir_irq_migration); |
| 2132 | |
| 2133 | /* |
| 2134 | * Migrate the IO-APIC irq in the presence of intr-remapping. |
| 2135 | * |
| 2136 | * For edge triggered, irq migration is a simple atomic update(of vector |
| 2137 | * and cpu destination) of IRTE and flush the hardware cache. |
| 2138 | * |
| 2139 | * For level triggered, we need to modify the io-apic RTE aswell with the update |
| 2140 | * vector information, along with modifying IRTE with vector and destination. |
| 2141 | * So irq migration for level triggered is little bit more complex compared to |
| 2142 | * edge triggered migration. But the good news is, we use the same algorithm |
| 2143 | * for level triggered migration as we have today, only difference being, |
| 2144 | * we now initiate the irq migration from process context instead of the |
| 2145 | * interrupt context. |
| 2146 | * |
| 2147 | * In future, when we do a directed EOI (combined with cpu EOI broadcast |
| 2148 | * suppression) to the IO-APIC, level triggered irq migration will also be |
| 2149 | * as simple as edge triggered migration and we can do the irq migration |
| 2150 | * with a simple atomic update to IO-APIC RTE. |
| 2151 | */ |
| 2152 | static void migrate_ioapic_irq(int irq, cpumask_t mask) |
| 2153 | { |
| 2154 | struct irq_cfg *cfg; |
| 2155 | struct irq_desc *desc; |
| 2156 | cpumask_t tmp, cleanup_mask; |
| 2157 | struct irte irte; |
| 2158 | int modify_ioapic_rte; |
| 2159 | unsigned int dest; |
| 2160 | unsigned long flags; |
| 2161 | |
| 2162 | cpus_and(tmp, mask, cpu_online_map); |
| 2163 | if (cpus_empty(tmp)) |
| 2164 | return; |
| 2165 | |
| 2166 | if (get_irte(irq, &irte)) |
| 2167 | return; |
| 2168 | |
| 2169 | if (assign_irq_vector(irq, mask)) |
| 2170 | return; |
| 2171 | |
| 2172 | cfg = irq_cfg(irq); |
| 2173 | cpus_and(tmp, cfg->domain, mask); |
| 2174 | dest = cpu_mask_to_apicid(tmp); |
| 2175 | |
| 2176 | desc = irq_to_desc(irq); |
| 2177 | modify_ioapic_rte = desc->status & IRQ_LEVEL; |
| 2178 | if (modify_ioapic_rte) { |
| 2179 | spin_lock_irqsave(&ioapic_lock, flags); |
| 2180 | __target_IO_APIC_irq(irq, dest, cfg->vector); |
| 2181 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 2182 | } |
| 2183 | |
| 2184 | irte.vector = cfg->vector; |
| 2185 | irte.dest_id = IRTE_DEST(dest); |
| 2186 | |
| 2187 | /* |
| 2188 | * Modified the IRTE and flushes the Interrupt entry cache. |
| 2189 | */ |
| 2190 | modify_irte(irq, &irte); |
| 2191 | |
| 2192 | if (cfg->move_in_progress) { |
| 2193 | cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map); |
| 2194 | cfg->move_cleanup_count = cpus_weight(cleanup_mask); |
| 2195 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); |
| 2196 | cfg->move_in_progress = 0; |
| 2197 | } |
| 2198 | |
| 2199 | desc->affinity = mask; |
| 2200 | } |
| 2201 | |
| 2202 | static int migrate_irq_remapped_level(int irq) |
| 2203 | { |
| 2204 | int ret = -1; |
| 2205 | struct irq_desc *desc = irq_to_desc(irq); |
| 2206 | |
| 2207 | mask_IO_APIC_irq(irq); |
| 2208 | |
| 2209 | if (io_apic_level_ack_pending(irq)) { |
| 2210 | /* |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2211 | * Interrupt in progress. Migrating irq now will change the |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2212 | * vector information in the IO-APIC RTE and that will confuse |
| 2213 | * the EOI broadcast performed by cpu. |
| 2214 | * So, delay the irq migration to the next instance. |
| 2215 | */ |
| 2216 | schedule_delayed_work(&ir_migration_work, 1); |
| 2217 | goto unmask; |
| 2218 | } |
| 2219 | |
| 2220 | /* everthing is clear. we have right of way */ |
| 2221 | migrate_ioapic_irq(irq, desc->pending_mask); |
| 2222 | |
| 2223 | ret = 0; |
| 2224 | desc->status &= ~IRQ_MOVE_PENDING; |
| 2225 | cpus_clear(desc->pending_mask); |
| 2226 | |
| 2227 | unmask: |
| 2228 | unmask_IO_APIC_irq(irq); |
| 2229 | return ret; |
| 2230 | } |
| 2231 | |
| 2232 | static void ir_irq_migration(struct work_struct *work) |
| 2233 | { |
| 2234 | unsigned int irq; |
| 2235 | struct irq_desc *desc; |
| 2236 | |
| 2237 | for_each_irq_desc(irq, desc) { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2238 | if (!desc) |
| 2239 | continue; |
| 2240 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2241 | if (desc->status & IRQ_MOVE_PENDING) { |
| 2242 | unsigned long flags; |
| 2243 | |
| 2244 | spin_lock_irqsave(&desc->lock, flags); |
| 2245 | if (!desc->chip->set_affinity || |
| 2246 | !(desc->status & IRQ_MOVE_PENDING)) { |
| 2247 | desc->status &= ~IRQ_MOVE_PENDING; |
| 2248 | spin_unlock_irqrestore(&desc->lock, flags); |
| 2249 | continue; |
| 2250 | } |
| 2251 | |
| 2252 | desc->chip->set_affinity(irq, desc->pending_mask); |
| 2253 | spin_unlock_irqrestore(&desc->lock, flags); |
| 2254 | } |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | /* |
| 2259 | * Migrates the IRQ destination in the process context. |
| 2260 | */ |
| 2261 | static void set_ir_ioapic_affinity_irq(unsigned int irq, cpumask_t mask) |
| 2262 | { |
| 2263 | struct irq_desc *desc = irq_to_desc(irq); |
| 2264 | |
| 2265 | if (desc->status & IRQ_LEVEL) { |
| 2266 | desc->status |= IRQ_MOVE_PENDING; |
| 2267 | desc->pending_mask = mask; |
| 2268 | migrate_irq_remapped_level(irq); |
| 2269 | return; |
| 2270 | } |
| 2271 | |
| 2272 | migrate_ioapic_irq(irq, mask); |
| 2273 | } |
| 2274 | #endif |
| 2275 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2276 | asmlinkage void smp_irq_move_cleanup_interrupt(void) |
| 2277 | { |
| 2278 | unsigned vector, me; |
| 2279 | ack_APIC_irq(); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2280 | #ifdef CONFIG_X86_64 |
| 2281 | exit_idle(); |
| 2282 | #endif |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2283 | irq_enter(); |
| 2284 | |
| 2285 | me = smp_processor_id(); |
| 2286 | for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) { |
| 2287 | unsigned int irq; |
| 2288 | struct irq_desc *desc; |
| 2289 | struct irq_cfg *cfg; |
| 2290 | irq = __get_cpu_var(vector_irq)[vector]; |
| 2291 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2292 | if (irq == -1) |
| 2293 | continue; |
| 2294 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2295 | desc = irq_to_desc(irq); |
| 2296 | if (!desc) |
| 2297 | continue; |
| 2298 | |
| 2299 | cfg = irq_cfg(irq); |
| 2300 | spin_lock(&desc->lock); |
| 2301 | if (!cfg->move_cleanup_count) |
| 2302 | goto unlock; |
| 2303 | |
| 2304 | if ((vector == cfg->vector) && cpu_isset(me, cfg->domain)) |
| 2305 | goto unlock; |
| 2306 | |
| 2307 | __get_cpu_var(vector_irq)[vector] = -1; |
| 2308 | cfg->move_cleanup_count--; |
| 2309 | unlock: |
| 2310 | spin_unlock(&desc->lock); |
| 2311 | } |
| 2312 | |
| 2313 | irq_exit(); |
| 2314 | } |
| 2315 | |
| 2316 | static void irq_complete_move(unsigned int irq) |
| 2317 | { |
| 2318 | struct irq_cfg *cfg = irq_cfg(irq); |
| 2319 | unsigned vector, me; |
| 2320 | |
| 2321 | if (likely(!cfg->move_in_progress)) |
| 2322 | return; |
| 2323 | |
| 2324 | vector = ~get_irq_regs()->orig_ax; |
| 2325 | me = smp_processor_id(); |
| 2326 | if ((vector == cfg->vector) && cpu_isset(me, cfg->domain)) { |
| 2327 | cpumask_t cleanup_mask; |
| 2328 | |
| 2329 | cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map); |
| 2330 | cfg->move_cleanup_count = cpus_weight(cleanup_mask); |
| 2331 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); |
| 2332 | cfg->move_in_progress = 0; |
| 2333 | } |
| 2334 | } |
| 2335 | #else |
| 2336 | static inline void irq_complete_move(unsigned int irq) {} |
| 2337 | #endif |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2338 | #ifdef CONFIG_INTR_REMAP |
| 2339 | static void ack_x2apic_level(unsigned int irq) |
| 2340 | { |
| 2341 | ack_x2APIC_irq(); |
| 2342 | } |
| 2343 | |
| 2344 | static void ack_x2apic_edge(unsigned int irq) |
| 2345 | { |
| 2346 | ack_x2APIC_irq(); |
| 2347 | } |
| 2348 | #endif |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2349 | |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 2350 | static void ack_apic_edge(unsigned int irq) |
| 2351 | { |
| 2352 | irq_complete_move(irq); |
| 2353 | move_native_irq(irq); |
| 2354 | ack_APIC_irq(); |
| 2355 | } |
| 2356 | |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 2357 | atomic_t irq_mis_count; |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 2358 | |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2359 | static void ack_apic_level(unsigned int irq) |
| 2360 | { |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 2361 | #ifdef CONFIG_X86_32 |
| 2362 | unsigned long v; |
| 2363 | int i; |
| 2364 | #endif |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2365 | int do_unmask_irq = 0; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2366 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2367 | irq_complete_move(irq); |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2368 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2369 | /* If we are moving the irq we need to mask it */ |
| 2370 | if (unlikely(irq_to_desc(irq)->status & IRQ_MOVE_PENDING)) { |
| 2371 | do_unmask_irq = 1; |
| 2372 | mask_IO_APIC_irq(irq); |
| 2373 | } |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2374 | #endif |
| 2375 | |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 2376 | #ifdef CONFIG_X86_32 |
| 2377 | /* |
| 2378 | * It appears there is an erratum which affects at least version 0x11 |
| 2379 | * of I/O APIC (that's the 82093AA and cores integrated into various |
| 2380 | * chipsets). Under certain conditions a level-triggered interrupt is |
| 2381 | * erroneously delivered as edge-triggered one but the respective IRR |
| 2382 | * bit gets set nevertheless. As a result the I/O unit expects an EOI |
| 2383 | * message but it will never arrive and further interrupts are blocked |
| 2384 | * from the source. The exact reason is so far unknown, but the |
| 2385 | * phenomenon was observed when two consecutive interrupt requests |
| 2386 | * from a given source get delivered to the same CPU and the source is |
| 2387 | * temporarily disabled in between. |
| 2388 | * |
| 2389 | * A workaround is to simulate an EOI message manually. We achieve it |
| 2390 | * by setting the trigger mode to edge and then to level when the edge |
| 2391 | * trigger mode gets detected in the TMR of a local APIC for a |
| 2392 | * level-triggered interrupt. We mask the source for the time of the |
| 2393 | * operation to prevent an edge-triggered interrupt escaping meanwhile. |
| 2394 | * The idea is from Manfred Spraul. --macro |
| 2395 | */ |
| 2396 | i = irq_cfg(irq)->vector; |
| 2397 | |
| 2398 | v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1)); |
| 2399 | #endif |
| 2400 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2401 | /* |
| 2402 | * We must acknowledge the irq before we move it or the acknowledge will |
| 2403 | * not propagate properly. |
| 2404 | */ |
| 2405 | ack_APIC_irq(); |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2406 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2407 | /* Now we can move and renable the irq */ |
| 2408 | if (unlikely(do_unmask_irq)) { |
| 2409 | /* Only migrate the irq if the ack has been received. |
| 2410 | * |
| 2411 | * On rare occasions the broadcast level triggered ack gets |
| 2412 | * delayed going to ioapics, and if we reprogram the |
| 2413 | * vector while Remote IRR is still set the irq will never |
| 2414 | * fire again. |
| 2415 | * |
| 2416 | * To prevent this scenario we read the Remote IRR bit |
| 2417 | * of the ioapic. This has two effects. |
| 2418 | * - On any sane system the read of the ioapic will |
| 2419 | * flush writes (and acks) going to the ioapic from |
| 2420 | * this cpu. |
| 2421 | * - We get to see if the ACK has actually been delivered. |
| 2422 | * |
| 2423 | * Based on failed experiments of reprogramming the |
| 2424 | * ioapic entry from outside of irq context starting |
| 2425 | * with masking the ioapic entry and then polling until |
| 2426 | * Remote IRR was clear before reprogramming the |
| 2427 | * ioapic I don't trust the Remote IRR bit to be |
| 2428 | * completey accurate. |
| 2429 | * |
| 2430 | * However there appears to be no other way to plug |
| 2431 | * this race, so if the Remote IRR bit is not |
| 2432 | * accurate and is causing problems then it is a hardware bug |
| 2433 | * and you can go talk to the chipset vendor about it. |
| 2434 | */ |
| 2435 | if (!io_apic_level_ack_pending(irq)) |
| 2436 | move_masked_irq(irq); |
| 2437 | unmask_IO_APIC_irq(irq); |
| 2438 | } |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 2439 | |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 2440 | #ifdef CONFIG_X86_32 |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 2441 | if (!(v & (1 << (i & 0x1f)))) { |
| 2442 | atomic_inc(&irq_mis_count); |
| 2443 | spin_lock(&ioapic_lock); |
| 2444 | __mask_and_edge_IO_APIC_irq(irq); |
| 2445 | __unmask_and_level_IO_APIC_irq(irq); |
| 2446 | spin_unlock(&ioapic_lock); |
| 2447 | } |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2448 | #endif |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 2449 | } |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 2450 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 2451 | static struct irq_chip ioapic_chip __read_mostly = { |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2452 | .name = "IO-APIC", |
| 2453 | .startup = startup_ioapic_irq, |
| 2454 | .mask = mask_IO_APIC_irq, |
| 2455 | .unmask = unmask_IO_APIC_irq, |
| 2456 | .ack = ack_apic_edge, |
| 2457 | .eoi = ack_apic_level, |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 2458 | #ifdef CONFIG_SMP |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2459 | .set_affinity = set_ioapic_affinity_irq, |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 2460 | #endif |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2461 | .retrigger = ioapic_retrigger_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | }; |
| 2463 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2464 | #ifdef CONFIG_INTR_REMAP |
| 2465 | static struct irq_chip ir_ioapic_chip __read_mostly = { |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2466 | .name = "IR-IO-APIC", |
| 2467 | .startup = startup_ioapic_irq, |
| 2468 | .mask = mask_IO_APIC_irq, |
| 2469 | .unmask = unmask_IO_APIC_irq, |
| 2470 | .ack = ack_x2apic_edge, |
| 2471 | .eoi = ack_x2apic_level, |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2472 | #ifdef CONFIG_SMP |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2473 | .set_affinity = set_ir_ioapic_affinity_irq, |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2474 | #endif |
| 2475 | .retrigger = ioapic_retrigger_irq, |
| 2476 | }; |
| 2477 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | |
| 2479 | static inline void init_IO_APIC_traps(void) |
| 2480 | { |
| 2481 | int irq; |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 2482 | struct irq_desc *desc; |
Yinghai Lu | da51a82 | 2008-08-19 20:50:25 -0700 | [diff] [blame] | 2483 | struct irq_cfg *cfg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2484 | |
| 2485 | /* |
| 2486 | * NOTE! The local APIC isn't very good at handling |
| 2487 | * multiple interrupts at the same interrupt level. |
| 2488 | * As the interrupt level is determined by taking the |
| 2489 | * vector number and shifting that right by 4, we |
| 2490 | * want to spread these out a bit so that they don't |
| 2491 | * all fall in the same interrupt level. |
| 2492 | * |
| 2493 | * Also, we've got to be careful not to trash gate |
| 2494 | * 0x80, because int 0x80 is hm, kind of importantish. ;) |
| 2495 | */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2496 | for_each_irq_desc(irq, desc) { |
| 2497 | if (!desc) |
| 2498 | continue; |
| 2499 | |
| 2500 | cfg = desc->chip_data; |
| 2501 | if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2502 | /* |
| 2503 | * Hmm.. We don't have an entry for this, |
| 2504 | * so default to an old-fashioned 8259 |
| 2505 | * interrupt if we can.. |
| 2506 | */ |
Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame^] | 2507 | if (irq < NR_IRQS_LEGACY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | make_8259A_irq(irq); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2509 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | /* Strange. Oh, well.. */ |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 2511 | desc->chip = &no_irq_chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | } |
| 2513 | } |
| 2514 | } |
| 2515 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 2516 | /* |
| 2517 | * The local APIC irq-chip implementation: |
| 2518 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2520 | static void mask_lapic_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | { |
| 2522 | unsigned long v; |
| 2523 | |
| 2524 | v = apic_read(APIC_LVT0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 2525 | apic_write(APIC_LVT0, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2528 | static void unmask_lapic_irq(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2529 | { |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 2530 | unsigned long v; |
| 2531 | |
| 2532 | v = apic_read(APIC_LVT0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 2533 | apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | } |
| 2535 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2536 | static void ack_lapic_irq (unsigned int irq) |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 2537 | { |
| 2538 | ack_APIC_irq(); |
| 2539 | } |
| 2540 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 2541 | static struct irq_chip lapic_chip __read_mostly = { |
Maciej W. Rozycki | 9a1c619 | 2008-05-27 21:19:09 +0100 | [diff] [blame] | 2542 | .name = "local-APIC", |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 2543 | .mask = mask_lapic_irq, |
| 2544 | .unmask = unmask_lapic_irq, |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 2545 | .ack = ack_lapic_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | }; |
| 2547 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2548 | static void lapic_register_intr(int irq) |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 2549 | { |
Yinghai Lu | 08678b0 | 2008-08-19 20:50:05 -0700 | [diff] [blame] | 2550 | struct irq_desc *desc; |
| 2551 | |
| 2552 | desc = irq_to_desc(irq); |
| 2553 | desc->status &= ~IRQ_LEVEL; |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 2554 | set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq, |
| 2555 | "edge"); |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 2556 | } |
| 2557 | |
Jan Beulich | e942710 | 2008-01-30 13:31:24 +0100 | [diff] [blame] | 2558 | static void __init setup_nmi(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | { |
| 2560 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2561 | * Dirty trick to enable the NMI watchdog ... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | * We put the 8259A master into AEOI mode and |
| 2563 | * unmask on all local APICs LVT0 as NMI. |
| 2564 | * |
| 2565 | * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire') |
| 2566 | * is from Maciej W. Rozycki - so we do not have to EOI from |
| 2567 | * the NMI handler or the timer interrupt. |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2568 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2569 | apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ..."); |
| 2570 | |
Jan Beulich | e942710 | 2008-01-30 13:31:24 +0100 | [diff] [blame] | 2571 | enable_NMI_through_LVT0(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | |
| 2573 | apic_printk(APIC_VERBOSE, " done.\n"); |
| 2574 | } |
| 2575 | |
| 2576 | /* |
| 2577 | * This looks a bit hackish but it's about the only one way of sending |
| 2578 | * a few INTA cycles to 8259As and any associated glue logic. ICR does |
| 2579 | * not support the ExtINT mode, unfortunately. We need to send these |
| 2580 | * cycles as some i82489DX-based boards have glue logic that keeps the |
| 2581 | * 8259A interrupt line asserted until INTA. --macro |
| 2582 | */ |
Jacek Luczak | 28acf28 | 2008-04-12 17:41:12 +0200 | [diff] [blame] | 2583 | static inline void __init unlock_ExtINT_logic(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2585 | int apic, pin, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | struct IO_APIC_route_entry entry0, entry1; |
| 2587 | unsigned char save_control, save_freq_select; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2589 | pin = find_isa_irq_pin(8, mp_INT); |
Adrian Bunk | 956fb53 | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 2590 | if (pin == -1) { |
| 2591 | WARN_ON_ONCE(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | return; |
Adrian Bunk | 956fb53 | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 2593 | } |
| 2594 | apic = find_isa_irq_apic(8, mp_INT); |
| 2595 | if (apic == -1) { |
| 2596 | WARN_ON_ONCE(1); |
| 2597 | return; |
| 2598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 2600 | entry0 = ioapic_read_entry(apic, pin); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2601 | clear_IO_APIC_pin(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | |
| 2603 | memset(&entry1, 0, sizeof(entry1)); |
| 2604 | |
| 2605 | entry1.dest_mode = 0; /* physical delivery */ |
| 2606 | entry1.mask = 0; /* unmask IRQ now */ |
Yinghai Lu | d83e94a | 2008-08-19 20:50:33 -0700 | [diff] [blame] | 2607 | entry1.dest = hard_smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | entry1.delivery_mode = dest_ExtINT; |
| 2609 | entry1.polarity = entry0.polarity; |
| 2610 | entry1.trigger = 0; |
| 2611 | entry1.vector = 0; |
| 2612 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 2613 | ioapic_write_entry(apic, pin, entry1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | |
| 2615 | save_control = CMOS_READ(RTC_CONTROL); |
| 2616 | save_freq_select = CMOS_READ(RTC_FREQ_SELECT); |
| 2617 | CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6, |
| 2618 | RTC_FREQ_SELECT); |
| 2619 | CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL); |
| 2620 | |
| 2621 | i = 100; |
| 2622 | while (i-- > 0) { |
| 2623 | mdelay(10); |
| 2624 | if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF) |
| 2625 | i -= 10; |
| 2626 | } |
| 2627 | |
| 2628 | CMOS_WRITE(save_control, RTC_CONTROL); |
| 2629 | CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2630 | clear_IO_APIC_pin(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 2632 | ioapic_write_entry(apic, pin, entry0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | } |
| 2634 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 2635 | static int disable_timer_pin_1 __initdata; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2636 | /* Actually the next is obsolete, but keep it for paranoid reasons -AK */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2637 | static int __init disable_timer_pin_setup(char *arg) |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 2638 | { |
| 2639 | disable_timer_pin_1 = 1; |
| 2640 | return 0; |
| 2641 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2642 | early_param("disable_timer_pin_1", disable_timer_pin_setup); |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 2643 | |
| 2644 | int timer_through_8259 __initdata; |
| 2645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | /* |
| 2647 | * This code may look a bit paranoid, but it's supposed to cooperate with |
| 2648 | * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ |
| 2649 | * is so screwy. Thanks to Brian Perkins for testing/hacking this beast |
| 2650 | * fanatically on his truly buggy board. |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2651 | * |
| 2652 | * FIXME: really need to revamp this for all platforms. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | */ |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 2654 | static inline void __init check_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2656 | struct irq_cfg *cfg = irq_cfg(0); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2657 | int apic1, pin1, apic2, pin2; |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2658 | unsigned long flags; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2659 | unsigned int ver; |
| 2660 | int no_pin1 = 0; |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2661 | |
| 2662 | local_irq_save(flags); |
Maciej W. Rozycki | d4d25de | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 2663 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2664 | ver = apic_read(APIC_LVR); |
| 2665 | ver = GET_APIC_VERSION(ver); |
Ingo Molnar | 6e90894 | 2008-03-21 14:32:36 +0100 | [diff] [blame] | 2666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | /* |
| 2668 | * get/set the timer IRQ vector: |
| 2669 | */ |
| 2670 | disable_8259A_irq(0); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2671 | assign_irq_vector(0, TARGET_CPUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | |
| 2673 | /* |
Maciej W. Rozycki | d11d579 | 2008-05-21 22:09:11 +0100 | [diff] [blame] | 2674 | * As IRQ0 is to be enabled in the 8259A, the virtual |
| 2675 | * wire has to be disabled in the local APIC. Also |
| 2676 | * timer interrupts need to be acknowledged manually in |
| 2677 | * the 8259A for the i82489DX when using the NMI |
| 2678 | * watchdog as that APIC treats NMIs as level-triggered. |
| 2679 | * The AEOI mode will finish them in the 8259A |
| 2680 | * automatically. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 2682 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2683 | init_8259A(1); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2684 | #ifdef CONFIG_X86_32 |
Maciej W. Rozycki | d11d579 | 2008-05-21 22:09:11 +0100 | [diff] [blame] | 2685 | timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver)); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2686 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2688 | pin1 = find_isa_irq_pin(0, mp_INT); |
| 2689 | apic1 = find_isa_irq_apic(0, mp_INT); |
| 2690 | pin2 = ioapic_i8259.pin; |
| 2691 | apic2 = ioapic_i8259.apic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2693 | apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X " |
| 2694 | "apic1=%d pin1=%d apic2=%d pin2=%d\n", |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2695 | cfg->vector, apic1, pin1, apic2, pin2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2696 | |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2697 | /* |
| 2698 | * Some BIOS writers are clueless and report the ExtINTA |
| 2699 | * I/O APIC input from the cascaded 8259A as the timer |
| 2700 | * interrupt input. So just in case, if only one pin |
| 2701 | * was found above, try it both directly and through the |
| 2702 | * 8259A. |
| 2703 | */ |
| 2704 | if (pin1 == -1) { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2705 | #ifdef CONFIG_INTR_REMAP |
| 2706 | if (intr_remapping_enabled) |
| 2707 | panic("BIOS bug: timer not connected to IO-APIC"); |
| 2708 | #endif |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2709 | pin1 = pin2; |
| 2710 | apic1 = apic2; |
| 2711 | no_pin1 = 1; |
| 2712 | } else if (pin2 == -1) { |
| 2713 | pin2 = pin1; |
| 2714 | apic2 = apic1; |
| 2715 | } |
| 2716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | if (pin1 != -1) { |
| 2718 | /* |
| 2719 | * Ok, does IRQ0 through the IOAPIC work? |
| 2720 | */ |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2721 | if (no_pin1) { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2722 | add_pin_to_irq_cpu(0, boot_cpu_id, apic1, pin1); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2723 | setup_timer_IRQ0_pin(apic1, pin1, cfg->vector); |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2724 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | unmask_IO_APIC_irq(0); |
| 2726 | if (timer_irq_works()) { |
| 2727 | if (nmi_watchdog == NMI_IO_APIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | setup_nmi(); |
| 2729 | enable_8259A_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | } |
Chuck Ebbert | 66759a0 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 2731 | if (disable_timer_pin_1 > 0) |
| 2732 | clear_IO_APIC_pin(0, pin1); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2733 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2735 | #ifdef CONFIG_INTR_REMAP |
| 2736 | if (intr_remapping_enabled) |
| 2737 | panic("timer doesn't work through Interrupt-remapped IO-APIC"); |
| 2738 | #endif |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2739 | clear_IO_APIC_pin(apic1, pin1); |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2740 | if (!no_pin1) |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2741 | apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: " |
| 2742 | "8254 timer not connected to IO-APIC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2743 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2744 | apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer " |
| 2745 | "(IRQ0) through the 8259A ...\n"); |
| 2746 | apic_printk(APIC_QUIET, KERN_INFO |
| 2747 | "..... (found apic %d pin %d) ...\n", apic2, pin2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2748 | /* |
| 2749 | * legacy devices should be connected to IO APIC #0 |
| 2750 | */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2751 | replace_pin_at_irq(0, boot_cpu_id, apic1, pin1, apic2, pin2); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2752 | setup_timer_IRQ0_pin(apic2, pin2, cfg->vector); |
Maciej W. Rozycki | 24742ec | 2008-05-27 21:19:40 +0100 | [diff] [blame] | 2753 | unmask_IO_APIC_irq(0); |
Maciej W. Rozycki | ecd2947 | 2008-05-21 22:09:19 +0100 | [diff] [blame] | 2754 | enable_8259A_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2756 | apic_printk(APIC_QUIET, KERN_INFO "....... works.\n"); |
Maciej W. Rozycki | 35542c5 | 2008-05-21 22:10:22 +0100 | [diff] [blame] | 2757 | timer_through_8259 = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | if (nmi_watchdog == NMI_IO_APIC) { |
Maciej W. Rozycki | 60134eb | 2008-05-21 22:09:34 +0100 | [diff] [blame] | 2759 | disable_8259A_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | setup_nmi(); |
Maciej W. Rozycki | 60134eb | 2008-05-21 22:09:34 +0100 | [diff] [blame] | 2761 | enable_8259A_irq(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | } |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2763 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | } |
| 2765 | /* |
| 2766 | * Cleanup, just in case ... |
| 2767 | */ |
Maciej W. Rozycki | ecd2947 | 2008-05-21 22:09:19 +0100 | [diff] [blame] | 2768 | disable_8259A_irq(0); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2769 | clear_IO_APIC_pin(apic2, pin2); |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2770 | apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | |
| 2773 | if (nmi_watchdog == NMI_IO_APIC) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2774 | apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work " |
| 2775 | "through the IO-APIC - disabling NMI Watchdog!\n"); |
Cyrill Gorcunov | 067fa0f | 2008-05-29 22:32:30 +0400 | [diff] [blame] | 2776 | nmi_watchdog = NMI_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2778 | #ifdef CONFIG_X86_32 |
Maciej W. Rozycki | d11d579 | 2008-05-21 22:09:11 +0100 | [diff] [blame] | 2779 | timer_ack = 0; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2780 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2782 | apic_printk(APIC_QUIET, KERN_INFO |
| 2783 | "...trying to set up timer as Virtual Wire IRQ...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2784 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2785 | lapic_register_intr(0); |
| 2786 | apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | enable_8259A_irq(0); |
| 2788 | |
| 2789 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2790 | apic_printk(APIC_QUIET, KERN_INFO "..... works.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2791 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | } |
Maciej W. Rozycki | e67465f | 2008-05-21 22:09:26 +0100 | [diff] [blame] | 2793 | disable_8259A_irq(0); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2794 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector); |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2795 | apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2797 | apic_printk(APIC_QUIET, KERN_INFO |
| 2798 | "...trying to set up timer as ExtINT IRQ...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | init_8259A(0); |
| 2801 | make_8259A_irq(0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 2802 | apic_write(APIC_LVT0, APIC_DM_EXTINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | |
| 2804 | unlock_ExtINT_logic(); |
| 2805 | |
| 2806 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2807 | apic_printk(APIC_QUIET, KERN_INFO "..... works.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2808 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | } |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2810 | apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | 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] | 2812 | "report. Then try booting with the 'noapic' option.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2813 | out: |
| 2814 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | /* |
Maciej W. Rozycki | af17478 | 2008-07-11 19:35:23 +0100 | [diff] [blame] | 2818 | * Traditionally ISA IRQ2 is the cascade IRQ, and is not available |
| 2819 | * to devices. However there may be an I/O APIC pin available for |
| 2820 | * this interrupt regardless. The pin may be left unconnected, but |
| 2821 | * typically it will be reused as an ExtINT cascade interrupt for |
| 2822 | * the master 8259A. In the MPS case such a pin will normally be |
| 2823 | * reported as an ExtINT interrupt in the MP table. With ACPI |
| 2824 | * there is no provision for ExtINT interrupts, and in the absence |
| 2825 | * of an override it would be treated as an ordinary ISA I/O APIC |
| 2826 | * interrupt, that is edge-triggered and unmasked by default. We |
| 2827 | * used to do this, but it caused problems on some systems because |
| 2828 | * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using |
| 2829 | * the same ExtINT cascade interrupt to drive the local APIC of the |
| 2830 | * bootstrap processor. Therefore we refrain from routing IRQ2 to |
| 2831 | * the I/O APIC in all cases now. No actual device should request |
| 2832 | * it anyway. --macro |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | */ |
| 2834 | #define PIC_IRQS (1 << PIC_CASCADE_IR) |
| 2835 | |
| 2836 | void __init setup_IO_APIC(void) |
| 2837 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2838 | |
| 2839 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | enable_IO_APIC(); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2841 | #else |
| 2842 | /* |
| 2843 | * calling enable_IO_APIC() is moved to setup_local_APIC for BP |
| 2844 | */ |
| 2845 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | |
Maciej W. Rozycki | af17478 | 2008-07-11 19:35:23 +0100 | [diff] [blame] | 2847 | io_apic_irqs = ~PIC_IRQS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2849 | apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n"); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2850 | /* |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2851 | * Set up IO-APIC IRQ routing. |
| 2852 | */ |
| 2853 | #ifdef CONFIG_X86_32 |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2854 | if (!acpi_ioapic) |
| 2855 | setup_ioapic_ids_from_mpc(); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2856 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | sync_Arb_IDs(); |
| 2858 | setup_IO_APIC_irqs(); |
| 2859 | init_IO_APIC_traps(); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 2860 | check_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | /* |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2864 | * Called after all the initialization is done. If we didnt find any |
| 2865 | * APIC bugs then we can allow the modify fast path |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2866 | */ |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2868 | static int __init io_apic_bug_finalize(void) |
| 2869 | { |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2870 | if (sis_apic_bug == -1) |
| 2871 | sis_apic_bug = 0; |
| 2872 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | late_initcall(io_apic_bug_finalize); |
| 2876 | |
| 2877 | struct sysfs_ioapic_data { |
| 2878 | struct sys_device dev; |
| 2879 | struct IO_APIC_route_entry entry[0]; |
| 2880 | }; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2881 | static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | |
Pavel Machek | 438510f | 2005-04-16 15:25:24 -0700 | [diff] [blame] | 2883 | static int ioapic_suspend(struct sys_device *dev, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2884 | { |
| 2885 | struct IO_APIC_route_entry *entry; |
| 2886 | struct sysfs_ioapic_data *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | int i; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2888 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | data = container_of(dev, struct sysfs_ioapic_data, dev); |
| 2890 | entry = data->entry; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2891 | for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ ) |
| 2892 | *entry = ioapic_read_entry(dev->id, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | |
| 2894 | return 0; |
| 2895 | } |
| 2896 | |
| 2897 | static int ioapic_resume(struct sys_device *dev) |
| 2898 | { |
| 2899 | struct IO_APIC_route_entry *entry; |
| 2900 | struct sysfs_ioapic_data *data; |
| 2901 | unsigned long flags; |
| 2902 | union IO_APIC_reg_00 reg_00; |
| 2903 | int i; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | data = container_of(dev, struct sysfs_ioapic_data, dev); |
| 2906 | entry = data->entry; |
| 2907 | |
| 2908 | spin_lock_irqsave(&ioapic_lock, flags); |
| 2909 | reg_00.raw = io_apic_read(dev->id, 0); |
Alexey Starikovskiy | ec2cd0a | 2008-05-14 19:03:10 +0400 | [diff] [blame] | 2910 | if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) { |
| 2911 | reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2912 | io_apic_write(dev->id, 0, reg_00.raw); |
| 2913 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | spin_unlock_irqrestore(&ioapic_lock, flags); |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2915 | for (i = 0; i < nr_ioapic_registers[dev->id]; i++) |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 2916 | ioapic_write_entry(dev->id, i, entry[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2917 | |
| 2918 | return 0; |
| 2919 | } |
| 2920 | |
| 2921 | static struct sysdev_class ioapic_sysdev_class = { |
Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 2922 | .name = "ioapic", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | .suspend = ioapic_suspend, |
| 2924 | .resume = ioapic_resume, |
| 2925 | }; |
| 2926 | |
| 2927 | static int __init ioapic_init_sysfs(void) |
| 2928 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2929 | struct sys_device * dev; |
| 2930 | int i, size, error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | |
| 2932 | error = sysdev_class_register(&ioapic_sysdev_class); |
| 2933 | if (error) |
| 2934 | return error; |
| 2935 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2936 | for (i = 0; i < nr_ioapics; i++ ) { |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2937 | size = sizeof(struct sys_device) + nr_ioapic_registers[i] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | * sizeof(struct IO_APIC_route_entry); |
Christophe Jaillet | 25556c1 | 2008-06-22 22:13:48 +0200 | [diff] [blame] | 2939 | mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | if (!mp_ioapic_data[i]) { |
| 2941 | printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i); |
| 2942 | continue; |
| 2943 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | dev = &mp_ioapic_data[i]->dev; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2945 | dev->id = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | dev->cls = &ioapic_sysdev_class; |
| 2947 | error = sysdev_register(dev); |
| 2948 | if (error) { |
| 2949 | kfree(mp_ioapic_data[i]); |
| 2950 | mp_ioapic_data[i] = NULL; |
| 2951 | printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i); |
| 2952 | continue; |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | return 0; |
| 2957 | } |
| 2958 | |
| 2959 | device_initcall(ioapic_init_sysfs); |
| 2960 | |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2961 | /* |
Eric W. Biederman | 95d7788 | 2006-10-04 02:17:01 -0700 | [diff] [blame] | 2962 | * Dynamic irq allocate and deallocation |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2963 | */ |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 2964 | unsigned int create_irq_nr(unsigned int irq_want) |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2965 | { |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2966 | /* Allocate an unused irq */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2967 | unsigned int irq; |
| 2968 | unsigned int new; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2969 | unsigned long flags; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2970 | struct irq_cfg *cfg_new = NULL; |
| 2971 | int cpu = boot_cpu_id; |
| 2972 | struct irq_desc *desc_new = NULL; |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 2973 | |
| 2974 | irq = 0; |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2975 | spin_lock_irqsave(&vector_lock, flags); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2976 | for (new = irq_want; new > 0; new--) { |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2977 | if (platform_legacy_irq(new)) |
| 2978 | continue; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2979 | |
| 2980 | desc_new = irq_to_desc_alloc_cpu(new, cpu); |
| 2981 | if (!desc_new) { |
| 2982 | printk(KERN_INFO "can not get irq_desc for %d\n", new); |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2983 | continue; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2984 | } |
| 2985 | cfg_new = desc_new->chip_data; |
| 2986 | |
| 2987 | if (cfg_new->vector != 0) |
| 2988 | continue; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2989 | if (__assign_irq_vector(new, TARGET_CPUS) == 0) |
Eric W. Biederman | ace80ab | 2006-10-04 02:16:47 -0700 | [diff] [blame] | 2990 | irq = new; |
| 2991 | break; |
| 2992 | } |
| 2993 | spin_unlock_irqrestore(&vector_lock, flags); |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2994 | |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 2995 | if (irq > 0) { |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 2996 | dynamic_irq_init(irq); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 2997 | /* restore it, in case dynamic_irq_init clear it */ |
| 2998 | if (desc_new) |
| 2999 | desc_new->chip_data = cfg_new; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 3000 | } |
| 3001 | return irq; |
| 3002 | } |
| 3003 | |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 3004 | int create_irq(void) |
| 3005 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3006 | int irq; |
| 3007 | |
| 3008 | irq = create_irq_nr(nr_irqs - 1); |
| 3009 | |
| 3010 | if (irq == 0) |
| 3011 | irq = -1; |
| 3012 | |
| 3013 | return irq; |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 3016 | void destroy_irq(unsigned int irq) |
| 3017 | { |
| 3018 | unsigned long flags; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3019 | struct irq_cfg *cfg; |
| 3020 | struct irq_desc *desc; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 3021 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3022 | /* store it, in case dynamic_irq_cleanup clear it */ |
| 3023 | desc = irq_to_desc(irq); |
| 3024 | cfg = desc->chip_data; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 3025 | dynamic_irq_cleanup(irq); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3026 | /* connect back irq_cfg */ |
| 3027 | if (desc) |
| 3028 | desc->chip_data = cfg; |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 3029 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3030 | #ifdef CONFIG_INTR_REMAP |
| 3031 | free_irte(irq); |
| 3032 | #endif |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 3033 | spin_lock_irqsave(&vector_lock, flags); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3034 | __clear_irq_vector(irq); |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 3035 | spin_unlock_irqrestore(&vector_lock, flags); |
| 3036 | } |
Eric W. Biederman | 3fc471e | 2006-10-04 02:16:39 -0700 | [diff] [blame] | 3037 | |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3038 | /* |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 3039 | * MSI message composition |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3040 | */ |
| 3041 | #ifdef CONFIG_PCI_MSI |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3042 | 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] | 3043 | { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3044 | struct irq_cfg *cfg; |
| 3045 | int err; |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3046 | unsigned dest; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3047 | cpumask_t tmp; |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3048 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3049 | tmp = TARGET_CPUS; |
| 3050 | err = assign_irq_vector(irq, tmp); |
| 3051 | if (err) |
| 3052 | return err; |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3053 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3054 | cfg = irq_cfg(irq); |
| 3055 | cpus_and(tmp, cfg->domain, tmp); |
| 3056 | dest = cpu_mask_to_apicid(tmp); |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3057 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3058 | #ifdef CONFIG_INTR_REMAP |
| 3059 | if (irq_remapped(irq)) { |
| 3060 | struct irte irte; |
| 3061 | int ir_index; |
| 3062 | u16 sub_handle; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3063 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3064 | ir_index = map_irq_to_irte_handle(irq, &sub_handle); |
| 3065 | BUG_ON(ir_index == -1); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3066 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3067 | memset (&irte, 0, sizeof(irte)); |
| 3068 | |
| 3069 | irte.present = 1; |
| 3070 | irte.dst_mode = INT_DEST_MODE; |
| 3071 | irte.trigger_mode = 0; /* edge */ |
| 3072 | irte.dlvry_mode = INT_DELIVERY_MODE; |
| 3073 | irte.vector = cfg->vector; |
| 3074 | irte.dest_id = IRTE_DEST(dest); |
| 3075 | |
| 3076 | modify_irte(irq, &irte); |
| 3077 | |
| 3078 | msg->address_hi = MSI_ADDR_BASE_HI; |
| 3079 | msg->data = sub_handle; |
| 3080 | msg->address_lo = MSI_ADDR_BASE_LO | MSI_ADDR_IR_EXT_INT | |
| 3081 | MSI_ADDR_IR_SHV | |
| 3082 | MSI_ADDR_IR_INDEX1(ir_index) | |
| 3083 | MSI_ADDR_IR_INDEX2(ir_index); |
| 3084 | } else |
| 3085 | #endif |
| 3086 | { |
| 3087 | msg->address_hi = MSI_ADDR_BASE_HI; |
| 3088 | msg->address_lo = |
| 3089 | MSI_ADDR_BASE_LO | |
| 3090 | ((INT_DEST_MODE == 0) ? |
| 3091 | MSI_ADDR_DEST_MODE_PHYSICAL: |
| 3092 | MSI_ADDR_DEST_MODE_LOGICAL) | |
| 3093 | ((INT_DELIVERY_MODE != dest_LowestPrio) ? |
| 3094 | MSI_ADDR_REDIRECTION_CPU: |
| 3095 | MSI_ADDR_REDIRECTION_LOWPRI) | |
| 3096 | MSI_ADDR_DEST_ID(dest); |
| 3097 | |
| 3098 | msg->data = |
| 3099 | MSI_DATA_TRIGGER_EDGE | |
| 3100 | MSI_DATA_LEVEL_ASSERT | |
| 3101 | ((INT_DELIVERY_MODE != dest_LowestPrio) ? |
| 3102 | MSI_DATA_DELIVERY_FIXED: |
| 3103 | MSI_DATA_DELIVERY_LOWPRI) | |
| 3104 | MSI_DATA_VECTOR(cfg->vector); |
| 3105 | } |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3106 | return err; |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3107 | } |
| 3108 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3109 | #ifdef CONFIG_SMP |
| 3110 | static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask) |
| 3111 | { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3112 | struct irq_cfg *cfg; |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3113 | struct msi_msg msg; |
| 3114 | unsigned int dest; |
| 3115 | cpumask_t tmp; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3116 | struct irq_desc *desc; |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3117 | |
| 3118 | cpus_and(tmp, mask, cpu_online_map); |
| 3119 | if (cpus_empty(tmp)) |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3120 | return; |
| 3121 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3122 | if (assign_irq_vector(irq, mask)) |
| 3123 | return; |
| 3124 | |
| 3125 | cfg = irq_cfg(irq); |
| 3126 | cpus_and(tmp, cfg->domain, mask); |
| 3127 | dest = cpu_mask_to_apicid(tmp); |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3128 | |
| 3129 | read_msi_msg(irq, &msg); |
| 3130 | |
| 3131 | msg.data &= ~MSI_DATA_VECTOR_MASK; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3132 | msg.data |= MSI_DATA_VECTOR(cfg->vector); |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3133 | msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK; |
| 3134 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); |
| 3135 | |
| 3136 | write_msi_msg(irq, &msg); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3137 | desc = irq_to_desc(irq); |
| 3138 | desc->affinity = mask; |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3139 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3140 | |
| 3141 | #ifdef CONFIG_INTR_REMAP |
| 3142 | /* |
| 3143 | * Migrate the MSI irq to another cpumask. This migration is |
| 3144 | * done in the process context using interrupt-remapping hardware. |
| 3145 | */ |
| 3146 | static void ir_set_msi_irq_affinity(unsigned int irq, cpumask_t mask) |
| 3147 | { |
| 3148 | struct irq_cfg *cfg; |
| 3149 | unsigned int dest; |
| 3150 | cpumask_t tmp, cleanup_mask; |
| 3151 | struct irte irte; |
| 3152 | struct irq_desc *desc; |
| 3153 | |
| 3154 | cpus_and(tmp, mask, cpu_online_map); |
| 3155 | if (cpus_empty(tmp)) |
| 3156 | return; |
| 3157 | |
| 3158 | if (get_irte(irq, &irte)) |
| 3159 | return; |
| 3160 | |
| 3161 | if (assign_irq_vector(irq, mask)) |
| 3162 | return; |
| 3163 | |
| 3164 | cfg = irq_cfg(irq); |
| 3165 | cpus_and(tmp, cfg->domain, mask); |
| 3166 | dest = cpu_mask_to_apicid(tmp); |
| 3167 | |
| 3168 | irte.vector = cfg->vector; |
| 3169 | irte.dest_id = IRTE_DEST(dest); |
| 3170 | |
| 3171 | /* |
| 3172 | * atomically update the IRTE with the new destination and vector. |
| 3173 | */ |
| 3174 | modify_irte(irq, &irte); |
| 3175 | |
| 3176 | /* |
| 3177 | * After this point, all the interrupts will start arriving |
| 3178 | * at the new destination. So, time to cleanup the previous |
| 3179 | * vector allocation. |
| 3180 | */ |
| 3181 | if (cfg->move_in_progress) { |
| 3182 | cpus_and(cleanup_mask, cfg->old_domain, cpu_online_map); |
| 3183 | cfg->move_cleanup_count = cpus_weight(cleanup_mask); |
| 3184 | send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR); |
| 3185 | cfg->move_in_progress = 0; |
| 3186 | } |
| 3187 | |
| 3188 | desc = irq_to_desc(irq); |
| 3189 | desc->affinity = mask; |
| 3190 | } |
| 3191 | #endif |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3192 | #endif /* CONFIG_SMP */ |
| 3193 | |
| 3194 | /* |
| 3195 | * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices, |
| 3196 | * which implement the MSI or MSI-X Capability Structure. |
| 3197 | */ |
| 3198 | static struct irq_chip msi_chip = { |
| 3199 | .name = "PCI-MSI", |
| 3200 | .unmask = unmask_msi_irq, |
| 3201 | .mask = mask_msi_irq, |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 3202 | .ack = ack_apic_edge, |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3203 | #ifdef CONFIG_SMP |
| 3204 | .set_affinity = set_msi_irq_affinity, |
| 3205 | #endif |
| 3206 | .retrigger = ioapic_retrigger_irq, |
| 3207 | }; |
| 3208 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3209 | #ifdef CONFIG_INTR_REMAP |
| 3210 | static struct irq_chip msi_ir_chip = { |
| 3211 | .name = "IR-PCI-MSI", |
| 3212 | .unmask = unmask_msi_irq, |
| 3213 | .mask = mask_msi_irq, |
| 3214 | .ack = ack_x2apic_edge, |
| 3215 | #ifdef CONFIG_SMP |
| 3216 | .set_affinity = ir_set_msi_irq_affinity, |
| 3217 | #endif |
| 3218 | .retrigger = ioapic_retrigger_irq, |
| 3219 | }; |
| 3220 | |
| 3221 | /* |
| 3222 | * Map the PCI dev to the corresponding remapping hardware unit |
| 3223 | * and allocate 'nvec' consecutive interrupt-remapping table entries |
| 3224 | * in it. |
| 3225 | */ |
| 3226 | static int msi_alloc_irte(struct pci_dev *dev, int irq, int nvec) |
| 3227 | { |
| 3228 | struct intel_iommu *iommu; |
| 3229 | int index; |
| 3230 | |
| 3231 | iommu = map_dev_to_ir(dev); |
| 3232 | if (!iommu) { |
| 3233 | printk(KERN_ERR |
| 3234 | "Unable to map PCI %s to iommu\n", pci_name(dev)); |
| 3235 | return -ENOENT; |
| 3236 | } |
| 3237 | |
| 3238 | index = alloc_irte(iommu, irq, nvec); |
| 3239 | if (index < 0) { |
| 3240 | printk(KERN_ERR |
| 3241 | "Unable to allocate %d IRTE for PCI %s\n", nvec, |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 3242 | pci_name(dev)); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3243 | return -ENOSPC; |
| 3244 | } |
| 3245 | return index; |
| 3246 | } |
| 3247 | #endif |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 3248 | |
| 3249 | static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc, int irq) |
| 3250 | { |
| 3251 | int ret; |
| 3252 | struct msi_msg msg; |
| 3253 | |
| 3254 | ret = msi_compose_msg(dev, irq, &msg); |
| 3255 | if (ret < 0) |
| 3256 | return ret; |
| 3257 | |
| 3258 | set_irq_msi(irq, desc); |
| 3259 | write_msi_msg(irq, &msg); |
| 3260 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3261 | #ifdef CONFIG_INTR_REMAP |
| 3262 | if (irq_remapped(irq)) { |
| 3263 | struct irq_desc *desc = irq_to_desc(irq); |
| 3264 | /* |
| 3265 | * irq migration in process context |
| 3266 | */ |
| 3267 | desc->status |= IRQ_MOVE_PCNTXT; |
| 3268 | set_irq_chip_and_handler_name(irq, &msi_ir_chip, handle_edge_irq, "edge"); |
| 3269 | } else |
| 3270 | #endif |
| 3271 | set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge"); |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 3272 | |
Yinghai Lu | c81bba4 | 2008-09-25 11:53:11 -0700 | [diff] [blame] | 3273 | dev_printk(KERN_DEBUG, &dev->dev, "irq %d for MSI/MSI-X\n", irq); |
| 3274 | |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 3275 | return 0; |
| 3276 | } |
| 3277 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3278 | int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc) |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3279 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3280 | unsigned int irq; |
| 3281 | int ret; |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 3282 | unsigned int irq_want; |
| 3283 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3284 | irq_want = nr_irqs - 1; |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 3285 | irq = create_irq_nr(irq_want); |
Yinghai Lu | 199751d | 2008-08-19 20:50:27 -0700 | [diff] [blame] | 3286 | if (irq == 0) |
| 3287 | return -1; |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 3288 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3289 | #ifdef CONFIG_INTR_REMAP |
| 3290 | if (!intr_remapping_enabled) |
| 3291 | goto no_ir; |
| 3292 | |
| 3293 | ret = msi_alloc_irte(dev, irq, 1); |
| 3294 | if (ret < 0) |
| 3295 | goto error; |
| 3296 | no_ir: |
| 3297 | #endif |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3298 | ret = setup_msi_irq(dev, msidesc, irq); |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 3299 | if (ret < 0) { |
| 3300 | destroy_irq(irq); |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3301 | return ret; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3302 | } |
Michael Ellerman | 7fe3730 | 2007-04-18 19:39:21 +1000 | [diff] [blame] | 3303 | return 0; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3304 | |
| 3305 | #ifdef CONFIG_INTR_REMAP |
| 3306 | error: |
| 3307 | destroy_irq(irq); |
| 3308 | return ret; |
| 3309 | #endif |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 3312 | int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type) |
| 3313 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3314 | unsigned int irq; |
| 3315 | int ret, sub_handle; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3316 | struct msi_desc *msidesc; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3317 | unsigned int irq_want; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 3318 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3319 | #ifdef CONFIG_INTR_REMAP |
| 3320 | struct intel_iommu *iommu = 0; |
| 3321 | int index = 0; |
| 3322 | #endif |
| 3323 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3324 | irq_want = nr_irqs - 1; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3325 | sub_handle = 0; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3326 | list_for_each_entry(msidesc, &dev->msi_list, list) { |
| 3327 | irq = create_irq_nr(irq_want); |
| 3328 | irq_want--; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3329 | if (irq == 0) |
| 3330 | return -1; |
| 3331 | #ifdef CONFIG_INTR_REMAP |
| 3332 | if (!intr_remapping_enabled) |
| 3333 | goto no_ir; |
| 3334 | |
| 3335 | if (!sub_handle) { |
| 3336 | /* |
| 3337 | * allocate the consecutive block of IRTE's |
| 3338 | * for 'nvec' |
| 3339 | */ |
| 3340 | index = msi_alloc_irte(dev, irq, nvec); |
| 3341 | if (index < 0) { |
| 3342 | ret = index; |
| 3343 | goto error; |
| 3344 | } |
| 3345 | } else { |
| 3346 | iommu = map_dev_to_ir(dev); |
| 3347 | if (!iommu) { |
| 3348 | ret = -ENOENT; |
| 3349 | goto error; |
| 3350 | } |
| 3351 | /* |
| 3352 | * setup the mapping between the irq and the IRTE |
| 3353 | * base index, the sub_handle pointing to the |
| 3354 | * appropriate interrupt remap table entry. |
| 3355 | */ |
| 3356 | set_irte_irq(irq, iommu, index, sub_handle); |
| 3357 | } |
| 3358 | no_ir: |
| 3359 | #endif |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3360 | ret = setup_msi_irq(dev, msidesc, irq); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3361 | if (ret < 0) |
| 3362 | goto error; |
| 3363 | sub_handle++; |
| 3364 | } |
| 3365 | return 0; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 3366 | |
| 3367 | error: |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3368 | destroy_irq(irq); |
| 3369 | return ret; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 3370 | } |
| 3371 | |
Eric W. Biederman | 3b7d192 | 2006-10-04 02:16:59 -0700 | [diff] [blame] | 3372 | void arch_teardown_msi_irq(unsigned int irq) |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3373 | { |
Eric W. Biederman | f7feaca | 2007-01-28 12:56:37 -0700 | [diff] [blame] | 3374 | destroy_irq(irq); |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3375 | } |
| 3376 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3377 | #ifdef CONFIG_DMAR |
| 3378 | #ifdef CONFIG_SMP |
| 3379 | static void dmar_msi_set_affinity(unsigned int irq, cpumask_t mask) |
| 3380 | { |
| 3381 | struct irq_cfg *cfg; |
| 3382 | struct msi_msg msg; |
| 3383 | unsigned int dest; |
| 3384 | cpumask_t tmp; |
| 3385 | struct irq_desc *desc; |
Eric W. Biederman | 2d3fcc1 | 2006-10-04 02:16:43 -0700 | [diff] [blame] | 3386 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3387 | cpus_and(tmp, mask, cpu_online_map); |
| 3388 | if (cpus_empty(tmp)) |
| 3389 | return; |
| 3390 | |
| 3391 | if (assign_irq_vector(irq, mask)) |
| 3392 | return; |
| 3393 | |
| 3394 | cfg = irq_cfg(irq); |
| 3395 | cpus_and(tmp, cfg->domain, mask); |
| 3396 | dest = cpu_mask_to_apicid(tmp); |
| 3397 | |
| 3398 | dmar_msi_read(irq, &msg); |
| 3399 | |
| 3400 | msg.data &= ~MSI_DATA_VECTOR_MASK; |
| 3401 | msg.data |= MSI_DATA_VECTOR(cfg->vector); |
| 3402 | msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK; |
| 3403 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); |
| 3404 | |
| 3405 | dmar_msi_write(irq, &msg); |
| 3406 | desc = irq_to_desc(irq); |
| 3407 | desc->affinity = mask; |
| 3408 | } |
| 3409 | #endif /* CONFIG_SMP */ |
| 3410 | |
| 3411 | struct irq_chip dmar_msi_type = { |
| 3412 | .name = "DMAR_MSI", |
| 3413 | .unmask = dmar_msi_unmask, |
| 3414 | .mask = dmar_msi_mask, |
| 3415 | .ack = ack_apic_edge, |
| 3416 | #ifdef CONFIG_SMP |
| 3417 | .set_affinity = dmar_msi_set_affinity, |
| 3418 | #endif |
| 3419 | .retrigger = ioapic_retrigger_irq, |
| 3420 | }; |
| 3421 | |
| 3422 | int arch_setup_dmar_msi(unsigned int irq) |
| 3423 | { |
| 3424 | int ret; |
| 3425 | struct msi_msg msg; |
| 3426 | |
| 3427 | ret = msi_compose_msg(NULL, irq, &msg); |
| 3428 | if (ret < 0) |
| 3429 | return ret; |
| 3430 | dmar_msi_write(irq, &msg); |
| 3431 | set_irq_chip_and_handler_name(irq, &dmar_msi_type, handle_edge_irq, |
| 3432 | "edge"); |
| 3433 | return 0; |
| 3434 | } |
| 3435 | #endif |
| 3436 | |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 3437 | #ifdef CONFIG_HPET_TIMER |
| 3438 | |
| 3439 | #ifdef CONFIG_SMP |
| 3440 | static void hpet_msi_set_affinity(unsigned int irq, cpumask_t mask) |
| 3441 | { |
| 3442 | struct irq_cfg *cfg; |
| 3443 | struct irq_desc *desc; |
| 3444 | struct msi_msg msg; |
| 3445 | unsigned int dest; |
| 3446 | cpumask_t tmp; |
| 3447 | |
| 3448 | cpus_and(tmp, mask, cpu_online_map); |
| 3449 | if (cpus_empty(tmp)) |
| 3450 | return; |
| 3451 | |
| 3452 | if (assign_irq_vector(irq, mask)) |
| 3453 | return; |
| 3454 | |
| 3455 | cfg = irq_cfg(irq); |
| 3456 | cpus_and(tmp, cfg->domain, mask); |
| 3457 | dest = cpu_mask_to_apicid(tmp); |
| 3458 | |
| 3459 | hpet_msi_read(irq, &msg); |
| 3460 | |
| 3461 | msg.data &= ~MSI_DATA_VECTOR_MASK; |
| 3462 | msg.data |= MSI_DATA_VECTOR(cfg->vector); |
| 3463 | msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK; |
| 3464 | msg.address_lo |= MSI_ADDR_DEST_ID(dest); |
| 3465 | |
| 3466 | hpet_msi_write(irq, &msg); |
| 3467 | desc = irq_to_desc(irq); |
| 3468 | desc->affinity = mask; |
| 3469 | } |
| 3470 | #endif /* CONFIG_SMP */ |
| 3471 | |
| 3472 | struct irq_chip hpet_msi_type = { |
| 3473 | .name = "HPET_MSI", |
| 3474 | .unmask = hpet_msi_unmask, |
| 3475 | .mask = hpet_msi_mask, |
| 3476 | .ack = ack_apic_edge, |
| 3477 | #ifdef CONFIG_SMP |
| 3478 | .set_affinity = hpet_msi_set_affinity, |
| 3479 | #endif |
| 3480 | .retrigger = ioapic_retrigger_irq, |
| 3481 | }; |
| 3482 | |
| 3483 | int arch_setup_hpet_msi(unsigned int irq) |
| 3484 | { |
| 3485 | int ret; |
| 3486 | struct msi_msg msg; |
| 3487 | |
| 3488 | ret = msi_compose_msg(NULL, irq, &msg); |
| 3489 | if (ret < 0) |
| 3490 | return ret; |
| 3491 | |
| 3492 | hpet_msi_write(irq, &msg); |
| 3493 | set_irq_chip_and_handler_name(irq, &hpet_msi_type, handle_edge_irq, |
| 3494 | "edge"); |
Yinghai Lu | c81bba4 | 2008-09-25 11:53:11 -0700 | [diff] [blame] | 3495 | |
venkatesh.pallipadi@intel.com | 58ac1e7 | 2008-09-05 18:02:17 -0700 | [diff] [blame] | 3496 | return 0; |
| 3497 | } |
| 3498 | #endif |
| 3499 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3500 | #endif /* CONFIG_PCI_MSI */ |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3501 | /* |
| 3502 | * Hypertransport interrupt support |
| 3503 | */ |
| 3504 | #ifdef CONFIG_HT_IRQ |
| 3505 | |
| 3506 | #ifdef CONFIG_SMP |
| 3507 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3508 | static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector) |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3509 | { |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 3510 | struct ht_irq_msg msg; |
| 3511 | fetch_ht_irq_msg(irq, &msg); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3512 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3513 | msg.address_lo &= ~(HT_IRQ_LOW_VECTOR_MASK | HT_IRQ_LOW_DEST_ID_MASK); |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 3514 | msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3515 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3516 | msg.address_lo |= HT_IRQ_LOW_VECTOR(vector) | HT_IRQ_LOW_DEST_ID(dest); |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 3517 | msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3518 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 3519 | write_ht_irq_msg(irq, &msg); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | static void set_ht_irq_affinity(unsigned int irq, cpumask_t mask) |
| 3523 | { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3524 | struct irq_cfg *cfg; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3525 | unsigned int dest; |
| 3526 | cpumask_t tmp; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3527 | struct irq_desc *desc; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3528 | |
| 3529 | cpus_and(tmp, mask, cpu_online_map); |
| 3530 | if (cpus_empty(tmp)) |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3531 | return; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3532 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3533 | if (assign_irq_vector(irq, mask)) |
| 3534 | return; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3535 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3536 | cfg = irq_cfg(irq); |
| 3537 | cpus_and(tmp, cfg->domain, mask); |
| 3538 | dest = cpu_mask_to_apicid(tmp); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3539 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3540 | target_ht_irq(irq, dest, cfg->vector); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3541 | desc = irq_to_desc(irq); |
| 3542 | desc->affinity = mask; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3543 | } |
| 3544 | #endif |
| 3545 | |
Aneesh Kumar K.V | c37e108 | 2006-10-11 01:20:43 -0700 | [diff] [blame] | 3546 | static struct irq_chip ht_irq_chip = { |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3547 | .name = "PCI-HT", |
| 3548 | .mask = mask_ht_irq, |
| 3549 | .unmask = unmask_ht_irq, |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 3550 | .ack = ack_apic_edge, |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3551 | #ifdef CONFIG_SMP |
| 3552 | .set_affinity = set_ht_irq_affinity, |
| 3553 | #endif |
| 3554 | .retrigger = ioapic_retrigger_irq, |
| 3555 | }; |
| 3556 | |
| 3557 | int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev) |
| 3558 | { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3559 | struct irq_cfg *cfg; |
| 3560 | int err; |
| 3561 | cpumask_t tmp; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3562 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3563 | tmp = TARGET_CPUS; |
| 3564 | err = assign_irq_vector(irq, tmp); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3565 | if (!err) { |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 3566 | struct ht_irq_msg msg; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3567 | unsigned dest; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3568 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3569 | cfg = irq_cfg(irq); |
| 3570 | cpus_and(tmp, cfg->domain, tmp); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3571 | dest = cpu_mask_to_apicid(tmp); |
| 3572 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 3573 | msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3574 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 3575 | msg.address_lo = |
| 3576 | HT_IRQ_LOW_BASE | |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3577 | HT_IRQ_LOW_DEST_ID(dest) | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3578 | HT_IRQ_LOW_VECTOR(cfg->vector) | |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3579 | ((INT_DEST_MODE == 0) ? |
| 3580 | HT_IRQ_LOW_DM_PHYSICAL : |
| 3581 | HT_IRQ_LOW_DM_LOGICAL) | |
| 3582 | HT_IRQ_LOW_RQEOI_EDGE | |
| 3583 | ((INT_DELIVERY_MODE != dest_LowestPrio) ? |
| 3584 | HT_IRQ_LOW_MT_FIXED : |
| 3585 | HT_IRQ_LOW_MT_ARBITRATED) | |
| 3586 | HT_IRQ_LOW_IRQ_MASKED; |
| 3587 | |
Eric W. Biederman | ec68307 | 2006-11-08 17:44:57 -0800 | [diff] [blame] | 3588 | write_ht_irq_msg(irq, &msg); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3589 | |
Ingo Molnar | a460e74 | 2006-10-17 00:10:03 -0700 | [diff] [blame] | 3590 | set_irq_chip_and_handler_name(irq, &ht_irq_chip, |
| 3591 | handle_edge_irq, "edge"); |
Yinghai Lu | c81bba4 | 2008-09-25 11:53:11 -0700 | [diff] [blame] | 3592 | |
| 3593 | dev_printk(KERN_DEBUG, &dev->dev, "irq %d for HT\n", irq); |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3594 | } |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3595 | return err; |
Eric W. Biederman | 8b955b0 | 2006-10-04 02:16:55 -0700 | [diff] [blame] | 3596 | } |
| 3597 | #endif /* CONFIG_HT_IRQ */ |
| 3598 | |
Dean Nelson | 4173a0e | 2008-10-02 12:18:21 -0500 | [diff] [blame] | 3599 | #ifdef CONFIG_X86_64 |
| 3600 | /* |
| 3601 | * Re-target the irq to the specified CPU and enable the specified MMR located |
| 3602 | * on the specified blade to allow the sending of MSIs to the specified CPU. |
| 3603 | */ |
| 3604 | int arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade, |
| 3605 | unsigned long mmr_offset) |
| 3606 | { |
| 3607 | const cpumask_t *eligible_cpu = get_cpu_mask(cpu); |
| 3608 | struct irq_cfg *cfg; |
| 3609 | int mmr_pnode; |
| 3610 | unsigned long mmr_value; |
| 3611 | struct uv_IO_APIC_route_entry *entry; |
| 3612 | unsigned long flags; |
| 3613 | int err; |
| 3614 | |
| 3615 | err = assign_irq_vector(irq, *eligible_cpu); |
| 3616 | if (err != 0) |
| 3617 | return err; |
| 3618 | |
| 3619 | spin_lock_irqsave(&vector_lock, flags); |
| 3620 | set_irq_chip_and_handler_name(irq, &uv_irq_chip, handle_percpu_irq, |
| 3621 | irq_name); |
| 3622 | spin_unlock_irqrestore(&vector_lock, flags); |
| 3623 | |
| 3624 | cfg = irq_cfg(irq); |
| 3625 | |
| 3626 | mmr_value = 0; |
| 3627 | entry = (struct uv_IO_APIC_route_entry *)&mmr_value; |
| 3628 | BUG_ON(sizeof(struct uv_IO_APIC_route_entry) != sizeof(unsigned long)); |
| 3629 | |
| 3630 | entry->vector = cfg->vector; |
| 3631 | entry->delivery_mode = INT_DELIVERY_MODE; |
| 3632 | entry->dest_mode = INT_DEST_MODE; |
| 3633 | entry->polarity = 0; |
| 3634 | entry->trigger = 0; |
| 3635 | entry->mask = 0; |
| 3636 | entry->dest = cpu_mask_to_apicid(*eligible_cpu); |
| 3637 | |
| 3638 | mmr_pnode = uv_blade_to_pnode(mmr_blade); |
| 3639 | uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value); |
| 3640 | |
| 3641 | return irq; |
| 3642 | } |
| 3643 | |
| 3644 | /* |
| 3645 | * Disable the specified MMR located on the specified blade so that MSIs are |
| 3646 | * longer allowed to be sent. |
| 3647 | */ |
| 3648 | void arch_disable_uv_irq(int mmr_blade, unsigned long mmr_offset) |
| 3649 | { |
| 3650 | unsigned long mmr_value; |
| 3651 | struct uv_IO_APIC_route_entry *entry; |
| 3652 | int mmr_pnode; |
| 3653 | |
| 3654 | mmr_value = 0; |
| 3655 | entry = (struct uv_IO_APIC_route_entry *)&mmr_value; |
| 3656 | BUG_ON(sizeof(struct uv_IO_APIC_route_entry) != sizeof(unsigned long)); |
| 3657 | |
| 3658 | entry->mask = 1; |
| 3659 | |
| 3660 | mmr_pnode = uv_blade_to_pnode(mmr_blade); |
| 3661 | uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value); |
| 3662 | } |
| 3663 | #endif /* CONFIG_X86_64 */ |
| 3664 | |
Yinghai Lu | 9d6a4d0 | 2008-08-19 20:50:52 -0700 | [diff] [blame] | 3665 | int __init io_apic_get_redir_entries (int ioapic) |
| 3666 | { |
| 3667 | union IO_APIC_reg_01 reg_01; |
| 3668 | unsigned long flags; |
| 3669 | |
| 3670 | spin_lock_irqsave(&ioapic_lock, flags); |
| 3671 | reg_01.raw = io_apic_read(ioapic, 1); |
| 3672 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 3673 | |
| 3674 | return reg_01.bits.entries; |
| 3675 | } |
| 3676 | |
| 3677 | int __init probe_nr_irqs(void) |
| 3678 | { |
Thomas Gleixner | a1967d6 | 2008-11-21 11:16:48 -0800 | [diff] [blame] | 3679 | return NR_IRQS; |
Yinghai Lu | 9d6a4d0 | 2008-08-19 20:50:52 -0700 | [diff] [blame] | 3680 | } |
| 3681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3682 | /* -------------------------------------------------------------------------- |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3683 | ACPI-based IOAPIC Configuration |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3684 | -------------------------------------------------------------------------- */ |
| 3685 | |
Len Brown | 888ba6c | 2005-08-24 12:07:20 -0400 | [diff] [blame] | 3686 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3688 | #ifdef CONFIG_X86_32 |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 3689 | int __init io_apic_get_unique_id(int ioapic, int apic_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3690 | { |
| 3691 | union IO_APIC_reg_00 reg_00; |
| 3692 | static physid_mask_t apic_id_map = PHYSID_MASK_NONE; |
| 3693 | physid_mask_t tmp; |
| 3694 | unsigned long flags; |
| 3695 | int i = 0; |
| 3696 | |
| 3697 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 3698 | * The P4 platform supports up to 256 APIC IDs on two separate APIC |
| 3699 | * buses (one for LAPICs, one for IOAPICs), where predecessors only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | * supports up to 16 on one shared APIC bus. |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 3701 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3702 | * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full |
| 3703 | * advantage of new APIC bus architecture. |
| 3704 | */ |
| 3705 | |
| 3706 | if (physids_empty(apic_id_map)) |
| 3707 | apic_id_map = ioapic_phys_id_map(phys_cpu_present_map); |
| 3708 | |
| 3709 | spin_lock_irqsave(&ioapic_lock, flags); |
| 3710 | reg_00.raw = io_apic_read(ioapic, 0); |
| 3711 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 3712 | |
| 3713 | if (apic_id >= get_physical_broadcast()) { |
| 3714 | printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying " |
| 3715 | "%d\n", ioapic, apic_id, reg_00.bits.ID); |
| 3716 | apic_id = reg_00.bits.ID; |
| 3717 | } |
| 3718 | |
| 3719 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 3720 | * 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] | 3721 | * 'stuck on smp_invalidate_needed IPI wait' messages. |
| 3722 | */ |
| 3723 | if (check_apicid_used(apic_id_map, apic_id)) { |
| 3724 | |
| 3725 | for (i = 0; i < get_physical_broadcast(); i++) { |
| 3726 | if (!check_apicid_used(apic_id_map, i)) |
| 3727 | break; |
| 3728 | } |
| 3729 | |
| 3730 | if (i == get_physical_broadcast()) |
| 3731 | panic("Max apic_id exceeded!\n"); |
| 3732 | |
| 3733 | printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, " |
| 3734 | "trying %d\n", ioapic, apic_id, i); |
| 3735 | |
| 3736 | apic_id = i; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 3737 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | |
| 3739 | tmp = apicid_to_cpu_present(apic_id); |
| 3740 | physids_or(apic_id_map, apic_id_map, tmp); |
| 3741 | |
| 3742 | if (reg_00.bits.ID != apic_id) { |
| 3743 | reg_00.bits.ID = apic_id; |
| 3744 | |
| 3745 | spin_lock_irqsave(&ioapic_lock, flags); |
| 3746 | io_apic_write(ioapic, 0, reg_00.raw); |
| 3747 | reg_00.raw = io_apic_read(ioapic, 0); |
| 3748 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 3749 | |
| 3750 | /* Sanity check */ |
Andreas Deresch | 6070f9e | 2006-02-26 04:18:34 +0100 | [diff] [blame] | 3751 | if (reg_00.bits.ID != apic_id) { |
| 3752 | printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic); |
| 3753 | return -1; |
| 3754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 3758 | "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id); |
| 3759 | |
| 3760 | return apic_id; |
| 3761 | } |
| 3762 | |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 3763 | int __init io_apic_get_version(int ioapic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3764 | { |
| 3765 | union IO_APIC_reg_01 reg_01; |
| 3766 | unsigned long flags; |
| 3767 | |
| 3768 | spin_lock_irqsave(&ioapic_lock, flags); |
| 3769 | reg_01.raw = io_apic_read(ioapic, 1); |
| 3770 | spin_unlock_irqrestore(&ioapic_lock, flags); |
| 3771 | |
| 3772 | return reg_01.bits.version; |
| 3773 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3774 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3775 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3776 | int io_apic_set_pci_routing (int ioapic, int pin, int irq, int triggering, int polarity) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3778 | struct irq_desc *desc; |
| 3779 | struct irq_cfg *cfg; |
| 3780 | int cpu = boot_cpu_id; |
| 3781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3782 | if (!IO_APIC_IRQ(irq)) { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3783 | apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3784 | ioapic); |
| 3785 | return -EINVAL; |
| 3786 | } |
| 3787 | |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3788 | desc = irq_to_desc_alloc_cpu(irq, cpu); |
| 3789 | if (!desc) { |
| 3790 | printk(KERN_INFO "can not get irq_desc %d\n", irq); |
| 3791 | return 0; |
| 3792 | } |
| 3793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3795 | * IRQs < 16 are already in the irq_2_pin[] map |
| 3796 | */ |
Yinghai Lu | 99d093d | 2008-12-05 18:58:32 -0800 | [diff] [blame^] | 3797 | if (irq >= NR_IRQS_LEGACY) { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3798 | cfg = desc->chip_data; |
| 3799 | add_pin_to_irq_cpu(irq, cpu, ioapic, pin); |
| 3800 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3801 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3802 | setup_IO_APIC_irq(ioapic, pin, irq, triggering, polarity); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | |
| 3804 | return 0; |
| 3805 | } |
| 3806 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3807 | |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 3808 | int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity) |
| 3809 | { |
| 3810 | int i; |
| 3811 | |
| 3812 | if (skip_ioapic_setup) |
| 3813 | return -1; |
| 3814 | |
| 3815 | for (i = 0; i < mp_irq_entries; i++) |
Alexey Starikovskiy | 2fddb6e28 | 2008-05-14 19:03:17 +0400 | [diff] [blame] | 3816 | if (mp_irqs[i].mp_irqtype == mp_INT && |
| 3817 | mp_irqs[i].mp_srcbusirq == bus_irq) |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 3818 | break; |
| 3819 | if (i >= mp_irq_entries) |
| 3820 | return -1; |
| 3821 | |
| 3822 | *trigger = irq_trigger(i); |
| 3823 | *polarity = irq_polarity(i); |
| 3824 | return 0; |
| 3825 | } |
| 3826 | |
Len Brown | 888ba6c | 2005-08-24 12:07:20 -0400 | [diff] [blame] | 3827 | #endif /* CONFIG_ACPI */ |
Rusty Russell | 1a3f239 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 3828 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3829 | /* |
| 3830 | * This function currently is only a helper for the i386 smp boot process where |
| 3831 | * we need to reprogram the ioredtbls to cater for the cpus which have come online |
| 3832 | * so mask in all cases should simply be TARGET_CPUS |
| 3833 | */ |
| 3834 | #ifdef CONFIG_SMP |
| 3835 | void __init setup_ioapic_dest(void) |
| 3836 | { |
| 3837 | int pin, ioapic, irq, irq_entry; |
Thomas Gleixner | 6c2e940 | 2008-11-07 12:33:49 +0100 | [diff] [blame] | 3838 | struct irq_desc *desc; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3839 | struct irq_cfg *cfg; |
Thomas Gleixner | 6c2e940 | 2008-11-07 12:33:49 +0100 | [diff] [blame] | 3840 | cpumask_t mask; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3841 | |
| 3842 | if (skip_ioapic_setup == 1) |
| 3843 | return; |
| 3844 | |
| 3845 | for (ioapic = 0; ioapic < nr_ioapics; ioapic++) { |
| 3846 | for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) { |
| 3847 | irq_entry = find_irq_entry(ioapic, pin, mp_INT); |
| 3848 | if (irq_entry == -1) |
| 3849 | continue; |
| 3850 | irq = pin_2_irq(irq_entry, ioapic, pin); |
| 3851 | |
| 3852 | /* setup_IO_APIC_irqs could fail to get vector for some device |
| 3853 | * when you have too many devices, because at that time only boot |
| 3854 | * cpu is online. |
| 3855 | */ |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 3856 | desc = irq_to_desc(irq); |
| 3857 | cfg = desc->chip_data; |
Thomas Gleixner | 6c2e940 | 2008-11-07 12:33:49 +0100 | [diff] [blame] | 3858 | if (!cfg->vector) { |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3859 | setup_IO_APIC_irq(ioapic, pin, irq, |
| 3860 | irq_trigger(irq_entry), |
| 3861 | irq_polarity(irq_entry)); |
Thomas Gleixner | 6c2e940 | 2008-11-07 12:33:49 +0100 | [diff] [blame] | 3862 | continue; |
| 3863 | |
| 3864 | } |
| 3865 | |
| 3866 | /* |
| 3867 | * Honour affinities which have been set in early boot |
| 3868 | */ |
Thomas Gleixner | 6c2e940 | 2008-11-07 12:33:49 +0100 | [diff] [blame] | 3869 | if (desc->status & |
| 3870 | (IRQ_NO_BALANCING | IRQ_AFFINITY_SET)) |
| 3871 | mask = desc->affinity; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3872 | else |
Thomas Gleixner | 6c2e940 | 2008-11-07 12:33:49 +0100 | [diff] [blame] | 3873 | mask = TARGET_CPUS; |
| 3874 | |
| 3875 | #ifdef CONFIG_INTR_REMAP |
| 3876 | if (intr_remapping_enabled) |
| 3877 | set_ir_ioapic_affinity_irq(irq, mask); |
| 3878 | else |
| 3879 | #endif |
| 3880 | set_ioapic_affinity_irq(irq, mask); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 3881 | } |
| 3882 | |
| 3883 | } |
| 3884 | } |
| 3885 | #endif |
| 3886 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3887 | #define IOAPIC_RESOURCE_NAME_SIZE 11 |
| 3888 | |
| 3889 | static struct resource *ioapic_resources; |
| 3890 | |
| 3891 | static struct resource * __init ioapic_setup_resources(void) |
| 3892 | { |
| 3893 | unsigned long n; |
| 3894 | struct resource *res; |
| 3895 | char *mem; |
| 3896 | int i; |
| 3897 | |
| 3898 | if (nr_ioapics <= 0) |
| 3899 | return NULL; |
| 3900 | |
| 3901 | n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource); |
| 3902 | n *= nr_ioapics; |
| 3903 | |
| 3904 | mem = alloc_bootmem(n); |
| 3905 | res = (void *)mem; |
| 3906 | |
| 3907 | if (mem != NULL) { |
| 3908 | mem += sizeof(struct resource) * nr_ioapics; |
| 3909 | |
| 3910 | for (i = 0; i < nr_ioapics; i++) { |
| 3911 | res[i].name = mem; |
| 3912 | res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
| 3913 | sprintf(mem, "IOAPIC %u", i); |
| 3914 | mem += IOAPIC_RESOURCE_NAME_SIZE; |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | ioapic_resources = res; |
| 3919 | |
| 3920 | return res; |
| 3921 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3922 | |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3923 | void __init ioapic_init_mappings(void) |
| 3924 | { |
| 3925 | unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3926 | struct resource *ioapic_res; |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 3927 | int i; |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3928 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3929 | ioapic_res = ioapic_setup_resources(); |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3930 | for (i = 0; i < nr_ioapics; i++) { |
| 3931 | if (smp_found_config) { |
| 3932 | ioapic_phys = mp_ioapics[i].mp_apicaddr; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3933 | #ifdef CONFIG_X86_32 |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 3934 | if (!ioapic_phys) { |
| 3935 | printk(KERN_ERR |
| 3936 | "WARNING: bogus zero IO-APIC " |
| 3937 | "address found in MPTABLE, " |
| 3938 | "disabling IO/APIC support!\n"); |
| 3939 | smp_found_config = 0; |
| 3940 | skip_ioapic_setup = 1; |
| 3941 | goto fake_ioapic_page; |
| 3942 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3943 | #endif |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3944 | } else { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3945 | #ifdef CONFIG_X86_32 |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3946 | fake_ioapic_page: |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3947 | #endif |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3948 | ioapic_phys = (unsigned long) |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3949 | alloc_bootmem_pages(PAGE_SIZE); |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3950 | ioapic_phys = __pa(ioapic_phys); |
| 3951 | } |
| 3952 | set_fixmap_nocache(idx, ioapic_phys); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3953 | apic_printk(APIC_VERBOSE, |
| 3954 | "mapped IOAPIC to %08lx (%08lx)\n", |
| 3955 | __fix_to_virt(idx), ioapic_phys); |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3956 | idx++; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3957 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3958 | if (ioapic_res != NULL) { |
| 3959 | ioapic_res->start = ioapic_phys; |
| 3960 | ioapic_res->end = ioapic_phys + (4 * 1024) - 1; |
| 3961 | ioapic_res++; |
| 3962 | } |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 3963 | } |
| 3964 | } |
| 3965 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 3966 | static int __init ioapic_insert_resources(void) |
| 3967 | { |
| 3968 | int i; |
| 3969 | struct resource *r = ioapic_resources; |
| 3970 | |
| 3971 | if (!r) { |
| 3972 | printk(KERN_ERR |
| 3973 | "IO APIC resources could be not be allocated.\n"); |
| 3974 | return -1; |
| 3975 | } |
| 3976 | |
| 3977 | for (i = 0; i < nr_ioapics; i++) { |
| 3978 | insert_resource(&iomem_resource, r); |
| 3979 | r++; |
| 3980 | } |
| 3981 | |
| 3982 | return 0; |
| 3983 | } |
| 3984 | |
| 3985 | /* Insert the IO APIC resources after PCI initialization has occured to handle |
| 3986 | * IO APICS that are mapped in on a BAR in PCI space. */ |
| 3987 | late_initcall(ioapic_insert_resources); |