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