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