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