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