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