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