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