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 |
Thomas Gleixner | 1f93464 | 2015-04-14 10:29:58 +0800 | [diff] [blame] | 21 | * |
| 22 | * Historical information which is worth to be preserved: |
| 23 | * |
| 24 | * - SiS APIC rmw bug: |
| 25 | * |
| 26 | * We used to have a workaround for a bug in SiS chips which |
| 27 | * required to rewrite the index register for a read-modify-write |
| 28 | * operation as the chip lost the index information which was |
| 29 | * setup for the read already. We cache the data now, so that |
| 30 | * workaround has been removed. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/interrupt.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/sched.h> |
Yinghai Lu | d4057bd | 2008-08-19 20:50:38 -0700 | [diff] [blame] | 38 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/mc146818rtc.h> |
| 40 | #include <linux/compiler.h> |
| 41 | #include <linux/acpi.h> |
Paul Gortmaker | 186f436 | 2016-07-13 20:18:56 -0400 | [diff] [blame] | 42 | #include <linux/export.h> |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 43 | #include <linux/syscore_ops.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 44 | #include <linux/freezer.h> |
Eric W. Biederman | f26d6a2 | 2007-05-02 19:27:19 +0200 | [diff] [blame] | 45 | #include <linux/kthread.h> |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 46 | #include <linux/jiffies.h> /* time_after() */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 47 | #include <linux/slab.h> |
Yinghai Lu | d4057bd | 2008-08-19 20:50:38 -0700 | [diff] [blame] | 48 | #include <linux/bootmem.h> |
Ashok Raj | 54d5d42 | 2005-09-06 15:16:15 -0700 | [diff] [blame] | 49 | |
Thomas Gleixner | f7a0c78 | 2015-04-14 10:30:08 +0800 | [diff] [blame] | 50 | #include <asm/irqdomain.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <asm/io.h> |
| 52 | #include <asm/smp.h> |
Jaswinder Singh Rajput | 6d652ea | 2009-01-07 21:38:59 +0530 | [diff] [blame] | 53 | #include <asm/cpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #include <asm/desc.h> |
Yinghai Lu | d4057bd | 2008-08-19 20:50:38 -0700 | [diff] [blame] | 55 | #include <asm/proto.h> |
| 56 | #include <asm/acpi.h> |
| 57 | #include <asm/dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include <asm/timer.h> |
Ingo Molnar | 306e440 | 2005-06-30 02:58:55 -0700 | [diff] [blame] | 59 | #include <asm/i8259.h> |
Yinghai Lu | a4dbc34 | 2008-07-25 02:14:28 -0700 | [diff] [blame] | 60 | #include <asm/setup.h> |
Suresh Siddha | 8a8f422 | 2012-03-30 11:47:08 -0700 | [diff] [blame] | 61 | #include <asm/irq_remapping.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 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 66 | #define for_each_ioapic(idx) \ |
| 67 | for ((idx) = 0; (idx) < nr_ioapics; (idx)++) |
| 68 | #define for_each_ioapic_reverse(idx) \ |
| 69 | for ((idx) = nr_ioapics - 1; (idx) >= 0; (idx)--) |
| 70 | #define for_each_pin(idx, pin) \ |
| 71 | for ((pin) = 0; (pin) < ioapics[(idx)].nr_registers; (pin)++) |
| 72 | #define for_each_ioapic_pin(idx, pin) \ |
| 73 | for_each_ioapic((idx)) \ |
| 74 | for_each_pin((idx), (pin)) |
Cyrill Gorcunov | 2977fb3 | 2009-08-01 11:47:59 +0400 | [diff] [blame] | 75 | #define for_each_irq_pin(entry, head) \ |
Yinghai Lu | a178b87 | 2014-10-27 16:11:55 +0800 | [diff] [blame] | 76 | list_for_each_entry(entry, &head, list) |
Maciej W. Rozycki | 32f71af | 2008-07-21 00:52:49 +0100 | [diff] [blame] | 77 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 78 | static DEFINE_RAW_SPINLOCK(ioapic_lock); |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 79 | static DEFINE_MUTEX(ioapic_mutex); |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 80 | static unsigned int ioapic_dynirq_base; |
Jiang Liu | b81975e | 2014-06-09 16:20:11 +0800 | [diff] [blame] | 81 | static int ioapic_initialized; |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 82 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 83 | struct irq_pin_list { |
| 84 | struct list_head list; |
| 85 | int apic, pin; |
| 86 | }; |
| 87 | |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 88 | struct mp_chip_data { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 89 | struct list_head irq_2_pin; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 90 | struct IO_APIC_route_entry entry; |
| 91 | int trigger; |
| 92 | int polarity; |
Jiang Liu | 96ed44b | 2015-04-13 14:11:58 +0800 | [diff] [blame] | 93 | u32 count; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 94 | bool isa_irq; |
| 95 | }; |
| 96 | |
Jiang Liu | 154d9e5 | 2015-04-14 10:29:56 +0800 | [diff] [blame] | 97 | struct mp_ioapic_gsi { |
| 98 | u32 gsi_base; |
| 99 | u32 gsi_end; |
| 100 | }; |
| 101 | |
Suresh Siddha | b69c6c3 | 2011-05-18 16:31:35 -0700 | [diff] [blame] | 102 | static struct ioapic { |
| 103 | /* |
| 104 | * # of IRQ routing registers |
| 105 | */ |
| 106 | int nr_registers; |
Suresh Siddha | 57a6f74 | 2011-05-18 16:31:36 -0700 | [diff] [blame] | 107 | /* |
| 108 | * Saved state during suspend/resume, or while enabling intr-remap. |
| 109 | */ |
| 110 | struct IO_APIC_route_entry *saved_registers; |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 111 | /* I/O APIC config */ |
| 112 | struct mpc_ioapic mp_config; |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 113 | /* IO APIC gsi routing info */ |
| 114 | struct mp_ioapic_gsi gsi_config; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 115 | struct ioapic_domain_cfg irqdomain_cfg; |
| 116 | struct irq_domain *irqdomain; |
Jiang Liu | 15516a3 | 2014-10-27 13:21:46 +0800 | [diff] [blame] | 117 | struct resource *iomem_res; |
Suresh Siddha | b69c6c3 | 2011-05-18 16:31:35 -0700 | [diff] [blame] | 118 | } ioapics[MAX_IO_APICS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 120 | #define mpc_ioapic_ver(ioapic_idx) ioapics[ioapic_idx].mp_config.apicver |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 121 | |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 122 | int mpc_ioapic_id(int ioapic_idx) |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 123 | { |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 124 | return ioapics[ioapic_idx].mp_config.apicid; |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 127 | unsigned int mpc_ioapic_addr(int ioapic_idx) |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 128 | { |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 129 | return ioapics[ioapic_idx].mp_config.apicaddr; |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Jiang Liu | 154d9e5 | 2015-04-14 10:29:56 +0800 | [diff] [blame] | 132 | static inline struct mp_ioapic_gsi *mp_ioapic_gsi_routing(int ioapic_idx) |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 133 | { |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 134 | return &ioapics[ioapic_idx].gsi_config; |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 135 | } |
Alexey Starikovskiy | 9f640cc | 2008-04-04 23:41:13 +0400 | [diff] [blame] | 136 | |
Jiang Liu | 18e4855 | 2014-06-09 16:19:45 +0800 | [diff] [blame] | 137 | static inline int mp_ioapic_pin_count(int ioapic) |
| 138 | { |
| 139 | struct mp_ioapic_gsi *gsi_cfg = mp_ioapic_gsi_routing(ioapic); |
| 140 | |
| 141 | return gsi_cfg->gsi_end - gsi_cfg->gsi_base + 1; |
| 142 | } |
| 143 | |
Jiang Liu | 154d9e5 | 2015-04-14 10:29:56 +0800 | [diff] [blame] | 144 | static inline u32 mp_pin_to_gsi(int ioapic, int pin) |
Jiang Liu | 18e4855 | 2014-06-09 16:19:45 +0800 | [diff] [blame] | 145 | { |
| 146 | return mp_ioapic_gsi_routing(ioapic)->gsi_base + pin; |
| 147 | } |
| 148 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 149 | static inline bool mp_is_legacy_irq(int irq) |
| 150 | { |
| 151 | return irq >= 0 && irq < nr_legacy_irqs(); |
| 152 | } |
| 153 | |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 154 | /* |
| 155 | * Initialize all legacy IRQs and all pins on the first IOAPIC |
| 156 | * if we have legacy interrupt controller. Kernel boot option "pirq=" |
| 157 | * may rely on non-legacy pins on the first IOAPIC. |
| 158 | */ |
Jiang Liu | 18e4855 | 2014-06-09 16:19:45 +0800 | [diff] [blame] | 159 | static inline int mp_init_irq_at_boot(int ioapic, int irq) |
| 160 | { |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 161 | if (!nr_legacy_irqs()) |
| 162 | return 0; |
| 163 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 164 | return ioapic == 0 || mp_is_legacy_irq(irq); |
Jiang Liu | 18e4855 | 2014-06-09 16:19:45 +0800 | [diff] [blame] | 165 | } |
| 166 | |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 167 | static inline struct irq_domain *mp_ioapic_irqdomain(int ioapic) |
| 168 | { |
| 169 | return ioapics[ioapic].irqdomain; |
| 170 | } |
| 171 | |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 172 | int nr_ioapics; |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 173 | |
Eric W. Biederman | a4384df | 2010-06-08 11:44:32 -0700 | [diff] [blame] | 174 | /* The one past the highest gsi number used */ |
| 175 | u32 gsi_top; |
Eric W. Biederman | 5777372 | 2010-03-30 01:07:10 -0700 | [diff] [blame] | 176 | |
Alexey Starikovskiy | 584f734 | 2008-04-04 23:41:32 +0400 | [diff] [blame] | 177 | /* MP IRQ source entries */ |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 178 | struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES]; |
Alexey Starikovskiy | 584f734 | 2008-04-04 23:41:32 +0400 | [diff] [blame] | 179 | |
| 180 | /* # of MP IRQ source entries */ |
| 181 | int mp_irq_entries; |
| 182 | |
Paul Gortmaker | bb8187d | 2012-05-17 19:06:13 -0400 | [diff] [blame] | 183 | #ifdef CONFIG_EISA |
Alexey Starikovskiy | 8732fc4 | 2008-05-19 19:47:16 +0400 | [diff] [blame] | 184 | int mp_bus_id_to_type[MAX_MP_BUSSES]; |
| 185 | #endif |
| 186 | |
| 187 | DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES); |
| 188 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 189 | int skip_ioapic_setup; |
| 190 | |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 191 | /** |
| 192 | * disable_ioapic_support() - disables ioapic support at runtime |
| 193 | */ |
| 194 | void disable_ioapic_support(void) |
Ingo Molnar | 65a4e57 | 2009-01-31 03:36:17 +0100 | [diff] [blame] | 195 | { |
| 196 | #ifdef CONFIG_PCI |
| 197 | noioapicquirk = 1; |
| 198 | noioapicreroute = -1; |
| 199 | #endif |
| 200 | skip_ioapic_setup = 1; |
| 201 | } |
| 202 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 203 | static int __init parse_noapic(char *str) |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 204 | { |
| 205 | /* disable IO-APIC */ |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 206 | disable_ioapic_support(); |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | early_param("noapic", parse_noapic); |
Chuck Ebbert | 66759a0 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 210 | |
Feng Tang | 2d8009b | 2010-11-19 11:33:35 +0800 | [diff] [blame] | 211 | /* Will be called in mpparse/acpi/sfi codes for saving IRQ info */ |
| 212 | void mp_save_irq(struct mpc_intsrc *m) |
| 213 | { |
| 214 | int i; |
| 215 | |
| 216 | apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x," |
| 217 | " IRQ %02x, APIC ID %x, APIC INT %02x\n", |
| 218 | m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus, |
| 219 | m->srcbusirq, m->dstapic, m->dstirq); |
| 220 | |
| 221 | for (i = 0; i < mp_irq_entries; i++) { |
Feng Tang | 0e3fa13 | 2010-12-08 15:18:57 +0800 | [diff] [blame] | 222 | if (!memcmp(&mp_irqs[i], m, sizeof(*m))) |
Feng Tang | 2d8009b | 2010-11-19 11:33:35 +0800 | [diff] [blame] | 223 | return; |
| 224 | } |
| 225 | |
Feng Tang | 0e3fa13 | 2010-12-08 15:18:57 +0800 | [diff] [blame] | 226 | memcpy(&mp_irqs[mp_irq_entries], m, sizeof(*m)); |
Feng Tang | 2d8009b | 2010-11-19 11:33:35 +0800 | [diff] [blame] | 227 | if (++mp_irq_entries == MAX_IRQ_SOURCES) |
| 228 | panic("Max # of irq sources exceeded!!\n"); |
| 229 | } |
| 230 | |
Yinghai Lu | 7e89941 | 2014-10-27 13:21:39 +0800 | [diff] [blame] | 231 | static void alloc_ioapic_saved_registers(int idx) |
| 232 | { |
| 233 | size_t size; |
| 234 | |
| 235 | if (ioapics[idx].saved_registers) |
| 236 | return; |
| 237 | |
| 238 | size = sizeof(struct IO_APIC_route_entry) * ioapics[idx].nr_registers; |
| 239 | ioapics[idx].saved_registers = kzalloc(size, GFP_KERNEL); |
| 240 | if (!ioapics[idx].saved_registers) |
| 241 | pr_err("IOAPIC %d: suspend/resume impossible!\n", idx); |
| 242 | } |
| 243 | |
Jiang Liu | 15516a3 | 2014-10-27 13:21:46 +0800 | [diff] [blame] | 244 | static void free_ioapic_saved_registers(int idx) |
| 245 | { |
| 246 | kfree(ioapics[idx].saved_registers); |
| 247 | ioapics[idx].saved_registers = NULL; |
| 248 | } |
| 249 | |
Jiang Liu | 11d686e | 2014-10-27 16:12:05 +0800 | [diff] [blame] | 250 | int __init arch_early_ioapic_init(void) |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 251 | { |
Jiang Liu | 1331532 | 2015-04-13 14:11:56 +0800 | [diff] [blame] | 252 | int i; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 253 | |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 254 | if (!nr_legacy_irqs()) |
Jacob Pan | 1f91233 | 2010-02-05 04:06:56 -0800 | [diff] [blame] | 255 | io_apic_irqs = ~0UL; |
Jacob Pan | 1f91233 | 2010-02-05 04:06:56 -0800 | [diff] [blame] | 256 | |
Yinghai Lu | 7e89941 | 2014-10-27 13:21:39 +0800 | [diff] [blame] | 257 | for_each_ioapic(i) |
| 258 | alloc_ioapic_saved_registers(i); |
Suresh Siddha | 4c79185 | 2011-05-18 16:31:32 -0700 | [diff] [blame] | 259 | |
Yinghai Lu | 13a0c3c | 2008-12-26 02:05:47 -0800 | [diff] [blame] | 260 | return 0; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 261 | } |
| 262 | |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 263 | struct io_apic { |
| 264 | unsigned int index; |
| 265 | unsigned int unused[3]; |
| 266 | unsigned int data; |
Suresh Siddha | 0280f7c | 2009-03-16 17:05:01 -0700 | [diff] [blame] | 267 | unsigned int unused2[11]; |
| 268 | unsigned int eoi; |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 269 | }; |
| 270 | |
| 271 | static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx) |
| 272 | { |
| 273 | return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx) |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 274 | + (mpc_ioapic_addr(idx) & ~PAGE_MASK); |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Jiang Liu | ad66e1e | 2015-04-14 10:29:43 +0800 | [diff] [blame] | 277 | static inline void io_apic_eoi(unsigned int apic, unsigned int vector) |
Suresh Siddha | 0280f7c | 2009-03-16 17:05:01 -0700 | [diff] [blame] | 278 | { |
| 279 | struct io_apic __iomem *io_apic = io_apic_base(apic); |
| 280 | writel(vector, &io_apic->eoi); |
| 281 | } |
| 282 | |
Konrad Rzeszutek Wilk | 4a8e2a3 | 2012-03-28 12:37:36 -0400 | [diff] [blame] | 283 | unsigned int native_io_apic_read(unsigned int apic, unsigned int reg) |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 284 | { |
| 285 | struct io_apic __iomem *io_apic = io_apic_base(apic); |
| 286 | writel(reg, &io_apic->index); |
| 287 | return readl(&io_apic->data); |
| 288 | } |
| 289 | |
Jiang Liu | 9a93d47 | 2015-04-14 10:29:55 +0800 | [diff] [blame] | 290 | static void io_apic_write(unsigned int apic, unsigned int reg, |
| 291 | unsigned int value) |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 292 | { |
| 293 | struct io_apic __iomem *io_apic = io_apic_base(apic); |
Jeremy Fitzhardinge | 136d249 | 2012-03-21 22:58:08 -0400 | [diff] [blame] | 294 | |
Linus Torvalds | 130fe05 | 2006-11-01 09:11:00 -0800 | [diff] [blame] | 295 | writel(reg, &io_apic->index); |
| 296 | writel(value, &io_apic->data); |
| 297 | } |
| 298 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 299 | union entry_union { |
| 300 | struct { u32 w1, w2; }; |
| 301 | struct IO_APIC_route_entry entry; |
| 302 | }; |
| 303 | |
Suresh Siddha | e57253a | 2011-08-25 12:01:12 -0700 | [diff] [blame] | 304 | static struct IO_APIC_route_entry __ioapic_read_entry(int apic, int pin) |
| 305 | { |
| 306 | union entry_union eu; |
| 307 | |
| 308 | eu.w1 = io_apic_read(apic, 0x10 + 2 * pin); |
| 309 | eu.w2 = io_apic_read(apic, 0x11 + 2 * pin); |
Jeremy Fitzhardinge | 136d249 | 2012-03-21 22:58:08 -0400 | [diff] [blame] | 310 | |
Suresh Siddha | e57253a | 2011-08-25 12:01:12 -0700 | [diff] [blame] | 311 | return eu.entry; |
| 312 | } |
| 313 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 314 | static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin) |
| 315 | { |
| 316 | union entry_union eu; |
| 317 | unsigned long flags; |
Jeremy Fitzhardinge | 136d249 | 2012-03-21 22:58:08 -0400 | [diff] [blame] | 318 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 319 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Suresh Siddha | e57253a | 2011-08-25 12:01:12 -0700 | [diff] [blame] | 320 | eu.entry = __ioapic_read_entry(apic, pin); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 321 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Jeremy Fitzhardinge | 136d249 | 2012-03-21 22:58:08 -0400 | [diff] [blame] | 322 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 323 | return eu.entry; |
| 324 | } |
| 325 | |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 326 | /* |
| 327 | * When we write a new IO APIC routing entry, we need to write the high |
| 328 | * word first! If the mask bit in the low word is clear, we will enable |
| 329 | * the interrupt, and we need to make sure the entry is fully populated |
| 330 | * before that happens. |
| 331 | */ |
Jeremy Fitzhardinge | 136d249 | 2012-03-21 22:58:08 -0400 | [diff] [blame] | 332 | static void __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e) |
Andi Kleen | d15512f | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 333 | { |
Figo.zhang | 50a8d4d2 | 2009-06-17 22:25:20 +0800 | [diff] [blame] | 334 | union entry_union eu = {{0, 0}}; |
| 335 | |
Andi Kleen | d15512f | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 336 | eu.entry = e; |
| 337 | io_apic_write(apic, 0x11 + 2*pin, eu.w2); |
| 338 | io_apic_write(apic, 0x10 + 2*pin, eu.w1); |
| 339 | } |
| 340 | |
Thomas Gleixner | 1a8ce7f | 2010-10-04 21:08:56 +0200 | [diff] [blame] | 341 | 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] | 342 | { |
| 343 | unsigned long flags; |
Jeremy Fitzhardinge | 136d249 | 2012-03-21 22:58:08 -0400 | [diff] [blame] | 344 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 345 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Andi Kleen | d15512f | 2006-12-07 02:14:07 +0100 | [diff] [blame] | 346 | __ioapic_write_entry(apic, pin, e); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 347 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* |
| 351 | * When we mask an IO APIC routing entry, we need to write the low |
| 352 | * word first, in order to set the mask bit before we change the |
| 353 | * high bits! |
| 354 | */ |
| 355 | static void ioapic_mask_entry(int apic, int pin) |
| 356 | { |
| 357 | unsigned long flags; |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 358 | union entry_union eu = { .entry.mask = IOAPIC_MASKED }; |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 359 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 360 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 361 | io_apic_write(apic, 0x10 + 2*pin, eu.w1); |
| 362 | io_apic_write(apic, 0x11 + 2*pin, eu.w2); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 363 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | /* |
| 367 | * The common case is 1:1 IRQ<->pin mappings. Sometimes there are |
| 368 | * shared ISA-space IRQs, so we have to support them. We are super |
| 369 | * fast in the common case, and fast for shared ISA-space IRQs. |
| 370 | */ |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 371 | static int __add_pin_to_irq_node(struct mp_chip_data *data, |
| 372 | int node, int apic, int pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | { |
Yinghai Lu | a178b87 | 2014-10-27 16:11:55 +0800 | [diff] [blame] | 374 | struct irq_pin_list *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Cyrill Gorcunov | 2977fb3 | 2009-08-01 11:47:59 +0400 | [diff] [blame] | 376 | /* don't allow duplicates */ |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 377 | for_each_irq_pin(entry, data->irq_2_pin) |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 378 | if (entry->apic == apic && entry->pin == pin) |
Cyrill Gorcunov | f3d1915 | 2009-08-06 00:09:31 +0400 | [diff] [blame] | 379 | return 0; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 380 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 381 | entry = kzalloc_node(sizeof(struct irq_pin_list), GFP_ATOMIC, node); |
Cyrill Gorcunov | a7428cd | 2009-08-01 11:48:00 +0400 | [diff] [blame] | 382 | if (!entry) { |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 383 | pr_err("can not alloc irq_pin_list (%d,%d,%d)\n", |
| 384 | node, apic, pin); |
Cyrill Gorcunov | f3d1915 | 2009-08-06 00:09:31 +0400 | [diff] [blame] | 385 | return -ENOMEM; |
Cyrill Gorcunov | a7428cd | 2009-08-01 11:48:00 +0400 | [diff] [blame] | 386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | entry->apic = apic; |
| 388 | entry->pin = pin; |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 389 | list_add_tail(&entry->list, &data->irq_2_pin); |
Jeremy Fitzhardinge | 875e68e | 2009-06-08 03:24:11 -0700 | [diff] [blame] | 390 | |
Cyrill Gorcunov | f3d1915 | 2009-08-06 00:09:31 +0400 | [diff] [blame] | 391 | return 0; |
| 392 | } |
| 393 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 394 | static void __remove_pin_from_irq(struct mp_chip_data *data, int apic, int pin) |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 395 | { |
Yinghai Lu | a178b87 | 2014-10-27 16:11:55 +0800 | [diff] [blame] | 396 | struct irq_pin_list *tmp, *entry; |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 397 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 398 | list_for_each_entry_safe(entry, tmp, &data->irq_2_pin, list) |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 399 | if (entry->apic == apic && entry->pin == pin) { |
Yinghai Lu | a178b87 | 2014-10-27 16:11:55 +0800 | [diff] [blame] | 400 | list_del(&entry->list); |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 401 | kfree(entry); |
| 402 | return; |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 403 | } |
| 404 | } |
| 405 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 406 | static void add_pin_to_irq_node(struct mp_chip_data *data, |
| 407 | int node, int apic, int pin) |
Cyrill Gorcunov | f3d1915 | 2009-08-06 00:09:31 +0400 | [diff] [blame] | 408 | { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 409 | if (__add_pin_to_irq_node(data, node, apic, pin)) |
Cyrill Gorcunov | f3d1915 | 2009-08-06 00:09:31 +0400 | [diff] [blame] | 410 | panic("IO-APIC: failed to add irq-pin. Can not proceed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Reroute an IRQ to a different pin. |
| 415 | */ |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 416 | static void __init replace_pin_at_irq_node(struct mp_chip_data *data, int node, |
Jeremy Fitzhardinge | 4eea6ff | 2009-06-08 03:32:15 -0700 | [diff] [blame] | 417 | int oldapic, int oldpin, |
| 418 | int newapic, int newpin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Jeremy Fitzhardinge | 535b642 | 2009-06-08 03:29:26 -0700 | [diff] [blame] | 420 | struct irq_pin_list *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 422 | for_each_irq_pin(entry, data->irq_2_pin) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | if (entry->apic == oldapic && entry->pin == oldpin) { |
| 424 | entry->apic = newapic; |
| 425 | entry->pin = newpin; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 426 | /* every one is different, right? */ |
Jeremy Fitzhardinge | 4eea6ff | 2009-06-08 03:32:15 -0700 | [diff] [blame] | 427 | return; |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
Yinghai Lu | 0f978f4 | 2008-08-19 20:50:26 -0700 | [diff] [blame] | 430 | |
Jeremy Fitzhardinge | 4eea6ff | 2009-06-08 03:32:15 -0700 | [diff] [blame] | 431 | /* old apic/pin didn't exist, so just add new ones */ |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 432 | add_pin_to_irq_node(data, node, newapic, newpin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 435 | static void io_apic_modify_irq(struct mp_chip_data *data, |
Jeremy Fitzhardinge | 2f210de | 2009-06-08 02:55:22 -0700 | [diff] [blame] | 436 | int mask_and, int mask_or, |
| 437 | void (*final)(struct irq_pin_list *entry)) |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 438 | { |
Jiang Liu | 0be275e | 2015-04-14 10:29:57 +0800 | [diff] [blame] | 439 | union entry_union eu; |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 440 | struct irq_pin_list *entry; |
| 441 | |
Jiang Liu | 0be275e | 2015-04-14 10:29:57 +0800 | [diff] [blame] | 442 | eu.entry = data->entry; |
| 443 | eu.w1 &= mask_and; |
| 444 | eu.w1 |= mask_or; |
| 445 | data->entry = eu.entry; |
| 446 | |
| 447 | for_each_irq_pin(entry, data->irq_2_pin) { |
| 448 | io_apic_write(entry->apic, 0x10 + 2 * entry->pin, eu.w1); |
| 449 | if (final) |
| 450 | final(entry); |
| 451 | } |
Suresh Siddha | c29d9db | 2009-12-01 15:31:16 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Jaswinder Singh Rajput | 7f3e632 | 2008-12-29 20:34:35 +0530 | [diff] [blame] | 454 | static void io_apic_sync(struct irq_pin_list *entry) |
Yinghai Lu | 4e738e2 | 2008-08-19 20:50:47 -0700 | [diff] [blame] | 455 | { |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 456 | /* |
| 457 | * Synchronize the IO-APIC and the CPU by doing |
| 458 | * a dummy read from the IO-APIC |
| 459 | */ |
| 460 | struct io_apic __iomem *io_apic; |
Jeremy Fitzhardinge | 136d249 | 2012-03-21 22:58:08 -0400 | [diff] [blame] | 461 | |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 462 | io_apic = io_apic_base(entry->apic); |
Yinghai Lu | 4e738e2 | 2008-08-19 20:50:47 -0700 | [diff] [blame] | 463 | readl(&io_apic->data); |
| 464 | } |
| 465 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 466 | static void mask_ioapic_irq(struct irq_data *irq_data) |
Cyrill Gorcunov | 87783be | 2008-09-10 22:19:50 +0400 | [diff] [blame] | 467 | { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 468 | struct mp_chip_data *data = irq_data->chip_data; |
Thomas Gleixner | dd5f15e | 2010-09-28 15:18:35 +0200 | [diff] [blame] | 469 | unsigned long flags; |
| 470 | |
| 471 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 472 | io_apic_modify_irq(data, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 473 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 476 | static void __unmask_ioapic(struct mp_chip_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 478 | io_apic_modify_irq(data, ~IO_APIC_REDIR_MASKED, 0, NULL); |
Thomas Gleixner | dd5f15e | 2010-09-28 15:18:35 +0200 | [diff] [blame] | 479 | } |
| 480 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 481 | static void unmask_ioapic_irq(struct irq_data *irq_data) |
Thomas Gleixner | dd5f15e | 2010-09-28 15:18:35 +0200 | [diff] [blame] | 482 | { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 483 | struct mp_chip_data *data = irq_data->chip_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | unsigned long flags; |
| 485 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 486 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 487 | __unmask_ioapic(data); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 488 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Suresh Siddha | c020570 | 2011-08-25 12:01:13 -0700 | [diff] [blame] | 491 | /* |
| 492 | * IO-APIC versions below 0x20 don't support EOI register. |
| 493 | * For the record, here is the information about various versions: |
| 494 | * 0Xh 82489DX |
| 495 | * 1Xh I/OAPIC or I/O(x)APIC which are not PCI 2.2 Compliant |
| 496 | * 2Xh I/O(x)APIC which is PCI 2.2 Compliant |
| 497 | * 30h-FFh Reserved |
| 498 | * |
| 499 | * Some of the Intel ICH Specs (ICH2 to ICH5) documents the io-apic |
| 500 | * version as 0x2. This is an error with documentation and these ICH chips |
| 501 | * use io-apic's of version 0x20. |
| 502 | * |
| 503 | * For IO-APIC's with EOI register, we use that to do an explicit EOI. |
| 504 | * Otherwise, we simulate the EOI message manually by changing the trigger |
| 505 | * mode to edge and then back to level, with RTE being masked during this. |
| 506 | */ |
Jiang Liu | ad66e1e | 2015-04-14 10:29:43 +0800 | [diff] [blame] | 507 | static void __eoi_ioapic_pin(int apic, int pin, int vector) |
Suresh Siddha | c020570 | 2011-08-25 12:01:13 -0700 | [diff] [blame] | 508 | { |
| 509 | if (mpc_ioapic_ver(apic) >= 0x20) { |
Joerg Roedel | da16532 | 2012-09-26 12:44:50 +0200 | [diff] [blame] | 510 | io_apic_eoi(apic, vector); |
Suresh Siddha | c020570 | 2011-08-25 12:01:13 -0700 | [diff] [blame] | 511 | } else { |
| 512 | struct IO_APIC_route_entry entry, entry1; |
| 513 | |
| 514 | entry = entry1 = __ioapic_read_entry(apic, pin); |
| 515 | |
| 516 | /* |
| 517 | * Mask the entry and change the trigger mode to edge. |
| 518 | */ |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 519 | entry1.mask = IOAPIC_MASKED; |
Suresh Siddha | c020570 | 2011-08-25 12:01:13 -0700 | [diff] [blame] | 520 | entry1.trigger = IOAPIC_EDGE; |
| 521 | |
| 522 | __ioapic_write_entry(apic, pin, entry1); |
| 523 | |
| 524 | /* |
| 525 | * Restore the previous level triggered entry. |
| 526 | */ |
| 527 | __ioapic_write_entry(apic, pin, entry); |
| 528 | } |
| 529 | } |
| 530 | |
Andy Shevchenko | 4faefda | 2015-10-09 17:24:45 +0300 | [diff] [blame] | 531 | static void eoi_ioapic_pin(int vector, struct mp_chip_data *data) |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 532 | { |
| 533 | unsigned long flags; |
| 534 | struct irq_pin_list *entry; |
| 535 | |
| 536 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 537 | for_each_irq_pin(entry, data->irq_2_pin) |
Jiang Liu | ad66e1e | 2015-04-14 10:29:43 +0800 | [diff] [blame] | 538 | __eoi_ioapic_pin(entry->apic, entry->pin, vector); |
Suresh Siddha | c020570 | 2011-08-25 12:01:13 -0700 | [diff] [blame] | 539 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
| 540 | } |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin) |
| 543 | { |
| 544 | struct IO_APIC_route_entry entry; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | /* 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] | 547 | entry = ioapic_read_entry(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | if (entry.delivery_mode == dest_SMI) |
| 549 | return; |
Suresh Siddha | 1e75b31 | 2011-08-25 12:01:11 -0700 | [diff] [blame] | 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | /* |
Suresh Siddha | 1e75b31 | 2011-08-25 12:01:11 -0700 | [diff] [blame] | 552 | * Make sure the entry is masked and re-read the contents to check |
| 553 | * if it is a level triggered pin and if the remote-IRR is set. |
| 554 | */ |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 555 | if (entry.mask == IOAPIC_UNMASKED) { |
| 556 | entry.mask = IOAPIC_MASKED; |
Suresh Siddha | 1e75b31 | 2011-08-25 12:01:11 -0700 | [diff] [blame] | 557 | ioapic_write_entry(apic, pin, entry); |
| 558 | entry = ioapic_read_entry(apic, pin); |
| 559 | } |
| 560 | |
| 561 | if (entry.irr) { |
Suresh Siddha | c020570 | 2011-08-25 12:01:13 -0700 | [diff] [blame] | 562 | unsigned long flags; |
| 563 | |
Suresh Siddha | 1e75b31 | 2011-08-25 12:01:11 -0700 | [diff] [blame] | 564 | /* |
| 565 | * Make sure the trigger mode is set to level. Explicit EOI |
| 566 | * doesn't clear the remote-IRR if the trigger mode is not |
| 567 | * set to level. |
| 568 | */ |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 569 | if (entry.trigger == IOAPIC_EDGE) { |
Suresh Siddha | 1e75b31 | 2011-08-25 12:01:11 -0700 | [diff] [blame] | 570 | entry.trigger = IOAPIC_LEVEL; |
| 571 | ioapic_write_entry(apic, pin, entry); |
| 572 | } |
Suresh Siddha | c020570 | 2011-08-25 12:01:13 -0700 | [diff] [blame] | 573 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Jiang Liu | ad66e1e | 2015-04-14 10:29:43 +0800 | [diff] [blame] | 574 | __eoi_ioapic_pin(apic, pin, entry.vector); |
Suresh Siddha | c020570 | 2011-08-25 12:01:13 -0700 | [diff] [blame] | 575 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Suresh Siddha | 1e75b31 | 2011-08-25 12:01:11 -0700 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | /* |
| 579 | * Clear the rest of the bits in the IO-APIC RTE except for the mask |
| 580 | * bit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | */ |
Linus Torvalds | f9dadfa | 2006-11-01 10:05:35 -0800 | [diff] [blame] | 582 | ioapic_mask_entry(apic, pin); |
Suresh Siddha | 1e75b31 | 2011-08-25 12:01:11 -0700 | [diff] [blame] | 583 | entry = ioapic_read_entry(apic, pin); |
| 584 | if (entry.irr) |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 585 | pr_err("Unable to reset IRR for apic: %d, pin :%d\n", |
Suresh Siddha | 1e75b31 | 2011-08-25 12:01:11 -0700 | [diff] [blame] | 586 | mpc_ioapic_id(apic), pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 589 | static void clear_IO_APIC (void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
| 591 | int apic, pin; |
| 592 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 593 | for_each_ioapic_pin(apic, pin) |
| 594 | clear_IO_APIC_pin(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 597 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | /* |
| 599 | * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to |
| 600 | * specific CPU-side IRQs. |
| 601 | */ |
| 602 | |
| 603 | #define MAX_PIRQS 8 |
Yinghai Lu | 3bd25d0 | 2009-02-15 02:54:03 -0800 | [diff] [blame] | 604 | static int pirq_entries[MAX_PIRQS] = { |
| 605 | [0 ... MAX_PIRQS - 1] = -1 |
| 606 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | static int __init ioapic_pirq_setup(char *str) |
| 609 | { |
| 610 | int i, max; |
| 611 | int ints[MAX_PIRQS+1]; |
| 612 | |
| 613 | get_options(str, ARRAY_SIZE(ints), ints); |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 616 | "PIRQ redirection, working around broken MP-BIOS.\n"); |
| 617 | max = MAX_PIRQS; |
| 618 | if (ints[0] < MAX_PIRQS) |
| 619 | max = ints[0]; |
| 620 | |
| 621 | for (i = 0; i < max; i++) { |
| 622 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 623 | "... PIRQ%d -> IRQ %d\n", i, ints[i+1]); |
| 624 | /* |
| 625 | * PIRQs are mapped upside down, usually. |
| 626 | */ |
| 627 | pirq_entries[MAX_PIRQS-i-1] = ints[i+1]; |
| 628 | } |
| 629 | return 1; |
| 630 | } |
| 631 | |
| 632 | __setup("pirq=", ioapic_pirq_setup); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 633 | #endif /* CONFIG_X86_32 */ |
| 634 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 635 | /* |
Suresh Siddha | 05c3dc2 | 2009-03-16 17:05:03 -0700 | [diff] [blame] | 636 | * Saves all the IO-APIC RTE's |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 637 | */ |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 638 | int save_ioapic_entries(void) |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 639 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 640 | int apic, pin; |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 641 | int err = 0; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 642 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 643 | for_each_ioapic(apic) { |
Suresh Siddha | 57a6f74 | 2011-05-18 16:31:36 -0700 | [diff] [blame] | 644 | if (!ioapics[apic].saved_registers) { |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 645 | err = -ENOMEM; |
| 646 | continue; |
| 647 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 648 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 649 | for_each_pin(apic, pin) |
Suresh Siddha | 57a6f74 | 2011-05-18 16:31:36 -0700 | [diff] [blame] | 650 | ioapics[apic].saved_registers[pin] = |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 651 | ioapic_read_entry(apic, pin); |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 652 | } |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 653 | |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 654 | return err; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 655 | } |
| 656 | |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 657 | /* |
| 658 | * Mask all IO APIC entries. |
| 659 | */ |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 660 | void mask_ioapic_entries(void) |
Suresh Siddha | 05c3dc2 | 2009-03-16 17:05:03 -0700 | [diff] [blame] | 661 | { |
| 662 | int apic, pin; |
| 663 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 664 | for_each_ioapic(apic) { |
Suresh Siddha | 2f344d2 | 2011-05-24 10:45:31 -0700 | [diff] [blame] | 665 | if (!ioapics[apic].saved_registers) |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 666 | continue; |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 667 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 668 | for_each_pin(apic, pin) { |
Suresh Siddha | 05c3dc2 | 2009-03-16 17:05:03 -0700 | [diff] [blame] | 669 | struct IO_APIC_route_entry entry; |
| 670 | |
Suresh Siddha | 57a6f74 | 2011-05-18 16:31:36 -0700 | [diff] [blame] | 671 | entry = ioapics[apic].saved_registers[pin]; |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 672 | if (entry.mask == IOAPIC_UNMASKED) { |
| 673 | entry.mask = IOAPIC_MASKED; |
Suresh Siddha | 05c3dc2 | 2009-03-16 17:05:03 -0700 | [diff] [blame] | 674 | ioapic_write_entry(apic, pin, entry); |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 680 | /* |
Suresh Siddha | 57a6f74 | 2011-05-18 16:31:36 -0700 | [diff] [blame] | 681 | * Restore IO APIC entries which was saved in the ioapic structure. |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 682 | */ |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 683 | int restore_ioapic_entries(void) |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 684 | { |
| 685 | int apic, pin; |
| 686 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 687 | for_each_ioapic(apic) { |
Suresh Siddha | 2f344d2 | 2011-05-24 10:45:31 -0700 | [diff] [blame] | 688 | if (!ioapics[apic].saved_registers) |
Suresh Siddha | 31dce14 | 2011-05-18 16:31:33 -0700 | [diff] [blame] | 689 | continue; |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 690 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 691 | for_each_pin(apic, pin) |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 692 | ioapic_write_entry(apic, pin, |
Suresh Siddha | 57a6f74 | 2011-05-18 16:31:36 -0700 | [diff] [blame] | 693 | ioapics[apic].saved_registers[pin]); |
Cyrill Gorcunov | 5ffa4eb | 2008-09-18 23:37:57 +0400 | [diff] [blame] | 694 | } |
Fenghua Yu | b24696b | 2009-03-27 14:22:44 -0700 | [diff] [blame] | 695 | return 0; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 696 | } |
| 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | /* |
| 699 | * Find the IRQ entry number of a certain pin. |
| 700 | */ |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 701 | static int find_irq_entry(int ioapic_idx, int pin, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | { |
| 703 | int i; |
| 704 | |
| 705 | for (i = 0; i < mp_irq_entries; i++) |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 706 | if (mp_irqs[i].irqtype == type && |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 707 | (mp_irqs[i].dstapic == mpc_ioapic_id(ioapic_idx) || |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 708 | mp_irqs[i].dstapic == MP_APIC_ALL) && |
| 709 | mp_irqs[i].dstirq == pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | return i; |
| 711 | |
| 712 | return -1; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | * Find the pin to which IRQ[irq] (ISA) is connected |
| 717 | */ |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 718 | static int __init find_isa_irq_pin(int irq, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
| 720 | int i; |
| 721 | |
| 722 | for (i = 0; i < mp_irq_entries; i++) { |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 723 | int lbus = mp_irqs[i].srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Alexey Starikovskiy | d27e2b8 | 2008-03-20 14:54:18 +0300 | [diff] [blame] | 725 | if (test_bit(lbus, mp_bus_not_pci) && |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 726 | (mp_irqs[i].irqtype == type) && |
| 727 | (mp_irqs[i].srcbusirq == irq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 729 | return mp_irqs[i].dstirq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } |
| 731 | return -1; |
| 732 | } |
| 733 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 734 | static int __init find_isa_irq_apic(int irq, int type) |
| 735 | { |
| 736 | int i; |
| 737 | |
| 738 | for (i = 0; i < mp_irq_entries; i++) { |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 739 | int lbus = mp_irqs[i].srcbus; |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 740 | |
Alexey Starikovskiy | 73b2961 | 2008-03-20 14:54:24 +0300 | [diff] [blame] | 741 | if (test_bit(lbus, mp_bus_not_pci) && |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 742 | (mp_irqs[i].irqtype == type) && |
| 743 | (mp_irqs[i].srcbusirq == irq)) |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 744 | break; |
| 745 | } |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 746 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 747 | if (i < mp_irq_entries) { |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 748 | int ioapic_idx; |
| 749 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 750 | for_each_ioapic(ioapic_idx) |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 751 | if (mpc_ioapic_id(ioapic_idx) == mp_irqs[i].dstapic) |
| 752 | return ioapic_idx; |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | return -1; |
| 756 | } |
| 757 | |
Paul Gortmaker | bb8187d | 2012-05-17 19:06:13 -0400 | [diff] [blame] | 758 | #ifdef CONFIG_EISA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | /* |
| 760 | * EISA Edge/Level control register, ELCR |
| 761 | */ |
| 762 | static int EISA_ELCR(unsigned int irq) |
| 763 | { |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 764 | if (irq < nr_legacy_irqs()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | unsigned int port = 0x4d0 + (irq >> 3); |
| 766 | return (inb(port) >> (irq & 7)) & 1; |
| 767 | } |
| 768 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 769 | "Broken MPtable reports ISA irq %d\n", irq); |
| 770 | return 0; |
| 771 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 772 | |
Alexey Starikovskiy | c0a282c | 2008-03-20 14:55:02 +0300 | [diff] [blame] | 773 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 775 | /* ISA interrupts are always active high edge triggered, |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 776 | * when listed as conforming in the MP table. */ |
| 777 | |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 778 | #define default_ISA_trigger(idx) (IOAPIC_EDGE) |
| 779 | #define default_ISA_polarity(idx) (IOAPIC_POL_HIGH) |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | /* EISA interrupts are always polarity zero and can be edge or level |
| 782 | * trigger depending on the ELCR value. If an interrupt is listed as |
| 783 | * EISA conforming in the MP table, that means its trigger type must |
| 784 | * be read in from the ELCR */ |
| 785 | |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 786 | #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].srcbusirq)) |
Alexey Starikovskiy | 6728801 | 2008-03-20 14:54:36 +0300 | [diff] [blame] | 787 | #define default_EISA_polarity(idx) default_ISA_polarity(idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 789 | /* PCI interrupts are always active low level triggered, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | * when listed as conforming in the MP table. */ |
| 791 | |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 792 | #define default_PCI_trigger(idx) (IOAPIC_LEVEL) |
| 793 | #define default_PCI_polarity(idx) (IOAPIC_POL_LOW) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
Thomas Gleixner | b77cf6a | 2011-02-23 17:33:53 +0100 | [diff] [blame] | 795 | static int irq_polarity(int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | { |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 797 | int bus = mp_irqs[idx].srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | /* |
| 800 | * Determine IRQ line polarity (high active or low active): |
| 801 | */ |
Thomas Gleixner | ab76085 | 2015-04-14 10:30:07 +0800 | [diff] [blame] | 802 | switch (mp_irqs[idx].irqflag & 0x03) { |
| 803 | case 0: |
| 804 | /* conforms to spec, ie. bus-type dependent polarity */ |
| 805 | if (test_bit(bus, mp_bus_not_pci)) |
| 806 | return default_ISA_polarity(idx); |
| 807 | else |
| 808 | return default_PCI_polarity(idx); |
| 809 | case 1: |
| 810 | return IOAPIC_POL_HIGH; |
| 811 | case 2: |
| 812 | pr_warn("IOAPIC: Invalid polarity: 2, defaulting to low\n"); |
| 813 | case 3: |
| 814 | default: /* Pointless default required due to do gcc stupidity */ |
| 815 | return IOAPIC_POL_LOW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | |
Thomas Gleixner | ab76085 | 2015-04-14 10:30:07 +0800 | [diff] [blame] | 819 | #ifdef CONFIG_EISA |
| 820 | static int eisa_irq_trigger(int idx, int bus, int trigger) |
| 821 | { |
| 822 | switch (mp_bus_id_to_type[bus]) { |
| 823 | case MP_BUS_PCI: |
| 824 | case MP_BUS_ISA: |
| 825 | return trigger; |
| 826 | case MP_BUS_EISA: |
| 827 | return default_EISA_trigger(idx); |
| 828 | } |
| 829 | pr_warn("IOAPIC: Invalid srcbus: %d defaulting to level\n", bus); |
| 830 | return IOAPIC_LEVEL; |
| 831 | } |
| 832 | #else |
| 833 | static inline int eisa_irq_trigger(int idx, int bus, int trigger) |
| 834 | { |
| 835 | return trigger; |
| 836 | } |
| 837 | #endif |
| 838 | |
Thomas Gleixner | b77cf6a | 2011-02-23 17:33:53 +0100 | [diff] [blame] | 839 | static int irq_trigger(int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | { |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 841 | int bus = mp_irqs[idx].srcbus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | int trigger; |
| 843 | |
| 844 | /* |
| 845 | * Determine IRQ trigger mode (edge or level sensitive): |
| 846 | */ |
Thomas Gleixner | ab76085 | 2015-04-14 10:30:07 +0800 | [diff] [blame] | 847 | switch ((mp_irqs[idx].irqflag >> 2) & 0x03) { |
| 848 | case 0: |
| 849 | /* conforms to spec, ie. bus-type dependent trigger mode */ |
| 850 | if (test_bit(bus, mp_bus_not_pci)) |
| 851 | trigger = default_ISA_trigger(idx); |
| 852 | else |
| 853 | trigger = default_PCI_trigger(idx); |
| 854 | /* Take EISA into account */ |
| 855 | return eisa_irq_trigger(idx, bus, trigger); |
| 856 | case 1: |
| 857 | return IOAPIC_EDGE; |
| 858 | case 2: |
| 859 | pr_warn("IOAPIC: Invalid trigger mode 2 defaulting to level\n"); |
| 860 | case 3: |
| 861 | default: /* Pointless default required due to do gcc stupidity */ |
| 862 | return IOAPIC_LEVEL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 866 | void ioapic_set_alloc_attr(struct irq_alloc_info *info, int node, |
| 867 | int trigger, int polarity) |
| 868 | { |
| 869 | init_irq_alloc_info(info, NULL); |
| 870 | info->type = X86_IRQ_ALLOC_TYPE_IOAPIC; |
| 871 | info->ioapic_node = node; |
| 872 | info->ioapic_trigger = trigger; |
| 873 | info->ioapic_polarity = polarity; |
| 874 | info->ioapic_valid = 1; |
| 875 | } |
| 876 | |
Jiang Liu | 96ed44b | 2015-04-13 14:11:58 +0800 | [diff] [blame] | 877 | #ifndef CONFIG_ACPI |
| 878 | int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity); |
| 879 | #endif |
| 880 | |
| 881 | static void ioapic_copy_alloc_attr(struct irq_alloc_info *dst, |
| 882 | struct irq_alloc_info *src, |
| 883 | u32 gsi, int ioapic_idx, int pin) |
| 884 | { |
| 885 | int trigger, polarity; |
| 886 | |
| 887 | copy_irq_alloc_info(dst, src); |
| 888 | dst->type = X86_IRQ_ALLOC_TYPE_IOAPIC; |
| 889 | dst->ioapic_id = mpc_ioapic_id(ioapic_idx); |
| 890 | dst->ioapic_pin = pin; |
| 891 | dst->ioapic_valid = 1; |
| 892 | if (src && src->ioapic_valid) { |
| 893 | dst->ioapic_node = src->ioapic_node; |
| 894 | dst->ioapic_trigger = src->ioapic_trigger; |
| 895 | dst->ioapic_polarity = src->ioapic_polarity; |
| 896 | } else { |
| 897 | dst->ioapic_node = NUMA_NO_NODE; |
| 898 | if (acpi_get_override_irq(gsi, &trigger, &polarity) >= 0) { |
| 899 | dst->ioapic_trigger = trigger; |
| 900 | dst->ioapic_polarity = polarity; |
| 901 | } else { |
| 902 | /* |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 903 | * PCI interrupts are always active low level |
Jiang Liu | 96ed44b | 2015-04-13 14:11:58 +0800 | [diff] [blame] | 904 | * triggered. |
| 905 | */ |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 906 | dst->ioapic_trigger = IOAPIC_LEVEL; |
| 907 | dst->ioapic_polarity = IOAPIC_POL_LOW; |
Jiang Liu | 96ed44b | 2015-04-13 14:11:58 +0800 | [diff] [blame] | 908 | } |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | static int ioapic_alloc_attr_node(struct irq_alloc_info *info) |
| 913 | { |
| 914 | return (info && info->ioapic_valid) ? info->ioapic_node : NUMA_NO_NODE; |
| 915 | } |
| 916 | |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 917 | static void mp_register_handler(unsigned int irq, unsigned long trigger) |
| 918 | { |
| 919 | irq_flow_handler_t hdl; |
| 920 | bool fasteoi; |
| 921 | |
| 922 | if (trigger) { |
| 923 | irq_set_status_flags(irq, IRQ_LEVEL); |
| 924 | fasteoi = true; |
| 925 | } else { |
| 926 | irq_clear_status_flags(irq, IRQ_LEVEL); |
| 927 | fasteoi = false; |
| 928 | } |
| 929 | |
| 930 | hdl = fasteoi ? handle_fasteoi_irq : handle_edge_irq; |
| 931 | __irq_set_handler(irq, hdl, 0, fasteoi ? "fasteoi" : "edge"); |
| 932 | } |
| 933 | |
Jiang Liu | 96ed44b | 2015-04-13 14:11:58 +0800 | [diff] [blame] | 934 | static bool mp_check_pin_attr(int irq, struct irq_alloc_info *info) |
| 935 | { |
| 936 | struct mp_chip_data *data = irq_get_chip_data(irq); |
| 937 | |
| 938 | /* |
| 939 | * setup_IO_APIC_irqs() programs all legacy IRQs with default trigger |
| 940 | * and polarity attirbutes. So allow the first user to reprogram the |
| 941 | * pin with real trigger and polarity attributes. |
| 942 | */ |
| 943 | if (irq < nr_legacy_irqs() && data->count == 1) { |
| 944 | if (info->ioapic_trigger != data->trigger) |
Jiang Liu | 646c4b7 | 2015-07-30 15:51:32 +0800 | [diff] [blame] | 945 | mp_register_handler(irq, info->ioapic_trigger); |
Jiang Liu | 96ed44b | 2015-04-13 14:11:58 +0800 | [diff] [blame] | 946 | data->entry.trigger = data->trigger = info->ioapic_trigger; |
| 947 | data->entry.polarity = data->polarity = info->ioapic_polarity; |
| 948 | } |
| 949 | |
| 950 | return data->trigger == info->ioapic_trigger && |
| 951 | data->polarity == info->ioapic_polarity; |
| 952 | } |
| 953 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 954 | static int alloc_irq_from_domain(struct irq_domain *domain, int ioapic, u32 gsi, |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 955 | struct irq_alloc_info *info) |
Jiang Liu | 6b9fb70 | 2014-06-10 14:13:25 +0800 | [diff] [blame] | 956 | { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 957 | bool legacy = false; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 958 | int irq = -1; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 959 | int type = ioapics[ioapic].irqdomain_cfg.type; |
| 960 | |
| 961 | switch (type) { |
| 962 | case IOAPIC_DOMAIN_LEGACY: |
| 963 | /* |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 964 | * Dynamically allocate IRQ number for non-ISA IRQs in the first |
| 965 | * 16 GSIs on some weird platforms. |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 966 | */ |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 967 | if (!ioapic_initialized || gsi >= nr_legacy_irqs()) |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 968 | irq = gsi; |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 969 | legacy = mp_is_legacy_irq(irq); |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 970 | break; |
| 971 | case IOAPIC_DOMAIN_STRICT: |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 972 | irq = gsi; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 973 | break; |
| 974 | case IOAPIC_DOMAIN_DYNAMIC: |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 975 | break; |
| 976 | default: |
| 977 | WARN(1, "ioapic: unknown irqdomain type %d\n", type); |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 978 | return -1; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 979 | } |
| 980 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 981 | return __irq_domain_alloc_irqs(domain, irq, 1, |
| 982 | ioapic_alloc_attr_node(info), |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 983 | info, legacy, NULL); |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | /* |
| 987 | * Need special handling for ISA IRQs because there may be multiple IOAPIC pins |
| 988 | * sharing the same ISA IRQ number and irqdomain only supports 1:1 mapping |
| 989 | * between IOAPIC pin and IRQ number. A typical IOAPIC has 24 pins, pin 0-15 are |
| 990 | * used for legacy IRQs and pin 16-23 are used for PCI IRQs (PIRQ A-H). |
| 991 | * When ACPI is disabled, only legacy IRQ numbers (IRQ0-15) are available, and |
| 992 | * some BIOSes may use MP Interrupt Source records to override IRQ numbers for |
| 993 | * PIRQs instead of reprogramming the interrupt routing logic. Thus there may be |
| 994 | * multiple pins sharing the same legacy IRQ number when ACPI is disabled. |
| 995 | */ |
| 996 | static int alloc_isa_irq_from_domain(struct irq_domain *domain, |
| 997 | int irq, int ioapic, int pin, |
| 998 | struct irq_alloc_info *info) |
| 999 | { |
| 1000 | struct mp_chip_data *data; |
| 1001 | struct irq_data *irq_data = irq_get_irq_data(irq); |
| 1002 | int node = ioapic_alloc_attr_node(info); |
| 1003 | |
| 1004 | /* |
| 1005 | * Legacy ISA IRQ has already been allocated, just add pin to |
| 1006 | * the pin list assoicated with this IRQ and program the IOAPIC |
| 1007 | * entry. The IOAPIC entry |
| 1008 | */ |
| 1009 | if (irq_data && irq_data->parent_data) { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1010 | if (!mp_check_pin_attr(irq, info)) |
| 1011 | return -EBUSY; |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1012 | if (__add_pin_to_irq_node(irq_data->chip_data, node, ioapic, |
| 1013 | info->ioapic_pin)) |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1014 | return -ENOMEM; |
| 1015 | } else { |
Thomas Gleixner | 06ee6d5 | 2016-07-04 17:39:24 +0900 | [diff] [blame] | 1016 | irq = __irq_domain_alloc_irqs(domain, irq, 1, node, info, true, |
| 1017 | NULL); |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1018 | if (irq >= 0) { |
| 1019 | irq_data = irq_domain_get_irq_data(domain, irq); |
| 1020 | data = irq_data->chip_data; |
| 1021 | data->isa_irq = true; |
| 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | return irq; |
Jiang Liu | 6b9fb70 | 2014-06-10 14:13:25 +0800 | [diff] [blame] | 1026 | } |
| 1027 | |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1028 | static int mp_map_pin_to_irq(u32 gsi, int idx, int ioapic, int pin, |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 1029 | unsigned int flags, struct irq_alloc_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { |
Eric W. Biederman | d464207 | 2010-03-30 01:07:13 -0700 | [diff] [blame] | 1031 | int irq; |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1032 | bool legacy = false; |
| 1033 | struct irq_alloc_info tmp; |
| 1034 | struct mp_chip_data *data; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1035 | struct irq_domain *domain = mp_ioapic_irqdomain(ioapic); |
| 1036 | |
Jiang Liu | b81975e | 2014-06-09 16:20:11 +0800 | [diff] [blame] | 1037 | if (!domain) |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1038 | return -ENOSYS; |
Jiang Liu | 16ee7b3 | 2014-06-09 16:20:04 +0800 | [diff] [blame] | 1039 | |
Jiang Liu | 16ee7b3 | 2014-06-09 16:20:04 +0800 | [diff] [blame] | 1040 | if (idx >= 0 && test_bit(mp_irqs[idx].srcbus, mp_bus_not_pci)) { |
| 1041 | irq = mp_irqs[idx].srcbusirq; |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1042 | legacy = mp_is_legacy_irq(irq); |
| 1043 | } |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1044 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1045 | mutex_lock(&ioapic_mutex); |
| 1046 | if (!(flags & IOAPIC_MAP_ALLOC)) { |
| 1047 | if (!legacy) { |
| 1048 | irq = irq_find_mapping(domain, pin); |
Jiang Liu | 16ee7b3 | 2014-06-09 16:20:04 +0800 | [diff] [blame] | 1049 | if (irq == 0) |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1050 | irq = -ENOENT; |
Jiang Liu | 16ee7b3 | 2014-06-09 16:20:04 +0800 | [diff] [blame] | 1051 | } |
| 1052 | } else { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1053 | ioapic_copy_alloc_attr(&tmp, info, gsi, ioapic, pin); |
| 1054 | if (legacy) |
| 1055 | irq = alloc_isa_irq_from_domain(domain, irq, |
| 1056 | ioapic, pin, &tmp); |
| 1057 | else if ((irq = irq_find_mapping(domain, pin)) == 0) |
| 1058 | irq = alloc_irq_from_domain(domain, ioapic, gsi, &tmp); |
| 1059 | else if (!mp_check_pin_attr(irq, &tmp)) |
| 1060 | irq = -EBUSY; |
| 1061 | if (irq >= 0) { |
| 1062 | data = irq_get_chip_data(irq); |
| 1063 | data->count++; |
| 1064 | } |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1065 | } |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1066 | mutex_unlock(&ioapic_mutex); |
| 1067 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1068 | return irq; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | static int pin_2_irq(int idx, int ioapic, int pin, unsigned int flags) |
| 1072 | { |
| 1073 | u32 gsi = mp_pin_to_gsi(ioapic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | |
| 1075 | /* |
| 1076 | * Debugging check, we are in big trouble if this message pops up! |
| 1077 | */ |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 1078 | if (mp_irqs[idx].dstirq != pin) |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 1079 | pr_err("broken BIOS or MPTABLE parser, ayiee!!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1081 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | /* |
| 1083 | * PCI IRQ command line redirection. Yes, limits are hardcoded. |
| 1084 | */ |
| 1085 | if ((pin >= 16) && (pin <= 23)) { |
| 1086 | if (pirq_entries[pin-16] != -1) { |
| 1087 | if (!pirq_entries[pin-16]) { |
| 1088 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 1089 | "disabling PIRQ%d\n", pin-16); |
| 1090 | } else { |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1091 | int irq = pirq_entries[pin-16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 1093 | "using PIRQ%d -> IRQ %d\n", |
| 1094 | pin-16, irq); |
Jiang Liu | 6b9fb70 | 2014-06-10 14:13:25 +0800 | [diff] [blame] | 1095 | return irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1099 | #endif |
| 1100 | |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 1101 | return mp_map_pin_to_irq(gsi, idx, ioapic, pin, flags, NULL); |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1102 | } |
Jiang Liu | 6b9fb70 | 2014-06-10 14:13:25 +0800 | [diff] [blame] | 1103 | |
Jiang Liu | 154d9e5 | 2015-04-14 10:29:56 +0800 | [diff] [blame] | 1104 | int mp_map_gsi_to_irq(u32 gsi, unsigned int flags, struct irq_alloc_info *info) |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1105 | { |
| 1106 | int ioapic, pin, idx; |
| 1107 | |
| 1108 | ioapic = mp_find_ioapic(gsi); |
| 1109 | if (ioapic < 0) |
Andy Shevchenko | 358e96d | 2017-01-19 21:24:22 +0200 | [diff] [blame] | 1110 | return -ENODEV; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1111 | |
| 1112 | pin = mp_find_ioapic_pin(ioapic, gsi); |
| 1113 | idx = find_irq_entry(ioapic, pin, mp_INT); |
| 1114 | if ((flags & IOAPIC_MAP_CHECK) && idx < 0) |
Andy Shevchenko | 358e96d | 2017-01-19 21:24:22 +0200 | [diff] [blame] | 1115 | return -ENODEV; |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1116 | |
Jiang Liu | c4d05a2 | 2015-04-13 14:11:54 +0800 | [diff] [blame] | 1117 | return mp_map_pin_to_irq(gsi, idx, ioapic, pin, flags, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 1120 | void mp_unmap_irq(int irq) |
| 1121 | { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1122 | struct irq_data *irq_data = irq_get_irq_data(irq); |
| 1123 | struct mp_chip_data *data; |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 1124 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1125 | if (!irq_data || !irq_data->domain) |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 1126 | return; |
| 1127 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1128 | data = irq_data->chip_data; |
| 1129 | if (!data || data->isa_irq) |
| 1130 | return; |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 1131 | |
| 1132 | mutex_lock(&ioapic_mutex); |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1133 | if (--data->count == 0) |
| 1134 | irq_domain_free_irqs(irq, 1); |
Jiang Liu | df334be | 2014-06-09 16:20:06 +0800 | [diff] [blame] | 1135 | mutex_unlock(&ioapic_mutex); |
| 1136 | } |
| 1137 | |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1138 | /* |
| 1139 | * Find a specific PCI IRQ entry. |
| 1140 | * Not an __init, possibly needed by modules |
| 1141 | */ |
Jiang Liu | 25d0d35 | 2014-10-27 16:11:54 +0800 | [diff] [blame] | 1142 | int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin) |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1143 | { |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1144 | int irq, i, best_ioapic = -1, best_idx = -1; |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1145 | |
| 1146 | apic_printk(APIC_DEBUG, |
| 1147 | "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n", |
| 1148 | bus, slot, pin); |
| 1149 | if (test_bit(bus, mp_bus_not_pci)) { |
| 1150 | apic_printk(APIC_VERBOSE, |
| 1151 | "PCI BIOS passed nonexistent PCI bus %d!\n", bus); |
| 1152 | return -1; |
| 1153 | } |
Jiang Liu | 7959850 | 2014-06-09 16:19:44 +0800 | [diff] [blame] | 1154 | |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1155 | for (i = 0; i < mp_irq_entries; i++) { |
| 1156 | int lbus = mp_irqs[i].srcbus; |
Jiang Liu | 7959850 | 2014-06-09 16:19:44 +0800 | [diff] [blame] | 1157 | int ioapic_idx, found = 0; |
| 1158 | |
| 1159 | if (bus != lbus || mp_irqs[i].irqtype != mp_INT || |
| 1160 | slot != ((mp_irqs[i].srcbusirq >> 2) & 0x1f)) |
| 1161 | continue; |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1162 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1163 | for_each_ioapic(ioapic_idx) |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1164 | if (mpc_ioapic_id(ioapic_idx) == mp_irqs[i].dstapic || |
Jiang Liu | 7959850 | 2014-06-09 16:19:44 +0800 | [diff] [blame] | 1165 | mp_irqs[i].dstapic == MP_APIC_ALL) { |
| 1166 | found = 1; |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1167 | break; |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1168 | } |
Jiang Liu | 7959850 | 2014-06-09 16:19:44 +0800 | [diff] [blame] | 1169 | if (!found) |
| 1170 | continue; |
| 1171 | |
| 1172 | /* Skip ISA IRQs */ |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1173 | irq = pin_2_irq(i, ioapic_idx, mp_irqs[i].dstirq, 0); |
| 1174 | if (irq > 0 && !IO_APIC_IRQ(irq)) |
Jiang Liu | 7959850 | 2014-06-09 16:19:44 +0800 | [diff] [blame] | 1175 | continue; |
| 1176 | |
| 1177 | if (pin == (mp_irqs[i].srcbusirq & 3)) { |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1178 | best_idx = i; |
| 1179 | best_ioapic = ioapic_idx; |
| 1180 | goto out; |
Jiang Liu | 7959850 | 2014-06-09 16:19:44 +0800 | [diff] [blame] | 1181 | } |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1182 | |
Jiang Liu | 7959850 | 2014-06-09 16:19:44 +0800 | [diff] [blame] | 1183 | /* |
| 1184 | * Use the first all-but-pin matching entry as a |
| 1185 | * best-guess fuzzy result for broken mptables. |
| 1186 | */ |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1187 | if (best_idx < 0) { |
| 1188 | best_idx = i; |
| 1189 | best_ioapic = ioapic_idx; |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1190 | } |
| 1191 | } |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1192 | if (best_idx < 0) |
| 1193 | return -1; |
| 1194 | |
| 1195 | out: |
Jiang Liu | 25d0d35 | 2014-10-27 16:11:54 +0800 | [diff] [blame] | 1196 | return pin_2_irq(best_idx, best_ioapic, mp_irqs[best_idx].dstirq, |
| 1197 | IOAPIC_MAP_ALLOC); |
Yinghai Lu | e20c06f | 2009-05-06 10:08:22 -0700 | [diff] [blame] | 1198 | } |
| 1199 | EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector); |
| 1200 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1201 | static struct irq_chip ioapic_chip, ioapic_ir_chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1203 | #ifdef CONFIG_X86_32 |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1204 | static inline int IO_APIC_irq_trigger(int irq) |
| 1205 | { |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1206 | int apic, idx, pin; |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1207 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1208 | for_each_ioapic_pin(apic, pin) { |
| 1209 | idx = find_irq_entry(apic, pin, mp_INT); |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 1210 | if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin, 0))) |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1211 | return irq_trigger(idx); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1212 | } |
| 1213 | /* |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1214 | * nonexistent IRQs are edge default |
| 1215 | */ |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1216 | return 0; |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1217 | } |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1218 | #else |
| 1219 | static inline int IO_APIC_irq_trigger(int irq) |
| 1220 | { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1221 | return 1; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1222 | } |
| 1223 | #endif |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1224 | |
Thomas Gleixner | ed972cc | 2011-02-23 14:31:36 +0100 | [diff] [blame] | 1225 | static void __init setup_IO_APIC_irqs(void) |
| 1226 | { |
Jiang Liu | 16ee7b3 | 2014-06-09 16:20:04 +0800 | [diff] [blame] | 1227 | unsigned int ioapic, pin; |
| 1228 | int idx; |
Thomas Gleixner | ed972cc | 2011-02-23 14:31:36 +0100 | [diff] [blame] | 1229 | |
| 1230 | apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n"); |
| 1231 | |
Jiang Liu | 16ee7b3 | 2014-06-09 16:20:04 +0800 | [diff] [blame] | 1232 | for_each_ioapic_pin(ioapic, pin) { |
| 1233 | idx = find_irq_entry(ioapic, pin, mp_INT); |
| 1234 | if (idx < 0) |
| 1235 | apic_printk(APIC_VERBOSE, |
| 1236 | KERN_DEBUG " apic %d pin %d not connected\n", |
| 1237 | mpc_ioapic_id(ioapic), pin); |
| 1238 | else |
| 1239 | pin_2_irq(idx, ioapic, pin, |
| 1240 | ioapic ? 0 : IOAPIC_MAP_ALLOC); |
| 1241 | } |
Thomas Gleixner | ed972cc | 2011-02-23 14:31:36 +0100 | [diff] [blame] | 1242 | } |
| 1243 | |
Yoshihiro YUNOMAE | 1740545 | 2013-08-20 16:01:07 +0900 | [diff] [blame] | 1244 | void ioapic_zap_locks(void) |
| 1245 | { |
| 1246 | raw_spin_lock_init(&ioapic_lock); |
| 1247 | } |
| 1248 | |
Jiang Liu | a44174e | 2015-04-13 14:11:57 +0800 | [diff] [blame] | 1249 | static void io_apic_print_entries(unsigned int apic, unsigned int nr_entries) |
| 1250 | { |
| 1251 | int i; |
| 1252 | char buf[256]; |
| 1253 | struct IO_APIC_route_entry entry; |
| 1254 | struct IR_IO_APIC_route_entry *ir_entry = (void *)&entry; |
| 1255 | |
| 1256 | printk(KERN_DEBUG "IOAPIC %d:\n", apic); |
| 1257 | for (i = 0; i <= nr_entries; i++) { |
| 1258 | entry = ioapic_read_entry(apic, i); |
| 1259 | snprintf(buf, sizeof(buf), |
| 1260 | " pin%02x, %s, %s, %s, V(%02X), IRR(%1d), S(%1d)", |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 1261 | i, |
| 1262 | entry.mask == IOAPIC_MASKED ? "disabled" : "enabled ", |
| 1263 | entry.trigger == IOAPIC_LEVEL ? "level" : "edge ", |
| 1264 | entry.polarity == IOAPIC_POL_LOW ? "low " : "high", |
Jiang Liu | a44174e | 2015-04-13 14:11:57 +0800 | [diff] [blame] | 1265 | entry.vector, entry.irr, entry.delivery_status); |
| 1266 | if (ir_entry->format) |
| 1267 | printk(KERN_DEBUG "%s, remapped, I(%04X), Z(%X)\n", |
| 1268 | buf, (ir_entry->index << 15) | ir_entry->index, |
| 1269 | ir_entry->zero); |
| 1270 | else |
| 1271 | printk(KERN_DEBUG "%s, %s, D(%02X), M(%1d)\n", |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 1272 | buf, |
| 1273 | entry.dest_mode == IOAPIC_DEST_MODE_LOGICAL ? |
| 1274 | "logical " : "physical", |
Jiang Liu | a44174e | 2015-04-13 14:11:57 +0800 | [diff] [blame] | 1275 | entry.dest, entry.delivery_mode); |
| 1276 | } |
| 1277 | } |
| 1278 | |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 1279 | static void __init print_IO_APIC(int ioapic_idx) |
Joerg Roedel | afcc8a4 | 2012-09-26 12:44:36 +0200 | [diff] [blame] | 1280 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | union IO_APIC_reg_00 reg_00; |
| 1282 | union IO_APIC_reg_01 reg_01; |
| 1283 | union IO_APIC_reg_02 reg_02; |
| 1284 | union IO_APIC_reg_03 reg_03; |
| 1285 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1287 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1288 | reg_00.raw = io_apic_read(ioapic_idx, 0); |
| 1289 | reg_01.raw = io_apic_read(ioapic_idx, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | if (reg_01.bits.version >= 0x10) |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1291 | reg_02.raw = io_apic_read(ioapic_idx, 2); |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 1292 | if (reg_01.bits.version >= 0x20) |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1293 | reg_03.raw = io_apic_read(ioapic_idx, 3); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1294 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1296 | printk(KERN_DEBUG "IO APIC #%d......\n", mpc_ioapic_id(ioapic_idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw); |
| 1298 | printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID); |
| 1299 | printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type); |
| 1300 | printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1302 | printk(KERN_DEBUG ".... register #01: %08X\n", *(int *)®_01); |
Naga Chumbalkar | bd6a46e | 2011-07-08 18:46:36 +0000 | [diff] [blame] | 1303 | printk(KERN_DEBUG "....... : max redirection entries: %02X\n", |
| 1304 | reg_01.bits.entries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | |
| 1306 | printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ); |
Naga Chumbalkar | bd6a46e | 2011-07-08 18:46:36 +0000 | [diff] [blame] | 1307 | printk(KERN_DEBUG "....... : IO APIC version: %02X\n", |
| 1308 | reg_01.bits.version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | |
| 1310 | /* |
| 1311 | * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02, |
| 1312 | * but the value of reg_02 is read as the previous read register |
| 1313 | * value, so ignore it if reg_02 == reg_01. |
| 1314 | */ |
| 1315 | if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) { |
| 1316 | printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw); |
| 1317 | printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
| 1320 | /* |
| 1321 | * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02 |
| 1322 | * or reg_03, but the value of reg_0[23] is read as the previous read |
| 1323 | * register value, so ignore it if reg_03 == reg_0[12]. |
| 1324 | */ |
| 1325 | if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw && |
| 1326 | reg_03.raw != reg_01.raw) { |
| 1327 | printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw); |
| 1328 | printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | printk(KERN_DEBUG ".... IRQ redirection table:\n"); |
Jiang Liu | a44174e | 2015-04-13 14:11:57 +0800 | [diff] [blame] | 1332 | io_apic_print_entries(ioapic_idx, reg_01.bits.entries); |
Yinghai Lu | cda417d | 2011-10-12 00:33:39 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Jiang Liu | 74afab7 | 2014-10-27 16:12:00 +0800 | [diff] [blame] | 1335 | void __init print_IO_APICs(void) |
Yinghai Lu | cda417d | 2011-10-12 00:33:39 -0700 | [diff] [blame] | 1336 | { |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1337 | int ioapic_idx; |
Yinghai Lu | cda417d | 2011-10-12 00:33:39 -0700 | [diff] [blame] | 1338 | unsigned int irq; |
| 1339 | |
| 1340 | printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries); |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1341 | for_each_ioapic(ioapic_idx) |
Yinghai Lu | cda417d | 2011-10-12 00:33:39 -0700 | [diff] [blame] | 1342 | printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n", |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1343 | mpc_ioapic_id(ioapic_idx), |
| 1344 | ioapics[ioapic_idx].nr_registers); |
Yinghai Lu | cda417d | 2011-10-12 00:33:39 -0700 | [diff] [blame] | 1345 | |
| 1346 | /* |
| 1347 | * We are a bit conservative about what we expect. We have to |
| 1348 | * know about every hardware change ASAP. |
| 1349 | */ |
| 1350 | printk(KERN_INFO "testing the IO APIC.......................\n"); |
| 1351 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1352 | for_each_ioapic(ioapic_idx) |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1353 | print_IO_APIC(ioapic_idx); |
Naga Chumbalkar | 42f0efc | 2011-07-12 21:17:35 +0000 | [diff] [blame] | 1354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | printk(KERN_DEBUG "IRQ to pin mappings:\n"); |
Thomas Gleixner | ad9f433 | 2010-09-30 11:26:43 +0200 | [diff] [blame] | 1356 | for_each_active_irq(irq) { |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1357 | struct irq_pin_list *entry; |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1358 | struct irq_chip *chip; |
| 1359 | struct mp_chip_data *data; |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1360 | |
Mathias Nyman | 6fd36ba | 2011-11-10 13:45:24 +0000 | [diff] [blame] | 1361 | chip = irq_get_chip(irq); |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1362 | if (chip != &ioapic_chip && chip != &ioapic_ir_chip) |
Mathias Nyman | 6fd36ba | 2011-11-10 13:45:24 +0000 | [diff] [blame] | 1363 | continue; |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1364 | data = irq_get_chip_data(irq); |
| 1365 | if (!data) |
| 1366 | continue; |
| 1367 | if (list_empty(&data->irq_2_pin)) |
| 1368 | continue; |
Mathias Nyman | 6fd36ba | 2011-11-10 13:45:24 +0000 | [diff] [blame] | 1369 | |
Yinghai Lu | 8f09cd2 | 2008-08-19 20:50:51 -0700 | [diff] [blame] | 1370 | printk(KERN_DEBUG "IRQ%d ", irq); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1371 | for_each_irq_pin(entry, data->irq_2_pin) |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 1372 | pr_cont("-> %d:%d", entry->apic, entry->pin); |
| 1373 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | printk(KERN_INFO ".................................... done.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 1379 | /* Where if anywhere is the i8259 connect in external int mode */ |
| 1380 | static struct { int pin, apic; } ioapic_i8259 = { -1, -1 }; |
| 1381 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1382 | void __init enable_IO_APIC(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1384 | int i8259_apic, i8259_pin; |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1385 | int apic, pin; |
Thomas Gleixner | bc07844 | 2009-08-29 18:09:57 +0200 | [diff] [blame] | 1386 | |
Thomas Gleixner | a46f5c8 | 2015-01-15 21:22:32 +0000 | [diff] [blame] | 1387 | if (skip_ioapic_setup) |
| 1388 | nr_ioapics = 0; |
| 1389 | |
| 1390 | if (!nr_legacy_irqs() || !nr_ioapics) |
Thomas Gleixner | bc07844 | 2009-08-29 18:09:57 +0200 | [diff] [blame] | 1391 | return; |
| 1392 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1393 | for_each_ioapic_pin(apic, pin) { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1394 | /* See if any of the pins is in ExtINT mode */ |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1395 | struct IO_APIC_route_entry entry = ioapic_read_entry(apic, pin); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1396 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1397 | /* If the interrupt line is enabled and in ExtInt mode |
| 1398 | * I have found the pin where the i8259 is connected. |
| 1399 | */ |
| 1400 | if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) { |
| 1401 | ioapic_i8259.apic = apic; |
| 1402 | ioapic_i8259.pin = pin; |
| 1403 | goto found_i8259; |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | found_i8259: |
| 1407 | /* Look to see what if the MP table has reported the ExtINT */ |
| 1408 | /* If we could not find the appropriate pin by looking at the ioapic |
| 1409 | * the i8259 probably is not connected the ioapic but give the |
| 1410 | * mptable a chance anyway. |
| 1411 | */ |
| 1412 | i8259_pin = find_isa_irq_pin(0, mp_ExtINT); |
| 1413 | i8259_apic = find_isa_irq_apic(0, mp_ExtINT); |
| 1414 | /* Trust the MP table if nothing is setup in the hardware */ |
| 1415 | if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) { |
| 1416 | printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n"); |
| 1417 | ioapic_i8259.pin = i8259_pin; |
| 1418 | ioapic_i8259.apic = i8259_apic; |
| 1419 | } |
| 1420 | /* Complain if the MP table and the hardware disagree */ |
| 1421 | if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) && |
| 1422 | (i8259_pin >= 0) && (ioapic_i8259.pin >= 0)) |
| 1423 | { |
| 1424 | printk(KERN_WARNING "ExtINT in hardware and MP table differ\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | /* |
| 1428 | * Do not trust the IO-APIC being empty at bootup |
| 1429 | */ |
| 1430 | clear_IO_APIC(); |
| 1431 | } |
| 1432 | |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 1433 | void native_disable_io_apic(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | { |
| 1435 | /* |
Karsten Wiese | 0b968d2 | 2005-09-09 12:59:04 +0200 | [diff] [blame] | 1436 | * If the i8259 is routed through an IOAPIC |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1437 | * Put that IOAPIC in virtual wire mode |
Karsten Wiese | 0b968d2 | 2005-09-09 12:59:04 +0200 | [diff] [blame] | 1438 | * so legacy interrupts can be delivered. |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1439 | */ |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 1440 | if (ioapic_i8259.pin != -1) { |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1441 | struct IO_APIC_route_entry entry; |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1442 | |
| 1443 | memset(&entry, 0, sizeof(entry)); |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 1444 | entry.mask = IOAPIC_UNMASKED; |
| 1445 | entry.trigger = IOAPIC_EDGE; |
| 1446 | entry.polarity = IOAPIC_POL_HIGH; |
| 1447 | entry.dest_mode = IOAPIC_DEST_MODE_PHYSICAL; |
| 1448 | entry.delivery_mode = dest_ExtINT; |
| 1449 | entry.dest = read_apic_id(); |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1450 | |
| 1451 | /* |
| 1452 | * Add it to the IO-APIC irq-routing table: |
| 1453 | */ |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1454 | ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry); |
Eric W. Biederman | 650927e | 2005-06-25 14:57:44 -0700 | [diff] [blame] | 1455 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1456 | |
Borislav Petkov | 93984fb | 2016-04-04 22:25:00 +0200 | [diff] [blame] | 1457 | if (boot_cpu_has(X86_FEATURE_APIC) || apic_from_smp_config()) |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 1458 | disconnect_bsp_APIC(ioapic_i8259.pin != -1); |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /* |
| 1462 | * Not an __init, needed by the reboot code |
| 1463 | */ |
| 1464 | void disable_IO_APIC(void) |
| 1465 | { |
| 1466 | /* |
| 1467 | * Clear the IO-APIC before rebooting: |
| 1468 | */ |
| 1469 | clear_IO_APIC(); |
| 1470 | |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 1471 | if (!nr_legacy_irqs()) |
Joerg Roedel | 1c4248c | 2012-09-26 12:44:35 +0200 | [diff] [blame] | 1472 | return; |
| 1473 | |
| 1474 | x86_io_apic_ops.disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1477 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | /* |
| 1479 | * function to set the IO-APIC physical IDs based on the |
| 1480 | * values stored in the MPC table. |
| 1481 | * |
| 1482 | * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999 |
| 1483 | */ |
Sebastian Andrzej Siewior | a38c538 | 2010-11-26 17:50:20 +0100 | [diff] [blame] | 1484 | void __init setup_ioapic_ids_from_mpc_nocheck(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | { |
| 1486 | union IO_APIC_reg_00 reg_00; |
| 1487 | physid_mask_t phys_id_present_map; |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1488 | int ioapic_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | int i; |
| 1490 | unsigned char old_id; |
| 1491 | unsigned long flags; |
| 1492 | |
Natalie Protasevich | ca05fea | 2005-06-23 00:08:22 -0700 | [diff] [blame] | 1493 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | * This is broken; anything with a real cpu count has to |
| 1495 | * circumvent this idiocy regardless. |
| 1496 | */ |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 1497 | 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] | 1498 | |
| 1499 | /* |
| 1500 | * Set the IOAPIC ID to the value stored in the MPC table. |
| 1501 | */ |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 1502 | for_each_ioapic(ioapic_idx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | /* Read the register 0 value */ |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1504 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1505 | reg_00.raw = io_apic_read(ioapic_idx, 0); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1506 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1507 | |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1508 | old_id = mpc_ioapic_id(ioapic_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1510 | if (mpc_ioapic_id(ioapic_idx) >= get_physical_broadcast()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n", |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1512 | ioapic_idx, mpc_ioapic_id(ioapic_idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n", |
| 1514 | reg_00.bits.ID); |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1515 | ioapics[ioapic_idx].mp_config.apicid = reg_00.bits.ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | /* |
| 1519 | * Sanity check, is the ID really free? Every APIC in a |
| 1520 | * system must have a unique ID or we get lots of nice |
| 1521 | * 'stuck on smp_invalidate_needed IPI wait' messages. |
| 1522 | */ |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 1523 | if (apic->check_apicid_used(&phys_id_present_map, |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1524 | mpc_ioapic_id(ioapic_idx))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n", |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1526 | ioapic_idx, mpc_ioapic_id(ioapic_idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | for (i = 0; i < get_physical_broadcast(); i++) |
| 1528 | if (!physid_isset(i, phys_id_present_map)) |
| 1529 | break; |
| 1530 | if (i >= get_physical_broadcast()) |
| 1531 | panic("Max APIC ID exceeded!\n"); |
| 1532 | printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n", |
| 1533 | i); |
| 1534 | physid_set(i, phys_id_present_map); |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1535 | ioapics[ioapic_idx].mp_config.apicid = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | } else { |
| 1537 | physid_mask_t tmp; |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1538 | apic->apicid_to_cpu_present(mpc_ioapic_id(ioapic_idx), |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 1539 | &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | apic_printk(APIC_VERBOSE, "Setting %d in the " |
| 1541 | "phys_id_present_map\n", |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1542 | mpc_ioapic_id(ioapic_idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | physids_or(phys_id_present_map, phys_id_present_map, tmp); |
| 1544 | } |
| 1545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | /* |
| 1547 | * We need to adjust the IRQ routing table |
| 1548 | * if the ID changed. |
| 1549 | */ |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1550 | if (old_id != mpc_ioapic_id(ioapic_idx)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | for (i = 0; i < mp_irq_entries; i++) |
Jaswinder Singh Rajput | c2c2174 | 2009-01-12 17:47:22 +0530 | [diff] [blame] | 1552 | if (mp_irqs[i].dstapic == old_id) |
| 1553 | mp_irqs[i].dstapic |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1554 | = mpc_ioapic_id(ioapic_idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | |
| 1556 | /* |
Yinghai Lu | 60d79fd | 2010-12-07 00:59:49 -0800 | [diff] [blame] | 1557 | * Update the ID register according to the right value |
| 1558 | * from the MPC table if they are different. |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 1559 | */ |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1560 | if (mpc_ioapic_id(ioapic_idx) == reg_00.bits.ID) |
Yinghai Lu | 60d79fd | 2010-12-07 00:59:49 -0800 | [diff] [blame] | 1561 | continue; |
| 1562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 1564 | "...changing IO-APIC physical APIC ID to %d ...", |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1565 | mpc_ioapic_id(ioapic_idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1567 | reg_00.bits.ID = mpc_ioapic_id(ioapic_idx); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1568 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1569 | io_apic_write(ioapic_idx, 0, reg_00.raw); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1570 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | |
| 1572 | /* |
| 1573 | * Sanity check |
| 1574 | */ |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1575 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1576 | reg_00.raw = io_apic_read(ioapic_idx, 0); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1577 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 1578 | if (reg_00.bits.ID != mpc_ioapic_id(ioapic_idx)) |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 1579 | pr_cont("could not set ID!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | else |
| 1581 | apic_printk(APIC_VERBOSE, " ok.\n"); |
| 1582 | } |
| 1583 | } |
Sebastian Andrzej Siewior | a38c538 | 2010-11-26 17:50:20 +0100 | [diff] [blame] | 1584 | |
| 1585 | void __init setup_ioapic_ids_from_mpc(void) |
| 1586 | { |
| 1587 | |
| 1588 | if (acpi_ioapic) |
| 1589 | return; |
| 1590 | /* |
| 1591 | * Don't check I/O APIC IDs for xAPIC systems. They have |
| 1592 | * no meaning without the serial APIC bus. |
| 1593 | */ |
| 1594 | if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) |
Denys Vlasenko | cff9ab2 | 2016-09-13 20:12:32 +0200 | [diff] [blame] | 1595 | || APIC_XAPIC(boot_cpu_apic_version)) |
Sebastian Andrzej Siewior | a38c538 | 2010-11-26 17:50:20 +0100 | [diff] [blame] | 1596 | return; |
| 1597 | setup_ioapic_ids_from_mpc_nocheck(); |
| 1598 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1599 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 1601 | int no_timer_check __initdata; |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 1602 | |
| 1603 | static int __init notimercheck(char *s) |
| 1604 | { |
| 1605 | no_timer_check = 1; |
| 1606 | return 1; |
| 1607 | } |
| 1608 | __setup("no_timer_check", notimercheck); |
| 1609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | /* |
| 1611 | * There is a nasty bug in some older SMP boards, their mptable lies |
| 1612 | * about the timer IRQ. We do the following to work around the situation: |
| 1613 | * |
| 1614 | * - timer IRQ defaults to IO-APIC IRQ |
| 1615 | * - if this function detects that timer IRQs are defunct, then we fall |
| 1616 | * back to ISA timer IRQs |
| 1617 | */ |
Adrian Bunk | f0a7a5c | 2007-07-21 17:10:29 +0200 | [diff] [blame] | 1618 | static int __init timer_irq_works(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | { |
| 1620 | unsigned long t1 = jiffies; |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1621 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 1623 | if (no_timer_check) |
| 1624 | return 1; |
| 1625 | |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1626 | local_save_flags(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | local_irq_enable(); |
| 1628 | /* Let ten ticks pass... */ |
| 1629 | mdelay((10 * 1000) / HZ); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 1630 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | |
| 1632 | /* |
| 1633 | * Expect a few ticks at least, to be sure some possible |
| 1634 | * glue logic does not lock up after one or two first |
| 1635 | * ticks in a non-ExtINT mode. Also the local APIC |
| 1636 | * might have cached one ExtINT interrupt. Finally, at |
| 1637 | * least one tick may be lost due to delays. |
| 1638 | */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1639 | |
| 1640 | /* jiffies wrap? */ |
Julia Lawall | 1d16b53 | 2008-01-30 13:32:19 +0100 | [diff] [blame] | 1641 | if (time_after(jiffies, t1 + 4)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1642 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | return 0; |
| 1644 | } |
| 1645 | |
| 1646 | /* |
| 1647 | * In the SMP+IOAPIC case it might happen that there are an unspecified |
| 1648 | * number of pending IRQ events unhandled. These cases are very rare, |
| 1649 | * so we 'resend' these IRQs via IPIs, to the same CPU. It's much |
| 1650 | * better to do it this way as thus we do not have to be aware of |
| 1651 | * 'pending' interrupts in the IRQ path, except at this point. |
| 1652 | */ |
| 1653 | /* |
| 1654 | * Edge triggered needs to resend any interrupt |
| 1655 | * that was delayed but this is now handled in the device |
| 1656 | * independent code. |
| 1657 | */ |
| 1658 | |
| 1659 | /* |
| 1660 | * Starting up a edge-triggered IO-APIC interrupt is |
| 1661 | * nasty - we need to make sure that we get the edge. |
| 1662 | * If it is already asserted for some reason, we need |
| 1663 | * return 1 to indicate that is was pending. |
| 1664 | * |
| 1665 | * This is not complete - we should be able to fake |
| 1666 | * an edge even if it isn't on the 8259A... |
| 1667 | */ |
Thomas Gleixner | 61a38ce | 2010-09-28 16:00:34 +0200 | [diff] [blame] | 1668 | static unsigned int startup_ioapic_irq(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | { |
Thomas Gleixner | 61a38ce | 2010-09-28 16:00:34 +0200 | [diff] [blame] | 1670 | int was_pending = 0, irq = data->irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | unsigned long flags; |
| 1672 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1673 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 1674 | if (irq < nr_legacy_irqs()) { |
Thomas Gleixner | 4305df9 | 2010-09-28 15:01:33 +0200 | [diff] [blame] | 1675 | legacy_pic->mask(irq); |
Jacob Pan | b81bb37 | 2009-11-09 11:27:04 -0800 | [diff] [blame] | 1676 | if (legacy_pic->irq_pending(irq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1677 | was_pending = 1; |
| 1678 | } |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1679 | __unmask_ioapic(data->chip_data); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 1680 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | |
| 1682 | return was_pending; |
| 1683 | } |
| 1684 | |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 1685 | atomic_t irq_mis_count; |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 1686 | |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1687 | #ifdef CONFIG_GENERIC_PENDING_IRQ |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1688 | static bool io_apic_level_ack_pending(struct mp_chip_data *data) |
Márton Németh | d1ecad6 | 2012-05-08 00:24:20 -0700 | [diff] [blame] | 1689 | { |
| 1690 | struct irq_pin_list *entry; |
| 1691 | unsigned long flags; |
| 1692 | |
| 1693 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1694 | for_each_irq_pin(entry, data->irq_2_pin) { |
Márton Németh | d1ecad6 | 2012-05-08 00:24:20 -0700 | [diff] [blame] | 1695 | unsigned int reg; |
| 1696 | int pin; |
| 1697 | |
| 1698 | pin = entry->pin; |
| 1699 | reg = io_apic_read(entry->apic, 0x10 + pin*2); |
| 1700 | /* Is the remote IRR bit set? */ |
| 1701 | if (reg & IO_APIC_REDIR_REMOTE_IRR) { |
| 1702 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
| 1703 | return true; |
| 1704 | } |
| 1705 | } |
| 1706 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
| 1707 | |
| 1708 | return false; |
| 1709 | } |
| 1710 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1711 | static inline bool ioapic_irqd_mask(struct irq_data *data) |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1712 | { |
| 1713 | /* If we are moving the irq we need to mask it */ |
| 1714 | if (unlikely(irqd_is_setaffinity_pending(data))) { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1715 | mask_ioapic_irq(data); |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1716 | return true; |
| 1717 | } |
| 1718 | return false; |
| 1719 | } |
| 1720 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1721 | static inline void ioapic_irqd_unmask(struct irq_data *data, bool masked) |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1722 | { |
| 1723 | if (unlikely(masked)) { |
| 1724 | /* Only migrate the irq if the ack has been received. |
| 1725 | * |
| 1726 | * On rare occasions the broadcast level triggered ack gets |
| 1727 | * delayed going to ioapics, and if we reprogram the |
| 1728 | * vector while Remote IRR is still set the irq will never |
| 1729 | * fire again. |
| 1730 | * |
| 1731 | * To prevent this scenario we read the Remote IRR bit |
| 1732 | * of the ioapic. This has two effects. |
| 1733 | * - On any sane system the read of the ioapic will |
| 1734 | * flush writes (and acks) going to the ioapic from |
| 1735 | * this cpu. |
| 1736 | * - We get to see if the ACK has actually been delivered. |
| 1737 | * |
| 1738 | * Based on failed experiments of reprogramming the |
| 1739 | * ioapic entry from outside of irq context starting |
| 1740 | * with masking the ioapic entry and then polling until |
| 1741 | * Remote IRR was clear before reprogramming the |
| 1742 | * ioapic I don't trust the Remote IRR bit to be |
| 1743 | * completey accurate. |
| 1744 | * |
| 1745 | * However there appears to be no other way to plug |
| 1746 | * this race, so if the Remote IRR bit is not |
| 1747 | * accurate and is causing problems then it is a hardware bug |
| 1748 | * and you can go talk to the chipset vendor about it. |
| 1749 | */ |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1750 | if (!io_apic_level_ack_pending(data->chip_data)) |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1751 | irq_move_masked_irq(data); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1752 | unmask_ioapic_irq(data); |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1753 | } |
| 1754 | } |
| 1755 | #else |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1756 | static inline bool ioapic_irqd_mask(struct irq_data *data) |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1757 | { |
| 1758 | return false; |
| 1759 | } |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1760 | static inline void ioapic_irqd_unmask(struct irq_data *data, bool masked) |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1761 | { |
| 1762 | } |
| 1763 | #endif |
| 1764 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1765 | static void ioapic_ack_level(struct irq_data *irq_data) |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1766 | { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1767 | struct irq_cfg *cfg = irqd_cfg(irq_data); |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 1768 | unsigned long v; |
Alexander Gordeev | 4da7072 | 2012-03-20 15:19:36 +0100 | [diff] [blame] | 1769 | bool masked; |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1770 | int i; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1771 | |
Thomas Gleixner | dd5f15e | 2010-09-28 15:18:35 +0200 | [diff] [blame] | 1772 | irq_complete_move(cfg); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1773 | masked = ioapic_irqd_mask(irq_data); |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1774 | |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 1775 | /* |
Jeremy Fitzhardinge | 916a0fe | 2009-06-08 03:00:22 -0700 | [diff] [blame] | 1776 | * It appears there is an erratum which affects at least version 0x11 |
| 1777 | * of I/O APIC (that's the 82093AA and cores integrated into various |
| 1778 | * chipsets). Under certain conditions a level-triggered interrupt is |
| 1779 | * erroneously delivered as edge-triggered one but the respective IRR |
| 1780 | * bit gets set nevertheless. As a result the I/O unit expects an EOI |
| 1781 | * message but it will never arrive and further interrupts are blocked |
| 1782 | * from the source. The exact reason is so far unknown, but the |
| 1783 | * phenomenon was observed when two consecutive interrupt requests |
| 1784 | * from a given source get delivered to the same CPU and the source is |
| 1785 | * temporarily disabled in between. |
| 1786 | * |
| 1787 | * A workaround is to simulate an EOI message manually. We achieve it |
| 1788 | * by setting the trigger mode to edge and then to level when the edge |
| 1789 | * trigger mode gets detected in the TMR of a local APIC for a |
| 1790 | * level-triggered interrupt. We mask the source for the time of the |
| 1791 | * operation to prevent an edge-triggered interrupt escaping meanwhile. |
| 1792 | * The idea is from Manfred Spraul. --macro |
Suresh Siddha | 1c83995 | 2009-12-01 15:31:17 -0800 | [diff] [blame] | 1793 | * |
| 1794 | * Also in the case when cpu goes offline, fixup_irqs() will forward |
| 1795 | * any unhandled interrupt on the offlined cpu to the new cpu |
| 1796 | * destination that is handling the corresponding interrupt. This |
| 1797 | * interrupt forwarding is done via IPI's. Hence, in this case also |
| 1798 | * level-triggered io-apic interrupt will be seen as an edge |
| 1799 | * interrupt in the IRR. And we can't rely on the cpu's EOI |
| 1800 | * to be broadcasted to the IO-APIC's which will clear the remoteIRR |
| 1801 | * corresponding to the level-triggered interrupt. Hence on IO-APIC's |
| 1802 | * supporting EOI register, we do an explicit EOI to clear the |
| 1803 | * remote IRR and on IO-APIC's which don't have an EOI register, |
| 1804 | * we use the above logic (mask+edge followed by unmask+level) from |
| 1805 | * Manfred Spraul to clear the remote IRR. |
Jeremy Fitzhardinge | 916a0fe | 2009-06-08 03:00:22 -0700 | [diff] [blame] | 1806 | */ |
Yinghai Lu | 3145e94 | 2008-12-05 18:58:34 -0800 | [diff] [blame] | 1807 | i = cfg->vector; |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 1808 | v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1)); |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 1809 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 1810 | /* |
| 1811 | * We must acknowledge the irq before we move it or the acknowledge will |
| 1812 | * not propagate properly. |
| 1813 | */ |
| 1814 | ack_APIC_irq(); |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 1815 | |
Suresh Siddha | 1c83995 | 2009-12-01 15:31:17 -0800 | [diff] [blame] | 1816 | /* |
| 1817 | * Tail end of clearing remote IRR bit (either by delivering the EOI |
| 1818 | * message via io-apic EOI register write or simulating it using |
| 1819 | * mask+edge followed by unnask+level logic) manually when the |
| 1820 | * level triggered interrupt is seen as the edge triggered interrupt |
| 1821 | * at the cpu. |
| 1822 | */ |
Maciej W. Rozycki | ca64c47 | 2009-12-01 15:31:15 -0800 | [diff] [blame] | 1823 | if (!(v & (1 << (i & 0x1f)))) { |
| 1824 | atomic_inc(&irq_mis_count); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1825 | eoi_ioapic_pin(cfg->vector, irq_data->chip_data); |
Maciej W. Rozycki | ca64c47 | 2009-12-01 15:31:15 -0800 | [diff] [blame] | 1826 | } |
| 1827 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1828 | ioapic_irqd_unmask(irq_data, masked); |
Yinghai Lu | 3eb2cce | 2008-08-19 20:50:48 -0700 | [diff] [blame] | 1829 | } |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1830 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1831 | static void ioapic_ir_ack_level(struct irq_data *irq_data) |
| 1832 | { |
| 1833 | struct mp_chip_data *data = irq_data->chip_data; |
| 1834 | |
| 1835 | /* |
| 1836 | * Intr-remapping uses pin number as the virtual vector |
| 1837 | * in the RTE. Actual vector is programmed in |
| 1838 | * intr-remapping table entry. Hence for the io-apic |
| 1839 | * EOI we use the pin number. |
| 1840 | */ |
| 1841 | ack_APIC_irq(); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 1842 | eoi_ioapic_pin(data->entry.vector, data); |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | static int ioapic_set_affinity(struct irq_data *irq_data, |
| 1846 | const struct cpumask *mask, bool force) |
| 1847 | { |
| 1848 | struct irq_data *parent = irq_data->parent_data; |
| 1849 | struct mp_chip_data *data = irq_data->chip_data; |
Jiang Liu | 0be275e | 2015-04-14 10:29:57 +0800 | [diff] [blame] | 1850 | struct irq_pin_list *entry; |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1851 | struct irq_cfg *cfg; |
| 1852 | unsigned long flags; |
| 1853 | int ret; |
| 1854 | |
| 1855 | ret = parent->chip->irq_set_affinity(parent, mask, force); |
| 1856 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
| 1857 | if (ret >= 0 && ret != IRQ_SET_MASK_OK_DONE) { |
| 1858 | cfg = irqd_cfg(irq_data); |
| 1859 | data->entry.dest = cfg->dest_apicid; |
| 1860 | data->entry.vector = cfg->vector; |
Jiang Liu | 0be275e | 2015-04-14 10:29:57 +0800 | [diff] [blame] | 1861 | for_each_irq_pin(entry, data->irq_2_pin) |
| 1862 | __ioapic_write_entry(entry->apic, entry->pin, |
| 1863 | data->entry); |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1864 | } |
| 1865 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
| 1866 | |
| 1867 | return ret; |
| 1868 | } |
| 1869 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1870 | static struct irq_chip ioapic_chip __read_mostly = { |
Thomas Gleixner | f7e909e | 2010-10-08 21:40:23 +0200 | [diff] [blame] | 1871 | .name = "IO-APIC", |
| 1872 | .irq_startup = startup_ioapic_irq, |
| 1873 | .irq_mask = mask_ioapic_irq, |
| 1874 | .irq_unmask = unmask_ioapic_irq, |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1875 | .irq_ack = irq_chip_ack_parent, |
| 1876 | .irq_eoi = ioapic_ack_level, |
| 1877 | .irq_set_affinity = ioapic_set_affinity, |
Ruslan Ruslichenko | a9b4f08 | 2017-01-17 16:13:52 +0200 | [diff] [blame] | 1878 | .irq_retrigger = irq_chip_retrigger_hierarchy, |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 1879 | .flags = IRQCHIP_SKIP_SET_WAKE, |
| 1880 | }; |
| 1881 | |
| 1882 | static struct irq_chip ioapic_ir_chip __read_mostly = { |
| 1883 | .name = "IR-IO-APIC", |
| 1884 | .irq_startup = startup_ioapic_irq, |
| 1885 | .irq_mask = mask_ioapic_irq, |
| 1886 | .irq_unmask = unmask_ioapic_irq, |
| 1887 | .irq_ack = irq_chip_ack_parent, |
| 1888 | .irq_eoi = ioapic_ir_ack_level, |
| 1889 | .irq_set_affinity = ioapic_set_affinity, |
Ruslan Ruslichenko | a9b4f08 | 2017-01-17 16:13:52 +0200 | [diff] [blame] | 1890 | .irq_retrigger = irq_chip_retrigger_hierarchy, |
Rafael J. Wysocki | 5613570 | 2014-09-01 13:49:07 +0200 | [diff] [blame] | 1891 | .flags = IRQCHIP_SKIP_SET_WAKE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | }; |
| 1893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | static inline void init_IO_APIC_traps(void) |
| 1895 | { |
Yinghai Lu | da51a82 | 2008-08-19 20:50:25 -0700 | [diff] [blame] | 1896 | struct irq_cfg *cfg; |
Thomas Gleixner | ad9f433 | 2010-09-30 11:26:43 +0200 | [diff] [blame] | 1897 | unsigned int irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | |
Thomas Gleixner | ad9f433 | 2010-09-30 11:26:43 +0200 | [diff] [blame] | 1899 | for_each_active_irq(irq) { |
Jiang Liu | 32f5ef5 | 2014-06-09 16:19:43 +0800 | [diff] [blame] | 1900 | cfg = irq_cfg(irq); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1901 | if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | /* |
| 1903 | * Hmm.. We don't have an entry for this, |
| 1904 | * so default to an old-fashioned 8259 |
| 1905 | * interrupt if we can.. |
| 1906 | */ |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 1907 | if (irq < nr_legacy_irqs()) |
Jacob Pan | b81bb37 | 2009-11-09 11:27:04 -0800 | [diff] [blame] | 1908 | legacy_pic->make_irq(irq); |
Yinghai Lu | 0b8f1ef | 2008-12-05 18:58:31 -0800 | [diff] [blame] | 1909 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | /* Strange. Oh, well.. */ |
Thomas Gleixner | 2c77865 | 2011-03-12 12:20:43 +0100 | [diff] [blame] | 1911 | irq_set_chip(irq, &no_irq_chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | } |
| 1913 | } |
| 1914 | } |
| 1915 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1916 | /* |
| 1917 | * The local APIC irq-chip implementation: |
| 1918 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Thomas Gleixner | 90297c5 | 2010-09-28 16:03:54 +0200 | [diff] [blame] | 1920 | static void mask_lapic_irq(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | { |
| 1922 | unsigned long v; |
| 1923 | |
| 1924 | v = apic_read(APIC_LVT0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1925 | apic_write(APIC_LVT0, v | APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Thomas Gleixner | 90297c5 | 2010-09-28 16:03:54 +0200 | [diff] [blame] | 1928 | static void unmask_lapic_irq(struct irq_data *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | { |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1930 | unsigned long v; |
| 1931 | |
| 1932 | v = apic_read(APIC_LVT0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 1933 | apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
Thomas Gleixner | 90297c5 | 2010-09-28 16:03:54 +0200 | [diff] [blame] | 1936 | static void ack_lapic_irq(struct irq_data *data) |
Yinghai Lu | 1d02519 | 2008-08-19 20:50:34 -0700 | [diff] [blame] | 1937 | { |
| 1938 | ack_APIC_irq(); |
| 1939 | } |
| 1940 | |
Ingo Molnar | f5b9ed7 | 2006-10-04 02:16:26 -0700 | [diff] [blame] | 1941 | static struct irq_chip lapic_chip __read_mostly = { |
Maciej W. Rozycki | 9a1c619 | 2008-05-27 21:19:09 +0100 | [diff] [blame] | 1942 | .name = "local-APIC", |
Thomas Gleixner | 90297c5 | 2010-09-28 16:03:54 +0200 | [diff] [blame] | 1943 | .irq_mask = mask_lapic_irq, |
| 1944 | .irq_unmask = unmask_lapic_irq, |
| 1945 | .irq_ack = ack_lapic_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | }; |
| 1947 | |
Thomas Gleixner | 60c6994 | 2010-09-28 17:28:38 +0200 | [diff] [blame] | 1948 | static void lapic_register_intr(int irq) |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 1949 | { |
Thomas Gleixner | 60c6994 | 2010-09-28 17:28:38 +0200 | [diff] [blame] | 1950 | irq_clear_status_flags(irq, IRQ_LEVEL); |
Thomas Gleixner | 2c77865 | 2011-03-12 12:20:43 +0100 | [diff] [blame] | 1951 | 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] | 1952 | "edge"); |
Maciej W. Rozycki | c88ac1d | 2008-07-11 19:35:17 +0100 | [diff] [blame] | 1953 | } |
| 1954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | /* |
| 1956 | * This looks a bit hackish but it's about the only one way of sending |
| 1957 | * a few INTA cycles to 8259As and any associated glue logic. ICR does |
| 1958 | * not support the ExtINT mode, unfortunately. We need to send these |
| 1959 | * cycles as some i82489DX-based boards have glue logic that keeps the |
| 1960 | * 8259A interrupt line asserted until INTA. --macro |
| 1961 | */ |
Jacek Luczak | 28acf28 | 2008-04-12 17:41:12 +0200 | [diff] [blame] | 1962 | static inline void __init unlock_ExtINT_logic(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | { |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1964 | int apic, pin, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | struct IO_APIC_route_entry entry0, entry1; |
| 1966 | unsigned char save_control, save_freq_select; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1968 | pin = find_isa_irq_pin(8, mp_INT); |
Adrian Bunk | 956fb53 | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 1969 | if (pin == -1) { |
| 1970 | WARN_ON_ONCE(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | return; |
Adrian Bunk | 956fb53 | 2006-12-07 02:14:11 +0100 | [diff] [blame] | 1972 | } |
| 1973 | apic = find_isa_irq_apic(8, mp_INT); |
| 1974 | if (apic == -1) { |
| 1975 | WARN_ON_ONCE(1); |
| 1976 | return; |
| 1977 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1979 | entry0 = ioapic_read_entry(apic, pin); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 1980 | clear_IO_APIC_pin(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | |
| 1982 | memset(&entry1, 0, sizeof(entry1)); |
| 1983 | |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 1984 | entry1.dest_mode = IOAPIC_DEST_MODE_PHYSICAL; |
| 1985 | entry1.mask = IOAPIC_UNMASKED; |
Yinghai Lu | d83e94a | 2008-08-19 20:50:33 -0700 | [diff] [blame] | 1986 | entry1.dest = hard_smp_processor_id(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | entry1.delivery_mode = dest_ExtINT; |
| 1988 | entry1.polarity = entry0.polarity; |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 1989 | entry1.trigger = IOAPIC_EDGE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | entry1.vector = 0; |
| 1991 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 1992 | ioapic_write_entry(apic, pin, entry1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | |
| 1994 | save_control = CMOS_READ(RTC_CONTROL); |
| 1995 | save_freq_select = CMOS_READ(RTC_FREQ_SELECT); |
| 1996 | CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6, |
| 1997 | RTC_FREQ_SELECT); |
| 1998 | CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL); |
| 1999 | |
| 2000 | i = 100; |
| 2001 | while (i-- > 0) { |
| 2002 | mdelay(10); |
| 2003 | if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF) |
| 2004 | i -= 10; |
| 2005 | } |
| 2006 | |
| 2007 | CMOS_WRITE(save_control, RTC_CONTROL); |
| 2008 | CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2009 | clear_IO_APIC_pin(apic, pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
Andi Kleen | cf4c6a2 | 2006-09-26 10:52:30 +0200 | [diff] [blame] | 2011 | ioapic_write_entry(apic, pin, entry0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | } |
| 2013 | |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 2014 | static int disable_timer_pin_1 __initdata; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2015 | /* Actually the next is obsolete, but keep it for paranoid reasons -AK */ |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2016 | static int __init disable_timer_pin_setup(char *arg) |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 2017 | { |
| 2018 | disable_timer_pin_1 = 1; |
| 2019 | return 0; |
| 2020 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2021 | early_param("disable_timer_pin_1", disable_timer_pin_setup); |
Yinghai Lu | efa2559 | 2008-08-19 20:50:36 -0700 | [diff] [blame] | 2022 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2023 | static int mp_alloc_timer_irq(int ioapic, int pin) |
| 2024 | { |
| 2025 | int irq = -1; |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2026 | struct irq_domain *domain = mp_ioapic_irqdomain(ioapic); |
| 2027 | |
| 2028 | if (domain) { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2029 | struct irq_alloc_info info; |
| 2030 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2031 | ioapic_set_alloc_attr(&info, NUMA_NO_NODE, 0, 0); |
| 2032 | info.ioapic_id = mpc_ioapic_id(ioapic); |
| 2033 | info.ioapic_pin = pin; |
| 2034 | mutex_lock(&ioapic_mutex); |
| 2035 | irq = alloc_isa_irq_from_domain(domain, 0, ioapic, pin, &info); |
| 2036 | mutex_unlock(&ioapic_mutex); |
| 2037 | } |
| 2038 | |
| 2039 | return irq; |
| 2040 | } |
| 2041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | /* |
| 2043 | * This code may look a bit paranoid, but it's supposed to cooperate with |
| 2044 | * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ |
| 2045 | * is so screwy. Thanks to Brian Perkins for testing/hacking this beast |
| 2046 | * fanatically on his truly buggy board. |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2047 | * |
| 2048 | * FIXME: really need to revamp this for all platforms. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | */ |
Zachary Amsden | 8542b20 | 2006-12-07 02:14:09 +0100 | [diff] [blame] | 2050 | static inline void __init check_timer(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2052 | struct irq_data *irq_data = irq_get_irq_data(0); |
| 2053 | struct mp_chip_data *data = irq_data->chip_data; |
| 2054 | struct irq_cfg *cfg = irqd_cfg(irq_data); |
Robert Richter | f6e9456c | 2010-07-21 19:03:58 +0200 | [diff] [blame] | 2055 | int node = cpu_to_node(0); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2056 | int apic1, pin1, apic2, pin2; |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2057 | unsigned long flags; |
Yinghai Lu | 047c8fd | 2008-08-19 20:50:41 -0700 | [diff] [blame] | 2058 | int no_pin1 = 0; |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2059 | |
| 2060 | local_irq_save(flags); |
Maciej W. Rozycki | d4d25de | 2007-11-26 20:42:19 +0100 | [diff] [blame] | 2061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | /* |
| 2063 | * get/set the timer IRQ vector: |
| 2064 | */ |
Thomas Gleixner | 4305df9 | 2010-09-28 15:01:33 +0200 | [diff] [blame] | 2065 | legacy_pic->mask(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | |
| 2067 | /* |
Maciej W. Rozycki | d11d579 | 2008-05-21 22:09:11 +0100 | [diff] [blame] | 2068 | * As IRQ0 is to be enabled in the 8259A, the virtual |
| 2069 | * wire has to be disabled in the local APIC. Also |
| 2070 | * timer interrupts need to be acknowledged manually in |
| 2071 | * the 8259A for the i82489DX when using the NMI |
| 2072 | * watchdog as that APIC treats NMIs as level-triggered. |
| 2073 | * The AEOI mode will finish them in the 8259A |
| 2074 | * automatically. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 2076 | apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT); |
Jacob Pan | b81bb37 | 2009-11-09 11:27:04 -0800 | [diff] [blame] | 2077 | legacy_pic->init(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2078 | |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2079 | pin1 = find_isa_irq_pin(0, mp_INT); |
| 2080 | apic1 = find_isa_irq_apic(0, mp_INT); |
| 2081 | pin2 = ioapic_i8259.pin; |
| 2082 | apic2 = ioapic_i8259.apic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2084 | apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X " |
| 2085 | "apic1=%d pin1=%d apic2=%d pin2=%d\n", |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2086 | cfg->vector, apic1, pin1, apic2, pin2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2087 | |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2088 | /* |
| 2089 | * Some BIOS writers are clueless and report the ExtINTA |
| 2090 | * I/O APIC input from the cascaded 8259A as the timer |
| 2091 | * interrupt input. So just in case, if only one pin |
| 2092 | * was found above, try it both directly and through the |
| 2093 | * 8259A. |
| 2094 | */ |
| 2095 | if (pin1 == -1) { |
Joerg Roedel | 6a9f5de | 2012-09-26 12:44:41 +0200 | [diff] [blame] | 2096 | panic_if_irq_remap("BIOS bug: timer not connected to IO-APIC"); |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2097 | pin1 = pin2; |
| 2098 | apic1 = apic2; |
| 2099 | no_pin1 = 1; |
| 2100 | } else if (pin2 == -1) { |
| 2101 | pin2 = pin1; |
| 2102 | apic2 = apic1; |
| 2103 | } |
| 2104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | if (pin1 != -1) { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2106 | /* Ok, does IRQ0 through the IOAPIC work? */ |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2107 | if (no_pin1) { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2108 | mp_alloc_timer_irq(apic1, pin1); |
Yinghai Lu | f72dcca | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 2109 | } else { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2110 | /* |
| 2111 | * for edge trigger, it's already unmasked, |
Yinghai Lu | f72dcca | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 2112 | * so only need to unmask if it is level-trigger |
| 2113 | * do we really have level trigger timer? |
| 2114 | */ |
| 2115 | int idx; |
| 2116 | idx = find_irq_entry(apic1, pin1, mp_INT); |
| 2117 | if (idx != -1 && irq_trigger(idx)) |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2118 | unmask_ioapic_irq(irq_get_chip_data(0)); |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2119 | } |
Thomas Gleixner | aaaec6f | 2017-01-31 19:03:21 +0100 | [diff] [blame] | 2120 | irq_domain_deactivate_irq(irq_data); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2121 | irq_domain_activate_irq(irq_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | if (timer_irq_works()) { |
Chuck Ebbert | 66759a0 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 2123 | if (disable_timer_pin_1 > 0) |
| 2124 | clear_IO_APIC_pin(0, pin1); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2125 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | } |
Joerg Roedel | 6a9f5de | 2012-09-26 12:44:41 +0200 | [diff] [blame] | 2127 | panic_if_irq_remap("timer doesn't work through Interrupt-remapped IO-APIC"); |
Yinghai Lu | f72dcca | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 2128 | local_irq_disable(); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2129 | clear_IO_APIC_pin(apic1, pin1); |
Maciej W. Rozycki | 691874f | 2008-05-27 21:19:51 +0100 | [diff] [blame] | 2130 | if (!no_pin1) |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2131 | apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: " |
| 2132 | "8254 timer not connected to IO-APIC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2134 | apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer " |
| 2135 | "(IRQ0) through the 8259A ...\n"); |
| 2136 | apic_printk(APIC_QUIET, KERN_INFO |
| 2137 | "..... (found apic %d pin %d) ...\n", apic2, pin2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | /* |
| 2139 | * legacy devices should be connected to IO APIC #0 |
| 2140 | */ |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2141 | replace_pin_at_irq_node(data, node, apic1, pin1, apic2, pin2); |
Thomas Gleixner | aaaec6f | 2017-01-31 19:03:21 +0100 | [diff] [blame] | 2142 | irq_domain_deactivate_irq(irq_data); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2143 | irq_domain_activate_irq(irq_data); |
Thomas Gleixner | 4305df9 | 2010-09-28 15:01:33 +0200 | [diff] [blame] | 2144 | legacy_pic->unmask(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2145 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2146 | apic_printk(APIC_QUIET, KERN_INFO "....... works.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2147 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | } |
| 2149 | /* |
| 2150 | * Cleanup, just in case ... |
| 2151 | */ |
Yinghai Lu | f72dcca | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 2152 | local_irq_disable(); |
Thomas Gleixner | 4305df9 | 2010-09-28 15:01:33 +0200 | [diff] [blame] | 2153 | legacy_pic->mask(0); |
Eric W. Biederman | fcfd636 | 2005-10-30 14:59:39 -0800 | [diff] [blame] | 2154 | clear_IO_APIC_pin(apic2, pin2); |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2155 | apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2158 | apic_printk(APIC_QUIET, KERN_INFO |
| 2159 | "...trying to set up timer as Virtual Wire IRQ...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | |
Thomas Gleixner | 60c6994 | 2010-09-28 17:28:38 +0200 | [diff] [blame] | 2161 | lapic_register_intr(0); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2162 | apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */ |
Thomas Gleixner | 4305df9 | 2010-09-28 15:01:33 +0200 | [diff] [blame] | 2163 | legacy_pic->unmask(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | |
| 2165 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2166 | apic_printk(APIC_QUIET, KERN_INFO "..... works.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2167 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | } |
Yinghai Lu | f72dcca | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 2169 | local_irq_disable(); |
Thomas Gleixner | 4305df9 | 2010-09-28 15:01:33 +0200 | [diff] [blame] | 2170 | legacy_pic->mask(0); |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2171 | 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] | 2172 | apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2174 | apic_printk(APIC_QUIET, KERN_INFO |
| 2175 | "...trying to set up timer as ExtINT IRQ...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | |
Jacob Pan | b81bb37 | 2009-11-09 11:27:04 -0800 | [diff] [blame] | 2177 | legacy_pic->init(0); |
| 2178 | legacy_pic->make_irq(0); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 2179 | apic_write(APIC_LVT0, APIC_DM_EXTINT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | |
| 2181 | unlock_ExtINT_logic(); |
| 2182 | |
| 2183 | if (timer_irq_works()) { |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2184 | apic_printk(APIC_QUIET, KERN_INFO "..... works.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2185 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | } |
Yinghai Lu | f72dcca | 2009-02-08 16:18:03 -0800 | [diff] [blame] | 2187 | local_irq_disable(); |
Maciej W. Rozycki | 49a66a0 | 2008-07-14 19:08:13 +0100 | [diff] [blame] | 2188 | apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n"); |
Thomas Gleixner | 2ca5b40 | 2015-01-15 21:22:14 +0000 | [diff] [blame] | 2189 | if (apic_is_x2apic_enabled()) |
Yinghai Lu | fb209bd | 2011-12-21 17:45:17 -0800 | [diff] [blame] | 2190 | apic_printk(APIC_QUIET, KERN_INFO |
| 2191 | "Perhaps problem with the pre-enabled x2apic mode\n" |
| 2192 | "Try booting with x2apic and interrupt-remapping disabled in the bios.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | 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] | 2194 | "report. Then try booting with the 'noapic' option.\n"); |
Ingo Molnar | 4aae070 | 2007-12-18 18:05:58 +0100 | [diff] [blame] | 2195 | out: |
| 2196 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | /* |
Maciej W. Rozycki | af17478 | 2008-07-11 19:35:23 +0100 | [diff] [blame] | 2200 | * Traditionally ISA IRQ2 is the cascade IRQ, and is not available |
| 2201 | * to devices. However there may be an I/O APIC pin available for |
| 2202 | * this interrupt regardless. The pin may be left unconnected, but |
| 2203 | * typically it will be reused as an ExtINT cascade interrupt for |
| 2204 | * the master 8259A. In the MPS case such a pin will normally be |
| 2205 | * reported as an ExtINT interrupt in the MP table. With ACPI |
| 2206 | * there is no provision for ExtINT interrupts, and in the absence |
| 2207 | * of an override it would be treated as an ordinary ISA I/O APIC |
| 2208 | * interrupt, that is edge-triggered and unmasked by default. We |
| 2209 | * used to do this, but it caused problems on some systems because |
| 2210 | * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using |
| 2211 | * the same ExtINT cascade interrupt to drive the local APIC of the |
| 2212 | * bootstrap processor. Therefore we refrain from routing IRQ2 to |
| 2213 | * the I/O APIC in all cases now. No actual device should request |
| 2214 | * it anyway. --macro |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | */ |
Thomas Gleixner | bc07844 | 2009-08-29 18:09:57 +0200 | [diff] [blame] | 2216 | #define PIC_IRQS (1UL << PIC_CASCADE_IR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2217 | |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 2218 | static int mp_irqdomain_create(int ioapic) |
| 2219 | { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2220 | struct irq_alloc_info info; |
| 2221 | struct irq_domain *parent; |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 2222 | int hwirqs = mp_ioapic_pin_count(ioapic); |
| 2223 | struct ioapic *ip = &ioapics[ioapic]; |
| 2224 | struct ioapic_domain_cfg *cfg = &ip->irqdomain_cfg; |
| 2225 | struct mp_ioapic_gsi *gsi_cfg = mp_ioapic_gsi_routing(ioapic); |
Thomas Gleixner | 1b60474 | 2017-06-20 01:37:07 +0200 | [diff] [blame] | 2226 | struct fwnode_handle *fn; |
| 2227 | char *name = "IO-APIC"; |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 2228 | |
| 2229 | if (cfg->type == IOAPIC_DOMAIN_INVALID) |
| 2230 | return 0; |
| 2231 | |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2232 | init_irq_alloc_info(&info, NULL); |
| 2233 | info.type = X86_IRQ_ALLOC_TYPE_IOAPIC; |
| 2234 | info.ioapic_id = mpc_ioapic_id(ioapic); |
| 2235 | parent = irq_remapping_get_ir_irq_domain(&info); |
| 2236 | if (!parent) |
| 2237 | parent = x86_vector_domain; |
Thomas Gleixner | 1b60474 | 2017-06-20 01:37:07 +0200 | [diff] [blame] | 2238 | else |
| 2239 | name = "IO-APIC-IR"; |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2240 | |
Thomas Gleixner | 1b60474 | 2017-06-20 01:37:07 +0200 | [diff] [blame] | 2241 | /* Handle device tree enumerated APICs proper */ |
| 2242 | if (cfg->dev) { |
| 2243 | fn = of_node_to_fwnode(cfg->dev); |
| 2244 | } else { |
| 2245 | fn = irq_domain_alloc_named_id_fwnode(name, ioapic); |
| 2246 | if (!fn) |
| 2247 | return -ENOMEM; |
| 2248 | } |
| 2249 | |
| 2250 | ip->irqdomain = irq_domain_create_linear(fn, hwirqs, cfg->ops, |
| 2251 | (void *)(long)ioapic); |
| 2252 | |
| 2253 | /* Release fw handle if it was allocated above */ |
| 2254 | if (!cfg->dev) |
| 2255 | irq_domain_free_fwnode(fn); |
| 2256 | |
Jiang Liu | b75e818 | 2015-04-14 10:29:39 +0800 | [diff] [blame] | 2257 | if (!ip->irqdomain) |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 2258 | return -ENOMEM; |
Jiang Liu | b75e818 | 2015-04-14 10:29:39 +0800 | [diff] [blame] | 2259 | |
| 2260 | ip->irqdomain->parent = parent; |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 2261 | |
| 2262 | if (cfg->type == IOAPIC_DOMAIN_LEGACY || |
| 2263 | cfg->type == IOAPIC_DOMAIN_STRICT) |
| 2264 | ioapic_dynirq_base = max(ioapic_dynirq_base, |
| 2265 | gsi_cfg->gsi_end + 1); |
| 2266 | |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 2267 | return 0; |
| 2268 | } |
| 2269 | |
Jiang Liu | 15516a3 | 2014-10-27 13:21:46 +0800 | [diff] [blame] | 2270 | static void ioapic_destroy_irqdomain(int idx) |
| 2271 | { |
| 2272 | if (ioapics[idx].irqdomain) { |
| 2273 | irq_domain_remove(ioapics[idx].irqdomain); |
| 2274 | ioapics[idx].irqdomain = NULL; |
| 2275 | } |
Jiang Liu | 15516a3 | 2014-10-27 13:21:46 +0800 | [diff] [blame] | 2276 | } |
| 2277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | void __init setup_IO_APIC(void) |
| 2279 | { |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 2280 | int ioapic; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2281 | |
Thomas Gleixner | a46f5c8 | 2015-01-15 21:22:32 +0000 | [diff] [blame] | 2282 | if (skip_ioapic_setup || !nr_ioapics) |
| 2283 | return; |
| 2284 | |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 2285 | io_apic_irqs = nr_legacy_irqs() ? ~PIC_IRQS : ~0UL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2287 | apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n"); |
Jiang Liu | 44767bf | 2014-06-09 16:19:53 +0800 | [diff] [blame] | 2288 | for_each_ioapic(ioapic) |
| 2289 | BUG_ON(mp_irqdomain_create(ioapic)); |
| 2290 | |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2291 | /* |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2292 | * Set up IO-APIC IRQ routing. |
| 2293 | */ |
Thomas Gleixner | de93410 | 2009-08-20 09:27:29 +0200 | [diff] [blame] | 2294 | x86_init.mpparse.setup_ioapic_ids(); |
| 2295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | sync_Arb_IDs(); |
| 2297 | setup_IO_APIC_irqs(); |
| 2298 | init_IO_APIC_traps(); |
Jiang Liu | 95d76ac | 2014-06-09 16:19:48 +0800 | [diff] [blame] | 2299 | if (nr_legacy_irqs()) |
Thomas Gleixner | bc07844 | 2009-08-29 18:09:57 +0200 | [diff] [blame] | 2300 | check_timer(); |
Jiang Liu | b81975e | 2014-06-09 16:20:11 +0800 | [diff] [blame] | 2301 | |
| 2302 | ioapic_initialized = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | } |
| 2304 | |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 2305 | static void resume_ioapic_id(int ioapic_idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2306 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | unsigned long flags; |
| 2308 | union IO_APIC_reg_00 reg_00; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2309 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2310 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 2311 | reg_00.raw = io_apic_read(ioapic_idx, 0); |
| 2312 | if (reg_00.bits.ID != mpc_ioapic_id(ioapic_idx)) { |
| 2313 | reg_00.bits.ID = mpc_ioapic_id(ioapic_idx); |
| 2314 | io_apic_write(ioapic_idx, 0, reg_00.raw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | } |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2316 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2319 | static void ioapic_resume(void) |
| 2320 | { |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 2321 | int ioapic_idx; |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2322 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2323 | for_each_ioapic_reverse(ioapic_idx) |
Yinghai Lu | 6f50d45 | 2011-10-12 00:33:48 -0700 | [diff] [blame] | 2324 | resume_ioapic_id(ioapic_idx); |
Suresh Siddha | 15bac20 | 2011-05-18 16:31:34 -0700 | [diff] [blame] | 2325 | |
| 2326 | restore_ioapic_entries(); |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | static struct syscore_ops ioapic_syscore_ops = { |
Suresh Siddha | 15bac20 | 2011-05-18 16:31:34 -0700 | [diff] [blame] | 2330 | .suspend = save_ioapic_entries, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | .resume = ioapic_resume, |
| 2332 | }; |
| 2333 | |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2334 | static int __init ioapic_init_ops(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | { |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2336 | register_syscore_ops(&ioapic_syscore_ops); |
| 2337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | return 0; |
| 2339 | } |
| 2340 | |
Rafael J. Wysocki | f3c6ea1 | 2011-03-23 22:15:54 +0100 | [diff] [blame] | 2341 | device_initcall(ioapic_init_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | |
Jiang Liu | 67dc5e7 | 2014-10-27 13:21:41 +0800 | [diff] [blame] | 2343 | static int io_apic_get_redir_entries(int ioapic) |
Yinghai Lu | 9d6a4d0 | 2008-08-19 20:50:52 -0700 | [diff] [blame] | 2344 | { |
| 2345 | union IO_APIC_reg_01 reg_01; |
| 2346 | unsigned long flags; |
| 2347 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2348 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Yinghai Lu | 9d6a4d0 | 2008-08-19 20:50:52 -0700 | [diff] [blame] | 2349 | reg_01.raw = io_apic_read(ioapic, 1); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2350 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Yinghai Lu | 9d6a4d0 | 2008-08-19 20:50:52 -0700 | [diff] [blame] | 2351 | |
Eric W. Biederman | 4b6b19a | 2010-03-30 01:07:08 -0700 | [diff] [blame] | 2352 | /* The register returns the maximum index redir index |
| 2353 | * supported, which is one less than the total number of redir |
| 2354 | * entries. |
| 2355 | */ |
| 2356 | return reg_01.bits.entries + 1; |
Yinghai Lu | 9d6a4d0 | 2008-08-19 20:50:52 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
Thomas Gleixner | 62a08ae | 2014-04-24 09:50:53 +0200 | [diff] [blame] | 2359 | unsigned int arch_dynirq_lower_bound(unsigned int from) |
| 2360 | { |
Jiang Liu | b81975e | 2014-06-09 16:20:11 +0800 | [diff] [blame] | 2361 | /* |
| 2362 | * dmar_alloc_hwirq() may be called before setup_IO_APIC(), so use |
| 2363 | * gsi_top if ioapic_dynirq_base hasn't been initialized yet. |
| 2364 | */ |
| 2365 | return ioapic_initialized ? ioapic_dynirq_base : gsi_top; |
Thomas Gleixner | 62a08ae | 2014-04-24 09:50:53 +0200 | [diff] [blame] | 2366 | } |
| 2367 | |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2368 | #ifdef CONFIG_X86_32 |
Jiang Liu | 67dc5e7 | 2014-10-27 13:21:41 +0800 | [diff] [blame] | 2369 | static int io_apic_get_unique_id(int ioapic, int apic_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | { |
| 2371 | union IO_APIC_reg_00 reg_00; |
| 2372 | static physid_mask_t apic_id_map = PHYSID_MASK_NONE; |
| 2373 | physid_mask_t tmp; |
| 2374 | unsigned long flags; |
| 2375 | int i = 0; |
| 2376 | |
| 2377 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2378 | * The P4 platform supports up to 256 APIC IDs on two separate APIC |
| 2379 | * buses (one for LAPICs, one for IOAPICs), where predecessors only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | * supports up to 16 on one shared APIC bus. |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2381 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full |
| 2383 | * advantage of new APIC bus architecture. |
| 2384 | */ |
| 2385 | |
| 2386 | if (physids_empty(apic_id_map)) |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 2387 | apic->ioapic_phys_id_map(&phys_cpu_present_map, &apic_id_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2389 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | reg_00.raw = io_apic_read(ioapic, 0); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2391 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | |
| 2393 | if (apic_id >= get_physical_broadcast()) { |
| 2394 | printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying " |
| 2395 | "%d\n", ioapic, apic_id, reg_00.bits.ID); |
| 2396 | apic_id = reg_00.bits.ID; |
| 2397 | } |
| 2398 | |
| 2399 | /* |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2400 | * 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] | 2401 | * 'stuck on smp_invalidate_needed IPI wait' messages. |
| 2402 | */ |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 2403 | if (apic->check_apicid_used(&apic_id_map, apic_id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | |
| 2405 | for (i = 0; i < get_physical_broadcast(); i++) { |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 2406 | if (!apic->check_apicid_used(&apic_id_map, i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | break; |
| 2408 | } |
| 2409 | |
| 2410 | if (i == get_physical_broadcast()) |
| 2411 | panic("Max apic_id exceeded!\n"); |
| 2412 | |
| 2413 | printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, " |
| 2414 | "trying %d\n", ioapic, apic_id, i); |
| 2415 | |
| 2416 | apic_id = i; |
Paolo Ciarrocchi | 3606244 | 2008-06-08 13:07:18 +0200 | [diff] [blame] | 2417 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | |
Cyrill Gorcunov | 7abc075 | 2009-11-10 01:06:59 +0300 | [diff] [blame] | 2419 | apic->apicid_to_cpu_present(apic_id, &tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | physids_or(apic_id_map, apic_id_map, tmp); |
| 2421 | |
| 2422 | if (reg_00.bits.ID != apic_id) { |
| 2423 | reg_00.bits.ID = apic_id; |
| 2424 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2425 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | io_apic_write(ioapic, 0, reg_00.raw); |
| 2427 | reg_00.raw = io_apic_read(ioapic, 0); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2428 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | |
| 2430 | /* Sanity check */ |
Andreas Deresch | 6070f9e | 2006-02-26 04:18:34 +0100 | [diff] [blame] | 2431 | if (reg_00.bits.ID != apic_id) { |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 2432 | pr_err("IOAPIC[%d]: Unable to change apic_id!\n", |
| 2433 | ioapic); |
Andreas Deresch | 6070f9e | 2006-02-26 04:18:34 +0100 | [diff] [blame] | 2434 | return -1; |
| 2435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 2439 | "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id); |
| 2440 | |
| 2441 | return apic_id; |
| 2442 | } |
Thomas Gleixner | 41098ff | 2011-02-23 16:08:03 +0100 | [diff] [blame] | 2443 | |
Jiang Liu | 67dc5e7 | 2014-10-27 13:21:41 +0800 | [diff] [blame] | 2444 | static u8 io_apic_unique_id(int idx, u8 id) |
Thomas Gleixner | 41098ff | 2011-02-23 16:08:03 +0100 | [diff] [blame] | 2445 | { |
| 2446 | if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) && |
Denys Vlasenko | cff9ab2 | 2016-09-13 20:12:32 +0200 | [diff] [blame] | 2447 | !APIC_XAPIC(boot_cpu_apic_version)) |
Yinghai Lu | 5411dc4 | 2014-10-27 13:21:40 +0800 | [diff] [blame] | 2448 | return io_apic_get_unique_id(idx, id); |
Thomas Gleixner | 41098ff | 2011-02-23 16:08:03 +0100 | [diff] [blame] | 2449 | else |
| 2450 | return id; |
| 2451 | } |
| 2452 | #else |
Jiang Liu | 67dc5e7 | 2014-10-27 13:21:41 +0800 | [diff] [blame] | 2453 | static u8 io_apic_unique_id(int idx, u8 id) |
Thomas Gleixner | 41098ff | 2011-02-23 16:08:03 +0100 | [diff] [blame] | 2454 | { |
Yinghai Lu | 5411dc4 | 2014-10-27 13:21:40 +0800 | [diff] [blame] | 2455 | union IO_APIC_reg_00 reg_00; |
Thomas Gleixner | 41098ff | 2011-02-23 16:08:03 +0100 | [diff] [blame] | 2456 | DECLARE_BITMAP(used, 256); |
Yinghai Lu | 5411dc4 | 2014-10-27 13:21:40 +0800 | [diff] [blame] | 2457 | unsigned long flags; |
| 2458 | u8 new_id; |
| 2459 | int i; |
Thomas Gleixner | 41098ff | 2011-02-23 16:08:03 +0100 | [diff] [blame] | 2460 | |
| 2461 | bitmap_zero(used, 256); |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2462 | for_each_ioapic(i) |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 2463 | __set_bit(mpc_ioapic_id(i), used); |
Yinghai Lu | 5411dc4 | 2014-10-27 13:21:40 +0800 | [diff] [blame] | 2464 | |
| 2465 | /* Hand out the requested id if available */ |
Thomas Gleixner | 41098ff | 2011-02-23 16:08:03 +0100 | [diff] [blame] | 2466 | if (!test_bit(id, used)) |
| 2467 | return id; |
Yinghai Lu | 5411dc4 | 2014-10-27 13:21:40 +0800 | [diff] [blame] | 2468 | |
| 2469 | /* |
| 2470 | * Read the current id from the ioapic and keep it if |
| 2471 | * available. |
| 2472 | */ |
| 2473 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
| 2474 | reg_00.raw = io_apic_read(idx, 0); |
| 2475 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
| 2476 | new_id = reg_00.bits.ID; |
| 2477 | if (!test_bit(new_id, used)) { |
| 2478 | apic_printk(APIC_VERBOSE, KERN_INFO |
| 2479 | "IOAPIC[%d]: Using reg apic_id %d instead of %d\n", |
| 2480 | idx, new_id, id); |
| 2481 | return new_id; |
| 2482 | } |
| 2483 | |
| 2484 | /* |
| 2485 | * Get the next free id and write it to the ioapic. |
| 2486 | */ |
| 2487 | new_id = find_first_zero_bit(used, 256); |
| 2488 | reg_00.bits.ID = new_id; |
| 2489 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
| 2490 | io_apic_write(idx, 0, reg_00.raw); |
| 2491 | reg_00.raw = io_apic_read(idx, 0); |
| 2492 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
| 2493 | /* Sanity check */ |
| 2494 | BUG_ON(reg_00.bits.ID != new_id); |
| 2495 | |
| 2496 | return new_id; |
Thomas Gleixner | 41098ff | 2011-02-23 16:08:03 +0100 | [diff] [blame] | 2497 | } |
Naga Chumbalkar | 58f892e | 2009-05-26 21:48:07 +0000 | [diff] [blame] | 2498 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | |
Jiang Liu | 67dc5e7 | 2014-10-27 13:21:41 +0800 | [diff] [blame] | 2500 | static int io_apic_get_version(int ioapic) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | { |
| 2502 | union IO_APIC_reg_01 reg_01; |
| 2503 | unsigned long flags; |
| 2504 | |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2505 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | reg_01.raw = io_apic_read(ioapic, 1); |
Thomas Gleixner | dade771 | 2009-07-25 18:39:36 +0200 | [diff] [blame] | 2507 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | |
| 2509 | return reg_01.bits.version; |
| 2510 | } |
| 2511 | |
Eric W. Biederman | 9a0a91b | 2010-03-30 01:07:03 -0700 | [diff] [blame] | 2512 | int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity) |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 2513 | { |
Eric W. Biederman | 9a0a91b | 2010-03-30 01:07:03 -0700 | [diff] [blame] | 2514 | int ioapic, pin, idx; |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 2515 | |
| 2516 | if (skip_ioapic_setup) |
| 2517 | return -1; |
| 2518 | |
Eric W. Biederman | 9a0a91b | 2010-03-30 01:07:03 -0700 | [diff] [blame] | 2519 | ioapic = mp_find_ioapic(gsi); |
| 2520 | if (ioapic < 0) |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 2521 | return -1; |
| 2522 | |
Eric W. Biederman | 9a0a91b | 2010-03-30 01:07:03 -0700 | [diff] [blame] | 2523 | pin = mp_find_ioapic_pin(ioapic, gsi); |
| 2524 | if (pin < 0) |
| 2525 | return -1; |
| 2526 | |
| 2527 | idx = find_irq_entry(ioapic, pin, mp_INT); |
| 2528 | if (idx < 0) |
| 2529 | return -1; |
| 2530 | |
| 2531 | *trigger = irq_trigger(idx); |
| 2532 | *polarity = irq_polarity(idx); |
Shaohua Li | 61fd47e | 2007-11-17 01:05:28 -0500 | [diff] [blame] | 2533 | return 0; |
| 2534 | } |
| 2535 | |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2536 | /* |
| 2537 | * This function currently is only a helper for the i386 smp boot process where |
| 2538 | * 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] | 2539 | * so mask in all cases should simply be apic->target_cpus() |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2540 | */ |
| 2541 | #ifdef CONFIG_SMP |
| 2542 | void __init setup_ioapic_dest(void) |
| 2543 | { |
Eric W. Biederman | fad5399 | 2010-02-28 01:06:34 -0800 | [diff] [blame] | 2544 | int pin, ioapic, irq, irq_entry; |
Mike Travis | 22f65d3 | 2008-12-16 17:33:56 -0800 | [diff] [blame] | 2545 | const struct cpumask *mask; |
Thomas Gleixner | e23b257 | 2016-01-14 08:43:38 +0100 | [diff] [blame] | 2546 | struct irq_desc *desc; |
Thomas Gleixner | 5451ddc | 2011-02-05 15:35:51 +0100 | [diff] [blame] | 2547 | struct irq_data *idata; |
Thomas Gleixner | 4857c91 | 2015-09-14 12:00:55 +0200 | [diff] [blame] | 2548 | struct irq_chip *chip; |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2549 | |
| 2550 | if (skip_ioapic_setup == 1) |
| 2551 | return; |
| 2552 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2553 | for_each_ioapic_pin(ioapic, pin) { |
Yinghai Lu | b9c61b70 | 2009-05-06 10:10:06 -0700 | [diff] [blame] | 2554 | irq_entry = find_irq_entry(ioapic, pin, mp_INT); |
| 2555 | if (irq_entry == -1) |
| 2556 | continue; |
Yinghai Lu | b9c61b70 | 2009-05-06 10:10:06 -0700 | [diff] [blame] | 2557 | |
Jiang Liu | d7f3d47 | 2014-06-09 16:19:52 +0800 | [diff] [blame] | 2558 | irq = pin_2_irq(irq_entry, ioapic, pin, 0); |
| 2559 | if (irq < 0 || !mp_init_irq_at_boot(ioapic, irq)) |
Eric W. Biederman | fad5399 | 2010-02-28 01:06:34 -0800 | [diff] [blame] | 2560 | continue; |
| 2561 | |
Thomas Gleixner | e23b257 | 2016-01-14 08:43:38 +0100 | [diff] [blame] | 2562 | desc = irq_to_desc(irq); |
| 2563 | raw_spin_lock_irq(&desc->lock); |
| 2564 | idata = irq_desc_get_irq_data(desc); |
Yinghai Lu | b9c61b70 | 2009-05-06 10:10:06 -0700 | [diff] [blame] | 2565 | |
| 2566 | /* |
| 2567 | * Honour affinities which have been set in early boot |
| 2568 | */ |
Thomas Gleixner | 5451ddc | 2011-02-05 15:35:51 +0100 | [diff] [blame] | 2569 | if (!irqd_can_balance(idata) || irqd_affinity_was_set(idata)) |
Jiang Liu | c149e4c | 2015-06-03 11:46:22 +0800 | [diff] [blame] | 2570 | mask = irq_data_get_affinity_mask(idata); |
Yinghai Lu | b9c61b70 | 2009-05-06 10:10:06 -0700 | [diff] [blame] | 2571 | else |
| 2572 | mask = apic->target_cpus(); |
| 2573 | |
Thomas Gleixner | 4857c91 | 2015-09-14 12:00:55 +0200 | [diff] [blame] | 2574 | chip = irq_data_get_irq_chip(idata); |
Werner Pawlitschko | ababae4 | 2015-10-27 09:08:04 +0900 | [diff] [blame] | 2575 | /* Might be lapic_chip for irq 0 */ |
| 2576 | if (chip->irq_set_affinity) |
| 2577 | chip->irq_set_affinity(idata, mask, false); |
Thomas Gleixner | e23b257 | 2016-01-14 08:43:38 +0100 | [diff] [blame] | 2578 | raw_spin_unlock_irq(&desc->lock); |
Yinghai Lu | b9c61b70 | 2009-05-06 10:10:06 -0700 | [diff] [blame] | 2579 | } |
Yinghai Lu | 497c9a1 | 2008-08-19 20:50:28 -0700 | [diff] [blame] | 2580 | } |
| 2581 | #endif |
| 2582 | |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2583 | #define IOAPIC_RESOURCE_NAME_SIZE 11 |
| 2584 | |
| 2585 | static struct resource *ioapic_resources; |
| 2586 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2587 | static struct resource * __init ioapic_setup_resources(void) |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2588 | { |
| 2589 | unsigned long n; |
| 2590 | struct resource *res; |
| 2591 | char *mem; |
Rui Wang | 4855531 | 2016-06-08 14:59:53 +0800 | [diff] [blame] | 2592 | int i; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2593 | |
Rui Wang | 4855531 | 2016-06-08 14:59:53 +0800 | [diff] [blame] | 2594 | if (nr_ioapics == 0) |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2595 | return NULL; |
| 2596 | |
| 2597 | n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource); |
Rui Wang | 4855531 | 2016-06-08 14:59:53 +0800 | [diff] [blame] | 2598 | n *= nr_ioapics; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2599 | |
| 2600 | mem = alloc_bootmem(n); |
| 2601 | res = (void *)mem; |
| 2602 | |
Rui Wang | 4855531 | 2016-06-08 14:59:53 +0800 | [diff] [blame] | 2603 | mem += sizeof(struct resource) * nr_ioapics; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2604 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2605 | for_each_ioapic(i) { |
Rui Wang | 4855531 | 2016-06-08 14:59:53 +0800 | [diff] [blame] | 2606 | res[i].name = mem; |
| 2607 | res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
Cyrill Gorcunov | 4343fe1 | 2009-11-08 18:54:31 +0300 | [diff] [blame] | 2608 | snprintf(mem, IOAPIC_RESOURCE_NAME_SIZE, "IOAPIC %u", i); |
Cyrill Gorcunov | ffc4383 | 2009-08-24 21:53:39 +0400 | [diff] [blame] | 2609 | mem += IOAPIC_RESOURCE_NAME_SIZE; |
Rui Wang | 4855531 | 2016-06-08 14:59:53 +0800 | [diff] [blame] | 2610 | ioapics[i].iomem_res = &res[i]; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | ioapic_resources = res; |
| 2614 | |
| 2615 | return res; |
| 2616 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2617 | |
Thomas Gleixner | ca1b886 | 2015-04-24 13:57:48 +0200 | [diff] [blame] | 2618 | void __init io_apic_init_mappings(void) |
Jeremy Fitzhardinge | 136d249 | 2012-03-21 22:58:08 -0400 | [diff] [blame] | 2619 | { |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2620 | unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2621 | struct resource *ioapic_res; |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2622 | int i; |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2623 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2624 | ioapic_res = ioapic_setup_resources(); |
| 2625 | for_each_ioapic(i) { |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2626 | if (smp_found_config) { |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 2627 | ioapic_phys = mpc_ioapic_addr(i); |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2628 | #ifdef CONFIG_X86_32 |
Thomas Gleixner | d6c88a5 | 2008-10-15 15:27:23 +0200 | [diff] [blame] | 2629 | if (!ioapic_phys) { |
| 2630 | printk(KERN_ERR |
| 2631 | "WARNING: bogus zero IO-APIC " |
| 2632 | "address found in MPTABLE, " |
| 2633 | "disabling IO/APIC support!\n"); |
| 2634 | smp_found_config = 0; |
| 2635 | skip_ioapic_setup = 1; |
| 2636 | goto fake_ioapic_page; |
| 2637 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2638 | #endif |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2639 | } else { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2640 | #ifdef CONFIG_X86_32 |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2641 | fake_ioapic_page: |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2642 | #endif |
Cyrill Gorcunov | e79c65a | 2009-11-16 18:14:26 +0300 | [diff] [blame] | 2643 | ioapic_phys = (unsigned long)alloc_bootmem_pages(PAGE_SIZE); |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2644 | ioapic_phys = __pa(ioapic_phys); |
| 2645 | } |
| 2646 | set_fixmap_nocache(idx, ioapic_phys); |
Cyrill Gorcunov | e79c65a | 2009-11-16 18:14:26 +0300 | [diff] [blame] | 2647 | apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n", |
| 2648 | __fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK), |
| 2649 | ioapic_phys); |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2650 | idx++; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2651 | |
Cyrill Gorcunov | ffc4383 | 2009-08-24 21:53:39 +0400 | [diff] [blame] | 2652 | ioapic_res->start = ioapic_phys; |
Cyrill Gorcunov | e79c65a | 2009-11-16 18:14:26 +0300 | [diff] [blame] | 2653 | ioapic_res->end = ioapic_phys + IO_APIC_SLOT_SIZE - 1; |
Cyrill Gorcunov | ffc4383 | 2009-08-24 21:53:39 +0400 | [diff] [blame] | 2654 | ioapic_res++; |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 2655 | } |
| 2656 | } |
| 2657 | |
Yinghai Lu | 857fdc5 | 2009-07-10 09:36:20 -0700 | [diff] [blame] | 2658 | void __init ioapic_insert_resources(void) |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2659 | { |
| 2660 | int i; |
| 2661 | struct resource *r = ioapic_resources; |
| 2662 | |
| 2663 | if (!r) { |
Yinghai Lu | 857fdc5 | 2009-07-10 09:36:20 -0700 | [diff] [blame] | 2664 | if (nr_ioapics > 0) |
Bartlomiej Zolnierkiewicz | 04c93ce | 2009-03-20 21:02:55 +0100 | [diff] [blame] | 2665 | printk(KERN_ERR |
| 2666 | "IO APIC resources couldn't be allocated.\n"); |
Yinghai Lu | 857fdc5 | 2009-07-10 09:36:20 -0700 | [diff] [blame] | 2667 | return; |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2668 | } |
| 2669 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2670 | for_each_ioapic(i) { |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2671 | insert_resource(&iomem_resource, r); |
| 2672 | r++; |
| 2673 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2674 | } |
Ingo Molnar | 54168ed | 2008-08-20 09:07:45 +0200 | [diff] [blame] | 2675 | |
Eric W. Biederman | eddb0c5 | 2010-03-30 01:07:09 -0700 | [diff] [blame] | 2676 | int mp_find_ioapic(u32 gsi) |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2677 | { |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2678 | int i; |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2679 | |
Paul Bolle | 678301e | 2011-02-14 22:52:38 +0100 | [diff] [blame] | 2680 | if (nr_ioapics == 0) |
| 2681 | return -1; |
| 2682 | |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2683 | /* Find the IOAPIC that manages this GSI. */ |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2684 | for_each_ioapic(i) { |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 2685 | struct mp_ioapic_gsi *gsi_cfg = mp_ioapic_gsi_routing(i); |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2686 | if (gsi >= gsi_cfg->gsi_base && gsi <= gsi_cfg->gsi_end) |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2687 | return i; |
| 2688 | } |
| 2689 | |
| 2690 | printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi); |
| 2691 | return -1; |
| 2692 | } |
| 2693 | |
Eric W. Biederman | eddb0c5 | 2010-03-30 01:07:09 -0700 | [diff] [blame] | 2694 | int mp_find_ioapic_pin(int ioapic, u32 gsi) |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2695 | { |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 2696 | struct mp_ioapic_gsi *gsi_cfg; |
| 2697 | |
Jiang Liu | f44d169 | 2014-06-09 16:19:42 +0800 | [diff] [blame] | 2698 | if (WARN_ON(ioapic < 0)) |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2699 | return -1; |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 2700 | |
| 2701 | gsi_cfg = mp_ioapic_gsi_routing(ioapic); |
| 2702 | if (WARN_ON(gsi > gsi_cfg->gsi_end)) |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2703 | return -1; |
| 2704 | |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 2705 | return gsi - gsi_cfg->gsi_base; |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2706 | } |
| 2707 | |
Jiang Liu | 67dc5e7 | 2014-10-27 13:21:41 +0800 | [diff] [blame] | 2708 | static int bad_ioapic_register(int idx) |
Suresh Siddha | 73d63d0 | 2012-03-12 11:36:33 -0700 | [diff] [blame] | 2709 | { |
| 2710 | union IO_APIC_reg_00 reg_00; |
| 2711 | union IO_APIC_reg_01 reg_01; |
| 2712 | union IO_APIC_reg_02 reg_02; |
| 2713 | |
| 2714 | reg_00.raw = io_apic_read(idx, 0); |
| 2715 | reg_01.raw = io_apic_read(idx, 1); |
| 2716 | reg_02.raw = io_apic_read(idx, 2); |
| 2717 | |
| 2718 | if (reg_00.raw == -1 && reg_01.raw == -1 && reg_02.raw == -1) { |
| 2719 | pr_warn("I/O APIC 0x%x registers return all ones, skipping!\n", |
| 2720 | mpc_ioapic_addr(idx)); |
| 2721 | return 1; |
| 2722 | } |
| 2723 | |
| 2724 | return 0; |
| 2725 | } |
| 2726 | |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2727 | static int find_free_ioapic_entry(void) |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2728 | { |
Jiang Liu | 7db298c | 2014-10-27 13:21:45 +0800 | [diff] [blame] | 2729 | int idx; |
| 2730 | |
| 2731 | for (idx = 0; idx < MAX_IO_APICS; idx++) |
| 2732 | if (ioapics[idx].nr_registers == 0) |
| 2733 | return idx; |
| 2734 | |
| 2735 | return MAX_IO_APICS; |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | /** |
| 2739 | * mp_register_ioapic - Register an IOAPIC device |
| 2740 | * @id: hardware IOAPIC ID |
| 2741 | * @address: physical address of IOAPIC register area |
| 2742 | * @gsi_base: base of GSI associated with the IOAPIC |
| 2743 | * @cfg: configuration information for the IOAPIC |
| 2744 | */ |
| 2745 | int mp_register_ioapic(int id, u32 address, u32 gsi_base, |
| 2746 | struct ioapic_domain_cfg *cfg) |
| 2747 | { |
Jiang Liu | 7db298c | 2014-10-27 13:21:45 +0800 | [diff] [blame] | 2748 | bool hotplug = !!ioapic_initialized; |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 2749 | struct mp_ioapic_gsi *gsi_cfg; |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2750 | int idx, ioapic, entries; |
| 2751 | u32 gsi_end; |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2752 | |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2753 | if (!address) { |
| 2754 | pr_warn("Bogus (zero) I/O APIC address found, skipping!\n"); |
| 2755 | return -EINVAL; |
| 2756 | } |
| 2757 | for_each_ioapic(ioapic) |
| 2758 | if (ioapics[ioapic].mp_config.apicaddr == address) { |
| 2759 | pr_warn("address 0x%x conflicts with IOAPIC%d\n", |
| 2760 | address, ioapic); |
| 2761 | return -EEXIST; |
| 2762 | } |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2763 | |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2764 | idx = find_free_ioapic_entry(); |
| 2765 | if (idx >= MAX_IO_APICS) { |
| 2766 | pr_warn("Max # of I/O APICs (%d) exceeded (found %d), skipping\n", |
| 2767 | MAX_IO_APICS, idx); |
| 2768 | return -ENOSPC; |
| 2769 | } |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2770 | |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 2771 | ioapics[idx].mp_config.type = MP_IOAPIC; |
| 2772 | ioapics[idx].mp_config.flags = MPC_APIC_USABLE; |
| 2773 | ioapics[idx].mp_config.apicaddr = address; |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2774 | |
| 2775 | set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address); |
Suresh Siddha | 73d63d0 | 2012-03-12 11:36:33 -0700 | [diff] [blame] | 2776 | if (bad_ioapic_register(idx)) { |
| 2777 | clear_fixmap(FIX_IO_APIC_BASE_0 + idx); |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2778 | return -ENODEV; |
Suresh Siddha | 73d63d0 | 2012-03-12 11:36:33 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
Yinghai Lu | 5411dc4 | 2014-10-27 13:21:40 +0800 | [diff] [blame] | 2781 | ioapics[idx].mp_config.apicid = io_apic_unique_id(idx, id); |
Suresh Siddha | d537143 | 2011-05-18 16:31:37 -0700 | [diff] [blame] | 2782 | ioapics[idx].mp_config.apicver = io_apic_get_version(idx); |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2783 | |
| 2784 | /* |
| 2785 | * Build basic GSI lookup table to facilitate gsi->io_apic lookups |
| 2786 | * and to prevent reprogramming of IOAPIC pins (PCI GSIs). |
| 2787 | */ |
Eric W. Biederman | 7716a5c | 2010-03-30 01:07:12 -0700 | [diff] [blame] | 2788 | entries = io_apic_get_redir_entries(idx); |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2789 | gsi_end = gsi_base + entries - 1; |
| 2790 | for_each_ioapic(ioapic) { |
| 2791 | gsi_cfg = mp_ioapic_gsi_routing(ioapic); |
| 2792 | if ((gsi_base >= gsi_cfg->gsi_base && |
| 2793 | gsi_base <= gsi_cfg->gsi_end) || |
| 2794 | (gsi_end >= gsi_cfg->gsi_base && |
| 2795 | gsi_end <= gsi_cfg->gsi_end)) { |
| 2796 | pr_warn("GSI range [%u-%u] for new IOAPIC conflicts with GSI[%u-%u]\n", |
| 2797 | gsi_base, gsi_end, |
| 2798 | gsi_cfg->gsi_base, gsi_cfg->gsi_end); |
| 2799 | clear_fixmap(FIX_IO_APIC_BASE_0 + idx); |
| 2800 | return -ENOSPC; |
| 2801 | } |
| 2802 | } |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 2803 | gsi_cfg = mp_ioapic_gsi_routing(idx); |
| 2804 | gsi_cfg->gsi_base = gsi_base; |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2805 | gsi_cfg->gsi_end = gsi_end; |
Eric W. Biederman | 7716a5c | 2010-03-30 01:07:12 -0700 | [diff] [blame] | 2806 | |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2807 | ioapics[idx].irqdomain = NULL; |
| 2808 | ioapics[idx].irqdomain_cfg = *cfg; |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2809 | |
Jiang Liu | 7db298c | 2014-10-27 13:21:45 +0800 | [diff] [blame] | 2810 | /* |
| 2811 | * If mp_register_ioapic() is called during early boot stage when |
| 2812 | * walking ACPI/SFI/DT tables, it's too early to create irqdomain, |
| 2813 | * we are still using bootmem allocator. So delay it to setup_IO_APIC(). |
| 2814 | */ |
| 2815 | if (hotplug) { |
| 2816 | if (mp_irqdomain_create(idx)) { |
| 2817 | clear_fixmap(FIX_IO_APIC_BASE_0 + idx); |
| 2818 | return -ENOMEM; |
| 2819 | } |
| 2820 | alloc_ioapic_saved_registers(idx); |
| 2821 | } |
| 2822 | |
Suresh Siddha | c040aae | 2011-05-18 16:31:38 -0700 | [diff] [blame] | 2823 | if (gsi_cfg->gsi_end >= gsi_top) |
| 2824 | gsi_top = gsi_cfg->gsi_end + 1; |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2825 | if (nr_ioapics <= idx) |
| 2826 | nr_ioapics = idx + 1; |
| 2827 | |
| 2828 | /* Set nr_registers to mark entry present */ |
| 2829 | ioapics[idx].nr_registers = entries; |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2830 | |
Suresh Siddha | 73d63d0 | 2012-03-12 11:36:33 -0700 | [diff] [blame] | 2831 | pr_info("IOAPIC[%d]: apic_id %d, version %d, address 0x%x, GSI %d-%d\n", |
| 2832 | idx, mpc_ioapic_id(idx), |
| 2833 | mpc_ioapic_ver(idx), mpc_ioapic_addr(idx), |
| 2834 | gsi_cfg->gsi_base, gsi_cfg->gsi_end); |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2835 | |
Jiang Liu | 35ef9c9 | 2014-10-27 13:21:43 +0800 | [diff] [blame] | 2836 | return 0; |
Feng Tang | 2a4ab64 | 2009-07-07 23:01:15 -0400 | [diff] [blame] | 2837 | } |
Jacob Pan | 05ddafb | 2009-09-23 07:20:23 -0700 | [diff] [blame] | 2838 | |
Jiang Liu | 15516a3 | 2014-10-27 13:21:46 +0800 | [diff] [blame] | 2839 | int mp_unregister_ioapic(u32 gsi_base) |
| 2840 | { |
| 2841 | int ioapic, pin; |
| 2842 | int found = 0; |
Jiang Liu | 15516a3 | 2014-10-27 13:21:46 +0800 | [diff] [blame] | 2843 | |
| 2844 | for_each_ioapic(ioapic) |
| 2845 | if (ioapics[ioapic].gsi_config.gsi_base == gsi_base) { |
| 2846 | found = 1; |
| 2847 | break; |
| 2848 | } |
| 2849 | if (!found) { |
| 2850 | pr_warn("can't find IOAPIC for GSI %d\n", gsi_base); |
| 2851 | return -ENODEV; |
| 2852 | } |
| 2853 | |
| 2854 | for_each_pin(ioapic, pin) { |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2855 | u32 gsi = mp_pin_to_gsi(ioapic, pin); |
| 2856 | int irq = mp_map_gsi_to_irq(gsi, 0, NULL); |
| 2857 | struct mp_chip_data *data; |
| 2858 | |
| 2859 | if (irq >= 0) { |
| 2860 | data = irq_get_chip_data(irq); |
| 2861 | if (data && data->count) { |
| 2862 | pr_warn("pin%d on IOAPIC%d is still in use.\n", |
| 2863 | pin, ioapic); |
| 2864 | return -EBUSY; |
| 2865 | } |
Jiang Liu | 15516a3 | 2014-10-27 13:21:46 +0800 | [diff] [blame] | 2866 | } |
| 2867 | } |
| 2868 | |
| 2869 | /* Mark entry not present */ |
| 2870 | ioapics[ioapic].nr_registers = 0; |
| 2871 | ioapic_destroy_irqdomain(ioapic); |
| 2872 | free_ioapic_saved_registers(ioapic); |
| 2873 | if (ioapics[ioapic].iomem_res) |
| 2874 | release_resource(ioapics[ioapic].iomem_res); |
| 2875 | clear_fixmap(FIX_IO_APIC_BASE_0 + ioapic); |
| 2876 | memset(&ioapics[ioapic], 0, sizeof(ioapics[ioapic])); |
| 2877 | |
| 2878 | return 0; |
| 2879 | } |
| 2880 | |
Jiang Liu | e89900c | 2014-10-27 13:21:47 +0800 | [diff] [blame] | 2881 | int mp_ioapic_registered(u32 gsi_base) |
| 2882 | { |
| 2883 | int ioapic; |
| 2884 | |
| 2885 | for_each_ioapic(ioapic) |
| 2886 | if (ioapics[ioapic].gsi_config.gsi_base == gsi_base) |
| 2887 | return 1; |
| 2888 | |
| 2889 | return 0; |
| 2890 | } |
| 2891 | |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2892 | static void mp_irqdomain_get_attr(u32 gsi, struct mp_chip_data *data, |
Jiang Liu | 5ad274d | 2015-04-14 10:29:38 +0800 | [diff] [blame] | 2893 | struct irq_alloc_info *info) |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2894 | { |
| 2895 | if (info && info->ioapic_valid) { |
| 2896 | data->trigger = info->ioapic_trigger; |
| 2897 | data->polarity = info->ioapic_polarity; |
| 2898 | } else if (acpi_get_override_irq(gsi, &data->trigger, |
| 2899 | &data->polarity) < 0) { |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 2900 | /* PCI interrupts are always active low level triggered. */ |
| 2901 | data->trigger = IOAPIC_LEVEL; |
| 2902 | data->polarity = IOAPIC_POL_LOW; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | static void mp_setup_entry(struct irq_cfg *cfg, struct mp_chip_data *data, |
| 2907 | struct IO_APIC_route_entry *entry) |
| 2908 | { |
| 2909 | memset(entry, 0, sizeof(*entry)); |
| 2910 | entry->delivery_mode = apic->irq_delivery_mode; |
| 2911 | entry->dest_mode = apic->irq_dest_mode; |
| 2912 | entry->dest = cfg->dest_apicid; |
| 2913 | entry->vector = cfg->vector; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2914 | entry->trigger = data->trigger; |
| 2915 | entry->polarity = data->polarity; |
| 2916 | /* |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 2917 | * Mask level triggered irqs. Edge triggered irqs are masked |
| 2918 | * by the irq core code in case they fire. |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2919 | */ |
Thomas Gleixner | 335efdf | 2015-04-14 10:30:06 +0800 | [diff] [blame] | 2920 | if (data->trigger == IOAPIC_LEVEL) |
| 2921 | entry->mask = IOAPIC_MASKED; |
| 2922 | else |
| 2923 | entry->mask = IOAPIC_UNMASKED; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | int mp_irqdomain_alloc(struct irq_domain *domain, unsigned int virq, |
| 2927 | unsigned int nr_irqs, void *arg) |
| 2928 | { |
| 2929 | int ret, ioapic, pin; |
| 2930 | struct irq_cfg *cfg; |
| 2931 | struct irq_data *irq_data; |
| 2932 | struct mp_chip_data *data; |
| 2933 | struct irq_alloc_info *info = arg; |
Vitaly Kuznetsov | c0ff971 | 2015-10-15 19:42:23 +0200 | [diff] [blame] | 2934 | unsigned long flags; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2935 | |
| 2936 | if (!info || nr_irqs > 1) |
| 2937 | return -EINVAL; |
| 2938 | irq_data = irq_domain_get_irq_data(domain, virq); |
| 2939 | if (!irq_data) |
| 2940 | return -EINVAL; |
| 2941 | |
| 2942 | ioapic = mp_irqdomain_ioapic_idx(domain); |
| 2943 | pin = info->ioapic_pin; |
| 2944 | if (irq_find_mapping(domain, (irq_hw_number_t)pin) > 0) |
| 2945 | return -EEXIST; |
| 2946 | |
| 2947 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 2948 | if (!data) |
| 2949 | return -ENOMEM; |
| 2950 | |
| 2951 | info->ioapic_entry = &data->entry; |
| 2952 | ret = irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, info); |
| 2953 | if (ret < 0) { |
| 2954 | kfree(data); |
| 2955 | return ret; |
| 2956 | } |
| 2957 | |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2958 | INIT_LIST_HEAD(&data->irq_2_pin); |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2959 | irq_data->hwirq = info->ioapic_pin; |
Jiang Liu | d32932d | 2015-04-13 14:11:59 +0800 | [diff] [blame] | 2960 | irq_data->chip = (domain->parent == x86_vector_domain) ? |
| 2961 | &ioapic_chip : &ioapic_ir_chip; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2962 | irq_data->chip_data = data; |
| 2963 | mp_irqdomain_get_attr(mp_pin_to_gsi(ioapic, pin), data, info); |
| 2964 | |
| 2965 | cfg = irqd_cfg(irq_data); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2966 | add_pin_to_irq_node(data, ioapic_alloc_attr_node(info), ioapic, pin); |
Vitaly Kuznetsov | c0ff971 | 2015-10-15 19:42:23 +0200 | [diff] [blame] | 2967 | |
| 2968 | local_irq_save(flags); |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2969 | if (info->ioapic_entry) |
| 2970 | mp_setup_entry(cfg, data, info->ioapic_entry); |
| 2971 | mp_register_handler(virq, data->trigger); |
| 2972 | if (virq < nr_legacy_irqs()) |
| 2973 | legacy_pic->mask(virq); |
Vitaly Kuznetsov | c0ff971 | 2015-10-15 19:42:23 +0200 | [diff] [blame] | 2974 | local_irq_restore(flags); |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2975 | |
| 2976 | apic_printk(APIC_VERBOSE, KERN_DEBUG |
| 2977 | "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> IRQ %d Mode:%i Active:%i Dest:%d)\n", |
| 2978 | ioapic, mpc_ioapic_id(ioapic), pin, cfg->vector, |
| 2979 | virq, data->trigger, data->polarity, cfg->dest_apicid); |
| 2980 | |
| 2981 | return 0; |
| 2982 | } |
| 2983 | |
| 2984 | void mp_irqdomain_free(struct irq_domain *domain, unsigned int virq, |
| 2985 | unsigned int nr_irqs) |
| 2986 | { |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2987 | struct irq_data *irq_data; |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2988 | struct mp_chip_data *data; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2989 | |
| 2990 | BUG_ON(nr_irqs != 1); |
| 2991 | irq_data = irq_domain_get_irq_data(domain, virq); |
| 2992 | if (irq_data && irq_data->chip_data) { |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2993 | data = irq_data->chip_data; |
| 2994 | __remove_pin_from_irq(data, mp_irqdomain_ioapic_idx(domain), |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2995 | (int)irq_data->hwirq); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 2996 | WARN_ON(!list_empty(&data->irq_2_pin)); |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 2997 | kfree(irq_data->chip_data); |
| 2998 | } |
| 2999 | irq_domain_free_irqs_top(domain, virq, nr_irqs); |
| 3000 | } |
| 3001 | |
| 3002 | void mp_irqdomain_activate(struct irq_domain *domain, |
| 3003 | struct irq_data *irq_data) |
| 3004 | { |
| 3005 | unsigned long flags; |
| 3006 | struct irq_pin_list *entry; |
| 3007 | struct mp_chip_data *data = irq_data->chip_data; |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 3008 | |
| 3009 | raw_spin_lock_irqsave(&ioapic_lock, flags); |
Jiang Liu | 4467715 | 2015-04-14 10:29:53 +0800 | [diff] [blame] | 3010 | for_each_irq_pin(entry, data->irq_2_pin) |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 3011 | __ioapic_write_entry(entry->apic, entry->pin, data->entry); |
| 3012 | raw_spin_unlock_irqrestore(&ioapic_lock, flags); |
| 3013 | } |
| 3014 | |
| 3015 | void mp_irqdomain_deactivate(struct irq_domain *domain, |
| 3016 | struct irq_data *irq_data) |
| 3017 | { |
| 3018 | /* It won't be called for IRQ with multiple IOAPIC pins associated */ |
| 3019 | ioapic_mask_entry(mp_irqdomain_ioapic_idx(domain), |
| 3020 | (int)irq_data->hwirq); |
| 3021 | } |
| 3022 | |
Jiang Liu | 49c7e60 | 2015-04-13 14:11:55 +0800 | [diff] [blame] | 3023 | int mp_irqdomain_ioapic_idx(struct irq_domain *domain) |
| 3024 | { |
| 3025 | return (int)(long)domain->host_data; |
| 3026 | } |
Thomas Gleixner | f7a0c78 | 2015-04-14 10:30:08 +0800 | [diff] [blame] | 3027 | |
| 3028 | const struct irq_domain_ops mp_ioapic_irqdomain_ops = { |
| 3029 | .alloc = mp_irqdomain_alloc, |
| 3030 | .free = mp_irqdomain_free, |
| 3031 | .activate = mp_irqdomain_activate, |
| 3032 | .deactivate = mp_irqdomain_deactivate, |
| 3033 | }; |