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