blob: 94a4bcf9dca808e58657045397ca7f1f41363bfc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Intel IO-APIC support for multi-Pentium hosts.
3 *
Ingo Molnar8f47e162009-01-31 02:03:42 +01004 * Copyright (C) 1997, 1998, 1999, 2000, 2009 Ingo Molnar, Hajnalka Szabo
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Many thanks to Stig Venaas for trying out countless experimental
7 * patches and reporting/debugging problems patiently!
8 *
9 * (c) 1999, Multiple IO-APIC support, developed by
10 * Ken-ichi Yaku <yaku@css1.kbnes.nec.co.jp> and
11 * Hidemi Kishimoto <kisimoto@css1.kbnes.nec.co.jp>,
12 * further tested and cleaned up by Zach Brown <zab@redhat.com>
13 * and Ingo Molnar <mingo@redhat.com>
14 *
15 * Fixes
16 * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
17 * thanks to Eric Gilmore
18 * and Rolf G. Tews
19 * for testing these extensively
20 * Paul Diefenbaugh : Added full ACPI support
21 */
22
23#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/interrupt.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/sched.h>
Yinghai Lud4057bd2008-08-19 20:50:38 -070028#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <linux/mc146818rtc.h>
30#include <linux/compiler.h>
31#include <linux/acpi.h>
Alexey Dobriyan129f6942005-06-23 00:08:33 -070032#include <linux/module.h>
Rafael J. Wysockif3c6ea12011-03-23 22:15:54 +010033#include <linux/syscore_ops.h>
Eric W. Biederman3b7d1922006-10-04 02:16:59 -070034#include <linux/msi.h>
Eric W. Biederman95d77882006-10-04 02:17:01 -070035#include <linux/htirq.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080036#include <linux/freezer.h>
Eric W. Biedermanf26d6a22007-05-02 19:27:19 +020037#include <linux/kthread.h>
Ingo Molnar54168ed2008-08-20 09:07:45 +020038#include <linux/jiffies.h> /* time_after() */
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090039#include <linux/slab.h>
Yinghai Lud4057bd2008-08-19 20:50:38 -070040#ifdef CONFIG_ACPI
41#include <acpi/acpi_bus.h>
42#endif
43#include <linux/bootmem.h>
44#include <linux/dmar.h>
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -070045#include <linux/hpet.h>
Ashok Raj54d5d422005-09-06 15:16:15 -070046
Yinghai Lud4057bd2008-08-19 20:50:38 -070047#include <asm/idle.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <asm/io.h>
49#include <asm/smp.h>
Jaswinder Singh Rajput6d652ea2009-01-07 21:38:59 +053050#include <asm/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <asm/desc.h>
Yinghai Lud4057bd2008-08-19 20:50:38 -070052#include <asm/proto.h>
53#include <asm/acpi.h>
54#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <asm/timer.h>
Ingo Molnar306e4402005-06-30 02:58:55 -070056#include <asm/i8259.h>
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -070057#include <asm/msidef.h>
Eric W. Biederman8b955b02006-10-04 02:16:55 -070058#include <asm/hypertransport.h>
Yinghai Lua4dbc342008-07-25 02:14:28 -070059#include <asm/setup.h>
Yinghai Lud4057bd2008-08-19 20:50:38 -070060#include <asm/irq_remapping.h>
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -070061#include <asm/hpet.h>
Jaswinder Singh Rajput2c1b2842009-04-11 00:03:10 +053062#include <asm/hw_irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Ingo Molnar7b6aa332009-02-17 13:58:15 +010064#include <asm/apic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Maciej W. Rozycki32f71af2008-07-21 00:52:49 +010066#define __apicdebuginit(type) static type __init
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +040067#define for_each_irq_pin(entry, head) \
68 for (entry = head; entry; entry = entry->next)
Maciej W. Rozycki32f71af2008-07-21 00:52:49 +010069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/*
Ingo Molnar54168ed2008-08-20 09:07:45 +020071 * Is the SiS APIC rmw bug present ?
72 * -1 = don't know, 0 = no, 1 = yes
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 */
74int sis_apic_bug = -1;
75
Thomas Gleixnerdade7712009-07-25 18:39:36 +020076static DEFINE_RAW_SPINLOCK(ioapic_lock);
77static DEFINE_RAW_SPINLOCK(vector_lock);
Yinghai Luefa25592008-08-19 20:50:36 -070078
Suresh Siddhab69c6c32011-05-18 16:31:35 -070079static struct ioapic {
80 /*
81 * # of IRQ routing registers
82 */
83 int nr_registers;
Suresh Siddha57a6f742011-05-18 16:31:36 -070084 /*
85 * Saved state during suspend/resume, or while enabling intr-remap.
86 */
87 struct IO_APIC_route_entry *saved_registers;
Suresh Siddhad5371432011-05-18 16:31:37 -070088 /* I/O APIC config */
89 struct mpc_ioapic mp_config;
Suresh Siddhac040aae2011-05-18 16:31:38 -070090 /* IO APIC gsi routing info */
91 struct mp_ioapic_gsi gsi_config;
Suresh Siddha8f18c972011-05-18 16:31:39 -070092 DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
Suresh Siddhab69c6c32011-05-18 16:31:35 -070093} ioapics[MAX_IO_APICS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Suresh Siddhad5371432011-05-18 16:31:37 -070095#define mpc_ioapic_ver(id) ioapics[id].mp_config.apicver
96
97int mpc_ioapic_id(int id)
98{
99 return ioapics[id].mp_config.apicid;
100}
101
102unsigned int mpc_ioapic_addr(int id)
103{
104 return ioapics[id].mp_config.apicaddr;
105}
106
Suresh Siddhac040aae2011-05-18 16:31:38 -0700107struct mp_ioapic_gsi *mp_ioapic_gsi_routing(int id)
108{
109 return &ioapics[id].gsi_config;
110}
Alexey Starikovskiy9f640cc2008-04-04 23:41:13 +0400111
Suresh Siddhac040aae2011-05-18 16:31:38 -0700112int nr_ioapics;
Feng Tang2a4ab642009-07-07 23:01:15 -0400113
Eric W. Biedermana4384df2010-06-08 11:44:32 -0700114/* The one past the highest gsi number used */
115u32 gsi_top;
Eric W. Biederman57773722010-03-30 01:07:10 -0700116
Alexey Starikovskiy584f7342008-04-04 23:41:32 +0400117/* MP IRQ source entries */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530118struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES];
Alexey Starikovskiy584f7342008-04-04 23:41:32 +0400119
120/* # of MP IRQ source entries */
121int mp_irq_entries;
122
Thomas Gleixnerbc078442009-08-29 18:09:57 +0200123/* GSI interrupts */
124static int nr_irqs_gsi = NR_IRQS_LEGACY;
125
Alexey Starikovskiy8732fc42008-05-19 19:47:16 +0400126#if defined (CONFIG_MCA) || defined (CONFIG_EISA)
127int mp_bus_id_to_type[MAX_MP_BUSSES];
128#endif
129
130DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
131
Yinghai Luefa25592008-08-19 20:50:36 -0700132int skip_ioapic_setup;
133
Henrik Kretzschmar7167d082011-02-22 15:38:05 +0100134/**
135 * disable_ioapic_support() - disables ioapic support at runtime
136 */
137void disable_ioapic_support(void)
Ingo Molnar65a4e572009-01-31 03:36:17 +0100138{
139#ifdef CONFIG_PCI
140 noioapicquirk = 1;
141 noioapicreroute = -1;
142#endif
143 skip_ioapic_setup = 1;
144}
145
Ingo Molnar54168ed2008-08-20 09:07:45 +0200146static int __init parse_noapic(char *str)
Yinghai Luefa25592008-08-19 20:50:36 -0700147{
148 /* disable IO-APIC */
Henrik Kretzschmar7167d082011-02-22 15:38:05 +0100149 disable_ioapic_support();
Yinghai Luefa25592008-08-19 20:50:36 -0700150 return 0;
151}
152early_param("noapic", parse_noapic);
Chuck Ebbert66759a02005-09-12 18:49:25 +0200153
Sebastian Andrzej Siewior20443592011-04-27 16:30:52 +0200154static int io_apic_setup_irq_pin(unsigned int irq, int node,
155 struct io_apic_irq_attr *attr);
Thomas Gleixner710dcda2011-02-23 17:47:41 +0100156
Feng Tang2d8009b2010-11-19 11:33:35 +0800157/* Will be called in mpparse/acpi/sfi codes for saving IRQ info */
158void mp_save_irq(struct mpc_intsrc *m)
159{
160 int i;
161
162 apic_printk(APIC_VERBOSE, "Int: type %d, pol %d, trig %d, bus %02x,"
163 " IRQ %02x, APIC ID %x, APIC INT %02x\n",
164 m->irqtype, m->irqflag & 3, (m->irqflag >> 2) & 3, m->srcbus,
165 m->srcbusirq, m->dstapic, m->dstirq);
166
167 for (i = 0; i < mp_irq_entries; i++) {
Feng Tang0e3fa132010-12-08 15:18:57 +0800168 if (!memcmp(&mp_irqs[i], m, sizeof(*m)))
Feng Tang2d8009b2010-11-19 11:33:35 +0800169 return;
170 }
171
Feng Tang0e3fa132010-12-08 15:18:57 +0800172 memcpy(&mp_irqs[mp_irq_entries], m, sizeof(*m));
Feng Tang2d8009b2010-11-19 11:33:35 +0800173 if (++mp_irq_entries == MAX_IRQ_SOURCES)
174 panic("Max # of irq sources exceeded!!\n");
175}
176
Yinghai Lu0f978f42008-08-19 20:50:26 -0700177struct irq_pin_list {
178 int apic, pin;
179 struct irq_pin_list *next;
180};
Yinghai Lu301e6192008-08-19 20:50:02 -0700181
Thomas Gleixner7e495522010-09-28 23:31:50 +0200182static struct irq_pin_list *alloc_irq_pin_list(int node)
Yinghai Lu0f978f42008-08-19 20:50:26 -0700183{
Thomas Gleixner2ee39062010-10-06 16:28:51 +0200184 return kzalloc_node(sizeof(struct irq_pin_list), GFP_KERNEL, node);
Yinghai Lu0f978f42008-08-19 20:50:26 -0700185}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Feng Tang2d8009b2010-11-19 11:33:35 +0800187
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800188/* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
189#ifdef CONFIG_SPARSE_IRQ
Suresh Siddha97943392010-01-19 12:20:54 -0800190static struct irq_cfg irq_cfgx[NR_IRQS_LEGACY];
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800191#else
Suresh Siddha97943392010-01-19 12:20:54 -0800192static struct irq_cfg irq_cfgx[NR_IRQS];
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800193#endif
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800194
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800195int __init arch_early_irq_init(void)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800196{
197 struct irq_cfg *cfg;
Thomas Gleixner60c69942010-09-28 17:28:38 +0200198 int count, node, i;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800199
Jacob Pan1f912332010-02-05 04:06:56 -0800200 if (!legacy_pic->nr_legacy_irqs) {
201 nr_irqs_gsi = 0;
202 io_apic_irqs = ~0UL;
203 }
204
Suresh Siddha4c791852011-05-18 16:31:32 -0700205 for (i = 0; i < nr_ioapics; i++) {
Suresh Siddha57a6f742011-05-18 16:31:36 -0700206 ioapics[i].saved_registers =
Suresh Siddha4c791852011-05-18 16:31:32 -0700207 kzalloc(sizeof(struct IO_APIC_route_entry) *
Suresh Siddhab69c6c32011-05-18 16:31:35 -0700208 ioapics[i].nr_registers, GFP_KERNEL);
Suresh Siddha57a6f742011-05-18 16:31:36 -0700209 if (!ioapics[i].saved_registers)
Suresh Siddha4c791852011-05-18 16:31:32 -0700210 pr_err("IOAPIC %d: suspend/resume impossible!\n", i);
211 }
212
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800213 cfg = irq_cfgx;
214 count = ARRAY_SIZE(irq_cfgx);
Robert Richterf6e9456c2010-07-21 19:03:58 +0200215 node = cpu_to_node(0);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800216
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +0200217 /* Make sure the legacy interrupts are marked in the bitmap */
218 irq_reserve_irqs(0, legacy_pic->nr_legacy_irqs);
219
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800220 for (i = 0; i < count; i++) {
Thomas Gleixner2c778652011-03-12 12:20:43 +0100221 irq_set_chip_data(i, &cfg[i]);
Thomas Gleixner2ee39062010-10-06 16:28:51 +0200222 zalloc_cpumask_var_node(&cfg[i].domain, GFP_KERNEL, node);
223 zalloc_cpumask_var_node(&cfg[i].old_domain, GFP_KERNEL, node);
Suresh Siddha97943392010-01-19 12:20:54 -0800224 /*
225 * For legacy IRQ's, start with assigning irq0 to irq15 to
226 * IRQ0_VECTOR to IRQ15_VECTOR on cpu 0.
227 */
H. Peter Anvin54b56172010-02-22 16:25:18 -0800228 if (i < legacy_pic->nr_legacy_irqs) {
Suresh Siddha97943392010-01-19 12:20:54 -0800229 cfg[i].vector = IRQ0_VECTOR + i;
230 cpumask_set_cpu(0, cfg[i].domain);
231 }
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800232 }
Yinghai Lu13a0c3c2008-12-26 02:05:47 -0800233
234 return 0;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800235}
236
237#ifdef CONFIG_SPARSE_IRQ
Thomas Gleixner48b26502010-09-30 11:43:08 +0200238static struct irq_cfg *irq_cfg(unsigned int irq)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800239{
Thomas Gleixner2c778652011-03-12 12:20:43 +0100240 return irq_get_chip_data(irq);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800241}
242
Thomas Gleixnerf981a3d2010-10-08 10:44:21 +0200243static struct irq_cfg *alloc_irq_cfg(unsigned int irq, int node)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800244{
245 struct irq_cfg *cfg;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800246
Thomas Gleixner2ee39062010-10-06 16:28:51 +0200247 cfg = kzalloc_node(sizeof(*cfg), GFP_KERNEL, node);
Thomas Gleixner6e2fff52010-10-06 22:07:03 +0200248 if (!cfg)
249 return NULL;
Thomas Gleixner2ee39062010-10-06 16:28:51 +0200250 if (!zalloc_cpumask_var_node(&cfg->domain, GFP_KERNEL, node))
Thomas Gleixner6e2fff52010-10-06 22:07:03 +0200251 goto out_cfg;
Thomas Gleixner2ee39062010-10-06 16:28:51 +0200252 if (!zalloc_cpumask_var_node(&cfg->old_domain, GFP_KERNEL, node))
Thomas Gleixner6e2fff52010-10-06 22:07:03 +0200253 goto out_domain;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800254 return cfg;
Thomas Gleixner6e2fff52010-10-06 22:07:03 +0200255out_domain:
256 free_cpumask_var(cfg->domain);
257out_cfg:
258 kfree(cfg);
259 return NULL;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800260}
261
Thomas Gleixnerf981a3d2010-10-08 10:44:21 +0200262static void free_irq_cfg(unsigned int at, struct irq_cfg *cfg)
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200263{
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +0200264 if (!cfg)
265 return;
Thomas Gleixner2c778652011-03-12 12:20:43 +0100266 irq_set_chip_data(at, NULL);
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200267 free_cpumask_var(cfg->domain);
268 free_cpumask_var(cfg->old_domain);
269 kfree(cfg);
270}
271
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800272#else
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200273
Dimitri Sivanich9338ad62009-10-13 15:32:36 -0500274struct irq_cfg *irq_cfg(unsigned int irq)
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800275{
276 return irq < nr_irqs ? irq_cfgx + irq : NULL;
277}
278
Thomas Gleixnerf981a3d2010-10-08 10:44:21 +0200279static struct irq_cfg *alloc_irq_cfg(unsigned int irq, int node)
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200280{
281 return irq_cfgx + irq;
282}
283
Thomas Gleixnerf981a3d2010-10-08 10:44:21 +0200284static inline void free_irq_cfg(unsigned int at, struct irq_cfg *cfg) { }
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200285
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -0800286#endif
287
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200288static struct irq_cfg *alloc_irq_and_cfg_at(unsigned int at, int node)
289{
290 int res = irq_alloc_desc_at(at, node);
291 struct irq_cfg *cfg;
292
293 if (res < 0) {
294 if (res != -EEXIST)
295 return NULL;
Thomas Gleixner2c778652011-03-12 12:20:43 +0100296 cfg = irq_get_chip_data(at);
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200297 if (cfg)
298 return cfg;
299 }
300
Thomas Gleixnerf981a3d2010-10-08 10:44:21 +0200301 cfg = alloc_irq_cfg(at, node);
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200302 if (cfg)
Thomas Gleixner2c778652011-03-12 12:20:43 +0100303 irq_set_chip_data(at, cfg);
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200304 else
305 irq_free_desc(at);
306 return cfg;
307}
308
309static int alloc_irq_from(unsigned int from, int node)
310{
311 return irq_alloc_desc_from(from, node);
312}
313
314static void free_irq_at(unsigned int at, struct irq_cfg *cfg)
315{
Thomas Gleixnerf981a3d2010-10-08 10:44:21 +0200316 free_irq_cfg(at, cfg);
Thomas Gleixner08c33db2010-10-06 22:14:21 +0200317 irq_free_desc(at);
318}
319
Linus Torvalds130fe052006-11-01 09:11:00 -0800320struct io_apic {
321 unsigned int index;
322 unsigned int unused[3];
323 unsigned int data;
Suresh Siddha0280f7c2009-03-16 17:05:01 -0700324 unsigned int unused2[11];
325 unsigned int eoi;
Linus Torvalds130fe052006-11-01 09:11:00 -0800326};
327
328static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
329{
330 return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
Suresh Siddhad5371432011-05-18 16:31:37 -0700331 + (mpc_ioapic_addr(idx) & ~PAGE_MASK);
Linus Torvalds130fe052006-11-01 09:11:00 -0800332}
333
Suresh Siddha0280f7c2009-03-16 17:05:01 -0700334static inline void io_apic_eoi(unsigned int apic, unsigned int vector)
335{
336 struct io_apic __iomem *io_apic = io_apic_base(apic);
337 writel(vector, &io_apic->eoi);
338}
339
Linus Torvalds130fe052006-11-01 09:11:00 -0800340static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
341{
342 struct io_apic __iomem *io_apic = io_apic_base(apic);
343 writel(reg, &io_apic->index);
344 return readl(&io_apic->data);
345}
346
347static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value)
348{
349 struct io_apic __iomem *io_apic = io_apic_base(apic);
350 writel(reg, &io_apic->index);
351 writel(value, &io_apic->data);
352}
353
354/*
355 * Re-write a value: to be used for read-modify-write
356 * cycles where the read already set up the index register.
357 *
358 * Older SiS APIC requires we rewrite the index register
359 */
360static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
361{
Ingo Molnar54168ed2008-08-20 09:07:45 +0200362 struct io_apic __iomem *io_apic = io_apic_base(apic);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +0200363
364 if (sis_apic_bug)
365 writel(reg, &io_apic->index);
Linus Torvalds130fe052006-11-01 09:11:00 -0800366 writel(value, &io_apic->data);
367}
368
Yinghai Lu3145e942008-12-05 18:58:34 -0800369static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700370{
371 struct irq_pin_list *entry;
372 unsigned long flags;
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700373
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200374 raw_spin_lock_irqsave(&ioapic_lock, flags);
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +0400375 for_each_irq_pin(entry, cfg->irq_2_pin) {
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700376 unsigned int reg;
377 int pin;
378
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700379 pin = entry->pin;
380 reg = io_apic_read(entry->apic, 0x10 + pin*2);
381 /* Is the remote IRR bit set? */
382 if (reg & IO_APIC_REDIR_REMOTE_IRR) {
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200383 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700384 return true;
385 }
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700386 }
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200387 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700388
389 return false;
390}
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700391
Andi Kleencf4c6a22006-09-26 10:52:30 +0200392union entry_union {
393 struct { u32 w1, w2; };
394 struct IO_APIC_route_entry entry;
395};
396
397static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
398{
399 union entry_union eu;
400 unsigned long flags;
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200401 raw_spin_lock_irqsave(&ioapic_lock, flags);
Andi Kleencf4c6a22006-09-26 10:52:30 +0200402 eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
403 eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200404 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Andi Kleencf4c6a22006-09-26 10:52:30 +0200405 return eu.entry;
406}
407
Linus Torvaldsf9dadfa2006-11-01 10:05:35 -0800408/*
409 * When we write a new IO APIC routing entry, we need to write the high
410 * word first! If the mask bit in the low word is clear, we will enable
411 * the interrupt, and we need to make sure the entry is fully populated
412 * before that happens.
413 */
Andi Kleend15512f2006-12-07 02:14:07 +0100414static void
415__ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
416{
Figo.zhang50a8d4d22009-06-17 22:25:20 +0800417 union entry_union eu = {{0, 0}};
418
Andi Kleend15512f2006-12-07 02:14:07 +0100419 eu.entry = e;
420 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
421 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
422}
423
Thomas Gleixner1a8ce7f2010-10-04 21:08:56 +0200424static void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
Andi Kleencf4c6a22006-09-26 10:52:30 +0200425{
426 unsigned long flags;
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200427 raw_spin_lock_irqsave(&ioapic_lock, flags);
Andi Kleend15512f2006-12-07 02:14:07 +0100428 __ioapic_write_entry(apic, pin, e);
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200429 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvaldsf9dadfa2006-11-01 10:05:35 -0800430}
431
432/*
433 * When we mask an IO APIC routing entry, we need to write the low
434 * word first, in order to set the mask bit before we change the
435 * high bits!
436 */
437static void ioapic_mask_entry(int apic, int pin)
438{
439 unsigned long flags;
440 union entry_union eu = { .entry.mask = 1 };
441
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200442 raw_spin_lock_irqsave(&ioapic_lock, flags);
Andi Kleencf4c6a22006-09-26 10:52:30 +0200443 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
444 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200445 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Andi Kleencf4c6a22006-09-26 10:52:30 +0200446}
447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448/*
449 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
450 * shared ISA-space IRQs, so we have to support them. We are super
451 * fast in the common case, and fast for shared ISA-space IRQs.
452 */
Cyrill Gorcunovf3d19152009-08-06 00:09:31 +0400453static int
Thomas Gleixner7e495522010-09-28 23:31:50 +0200454__add_pin_to_irq_node(struct irq_cfg *cfg, int node, int apic, int pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +0400456 struct irq_pin_list **last, *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +0400458 /* don't allow duplicates */
459 last = &cfg->irq_2_pin;
460 for_each_irq_pin(entry, cfg->irq_2_pin) {
Yinghai Lu0f978f42008-08-19 20:50:26 -0700461 if (entry->apic == apic && entry->pin == pin)
Cyrill Gorcunovf3d19152009-08-06 00:09:31 +0400462 return 0;
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +0400463 last = &entry->next;
Yinghai Lu0f978f42008-08-19 20:50:26 -0700464 }
465
Thomas Gleixner7e495522010-09-28 23:31:50 +0200466 entry = alloc_irq_pin_list(node);
Cyrill Gorcunova7428cd2009-08-01 11:48:00 +0400467 if (!entry) {
Cyrill Gorcunovf3d19152009-08-06 00:09:31 +0400468 printk(KERN_ERR "can not alloc irq_pin_list (%d,%d,%d)\n",
469 node, apic, pin);
470 return -ENOMEM;
Cyrill Gorcunova7428cd2009-08-01 11:48:00 +0400471 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 entry->apic = apic;
473 entry->pin = pin;
Jeremy Fitzhardinge875e68e2009-06-08 03:24:11 -0700474
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +0400475 *last = entry;
Cyrill Gorcunovf3d19152009-08-06 00:09:31 +0400476 return 0;
477}
478
479static void add_pin_to_irq_node(struct irq_cfg *cfg, int node, int apic, int pin)
480{
Thomas Gleixner7e495522010-09-28 23:31:50 +0200481 if (__add_pin_to_irq_node(cfg, node, apic, pin))
Cyrill Gorcunovf3d19152009-08-06 00:09:31 +0400482 panic("IO-APIC: failed to add irq-pin. Can not proceed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
484
485/*
486 * Reroute an IRQ to a different pin.
487 */
Yinghai Lu85ac16d2009-04-27 18:00:38 -0700488static void __init replace_pin_at_irq_node(struct irq_cfg *cfg, int node,
Jeremy Fitzhardinge4eea6ff2009-06-08 03:32:15 -0700489 int oldapic, int oldpin,
490 int newapic, int newpin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491{
Jeremy Fitzhardinge535b6422009-06-08 03:29:26 -0700492 struct irq_pin_list *entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +0400494 for_each_irq_pin(entry, cfg->irq_2_pin) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 if (entry->apic == oldapic && entry->pin == oldpin) {
496 entry->apic = newapic;
497 entry->pin = newpin;
Yinghai Lu0f978f42008-08-19 20:50:26 -0700498 /* every one is different, right? */
Jeremy Fitzhardinge4eea6ff2009-06-08 03:32:15 -0700499 return;
Yinghai Lu0f978f42008-08-19 20:50:26 -0700500 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
Yinghai Lu0f978f42008-08-19 20:50:26 -0700502
Jeremy Fitzhardinge4eea6ff2009-06-08 03:32:15 -0700503 /* old apic/pin didn't exist, so just add new ones */
504 add_pin_to_irq_node(cfg, node, newapic, newpin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505}
506
Suresh Siddhac29d9db2009-12-01 15:31:16 -0800507static void __io_apic_modify_irq(struct irq_pin_list *entry,
508 int mask_and, int mask_or,
509 void (*final)(struct irq_pin_list *entry))
510{
511 unsigned int reg, pin;
512
513 pin = entry->pin;
514 reg = io_apic_read(entry->apic, 0x10 + pin * 2);
515 reg &= mask_and;
516 reg |= mask_or;
517 io_apic_modify(entry->apic, 0x10 + pin * 2, reg);
518 if (final)
519 final(entry);
520}
521
Jeremy Fitzhardinge2f210de2009-06-08 02:55:22 -0700522static void io_apic_modify_irq(struct irq_cfg *cfg,
523 int mask_and, int mask_or,
524 void (*final)(struct irq_pin_list *entry))
Cyrill Gorcunov87783be2008-09-10 22:19:50 +0400525{
Cyrill Gorcunov87783be2008-09-10 22:19:50 +0400526 struct irq_pin_list *entry;
527
Suresh Siddhac29d9db2009-12-01 15:31:16 -0800528 for_each_irq_pin(entry, cfg->irq_2_pin)
529 __io_apic_modify_irq(entry, mask_and, mask_or, final);
530}
531
532static void __mask_and_edge_IO_APIC_irq(struct irq_pin_list *entry)
533{
534 __io_apic_modify_irq(entry, ~IO_APIC_REDIR_LEVEL_TRIGGER,
535 IO_APIC_REDIR_MASKED, NULL);
536}
537
538static void __unmask_and_level_IO_APIC_irq(struct irq_pin_list *entry)
539{
540 __io_apic_modify_irq(entry, ~IO_APIC_REDIR_MASKED,
541 IO_APIC_REDIR_LEVEL_TRIGGER, NULL);
Yinghai Lu047c8fd2008-08-19 20:50:41 -0700542}
543
Jaswinder Singh Rajput7f3e6322008-12-29 20:34:35 +0530544static void io_apic_sync(struct irq_pin_list *entry)
Yinghai Lu4e738e22008-08-19 20:50:47 -0700545{
Cyrill Gorcunov87783be2008-09-10 22:19:50 +0400546 /*
547 * Synchronize the IO-APIC and the CPU by doing
548 * a dummy read from the IO-APIC
549 */
550 struct io_apic __iomem *io_apic;
551 io_apic = io_apic_base(entry->apic);
Yinghai Lu4e738e22008-08-19 20:50:47 -0700552 readl(&io_apic->data);
553}
554
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +0200555static void mask_ioapic(struct irq_cfg *cfg)
Cyrill Gorcunov87783be2008-09-10 22:19:50 +0400556{
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +0200557 unsigned long flags;
558
559 raw_spin_lock_irqsave(&ioapic_lock, flags);
Yinghai Lu3145e942008-12-05 18:58:34 -0800560 io_apic_modify_irq(cfg, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync);
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200561 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
Thomas Gleixner90297c52010-09-28 16:03:54 +0200564static void mask_ioapic_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565{
Thomas Gleixner90297c52010-09-28 16:03:54 +0200566 mask_ioapic(data->chip_data);
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +0200567}
568
569static void __unmask_ioapic(struct irq_cfg *cfg)
570{
571 io_apic_modify_irq(cfg, ~IO_APIC_REDIR_MASKED, 0, NULL);
572}
573
574static void unmask_ioapic(struct irq_cfg *cfg)
575{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 unsigned long flags;
577
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200578 raw_spin_lock_irqsave(&ioapic_lock, flags);
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +0200579 __unmask_ioapic(cfg);
Thomas Gleixnerdade7712009-07-25 18:39:36 +0200580 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
Thomas Gleixner90297c52010-09-28 16:03:54 +0200583static void unmask_ioapic_irq(struct irq_data *data)
Yinghai Lu3145e942008-12-05 18:58:34 -0800584{
Thomas Gleixner90297c52010-09-28 16:03:54 +0200585 unmask_ioapic(data->chip_data);
Yinghai Lu3145e942008-12-05 18:58:34 -0800586}
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
589{
590 struct IO_APIC_route_entry entry;
Paolo Ciarrocchi36062442008-06-08 13:07:18 +0200591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 /* Check delivery_mode to be sure we're not clearing an SMI pin */
Andi Kleencf4c6a22006-09-26 10:52:30 +0200593 entry = ioapic_read_entry(apic, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (entry.delivery_mode == dest_SMI)
595 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 /*
597 * Disable it in the IO-APIC irq-routing table:
598 */
Linus Torvaldsf9dadfa2006-11-01 10:05:35 -0800599 ioapic_mask_entry(apic, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
Ingo Molnar54168ed2008-08-20 09:07:45 +0200602static void clear_IO_APIC (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
604 int apic, pin;
605
606 for (apic = 0; apic < nr_ioapics; apic++)
Suresh Siddhab69c6c32011-05-18 16:31:35 -0700607 for (pin = 0; pin < ioapics[apic].nr_registers; pin++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 clear_IO_APIC_pin(apic, pin);
609}
610
Ingo Molnar54168ed2008-08-20 09:07:45 +0200611#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612/*
613 * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
614 * specific CPU-side IRQs.
615 */
616
617#define MAX_PIRQS 8
Yinghai Lu3bd25d02009-02-15 02:54:03 -0800618static int pirq_entries[MAX_PIRQS] = {
619 [0 ... MAX_PIRQS - 1] = -1
620};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622static int __init ioapic_pirq_setup(char *str)
623{
624 int i, max;
625 int ints[MAX_PIRQS+1];
626
627 get_options(str, ARRAY_SIZE(ints), ints);
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 apic_printk(APIC_VERBOSE, KERN_INFO
630 "PIRQ redirection, working around broken MP-BIOS.\n");
631 max = MAX_PIRQS;
632 if (ints[0] < MAX_PIRQS)
633 max = ints[0];
634
635 for (i = 0; i < max; i++) {
636 apic_printk(APIC_VERBOSE, KERN_DEBUG
637 "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
638 /*
639 * PIRQs are mapped upside down, usually.
640 */
641 pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
642 }
643 return 1;
644}
645
646__setup("pirq=", ioapic_pirq_setup);
Ingo Molnar54168ed2008-08-20 09:07:45 +0200647#endif /* CONFIG_X86_32 */
648
Ingo Molnar54168ed2008-08-20 09:07:45 +0200649/*
Suresh Siddha05c3dc22009-03-16 17:05:03 -0700650 * Saves all the IO-APIC RTE's
Ingo Molnar54168ed2008-08-20 09:07:45 +0200651 */
Suresh Siddha31dce142011-05-18 16:31:33 -0700652int save_ioapic_entries(void)
Ingo Molnar54168ed2008-08-20 09:07:45 +0200653{
Ingo Molnar54168ed2008-08-20 09:07:45 +0200654 int apic, pin;
Suresh Siddha31dce142011-05-18 16:31:33 -0700655 int err = 0;
Ingo Molnar54168ed2008-08-20 09:07:45 +0200656
657 for (apic = 0; apic < nr_ioapics; apic++) {
Suresh Siddha57a6f742011-05-18 16:31:36 -0700658 if (!ioapics[apic].saved_registers) {
Suresh Siddha31dce142011-05-18 16:31:33 -0700659 err = -ENOMEM;
660 continue;
661 }
Ingo Molnar54168ed2008-08-20 09:07:45 +0200662
Suresh Siddhab69c6c32011-05-18 16:31:35 -0700663 for (pin = 0; pin < ioapics[apic].nr_registers; pin++)
Suresh Siddha57a6f742011-05-18 16:31:36 -0700664 ioapics[apic].saved_registers[pin] =
Ingo Molnar54168ed2008-08-20 09:07:45 +0200665 ioapic_read_entry(apic, pin);
Fenghua Yub24696b2009-03-27 14:22:44 -0700666 }
Cyrill Gorcunov5ffa4eb2008-09-18 23:37:57 +0400667
Suresh Siddha31dce142011-05-18 16:31:33 -0700668 return err;
Ingo Molnar54168ed2008-08-20 09:07:45 +0200669}
670
Fenghua Yub24696b2009-03-27 14:22:44 -0700671/*
672 * Mask all IO APIC entries.
673 */
Suresh Siddha31dce142011-05-18 16:31:33 -0700674void mask_ioapic_entries(void)
Suresh Siddha05c3dc22009-03-16 17:05:03 -0700675{
676 int apic, pin;
677
678 for (apic = 0; apic < nr_ioapics; apic++) {
Suresh Siddha2f344d22011-05-24 10:45:31 -0700679 if (!ioapics[apic].saved_registers)
Suresh Siddha31dce142011-05-18 16:31:33 -0700680 continue;
Fenghua Yub24696b2009-03-27 14:22:44 -0700681
Suresh Siddhab69c6c32011-05-18 16:31:35 -0700682 for (pin = 0; pin < ioapics[apic].nr_registers; pin++) {
Suresh Siddha05c3dc22009-03-16 17:05:03 -0700683 struct IO_APIC_route_entry entry;
684
Suresh Siddha57a6f742011-05-18 16:31:36 -0700685 entry = ioapics[apic].saved_registers[pin];
Suresh Siddha05c3dc22009-03-16 17:05:03 -0700686 if (!entry.mask) {
687 entry.mask = 1;
688 ioapic_write_entry(apic, pin, entry);
689 }
690 }
691 }
692}
693
Fenghua Yub24696b2009-03-27 14:22:44 -0700694/*
Suresh Siddha57a6f742011-05-18 16:31:36 -0700695 * Restore IO APIC entries which was saved in the ioapic structure.
Fenghua Yub24696b2009-03-27 14:22:44 -0700696 */
Suresh Siddha31dce142011-05-18 16:31:33 -0700697int restore_ioapic_entries(void)
Ingo Molnar54168ed2008-08-20 09:07:45 +0200698{
699 int apic, pin;
700
Cyrill Gorcunov5ffa4eb2008-09-18 23:37:57 +0400701 for (apic = 0; apic < nr_ioapics; apic++) {
Suresh Siddha2f344d22011-05-24 10:45:31 -0700702 if (!ioapics[apic].saved_registers)
Suresh Siddha31dce142011-05-18 16:31:33 -0700703 continue;
Fenghua Yub24696b2009-03-27 14:22:44 -0700704
Suresh Siddhab69c6c32011-05-18 16:31:35 -0700705 for (pin = 0; pin < ioapics[apic].nr_registers; pin++)
Ingo Molnar54168ed2008-08-20 09:07:45 +0200706 ioapic_write_entry(apic, pin,
Suresh Siddha57a6f742011-05-18 16:31:36 -0700707 ioapics[apic].saved_registers[pin]);
Cyrill Gorcunov5ffa4eb2008-09-18 23:37:57 +0400708 }
Fenghua Yub24696b2009-03-27 14:22:44 -0700709 return 0;
Ingo Molnar54168ed2008-08-20 09:07:45 +0200710}
711
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712/*
713 * Find the IRQ entry number of a certain pin.
714 */
715static int find_irq_entry(int apic, int pin, int type)
716{
717 int i;
718
719 for (i = 0; i < mp_irq_entries; i++)
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530720 if (mp_irqs[i].irqtype == type &&
Suresh Siddhad5371432011-05-18 16:31:37 -0700721 (mp_irqs[i].dstapic == mpc_ioapic_id(apic) ||
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530722 mp_irqs[i].dstapic == MP_APIC_ALL) &&
723 mp_irqs[i].dstirq == pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 return i;
725
726 return -1;
727}
728
729/*
730 * Find the pin to which IRQ[irq] (ISA) is connected
731 */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -0800732static int __init find_isa_irq_pin(int irq, int type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
734 int i;
735
736 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530737 int lbus = mp_irqs[i].srcbus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Alexey Starikovskiyd27e2b82008-03-20 14:54:18 +0300739 if (test_bit(lbus, mp_bus_not_pci) &&
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530740 (mp_irqs[i].irqtype == type) &&
741 (mp_irqs[i].srcbusirq == irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530743 return mp_irqs[i].dstirq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
745 return -1;
746}
747
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -0800748static int __init find_isa_irq_apic(int irq, int type)
749{
750 int i;
751
752 for (i = 0; i < mp_irq_entries; i++) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530753 int lbus = mp_irqs[i].srcbus;
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -0800754
Alexey Starikovskiy73b29612008-03-20 14:54:24 +0300755 if (test_bit(lbus, mp_bus_not_pci) &&
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530756 (mp_irqs[i].irqtype == type) &&
757 (mp_irqs[i].srcbusirq == irq))
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -0800758 break;
759 }
760 if (i < mp_irq_entries) {
761 int apic;
Ingo Molnar54168ed2008-08-20 09:07:45 +0200762 for(apic = 0; apic < nr_ioapics; apic++) {
Suresh Siddhad5371432011-05-18 16:31:37 -0700763 if (mpc_ioapic_id(apic) == mp_irqs[i].dstapic)
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -0800764 return apic;
765 }
766 }
767
768 return -1;
769}
770
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300771#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772/*
773 * EISA Edge/Level control register, ELCR
774 */
775static int EISA_ELCR(unsigned int irq)
776{
Jacob Panb81bb372009-11-09 11:27:04 -0800777 if (irq < legacy_pic->nr_legacy_irqs) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 unsigned int port = 0x4d0 + (irq >> 3);
779 return (inb(port) >> (irq & 7)) & 1;
780 }
781 apic_printk(APIC_VERBOSE, KERN_INFO
782 "Broken MPtable reports ISA irq %d\n", irq);
783 return 0;
784}
Ingo Molnar54168ed2008-08-20 09:07:45 +0200785
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300786#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Alexey Starikovskiy67288012008-03-20 14:54:36 +0300788/* ISA interrupts are always polarity zero edge triggered,
789 * when listed as conforming in the MP table. */
790
791#define default_ISA_trigger(idx) (0)
792#define default_ISA_polarity(idx) (0)
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794/* EISA interrupts are always polarity zero and can be edge or level
795 * trigger depending on the ELCR value. If an interrupt is listed as
796 * EISA conforming in the MP table, that means its trigger type must
797 * be read in from the ELCR */
798
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530799#define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].srcbusirq))
Alexey Starikovskiy67288012008-03-20 14:54:36 +0300800#define default_EISA_polarity(idx) default_ISA_polarity(idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802/* PCI interrupts are always polarity one level triggered,
803 * when listed as conforming in the MP table. */
804
805#define default_PCI_trigger(idx) (1)
806#define default_PCI_polarity(idx) (1)
807
808/* MCA interrupts are always polarity zero level triggered,
809 * when listed as conforming in the MP table. */
810
811#define default_MCA_trigger(idx) (1)
Alexey Starikovskiy67288012008-03-20 14:54:36 +0300812#define default_MCA_polarity(idx) default_ISA_polarity(idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
Thomas Gleixnerb77cf6a2011-02-23 17:33:53 +0100814static int irq_polarity(int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530816 int bus = mp_irqs[idx].srcbus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 int polarity;
818
819 /*
820 * Determine IRQ line polarity (high active or low active):
821 */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530822 switch (mp_irqs[idx].irqflag & 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 {
Ingo Molnar54168ed2008-08-20 09:07:45 +0200824 case 0: /* conforms, ie. bus-type dependent polarity */
825 if (test_bit(bus, mp_bus_not_pci))
826 polarity = default_ISA_polarity(idx);
827 else
828 polarity = default_PCI_polarity(idx);
829 break;
830 case 1: /* high active */
831 {
832 polarity = 0;
833 break;
834 }
835 case 2: /* reserved */
836 {
837 printk(KERN_WARNING "broken BIOS!!\n");
838 polarity = 1;
839 break;
840 }
841 case 3: /* low active */
842 {
843 polarity = 1;
844 break;
845 }
846 default: /* invalid */
847 {
848 printk(KERN_WARNING "broken BIOS!!\n");
849 polarity = 1;
850 break;
851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 }
853 return polarity;
854}
855
Thomas Gleixnerb77cf6a2011-02-23 17:33:53 +0100856static int irq_trigger(int idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857{
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530858 int bus = mp_irqs[idx].srcbus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 int trigger;
860
861 /*
862 * Determine IRQ trigger mode (edge or level sensitive):
863 */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530864 switch ((mp_irqs[idx].irqflag>>2) & 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 {
Ingo Molnar54168ed2008-08-20 09:07:45 +0200866 case 0: /* conforms, ie. bus-type dependent */
867 if (test_bit(bus, mp_bus_not_pci))
868 trigger = default_ISA_trigger(idx);
869 else
870 trigger = default_PCI_trigger(idx);
Alexey Starikovskiyc0a282c2008-03-20 14:55:02 +0300871#if defined(CONFIG_EISA) || defined(CONFIG_MCA)
Ingo Molnar54168ed2008-08-20 09:07:45 +0200872 switch (mp_bus_id_to_type[bus]) {
873 case MP_BUS_ISA: /* ISA pin */
874 {
875 /* set before the switch */
876 break;
877 }
878 case MP_BUS_EISA: /* EISA pin */
879 {
880 trigger = default_EISA_trigger(idx);
881 break;
882 }
883 case MP_BUS_PCI: /* PCI pin */
884 {
885 /* set before the switch */
886 break;
887 }
888 case MP_BUS_MCA: /* MCA pin */
889 {
890 trigger = default_MCA_trigger(idx);
891 break;
892 }
893 default:
894 {
895 printk(KERN_WARNING "broken BIOS!!\n");
896 trigger = 1;
897 break;
898 }
899 }
900#endif
901 break;
902 case 1: /* edge */
Paolo Ciarrocchi36062442008-06-08 13:07:18 +0200903 {
Ingo Molnar54168ed2008-08-20 09:07:45 +0200904 trigger = 0;
Paolo Ciarrocchi36062442008-06-08 13:07:18 +0200905 break;
906 }
Ingo Molnar54168ed2008-08-20 09:07:45 +0200907 case 2: /* reserved */
Paolo Ciarrocchi36062442008-06-08 13:07:18 +0200908 {
909 printk(KERN_WARNING "broken BIOS!!\n");
910 trigger = 1;
911 break;
912 }
Ingo Molnar54168ed2008-08-20 09:07:45 +0200913 case 3: /* level */
914 {
915 trigger = 1;
916 break;
917 }
918 default: /* invalid */
919 {
920 printk(KERN_WARNING "broken BIOS!!\n");
921 trigger = 0;
922 break;
923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925 return trigger;
926}
927
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928static int pin_2_irq(int idx, int apic, int pin)
929{
Eric W. Biedermand4642072010-03-30 01:07:13 -0700930 int irq;
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530931 int bus = mp_irqs[idx].srcbus;
Suresh Siddhac040aae2011-05-18 16:31:38 -0700932 struct mp_ioapic_gsi *gsi_cfg = mp_ioapic_gsi_routing(apic);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934 /*
935 * Debugging check, we are in big trouble if this message pops up!
936 */
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530937 if (mp_irqs[idx].dstirq != pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
939
Ingo Molnar54168ed2008-08-20 09:07:45 +0200940 if (test_bit(bus, mp_bus_not_pci)) {
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +0530941 irq = mp_irqs[idx].srcbusirq;
Ingo Molnar54168ed2008-08-20 09:07:45 +0200942 } else {
Suresh Siddhac040aae2011-05-18 16:31:38 -0700943 u32 gsi = gsi_cfg->gsi_base + pin;
Eric W. Biederman988856e2010-03-30 01:07:15 -0700944
945 if (gsi >= NR_IRQS_LEGACY)
946 irq = gsi;
947 else
Eric W. Biedermana4384df2010-06-08 11:44:32 -0700948 irq = gsi_top + gsi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950
Ingo Molnar54168ed2008-08-20 09:07:45 +0200951#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 /*
953 * PCI IRQ command line redirection. Yes, limits are hardcoded.
954 */
955 if ((pin >= 16) && (pin <= 23)) {
956 if (pirq_entries[pin-16] != -1) {
957 if (!pirq_entries[pin-16]) {
958 apic_printk(APIC_VERBOSE, KERN_DEBUG
959 "disabling PIRQ%d\n", pin-16);
960 } else {
961 irq = pirq_entries[pin-16];
962 apic_printk(APIC_VERBOSE, KERN_DEBUG
963 "using PIRQ%d -> IRQ %d\n",
964 pin-16, irq);
965 }
966 }
967 }
Ingo Molnar54168ed2008-08-20 09:07:45 +0200968#endif
969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 return irq;
971}
972
Yinghai Lue20c06f2009-05-06 10:08:22 -0700973/*
974 * Find a specific PCI IRQ entry.
975 * Not an __init, possibly needed by modules
976 */
977int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
Yinghai Lue5198072009-05-15 13:05:16 -0700978 struct io_apic_irq_attr *irq_attr)
Yinghai Lue20c06f2009-05-06 10:08:22 -0700979{
980 int apic, i, best_guess = -1;
981
982 apic_printk(APIC_DEBUG,
983 "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
984 bus, slot, pin);
985 if (test_bit(bus, mp_bus_not_pci)) {
986 apic_printk(APIC_VERBOSE,
987 "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
988 return -1;
989 }
990 for (i = 0; i < mp_irq_entries; i++) {
991 int lbus = mp_irqs[i].srcbus;
992
993 for (apic = 0; apic < nr_ioapics; apic++)
Suresh Siddhad5371432011-05-18 16:31:37 -0700994 if (mpc_ioapic_id(apic) == mp_irqs[i].dstapic ||
Yinghai Lue20c06f2009-05-06 10:08:22 -0700995 mp_irqs[i].dstapic == MP_APIC_ALL)
996 break;
997
998 if (!test_bit(lbus, mp_bus_not_pci) &&
999 !mp_irqs[i].irqtype &&
1000 (bus == lbus) &&
1001 (slot == ((mp_irqs[i].srcbusirq >> 2) & 0x1f))) {
1002 int irq = pin_2_irq(i, apic, mp_irqs[i].dstirq);
1003
1004 if (!(apic || IO_APIC_IRQ(irq)))
1005 continue;
1006
1007 if (pin == (mp_irqs[i].srcbusirq & 3)) {
Yinghai Lue5198072009-05-15 13:05:16 -07001008 set_io_apic_irq_attr(irq_attr, apic,
1009 mp_irqs[i].dstirq,
1010 irq_trigger(i),
1011 irq_polarity(i));
Yinghai Lue20c06f2009-05-06 10:08:22 -07001012 return irq;
1013 }
1014 /*
1015 * Use the first all-but-pin matching entry as a
1016 * best-guess fuzzy result for broken mptables.
1017 */
1018 if (best_guess < 0) {
Yinghai Lue5198072009-05-15 13:05:16 -07001019 set_io_apic_irq_attr(irq_attr, apic,
1020 mp_irqs[i].dstirq,
1021 irq_trigger(i),
1022 irq_polarity(i));
Yinghai Lue20c06f2009-05-06 10:08:22 -07001023 best_guess = irq;
1024 }
1025 }
1026 }
1027 return best_guess;
1028}
1029EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
1030
Yinghai Lu497c9a12008-08-19 20:50:28 -07001031void lock_vector_lock(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
Yinghai Lu497c9a12008-08-19 20:50:28 -07001033 /* Used to the online set of cpus does not change
1034 * during assign_irq_vector.
1035 */
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001036 raw_spin_lock(&vector_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037}
1038
Yinghai Lu497c9a12008-08-19 20:50:28 -07001039void unlock_vector_lock(void)
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001040{
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001041 raw_spin_unlock(&vector_lock);
Yinghai Lu497c9a12008-08-19 20:50:28 -07001042}
1043
Mike Travise7986732008-12-16 17:33:52 -08001044static int
1045__assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
Yinghai Lu497c9a12008-08-19 20:50:28 -07001046{
Yinghai Lu047c8fd2008-08-19 20:50:41 -07001047 /*
1048 * NOTE! The local APIC isn't very good at handling
1049 * multiple interrupts at the same interrupt level.
1050 * As the interrupt level is determined by taking the
1051 * vector number and shifting that right by 4, we
1052 * want to spread these out a bit so that they don't
1053 * all fall in the same interrupt level.
1054 *
1055 * Also, we've got to be careful not to trash gate
1056 * 0x80, because int 0x80 is hm, kind of importantish. ;)
1057 */
Suresh Siddha6579b472010-01-13 16:19:11 -08001058 static int current_vector = FIRST_EXTERNAL_VECTOR + VECTOR_OFFSET_START;
H. Peter Anvinea943962010-01-04 21:14:41 -08001059 static int current_offset = VECTOR_OFFSET_START % 8;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001060 unsigned int old_vector;
Mike Travis22f65d32008-12-16 17:33:56 -08001061 int cpu, err;
1062 cpumask_var_t tmp_mask;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001063
Suresh Siddha23359a82009-10-26 14:24:33 -08001064 if (cfg->move_in_progress)
Ingo Molnar54168ed2008-08-20 09:07:45 +02001065 return -EBUSY;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001066
Mike Travis22f65d32008-12-16 17:33:56 -08001067 if (!alloc_cpumask_var(&tmp_mask, GFP_ATOMIC))
1068 return -ENOMEM;
Yinghai Lu3145e942008-12-05 18:58:34 -08001069
Ingo Molnar54168ed2008-08-20 09:07:45 +02001070 old_vector = cfg->vector;
1071 if (old_vector) {
Mike Travis22f65d32008-12-16 17:33:56 -08001072 cpumask_and(tmp_mask, mask, cpu_online_mask);
1073 cpumask_and(tmp_mask, cfg->domain, tmp_mask);
1074 if (!cpumask_empty(tmp_mask)) {
1075 free_cpumask_var(tmp_mask);
Ingo Molnar54168ed2008-08-20 09:07:45 +02001076 return 0;
Mike Travis22f65d32008-12-16 17:33:56 -08001077 }
Ingo Molnar54168ed2008-08-20 09:07:45 +02001078 }
Yinghai Lu497c9a12008-08-19 20:50:28 -07001079
Mike Travise7986732008-12-16 17:33:52 -08001080 /* Only try and allocate irqs on cpus that are present */
Mike Travis22f65d32008-12-16 17:33:56 -08001081 err = -ENOSPC;
1082 for_each_cpu_and(cpu, mask, cpu_online_mask) {
Ingo Molnar54168ed2008-08-20 09:07:45 +02001083 int new_cpu;
1084 int vector, offset;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001085
Ingo Molnare2d40b12009-01-28 06:50:47 +01001086 apic->vector_allocation_domain(cpu, tmp_mask);
Yinghai Lu497c9a12008-08-19 20:50:28 -07001087
Ingo Molnar54168ed2008-08-20 09:07:45 +02001088 vector = current_vector;
1089 offset = current_offset;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001090next:
Ingo Molnar54168ed2008-08-20 09:07:45 +02001091 vector += 8;
1092 if (vector >= first_system_vector) {
Mike Travise7986732008-12-16 17:33:52 -08001093 /* If out of vectors on large boxen, must share them. */
Ingo Molnar54168ed2008-08-20 09:07:45 +02001094 offset = (offset + 1) % 8;
Suresh Siddha6579b472010-01-13 16:19:11 -08001095 vector = FIRST_EXTERNAL_VECTOR + offset;
Yinghai Lu7a959cf2008-08-19 20:50:32 -07001096 }
Ingo Molnar54168ed2008-08-20 09:07:45 +02001097 if (unlikely(current_vector == vector))
1098 continue;
Yinghai Lub77b8812008-12-19 15:23:44 -08001099
1100 if (test_bit(vector, used_vectors))
Ingo Molnar54168ed2008-08-20 09:07:45 +02001101 goto next;
Yinghai Lub77b8812008-12-19 15:23:44 -08001102
Mike Travis22f65d32008-12-16 17:33:56 -08001103 for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
Ingo Molnar54168ed2008-08-20 09:07:45 +02001104 if (per_cpu(vector_irq, new_cpu)[vector] != -1)
1105 goto next;
1106 /* Found one! */
1107 current_vector = vector;
1108 current_offset = offset;
1109 if (old_vector) {
1110 cfg->move_in_progress = 1;
Mike Travis22f65d32008-12-16 17:33:56 -08001111 cpumask_copy(cfg->old_domain, cfg->domain);
Ingo Molnar54168ed2008-08-20 09:07:45 +02001112 }
Mike Travis22f65d32008-12-16 17:33:56 -08001113 for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
Ingo Molnar54168ed2008-08-20 09:07:45 +02001114 per_cpu(vector_irq, new_cpu)[vector] = irq;
1115 cfg->vector = vector;
Mike Travis22f65d32008-12-16 17:33:56 -08001116 cpumask_copy(cfg->domain, tmp_mask);
1117 err = 0;
1118 break;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001119 }
Mike Travis22f65d32008-12-16 17:33:56 -08001120 free_cpumask_var(tmp_mask);
1121 return err;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001122}
1123
Dimitri Sivanich9338ad62009-10-13 15:32:36 -05001124int assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
Yinghai Lu497c9a12008-08-19 20:50:28 -07001125{
1126 int err;
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001127 unsigned long flags;
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001128
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001129 raw_spin_lock_irqsave(&vector_lock, flags);
Yinghai Lu3145e942008-12-05 18:58:34 -08001130 err = __assign_irq_vector(irq, cfg, mask);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001131 raw_spin_unlock_irqrestore(&vector_lock, flags);
Yinghai Lu497c9a12008-08-19 20:50:28 -07001132 return err;
1133}
1134
Yinghai Lu3145e942008-12-05 18:58:34 -08001135static void __clear_irq_vector(int irq, struct irq_cfg *cfg)
Yinghai Lu497c9a12008-08-19 20:50:28 -07001136{
Yinghai Lu497c9a12008-08-19 20:50:28 -07001137 int cpu, vector;
1138
Yinghai Lu497c9a12008-08-19 20:50:28 -07001139 BUG_ON(!cfg->vector);
1140
1141 vector = cfg->vector;
Mike Travis22f65d32008-12-16 17:33:56 -08001142 for_each_cpu_and(cpu, cfg->domain, cpu_online_mask)
Yinghai Lu497c9a12008-08-19 20:50:28 -07001143 per_cpu(vector_irq, cpu)[vector] = -1;
1144
1145 cfg->vector = 0;
Mike Travis22f65d32008-12-16 17:33:56 -08001146 cpumask_clear(cfg->domain);
Matthew Wilcox0ca4b6b2008-11-20 14:09:33 -07001147
1148 if (likely(!cfg->move_in_progress))
1149 return;
Mike Travis22f65d32008-12-16 17:33:56 -08001150 for_each_cpu_and(cpu, cfg->old_domain, cpu_online_mask) {
Matthew Wilcox0ca4b6b2008-11-20 14:09:33 -07001151 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS;
1152 vector++) {
1153 if (per_cpu(vector_irq, cpu)[vector] != irq)
1154 continue;
1155 per_cpu(vector_irq, cpu)[vector] = -1;
1156 break;
1157 }
1158 }
1159 cfg->move_in_progress = 0;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001160}
1161
1162void __setup_vector_irq(int cpu)
1163{
1164 /* Initialize vector_irq on a new cpu */
Yinghai Lu497c9a12008-08-19 20:50:28 -07001165 int irq, vector;
1166 struct irq_cfg *cfg;
1167
Suresh Siddha9d133e52010-01-29 11:42:21 -08001168 /*
1169 * vector_lock will make sure that we don't run into irq vector
1170 * assignments that might be happening on another cpu in parallel,
1171 * while we setup our initial vector to irq mappings.
1172 */
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001173 raw_spin_lock(&vector_lock);
Yinghai Lu497c9a12008-08-19 20:50:28 -07001174 /* Mark the inuse vectors */
Thomas Gleixnerad9f4332010-09-30 11:26:43 +02001175 for_each_active_irq(irq) {
Thomas Gleixner2c778652011-03-12 12:20:43 +01001176 cfg = irq_get_chip_data(irq);
Thomas Gleixnerad9f4332010-09-30 11:26:43 +02001177 if (!cfg)
1178 continue;
Suresh Siddha36e9e1e2010-03-15 14:33:06 -08001179 /*
1180 * If it is a legacy IRQ handled by the legacy PIC, this cpu
1181 * will be part of the irq_cfg's domain.
1182 */
1183 if (irq < legacy_pic->nr_legacy_irqs && !IO_APIC_IRQ(irq))
1184 cpumask_set_cpu(cpu, cfg->domain);
1185
Mike Travis22f65d32008-12-16 17:33:56 -08001186 if (!cpumask_test_cpu(cpu, cfg->domain))
Yinghai Lu497c9a12008-08-19 20:50:28 -07001187 continue;
1188 vector = cfg->vector;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001189 per_cpu(vector_irq, cpu)[vector] = irq;
1190 }
1191 /* Mark the free vectors */
1192 for (vector = 0; vector < NR_VECTORS; ++vector) {
1193 irq = per_cpu(vector_irq, cpu)[vector];
1194 if (irq < 0)
1195 continue;
1196
1197 cfg = irq_cfg(irq);
Mike Travis22f65d32008-12-16 17:33:56 -08001198 if (!cpumask_test_cpu(cpu, cfg->domain))
Yinghai Lu497c9a12008-08-19 20:50:28 -07001199 per_cpu(vector_irq, cpu)[vector] = -1;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001200 }
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001201 raw_spin_unlock(&vector_lock);
Eric W. Biedermanace80ab2006-10-04 02:16:47 -07001202}
Glauber Costa3fde6902008-05-28 20:34:19 -07001203
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07001204static struct irq_chip ioapic_chip;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001205static struct irq_chip ir_ioapic_chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Yinghai Lu047c8fd2008-08-19 20:50:41 -07001207#ifdef CONFIG_X86_32
Yinghai Lu1d025192008-08-19 20:50:34 -07001208static inline int IO_APIC_irq_trigger(int irq)
1209{
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02001210 int apic, idx, pin;
Yinghai Lu1d025192008-08-19 20:50:34 -07001211
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02001212 for (apic = 0; apic < nr_ioapics; apic++) {
Suresh Siddhab69c6c32011-05-18 16:31:35 -07001213 for (pin = 0; pin < ioapics[apic].nr_registers; pin++) {
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02001214 idx = find_irq_entry(apic, pin, mp_INT);
1215 if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
1216 return irq_trigger(idx);
1217 }
1218 }
1219 /*
Ingo Molnar54168ed2008-08-20 09:07:45 +02001220 * nonexistent IRQs are edge default
1221 */
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02001222 return 0;
Yinghai Lu1d025192008-08-19 20:50:34 -07001223}
Yinghai Lu047c8fd2008-08-19 20:50:41 -07001224#else
1225static inline int IO_APIC_irq_trigger(int irq)
1226{
Ingo Molnar54168ed2008-08-20 09:07:45 +02001227 return 1;
Yinghai Lu047c8fd2008-08-19 20:50:41 -07001228}
1229#endif
Yinghai Lu1d025192008-08-19 20:50:34 -07001230
Thomas Gleixner1a0e62a2011-03-12 13:47:18 +01001231static void ioapic_register_intr(unsigned int irq, struct irq_cfg *cfg,
1232 unsigned long trigger)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01001234 struct irq_chip *chip = &ioapic_chip;
1235 irq_flow_handler_t hdl;
1236 bool fasteoi;
Yinghai Lu199751d2008-08-19 20:50:27 -07001237
Jan Beulich6ebcc002006-06-26 13:56:46 +02001238 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01001239 trigger == IOAPIC_LEVEL) {
Thomas Gleixner60c69942010-09-28 17:28:38 +02001240 irq_set_status_flags(irq, IRQ_LEVEL);
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01001241 fasteoi = true;
1242 } else {
Thomas Gleixner60c69942010-09-28 17:28:38 +02001243 irq_clear_status_flags(irq, IRQ_LEVEL);
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01001244 fasteoi = false;
1245 }
Yinghai Lu047c8fd2008-08-19 20:50:41 -07001246
Thomas Gleixner1a0e62a2011-03-12 13:47:18 +01001247 if (irq_remapped(cfg)) {
Thomas Gleixner60c69942010-09-28 17:28:38 +02001248 irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01001249 chip = &ir_ioapic_chip;
1250 fasteoi = trigger != 0;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001251 }
Suresh Siddha29b61be2009-03-16 17:05:02 -07001252
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01001253 hdl = fasteoi ? handle_fasteoi_irq : handle_edge_irq;
1254 irq_set_chip_and_handler_name(irq, chip, hdl,
1255 fasteoi ? "fasteoi" : "edge");
Yinghai Lu497c9a12008-08-19 20:50:28 -07001256}
1257
Yinghai Luc5b47122011-10-12 00:33:15 -07001258
1259static int setup_ir_ioapic_entry(int irq,
1260 struct IR_IO_APIC_route_entry *entry,
1261 unsigned int destination, int vector,
1262 struct io_apic_irq_attr *attr)
Yinghai Lu497c9a12008-08-19 20:50:28 -07001263{
Yinghai Luc5b47122011-10-12 00:33:15 -07001264 int index;
1265 struct irte irte;
1266 int apic_id = mpc_ioapic_id(attr->ioapic);
1267 struct intel_iommu *iommu = map_ioapic_to_ir(apic_id);
Yinghai Lu497c9a12008-08-19 20:50:28 -07001268
Yinghai Luc5b47122011-10-12 00:33:15 -07001269 if (!iommu) {
1270 pr_warn("No mapping iommu for ioapic %d\n", apic_id);
1271 return -ENODEV;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001272 }
1273
Yinghai Luc5b47122011-10-12 00:33:15 -07001274 index = alloc_irte(iommu, irq, 1);
1275 if (index < 0) {
1276 pr_warn("Failed to allocate IRTE for ioapic %d\n", apic_id);
1277 return -ENOMEM;
1278 }
1279
1280 prepare_irte(&irte, vector, destination);
1281
1282 /* Set source-id of interrupt request */
1283 set_ioapic_sid(&irte, apic_id);
1284
1285 modify_irte(irq, &irte);
1286
1287 apic_printk(APIC_VERBOSE, KERN_DEBUG "IOAPIC[%d]: "
1288 "Set IRTE entry (P:%d FPD:%d Dst_Mode:%d "
1289 "Redir_hint:%d Trig_Mode:%d Dlvry_Mode:%X "
1290 "Avail:%X Vector:%02X Dest:%08X "
1291 "SID:%04X SQ:%X SVT:%X)\n",
Yinghai Lu3a61d7f2011-10-12 00:33:28 -07001292 attr->ioapic, irte.present, irte.fpd, irte.dst_mode,
Yinghai Luc5b47122011-10-12 00:33:15 -07001293 irte.redir_hint, irte.trigger_mode, irte.dlvry_mode,
1294 irte.avail, irte.vector, irte.dest_id,
1295 irte.sid, irte.sq, irte.svt);
1296
1297 memset(entry, 0, sizeof(*entry));
1298
1299 entry->index2 = (index >> 15) & 0x1;
1300 entry->zero = 0;
1301 entry->format = 1;
1302 entry->index = (index & 0x7fff);
1303 /*
1304 * IO-APIC RTE will be configured with virtual vector.
1305 * irq handler will do the explicit EOI to the io-apic.
1306 */
1307 entry->vector = attr->ioapic_pin;
1308 entry->mask = 0; /* enable IRQ */
1309 entry->trigger = attr->trigger;
1310 entry->polarity = attr->polarity;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001311
1312 /* Mask level triggered irqs.
1313 * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
1314 */
Yinghai Luc5b47122011-10-12 00:33:15 -07001315 if (attr->trigger)
Yinghai Lu497c9a12008-08-19 20:50:28 -07001316 entry->mask = 1;
Yinghai Luc5b47122011-10-12 00:33:15 -07001317
1318 return 0;
1319}
1320
1321static int setup_ioapic_entry(int irq, struct IO_APIC_route_entry *entry,
1322 unsigned int destination, int vector,
1323 struct io_apic_irq_attr *attr)
1324{
1325 if (intr_remapping_enabled)
1326 return setup_ir_ioapic_entry(irq,
1327 (struct IR_IO_APIC_route_entry *)entry,
1328 destination, vector, attr);
1329
1330 memset(entry, 0, sizeof(*entry));
1331
1332 entry->delivery_mode = apic->irq_delivery_mode;
1333 entry->dest_mode = apic->irq_dest_mode;
1334 entry->dest = destination;
1335 entry->vector = vector;
1336 entry->mask = 0; /* enable IRQ */
1337 entry->trigger = attr->trigger;
1338 entry->polarity = attr->polarity;
1339
1340 /*
1341 * Mask level triggered irqs.
1342 * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
1343 */
1344 if (attr->trigger)
1345 entry->mask = 1;
1346
Yinghai Lu497c9a12008-08-19 20:50:28 -07001347 return 0;
1348}
1349
Yinghai Lue4aff812011-10-12 00:33:05 -07001350static void setup_ioapic_irq(unsigned int irq, struct irq_cfg *cfg,
1351 struct io_apic_irq_attr *attr)
Yinghai Lu497c9a12008-08-19 20:50:28 -07001352{
Yinghai Lu497c9a12008-08-19 20:50:28 -07001353 struct IO_APIC_route_entry entry;
Mike Travis22f65d32008-12-16 17:33:56 -08001354 unsigned int dest;
Yinghai Lu497c9a12008-08-19 20:50:28 -07001355
1356 if (!IO_APIC_IRQ(irq))
1357 return;
Suresh Siddha69c89ef2010-01-29 11:42:20 -08001358 /*
1359 * For legacy irqs, cfg->domain starts with cpu 0 for legacy
1360 * controllers like 8259. Now that IO-APIC can handle this irq, update
1361 * the cfg->domain.
1362 */
Yinghai Lu28c6a0b2010-02-23 20:27:48 -08001363 if (irq < legacy_pic->nr_legacy_irqs && cpumask_test_cpu(0, cfg->domain))
Suresh Siddha69c89ef2010-01-29 11:42:20 -08001364 apic->vector_allocation_domain(0, cfg->domain);
1365
Ingo Molnarfe402e12009-01-28 04:32:51 +01001366 if (assign_irq_vector(irq, cfg, apic->target_cpus()))
Yinghai Lu497c9a12008-08-19 20:50:28 -07001367 return;
1368
Ingo Molnardebccb32009-01-28 15:20:18 +01001369 dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
Yinghai Lu497c9a12008-08-19 20:50:28 -07001370
1371 apic_printk(APIC_VERBOSE,KERN_DEBUG
1372 "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
Naga Chumbalkar7fece832011-07-08 18:46:42 +00001373 "IRQ %d Mode:%i Active:%i Dest:%d)\n",
Yinghai Lue4aff812011-10-12 00:33:05 -07001374 attr->ioapic, mpc_ioapic_id(attr->ioapic), attr->ioapic_pin,
1375 cfg->vector, irq, attr->trigger, attr->polarity, dest);
Yinghai Lu497c9a12008-08-19 20:50:28 -07001376
Yinghai Luc5b47122011-10-12 00:33:15 -07001377 if (setup_ioapic_entry(irq, &entry, dest, cfg->vector, attr)) {
1378 pr_warn("Failed to setup ioapic entry for ioapic %d, pin %d\n",
1379 mpc_ioapic_id(attr->ioapic), attr->ioapic_pin);
Yinghai Lu3145e942008-12-05 18:58:34 -08001380 __clear_irq_vector(irq, cfg);
Yinghai Luc5b47122011-10-12 00:33:15 -07001381
Yinghai Lu497c9a12008-08-19 20:50:28 -07001382 return;
1383 }
1384
Yinghai Lue4aff812011-10-12 00:33:05 -07001385 ioapic_register_intr(irq, cfg, attr->trigger);
Jacob Panb81bb372009-11-09 11:27:04 -08001386 if (irq < legacy_pic->nr_legacy_irqs)
Thomas Gleixner4305df92010-09-28 15:01:33 +02001387 legacy_pic->mask(irq);
Yinghai Lu497c9a12008-08-19 20:50:28 -07001388
Yinghai Lue4aff812011-10-12 00:33:05 -07001389 ioapic_write_entry(attr->ioapic, attr->ioapic_pin, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390}
1391
Thomas Gleixnerc8d6b8f2011-02-23 14:29:34 +01001392static bool __init io_apic_pin_not_connected(int idx, int apic_id, int pin)
1393{
1394 if (idx != -1)
1395 return false;
1396
1397 apic_printk(APIC_VERBOSE, KERN_DEBUG " apic %d pin %d not connected\n",
Suresh Siddhad5371432011-05-18 16:31:37 -07001398 mpc_ioapic_id(apic_id), pin);
Thomas Gleixnerc8d6b8f2011-02-23 14:29:34 +01001399 return true;
1400}
1401
Thomas Gleixnered972cc2011-02-23 14:31:36 +01001402static void __init __io_apic_setup_irqs(unsigned int apic_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
Thomas Gleixnered972cc2011-02-23 14:31:36 +01001404 int idx, node = cpu_to_node(0);
Thomas Gleixner2d57e372011-02-23 14:40:35 +01001405 struct io_apic_irq_attr attr;
Thomas Gleixnered972cc2011-02-23 14:31:36 +01001406 unsigned int pin, irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Suresh Siddhab69c6c32011-05-18 16:31:35 -07001408 for (pin = 0; pin < ioapics[apic_id].nr_registers; pin++) {
Yinghai Lub9c61b702009-05-06 10:10:06 -07001409 idx = find_irq_entry(apic_id, pin, mp_INT);
Thomas Gleixnerc8d6b8f2011-02-23 14:29:34 +01001410 if (io_apic_pin_not_connected(idx, apic_id, pin))
Yinghai Lub9c61b702009-05-06 10:10:06 -07001411 continue;
Yinghai Lub9c61b702009-05-06 10:10:06 -07001412
1413 irq = pin_2_irq(idx, apic_id, pin);
1414
Eric W. Biedermanfad53992010-02-28 01:06:34 -08001415 if ((apic_id > 0) && (irq > 16))
1416 continue;
1417
Yinghai Lub9c61b702009-05-06 10:10:06 -07001418 /*
1419 * Skip the timer IRQ if there's a quirk handler
1420 * installed and if it returns 1:
1421 */
1422 if (apic->multi_timer_check &&
Thomas Gleixner2d57e372011-02-23 14:40:35 +01001423 apic->multi_timer_check(apic_id, irq))
Yinghai Lub9c61b702009-05-06 10:10:06 -07001424 continue;
1425
Thomas Gleixner2d57e372011-02-23 14:40:35 +01001426 set_io_apic_irq_attr(&attr, apic_id, pin, irq_trigger(idx),
1427 irq_polarity(idx));
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02001428
Thomas Gleixner2d57e372011-02-23 14:40:35 +01001429 io_apic_setup_irq_pin(irq, node, &attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431}
1432
Thomas Gleixnered972cc2011-02-23 14:31:36 +01001433static void __init setup_IO_APIC_irqs(void)
1434{
1435 unsigned int apic_id;
1436
1437 apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
1438
1439 for (apic_id = 0; apic_id < nr_ioapics; apic_id++)
1440 __io_apic_setup_irqs(apic_id);
1441}
1442
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443/*
Yinghai Lu18dce6b2010-02-10 01:20:05 -08001444 * for the gsit that is not in first ioapic
1445 * but could not use acpi_register_gsi()
1446 * like some special sci in IBM x3330
1447 */
1448void setup_IO_APIC_irq_extra(u32 gsi)
1449{
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02001450 int apic_id = 0, pin, idx, irq, node = cpu_to_node(0);
Thomas Gleixnerda1ad9d2011-02-23 14:52:16 +01001451 struct io_apic_irq_attr attr;
Yinghai Lu18dce6b2010-02-10 01:20:05 -08001452
1453 /*
1454 * Convert 'gsi' to 'ioapic.pin'.
1455 */
1456 apic_id = mp_find_ioapic(gsi);
1457 if (apic_id < 0)
1458 return;
1459
1460 pin = mp_find_ioapic_pin(apic_id, gsi);
1461 idx = find_irq_entry(apic_id, pin, mp_INT);
1462 if (idx == -1)
1463 return;
1464
1465 irq = pin_2_irq(idx, apic_id, pin);
Yinghai Lufe6dab42010-10-08 22:44:02 -07001466
1467 /* Only handle the non legacy irqs on secondary ioapics */
1468 if (apic_id == 0 || irq < NR_IRQS_LEGACY)
Yinghai Lu18dce6b2010-02-10 01:20:05 -08001469 return;
Yinghai Lufe6dab42010-10-08 22:44:02 -07001470
Thomas Gleixnerda1ad9d2011-02-23 14:52:16 +01001471 set_io_apic_irq_attr(&attr, apic_id, pin, irq_trigger(idx),
1472 irq_polarity(idx));
1473
Thomas Gleixner710dcda2011-02-23 17:47:41 +01001474 io_apic_setup_irq_pin_once(irq, node, &attr);
Yinghai Lu18dce6b2010-02-10 01:20:05 -08001475}
1476
1477/*
Maciej W. Rozyckif7633ce2008-05-27 21:19:34 +01001478 * Set up the timer pin, possibly with the 8259A-master behind.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 */
Ingo Molnarc8d46cf2009-01-28 00:14:11 +01001480static void __init setup_timer_IRQ0_pin(unsigned int apic_id, unsigned int pin,
Maciej W. Rozyckif7633ce2008-05-27 21:19:34 +01001481 int vector)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482{
1483 struct IO_APIC_route_entry entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Ingo Molnar54168ed2008-08-20 09:07:45 +02001485 if (intr_remapping_enabled)
1486 return;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001487
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02001488 memset(&entry, 0, sizeof(entry));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
1490 /*
1491 * We use logical delivery to get the timer IRQ
1492 * to the first CPU.
1493 */
Ingo Molnar9b5bc8d2009-01-28 04:09:58 +01001494 entry.dest_mode = apic->irq_dest_mode;
Yinghai Luf72dcca2009-02-08 16:18:03 -08001495 entry.mask = 0; /* don't mask IRQ for edge */
Ingo Molnardebccb32009-01-28 15:20:18 +01001496 entry.dest = apic->cpu_mask_to_apicid(apic->target_cpus());
Ingo Molnar9b5bc8d2009-01-28 04:09:58 +01001497 entry.delivery_mode = apic->irq_delivery_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 entry.polarity = 0;
1499 entry.trigger = 0;
1500 entry.vector = vector;
1501
1502 /*
1503 * The timer IRQ doesn't have to know that behind the
Maciej W. Rozyckif7633ce2008-05-27 21:19:34 +01001504 * scene we may have a 8259A-master in AEOI mode ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 */
Thomas Gleixner2c778652011-03-12 12:20:43 +01001506 irq_set_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq,
1507 "edge");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509 /*
1510 * Add it to the IO-APIC irq-routing table:
1511 */
Ingo Molnarc8d46cf2009-01-28 00:14:11 +01001512 ioapic_write_entry(apic_id, pin, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Yinghai Lucda417d2011-10-12 00:33:39 -07001515__apicdebuginit(void) print_IO_APIC(int apic)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516{
Yinghai Lucda417d2011-10-12 00:33:39 -07001517 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 union IO_APIC_reg_00 reg_00;
1519 union IO_APIC_reg_01 reg_01;
1520 union IO_APIC_reg_02 reg_02;
1521 union IO_APIC_reg_03 reg_03;
1522 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001524 raw_spin_lock_irqsave(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 reg_00.raw = io_apic_read(apic, 0);
1526 reg_01.raw = io_apic_read(apic, 1);
1527 if (reg_01.bits.version >= 0x10)
1528 reg_02.raw = io_apic_read(apic, 2);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02001529 if (reg_01.bits.version >= 0x20)
1530 reg_03.raw = io_apic_read(apic, 3);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001531 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Ingo Molnar54168ed2008-08-20 09:07:45 +02001533 printk("\n");
Suresh Siddhad5371432011-05-18 16:31:37 -07001534 printk(KERN_DEBUG "IO APIC #%d......\n", mpc_ioapic_id(apic));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
1536 printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
1537 printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type);
1538 printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Ingo Molnar54168ed2008-08-20 09:07:45 +02001540 printk(KERN_DEBUG ".... register #01: %08X\n", *(int *)&reg_01);
Naga Chumbalkarbd6a46e2011-07-08 18:46:36 +00001541 printk(KERN_DEBUG "....... : max redirection entries: %02X\n",
1542 reg_01.bits.entries);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
1544 printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
Naga Chumbalkarbd6a46e2011-07-08 18:46:36 +00001545 printk(KERN_DEBUG "....... : IO APIC version: %02X\n",
1546 reg_01.bits.version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548 /*
1549 * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
1550 * but the value of reg_02 is read as the previous read register
1551 * value, so ignore it if reg_02 == reg_01.
1552 */
1553 if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) {
1554 printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
1555 printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 }
1557
1558 /*
1559 * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
1560 * or reg_03, but the value of reg_0[23] is read as the previous read
1561 * register value, so ignore it if reg_03 == reg_0[12].
1562 */
1563 if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw &&
1564 reg_03.raw != reg_01.raw) {
1565 printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw);
1566 printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 }
1568
1569 printk(KERN_DEBUG ".... IRQ redirection table:\n");
1570
Naga Chumbalkar42f0efc2011-07-12 21:17:35 +00001571 if (intr_remapping_enabled) {
1572 printk(KERN_DEBUG " NR Indx Fmt Mask Trig IRR"
1573 " Pol Stat Indx2 Zero Vect:\n");
1574 } else {
1575 printk(KERN_DEBUG " NR Dst Mask Trig IRR Pol"
1576 " Stat Dmod Deli Vect:\n");
1577 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 for (i = 0; i <= reg_01.bits.entries; i++) {
Naga Chumbalkar42f0efc2011-07-12 21:17:35 +00001580 if (intr_remapping_enabled) {
1581 struct IO_APIC_route_entry entry;
1582 struct IR_IO_APIC_route_entry *ir_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
Naga Chumbalkar42f0efc2011-07-12 21:17:35 +00001584 entry = ioapic_read_entry(apic, i);
1585 ir_entry = (struct IR_IO_APIC_route_entry *) &entry;
1586 printk(KERN_DEBUG " %02x %04X ",
1587 i,
1588 ir_entry->index
1589 );
1590 printk("%1d %1d %1d %1d %1d "
1591 "%1d %1d %X %02X\n",
1592 ir_entry->format,
1593 ir_entry->mask,
1594 ir_entry->trigger,
1595 ir_entry->irr,
1596 ir_entry->polarity,
1597 ir_entry->delivery_status,
1598 ir_entry->index2,
1599 ir_entry->zero,
1600 ir_entry->vector
1601 );
1602 } else {
1603 struct IO_APIC_route_entry entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Naga Chumbalkar42f0efc2011-07-12 21:17:35 +00001605 entry = ioapic_read_entry(apic, i);
1606 printk(KERN_DEBUG " %02x %02X ",
1607 i,
1608 entry.dest
1609 );
1610 printk("%1d %1d %1d %1d %1d "
1611 "%1d %1d %02X\n",
1612 entry.mask,
1613 entry.trigger,
1614 entry.irr,
1615 entry.polarity,
1616 entry.delivery_status,
1617 entry.dest_mode,
1618 entry.delivery_mode,
1619 entry.vector
1620 );
1621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 }
Yinghai Lucda417d2011-10-12 00:33:39 -07001623}
1624
1625__apicdebuginit(void) print_IO_APICs(void)
1626{
1627 int apic, i;
1628 struct irq_cfg *cfg;
1629 unsigned int irq;
1630
1631 printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
1632 for (i = 0; i < nr_ioapics; i++)
1633 printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
1634 mpc_ioapic_id(i), ioapics[i].nr_registers);
1635
1636 /*
1637 * We are a bit conservative about what we expect. We have to
1638 * know about every hardware change ASAP.
1639 */
1640 printk(KERN_INFO "testing the IO APIC.......................\n");
1641
1642 for (apic = 0; apic < nr_ioapics; apic++)
1643 print_IO_APIC(apic);
Naga Chumbalkar42f0efc2011-07-12 21:17:35 +00001644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 printk(KERN_DEBUG "IRQ to pin mappings:\n");
Thomas Gleixnerad9f4332010-09-30 11:26:43 +02001646 for_each_active_irq(irq) {
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -08001647 struct irq_pin_list *entry;
1648
Thomas Gleixner2c778652011-03-12 12:20:43 +01001649 cfg = irq_get_chip_data(irq);
Daniel Kiper05e40762010-08-20 00:46:16 +02001650 if (!cfg)
1651 continue;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -08001652 entry = cfg->irq_2_pin;
Yinghai Lu0f978f42008-08-19 20:50:26 -07001653 if (!entry)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 continue;
Yinghai Lu8f09cd22008-08-19 20:50:51 -07001655 printk(KERN_DEBUG "IRQ%d ", irq);
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +04001656 for_each_irq_pin(entry, cfg->irq_2_pin)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 printk("-> %d:%d", entry->apic, entry->pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 printk("\n");
1659 }
1660
1661 printk(KERN_INFO ".................................... done.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662}
1663
Ingo Molnar251e1e42009-07-02 08:54:01 +02001664__apicdebuginit(void) print_APIC_field(int base)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665{
Ingo Molnar251e1e42009-07-02 08:54:01 +02001666 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Ingo Molnar251e1e42009-07-02 08:54:01 +02001668 printk(KERN_DEBUG);
1669
1670 for (i = 0; i < 8; i++)
1671 printk(KERN_CONT "%08x", apic_read(base + i*0x10));
1672
1673 printk(KERN_CONT "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674}
1675
Maciej W. Rozycki32f71af2008-07-21 00:52:49 +01001676__apicdebuginit(void) print_local_APIC(void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677{
Andreas Herrmann97a52712009-05-08 18:23:50 +02001678 unsigned int i, v, ver, maxlvt;
Hiroshi Shimamoto7ab6af72008-07-30 17:36:48 -07001679 u64 icr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680
Ingo Molnar251e1e42009-07-02 08:54:01 +02001681 printk(KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 smp_processor_id(), hard_smp_processor_id());
Andreas Herrmann66823112008-06-05 16:35:10 +02001683 v = apic_read(APIC_ID);
Ingo Molnar54168ed2008-08-20 09:07:45 +02001684 printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, read_apic_id());
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 v = apic_read(APIC_LVR);
1686 printk(KERN_INFO "... APIC VERSION: %08x\n", v);
1687 ver = GET_APIC_VERSION(v);
Thomas Gleixnere05d7232007-02-16 01:27:58 -08001688 maxlvt = lapic_get_maxlvt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
1690 v = apic_read(APIC_TASKPRI);
1691 printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
1692
Ingo Molnar54168ed2008-08-20 09:07:45 +02001693 if (APIC_INTEGRATED(ver)) { /* !82489DX */
Yinghai Lua11b5ab2008-09-03 16:58:31 -07001694 if (!APIC_XAPIC(ver)) {
1695 v = apic_read(APIC_ARBPRI);
1696 printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
1697 v & APIC_ARBPRI_MASK);
1698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 v = apic_read(APIC_PROCPRI);
1700 printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
1701 }
1702
Yinghai Lua11b5ab2008-09-03 16:58:31 -07001703 /*
1704 * Remote read supported only in the 82489DX and local APIC for
1705 * Pentium processors.
1706 */
1707 if (!APIC_INTEGRATED(ver) || maxlvt == 3) {
1708 v = apic_read(APIC_RRR);
1709 printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
1710 }
1711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 v = apic_read(APIC_LDR);
1713 printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
Yinghai Lua11b5ab2008-09-03 16:58:31 -07001714 if (!x2apic_enabled()) {
1715 v = apic_read(APIC_DFR);
1716 printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
1717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 v = apic_read(APIC_SPIV);
1719 printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
1720
1721 printk(KERN_DEBUG "... APIC ISR field:\n");
Ingo Molnar251e1e42009-07-02 08:54:01 +02001722 print_APIC_field(APIC_ISR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 printk(KERN_DEBUG "... APIC TMR field:\n");
Ingo Molnar251e1e42009-07-02 08:54:01 +02001724 print_APIC_field(APIC_TMR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 printk(KERN_DEBUG "... APIC IRR field:\n");
Ingo Molnar251e1e42009-07-02 08:54:01 +02001726 print_APIC_field(APIC_IRR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Ingo Molnar54168ed2008-08-20 09:07:45 +02001728 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1729 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 apic_write(APIC_ESR, 0);
Ingo Molnar54168ed2008-08-20 09:07:45 +02001731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 v = apic_read(APIC_ESR);
1733 printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
1734 }
1735
Hiroshi Shimamoto7ab6af72008-07-30 17:36:48 -07001736 icr = apic_icr_read();
Ingo Molnar0c425ce2008-08-18 13:04:26 +02001737 printk(KERN_DEBUG "... APIC ICR: %08x\n", (u32)icr);
1738 printk(KERN_DEBUG "... APIC ICR2: %08x\n", (u32)(icr >> 32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 v = apic_read(APIC_LVTT);
1741 printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
1742
1743 if (maxlvt > 3) { /* PC is LVT#4. */
1744 v = apic_read(APIC_LVTPC);
1745 printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
1746 }
1747 v = apic_read(APIC_LVT0);
1748 printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
1749 v = apic_read(APIC_LVT1);
1750 printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
1751
1752 if (maxlvt > 2) { /* ERR is LVT#3. */
1753 v = apic_read(APIC_LVTERR);
1754 printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
1755 }
1756
1757 v = apic_read(APIC_TMICT);
1758 printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
1759 v = apic_read(APIC_TMCCT);
1760 printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
1761 v = apic_read(APIC_TDCR);
1762 printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
Andreas Herrmann97a52712009-05-08 18:23:50 +02001763
1764 if (boot_cpu_has(X86_FEATURE_EXTAPIC)) {
1765 v = apic_read(APIC_EFEAT);
1766 maxlvt = (v >> 16) & 0xff;
1767 printk(KERN_DEBUG "... APIC EFEAT: %08x\n", v);
1768 v = apic_read(APIC_ECTRL);
1769 printk(KERN_DEBUG "... APIC ECTRL: %08x\n", v);
1770 for (i = 0; i < maxlvt; i++) {
1771 v = apic_read(APIC_EILVTn(i));
1772 printk(KERN_DEBUG "... APIC EILVT%d: %08x\n", i, v);
1773 }
1774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 printk("\n");
1776}
1777
Cyrill Gorcunov2626eb22009-10-14 00:07:05 +04001778__apicdebuginit(void) print_local_APICs(int maxcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779{
Yinghai Luffd5aae2008-08-19 20:50:50 -07001780 int cpu;
1781
Cyrill Gorcunov2626eb22009-10-14 00:07:05 +04001782 if (!maxcpu)
1783 return;
1784
Yinghai Luffd5aae2008-08-19 20:50:50 -07001785 preempt_disable();
Cyrill Gorcunov2626eb22009-10-14 00:07:05 +04001786 for_each_online_cpu(cpu) {
1787 if (cpu >= maxcpu)
1788 break;
Yinghai Luffd5aae2008-08-19 20:50:50 -07001789 smp_call_function_single(cpu, print_local_APIC, NULL, 1);
Cyrill Gorcunov2626eb22009-10-14 00:07:05 +04001790 }
Yinghai Luffd5aae2008-08-19 20:50:50 -07001791 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792}
1793
Maciej W. Rozycki32f71af2008-07-21 00:52:49 +01001794__apicdebuginit(void) print_PIC(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 unsigned int v;
1797 unsigned long flags;
1798
Jacob Panb81bb372009-11-09 11:27:04 -08001799 if (!legacy_pic->nr_legacy_irqs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 return;
1801
1802 printk(KERN_DEBUG "\nprinting PIC contents\n");
1803
Thomas Gleixner5619c282009-07-25 18:35:11 +02001804 raw_spin_lock_irqsave(&i8259A_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
1806 v = inb(0xa1) << 8 | inb(0x21);
1807 printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
1808
1809 v = inb(0xa0) << 8 | inb(0x20);
1810 printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
1811
Ingo Molnar54168ed2008-08-20 09:07:45 +02001812 outb(0x0b,0xa0);
1813 outb(0x0b,0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 v = inb(0xa0) << 8 | inb(0x20);
Ingo Molnar54168ed2008-08-20 09:07:45 +02001815 outb(0x0a,0xa0);
1816 outb(0x0a,0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
Thomas Gleixner5619c282009-07-25 18:35:11 +02001818 raw_spin_unlock_irqrestore(&i8259A_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
1820 printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
1821
1822 v = inb(0x4d1) << 8 | inb(0x4d0);
1823 printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
1824}
1825
Cyrill Gorcunov2626eb22009-10-14 00:07:05 +04001826static int __initdata show_lapic = 1;
1827static __init int setup_show_lapic(char *arg)
Maciej W. Rozycki32f71af2008-07-21 00:52:49 +01001828{
Cyrill Gorcunov2626eb22009-10-14 00:07:05 +04001829 int num = -1;
1830
1831 if (strcmp(arg, "all") == 0) {
1832 show_lapic = CONFIG_NR_CPUS;
1833 } else {
1834 get_option(&arg, &num);
1835 if (num >= 0)
1836 show_lapic = num;
1837 }
1838
1839 return 1;
1840}
1841__setup("show_lapic=", setup_show_lapic);
1842
1843__apicdebuginit(int) print_ICs(void)
1844{
1845 if (apic_verbosity == APIC_QUIET)
1846 return 0;
1847
Maciej W. Rozycki32f71af2008-07-21 00:52:49 +01001848 print_PIC();
Yinghai Lu4797f6b2009-05-02 10:40:57 -07001849
1850 /* don't print out if apic is not there */
Cyrill Gorcunov83121362009-09-15 11:12:30 +04001851 if (!cpu_has_apic && !apic_from_smp_config())
Yinghai Lu4797f6b2009-05-02 10:40:57 -07001852 return 0;
1853
Cyrill Gorcunov2626eb22009-10-14 00:07:05 +04001854 print_local_APICs(show_lapic);
Yinghai Lucda417d2011-10-12 00:33:39 -07001855 print_IO_APICs();
Maciej W. Rozycki32f71af2008-07-21 00:52:49 +01001856
1857 return 0;
1858}
1859
Naga Chumbalkarded1f6a2011-07-08 08:36:34 +00001860late_initcall(print_ICs);
Maciej W. Rozycki32f71af2008-07-21 00:52:49 +01001861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
Yinghai Luefa25592008-08-19 20:50:36 -07001863/* Where if anywhere is the i8259 connect in external int mode */
1864static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
1865
Ingo Molnar54168ed2008-08-20 09:07:45 +02001866void __init enable_IO_APIC(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867{
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001868 int i8259_apic, i8259_pin;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001869 int apic;
Thomas Gleixnerbc078442009-08-29 18:09:57 +02001870
Jacob Panb81bb372009-11-09 11:27:04 -08001871 if (!legacy_pic->nr_legacy_irqs)
Thomas Gleixnerbc078442009-08-29 18:09:57 +02001872 return;
1873
Ingo Molnar54168ed2008-08-20 09:07:45 +02001874 for(apic = 0; apic < nr_ioapics; apic++) {
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001875 int pin;
1876 /* See if any of the pins is in ExtINT mode */
Suresh Siddhab69c6c32011-05-18 16:31:35 -07001877 for (pin = 0; pin < ioapics[apic].nr_registers; pin++) {
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001878 struct IO_APIC_route_entry entry;
Andi Kleencf4c6a22006-09-26 10:52:30 +02001879 entry = ioapic_read_entry(apic, pin);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001880
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001881 /* If the interrupt line is enabled and in ExtInt mode
1882 * I have found the pin where the i8259 is connected.
1883 */
1884 if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
1885 ioapic_i8259.apic = apic;
1886 ioapic_i8259.pin = pin;
1887 goto found_i8259;
1888 }
1889 }
1890 }
1891 found_i8259:
1892 /* Look to see what if the MP table has reported the ExtINT */
1893 /* If we could not find the appropriate pin by looking at the ioapic
1894 * the i8259 probably is not connected the ioapic but give the
1895 * mptable a chance anyway.
1896 */
1897 i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
1898 i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
1899 /* Trust the MP table if nothing is setup in the hardware */
1900 if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
1901 printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
1902 ioapic_i8259.pin = i8259_pin;
1903 ioapic_i8259.apic = i8259_apic;
1904 }
1905 /* Complain if the MP table and the hardware disagree */
1906 if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
1907 (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
1908 {
1909 printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 }
1911
1912 /*
1913 * Do not trust the IO-APIC being empty at bootup
1914 */
1915 clear_IO_APIC();
1916}
1917
1918/*
1919 * Not an __init, needed by the reboot code
1920 */
1921void disable_IO_APIC(void)
1922{
1923 /*
1924 * Clear the IO-APIC before rebooting:
1925 */
1926 clear_IO_APIC();
1927
Jacob Panb81bb372009-11-09 11:27:04 -08001928 if (!legacy_pic->nr_legacy_irqs)
Thomas Gleixnerbc078442009-08-29 18:09:57 +02001929 return;
1930
Eric W. Biederman650927e2005-06-25 14:57:44 -07001931 /*
Karsten Wiese0b968d22005-09-09 12:59:04 +02001932 * If the i8259 is routed through an IOAPIC
Eric W. Biederman650927e2005-06-25 14:57:44 -07001933 * Put that IOAPIC in virtual wire mode
Karsten Wiese0b968d22005-09-09 12:59:04 +02001934 * so legacy interrupts can be delivered.
Suresh Siddha7c6d9f92009-03-16 17:04:59 -07001935 *
1936 * With interrupt-remapping, for now we will use virtual wire A mode,
1937 * as virtual wire B is little complex (need to configure both
Lucas De Marchi0d2eb442011-03-17 16:24:16 -03001938 * IOAPIC RTE as well as interrupt-remapping table entry).
Suresh Siddha7c6d9f92009-03-16 17:04:59 -07001939 * As this gets called during crash dump, keep this simple for now.
Eric W. Biederman650927e2005-06-25 14:57:44 -07001940 */
Suresh Siddha7c6d9f92009-03-16 17:04:59 -07001941 if (ioapic_i8259.pin != -1 && !intr_remapping_enabled) {
Eric W. Biederman650927e2005-06-25 14:57:44 -07001942 struct IO_APIC_route_entry entry;
Eric W. Biederman650927e2005-06-25 14:57:44 -07001943
1944 memset(&entry, 0, sizeof(entry));
1945 entry.mask = 0; /* Enabled */
1946 entry.trigger = 0; /* Edge */
1947 entry.irr = 0;
1948 entry.polarity = 0; /* High */
1949 entry.delivery_status = 0;
1950 entry.dest_mode = 0; /* Physical */
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08001951 entry.delivery_mode = dest_ExtINT; /* ExtInt */
Eric W. Biederman650927e2005-06-25 14:57:44 -07001952 entry.vector = 0;
Ingo Molnar54168ed2008-08-20 09:07:45 +02001953 entry.dest = read_apic_id();
Eric W. Biederman650927e2005-06-25 14:57:44 -07001954
1955 /*
1956 * Add it to the IO-APIC irq-routing table:
1957 */
Andi Kleencf4c6a22006-09-26 10:52:30 +02001958 ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
Eric W. Biederman650927e2005-06-25 14:57:44 -07001959 }
Ingo Molnar54168ed2008-08-20 09:07:45 +02001960
Suresh Siddha7c6d9f92009-03-16 17:04:59 -07001961 /*
1962 * Use virtual wire A mode when interrupt remapping is enabled.
1963 */
Cyrill Gorcunov83121362009-09-15 11:12:30 +04001964 if (cpu_has_apic || apic_from_smp_config())
Cyrill Gorcunov3f4c3952009-06-17 22:13:22 +04001965 disconnect_bsp_APIC(!intr_remapping_enabled &&
1966 ioapic_i8259.pin != -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967}
1968
Ingo Molnar54168ed2008-08-20 09:07:45 +02001969#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970/*
1971 * function to set the IO-APIC physical IDs based on the
1972 * values stored in the MPC table.
1973 *
1974 * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
1975 */
Sebastian Andrzej Siewiora38c5382010-11-26 17:50:20 +01001976void __init setup_ioapic_ids_from_mpc_nocheck(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977{
1978 union IO_APIC_reg_00 reg_00;
1979 physid_mask_t phys_id_present_map;
Ingo Molnarc8d46cf2009-01-28 00:14:11 +01001980 int apic_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 int i;
1982 unsigned char old_id;
1983 unsigned long flags;
1984
Natalie Protasevichca05fea2005-06-23 00:08:22 -07001985 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 * This is broken; anything with a real cpu count has to
1987 * circumvent this idiocy regardless.
1988 */
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +03001989 apic->ioapic_phys_id_map(&phys_cpu_present_map, &phys_id_present_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
1991 /*
1992 * Set the IOAPIC ID to the value stored in the MPC table.
1993 */
Ingo Molnarc8d46cf2009-01-28 00:14:11 +01001994 for (apic_id = 0; apic_id < nr_ioapics; apic_id++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996 /* Read the register 0 value */
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001997 raw_spin_lock_irqsave(&ioapic_lock, flags);
Ingo Molnarc8d46cf2009-01-28 00:14:11 +01001998 reg_00.raw = io_apic_read(apic_id, 0);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02001999 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02002000
Suresh Siddhad5371432011-05-18 16:31:37 -07002001 old_id = mpc_ioapic_id(apic_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002
Suresh Siddhad5371432011-05-18 16:31:37 -07002003 if (mpc_ioapic_id(apic_id) >= get_physical_broadcast()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
Suresh Siddhad5371432011-05-18 16:31:37 -07002005 apic_id, mpc_ioapic_id(apic_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
2007 reg_00.bits.ID);
Suresh Siddhad5371432011-05-18 16:31:37 -07002008 ioapics[apic_id].mp_config.apicid = reg_00.bits.ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
2010
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 /*
2012 * Sanity check, is the ID really free? Every APIC in a
2013 * system must have a unique ID or we get lots of nice
2014 * 'stuck on smp_invalidate_needed IPI wait' messages.
2015 */
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +03002016 if (apic->check_apicid_used(&phys_id_present_map,
Suresh Siddhad5371432011-05-18 16:31:37 -07002017 mpc_ioapic_id(apic_id))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
Suresh Siddhad5371432011-05-18 16:31:37 -07002019 apic_id, mpc_ioapic_id(apic_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 for (i = 0; i < get_physical_broadcast(); i++)
2021 if (!physid_isset(i, phys_id_present_map))
2022 break;
2023 if (i >= get_physical_broadcast())
2024 panic("Max APIC ID exceeded!\n");
2025 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
2026 i);
2027 physid_set(i, phys_id_present_map);
Suresh Siddhad5371432011-05-18 16:31:37 -07002028 ioapics[apic_id].mp_config.apicid = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 } else {
2030 physid_mask_t tmp;
Suresh Siddhad5371432011-05-18 16:31:37 -07002031 apic->apicid_to_cpu_present(mpc_ioapic_id(apic_id),
2032 &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 apic_printk(APIC_VERBOSE, "Setting %d in the "
2034 "phys_id_present_map\n",
Suresh Siddhad5371432011-05-18 16:31:37 -07002035 mpc_ioapic_id(apic_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 physids_or(phys_id_present_map, phys_id_present_map, tmp);
2037 }
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 /*
2040 * We need to adjust the IRQ routing table
2041 * if the ID changed.
2042 */
Suresh Siddhad5371432011-05-18 16:31:37 -07002043 if (old_id != mpc_ioapic_id(apic_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 for (i = 0; i < mp_irq_entries; i++)
Jaswinder Singh Rajputc2c21742009-01-12 17:47:22 +05302045 if (mp_irqs[i].dstapic == old_id)
2046 mp_irqs[i].dstapic
Suresh Siddhad5371432011-05-18 16:31:37 -07002047 = mpc_ioapic_id(apic_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
2049 /*
Yinghai Lu60d79fd2010-12-07 00:59:49 -08002050 * Update the ID register according to the right value
2051 * from the MPC table if they are different.
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02002052 */
Suresh Siddhad5371432011-05-18 16:31:37 -07002053 if (mpc_ioapic_id(apic_id) == reg_00.bits.ID)
Yinghai Lu60d79fd2010-12-07 00:59:49 -08002054 continue;
2055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 apic_printk(APIC_VERBOSE, KERN_INFO
2057 "...changing IO-APIC physical APIC ID to %d ...",
Suresh Siddhad5371432011-05-18 16:31:37 -07002058 mpc_ioapic_id(apic_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Suresh Siddhad5371432011-05-18 16:31:37 -07002060 reg_00.bits.ID = mpc_ioapic_id(apic_id);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002061 raw_spin_lock_irqsave(&ioapic_lock, flags);
Ingo Molnarc8d46cf2009-01-28 00:14:11 +01002062 io_apic_write(apic_id, 0, reg_00.raw);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002063 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
2065 /*
2066 * Sanity check
2067 */
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002068 raw_spin_lock_irqsave(&ioapic_lock, flags);
Ingo Molnarc8d46cf2009-01-28 00:14:11 +01002069 reg_00.raw = io_apic_read(apic_id, 0);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002070 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Suresh Siddhad5371432011-05-18 16:31:37 -07002071 if (reg_00.bits.ID != mpc_ioapic_id(apic_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 printk("could not set ID!\n");
2073 else
2074 apic_printk(APIC_VERBOSE, " ok.\n");
2075 }
2076}
Sebastian Andrzej Siewiora38c5382010-11-26 17:50:20 +01002077
2078void __init setup_ioapic_ids_from_mpc(void)
2079{
2080
2081 if (acpi_ioapic)
2082 return;
2083 /*
2084 * Don't check I/O APIC IDs for xAPIC systems. They have
2085 * no meaning without the serial APIC bus.
2086 */
2087 if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
2088 || APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
2089 return;
2090 setup_ioapic_ids_from_mpc_nocheck();
2091}
Ingo Molnar54168ed2008-08-20 09:07:45 +02002092#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Zachary Amsden7ce0bcf2007-02-13 13:26:21 +01002094int no_timer_check __initdata;
Zachary Amsden8542b202006-12-07 02:14:09 +01002095
2096static int __init notimercheck(char *s)
2097{
2098 no_timer_check = 1;
2099 return 1;
2100}
2101__setup("no_timer_check", notimercheck);
2102
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103/*
2104 * There is a nasty bug in some older SMP boards, their mptable lies
2105 * about the timer IRQ. We do the following to work around the situation:
2106 *
2107 * - timer IRQ defaults to IO-APIC IRQ
2108 * - if this function detects that timer IRQs are defunct, then we fall
2109 * back to ISA timer IRQs
2110 */
Adrian Bunkf0a7a5c2007-07-21 17:10:29 +02002111static int __init timer_irq_works(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
2113 unsigned long t1 = jiffies;
Ingo Molnar4aae0702007-12-18 18:05:58 +01002114 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Zachary Amsden8542b202006-12-07 02:14:09 +01002116 if (no_timer_check)
2117 return 1;
2118
Ingo Molnar4aae0702007-12-18 18:05:58 +01002119 local_save_flags(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 local_irq_enable();
2121 /* Let ten ticks pass... */
2122 mdelay((10 * 1000) / HZ);
Ingo Molnar4aae0702007-12-18 18:05:58 +01002123 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
2125 /*
2126 * Expect a few ticks at least, to be sure some possible
2127 * glue logic does not lock up after one or two first
2128 * ticks in a non-ExtINT mode. Also the local APIC
2129 * might have cached one ExtINT interrupt. Finally, at
2130 * least one tick may be lost due to delays.
2131 */
Ingo Molnar54168ed2008-08-20 09:07:45 +02002132
2133 /* jiffies wrap? */
Julia Lawall1d16b532008-01-30 13:32:19 +01002134 if (time_after(jiffies, t1 + 4))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 return 0;
2137}
2138
2139/*
2140 * In the SMP+IOAPIC case it might happen that there are an unspecified
2141 * number of pending IRQ events unhandled. These cases are very rare,
2142 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
2143 * better to do it this way as thus we do not have to be aware of
2144 * 'pending' interrupts in the IRQ path, except at this point.
2145 */
2146/*
2147 * Edge triggered needs to resend any interrupt
2148 * that was delayed but this is now handled in the device
2149 * independent code.
2150 */
2151
2152/*
2153 * Starting up a edge-triggered IO-APIC interrupt is
2154 * nasty - we need to make sure that we get the edge.
2155 * If it is already asserted for some reason, we need
2156 * return 1 to indicate that is was pending.
2157 *
2158 * This is not complete - we should be able to fake
2159 * an edge even if it isn't on the 8259A...
2160 */
Ingo Molnar54168ed2008-08-20 09:07:45 +02002161
Thomas Gleixner61a38ce2010-09-28 16:00:34 +02002162static unsigned int startup_ioapic_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163{
Thomas Gleixner61a38ce2010-09-28 16:00:34 +02002164 int was_pending = 0, irq = data->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 unsigned long flags;
2166
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002167 raw_spin_lock_irqsave(&ioapic_lock, flags);
Jacob Panb81bb372009-11-09 11:27:04 -08002168 if (irq < legacy_pic->nr_legacy_irqs) {
Thomas Gleixner4305df92010-09-28 15:01:33 +02002169 legacy_pic->mask(irq);
Jacob Panb81bb372009-11-09 11:27:04 -08002170 if (legacy_pic->irq_pending(irq))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 was_pending = 1;
2172 }
Thomas Gleixner61a38ce2010-09-28 16:00:34 +02002173 __unmask_ioapic(data->chip_data);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002174 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
2176 return was_pending;
2177}
2178
Thomas Gleixner90297c52010-09-28 16:03:54 +02002179static int ioapic_retrigger_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
Thomas Gleixner90297c52010-09-28 16:03:54 +02002181 struct irq_cfg *cfg = data->chip_data;
Ingo Molnar54168ed2008-08-20 09:07:45 +02002182 unsigned long flags;
2183
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002184 raw_spin_lock_irqsave(&vector_lock, flags);
Ingo Molnardac5f412009-01-28 15:42:24 +01002185 apic->send_IPI_mask(cpumask_of(cpumask_first(cfg->domain)), cfg->vector);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002186 raw_spin_unlock_irqrestore(&vector_lock, flags);
Ingo Molnarc0ad90a2006-06-29 02:24:44 -07002187
2188 return 1;
2189}
Ingo Molnar54168ed2008-08-20 09:07:45 +02002190
2191/*
2192 * Level and edge triggered IO-APIC interrupts need different handling,
2193 * so we use two separate IRQ descriptors. Edge triggered IRQs can be
2194 * handled with the level-triggered descriptor, but that one has slightly
2195 * more overhead. Level-triggered interrupts cannot be handled with the
2196 * edge-triggered handler, without risking IRQ storms and other ugly
2197 * races.
2198 */
Ingo Molnarc0ad90a2006-06-29 02:24:44 -07002199
Yinghai Lu497c9a12008-08-19 20:50:28 -07002200#ifdef CONFIG_SMP
Dimitri Sivanich9338ad62009-10-13 15:32:36 -05002201void send_cleanup_vector(struct irq_cfg *cfg)
Gary Hadee85abf82009-04-08 14:07:25 -07002202{
2203 cpumask_var_t cleanup_mask;
2204
2205 if (unlikely(!alloc_cpumask_var(&cleanup_mask, GFP_ATOMIC))) {
2206 unsigned int i;
Gary Hadee85abf82009-04-08 14:07:25 -07002207 for_each_cpu_and(i, cfg->old_domain, cpu_online_mask)
2208 apic->send_IPI_mask(cpumask_of(i), IRQ_MOVE_CLEANUP_VECTOR);
2209 } else {
2210 cpumask_and(cleanup_mask, cfg->old_domain, cpu_online_mask);
Gary Hadee85abf82009-04-08 14:07:25 -07002211 apic->send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
2212 free_cpumask_var(cleanup_mask);
2213 }
2214 cfg->move_in_progress = 0;
2215}
2216
Ingo Molnar44204712009-05-01 19:02:50 +02002217static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, struct irq_cfg *cfg)
Gary Hadee85abf82009-04-08 14:07:25 -07002218{
2219 int apic, pin;
2220 struct irq_pin_list *entry;
2221 u8 vector = cfg->vector;
2222
Cyrill Gorcunov2977fb32009-08-01 11:47:59 +04002223 for_each_irq_pin(entry, cfg->irq_2_pin) {
Gary Hadee85abf82009-04-08 14:07:25 -07002224 unsigned int reg;
2225
Gary Hadee85abf82009-04-08 14:07:25 -07002226 apic = entry->apic;
2227 pin = entry->pin;
2228 /*
2229 * With interrupt-remapping, destination information comes
2230 * from interrupt-remapping table entry.
2231 */
Thomas Gleixner1a0730d2010-10-11 11:55:37 +02002232 if (!irq_remapped(cfg))
Gary Hadee85abf82009-04-08 14:07:25 -07002233 io_apic_write(apic, 0x11 + pin*2, dest);
2234 reg = io_apic_read(apic, 0x10 + pin*2);
2235 reg &= ~IO_APIC_REDIR_VECTOR_MASK;
2236 reg |= vector;
2237 io_apic_modify(apic, 0x10 + pin*2, reg);
Gary Hadee85abf82009-04-08 14:07:25 -07002238 }
2239}
2240
2241/*
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002242 * Either sets data->affinity to a valid value, and returns
Suresh Siddha18374d82009-12-17 18:29:46 -08002243 * ->cpu_mask_to_apicid of that in dest_id, or returns -1 and
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002244 * leaves data->affinity untouched.
Gary Hadee85abf82009-04-08 14:07:25 -07002245 */
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002246int __ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
2247 unsigned int *dest_id)
Gary Hadee85abf82009-04-08 14:07:25 -07002248{
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002249 struct irq_cfg *cfg = data->chip_data;
Gary Hadee85abf82009-04-08 14:07:25 -07002250
2251 if (!cpumask_intersects(mask, cpu_online_mask))
Suresh Siddha18374d82009-12-17 18:29:46 -08002252 return -1;
Gary Hadee85abf82009-04-08 14:07:25 -07002253
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002254 if (assign_irq_vector(data->irq, data->chip_data, mask))
Suresh Siddha18374d82009-12-17 18:29:46 -08002255 return -1;
Gary Hadee85abf82009-04-08 14:07:25 -07002256
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002257 cpumask_copy(data->affinity, mask);
Gary Hadee85abf82009-04-08 14:07:25 -07002258
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002259 *dest_id = apic->cpu_mask_to_apicid_and(mask, cfg->domain);
Suresh Siddha18374d82009-12-17 18:29:46 -08002260 return 0;
Gary Hadee85abf82009-04-08 14:07:25 -07002261}
2262
Ingo Molnar44204712009-05-01 19:02:50 +02002263static int
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002264ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
2265 bool force)
Gary Hadee85abf82009-04-08 14:07:25 -07002266{
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002267 unsigned int dest, irq = data->irq;
Gary Hadee85abf82009-04-08 14:07:25 -07002268 unsigned long flags;
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002269 int ret;
Gary Hadee85abf82009-04-08 14:07:25 -07002270
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002271 raw_spin_lock_irqsave(&ioapic_lock, flags);
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002272 ret = __ioapic_set_affinity(data, mask, &dest);
Suresh Siddha18374d82009-12-17 18:29:46 -08002273 if (!ret) {
Gary Hadee85abf82009-04-08 14:07:25 -07002274 /* Only the high 8 bits are valid. */
2275 dest = SET_APIC_LOGICAL_ID(dest);
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002276 __target_IO_APIC_irq(irq, dest, data->chip_data);
Gary Hadee85abf82009-04-08 14:07:25 -07002277 }
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002278 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Ingo Molnar44204712009-05-01 19:02:50 +02002279 return ret;
Gary Hadee85abf82009-04-08 14:07:25 -07002280}
2281
Ingo Molnar54168ed2008-08-20 09:07:45 +02002282#ifdef CONFIG_INTR_REMAP
Ingo Molnar54168ed2008-08-20 09:07:45 +02002283
2284/*
2285 * Migrate the IO-APIC irq in the presence of intr-remapping.
2286 *
Suresh Siddha0280f7c2009-03-16 17:05:01 -07002287 * For both level and edge triggered, irq migration is a simple atomic
2288 * update(of vector and cpu destination) of IRTE and flush the hardware cache.
Ingo Molnar54168ed2008-08-20 09:07:45 +02002289 *
Suresh Siddha0280f7c2009-03-16 17:05:01 -07002290 * For level triggered, we eliminate the io-apic RTE modification (with the
2291 * updated vector information), by using a virtual vector (io-apic pin number).
2292 * Real vector that is used for interrupting cpu will be coming from
2293 * the interrupt-remapping table entry.
Ingo Molnar54168ed2008-08-20 09:07:45 +02002294 */
Yinghai Lud5dedd42009-04-27 17:59:21 -07002295static int
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002296ir_ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
2297 bool force)
Ingo Molnar54168ed2008-08-20 09:07:45 +02002298{
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002299 struct irq_cfg *cfg = data->chip_data;
2300 unsigned int dest, irq = data->irq;
Ingo Molnar54168ed2008-08-20 09:07:45 +02002301 struct irte irte;
Ingo Molnar54168ed2008-08-20 09:07:45 +02002302
Mike Travis22f65d32008-12-16 17:33:56 -08002303 if (!cpumask_intersects(mask, cpu_online_mask))
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002304 return -EINVAL;
Ingo Molnar54168ed2008-08-20 09:07:45 +02002305
2306 if (get_irte(irq, &irte))
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002307 return -EBUSY;
Ingo Molnar54168ed2008-08-20 09:07:45 +02002308
Yinghai Lu3145e942008-12-05 18:58:34 -08002309 if (assign_irq_vector(irq, cfg, mask))
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002310 return -EBUSY;
Ingo Molnar54168ed2008-08-20 09:07:45 +02002311
Ingo Molnardebccb32009-01-28 15:20:18 +01002312 dest = apic->cpu_mask_to_apicid_and(cfg->domain, mask);
Ingo Molnar54168ed2008-08-20 09:07:45 +02002313
Ingo Molnar54168ed2008-08-20 09:07:45 +02002314 irte.vector = cfg->vector;
2315 irte.dest_id = IRTE_DEST(dest);
2316
2317 /*
2318 * Modified the IRTE and flushes the Interrupt entry cache.
2319 */
2320 modify_irte(irq, &irte);
2321
Mike Travis22f65d32008-12-16 17:33:56 -08002322 if (cfg->move_in_progress)
2323 send_cleanup_vector(cfg);
Ingo Molnar54168ed2008-08-20 09:07:45 +02002324
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002325 cpumask_copy(data->affinity, mask);
Yinghai Lud5dedd42009-04-27 17:59:21 -07002326 return 0;
Ingo Molnar54168ed2008-08-20 09:07:45 +02002327}
2328
Suresh Siddha29b61be2009-03-16 17:05:02 -07002329#else
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002330static inline int
2331ir_ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
2332 bool force)
Suresh Siddha29b61be2009-03-16 17:05:02 -07002333{
Yinghai Lud5dedd42009-04-27 17:59:21 -07002334 return 0;
Suresh Siddha29b61be2009-03-16 17:05:02 -07002335}
Ingo Molnar54168ed2008-08-20 09:07:45 +02002336#endif
2337
Yinghai Lu497c9a12008-08-19 20:50:28 -07002338asmlinkage void smp_irq_move_cleanup_interrupt(void)
2339{
2340 unsigned vector, me;
Hiroshi Shimamoto8f2466f2008-12-08 19:19:07 -08002341
Yinghai Lu497c9a12008-08-19 20:50:28 -07002342 ack_APIC_irq();
Ingo Molnar54168ed2008-08-20 09:07:45 +02002343 exit_idle();
Yinghai Lu497c9a12008-08-19 20:50:28 -07002344 irq_enter();
2345
2346 me = smp_processor_id();
2347 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
2348 unsigned int irq;
Suresh Siddha68a8ca52009-03-16 17:05:04 -07002349 unsigned int irr;
Yinghai Lu497c9a12008-08-19 20:50:28 -07002350 struct irq_desc *desc;
2351 struct irq_cfg *cfg;
Tejun Heo0a3aee02010-12-18 16:28:55 +01002352 irq = __this_cpu_read(vector_irq[vector]);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002353
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -08002354 if (irq == -1)
2355 continue;
2356
Yinghai Lu497c9a12008-08-19 20:50:28 -07002357 desc = irq_to_desc(irq);
2358 if (!desc)
2359 continue;
2360
2361 cfg = irq_cfg(irq);
Thomas Gleixner239007b2009-11-17 16:46:45 +01002362 raw_spin_lock(&desc->lock);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002363
Suresh Siddha7f41c2e2010-01-06 10:56:31 -08002364 /*
2365 * Check if the irq migration is in progress. If so, we
2366 * haven't received the cleanup request yet for this irq.
2367 */
2368 if (cfg->move_in_progress)
2369 goto unlock;
2370
Mike Travis22f65d32008-12-16 17:33:56 -08002371 if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
Yinghai Lu497c9a12008-08-19 20:50:28 -07002372 goto unlock;
2373
Suresh Siddha68a8ca52009-03-16 17:05:04 -07002374 irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
2375 /*
2376 * Check if the vector that needs to be cleanedup is
2377 * registered at the cpu's IRR. If so, then this is not
2378 * the best time to clean it up. Lets clean it up in the
2379 * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
2380 * to myself.
2381 */
2382 if (irr & (1 << (vector % 32))) {
2383 apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
2384 goto unlock;
2385 }
Tejun Heo0a3aee02010-12-18 16:28:55 +01002386 __this_cpu_write(vector_irq[vector], -1);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002387unlock:
Thomas Gleixner239007b2009-11-17 16:46:45 +01002388 raw_spin_unlock(&desc->lock);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002389 }
2390
2391 irq_exit();
2392}
2393
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002394static void __irq_complete_move(struct irq_cfg *cfg, unsigned vector)
Yinghai Lu497c9a12008-08-19 20:50:28 -07002395{
Suresh Siddhaa5e74b82009-10-26 14:24:34 -08002396 unsigned me;
Yinghai Lu497c9a12008-08-19 20:50:28 -07002397
Yinghai Lufcef5912009-04-27 17:58:23 -07002398 if (likely(!cfg->move_in_progress))
Yinghai Lu497c9a12008-08-19 20:50:28 -07002399 return;
2400
Yinghai Lu497c9a12008-08-19 20:50:28 -07002401 me = smp_processor_id();
Yinghai Lu10b888d2009-01-31 14:50:07 -08002402
Yinghai Lufcef5912009-04-27 17:58:23 -07002403 if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
Mike Travis22f65d32008-12-16 17:33:56 -08002404 send_cleanup_vector(cfg);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002405}
Suresh Siddhaa5e74b82009-10-26 14:24:34 -08002406
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002407static void irq_complete_move(struct irq_cfg *cfg)
Suresh Siddhaa5e74b82009-10-26 14:24:34 -08002408{
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002409 __irq_complete_move(cfg, ~get_irq_regs()->orig_ax);
Suresh Siddhaa5e74b82009-10-26 14:24:34 -08002410}
2411
2412void irq_force_complete_move(int irq)
2413{
Thomas Gleixner2c778652011-03-12 12:20:43 +01002414 struct irq_cfg *cfg = irq_get_chip_data(irq);
Suresh Siddhaa5e74b82009-10-26 14:24:34 -08002415
Prarit Bhargavabbd391a2010-04-27 11:24:42 -04002416 if (!cfg)
2417 return;
2418
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002419 __irq_complete_move(cfg, cfg->vector);
Suresh Siddhaa5e74b82009-10-26 14:24:34 -08002420}
Yinghai Lu497c9a12008-08-19 20:50:28 -07002421#else
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002422static inline void irq_complete_move(struct irq_cfg *cfg) { }
Yinghai Lu497c9a12008-08-19 20:50:28 -07002423#endif
Yinghai Lu3145e942008-12-05 18:58:34 -08002424
Thomas Gleixner90297c52010-09-28 16:03:54 +02002425static void ack_apic_edge(struct irq_data *data)
Yinghai Lu1d025192008-08-19 20:50:34 -07002426{
Thomas Gleixner90297c52010-09-28 16:03:54 +02002427 irq_complete_move(data->chip_data);
Thomas Gleixner08221112011-02-04 18:56:11 +01002428 irq_move_irq(data);
Yinghai Lu1d025192008-08-19 20:50:34 -07002429 ack_APIC_irq();
2430}
2431
Yinghai Lu3eb2cce2008-08-19 20:50:48 -07002432atomic_t irq_mis_count;
Yinghai Lu3eb2cce2008-08-19 20:50:48 -07002433
Suresh Siddhac29d9db2009-12-01 15:31:16 -08002434/*
2435 * IO-APIC versions below 0x20 don't support EOI register.
2436 * For the record, here is the information about various versions:
2437 * 0Xh 82489DX
2438 * 1Xh I/OAPIC or I/O(x)APIC which are not PCI 2.2 Compliant
2439 * 2Xh I/O(x)APIC which is PCI 2.2 Compliant
2440 * 30h-FFh Reserved
2441 *
2442 * Some of the Intel ICH Specs (ICH2 to ICH5) documents the io-apic
2443 * version as 0x2. This is an error with documentation and these ICH chips
2444 * use io-apic's of version 0x20.
2445 *
2446 * For IO-APIC's with EOI register, we use that to do an explicit EOI.
2447 * Otherwise, we simulate the EOI message manually by changing the trigger
2448 * mode to edge and then back to level, with RTE being masked during this.
2449*/
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002450static void eoi_ioapic_irq(unsigned int irq, struct irq_cfg *cfg)
Suresh Siddhab3ec0a32009-10-26 14:24:35 -08002451{
2452 struct irq_pin_list *entry;
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002453 unsigned long flags;
Suresh Siddhab3ec0a32009-10-26 14:24:35 -08002454
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002455 raw_spin_lock_irqsave(&ioapic_lock, flags);
Suresh Siddhab3ec0a32009-10-26 14:24:35 -08002456 for_each_irq_pin(entry, cfg->irq_2_pin) {
Suresh Siddhad5371432011-05-18 16:31:37 -07002457 if (mpc_ioapic_ver(entry->apic) >= 0x20) {
Suresh Siddhac29d9db2009-12-01 15:31:16 -08002458 /*
2459 * Intr-remapping uses pin number as the virtual vector
2460 * in the RTE. Actual vector is programmed in
2461 * intr-remapping table entry. Hence for the io-apic
2462 * EOI we use the pin number.
2463 */
Thomas Gleixner1a0730d2010-10-11 11:55:37 +02002464 if (irq_remapped(cfg))
Suresh Siddhac29d9db2009-12-01 15:31:16 -08002465 io_apic_eoi(entry->apic, entry->pin);
2466 else
2467 io_apic_eoi(entry->apic, cfg->vector);
2468 } else {
2469 __mask_and_edge_IO_APIC_irq(entry);
2470 __unmask_and_level_IO_APIC_irq(entry);
2471 }
Suresh Siddhab3ec0a32009-10-26 14:24:35 -08002472 }
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002473 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Suresh Siddhab3ec0a32009-10-26 14:24:35 -08002474}
2475
Thomas Gleixner90297c52010-09-28 16:03:54 +02002476static void ack_apic_level(struct irq_data *data)
Yinghai Lu047c8fd2008-08-19 20:50:41 -07002477{
Thomas Gleixner90297c52010-09-28 16:03:54 +02002478 struct irq_cfg *cfg = data->chip_data;
2479 int i, do_unmask_irq = 0, irq = data->irq;
Yinghai Lu3eb2cce2008-08-19 20:50:48 -07002480 unsigned long v;
Yinghai Lu047c8fd2008-08-19 20:50:41 -07002481
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002482 irq_complete_move(cfg);
Yinghai Lu047c8fd2008-08-19 20:50:41 -07002483#ifdef CONFIG_GENERIC_PENDING_IRQ
Ingo Molnar54168ed2008-08-20 09:07:45 +02002484 /* If we are moving the irq we need to mask it */
Thomas Gleixner5451ddc2011-02-05 15:35:51 +01002485 if (unlikely(irqd_is_setaffinity_pending(data))) {
Ingo Molnar54168ed2008-08-20 09:07:45 +02002486 do_unmask_irq = 1;
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002487 mask_ioapic(cfg);
Ingo Molnar54168ed2008-08-20 09:07:45 +02002488 }
Yinghai Lu047c8fd2008-08-19 20:50:41 -07002489#endif
2490
Yinghai Lu3eb2cce2008-08-19 20:50:48 -07002491 /*
Jeremy Fitzhardinge916a0fe2009-06-08 03:00:22 -07002492 * It appears there is an erratum which affects at least version 0x11
2493 * of I/O APIC (that's the 82093AA and cores integrated into various
2494 * chipsets). Under certain conditions a level-triggered interrupt is
2495 * erroneously delivered as edge-triggered one but the respective IRR
2496 * bit gets set nevertheless. As a result the I/O unit expects an EOI
2497 * message but it will never arrive and further interrupts are blocked
2498 * from the source. The exact reason is so far unknown, but the
2499 * phenomenon was observed when two consecutive interrupt requests
2500 * from a given source get delivered to the same CPU and the source is
2501 * temporarily disabled in between.
2502 *
2503 * A workaround is to simulate an EOI message manually. We achieve it
2504 * by setting the trigger mode to edge and then to level when the edge
2505 * trigger mode gets detected in the TMR of a local APIC for a
2506 * level-triggered interrupt. We mask the source for the time of the
2507 * operation to prevent an edge-triggered interrupt escaping meanwhile.
2508 * The idea is from Manfred Spraul. --macro
Suresh Siddha1c839952009-12-01 15:31:17 -08002509 *
2510 * Also in the case when cpu goes offline, fixup_irqs() will forward
2511 * any unhandled interrupt on the offlined cpu to the new cpu
2512 * destination that is handling the corresponding interrupt. This
2513 * interrupt forwarding is done via IPI's. Hence, in this case also
2514 * level-triggered io-apic interrupt will be seen as an edge
2515 * interrupt in the IRR. And we can't rely on the cpu's EOI
2516 * to be broadcasted to the IO-APIC's which will clear the remoteIRR
2517 * corresponding to the level-triggered interrupt. Hence on IO-APIC's
2518 * supporting EOI register, we do an explicit EOI to clear the
2519 * remote IRR and on IO-APIC's which don't have an EOI register,
2520 * we use the above logic (mask+edge followed by unmask+level) from
2521 * Manfred Spraul to clear the remote IRR.
Jeremy Fitzhardinge916a0fe2009-06-08 03:00:22 -07002522 */
Yinghai Lu3145e942008-12-05 18:58:34 -08002523 i = cfg->vector;
Yinghai Lu3eb2cce2008-08-19 20:50:48 -07002524 v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
Yinghai Lu3eb2cce2008-08-19 20:50:48 -07002525
Ingo Molnar54168ed2008-08-20 09:07:45 +02002526 /*
2527 * We must acknowledge the irq before we move it or the acknowledge will
2528 * not propagate properly.
2529 */
2530 ack_APIC_irq();
Yinghai Lu047c8fd2008-08-19 20:50:41 -07002531
Suresh Siddha1c839952009-12-01 15:31:17 -08002532 /*
2533 * Tail end of clearing remote IRR bit (either by delivering the EOI
2534 * message via io-apic EOI register write or simulating it using
2535 * mask+edge followed by unnask+level logic) manually when the
2536 * level triggered interrupt is seen as the edge triggered interrupt
2537 * at the cpu.
2538 */
Maciej W. Rozyckica64c472009-12-01 15:31:15 -08002539 if (!(v & (1 << (i & 0x1f)))) {
2540 atomic_inc(&irq_mis_count);
2541
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002542 eoi_ioapic_irq(irq, cfg);
Maciej W. Rozyckica64c472009-12-01 15:31:15 -08002543 }
2544
Ingo Molnar54168ed2008-08-20 09:07:45 +02002545 /* Now we can move and renable the irq */
2546 if (unlikely(do_unmask_irq)) {
2547 /* Only migrate the irq if the ack has been received.
2548 *
2549 * On rare occasions the broadcast level triggered ack gets
2550 * delayed going to ioapics, and if we reprogram the
2551 * vector while Remote IRR is still set the irq will never
2552 * fire again.
2553 *
2554 * To prevent this scenario we read the Remote IRR bit
2555 * of the ioapic. This has two effects.
2556 * - On any sane system the read of the ioapic will
2557 * flush writes (and acks) going to the ioapic from
2558 * this cpu.
2559 * - We get to see if the ACK has actually been delivered.
2560 *
2561 * Based on failed experiments of reprogramming the
2562 * ioapic entry from outside of irq context starting
2563 * with masking the ioapic entry and then polling until
2564 * Remote IRR was clear before reprogramming the
2565 * ioapic I don't trust the Remote IRR bit to be
2566 * completey accurate.
2567 *
2568 * However there appears to be no other way to plug
2569 * this race, so if the Remote IRR bit is not
2570 * accurate and is causing problems then it is a hardware bug
2571 * and you can go talk to the chipset vendor about it.
2572 */
Yinghai Lu3145e942008-12-05 18:58:34 -08002573 if (!io_apic_level_ack_pending(cfg))
Thomas Gleixner08221112011-02-04 18:56:11 +01002574 irq_move_masked_irq(data);
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002575 unmask_ioapic(cfg);
Ingo Molnar54168ed2008-08-20 09:07:45 +02002576 }
Yinghai Lu3eb2cce2008-08-19 20:50:48 -07002577}
Yinghai Lu1d025192008-08-19 20:50:34 -07002578
Han, Weidongd0b03bd2009-04-03 17:15:50 +08002579#ifdef CONFIG_INTR_REMAP
Thomas Gleixner90297c52010-09-28 16:03:54 +02002580static void ir_ack_apic_edge(struct irq_data *data)
Han, Weidongd0b03bd2009-04-03 17:15:50 +08002581{
Weidong Han5d0ae2d2009-04-17 16:42:13 +08002582 ack_APIC_irq();
Han, Weidongd0b03bd2009-04-03 17:15:50 +08002583}
2584
Thomas Gleixner90297c52010-09-28 16:03:54 +02002585static void ir_ack_apic_level(struct irq_data *data)
Han, Weidongd0b03bd2009-04-03 17:15:50 +08002586{
Weidong Han5d0ae2d2009-04-17 16:42:13 +08002587 ack_APIC_irq();
Thomas Gleixner90297c52010-09-28 16:03:54 +02002588 eoi_ioapic_irq(data->irq, data->chip_data);
Han, Weidongd0b03bd2009-04-03 17:15:50 +08002589}
2590#endif /* CONFIG_INTR_REMAP */
2591
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002592static struct irq_chip ioapic_chip __read_mostly = {
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002593 .name = "IO-APIC",
2594 .irq_startup = startup_ioapic_irq,
2595 .irq_mask = mask_ioapic_irq,
2596 .irq_unmask = unmask_ioapic_irq,
2597 .irq_ack = ack_apic_edge,
2598 .irq_eoi = ack_apic_level,
Ashok Raj54d5d422005-09-06 15:16:15 -07002599#ifdef CONFIG_SMP
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002600 .irq_set_affinity = ioapic_set_affinity,
Ashok Raj54d5d422005-09-06 15:16:15 -07002601#endif
Thomas Gleixnerf7e909e2010-10-08 21:40:23 +02002602 .irq_retrigger = ioapic_retrigger_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603};
2604
Ingo Molnar54168ed2008-08-20 09:07:45 +02002605static struct irq_chip ir_ioapic_chip __read_mostly = {
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002606 .name = "IR-IO-APIC",
2607 .irq_startup = startup_ioapic_irq,
2608 .irq_mask = mask_ioapic_irq,
2609 .irq_unmask = unmask_ioapic_irq,
Jaswinder Singh Rajputa1e38ca2009-03-23 02:11:25 +05302610#ifdef CONFIG_INTR_REMAP
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002611 .irq_ack = ir_ack_apic_edge,
2612 .irq_eoi = ir_ack_apic_level,
Ingo Molnar54168ed2008-08-20 09:07:45 +02002613#ifdef CONFIG_SMP
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002614 .irq_set_affinity = ir_ioapic_set_affinity,
Ingo Molnar54168ed2008-08-20 09:07:45 +02002615#endif
Jaswinder Singh Rajputa1e38ca2009-03-23 02:11:25 +05302616#endif
Thomas Gleixnerf19f5ec2010-10-08 21:50:22 +02002617 .irq_retrigger = ioapic_retrigger_irq,
Ingo Molnar54168ed2008-08-20 09:07:45 +02002618};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
2620static inline void init_IO_APIC_traps(void)
2621{
Yinghai Luda51a822008-08-19 20:50:25 -07002622 struct irq_cfg *cfg;
Thomas Gleixnerad9f4332010-09-30 11:26:43 +02002623 unsigned int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624
2625 /*
2626 * NOTE! The local APIC isn't very good at handling
2627 * multiple interrupts at the same interrupt level.
2628 * As the interrupt level is determined by taking the
2629 * vector number and shifting that right by 4, we
2630 * want to spread these out a bit so that they don't
2631 * all fall in the same interrupt level.
2632 *
2633 * Also, we've got to be careful not to trash gate
2634 * 0x80, because int 0x80 is hm, kind of importantish. ;)
2635 */
Thomas Gleixnerad9f4332010-09-30 11:26:43 +02002636 for_each_active_irq(irq) {
Thomas Gleixner2c778652011-03-12 12:20:43 +01002637 cfg = irq_get_chip_data(irq);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -08002638 if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 /*
2640 * Hmm.. We don't have an entry for this,
2641 * so default to an old-fashioned 8259
2642 * interrupt if we can..
2643 */
Jacob Panb81bb372009-11-09 11:27:04 -08002644 if (irq < legacy_pic->nr_legacy_irqs)
2645 legacy_pic->make_irq(irq);
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -08002646 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 /* Strange. Oh, well.. */
Thomas Gleixner2c778652011-03-12 12:20:43 +01002648 irq_set_chip(irq, &no_irq_chip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 }
2650 }
2651}
2652
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002653/*
2654 * The local APIC irq-chip implementation:
2655 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
Thomas Gleixner90297c52010-09-28 16:03:54 +02002657static void mask_lapic_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658{
2659 unsigned long v;
2660
2661 v = apic_read(APIC_LVT0);
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +01002662 apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663}
2664
Thomas Gleixner90297c52010-09-28 16:03:54 +02002665static void unmask_lapic_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666{
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002667 unsigned long v;
2668
2669 v = apic_read(APIC_LVT0);
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +01002670 apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
Thomas Gleixner90297c52010-09-28 16:03:54 +02002673static void ack_lapic_irq(struct irq_data *data)
Yinghai Lu1d025192008-08-19 20:50:34 -07002674{
2675 ack_APIC_irq();
2676}
2677
Ingo Molnarf5b9ed72006-10-04 02:16:26 -07002678static struct irq_chip lapic_chip __read_mostly = {
Maciej W. Rozycki9a1c6192008-05-27 21:19:09 +01002679 .name = "local-APIC",
Thomas Gleixner90297c52010-09-28 16:03:54 +02002680 .irq_mask = mask_lapic_irq,
2681 .irq_unmask = unmask_lapic_irq,
2682 .irq_ack = ack_lapic_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683};
2684
Thomas Gleixner60c69942010-09-28 17:28:38 +02002685static void lapic_register_intr(int irq)
Maciej W. Rozyckic88ac1d2008-07-11 19:35:17 +01002686{
Thomas Gleixner60c69942010-09-28 17:28:38 +02002687 irq_clear_status_flags(irq, IRQ_LEVEL);
Thomas Gleixner2c778652011-03-12 12:20:43 +01002688 irq_set_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
Maciej W. Rozyckic88ac1d2008-07-11 19:35:17 +01002689 "edge");
Maciej W. Rozyckic88ac1d2008-07-11 19:35:17 +01002690}
2691
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692/*
2693 * This looks a bit hackish but it's about the only one way of sending
2694 * a few INTA cycles to 8259As and any associated glue logic. ICR does
2695 * not support the ExtINT mode, unfortunately. We need to send these
2696 * cycles as some i82489DX-based boards have glue logic that keeps the
2697 * 8259A interrupt line asserted until INTA. --macro
2698 */
Jacek Luczak28acf282008-04-12 17:41:12 +02002699static inline void __init unlock_ExtINT_logic(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700{
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002701 int apic, pin, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 struct IO_APIC_route_entry entry0, entry1;
2703 unsigned char save_control, save_freq_select;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002705 pin = find_isa_irq_pin(8, mp_INT);
Adrian Bunk956fb532006-12-07 02:14:11 +01002706 if (pin == -1) {
2707 WARN_ON_ONCE(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 return;
Adrian Bunk956fb532006-12-07 02:14:11 +01002709 }
2710 apic = find_isa_irq_apic(8, mp_INT);
2711 if (apic == -1) {
2712 WARN_ON_ONCE(1);
2713 return;
2714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715
Andi Kleencf4c6a22006-09-26 10:52:30 +02002716 entry0 = ioapic_read_entry(apic, pin);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002717 clear_IO_APIC_pin(apic, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
2719 memset(&entry1, 0, sizeof(entry1));
2720
2721 entry1.dest_mode = 0; /* physical delivery */
2722 entry1.mask = 0; /* unmask IRQ now */
Yinghai Lud83e94a2008-08-19 20:50:33 -07002723 entry1.dest = hard_smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 entry1.delivery_mode = dest_ExtINT;
2725 entry1.polarity = entry0.polarity;
2726 entry1.trigger = 0;
2727 entry1.vector = 0;
2728
Andi Kleencf4c6a22006-09-26 10:52:30 +02002729 ioapic_write_entry(apic, pin, entry1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
2731 save_control = CMOS_READ(RTC_CONTROL);
2732 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
2733 CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
2734 RTC_FREQ_SELECT);
2735 CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
2736
2737 i = 100;
2738 while (i-- > 0) {
2739 mdelay(10);
2740 if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
2741 i -= 10;
2742 }
2743
2744 CMOS_WRITE(save_control, RTC_CONTROL);
2745 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002746 clear_IO_APIC_pin(apic, pin);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
Andi Kleencf4c6a22006-09-26 10:52:30 +02002748 ioapic_write_entry(apic, pin, entry0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749}
2750
Yinghai Luefa25592008-08-19 20:50:36 -07002751static int disable_timer_pin_1 __initdata;
Yinghai Lu047c8fd2008-08-19 20:50:41 -07002752/* Actually the next is obsolete, but keep it for paranoid reasons -AK */
Ingo Molnar54168ed2008-08-20 09:07:45 +02002753static int __init disable_timer_pin_setup(char *arg)
Yinghai Luefa25592008-08-19 20:50:36 -07002754{
2755 disable_timer_pin_1 = 1;
2756 return 0;
2757}
Ingo Molnar54168ed2008-08-20 09:07:45 +02002758early_param("disable_timer_pin_1", disable_timer_pin_setup);
Yinghai Luefa25592008-08-19 20:50:36 -07002759
2760int timer_through_8259 __initdata;
2761
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762/*
2763 * This code may look a bit paranoid, but it's supposed to cooperate with
2764 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
2765 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
2766 * fanatically on his truly buggy board.
Ingo Molnar54168ed2008-08-20 09:07:45 +02002767 *
2768 * FIXME: really need to revamp this for all platforms.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 */
Zachary Amsden8542b202006-12-07 02:14:09 +01002770static inline void __init check_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771{
Thomas Gleixner2c778652011-03-12 12:20:43 +01002772 struct irq_cfg *cfg = irq_get_chip_data(0);
Robert Richterf6e9456c2010-07-21 19:03:58 +02002773 int node = cpu_to_node(0);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002774 int apic1, pin1, apic2, pin2;
Ingo Molnar4aae0702007-12-18 18:05:58 +01002775 unsigned long flags;
Yinghai Lu047c8fd2008-08-19 20:50:41 -07002776 int no_pin1 = 0;
Ingo Molnar4aae0702007-12-18 18:05:58 +01002777
2778 local_irq_save(flags);
Maciej W. Rozyckid4d25de2007-11-26 20:42:19 +01002779
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 /*
2781 * get/set the timer IRQ vector:
2782 */
Thomas Gleixner4305df92010-09-28 15:01:33 +02002783 legacy_pic->mask(0);
Ingo Molnarfe402e12009-01-28 04:32:51 +01002784 assign_irq_vector(0, cfg, apic->target_cpus());
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
2786 /*
Maciej W. Rozyckid11d5792008-05-21 22:09:11 +01002787 * As IRQ0 is to be enabled in the 8259A, the virtual
2788 * wire has to be disabled in the local APIC. Also
2789 * timer interrupts need to be acknowledged manually in
2790 * the 8259A for the i82489DX when using the NMI
2791 * watchdog as that APIC treats NMIs as level-triggered.
2792 * The AEOI mode will finish them in the 8259A
2793 * automatically.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 */
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +01002795 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
Jacob Panb81bb372009-11-09 11:27:04 -08002796 legacy_pic->init(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002798 pin1 = find_isa_irq_pin(0, mp_INT);
2799 apic1 = find_isa_irq_apic(0, mp_INT);
2800 pin2 = ioapic_i8259.pin;
2801 apic2 = ioapic_i8259.apic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002803 apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X "
2804 "apic1=%d pin1=%d apic2=%d pin2=%d\n",
Yinghai Lu497c9a12008-08-19 20:50:28 -07002805 cfg->vector, apic1, pin1, apic2, pin2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
Maciej W. Rozycki691874f2008-05-27 21:19:51 +01002807 /*
2808 * Some BIOS writers are clueless and report the ExtINTA
2809 * I/O APIC input from the cascaded 8259A as the timer
2810 * interrupt input. So just in case, if only one pin
2811 * was found above, try it both directly and through the
2812 * 8259A.
2813 */
2814 if (pin1 == -1) {
Ingo Molnar54168ed2008-08-20 09:07:45 +02002815 if (intr_remapping_enabled)
2816 panic("BIOS bug: timer not connected to IO-APIC");
Maciej W. Rozycki691874f2008-05-27 21:19:51 +01002817 pin1 = pin2;
2818 apic1 = apic2;
2819 no_pin1 = 1;
2820 } else if (pin2 == -1) {
2821 pin2 = pin1;
2822 apic2 = apic1;
2823 }
2824
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 if (pin1 != -1) {
2826 /*
2827 * Ok, does IRQ0 through the IOAPIC work?
2828 */
Maciej W. Rozycki691874f2008-05-27 21:19:51 +01002829 if (no_pin1) {
Yinghai Lu85ac16d2009-04-27 18:00:38 -07002830 add_pin_to_irq_node(cfg, node, apic1, pin1);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002831 setup_timer_IRQ0_pin(apic1, pin1, cfg->vector);
Yinghai Luf72dcca2009-02-08 16:18:03 -08002832 } else {
Thomas Gleixner60c69942010-09-28 17:28:38 +02002833 /* for edge trigger, setup_ioapic_irq already
Yinghai Luf72dcca2009-02-08 16:18:03 -08002834 * leave it unmasked.
2835 * so only need to unmask if it is level-trigger
2836 * do we really have level trigger timer?
2837 */
2838 int idx;
2839 idx = find_irq_entry(apic1, pin1, mp_INT);
2840 if (idx != -1 && irq_trigger(idx))
Thomas Gleixnerdd5f15e2010-09-28 15:18:35 +02002841 unmask_ioapic(cfg);
Maciej W. Rozycki691874f2008-05-27 21:19:51 +01002842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 if (timer_irq_works()) {
Chuck Ebbert66759a02005-09-12 18:49:25 +02002844 if (disable_timer_pin_1 > 0)
2845 clear_IO_APIC_pin(0, pin1);
Ingo Molnar4aae0702007-12-18 18:05:58 +01002846 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 }
Ingo Molnar54168ed2008-08-20 09:07:45 +02002848 if (intr_remapping_enabled)
2849 panic("timer doesn't work through Interrupt-remapped IO-APIC");
Yinghai Luf72dcca2009-02-08 16:18:03 -08002850 local_irq_disable();
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002851 clear_IO_APIC_pin(apic1, pin1);
Maciej W. Rozycki691874f2008-05-27 21:19:51 +01002852 if (!no_pin1)
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002853 apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: "
2854 "8254 timer not connected to IO-APIC\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002856 apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer "
2857 "(IRQ0) through the 8259A ...\n");
2858 apic_printk(APIC_QUIET, KERN_INFO
2859 "..... (found apic %d pin %d) ...\n", apic2, pin2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 /*
2861 * legacy devices should be connected to IO APIC #0
2862 */
Yinghai Lu85ac16d2009-04-27 18:00:38 -07002863 replace_pin_at_irq_node(cfg, node, apic1, pin1, apic2, pin2);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002864 setup_timer_IRQ0_pin(apic2, pin2, cfg->vector);
Thomas Gleixner4305df92010-09-28 15:01:33 +02002865 legacy_pic->unmask(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 if (timer_irq_works()) {
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002867 apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
Maciej W. Rozycki35542c52008-05-21 22:10:22 +01002868 timer_through_8259 = 1;
Ingo Molnar4aae0702007-12-18 18:05:58 +01002869 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 }
2871 /*
2872 * Cleanup, just in case ...
2873 */
Yinghai Luf72dcca2009-02-08 16:18:03 -08002874 local_irq_disable();
Thomas Gleixner4305df92010-09-28 15:01:33 +02002875 legacy_pic->mask(0);
Eric W. Biedermanfcfd6362005-10-30 14:59:39 -08002876 clear_IO_APIC_pin(apic2, pin2);
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002877 apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002880 apic_printk(APIC_QUIET, KERN_INFO
2881 "...trying to set up timer as Virtual Wire IRQ...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882
Thomas Gleixner60c69942010-09-28 17:28:38 +02002883 lapic_register_intr(0);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002884 apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */
Thomas Gleixner4305df92010-09-28 15:01:33 +02002885 legacy_pic->unmask(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886
2887 if (timer_irq_works()) {
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002888 apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
Ingo Molnar4aae0702007-12-18 18:05:58 +01002889 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 }
Yinghai Luf72dcca2009-02-08 16:18:03 -08002891 local_irq_disable();
Thomas Gleixner4305df92010-09-28 15:01:33 +02002892 legacy_pic->mask(0);
Yinghai Lu497c9a12008-08-19 20:50:28 -07002893 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector);
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002894 apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002896 apic_printk(APIC_QUIET, KERN_INFO
2897 "...trying to set up timer as ExtINT IRQ...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
Jacob Panb81bb372009-11-09 11:27:04 -08002899 legacy_pic->init(0);
2900 legacy_pic->make_irq(0);
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +01002901 apic_write(APIC_LVT0, APIC_DM_EXTINT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902
2903 unlock_ExtINT_logic();
2904
2905 if (timer_irq_works()) {
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002906 apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
Ingo Molnar4aae0702007-12-18 18:05:58 +01002907 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 }
Yinghai Luf72dcca2009-02-08 16:18:03 -08002909 local_irq_disable();
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002910 apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
Maciej W. Rozycki49a66a02008-07-14 19:08:13 +01002912 "report. Then try booting with the 'noapic' option.\n");
Ingo Molnar4aae0702007-12-18 18:05:58 +01002913out:
2914 local_irq_restore(flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915}
2916
2917/*
Maciej W. Rozyckiaf174782008-07-11 19:35:23 +01002918 * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
2919 * to devices. However there may be an I/O APIC pin available for
2920 * this interrupt regardless. The pin may be left unconnected, but
2921 * typically it will be reused as an ExtINT cascade interrupt for
2922 * the master 8259A. In the MPS case such a pin will normally be
2923 * reported as an ExtINT interrupt in the MP table. With ACPI
2924 * there is no provision for ExtINT interrupts, and in the absence
2925 * of an override it would be treated as an ordinary ISA I/O APIC
2926 * interrupt, that is edge-triggered and unmasked by default. We
2927 * used to do this, but it caused problems on some systems because
2928 * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
2929 * the same ExtINT cascade interrupt to drive the local APIC of the
2930 * bootstrap processor. Therefore we refrain from routing IRQ2 to
2931 * the I/O APIC in all cases now. No actual device should request
2932 * it anyway. --macro
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 */
Thomas Gleixnerbc078442009-08-29 18:09:57 +02002934#define PIC_IRQS (1UL << PIC_CASCADE_IR)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
2936void __init setup_IO_APIC(void)
2937{
Ingo Molnar54168ed2008-08-20 09:07:45 +02002938
Ingo Molnar54168ed2008-08-20 09:07:45 +02002939 /*
2940 * calling enable_IO_APIC() is moved to setup_local_APIC for BP
2941 */
Jacob Panb81bb372009-11-09 11:27:04 -08002942 io_apic_irqs = legacy_pic->nr_legacy_irqs ? ~PIC_IRQS : ~0UL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943
Ingo Molnar54168ed2008-08-20 09:07:45 +02002944 apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n");
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02002945 /*
Ingo Molnar54168ed2008-08-20 09:07:45 +02002946 * Set up IO-APIC IRQ routing.
2947 */
Thomas Gleixnerde934102009-08-20 09:27:29 +02002948 x86_init.mpparse.setup_ioapic_ids();
2949
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 sync_Arb_IDs();
2951 setup_IO_APIC_irqs();
2952 init_IO_APIC_traps();
Jacob Panb81bb372009-11-09 11:27:04 -08002953 if (legacy_pic->nr_legacy_irqs)
Thomas Gleixnerbc078442009-08-29 18:09:57 +02002954 check_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955}
2956
2957/*
Lucas De Marchi0d2eb442011-03-17 16:24:16 -03002958 * Called after all the initialization is done. If we didn't find any
Ingo Molnar54168ed2008-08-20 09:07:45 +02002959 * APIC bugs then we can allow the modify fast path
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 */
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02002961
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962static int __init io_apic_bug_finalize(void)
2963{
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02002964 if (sis_apic_bug == -1)
2965 sis_apic_bug = 0;
2966 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967}
2968
2969late_initcall(io_apic_bug_finalize);
2970
Suresh Siddha15bac202011-05-18 16:31:34 -07002971static void resume_ioapic_id(int ioapic_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 unsigned long flags;
2974 union IO_APIC_reg_00 reg_00;
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02002975
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002977 raw_spin_lock_irqsave(&ioapic_lock, flags);
Rafael J. Wysockif3c6ea12011-03-23 22:15:54 +01002978 reg_00.raw = io_apic_read(ioapic_id, 0);
Suresh Siddhad5371432011-05-18 16:31:37 -07002979 if (reg_00.bits.ID != mpc_ioapic_id(ioapic_id)) {
2980 reg_00.bits.ID = mpc_ioapic_id(ioapic_id);
Rafael J. Wysockif3c6ea12011-03-23 22:15:54 +01002981 io_apic_write(ioapic_id, 0, reg_00.raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 }
Thomas Gleixnerdade7712009-07-25 18:39:36 +02002983 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984}
2985
Rafael J. Wysockif3c6ea12011-03-23 22:15:54 +01002986static void ioapic_resume(void)
2987{
2988 int ioapic_id;
2989
2990 for (ioapic_id = nr_ioapics - 1; ioapic_id >= 0; ioapic_id--)
Suresh Siddha15bac202011-05-18 16:31:34 -07002991 resume_ioapic_id(ioapic_id);
2992
2993 restore_ioapic_entries();
Rafael J. Wysockif3c6ea12011-03-23 22:15:54 +01002994}
2995
2996static struct syscore_ops ioapic_syscore_ops = {
Suresh Siddha15bac202011-05-18 16:31:34 -07002997 .suspend = save_ioapic_entries,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 .resume = ioapic_resume,
2999};
3000
Rafael J. Wysockif3c6ea12011-03-23 22:15:54 +01003001static int __init ioapic_init_ops(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002{
Rafael J. Wysockif3c6ea12011-03-23 22:15:54 +01003003 register_syscore_ops(&ioapic_syscore_ops);
3004
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 return 0;
3006}
3007
Rafael J. Wysockif3c6ea12011-03-23 22:15:54 +01003008device_initcall(ioapic_init_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003010/*
Eric W. Biederman95d77882006-10-04 02:17:01 -07003011 * Dynamic irq allocate and deallocation
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003012 */
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003013unsigned int create_irq_nr(unsigned int from, int node)
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003014{
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003015 struct irq_cfg *cfg;
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003016 unsigned long flags;
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003017 unsigned int ret = 0;
3018 int irq;
Yinghai Lu199751d2008-08-19 20:50:27 -07003019
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003020 if (from < nr_irqs_gsi)
3021 from = nr_irqs_gsi;
3022
3023 irq = alloc_irq_from(from, node);
3024 if (irq < 0)
3025 return 0;
3026 cfg = alloc_irq_cfg(irq, node);
3027 if (!cfg) {
3028 free_irq_at(irq, NULL);
3029 return 0;
3030 }
Yinghai Luabcaa2b2009-02-08 16:18:03 -08003031
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003032 raw_spin_lock_irqsave(&vector_lock, flags);
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003033 if (!__assign_irq_vector(irq, cfg, apic->target_cpus()))
3034 ret = irq;
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003035 raw_spin_unlock_irqrestore(&vector_lock, flags);
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003036
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003037 if (ret) {
Thomas Gleixner2c778652011-03-12 12:20:43 +01003038 irq_set_chip_data(irq, cfg);
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003039 irq_clear_status_flags(irq, IRQ_NOREQUEST);
3040 } else {
3041 free_irq_at(irq, cfg);
3042 }
3043 return ret;
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003044}
3045
Yinghai Lu199751d2008-08-19 20:50:27 -07003046int create_irq(void)
3047{
Robert Richterf6e9456c2010-07-21 19:03:58 +02003048 int node = cpu_to_node(0);
Yinghai Lube5d5352008-12-05 18:58:33 -08003049 unsigned int irq_want;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003050 int irq;
3051
Yinghai Lube5d5352008-12-05 18:58:33 -08003052 irq_want = nr_irqs_gsi;
Yinghai Lud047f53a2009-04-27 18:02:23 -07003053 irq = create_irq_nr(irq_want, node);
Ingo Molnar54168ed2008-08-20 09:07:45 +02003054
3055 if (irq == 0)
3056 irq = -1;
3057
3058 return irq;
Yinghai Lu199751d2008-08-19 20:50:27 -07003059}
3060
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003061void destroy_irq(unsigned int irq)
3062{
Thomas Gleixner2c778652011-03-12 12:20:43 +01003063 struct irq_cfg *cfg = irq_get_chip_data(irq);
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003064 unsigned long flags;
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003065
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003066 irq_set_status_flags(irq, IRQ_NOREQUEST|IRQ_NOPROBE);
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003067
Yinghai Lu7b794622010-10-30 01:19:29 -07003068 if (irq_remapped(cfg))
Yinghai Lu97179672010-10-18 13:47:48 -07003069 free_irte(irq);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003070 raw_spin_lock_irqsave(&vector_lock, flags);
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003071 __clear_irq_vector(irq, cfg);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003072 raw_spin_unlock_irqrestore(&vector_lock, flags);
Thomas Gleixnerfbc6bff2010-09-28 20:34:53 +02003073 free_irq_at(irq, cfg);
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003074}
Eric W. Biederman3fc471e2006-10-04 02:16:39 -07003075
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003076/*
Simon Arlott27b46d72007-10-20 01:13:56 +02003077 * MSI message composition
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003078 */
3079#ifdef CONFIG_PCI_MSI
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003080static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq,
3081 struct msi_msg *msg, u8 hpet_id)
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003082{
Yinghai Lu497c9a12008-08-19 20:50:28 -07003083 struct irq_cfg *cfg;
3084 int err;
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003085 unsigned dest;
3086
Jan Beulichf1182632009-01-14 12:27:35 +00003087 if (disable_apic)
3088 return -ENXIO;
3089
Yinghai Lu3145e942008-12-05 18:58:34 -08003090 cfg = irq_cfg(irq);
Ingo Molnarfe402e12009-01-28 04:32:51 +01003091 err = assign_irq_vector(irq, cfg, apic->target_cpus());
Yinghai Lu497c9a12008-08-19 20:50:28 -07003092 if (err)
3093 return err;
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003094
Ingo Molnardebccb32009-01-28 15:20:18 +01003095 dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003096
Thomas Gleixner1a0e62a2011-03-12 13:47:18 +01003097 if (irq_remapped(cfg)) {
Ingo Molnar54168ed2008-08-20 09:07:45 +02003098 struct irte irte;
3099 int ir_index;
3100 u16 sub_handle;
Yinghai Lu497c9a12008-08-19 20:50:28 -07003101
Ingo Molnar54168ed2008-08-20 09:07:45 +02003102 ir_index = map_irq_to_irte_handle(irq, &sub_handle);
3103 BUG_ON(ir_index == -1);
Yinghai Lu497c9a12008-08-19 20:50:28 -07003104
Suresh Siddha62a92f42010-08-27 11:09:49 -07003105 prepare_irte(&irte, cfg->vector, dest);
Ingo Molnar54168ed2008-08-20 09:07:45 +02003106
Weidong Hanf007e992009-05-23 00:41:15 +08003107 /* Set source-id of interrupt request */
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003108 if (pdev)
3109 set_msi_sid(&irte, pdev);
3110 else
3111 set_hpet_sid(&irte, hpet_id);
Weidong Hanf007e992009-05-23 00:41:15 +08003112
Ingo Molnar54168ed2008-08-20 09:07:45 +02003113 modify_irte(irq, &irte);
3114
3115 msg->address_hi = MSI_ADDR_BASE_HI;
3116 msg->data = sub_handle;
3117 msg->address_lo = MSI_ADDR_BASE_LO | MSI_ADDR_IR_EXT_INT |
3118 MSI_ADDR_IR_SHV |
3119 MSI_ADDR_IR_INDEX1(ir_index) |
3120 MSI_ADDR_IR_INDEX2(ir_index);
Suresh Siddha29b61be2009-03-16 17:05:02 -07003121 } else {
Suresh Siddha9d783ba2009-03-16 17:04:55 -07003122 if (x2apic_enabled())
3123 msg->address_hi = MSI_ADDR_BASE_HI |
3124 MSI_ADDR_EXT_DEST_ID(dest);
3125 else
3126 msg->address_hi = MSI_ADDR_BASE_HI;
3127
Ingo Molnar54168ed2008-08-20 09:07:45 +02003128 msg->address_lo =
3129 MSI_ADDR_BASE_LO |
Ingo Molnar9b5bc8d2009-01-28 04:09:58 +01003130 ((apic->irq_dest_mode == 0) ?
Ingo Molnar54168ed2008-08-20 09:07:45 +02003131 MSI_ADDR_DEST_MODE_PHYSICAL:
3132 MSI_ADDR_DEST_MODE_LOGICAL) |
Ingo Molnar9b5bc8d2009-01-28 04:09:58 +01003133 ((apic->irq_delivery_mode != dest_LowestPrio) ?
Ingo Molnar54168ed2008-08-20 09:07:45 +02003134 MSI_ADDR_REDIRECTION_CPU:
3135 MSI_ADDR_REDIRECTION_LOWPRI) |
3136 MSI_ADDR_DEST_ID(dest);
3137
3138 msg->data =
3139 MSI_DATA_TRIGGER_EDGE |
3140 MSI_DATA_LEVEL_ASSERT |
Ingo Molnar9b5bc8d2009-01-28 04:09:58 +01003141 ((apic->irq_delivery_mode != dest_LowestPrio) ?
Ingo Molnar54168ed2008-08-20 09:07:45 +02003142 MSI_DATA_DELIVERY_FIXED:
3143 MSI_DATA_DELIVERY_LOWPRI) |
3144 MSI_DATA_VECTOR(cfg->vector);
3145 }
Yinghai Lu497c9a12008-08-19 20:50:28 -07003146 return err;
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003147}
3148
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003149#ifdef CONFIG_SMP
Thomas Gleixner5346b2a2010-10-08 21:49:03 +02003150static int
3151msi_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003152{
Thomas Gleixner5346b2a2010-10-08 21:49:03 +02003153 struct irq_cfg *cfg = data->chip_data;
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003154 struct msi_msg msg;
3155 unsigned int dest;
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003156
Thomas Gleixner5346b2a2010-10-08 21:49:03 +02003157 if (__ioapic_set_affinity(data, mask, &dest))
Yinghai Lud5dedd42009-04-27 17:59:21 -07003158 return -1;
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003159
Thomas Gleixner5346b2a2010-10-08 21:49:03 +02003160 __get_cached_msi_msg(data->msi_desc, &msg);
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003161
3162 msg.data &= ~MSI_DATA_VECTOR_MASK;
Yinghai Lu497c9a12008-08-19 20:50:28 -07003163 msg.data |= MSI_DATA_VECTOR(cfg->vector);
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003164 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3165 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3166
Thomas Gleixner5346b2a2010-10-08 21:49:03 +02003167 __write_msi_msg(data->msi_desc, &msg);
Yinghai Lud5dedd42009-04-27 17:59:21 -07003168
3169 return 0;
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003170}
Ingo Molnar54168ed2008-08-20 09:07:45 +02003171#ifdef CONFIG_INTR_REMAP
3172/*
3173 * Migrate the MSI irq to another cpumask. This migration is
3174 * done in the process context using interrupt-remapping hardware.
3175 */
Yinghai Lud5dedd42009-04-27 17:59:21 -07003176static int
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003177ir_msi_set_affinity(struct irq_data *data, const struct cpumask *mask,
3178 bool force)
Ingo Molnar54168ed2008-08-20 09:07:45 +02003179{
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003180 struct irq_cfg *cfg = data->chip_data;
3181 unsigned int dest, irq = data->irq;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003182 struct irte irte;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003183
3184 if (get_irte(irq, &irte))
Yinghai Lud5dedd42009-04-27 17:59:21 -07003185 return -1;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003186
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003187 if (__ioapic_set_affinity(data, mask, &dest))
Yinghai Lud5dedd42009-04-27 17:59:21 -07003188 return -1;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003189
Ingo Molnar54168ed2008-08-20 09:07:45 +02003190 irte.vector = cfg->vector;
3191 irte.dest_id = IRTE_DEST(dest);
3192
3193 /*
3194 * atomically update the IRTE with the new destination and vector.
3195 */
3196 modify_irte(irq, &irte);
3197
3198 /*
3199 * After this point, all the interrupts will start arriving
3200 * at the new destination. So, time to cleanup the previous
3201 * vector allocation.
3202 */
Mike Travis22f65d32008-12-16 17:33:56 -08003203 if (cfg->move_in_progress)
3204 send_cleanup_vector(cfg);
Yinghai Lud5dedd42009-04-27 17:59:21 -07003205
3206 return 0;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003207}
Yinghai Lu3145e942008-12-05 18:58:34 -08003208
Ingo Molnar54168ed2008-08-20 09:07:45 +02003209#endif
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003210#endif /* CONFIG_SMP */
3211
3212/*
3213 * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
3214 * which implement the MSI or MSI-X Capability Structure.
3215 */
3216static struct irq_chip msi_chip = {
Thomas Gleixner5346b2a2010-10-08 21:49:03 +02003217 .name = "PCI-MSI",
3218 .irq_unmask = unmask_msi_irq,
3219 .irq_mask = mask_msi_irq,
3220 .irq_ack = ack_apic_edge,
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003221#ifdef CONFIG_SMP
Thomas Gleixner5346b2a2010-10-08 21:49:03 +02003222 .irq_set_affinity = msi_set_affinity,
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003223#endif
Thomas Gleixner5346b2a2010-10-08 21:49:03 +02003224 .irq_retrigger = ioapic_retrigger_irq,
Eric W. Biederman3b7d1922006-10-04 02:16:59 -07003225};
3226
Ingo Molnar54168ed2008-08-20 09:07:45 +02003227static struct irq_chip msi_ir_chip = {
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003228 .name = "IR-PCI-MSI",
3229 .irq_unmask = unmask_msi_irq,
3230 .irq_mask = mask_msi_irq,
Jaswinder Singh Rajputa1e38ca2009-03-23 02:11:25 +05303231#ifdef CONFIG_INTR_REMAP
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003232 .irq_ack = ir_ack_apic_edge,
Ingo Molnar54168ed2008-08-20 09:07:45 +02003233#ifdef CONFIG_SMP
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003234 .irq_set_affinity = ir_msi_set_affinity,
Ingo Molnar54168ed2008-08-20 09:07:45 +02003235#endif
Jaswinder Singh Rajputa1e38ca2009-03-23 02:11:25 +05303236#endif
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003237 .irq_retrigger = ioapic_retrigger_irq,
Ingo Molnar54168ed2008-08-20 09:07:45 +02003238};
3239
3240/*
3241 * Map the PCI dev to the corresponding remapping hardware unit
3242 * and allocate 'nvec' consecutive interrupt-remapping table entries
3243 * in it.
3244 */
3245static int msi_alloc_irte(struct pci_dev *dev, int irq, int nvec)
3246{
3247 struct intel_iommu *iommu;
3248 int index;
3249
3250 iommu = map_dev_to_ir(dev);
3251 if (!iommu) {
3252 printk(KERN_ERR
3253 "Unable to map PCI %s to iommu\n", pci_name(dev));
3254 return -ENOENT;
3255 }
3256
3257 index = alloc_irte(iommu, irq, nvec);
3258 if (index < 0) {
3259 printk(KERN_ERR
3260 "Unable to allocate %d IRTE for PCI %s\n", nvec,
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02003261 pci_name(dev));
Ingo Molnar54168ed2008-08-20 09:07:45 +02003262 return -ENOSPC;
3263 }
3264 return index;
3265}
Yinghai Lu1d025192008-08-19 20:50:34 -07003266
Yinghai Lu3145e942008-12-05 18:58:34 -08003267static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)
Yinghai Lu1d025192008-08-19 20:50:34 -07003268{
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01003269 struct irq_chip *chip = &msi_chip;
Yinghai Lu1d025192008-08-19 20:50:34 -07003270 struct msi_msg msg;
Thomas Gleixner60c69942010-09-28 17:28:38 +02003271 int ret;
Yinghai Lu1d025192008-08-19 20:50:34 -07003272
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003273 ret = msi_compose_msg(dev, irq, &msg, -1);
Yinghai Lu1d025192008-08-19 20:50:34 -07003274 if (ret < 0)
3275 return ret;
3276
Thomas Gleixner2c778652011-03-12 12:20:43 +01003277 irq_set_msi_desc(irq, msidesc);
Yinghai Lu1d025192008-08-19 20:50:34 -07003278 write_msi_msg(irq, &msg);
3279
Thomas Gleixner2c778652011-03-12 12:20:43 +01003280 if (irq_remapped(irq_get_chip_data(irq))) {
Thomas Gleixner60c69942010-09-28 17:28:38 +02003281 irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01003282 chip = &msi_ir_chip;
3283 }
3284
3285 irq_set_chip_and_handler_name(irq, chip, handle_edge_irq, "edge");
Yinghai Lu1d025192008-08-19 20:50:34 -07003286
Yinghai Luc81bba42008-09-25 11:53:11 -07003287 dev_printk(KERN_DEBUG, &dev->dev, "irq %d for MSI/MSI-X\n", irq);
3288
Yinghai Lu1d025192008-08-19 20:50:34 -07003289 return 0;
3290}
3291
Stefano Stabellini294ee6f2010-10-06 16:12:28 -04003292int native_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
Yinghai Lu047c8fd2008-08-19 20:50:41 -07003293{
Thomas Gleixner60c69942010-09-28 17:28:38 +02003294 int node, ret, sub_handle, index = 0;
3295 unsigned int irq, irq_want;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -08003296 struct msi_desc *msidesc;
Dmitri Vorobiev1cc18522009-03-22 19:11:09 +02003297 struct intel_iommu *iommu = NULL;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003298
Matthew Wilcox1c8d7b02009-03-17 08:54:10 -04003299 /* x86 doesn't support multiple MSI yet */
3300 if (type == PCI_CAP_ID_MSI && nvec > 1)
3301 return 1;
3302
Yinghai Lud047f53a2009-04-27 18:02:23 -07003303 node = dev_to_node(&dev->dev);
Yinghai Lube5d5352008-12-05 18:58:33 -08003304 irq_want = nr_irqs_gsi;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003305 sub_handle = 0;
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -08003306 list_for_each_entry(msidesc, &dev->msi_list, list) {
Yinghai Lud047f53a2009-04-27 18:02:23 -07003307 irq = create_irq_nr(irq_want, node);
Ingo Molnar54168ed2008-08-20 09:07:45 +02003308 if (irq == 0)
3309 return -1;
Yinghai Luf1ee5542009-02-08 16:18:03 -08003310 irq_want = irq + 1;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003311 if (!intr_remapping_enabled)
3312 goto no_ir;
3313
3314 if (!sub_handle) {
3315 /*
3316 * allocate the consecutive block of IRTE's
3317 * for 'nvec'
3318 */
3319 index = msi_alloc_irte(dev, irq, nvec);
3320 if (index < 0) {
3321 ret = index;
3322 goto error;
3323 }
3324 } else {
3325 iommu = map_dev_to_ir(dev);
3326 if (!iommu) {
3327 ret = -ENOENT;
3328 goto error;
3329 }
3330 /*
3331 * setup the mapping between the irq and the IRTE
3332 * base index, the sub_handle pointing to the
3333 * appropriate interrupt remap table entry.
3334 */
3335 set_irte_irq(irq, iommu, index, sub_handle);
3336 }
3337no_ir:
Yinghai Lu0b8f1ef2008-12-05 18:58:31 -08003338 ret = setup_msi_irq(dev, msidesc, irq);
Ingo Molnar54168ed2008-08-20 09:07:45 +02003339 if (ret < 0)
3340 goto error;
3341 sub_handle++;
3342 }
3343 return 0;
Yinghai Lu047c8fd2008-08-19 20:50:41 -07003344
3345error:
Ingo Molnar54168ed2008-08-20 09:07:45 +02003346 destroy_irq(irq);
3347 return ret;
Yinghai Lu047c8fd2008-08-19 20:50:41 -07003348}
3349
Stefano Stabellini294ee6f2010-10-06 16:12:28 -04003350void native_teardown_msi_irq(unsigned int irq)
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003351{
Eric W. Biedermanf7feaca2007-01-28 12:56:37 -07003352 destroy_irq(irq);
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003353}
3354
Suresh Siddha9d783ba2009-03-16 17:04:55 -07003355#if defined (CONFIG_DMAR) || defined (CONFIG_INTR_REMAP)
Ingo Molnar54168ed2008-08-20 09:07:45 +02003356#ifdef CONFIG_SMP
Thomas Gleixnerfe52b2d2010-10-08 22:19:29 +02003357static int
3358dmar_msi_set_affinity(struct irq_data *data, const struct cpumask *mask,
3359 bool force)
Ingo Molnar54168ed2008-08-20 09:07:45 +02003360{
Thomas Gleixnerfe52b2d2010-10-08 22:19:29 +02003361 struct irq_cfg *cfg = data->chip_data;
3362 unsigned int dest, irq = data->irq;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003363 struct msi_msg msg;
Eric W. Biederman2d3fcc12006-10-04 02:16:43 -07003364
Thomas Gleixnerfe52b2d2010-10-08 22:19:29 +02003365 if (__ioapic_set_affinity(data, mask, &dest))
Yinghai Lud5dedd42009-04-27 17:59:21 -07003366 return -1;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003367
Ingo Molnar54168ed2008-08-20 09:07:45 +02003368 dmar_msi_read(irq, &msg);
3369
3370 msg.data &= ~MSI_DATA_VECTOR_MASK;
3371 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3372 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3373 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
Kenji Kaneshige086e8ce2010-12-01 09:40:32 -08003374 msg.address_hi = MSI_ADDR_BASE_HI | MSI_ADDR_EXT_DEST_ID(dest);
Ingo Molnar54168ed2008-08-20 09:07:45 +02003375
3376 dmar_msi_write(irq, &msg);
Yinghai Lud5dedd42009-04-27 17:59:21 -07003377
3378 return 0;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003379}
Yinghai Lu3145e942008-12-05 18:58:34 -08003380
Ingo Molnar54168ed2008-08-20 09:07:45 +02003381#endif /* CONFIG_SMP */
3382
Jaswinder Singh Rajput8f7007a2009-06-10 12:41:01 -07003383static struct irq_chip dmar_msi_type = {
Thomas Gleixnerfe52b2d2010-10-08 22:19:29 +02003384 .name = "DMAR_MSI",
3385 .irq_unmask = dmar_msi_unmask,
3386 .irq_mask = dmar_msi_mask,
3387 .irq_ack = ack_apic_edge,
Ingo Molnar54168ed2008-08-20 09:07:45 +02003388#ifdef CONFIG_SMP
Thomas Gleixnerfe52b2d2010-10-08 22:19:29 +02003389 .irq_set_affinity = dmar_msi_set_affinity,
Ingo Molnar54168ed2008-08-20 09:07:45 +02003390#endif
Thomas Gleixnerfe52b2d2010-10-08 22:19:29 +02003391 .irq_retrigger = ioapic_retrigger_irq,
Ingo Molnar54168ed2008-08-20 09:07:45 +02003392};
3393
3394int arch_setup_dmar_msi(unsigned int irq)
3395{
3396 int ret;
3397 struct msi_msg msg;
3398
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003399 ret = msi_compose_msg(NULL, irq, &msg, -1);
Ingo Molnar54168ed2008-08-20 09:07:45 +02003400 if (ret < 0)
3401 return ret;
3402 dmar_msi_write(irq, &msg);
Thomas Gleixner2c778652011-03-12 12:20:43 +01003403 irq_set_chip_and_handler_name(irq, &dmar_msi_type, handle_edge_irq,
3404 "edge");
Ingo Molnar54168ed2008-08-20 09:07:45 +02003405 return 0;
3406}
3407#endif
3408
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003409#ifdef CONFIG_HPET_TIMER
3410
3411#ifdef CONFIG_SMP
Thomas Gleixnerd0fbca82010-09-28 16:18:39 +02003412static int hpet_msi_set_affinity(struct irq_data *data,
3413 const struct cpumask *mask, bool force)
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003414{
Thomas Gleixnerd0fbca82010-09-28 16:18:39 +02003415 struct irq_cfg *cfg = data->chip_data;
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003416 struct msi_msg msg;
3417 unsigned int dest;
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003418
Thomas Gleixner0e09ddf2010-10-08 22:21:26 +02003419 if (__ioapic_set_affinity(data, mask, &dest))
Yinghai Lud5dedd42009-04-27 17:59:21 -07003420 return -1;
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003421
Thomas Gleixnerd0fbca82010-09-28 16:18:39 +02003422 hpet_msi_read(data->handler_data, &msg);
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003423
3424 msg.data &= ~MSI_DATA_VECTOR_MASK;
3425 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3426 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3427 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3428
Thomas Gleixnerd0fbca82010-09-28 16:18:39 +02003429 hpet_msi_write(data->handler_data, &msg);
Yinghai Lud5dedd42009-04-27 17:59:21 -07003430
3431 return 0;
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003432}
Yinghai Lu3145e942008-12-05 18:58:34 -08003433
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003434#endif /* CONFIG_SMP */
3435
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003436static struct irq_chip ir_hpet_msi_type = {
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003437 .name = "IR-HPET_MSI",
3438 .irq_unmask = hpet_msi_unmask,
3439 .irq_mask = hpet_msi_mask,
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003440#ifdef CONFIG_INTR_REMAP
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003441 .irq_ack = ir_ack_apic_edge,
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003442#ifdef CONFIG_SMP
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003443 .irq_set_affinity = ir_msi_set_affinity,
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003444#endif
3445#endif
Thomas Gleixnerb5d1c462010-10-08 22:15:49 +02003446 .irq_retrigger = ioapic_retrigger_irq,
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003447};
3448
Dmitri Vorobiev1cc18522009-03-22 19:11:09 +02003449static struct irq_chip hpet_msi_type = {
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003450 .name = "HPET_MSI",
Thomas Gleixnerd0fbca82010-09-28 16:18:39 +02003451 .irq_unmask = hpet_msi_unmask,
3452 .irq_mask = hpet_msi_mask,
Thomas Gleixner90297c52010-09-28 16:03:54 +02003453 .irq_ack = ack_apic_edge,
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003454#ifdef CONFIG_SMP
Thomas Gleixnerd0fbca82010-09-28 16:18:39 +02003455 .irq_set_affinity = hpet_msi_set_affinity,
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003456#endif
Thomas Gleixner90297c52010-09-28 16:03:54 +02003457 .irq_retrigger = ioapic_retrigger_irq,
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003458};
3459
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003460int arch_setup_hpet_msi(unsigned int irq, unsigned int id)
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003461{
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01003462 struct irq_chip *chip = &hpet_msi_type;
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003463 struct msi_msg msg;
Thomas Gleixnerd0fbca82010-09-28 16:18:39 +02003464 int ret;
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003465
Suresh Siddhac8bc6f32009-08-04 12:07:09 -07003466 if (intr_remapping_enabled) {
3467 struct intel_iommu *iommu = map_hpet_to_ir(id);
3468 int index;
3469
3470 if (!iommu)
3471 return -1;
3472
3473 index = alloc_irte(iommu, irq, 1);
3474 if (index < 0)
3475 return -1;
3476 }
3477
3478 ret = msi_compose_msg(NULL, irq, &msg, id);
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003479 if (ret < 0)
3480 return ret;
3481
Thomas Gleixner2c778652011-03-12 12:20:43 +01003482 hpet_msi_write(irq_get_handler_data(irq), &msg);
Thomas Gleixner60c69942010-09-28 17:28:38 +02003483 irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
Thomas Gleixner2c778652011-03-12 12:20:43 +01003484 if (irq_remapped(irq_get_chip_data(irq)))
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01003485 chip = &ir_hpet_msi_type;
Yinghai Luc81bba42008-09-25 11:53:11 -07003486
Thomas Gleixnerc60eaf22011-03-11 13:17:16 +01003487 irq_set_chip_and_handler_name(irq, chip, handle_edge_irq, "edge");
venkatesh.pallipadi@intel.com58ac1e72008-09-05 18:02:17 -07003488 return 0;
3489}
3490#endif
3491
Ingo Molnar54168ed2008-08-20 09:07:45 +02003492#endif /* CONFIG_PCI_MSI */
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003493/*
3494 * Hypertransport interrupt support
3495 */
3496#ifdef CONFIG_HT_IRQ
3497
3498#ifdef CONFIG_SMP
3499
Yinghai Lu497c9a12008-08-19 20:50:28 -07003500static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector)
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003501{
Eric W. Biedermanec683072006-11-08 17:44:57 -08003502 struct ht_irq_msg msg;
3503 fetch_ht_irq_msg(irq, &msg);
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003504
Yinghai Lu497c9a12008-08-19 20:50:28 -07003505 msg.address_lo &= ~(HT_IRQ_LOW_VECTOR_MASK | HT_IRQ_LOW_DEST_ID_MASK);
Eric W. Biedermanec683072006-11-08 17:44:57 -08003506 msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003507
Yinghai Lu497c9a12008-08-19 20:50:28 -07003508 msg.address_lo |= HT_IRQ_LOW_VECTOR(vector) | HT_IRQ_LOW_DEST_ID(dest);
Eric W. Biedermanec683072006-11-08 17:44:57 -08003509 msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest);
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003510
Eric W. Biedermanec683072006-11-08 17:44:57 -08003511 write_ht_irq_msg(irq, &msg);
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003512}
3513
Thomas Gleixnerbe5b7bf2010-10-08 22:31:46 +02003514static int
3515ht_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003516{
Thomas Gleixnerbe5b7bf2010-10-08 22:31:46 +02003517 struct irq_cfg *cfg = data->chip_data;
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003518 unsigned int dest;
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003519
Thomas Gleixnerbe5b7bf2010-10-08 22:31:46 +02003520 if (__ioapic_set_affinity(data, mask, &dest))
Yinghai Lud5dedd42009-04-27 17:59:21 -07003521 return -1;
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003522
Thomas Gleixnerbe5b7bf2010-10-08 22:31:46 +02003523 target_ht_irq(data->irq, dest, cfg->vector);
Yinghai Lud5dedd42009-04-27 17:59:21 -07003524 return 0;
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003525}
Yinghai Lu3145e942008-12-05 18:58:34 -08003526
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003527#endif
3528
Aneesh Kumar K.Vc37e1082006-10-11 01:20:43 -07003529static struct irq_chip ht_irq_chip = {
Thomas Gleixnerbe5b7bf2010-10-08 22:31:46 +02003530 .name = "PCI-HT",
3531 .irq_mask = mask_ht_irq,
3532 .irq_unmask = unmask_ht_irq,
3533 .irq_ack = ack_apic_edge,
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003534#ifdef CONFIG_SMP
Thomas Gleixnerbe5b7bf2010-10-08 22:31:46 +02003535 .irq_set_affinity = ht_set_affinity,
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003536#endif
Thomas Gleixnerbe5b7bf2010-10-08 22:31:46 +02003537 .irq_retrigger = ioapic_retrigger_irq,
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003538};
3539
3540int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
3541{
Yinghai Lu497c9a12008-08-19 20:50:28 -07003542 struct irq_cfg *cfg;
3543 int err;
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003544
Jan Beulichf1182632009-01-14 12:27:35 +00003545 if (disable_apic)
3546 return -ENXIO;
3547
Yinghai Lu3145e942008-12-05 18:58:34 -08003548 cfg = irq_cfg(irq);
Ingo Molnarfe402e12009-01-28 04:32:51 +01003549 err = assign_irq_vector(irq, cfg, apic->target_cpus());
Ingo Molnar54168ed2008-08-20 09:07:45 +02003550 if (!err) {
Eric W. Biedermanec683072006-11-08 17:44:57 -08003551 struct ht_irq_msg msg;
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003552 unsigned dest;
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003553
Ingo Molnardebccb32009-01-28 15:20:18 +01003554 dest = apic->cpu_mask_to_apicid_and(cfg->domain,
3555 apic->target_cpus());
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003556
Eric W. Biedermanec683072006-11-08 17:44:57 -08003557 msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest);
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003558
Eric W. Biedermanec683072006-11-08 17:44:57 -08003559 msg.address_lo =
3560 HT_IRQ_LOW_BASE |
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003561 HT_IRQ_LOW_DEST_ID(dest) |
Yinghai Lu497c9a12008-08-19 20:50:28 -07003562 HT_IRQ_LOW_VECTOR(cfg->vector) |
Ingo Molnar9b5bc8d2009-01-28 04:09:58 +01003563 ((apic->irq_dest_mode == 0) ?
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003564 HT_IRQ_LOW_DM_PHYSICAL :
3565 HT_IRQ_LOW_DM_LOGICAL) |
3566 HT_IRQ_LOW_RQEOI_EDGE |
Ingo Molnar9b5bc8d2009-01-28 04:09:58 +01003567 ((apic->irq_delivery_mode != dest_LowestPrio) ?
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003568 HT_IRQ_LOW_MT_FIXED :
3569 HT_IRQ_LOW_MT_ARBITRATED) |
3570 HT_IRQ_LOW_IRQ_MASKED;
3571
Eric W. Biedermanec683072006-11-08 17:44:57 -08003572 write_ht_irq_msg(irq, &msg);
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003573
Thomas Gleixner2c778652011-03-12 12:20:43 +01003574 irq_set_chip_and_handler_name(irq, &ht_irq_chip,
Ingo Molnara460e742006-10-17 00:10:03 -07003575 handle_edge_irq, "edge");
Yinghai Luc81bba42008-09-25 11:53:11 -07003576
3577 dev_printk(KERN_DEBUG, &dev->dev, "irq %d for HT\n", irq);
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003578 }
Yinghai Lu497c9a12008-08-19 20:50:28 -07003579 return err;
Eric W. Biederman8b955b02006-10-04 02:16:55 -07003580}
3581#endif /* CONFIG_HT_IRQ */
3582
Sebastian Andrzej Siewior20443592011-04-27 16:30:52 +02003583static int
Thomas Gleixnerff973d02011-02-23 13:00:56 +01003584io_apic_setup_irq_pin(unsigned int irq, int node, struct io_apic_irq_attr *attr)
3585{
3586 struct irq_cfg *cfg = alloc_irq_and_cfg_at(irq, node);
3587 int ret;
3588
3589 if (!cfg)
3590 return -EINVAL;
3591 ret = __add_pin_to_irq_node(cfg, node, attr->ioapic, attr->ioapic_pin);
3592 if (!ret)
Yinghai Lue4aff812011-10-12 00:33:05 -07003593 setup_ioapic_irq(irq, cfg, attr);
Thomas Gleixnerff973d02011-02-23 13:00:56 +01003594 return ret;
3595}
3596
Sebastian Andrzej Siewior20443592011-04-27 16:30:52 +02003597int io_apic_setup_irq_pin_once(unsigned int irq, int node,
3598 struct io_apic_irq_attr *attr)
Thomas Gleixner710dcda2011-02-23 17:47:41 +01003599{
3600 unsigned int id = attr->ioapic, pin = attr->ioapic_pin;
3601 int ret;
3602
3603 /* Avoid redundant programming */
Suresh Siddha8f18c972011-05-18 16:31:39 -07003604 if (test_bit(pin, ioapics[id].pin_programmed)) {
Thomas Gleixner710dcda2011-02-23 17:47:41 +01003605 pr_debug("Pin %d-%d already programmed\n",
Suresh Siddhad5371432011-05-18 16:31:37 -07003606 mpc_ioapic_id(id), pin);
Thomas Gleixner710dcda2011-02-23 17:47:41 +01003607 return 0;
3608 }
3609 ret = io_apic_setup_irq_pin(irq, node, attr);
3610 if (!ret)
Suresh Siddha8f18c972011-05-18 16:31:39 -07003611 set_bit(pin, ioapics[id].pin_programmed);
Thomas Gleixner710dcda2011-02-23 17:47:41 +01003612 return ret;
3613}
3614
Thomas Gleixner41098ff2011-02-23 16:08:03 +01003615static int __init io_apic_get_redir_entries(int ioapic)
Yinghai Lu9d6a4d02008-08-19 20:50:52 -07003616{
3617 union IO_APIC_reg_01 reg_01;
3618 unsigned long flags;
3619
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003620 raw_spin_lock_irqsave(&ioapic_lock, flags);
Yinghai Lu9d6a4d02008-08-19 20:50:52 -07003621 reg_01.raw = io_apic_read(ioapic, 1);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003622 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Yinghai Lu9d6a4d02008-08-19 20:50:52 -07003623
Eric W. Biederman4b6b19a2010-03-30 01:07:08 -07003624 /* The register returns the maximum index redir index
3625 * supported, which is one less than the total number of redir
3626 * entries.
3627 */
3628 return reg_01.bits.entries + 1;
Yinghai Lu9d6a4d02008-08-19 20:50:52 -07003629}
3630
Thomas Gleixner23f9b262010-10-15 15:38:50 -07003631static void __init probe_nr_irqs_gsi(void)
Yinghai Lu9d6a4d02008-08-19 20:50:52 -07003632{
Eric W. Biederman4afc51a2010-03-30 01:07:14 -07003633 int nr;
Yinghai Lube5d5352008-12-05 18:58:33 -08003634
Eric W. Biedermana4384df2010-06-08 11:44:32 -07003635 nr = gsi_top + NR_IRQS_LEGACY;
Eric W. Biederman4afc51a2010-03-30 01:07:14 -07003636 if (nr > nr_irqs_gsi)
Yinghai Lube5d5352008-12-05 18:58:33 -08003637 nr_irqs_gsi = nr;
Yinghai Lucc6c5002009-02-08 16:18:03 -08003638
3639 printk(KERN_DEBUG "nr_irqs_gsi: %d\n", nr_irqs_gsi);
Yinghai Lu9d6a4d02008-08-19 20:50:52 -07003640}
3641
Jeremy Fitzhardinge7b586d72009-02-12 17:22:49 -08003642int get_nr_irqs_gsi(void)
3643{
3644 return nr_irqs_gsi;
3645}
3646
Yinghai Lu4a046d12009-01-12 17:39:24 -08003647#ifdef CONFIG_SPARSE_IRQ
3648int __init arch_probe_nr_irqs(void)
3649{
3650 int nr;
3651
Yinghai Luf1ee5542009-02-08 16:18:03 -08003652 if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
3653 nr_irqs = NR_VECTORS * nr_cpu_ids;
Yinghai Lu4a046d12009-01-12 17:39:24 -08003654
Yinghai Luf1ee5542009-02-08 16:18:03 -08003655 nr = nr_irqs_gsi + 8 * nr_cpu_ids;
3656#if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
3657 /*
3658 * for MSI and HT dyn irq
3659 */
3660 nr += nr_irqs_gsi * 16;
3661#endif
3662 if (nr < nr_irqs)
Yinghai Lu4a046d12009-01-12 17:39:24 -08003663 nr_irqs = nr;
3664
Thomas Gleixnerb683de22010-09-27 20:55:03 +02003665 return NR_IRQS_LEGACY;
Yinghai Lu4a046d12009-01-12 17:39:24 -08003666}
3667#endif
3668
Thomas Gleixner710dcda2011-02-23 17:47:41 +01003669int io_apic_set_pci_routing(struct device *dev, int irq,
3670 struct io_apic_irq_attr *irq_attr)
Yinghai Lu5ef21832009-05-06 10:08:50 -07003671{
Yinghai Lu5ef21832009-05-06 10:08:50 -07003672 int node;
3673
3674 if (!IO_APIC_IRQ(irq)) {
3675 apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
Thomas Gleixnere0799c02011-02-23 14:10:54 +01003676 irq_attr->ioapic);
Yinghai Lu5ef21832009-05-06 10:08:50 -07003677 return -EINVAL;
3678 }
3679
Thomas Gleixnere0799c02011-02-23 14:10:54 +01003680 node = dev ? dev_to_node(dev) : cpu_to_node(0);
Yinghai Lu5ef21832009-05-06 10:08:50 -07003681
Thomas Gleixner710dcda2011-02-23 17:47:41 +01003682 return io_apic_setup_irq_pin_once(irq, node, irq_attr);
Yinghai Lu5ef21832009-05-06 10:08:50 -07003683}
3684
Feng Tang2a4ab642009-07-07 23:01:15 -04003685#ifdef CONFIG_X86_32
Thomas Gleixner41098ff2011-02-23 16:08:03 +01003686static int __init io_apic_get_unique_id(int ioapic, int apic_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687{
3688 union IO_APIC_reg_00 reg_00;
3689 static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
3690 physid_mask_t tmp;
3691 unsigned long flags;
3692 int i = 0;
3693
3694 /*
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02003695 * The P4 platform supports up to 256 APIC IDs on two separate APIC
3696 * buses (one for LAPICs, one for IOAPICs), where predecessors only
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697 * supports up to 16 on one shared APIC bus.
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02003698 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003699 * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
3700 * advantage of new APIC bus architecture.
3701 */
3702
3703 if (physids_empty(apic_id_map))
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +03003704 apic->ioapic_phys_id_map(&phys_cpu_present_map, &apic_id_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003706 raw_spin_lock_irqsave(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 reg_00.raw = io_apic_read(ioapic, 0);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003708 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709
3710 if (apic_id >= get_physical_broadcast()) {
3711 printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
3712 "%d\n", ioapic, apic_id, reg_00.bits.ID);
3713 apic_id = reg_00.bits.ID;
3714 }
3715
3716 /*
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02003717 * Every APIC in a system must have a unique ID or we get lots of nice
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 * 'stuck on smp_invalidate_needed IPI wait' messages.
3719 */
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +03003720 if (apic->check_apicid_used(&apic_id_map, apic_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721
3722 for (i = 0; i < get_physical_broadcast(); i++) {
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +03003723 if (!apic->check_apicid_used(&apic_id_map, i))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 break;
3725 }
3726
3727 if (i == get_physical_broadcast())
3728 panic("Max apic_id exceeded!\n");
3729
3730 printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
3731 "trying %d\n", ioapic, apic_id, i);
3732
3733 apic_id = i;
Paolo Ciarrocchi36062442008-06-08 13:07:18 +02003734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003735
Cyrill Gorcunov7abc0752009-11-10 01:06:59 +03003736 apic->apicid_to_cpu_present(apic_id, &tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 physids_or(apic_id_map, apic_id_map, tmp);
3738
3739 if (reg_00.bits.ID != apic_id) {
3740 reg_00.bits.ID = apic_id;
3741
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003742 raw_spin_lock_irqsave(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 io_apic_write(ioapic, 0, reg_00.raw);
3744 reg_00.raw = io_apic_read(ioapic, 0);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003745 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746
3747 /* Sanity check */
Andreas Deresch6070f9e2006-02-26 04:18:34 +01003748 if (reg_00.bits.ID != apic_id) {
3749 printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
3750 return -1;
3751 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 }
3753
3754 apic_printk(APIC_VERBOSE, KERN_INFO
3755 "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
3756
3757 return apic_id;
3758}
Thomas Gleixner41098ff2011-02-23 16:08:03 +01003759
3760static u8 __init io_apic_unique_id(u8 id)
3761{
3762 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
3763 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
3764 return io_apic_get_unique_id(nr_ioapics, id);
3765 else
3766 return id;
3767}
3768#else
3769static u8 __init io_apic_unique_id(u8 id)
3770{
3771 int i;
3772 DECLARE_BITMAP(used, 256);
3773
3774 bitmap_zero(used, 256);
3775 for (i = 0; i < nr_ioapics; i++) {
Suresh Siddhad5371432011-05-18 16:31:37 -07003776 __set_bit(mpc_ioapic_id(i), used);
Thomas Gleixner41098ff2011-02-23 16:08:03 +01003777 }
3778 if (!test_bit(id, used))
3779 return id;
3780 return find_first_zero_bit(used, 256);
3781}
Naga Chumbalkar58f892e2009-05-26 21:48:07 +00003782#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783
Thomas Gleixner41098ff2011-02-23 16:08:03 +01003784static int __init io_apic_get_version(int ioapic)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785{
3786 union IO_APIC_reg_01 reg_01;
3787 unsigned long flags;
3788
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003789 raw_spin_lock_irqsave(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 reg_01.raw = io_apic_read(ioapic, 1);
Thomas Gleixnerdade7712009-07-25 18:39:36 +02003791 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792
3793 return reg_01.bits.version;
3794}
3795
Eric W. Biederman9a0a91b2010-03-30 01:07:03 -07003796int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity)
Shaohua Li61fd47e2007-11-17 01:05:28 -05003797{
Eric W. Biederman9a0a91b2010-03-30 01:07:03 -07003798 int ioapic, pin, idx;
Shaohua Li61fd47e2007-11-17 01:05:28 -05003799
3800 if (skip_ioapic_setup)
3801 return -1;
3802
Eric W. Biederman9a0a91b2010-03-30 01:07:03 -07003803 ioapic = mp_find_ioapic(gsi);
3804 if (ioapic < 0)
Shaohua Li61fd47e2007-11-17 01:05:28 -05003805 return -1;
3806
Eric W. Biederman9a0a91b2010-03-30 01:07:03 -07003807 pin = mp_find_ioapic_pin(ioapic, gsi);
3808 if (pin < 0)
3809 return -1;
3810
3811 idx = find_irq_entry(ioapic, pin, mp_INT);
3812 if (idx < 0)
3813 return -1;
3814
3815 *trigger = irq_trigger(idx);
3816 *polarity = irq_polarity(idx);
Shaohua Li61fd47e2007-11-17 01:05:28 -05003817 return 0;
3818}
3819
Yinghai Lu497c9a12008-08-19 20:50:28 -07003820/*
3821 * This function currently is only a helper for the i386 smp boot process where
3822 * we need to reprogram the ioredtbls to cater for the cpus which have come online
Ingo Molnarfe402e12009-01-28 04:32:51 +01003823 * so mask in all cases should simply be apic->target_cpus()
Yinghai Lu497c9a12008-08-19 20:50:28 -07003824 */
3825#ifdef CONFIG_SMP
3826void __init setup_ioapic_dest(void)
3827{
Eric W. Biedermanfad53992010-02-28 01:06:34 -08003828 int pin, ioapic, irq, irq_entry;
Mike Travis22f65d32008-12-16 17:33:56 -08003829 const struct cpumask *mask;
Thomas Gleixner5451ddc2011-02-05 15:35:51 +01003830 struct irq_data *idata;
Yinghai Lu497c9a12008-08-19 20:50:28 -07003831
3832 if (skip_ioapic_setup == 1)
3833 return;
3834
Eric W. Biedermanfad53992010-02-28 01:06:34 -08003835 for (ioapic = 0; ioapic < nr_ioapics; ioapic++)
Suresh Siddhab69c6c32011-05-18 16:31:35 -07003836 for (pin = 0; pin < ioapics[ioapic].nr_registers; pin++) {
Yinghai Lub9c61b702009-05-06 10:10:06 -07003837 irq_entry = find_irq_entry(ioapic, pin, mp_INT);
3838 if (irq_entry == -1)
3839 continue;
3840 irq = pin_2_irq(irq_entry, ioapic, pin);
3841
Eric W. Biedermanfad53992010-02-28 01:06:34 -08003842 if ((ioapic > 0) && (irq > 16))
3843 continue;
3844
Thomas Gleixner5451ddc2011-02-05 15:35:51 +01003845 idata = irq_get_irq_data(irq);
Yinghai Lub9c61b702009-05-06 10:10:06 -07003846
3847 /*
3848 * Honour affinities which have been set in early boot
3849 */
Thomas Gleixner5451ddc2011-02-05 15:35:51 +01003850 if (!irqd_can_balance(idata) || irqd_affinity_was_set(idata))
3851 mask = idata->affinity;
Yinghai Lub9c61b702009-05-06 10:10:06 -07003852 else
3853 mask = apic->target_cpus();
3854
3855 if (intr_remapping_enabled)
Thomas Gleixner5451ddc2011-02-05 15:35:51 +01003856 ir_ioapic_set_affinity(idata, mask, false);
Yinghai Lub9c61b702009-05-06 10:10:06 -07003857 else
Thomas Gleixner5451ddc2011-02-05 15:35:51 +01003858 ioapic_set_affinity(idata, mask, false);
Yinghai Lub9c61b702009-05-06 10:10:06 -07003859 }
3860
Yinghai Lu497c9a12008-08-19 20:50:28 -07003861}
3862#endif
3863
Ingo Molnar54168ed2008-08-20 09:07:45 +02003864#define IOAPIC_RESOURCE_NAME_SIZE 11
3865
3866static struct resource *ioapic_resources;
3867
Cyrill Gorcunovffc43832009-08-24 21:53:39 +04003868static struct resource * __init ioapic_setup_resources(int nr_ioapics)
Ingo Molnar54168ed2008-08-20 09:07:45 +02003869{
3870 unsigned long n;
3871 struct resource *res;
3872 char *mem;
3873 int i;
3874
3875 if (nr_ioapics <= 0)
3876 return NULL;
3877
3878 n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource);
3879 n *= nr_ioapics;
3880
3881 mem = alloc_bootmem(n);
3882 res = (void *)mem;
3883
Cyrill Gorcunovffc43832009-08-24 21:53:39 +04003884 mem += sizeof(struct resource) * nr_ioapics;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003885
Cyrill Gorcunovffc43832009-08-24 21:53:39 +04003886 for (i = 0; i < nr_ioapics; i++) {
3887 res[i].name = mem;
3888 res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY;
Cyrill Gorcunov4343fe12009-11-08 18:54:31 +03003889 snprintf(mem, IOAPIC_RESOURCE_NAME_SIZE, "IOAPIC %u", i);
Cyrill Gorcunovffc43832009-08-24 21:53:39 +04003890 mem += IOAPIC_RESOURCE_NAME_SIZE;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003891 }
3892
3893 ioapic_resources = res;
3894
3895 return res;
3896}
Ingo Molnar54168ed2008-08-20 09:07:45 +02003897
Thomas Gleixner23f9b262010-10-15 15:38:50 -07003898void __init ioapic_and_gsi_init(void)
Yinghai Luf3294a32008-06-27 01:41:56 -07003899{
3900 unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003901 struct resource *ioapic_res;
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02003902 int i;
Yinghai Luf3294a32008-06-27 01:41:56 -07003903
Cyrill Gorcunovffc43832009-08-24 21:53:39 +04003904 ioapic_res = ioapic_setup_resources(nr_ioapics);
Yinghai Luf3294a32008-06-27 01:41:56 -07003905 for (i = 0; i < nr_ioapics; i++) {
3906 if (smp_found_config) {
Suresh Siddhad5371432011-05-18 16:31:37 -07003907 ioapic_phys = mpc_ioapic_addr(i);
Ingo Molnar54168ed2008-08-20 09:07:45 +02003908#ifdef CONFIG_X86_32
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +02003909 if (!ioapic_phys) {
3910 printk(KERN_ERR
3911 "WARNING: bogus zero IO-APIC "
3912 "address found in MPTABLE, "
3913 "disabling IO/APIC support!\n");
3914 smp_found_config = 0;
3915 skip_ioapic_setup = 1;
3916 goto fake_ioapic_page;
3917 }
Ingo Molnar54168ed2008-08-20 09:07:45 +02003918#endif
Yinghai Luf3294a32008-06-27 01:41:56 -07003919 } else {
Ingo Molnar54168ed2008-08-20 09:07:45 +02003920#ifdef CONFIG_X86_32
Yinghai Luf3294a32008-06-27 01:41:56 -07003921fake_ioapic_page:
Ingo Molnar54168ed2008-08-20 09:07:45 +02003922#endif
Cyrill Gorcunove79c65a2009-11-16 18:14:26 +03003923 ioapic_phys = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
Yinghai Luf3294a32008-06-27 01:41:56 -07003924 ioapic_phys = __pa(ioapic_phys);
3925 }
3926 set_fixmap_nocache(idx, ioapic_phys);
Cyrill Gorcunove79c65a2009-11-16 18:14:26 +03003927 apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n",
3928 __fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK),
3929 ioapic_phys);
Yinghai Luf3294a32008-06-27 01:41:56 -07003930 idx++;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003931
Cyrill Gorcunovffc43832009-08-24 21:53:39 +04003932 ioapic_res->start = ioapic_phys;
Cyrill Gorcunove79c65a2009-11-16 18:14:26 +03003933 ioapic_res->end = ioapic_phys + IO_APIC_SLOT_SIZE - 1;
Cyrill Gorcunovffc43832009-08-24 21:53:39 +04003934 ioapic_res++;
Yinghai Luf3294a32008-06-27 01:41:56 -07003935 }
Thomas Gleixner23f9b262010-10-15 15:38:50 -07003936
3937 probe_nr_irqs_gsi();
Yinghai Luf3294a32008-06-27 01:41:56 -07003938}
3939
Yinghai Lu857fdc52009-07-10 09:36:20 -07003940void __init ioapic_insert_resources(void)
Ingo Molnar54168ed2008-08-20 09:07:45 +02003941{
3942 int i;
3943 struct resource *r = ioapic_resources;
3944
3945 if (!r) {
Yinghai Lu857fdc52009-07-10 09:36:20 -07003946 if (nr_ioapics > 0)
Bartlomiej Zolnierkiewicz04c93ce2009-03-20 21:02:55 +01003947 printk(KERN_ERR
3948 "IO APIC resources couldn't be allocated.\n");
Yinghai Lu857fdc52009-07-10 09:36:20 -07003949 return;
Ingo Molnar54168ed2008-08-20 09:07:45 +02003950 }
3951
3952 for (i = 0; i < nr_ioapics; i++) {
3953 insert_resource(&iomem_resource, r);
3954 r++;
3955 }
Ingo Molnar54168ed2008-08-20 09:07:45 +02003956}
Ingo Molnar54168ed2008-08-20 09:07:45 +02003957
Eric W. Biedermaneddb0c52010-03-30 01:07:09 -07003958int mp_find_ioapic(u32 gsi)
Feng Tang2a4ab642009-07-07 23:01:15 -04003959{
3960 int i = 0;
3961
Paul Bolle678301e2011-02-14 22:52:38 +01003962 if (nr_ioapics == 0)
3963 return -1;
3964
Feng Tang2a4ab642009-07-07 23:01:15 -04003965 /* Find the IOAPIC that manages this GSI. */
3966 for (i = 0; i < nr_ioapics; i++) {
Suresh Siddhac040aae2011-05-18 16:31:38 -07003967 struct mp_ioapic_gsi *gsi_cfg = mp_ioapic_gsi_routing(i);
3968 if ((gsi >= gsi_cfg->gsi_base)
3969 && (gsi <= gsi_cfg->gsi_end))
Feng Tang2a4ab642009-07-07 23:01:15 -04003970 return i;
3971 }
3972
3973 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
3974 return -1;
3975}
3976
Eric W. Biedermaneddb0c52010-03-30 01:07:09 -07003977int mp_find_ioapic_pin(int ioapic, u32 gsi)
Feng Tang2a4ab642009-07-07 23:01:15 -04003978{
Suresh Siddhac040aae2011-05-18 16:31:38 -07003979 struct mp_ioapic_gsi *gsi_cfg;
3980
Feng Tang2a4ab642009-07-07 23:01:15 -04003981 if (WARN_ON(ioapic == -1))
3982 return -1;
Suresh Siddhac040aae2011-05-18 16:31:38 -07003983
3984 gsi_cfg = mp_ioapic_gsi_routing(ioapic);
3985 if (WARN_ON(gsi > gsi_cfg->gsi_end))
Feng Tang2a4ab642009-07-07 23:01:15 -04003986 return -1;
3987
Suresh Siddhac040aae2011-05-18 16:31:38 -07003988 return gsi - gsi_cfg->gsi_base;
Feng Tang2a4ab642009-07-07 23:01:15 -04003989}
3990
Thomas Gleixner41098ff2011-02-23 16:08:03 +01003991static __init int bad_ioapic(unsigned long address)
Feng Tang2a4ab642009-07-07 23:01:15 -04003992{
3993 if (nr_ioapics >= MAX_IO_APICS) {
Paul Bolle45e8234c2011-02-08 23:27:36 +01003994 printk(KERN_WARNING "WARNING: Max # of I/O APICs (%d) exceeded "
Feng Tang2a4ab642009-07-07 23:01:15 -04003995 "(found %d), skipping\n", MAX_IO_APICS, nr_ioapics);
3996 return 1;
3997 }
3998 if (!address) {
3999 printk(KERN_WARNING "WARNING: Bogus (zero) I/O APIC address"
4000 " found in table, skipping!\n");
4001 return 1;
4002 }
Ingo Molnar54168ed2008-08-20 09:07:45 +02004003 return 0;
4004}
4005
Feng Tang2a4ab642009-07-07 23:01:15 -04004006void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
4007{
4008 int idx = 0;
Eric W. Biederman7716a5c2010-03-30 01:07:12 -07004009 int entries;
Suresh Siddhac040aae2011-05-18 16:31:38 -07004010 struct mp_ioapic_gsi *gsi_cfg;
Feng Tang2a4ab642009-07-07 23:01:15 -04004011
4012 if (bad_ioapic(address))
4013 return;
4014
4015 idx = nr_ioapics;
4016
Suresh Siddhad5371432011-05-18 16:31:37 -07004017 ioapics[idx].mp_config.type = MP_IOAPIC;
4018 ioapics[idx].mp_config.flags = MPC_APIC_USABLE;
4019 ioapics[idx].mp_config.apicaddr = address;
Feng Tang2a4ab642009-07-07 23:01:15 -04004020
4021 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
Suresh Siddhad5371432011-05-18 16:31:37 -07004022 ioapics[idx].mp_config.apicid = io_apic_unique_id(id);
4023 ioapics[idx].mp_config.apicver = io_apic_get_version(idx);
Feng Tang2a4ab642009-07-07 23:01:15 -04004024
4025 /*
4026 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
4027 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
4028 */
Eric W. Biederman7716a5c2010-03-30 01:07:12 -07004029 entries = io_apic_get_redir_entries(idx);
Suresh Siddhac040aae2011-05-18 16:31:38 -07004030 gsi_cfg = mp_ioapic_gsi_routing(idx);
4031 gsi_cfg->gsi_base = gsi_base;
4032 gsi_cfg->gsi_end = gsi_base + entries - 1;
Eric W. Biederman7716a5c2010-03-30 01:07:12 -07004033
4034 /*
4035 * The number of IO-APIC IRQ registers (== #pins):
4036 */
Suresh Siddhab69c6c32011-05-18 16:31:35 -07004037 ioapics[idx].nr_registers = entries;
Feng Tang2a4ab642009-07-07 23:01:15 -04004038
Suresh Siddhac040aae2011-05-18 16:31:38 -07004039 if (gsi_cfg->gsi_end >= gsi_top)
4040 gsi_top = gsi_cfg->gsi_end + 1;
Feng Tang2a4ab642009-07-07 23:01:15 -04004041
4042 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
Suresh Siddhad5371432011-05-18 16:31:37 -07004043 "GSI %d-%d\n", idx, mpc_ioapic_id(idx),
4044 mpc_ioapic_ver(idx), mpc_ioapic_addr(idx),
Suresh Siddhac040aae2011-05-18 16:31:38 -07004045 gsi_cfg->gsi_base, gsi_cfg->gsi_end);
Feng Tang2a4ab642009-07-07 23:01:15 -04004046
4047 nr_ioapics++;
4048}
Jacob Pan05ddafb2009-09-23 07:20:23 -07004049
4050/* Enable IOAPIC early just for system timer */
4051void __init pre_init_apic_IRQ0(void)
4052{
Thomas Gleixnerf880ec72011-02-23 13:07:54 +01004053 struct io_apic_irq_attr attr = { 0, 0, 0, 0 };
Jacob Pan05ddafb2009-09-23 07:20:23 -07004054
4055 printk(KERN_INFO "Early APIC setup for system timer0\n");
4056#ifndef CONFIG_SMP
Yinghai Lucb2ded32011-01-04 16:38:52 -08004057 physid_set_mask_of_physid(boot_cpu_physical_apicid,
4058 &phys_cpu_present_map);
Jacob Pan05ddafb2009-09-23 07:20:23 -07004059#endif
Jacob Pan05ddafb2009-09-23 07:20:23 -07004060 setup_local_APIC();
4061
Thomas Gleixnerf880ec72011-02-23 13:07:54 +01004062 io_apic_setup_irq_pin(0, 0, &attr);
Thomas Gleixner2c778652011-03-12 12:20:43 +01004063 irq_set_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq,
4064 "edge");
Jacob Pan05ddafb2009-09-23 07:20:23 -07004065}