2 * Intel IO-APIC support for multi-Pentium hosts.
4 * Copyright (C) 1997, 1998, 1999, 2000, 2009 Ingo Molnar, Hajnalka Szabo
6 * Many thanks to Stig Venaas for trying out countless experimental
7 * patches and reporting/debugging problems patiently!
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>
16 * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
17 * thanks to Eric Gilmore
19 * for testing these extensively
20 * Paul Diefenbaugh : Added full ACPI support
24 #include <linux/interrupt.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/sched.h>
28 #include <linux/pci.h>
29 #include <linux/mc146818rtc.h>
30 #include <linux/compiler.h>
31 #include <linux/acpi.h>
32 #include <linux/module.h>
33 #include <linux/sysdev.h>
34 #include <linux/msi.h>
35 #include <linux/htirq.h>
36 #include <linux/freezer.h>
37 #include <linux/kthread.h>
38 #include <linux/jiffies.h> /* time_after() */
40 #include <acpi/acpi_bus.h>
42 #include <linux/bootmem.h>
43 #include <linux/dmar.h>
44 #include <linux/hpet.h>
46 #include <linux/kdb.h>
54 #include <asm/proto.h>
57 #include <asm/timer.h>
58 #include <asm/i8259.h>
60 #include <asm/msidef.h>
61 #include <asm/hypertransport.h>
62 #include <asm/setup.h>
63 #include <asm/irq_remapping.h>
65 #include <asm/hw_irq.h>
69 #define __apicdebuginit(type) static type __init
70 #define for_each_irq_pin(entry, head) \
71 for (entry = head; entry; entry = entry->next)
74 * Is the SiS APIC rmw bug present ?
75 * -1 = don't know, 0 = no, 1 = yes
77 int sis_apic_bug = -1;
79 static DEFINE_SPINLOCK(ioapic_lock);
80 static DEFINE_SPINLOCK(vector_lock);
83 * # of IRQ routing registers
85 int nr_ioapic_registers[MAX_IO_APICS];
87 /* I/O APIC entries */
88 struct mpc_ioapic mp_ioapics[MAX_IO_APICS];
91 /* IO APIC gsi routing info */
92 struct mp_ioapic_gsi mp_gsi_routing[MAX_IO_APICS];
94 /* MP IRQ source entries */
95 struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES];
97 /* # of MP IRQ source entries */
100 /* Number of legacy interrupts */
101 static int nr_legacy_irqs __read_mostly = NR_IRQS_LEGACY;
103 static int nr_irqs_gsi = NR_IRQS_LEGACY;
105 #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
106 int mp_bus_id_to_type[MAX_MP_BUSSES];
109 DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
111 int skip_ioapic_setup;
113 void arch_disable_smp_support(void)
117 noioapicreroute = -1;
119 skip_ioapic_setup = 1;
122 static int __init parse_noapic(char *str)
124 /* disable IO-APIC */
125 arch_disable_smp_support();
128 early_param("noapic", parse_noapic);
130 struct irq_pin_list {
132 struct irq_pin_list *next;
135 static struct irq_pin_list *get_one_free_irq_2_pin(int node)
137 struct irq_pin_list *pin;
139 pin = kzalloc_node(sizeof(*pin), GFP_ATOMIC, node);
144 /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
145 #ifdef CONFIG_SPARSE_IRQ
146 static struct irq_cfg irq_cfgx[] = {
148 static struct irq_cfg irq_cfgx[NR_IRQS] = {
150 [0] = { .vector = IRQ0_VECTOR, },
151 [1] = { .vector = IRQ1_VECTOR, },
152 [2] = { .vector = IRQ2_VECTOR, },
153 [3] = { .vector = IRQ3_VECTOR, },
154 [4] = { .vector = IRQ4_VECTOR, },
155 [5] = { .vector = IRQ5_VECTOR, },
156 [6] = { .vector = IRQ6_VECTOR, },
157 [7] = { .vector = IRQ7_VECTOR, },
158 [8] = { .vector = IRQ8_VECTOR, },
159 [9] = { .vector = IRQ9_VECTOR, },
160 [10] = { .vector = IRQ10_VECTOR, },
161 [11] = { .vector = IRQ11_VECTOR, },
162 [12] = { .vector = IRQ12_VECTOR, },
163 [13] = { .vector = IRQ13_VECTOR, },
164 [14] = { .vector = IRQ14_VECTOR, },
165 [15] = { .vector = IRQ15_VECTOR, },
168 void __init io_apic_disable_legacy(void)
174 int __init arch_early_irq_init(void)
177 struct irq_desc *desc;
183 count = ARRAY_SIZE(irq_cfgx);
184 node= cpu_to_node(boot_cpu_id);
186 for (i = 0; i < count; i++) {
187 desc = irq_to_desc(i);
188 desc->chip_data = &cfg[i];
189 zalloc_cpumask_var_node(&cfg[i].domain, GFP_NOWAIT, node);
190 zalloc_cpumask_var_node(&cfg[i].old_domain, GFP_NOWAIT, node);
191 if (i < nr_legacy_irqs)
192 cpumask_setall(cfg[i].domain);
198 #ifdef CONFIG_SPARSE_IRQ
199 struct irq_cfg *irq_cfg(unsigned int irq)
201 struct irq_cfg *cfg = NULL;
202 struct irq_desc *desc;
204 desc = irq_to_desc(irq);
206 cfg = desc->chip_data;
211 static struct irq_cfg *get_one_free_irq_cfg(int node)
215 cfg = kzalloc_node(sizeof(*cfg), GFP_ATOMIC, node);
217 if (!zalloc_cpumask_var_node(&cfg->domain, GFP_ATOMIC, node)) {
220 } else if (!zalloc_cpumask_var_node(&cfg->old_domain,
222 free_cpumask_var(cfg->domain);
231 int arch_init_chip_data(struct irq_desc *desc, int node)
235 cfg = desc->chip_data;
237 desc->chip_data = get_one_free_irq_cfg(node);
238 if (!desc->chip_data) {
239 printk(KERN_ERR "can not alloc irq_cfg\n");
247 /* for move_irq_desc */
249 init_copy_irq_2_pin(struct irq_cfg *old_cfg, struct irq_cfg *cfg, int node)
251 struct irq_pin_list *old_entry, *head, *tail, *entry;
253 cfg->irq_2_pin = NULL;
254 old_entry = old_cfg->irq_2_pin;
258 entry = get_one_free_irq_2_pin(node);
262 entry->apic = old_entry->apic;
263 entry->pin = old_entry->pin;
266 old_entry = old_entry->next;
268 entry = get_one_free_irq_2_pin(node);
276 /* still use the old one */
279 entry->apic = old_entry->apic;
280 entry->pin = old_entry->pin;
283 old_entry = old_entry->next;
287 cfg->irq_2_pin = head;
290 static void free_irq_2_pin(struct irq_cfg *old_cfg, struct irq_cfg *cfg)
292 struct irq_pin_list *entry, *next;
294 if (old_cfg->irq_2_pin == cfg->irq_2_pin)
297 entry = old_cfg->irq_2_pin;
304 old_cfg->irq_2_pin = NULL;
307 void arch_init_copy_chip_data(struct irq_desc *old_desc,
308 struct irq_desc *desc, int node)
311 struct irq_cfg *old_cfg;
313 cfg = get_one_free_irq_cfg(node);
318 desc->chip_data = cfg;
320 old_cfg = old_desc->chip_data;
322 memcpy(cfg, old_cfg, sizeof(struct irq_cfg));
324 init_copy_irq_2_pin(old_cfg, cfg, node);
327 static void free_irq_cfg(struct irq_cfg *old_cfg)
332 void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc)
334 struct irq_cfg *old_cfg, *cfg;
336 old_cfg = old_desc->chip_data;
337 cfg = desc->chip_data;
343 free_irq_2_pin(old_cfg, cfg);
344 free_irq_cfg(old_cfg);
345 old_desc->chip_data = NULL;
348 /* end for move_irq_desc */
351 struct irq_cfg *irq_cfg(unsigned int irq)
353 return irq < nr_irqs ? irq_cfgx + irq : NULL;
360 unsigned int unused[3];
362 unsigned int unused2[11];
366 static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
368 return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
369 + (mp_ioapics[idx].apicaddr & ~PAGE_MASK);
372 static inline void io_apic_eoi(unsigned int apic, unsigned int vector)
374 struct io_apic __iomem *io_apic = io_apic_base(apic);
375 writel(vector, &io_apic->eoi);
378 static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
380 struct io_apic __iomem *io_apic = io_apic_base(apic);
381 writel(reg, &io_apic->index);
382 return readl(&io_apic->data);
385 static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value)
387 struct io_apic __iomem *io_apic = io_apic_base(apic);
388 writel(reg, &io_apic->index);
389 writel(value, &io_apic->data);
393 * Re-write a value: to be used for read-modify-write
394 * cycles where the read already set up the index register.
396 * Older SiS APIC requires we rewrite the index register
398 static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
400 struct io_apic __iomem *io_apic = io_apic_base(apic);
403 writel(reg, &io_apic->index);
404 writel(value, &io_apic->data);
407 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
409 struct irq_pin_list *entry;
412 spin_lock_irqsave(&ioapic_lock, flags);
413 for_each_irq_pin(entry, cfg->irq_2_pin) {
418 reg = io_apic_read(entry->apic, 0x10 + pin*2);
419 /* Is the remote IRR bit set? */
420 if (reg & IO_APIC_REDIR_REMOTE_IRR) {
421 spin_unlock_irqrestore(&ioapic_lock, flags);
425 spin_unlock_irqrestore(&ioapic_lock, flags);
431 struct { u32 w1, w2; };
432 struct IO_APIC_route_entry entry;
435 static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
437 union entry_union eu;
439 spin_lock_irqsave(&ioapic_lock, flags);
440 eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
441 eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
442 spin_unlock_irqrestore(&ioapic_lock, flags);
447 * When we write a new IO APIC routing entry, we need to write the high
448 * word first! If the mask bit in the low word is clear, we will enable
449 * the interrupt, and we need to make sure the entry is fully populated
450 * before that happens.
453 __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
455 union entry_union eu = {{0, 0}};
458 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
459 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
462 void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
465 spin_lock_irqsave(&ioapic_lock, flags);
466 __ioapic_write_entry(apic, pin, e);
467 spin_unlock_irqrestore(&ioapic_lock, flags);
471 * When we mask an IO APIC routing entry, we need to write the low
472 * word first, in order to set the mask bit before we change the
475 static void ioapic_mask_entry(int apic, int pin)
478 union entry_union eu = { .entry.mask = 1 };
480 spin_lock_irqsave(&ioapic_lock, flags);
481 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
482 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
483 spin_unlock_irqrestore(&ioapic_lock, flags);
487 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
488 * shared ISA-space IRQs, so we have to support them. We are super
489 * fast in the common case, and fast for shared ISA-space IRQs.
492 add_pin_to_irq_node_nopanic(struct irq_cfg *cfg, int node, int apic, int pin)
494 struct irq_pin_list **last, *entry;
496 /* don't allow duplicates */
497 last = &cfg->irq_2_pin;
498 for_each_irq_pin(entry, cfg->irq_2_pin) {
499 if (entry->apic == apic && entry->pin == pin)
504 entry = get_one_free_irq_2_pin(node);
506 printk(KERN_ERR "can not alloc irq_pin_list (%d,%d,%d)\n",
517 static void add_pin_to_irq_node(struct irq_cfg *cfg, int node, int apic, int pin)
519 if (add_pin_to_irq_node_nopanic(cfg, node, apic, pin))
520 panic("IO-APIC: failed to add irq-pin. Can not proceed\n");
524 * Reroute an IRQ to a different pin.
526 static void __init replace_pin_at_irq_node(struct irq_cfg *cfg, int node,
527 int oldapic, int oldpin,
528 int newapic, int newpin)
530 struct irq_pin_list *entry;
532 for_each_irq_pin(entry, cfg->irq_2_pin) {
533 if (entry->apic == oldapic && entry->pin == oldpin) {
534 entry->apic = newapic;
536 /* every one is different, right? */
541 /* old apic/pin didn't exist, so just add new ones */
542 add_pin_to_irq_node(cfg, node, newapic, newpin);
545 static void __io_apic_modify_irq(struct irq_pin_list *entry,
546 int mask_and, int mask_or,
547 void (*final)(struct irq_pin_list *entry))
549 unsigned int reg, pin;
552 reg = io_apic_read(entry->apic, 0x10 + pin * 2);
555 io_apic_modify(entry->apic, 0x10 + pin * 2, reg);
560 static void io_apic_modify_irq(struct irq_cfg *cfg,
561 int mask_and, int mask_or,
562 void (*final)(struct irq_pin_list *entry))
564 struct irq_pin_list *entry;
566 for_each_irq_pin(entry, cfg->irq_2_pin)
567 __io_apic_modify_irq(entry, mask_and, mask_or, final);
570 static void __mask_and_edge_IO_APIC_irq(struct irq_pin_list *entry)
572 __io_apic_modify_irq(entry, ~IO_APIC_REDIR_LEVEL_TRIGGER,
573 IO_APIC_REDIR_MASKED, NULL);
576 static void __unmask_and_level_IO_APIC_irq(struct irq_pin_list *entry)
578 __io_apic_modify_irq(entry, ~IO_APIC_REDIR_MASKED,
579 IO_APIC_REDIR_LEVEL_TRIGGER, NULL);
582 static void __unmask_IO_APIC_irq(struct irq_cfg *cfg)
584 io_apic_modify_irq(cfg, ~IO_APIC_REDIR_MASKED, 0, NULL);
587 static void io_apic_sync(struct irq_pin_list *entry)
590 * Synchronize the IO-APIC and the CPU by doing
591 * a dummy read from the IO-APIC
593 struct io_apic __iomem *io_apic;
594 io_apic = io_apic_base(entry->apic);
595 readl(&io_apic->data);
598 static void __mask_IO_APIC_irq(struct irq_cfg *cfg)
600 io_apic_modify_irq(cfg, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync);
603 static void mask_IO_APIC_irq_desc(struct irq_desc *desc)
605 struct irq_cfg *cfg = desc->chip_data;
610 spin_lock_irqsave(&ioapic_lock, flags);
611 __mask_IO_APIC_irq(cfg);
612 spin_unlock_irqrestore(&ioapic_lock, flags);
615 static void unmask_IO_APIC_irq_desc(struct irq_desc *desc)
617 struct irq_cfg *cfg = desc->chip_data;
620 spin_lock_irqsave(&ioapic_lock, flags);
621 __unmask_IO_APIC_irq(cfg);
622 spin_unlock_irqrestore(&ioapic_lock, flags);
625 static void mask_IO_APIC_irq(unsigned int irq)
627 struct irq_desc *desc = irq_to_desc(irq);
629 mask_IO_APIC_irq_desc(desc);
631 static void unmask_IO_APIC_irq(unsigned int irq)
633 struct irq_desc *desc = irq_to_desc(irq);
635 unmask_IO_APIC_irq_desc(desc);
638 static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
640 struct IO_APIC_route_entry entry;
642 /* Check delivery_mode to be sure we're not clearing an SMI pin */
643 entry = ioapic_read_entry(apic, pin);
644 if (entry.delivery_mode == dest_SMI)
647 * Disable it in the IO-APIC irq-routing table:
649 ioapic_mask_entry(apic, pin);
652 static void clear_IO_APIC (void)
656 for (apic = 0; apic < nr_ioapics; apic++)
657 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
658 clear_IO_APIC_pin(apic, pin);
663 * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
664 * specific CPU-side IRQs.
668 static int pirq_entries[MAX_PIRQS] = {
669 [0 ... MAX_PIRQS - 1] = -1
672 static int __init ioapic_pirq_setup(char *str)
675 int ints[MAX_PIRQS+1];
677 get_options(str, ARRAY_SIZE(ints), ints);
679 apic_printk(APIC_VERBOSE, KERN_INFO
680 "PIRQ redirection, working around broken MP-BIOS.\n");
682 if (ints[0] < MAX_PIRQS)
685 for (i = 0; i < max; i++) {
686 apic_printk(APIC_VERBOSE, KERN_DEBUG
687 "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
689 * PIRQs are mapped upside down, usually.
691 pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
696 __setup("pirq=", ioapic_pirq_setup);
697 #endif /* CONFIG_X86_32 */
699 struct IO_APIC_route_entry **alloc_ioapic_entries(void)
702 struct IO_APIC_route_entry **ioapic_entries;
704 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
709 for (apic = 0; apic < nr_ioapics; apic++) {
710 ioapic_entries[apic] =
711 kzalloc(sizeof(struct IO_APIC_route_entry) *
712 nr_ioapic_registers[apic], GFP_ATOMIC);
713 if (!ioapic_entries[apic])
717 return ioapic_entries;
721 kfree(ioapic_entries[apic]);
722 kfree(ioapic_entries);
728 * Saves all the IO-APIC RTE's
730 int save_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
737 for (apic = 0; apic < nr_ioapics; apic++) {
738 if (!ioapic_entries[apic])
741 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
742 ioapic_entries[apic][pin] =
743 ioapic_read_entry(apic, pin);
750 * Mask all IO APIC entries.
752 void mask_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
759 for (apic = 0; apic < nr_ioapics; apic++) {
760 if (!ioapic_entries[apic])
763 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
764 struct IO_APIC_route_entry entry;
766 entry = ioapic_entries[apic][pin];
769 ioapic_write_entry(apic, pin, entry);
776 * Restore IO APIC entries which was saved in ioapic_entries.
778 int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
785 for (apic = 0; apic < nr_ioapics; apic++) {
786 if (!ioapic_entries[apic])
789 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
790 ioapic_write_entry(apic, pin,
791 ioapic_entries[apic][pin]);
796 void free_ioapic_entries(struct IO_APIC_route_entry **ioapic_entries)
800 for (apic = 0; apic < nr_ioapics; apic++)
801 kfree(ioapic_entries[apic]);
803 kfree(ioapic_entries);
807 * Find the IRQ entry number of a certain pin.
809 static int find_irq_entry(int apic, int pin, int type)
813 for (i = 0; i < mp_irq_entries; i++)
814 if (mp_irqs[i].irqtype == type &&
815 (mp_irqs[i].dstapic == mp_ioapics[apic].apicid ||
816 mp_irqs[i].dstapic == MP_APIC_ALL) &&
817 mp_irqs[i].dstirq == pin)
824 * Find the pin to which IRQ[irq] (ISA) is connected
826 static int __init find_isa_irq_pin(int irq, int type)
830 for (i = 0; i < mp_irq_entries; i++) {
831 int lbus = mp_irqs[i].srcbus;
833 if (test_bit(lbus, mp_bus_not_pci) &&
834 (mp_irqs[i].irqtype == type) &&
835 (mp_irqs[i].srcbusirq == irq))
837 return mp_irqs[i].dstirq;
842 static int __init find_isa_irq_apic(int irq, int type)
846 for (i = 0; i < mp_irq_entries; i++) {
847 int lbus = mp_irqs[i].srcbus;
849 if (test_bit(lbus, mp_bus_not_pci) &&
850 (mp_irqs[i].irqtype == type) &&
851 (mp_irqs[i].srcbusirq == irq))
854 if (i < mp_irq_entries) {
856 for(apic = 0; apic < nr_ioapics; apic++) {
857 if (mp_ioapics[apic].apicid == mp_irqs[i].dstapic)
865 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
867 * EISA Edge/Level control register, ELCR
869 static int EISA_ELCR(unsigned int irq)
871 if (irq < nr_legacy_irqs) {
872 unsigned int port = 0x4d0 + (irq >> 3);
873 return (inb(port) >> (irq & 7)) & 1;
875 apic_printk(APIC_VERBOSE, KERN_INFO
876 "Broken MPtable reports ISA irq %d\n", irq);
882 /* ISA interrupts are always polarity zero edge triggered,
883 * when listed as conforming in the MP table. */
885 #define default_ISA_trigger(idx) (0)
886 #define default_ISA_polarity(idx) (0)
888 /* EISA interrupts are always polarity zero and can be edge or level
889 * trigger depending on the ELCR value. If an interrupt is listed as
890 * EISA conforming in the MP table, that means its trigger type must
891 * be read in from the ELCR */
893 #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].srcbusirq))
894 #define default_EISA_polarity(idx) default_ISA_polarity(idx)
896 /* PCI interrupts are always polarity one level triggered,
897 * when listed as conforming in the MP table. */
899 #define default_PCI_trigger(idx) (1)
900 #define default_PCI_polarity(idx) (1)
902 /* MCA interrupts are always polarity zero level triggered,
903 * when listed as conforming in the MP table. */
905 #define default_MCA_trigger(idx) (1)
906 #define default_MCA_polarity(idx) default_ISA_polarity(idx)
908 static int MPBIOS_polarity(int idx)
910 int bus = mp_irqs[idx].srcbus;
914 * Determine IRQ line polarity (high active or low active):
916 switch (mp_irqs[idx].irqflag & 3)
918 case 0: /* conforms, ie. bus-type dependent polarity */
919 if (test_bit(bus, mp_bus_not_pci))
920 polarity = default_ISA_polarity(idx);
922 polarity = default_PCI_polarity(idx);
924 case 1: /* high active */
929 case 2: /* reserved */
931 printk(KERN_WARNING "broken BIOS!!\n");
935 case 3: /* low active */
940 default: /* invalid */
942 printk(KERN_WARNING "broken BIOS!!\n");
950 static int MPBIOS_trigger(int idx)
952 int bus = mp_irqs[idx].srcbus;
956 * Determine IRQ trigger mode (edge or level sensitive):
958 switch ((mp_irqs[idx].irqflag>>2) & 3)
960 case 0: /* conforms, ie. bus-type dependent */
961 if (test_bit(bus, mp_bus_not_pci))
962 trigger = default_ISA_trigger(idx);
964 trigger = default_PCI_trigger(idx);
965 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
966 switch (mp_bus_id_to_type[bus]) {
967 case MP_BUS_ISA: /* ISA pin */
969 /* set before the switch */
972 case MP_BUS_EISA: /* EISA pin */
974 trigger = default_EISA_trigger(idx);
977 case MP_BUS_PCI: /* PCI pin */
979 /* set before the switch */
982 case MP_BUS_MCA: /* MCA pin */
984 trigger = default_MCA_trigger(idx);
989 printk(KERN_WARNING "broken BIOS!!\n");
1001 case 2: /* reserved */
1003 printk(KERN_WARNING "broken BIOS!!\n");
1012 default: /* invalid */
1014 printk(KERN_WARNING "broken BIOS!!\n");
1022 static inline int irq_polarity(int idx)
1024 return MPBIOS_polarity(idx);
1027 static inline int irq_trigger(int idx)
1029 return MPBIOS_trigger(idx);
1032 int (*ioapic_renumber_irq)(int ioapic, int irq);
1033 static int pin_2_irq(int idx, int apic, int pin)
1036 int bus = mp_irqs[idx].srcbus;
1039 * Debugging check, we are in big trouble if this message pops up!
1041 if (mp_irqs[idx].dstirq != pin)
1042 printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
1044 if (test_bit(bus, mp_bus_not_pci)) {
1045 irq = mp_irqs[idx].srcbusirq;
1048 * PCI IRQs are mapped in order
1052 irq += nr_ioapic_registers[i++];
1055 * For MPS mode, so far only needed by ES7000 platform
1057 if (ioapic_renumber_irq)
1058 irq = ioapic_renumber_irq(apic, irq);
1061 #ifdef CONFIG_X86_32
1063 * PCI IRQ command line redirection. Yes, limits are hardcoded.
1065 if ((pin >= 16) && (pin <= 23)) {
1066 if (pirq_entries[pin-16] != -1) {
1067 if (!pirq_entries[pin-16]) {
1068 apic_printk(APIC_VERBOSE, KERN_DEBUG
1069 "disabling PIRQ%d\n", pin-16);
1071 irq = pirq_entries[pin-16];
1072 apic_printk(APIC_VERBOSE, KERN_DEBUG
1073 "using PIRQ%d -> IRQ %d\n",
1084 * Find a specific PCI IRQ entry.
1085 * Not an __init, possibly needed by modules
1087 int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
1088 struct io_apic_irq_attr *irq_attr)
1090 int apic, i, best_guess = -1;
1092 apic_printk(APIC_DEBUG,
1093 "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
1095 if (test_bit(bus, mp_bus_not_pci)) {
1096 apic_printk(APIC_VERBOSE,
1097 "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
1100 for (i = 0; i < mp_irq_entries; i++) {
1101 int lbus = mp_irqs[i].srcbus;
1103 for (apic = 0; apic < nr_ioapics; apic++)
1104 if (mp_ioapics[apic].apicid == mp_irqs[i].dstapic ||
1105 mp_irqs[i].dstapic == MP_APIC_ALL)
1108 if (!test_bit(lbus, mp_bus_not_pci) &&
1109 !mp_irqs[i].irqtype &&
1111 (slot == ((mp_irqs[i].srcbusirq >> 2) & 0x1f))) {
1112 int irq = pin_2_irq(i, apic, mp_irqs[i].dstirq);
1114 if (!(apic || IO_APIC_IRQ(irq)))
1117 if (pin == (mp_irqs[i].srcbusirq & 3)) {
1118 set_io_apic_irq_attr(irq_attr, apic,
1125 * Use the first all-but-pin matching entry as a
1126 * best-guess fuzzy result for broken mptables.
1128 if (best_guess < 0) {
1129 set_io_apic_irq_attr(irq_attr, apic,
1139 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
1141 void lock_vector_lock(void)
1143 /* Used to the online set of cpus does not change
1144 * during assign_irq_vector.
1146 spin_lock(&vector_lock);
1149 void unlock_vector_lock(void)
1151 spin_unlock(&vector_lock);
1155 __assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
1158 * NOTE! The local APIC isn't very good at handling
1159 * multiple interrupts at the same interrupt level.
1160 * As the interrupt level is determined by taking the
1161 * vector number and shifting that right by 4, we
1162 * want to spread these out a bit so that they don't
1163 * all fall in the same interrupt level.
1165 * Also, we've got to be careful not to trash gate
1166 * 0x80, because int 0x80 is hm, kind of importantish. ;)
1168 static int current_vector = FIRST_DEVICE_VECTOR, current_offset = 0;
1169 unsigned int old_vector;
1171 cpumask_var_t tmp_mask;
1173 if (cfg->move_in_progress)
1176 if (!alloc_cpumask_var(&tmp_mask, GFP_ATOMIC))
1179 old_vector = cfg->vector;
1181 cpumask_and(tmp_mask, mask, cpu_online_mask);
1182 cpumask_and(tmp_mask, cfg->domain, tmp_mask);
1183 if (!cpumask_empty(tmp_mask)) {
1184 free_cpumask_var(tmp_mask);
1189 /* Only try and allocate irqs on cpus that are present */
1191 for_each_cpu_and(cpu, mask, cpu_online_mask) {
1195 apic->vector_allocation_domain(cpu, tmp_mask);
1197 vector = current_vector;
1198 offset = current_offset;
1201 if (vector >= first_system_vector) {
1202 /* If out of vectors on large boxen, must share them. */
1203 offset = (offset + 1) % 8;
1204 vector = FIRST_DEVICE_VECTOR + offset;
1206 if (unlikely(current_vector == vector))
1209 if (test_bit(vector, used_vectors))
1213 if (vector == KDBENTER_VECTOR)
1217 for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
1218 if (per_cpu(vector_irq, new_cpu)[vector] != -1)
1221 current_vector = vector;
1222 current_offset = offset;
1224 cfg->move_in_progress = 1;
1225 cpumask_copy(cfg->old_domain, cfg->domain);
1227 for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
1228 per_cpu(vector_irq, new_cpu)[vector] = irq;
1229 cfg->vector = vector;
1230 cpumask_copy(cfg->domain, tmp_mask);
1234 free_cpumask_var(tmp_mask);
1238 int assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
1241 unsigned long flags;
1243 spin_lock_irqsave(&vector_lock, flags);
1244 err = __assign_irq_vector(irq, cfg, mask);
1245 spin_unlock_irqrestore(&vector_lock, flags);
1249 static void __clear_irq_vector(int irq, struct irq_cfg *cfg)
1253 BUG_ON(!cfg->vector);
1255 vector = cfg->vector;
1256 for_each_cpu_and(cpu, cfg->domain, cpu_online_mask)
1257 per_cpu(vector_irq, cpu)[vector] = -1;
1260 cpumask_clear(cfg->domain);
1262 if (likely(!cfg->move_in_progress))
1264 for_each_cpu_and(cpu, cfg->old_domain, cpu_online_mask) {
1265 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS;
1267 if (per_cpu(vector_irq, cpu)[vector] != irq)
1269 per_cpu(vector_irq, cpu)[vector] = -1;
1273 cfg->move_in_progress = 0;
1276 void __setup_vector_irq(int cpu)
1278 /* Initialize vector_irq on a new cpu */
1279 /* This function must be called with vector_lock held */
1281 struct irq_cfg *cfg;
1282 struct irq_desc *desc;
1284 /* Mark the inuse vectors */
1285 for_each_irq_desc(irq, desc) {
1286 cfg = desc->chip_data;
1287 if (!cpumask_test_cpu(cpu, cfg->domain))
1289 vector = cfg->vector;
1290 per_cpu(vector_irq, cpu)[vector] = irq;
1292 /* Mark the free vectors */
1293 for (vector = 0; vector < NR_VECTORS; ++vector) {
1294 irq = per_cpu(vector_irq, cpu)[vector];
1299 if (!cpumask_test_cpu(cpu, cfg->domain))
1300 per_cpu(vector_irq, cpu)[vector] = -1;
1304 static struct irq_chip ioapic_chip;
1305 static struct irq_chip ir_ioapic_chip;
1307 #define IOAPIC_AUTO -1
1308 #define IOAPIC_EDGE 0
1309 #define IOAPIC_LEVEL 1
1311 #ifdef CONFIG_X86_32
1312 static inline int IO_APIC_irq_trigger(int irq)
1316 for (apic = 0; apic < nr_ioapics; apic++) {
1317 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
1318 idx = find_irq_entry(apic, pin, mp_INT);
1319 if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
1320 return irq_trigger(idx);
1324 * nonexistent IRQs are edge default
1329 static inline int IO_APIC_irq_trigger(int irq)
1335 static void ioapic_register_intr(int irq, struct irq_desc *desc, unsigned long trigger)
1338 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
1339 trigger == IOAPIC_LEVEL)
1340 desc->status |= IRQ_LEVEL;
1342 desc->status &= ~IRQ_LEVEL;
1344 if (irq_remapped(irq)) {
1345 desc->status |= IRQ_MOVE_PCNTXT;
1347 set_irq_chip_and_handler_name(irq, &ir_ioapic_chip,
1351 set_irq_chip_and_handler_name(irq, &ir_ioapic_chip,
1352 handle_edge_irq, "edge");
1356 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
1357 trigger == IOAPIC_LEVEL)
1358 set_irq_chip_and_handler_name(irq, &ioapic_chip,
1362 set_irq_chip_and_handler_name(irq, &ioapic_chip,
1363 handle_edge_irq, "edge");
1366 int setup_ioapic_entry(int apic_id, int irq,
1367 struct IO_APIC_route_entry *entry,
1368 unsigned int destination, int trigger,
1369 int polarity, int vector, int pin)
1372 * add it to the IO-APIC irq-routing table:
1374 memset(entry,0,sizeof(*entry));
1376 if (intr_remapping_enabled) {
1377 struct intel_iommu *iommu = map_ioapic_to_ir(apic_id);
1379 struct IR_IO_APIC_route_entry *ir_entry =
1380 (struct IR_IO_APIC_route_entry *) entry;
1384 panic("No mapping iommu for ioapic %d\n", apic_id);
1386 index = alloc_irte(iommu, irq, 1);
1388 panic("Failed to allocate IRTE for ioapic %d\n", apic_id);
1390 memset(&irte, 0, sizeof(irte));
1393 irte.dst_mode = apic->irq_dest_mode;
1395 * Trigger mode in the IRTE will always be edge, and the
1396 * actual level or edge trigger will be setup in the IO-APIC
1397 * RTE. This will help simplify level triggered irq migration.
1398 * For more details, see the comments above explainig IO-APIC
1399 * irq migration in the presence of interrupt-remapping.
1401 irte.trigger_mode = 0;
1402 irte.dlvry_mode = apic->irq_delivery_mode;
1403 irte.vector = vector;
1404 irte.dest_id = IRTE_DEST(destination);
1406 /* Set source-id of interrupt request */
1407 set_ioapic_sid(&irte, apic_id);
1409 modify_irte(irq, &irte);
1411 ir_entry->index2 = (index >> 15) & 0x1;
1413 ir_entry->format = 1;
1414 ir_entry->index = (index & 0x7fff);
1416 * IO-APIC RTE will be configured with virtual vector.
1417 * irq handler will do the explicit EOI to the io-apic.
1419 ir_entry->vector = pin;
1421 entry->delivery_mode = apic->irq_delivery_mode;
1422 entry->dest_mode = apic->irq_dest_mode;
1423 entry->dest = destination;
1424 entry->vector = vector;
1427 entry->mask = 0; /* enable IRQ */
1428 entry->trigger = trigger;
1429 entry->polarity = polarity;
1431 /* Mask level triggered irqs.
1432 * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
1439 static void setup_IO_APIC_irq(int apic_id, int pin, unsigned int irq, struct irq_desc *desc,
1440 int trigger, int polarity)
1442 struct irq_cfg *cfg;
1443 struct IO_APIC_route_entry entry;
1446 if (!IO_APIC_IRQ(irq))
1449 cfg = desc->chip_data;
1451 if (assign_irq_vector(irq, cfg, apic->target_cpus()))
1454 dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
1456 apic_printk(APIC_VERBOSE,KERN_DEBUG
1457 "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
1458 "IRQ %d Mode:%i Active:%i)\n",
1459 apic_id, mp_ioapics[apic_id].apicid, pin, cfg->vector,
1460 irq, trigger, polarity);
1463 if (setup_ioapic_entry(mp_ioapics[apic_id].apicid, irq, &entry,
1464 dest, trigger, polarity, cfg->vector, pin)) {
1465 printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
1466 mp_ioapics[apic_id].apicid, pin);
1467 __clear_irq_vector(irq, cfg);
1471 ioapic_register_intr(irq, desc, trigger);
1472 if (irq < nr_legacy_irqs)
1473 disable_8259A_irq(irq);
1475 ioapic_write_entry(apic_id, pin, entry);
1479 DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
1480 } mp_ioapic_routing[MAX_IO_APICS];
1482 static void __init setup_IO_APIC_irqs(void)
1484 int apic_id = 0, pin, idx, irq;
1486 struct irq_desc *desc;
1487 struct irq_cfg *cfg;
1488 int node = cpu_to_node(boot_cpu_id);
1490 apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
1493 if (!acpi_disabled && acpi_ioapic) {
1494 apic_id = mp_find_ioapic(0);
1500 for (pin = 0; pin < nr_ioapic_registers[apic_id]; pin++) {
1501 idx = find_irq_entry(apic_id, pin, mp_INT);
1505 apic_printk(APIC_VERBOSE,
1506 KERN_DEBUG " %d-%d",
1507 mp_ioapics[apic_id].apicid, pin);
1509 apic_printk(APIC_VERBOSE, " %d-%d",
1510 mp_ioapics[apic_id].apicid, pin);
1514 apic_printk(APIC_VERBOSE,
1515 " (apicid-pin) not connected\n");
1519 irq = pin_2_irq(idx, apic_id, pin);
1522 * Skip the timer IRQ if there's a quirk handler
1523 * installed and if it returns 1:
1525 if (apic->multi_timer_check &&
1526 apic->multi_timer_check(apic_id, irq))
1529 desc = irq_to_desc_alloc_node(irq, node);
1531 printk(KERN_INFO "can not get irq_desc for %d\n", irq);
1534 cfg = desc->chip_data;
1535 add_pin_to_irq_node(cfg, node, apic_id, pin);
1537 * don't mark it in pin_programmed, so later acpi could
1538 * set it correctly when irq < 16
1540 setup_IO_APIC_irq(apic_id, pin, irq, desc,
1541 irq_trigger(idx), irq_polarity(idx));
1545 apic_printk(APIC_VERBOSE,
1546 " (apicid-pin) not connected\n");
1550 * Set up the timer pin, possibly with the 8259A-master behind.
1552 static void __init setup_timer_IRQ0_pin(unsigned int apic_id, unsigned int pin,
1555 struct IO_APIC_route_entry entry;
1557 if (intr_remapping_enabled)
1560 memset(&entry, 0, sizeof(entry));
1563 * We use logical delivery to get the timer IRQ
1566 entry.dest_mode = apic->irq_dest_mode;
1567 entry.mask = 0; /* don't mask IRQ for edge */
1568 entry.dest = apic->cpu_mask_to_apicid(apic->target_cpus());
1569 entry.delivery_mode = apic->irq_delivery_mode;
1572 entry.vector = vector;
1575 * The timer IRQ doesn't have to know that behind the
1576 * scene we may have a 8259A-master in AEOI mode ...
1578 set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge");
1581 * Add it to the IO-APIC irq-routing table:
1583 ioapic_write_entry(apic_id, pin, entry);
1587 __apicdebuginit(void) print_IO_APIC(void)
1590 union IO_APIC_reg_00 reg_00;
1591 union IO_APIC_reg_01 reg_01;
1592 union IO_APIC_reg_02 reg_02;
1593 union IO_APIC_reg_03 reg_03;
1594 unsigned long flags;
1595 struct irq_cfg *cfg;
1596 struct irq_desc *desc;
1599 printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
1600 for (i = 0; i < nr_ioapics; i++)
1601 printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
1602 mp_ioapics[i].apicid, nr_ioapic_registers[i]);
1605 * We are a bit conservative about what we expect. We have to
1606 * know about every hardware change ASAP.
1608 printk(KERN_INFO "testing the IO APIC.......................\n");
1610 for (apic = 0; apic < nr_ioapics; apic++) {
1612 spin_lock_irqsave(&ioapic_lock, flags);
1613 reg_00.raw = io_apic_read(apic, 0);
1614 reg_01.raw = io_apic_read(apic, 1);
1615 if (reg_01.bits.version >= 0x10)
1616 reg_02.raw = io_apic_read(apic, 2);
1617 if (reg_01.bits.version >= 0x20)
1618 reg_03.raw = io_apic_read(apic, 3);
1619 spin_unlock_irqrestore(&ioapic_lock, flags);
1622 printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].apicid);
1623 printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
1624 printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
1625 printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type);
1626 printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS);
1628 printk(KERN_DEBUG ".... register #01: %08X\n", *(int *)®_01);
1629 printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
1631 printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
1632 printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
1635 * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
1636 * but the value of reg_02 is read as the previous read register
1637 * value, so ignore it if reg_02 == reg_01.
1639 if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) {
1640 printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
1641 printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
1645 * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
1646 * or reg_03, but the value of reg_0[23] is read as the previous read
1647 * register value, so ignore it if reg_03 == reg_0[12].
1649 if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw &&
1650 reg_03.raw != reg_01.raw) {
1651 printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw);
1652 printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT);
1655 printk(KERN_DEBUG ".... IRQ redirection table:\n");
1657 printk(KERN_DEBUG " NR Dst Mask Trig IRR Pol"
1658 " Stat Dmod Deli Vect: \n");
1660 for (i = 0; i <= reg_01.bits.entries; i++) {
1661 struct IO_APIC_route_entry entry;
1663 entry = ioapic_read_entry(apic, i);
1665 printk(KERN_DEBUG " %02x %03X ",
1670 printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
1675 entry.delivery_status,
1677 entry.delivery_mode,
1682 printk(KERN_DEBUG "IRQ to pin mappings:\n");
1683 for_each_irq_desc(irq, desc) {
1684 struct irq_pin_list *entry;
1686 cfg = desc->chip_data;
1687 entry = cfg->irq_2_pin;
1690 printk(KERN_DEBUG "IRQ%d ", irq);
1691 for_each_irq_pin(entry, cfg->irq_2_pin)
1692 printk("-> %d:%d", entry->apic, entry->pin);
1696 printk(KERN_INFO ".................................... done.\n");
1701 __apicdebuginit(void) print_APIC_field(int base)
1707 for (i = 0; i < 8; i++)
1708 printk(KERN_CONT "%08x", apic_read(base + i*0x10));
1710 printk(KERN_CONT "\n");
1713 __apicdebuginit(void) print_local_APIC(void *dummy)
1715 unsigned int i, v, ver, maxlvt;
1718 printk(KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
1719 smp_processor_id(), hard_smp_processor_id());
1720 v = apic_read(APIC_ID);
1721 printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, read_apic_id());
1722 v = apic_read(APIC_LVR);
1723 printk(KERN_INFO "... APIC VERSION: %08x\n", v);
1724 ver = GET_APIC_VERSION(v);
1725 maxlvt = lapic_get_maxlvt();
1727 v = apic_read(APIC_TASKPRI);
1728 printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
1730 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1731 if (!APIC_XAPIC(ver)) {
1732 v = apic_read(APIC_ARBPRI);
1733 printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
1734 v & APIC_ARBPRI_MASK);
1736 v = apic_read(APIC_PROCPRI);
1737 printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
1741 * Remote read supported only in the 82489DX and local APIC for
1742 * Pentium processors.
1744 if (!APIC_INTEGRATED(ver) || maxlvt == 3) {
1745 v = apic_read(APIC_RRR);
1746 printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
1749 v = apic_read(APIC_LDR);
1750 printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
1751 if (!x2apic_enabled()) {
1752 v = apic_read(APIC_DFR);
1753 printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
1755 v = apic_read(APIC_SPIV);
1756 printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
1758 printk(KERN_DEBUG "... APIC ISR field:\n");
1759 print_APIC_field(APIC_ISR);
1760 printk(KERN_DEBUG "... APIC TMR field:\n");
1761 print_APIC_field(APIC_TMR);
1762 printk(KERN_DEBUG "... APIC IRR field:\n");
1763 print_APIC_field(APIC_IRR);
1765 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1766 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
1767 apic_write(APIC_ESR, 0);
1769 v = apic_read(APIC_ESR);
1770 printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
1773 icr = apic_icr_read();
1774 printk(KERN_DEBUG "... APIC ICR: %08x\n", (u32)icr);
1775 printk(KERN_DEBUG "... APIC ICR2: %08x\n", (u32)(icr >> 32));
1777 v = apic_read(APIC_LVTT);
1778 printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
1780 if (maxlvt > 3) { /* PC is LVT#4. */
1781 v = apic_read(APIC_LVTPC);
1782 printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
1784 v = apic_read(APIC_LVT0);
1785 printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
1786 v = apic_read(APIC_LVT1);
1787 printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
1789 if (maxlvt > 2) { /* ERR is LVT#3. */
1790 v = apic_read(APIC_LVTERR);
1791 printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
1794 v = apic_read(APIC_TMICT);
1795 printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
1796 v = apic_read(APIC_TMCCT);
1797 printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
1798 v = apic_read(APIC_TDCR);
1799 printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
1801 if (boot_cpu_has(X86_FEATURE_EXTAPIC)) {
1802 v = apic_read(APIC_EFEAT);
1803 maxlvt = (v >> 16) & 0xff;
1804 printk(KERN_DEBUG "... APIC EFEAT: %08x\n", v);
1805 v = apic_read(APIC_ECTRL);
1806 printk(KERN_DEBUG "... APIC ECTRL: %08x\n", v);
1807 for (i = 0; i < maxlvt; i++) {
1808 v = apic_read(APIC_EILVTn(i));
1809 printk(KERN_DEBUG "... APIC EILVT%d: %08x\n", i, v);
1815 __apicdebuginit(void) print_local_APICs(int maxcpu)
1823 for_each_online_cpu(cpu) {
1826 smp_call_function_single(cpu, print_local_APIC, NULL, 1);
1831 __apicdebuginit(void) print_PIC(void)
1834 unsigned long flags;
1836 if (!nr_legacy_irqs)
1839 printk(KERN_DEBUG "\nprinting PIC contents\n");
1841 spin_lock_irqsave(&i8259A_lock, flags);
1843 v = inb(0xa1) << 8 | inb(0x21);
1844 printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
1846 v = inb(0xa0) << 8 | inb(0x20);
1847 printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
1851 v = inb(0xa0) << 8 | inb(0x20);
1855 spin_unlock_irqrestore(&i8259A_lock, flags);
1857 printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
1859 v = inb(0x4d1) << 8 | inb(0x4d0);
1860 printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
1863 static int __initdata show_lapic = 1;
1864 static __init int setup_show_lapic(char *arg)
1868 if (strcmp(arg, "all") == 0) {
1869 show_lapic = CONFIG_NR_CPUS;
1871 get_option(&arg, &num);
1878 __setup("show_lapic=", setup_show_lapic);
1880 __apicdebuginit(int) print_ICs(void)
1882 if (apic_verbosity == APIC_QUIET)
1887 /* don't print out if apic is not there */
1888 if (!cpu_has_apic && !apic_from_smp_config())
1891 print_local_APICs(show_lapic);
1897 fs_initcall(print_ICs);
1900 /* Where if anywhere is the i8259 connect in external int mode */
1901 static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
1903 void __init enable_IO_APIC(void)
1905 union IO_APIC_reg_01 reg_01;
1906 int i8259_apic, i8259_pin;
1908 unsigned long flags;
1911 * The number of IO-APIC IRQ registers (== #pins):
1913 for (apic = 0; apic < nr_ioapics; apic++) {
1914 spin_lock_irqsave(&ioapic_lock, flags);
1915 reg_01.raw = io_apic_read(apic, 1);
1916 spin_unlock_irqrestore(&ioapic_lock, flags);
1917 nr_ioapic_registers[apic] = reg_01.bits.entries+1;
1920 if (!nr_legacy_irqs)
1923 for(apic = 0; apic < nr_ioapics; apic++) {
1925 /* See if any of the pins is in ExtINT mode */
1926 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
1927 struct IO_APIC_route_entry entry;
1928 entry = ioapic_read_entry(apic, pin);
1930 /* If the interrupt line is enabled and in ExtInt mode
1931 * I have found the pin where the i8259 is connected.
1933 if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
1934 ioapic_i8259.apic = apic;
1935 ioapic_i8259.pin = pin;
1941 /* Look to see what if the MP table has reported the ExtINT */
1942 /* If we could not find the appropriate pin by looking at the ioapic
1943 * the i8259 probably is not connected the ioapic but give the
1944 * mptable a chance anyway.
1946 i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
1947 i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
1948 /* Trust the MP table if nothing is setup in the hardware */
1949 if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
1950 printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
1951 ioapic_i8259.pin = i8259_pin;
1952 ioapic_i8259.apic = i8259_apic;
1954 /* Complain if the MP table and the hardware disagree */
1955 if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
1956 (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
1958 printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
1962 * Do not trust the IO-APIC being empty at bootup
1968 * Not an __init, needed by the reboot code
1970 void disable_IO_APIC(void)
1973 * Clear the IO-APIC before rebooting:
1977 if (!nr_legacy_irqs)
1981 * If the i8259 is routed through an IOAPIC
1982 * Put that IOAPIC in virtual wire mode
1983 * so legacy interrupts can be delivered.
1985 * With interrupt-remapping, for now we will use virtual wire A mode,
1986 * as virtual wire B is little complex (need to configure both
1987 * IOAPIC RTE aswell as interrupt-remapping table entry).
1988 * As this gets called during crash dump, keep this simple for now.
1990 if (ioapic_i8259.pin != -1 && !intr_remapping_enabled) {
1991 struct IO_APIC_route_entry entry;
1993 memset(&entry, 0, sizeof(entry));
1994 entry.mask = 0; /* Enabled */
1995 entry.trigger = 0; /* Edge */
1997 entry.polarity = 0; /* High */
1998 entry.delivery_status = 0;
1999 entry.dest_mode = 0; /* Physical */
2000 entry.delivery_mode = dest_ExtINT; /* ExtInt */
2002 entry.dest = read_apic_id();
2005 * Add it to the IO-APIC irq-routing table:
2007 ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
2011 * Use virtual wire A mode when interrupt remapping is enabled.
2013 if (cpu_has_apic || apic_from_smp_config())
2014 disconnect_bsp_APIC(!intr_remapping_enabled &&
2015 ioapic_i8259.pin != -1);
2018 #ifdef CONFIG_X86_32
2020 * function to set the IO-APIC physical IDs based on the
2021 * values stored in the MPC table.
2023 * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
2026 void __init setup_ioapic_ids_from_mpc(void)
2028 union IO_APIC_reg_00 reg_00;
2029 physid_mask_t phys_id_present_map;
2032 unsigned char old_id;
2033 unsigned long flags;
2038 * Don't check I/O APIC IDs for xAPIC systems. They have
2039 * no meaning without the serial APIC bus.
2041 if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
2042 || APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
2045 * This is broken; anything with a real cpu count has to
2046 * circumvent this idiocy regardless.
2048 apic->ioapic_phys_id_map(&phys_cpu_present_map, &phys_id_present_map);
2051 * Set the IOAPIC ID to the value stored in the MPC table.
2053 for (apic_id = 0; apic_id < nr_ioapics; apic_id++) {
2055 /* Read the register 0 value */
2056 spin_lock_irqsave(&ioapic_lock, flags);
2057 reg_00.raw = io_apic_read(apic_id, 0);
2058 spin_unlock_irqrestore(&ioapic_lock, flags);
2060 old_id = mp_ioapics[apic_id].apicid;
2062 if (mp_ioapics[apic_id].apicid >= get_physical_broadcast()) {
2063 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
2064 apic_id, mp_ioapics[apic_id].apicid);
2065 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
2067 mp_ioapics[apic_id].apicid = reg_00.bits.ID;
2071 * Sanity check, is the ID really free? Every APIC in a
2072 * system must have a unique ID or we get lots of nice
2073 * 'stuck on smp_invalidate_needed IPI wait' messages.
2075 if (apic->check_apicid_used(&phys_id_present_map,
2076 mp_ioapics[apic_id].apicid)) {
2077 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
2078 apic_id, mp_ioapics[apic_id].apicid);
2079 for (i = 0; i < get_physical_broadcast(); i++)
2080 if (!physid_isset(i, phys_id_present_map))
2082 if (i >= get_physical_broadcast())
2083 panic("Max APIC ID exceeded!\n");
2084 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
2086 physid_set(i, phys_id_present_map);
2087 mp_ioapics[apic_id].apicid = i;
2090 apic->apicid_to_cpu_present(mp_ioapics[apic_id].apicid, &tmp);
2091 apic_printk(APIC_VERBOSE, "Setting %d in the "
2092 "phys_id_present_map\n",
2093 mp_ioapics[apic_id].apicid);
2094 physids_or(phys_id_present_map, phys_id_present_map, tmp);
2099 * We need to adjust the IRQ routing table
2100 * if the ID changed.
2102 if (old_id != mp_ioapics[apic_id].apicid)
2103 for (i = 0; i < mp_irq_entries; i++)
2104 if (mp_irqs[i].dstapic == old_id)
2106 = mp_ioapics[apic_id].apicid;
2109 * Read the right value from the MPC table and
2110 * write it into the ID register.
2112 apic_printk(APIC_VERBOSE, KERN_INFO
2113 "...changing IO-APIC physical APIC ID to %d ...",
2114 mp_ioapics[apic_id].apicid);
2116 reg_00.bits.ID = mp_ioapics[apic_id].apicid;
2117 spin_lock_irqsave(&ioapic_lock, flags);
2118 io_apic_write(apic_id, 0, reg_00.raw);
2119 spin_unlock_irqrestore(&ioapic_lock, flags);
2124 spin_lock_irqsave(&ioapic_lock, flags);
2125 reg_00.raw = io_apic_read(apic_id, 0);
2126 spin_unlock_irqrestore(&ioapic_lock, flags);
2127 if (reg_00.bits.ID != mp_ioapics[apic_id].apicid)
2128 printk("could not set ID!\n");
2130 apic_printk(APIC_VERBOSE, " ok.\n");
2135 int no_timer_check __initdata;
2137 static int __init notimercheck(char *s)
2142 __setup("no_timer_check", notimercheck);
2145 * There is a nasty bug in some older SMP boards, their mptable lies
2146 * about the timer IRQ. We do the following to work around the situation:
2148 * - timer IRQ defaults to IO-APIC IRQ
2149 * - if this function detects that timer IRQs are defunct, then we fall
2150 * back to ISA timer IRQs
2152 static int __init timer_irq_works(void)
2154 unsigned long t1 = jiffies;
2155 unsigned long flags;
2160 local_save_flags(flags);
2162 /* Let ten ticks pass... */
2163 mdelay((10 * 1000) / HZ);
2164 local_irq_restore(flags);
2167 * Expect a few ticks at least, to be sure some possible
2168 * glue logic does not lock up after one or two first
2169 * ticks in a non-ExtINT mode. Also the local APIC
2170 * might have cached one ExtINT interrupt. Finally, at
2171 * least one tick may be lost due to delays.
2175 if (time_after(jiffies, t1 + 4))
2181 * In the SMP+IOAPIC case it might happen that there are an unspecified
2182 * number of pending IRQ events unhandled. These cases are very rare,
2183 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
2184 * better to do it this way as thus we do not have to be aware of
2185 * 'pending' interrupts in the IRQ path, except at this point.
2188 * Edge triggered needs to resend any interrupt
2189 * that was delayed but this is now handled in the device
2194 * Starting up a edge-triggered IO-APIC interrupt is
2195 * nasty - we need to make sure that we get the edge.
2196 * If it is already asserted for some reason, we need
2197 * return 1 to indicate that is was pending.
2199 * This is not complete - we should be able to fake
2200 * an edge even if it isn't on the 8259A...
2203 static unsigned int startup_ioapic_irq(unsigned int irq)
2205 int was_pending = 0;
2206 unsigned long flags;
2207 struct irq_cfg *cfg;
2209 spin_lock_irqsave(&ioapic_lock, flags);
2210 if (irq < nr_legacy_irqs) {
2211 disable_8259A_irq(irq);
2212 if (i8259A_irq_pending(irq))
2216 __unmask_IO_APIC_irq(cfg);
2217 spin_unlock_irqrestore(&ioapic_lock, flags);
2222 static int ioapic_retrigger_irq(unsigned int irq)
2225 struct irq_cfg *cfg = irq_cfg(irq);
2226 unsigned long flags;
2228 spin_lock_irqsave(&vector_lock, flags);
2229 apic->send_IPI_mask(cpumask_of(cpumask_first(cfg->domain)), cfg->vector);
2230 spin_unlock_irqrestore(&vector_lock, flags);
2236 * Level and edge triggered IO-APIC interrupts need different handling,
2237 * so we use two separate IRQ descriptors. Edge triggered IRQs can be
2238 * handled with the level-triggered descriptor, but that one has slightly
2239 * more overhead. Level-triggered interrupts cannot be handled with the
2240 * edge-triggered handler, without risking IRQ storms and other ugly
2245 void send_cleanup_vector(struct irq_cfg *cfg)
2247 cpumask_var_t cleanup_mask;
2249 if (unlikely(!alloc_cpumask_var(&cleanup_mask, GFP_ATOMIC))) {
2251 for_each_cpu_and(i, cfg->old_domain, cpu_online_mask)
2252 apic->send_IPI_mask(cpumask_of(i), IRQ_MOVE_CLEANUP_VECTOR);
2254 cpumask_and(cleanup_mask, cfg->old_domain, cpu_online_mask);
2255 apic->send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
2256 free_cpumask_var(cleanup_mask);
2258 cfg->move_in_progress = 0;
2261 static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, struct irq_cfg *cfg)
2264 struct irq_pin_list *entry;
2265 u8 vector = cfg->vector;
2267 for_each_irq_pin(entry, cfg->irq_2_pin) {
2273 * With interrupt-remapping, destination information comes
2274 * from interrupt-remapping table entry.
2276 if (!irq_remapped(irq))
2277 io_apic_write(apic, 0x11 + pin*2, dest);
2278 reg = io_apic_read(apic, 0x10 + pin*2);
2279 reg &= ~IO_APIC_REDIR_VECTOR_MASK;
2281 io_apic_modify(apic, 0x10 + pin*2, reg);
2286 * Either sets desc->affinity to a valid value, and returns
2287 * ->cpu_mask_to_apicid of that in dest_id, or returns -1 and
2288 * leaves desc->affinity untouched.
2291 set_desc_affinity(struct irq_desc *desc, const struct cpumask *mask,
2292 unsigned int *dest_id)
2294 struct irq_cfg *cfg;
2297 if (!cpumask_intersects(mask, cpu_online_mask))
2301 cfg = desc->chip_data;
2302 if (assign_irq_vector(irq, cfg, mask))
2305 cpumask_copy(desc->affinity, mask);
2307 *dest_id = apic->cpu_mask_to_apicid_and(desc->affinity, cfg->domain);
2312 set_ioapic_affinity_irq_desc(struct irq_desc *desc, const struct cpumask *mask)
2314 struct irq_cfg *cfg;
2315 unsigned long flags;
2321 cfg = desc->chip_data;
2323 spin_lock_irqsave(&ioapic_lock, flags);
2324 ret = set_desc_affinity(desc, mask, &dest);
2326 /* Only the high 8 bits are valid. */
2327 dest = SET_APIC_LOGICAL_ID(dest);
2328 __target_IO_APIC_irq(irq, dest, cfg);
2330 spin_unlock_irqrestore(&ioapic_lock, flags);
2336 set_ioapic_affinity_irq(unsigned int irq, const struct cpumask *mask)
2338 struct irq_desc *desc;
2340 desc = irq_to_desc(irq);
2342 return set_ioapic_affinity_irq_desc(desc, mask);
2345 #ifdef CONFIG_INTR_REMAP
2348 * Migrate the IO-APIC irq in the presence of intr-remapping.
2350 * For both level and edge triggered, irq migration is a simple atomic
2351 * update(of vector and cpu destination) of IRTE and flush the hardware cache.
2353 * For level triggered, we eliminate the io-apic RTE modification (with the
2354 * updated vector information), by using a virtual vector (io-apic pin number).
2355 * Real vector that is used for interrupting cpu will be coming from
2356 * the interrupt-remapping table entry.
2359 migrate_ioapic_irq_desc(struct irq_desc *desc, const struct cpumask *mask)
2361 struct irq_cfg *cfg;
2367 if (!cpumask_intersects(mask, cpu_online_mask))
2371 if (get_irte(irq, &irte))
2374 cfg = desc->chip_data;
2375 if (assign_irq_vector(irq, cfg, mask))
2378 dest = apic->cpu_mask_to_apicid_and(cfg->domain, mask);
2380 irte.vector = cfg->vector;
2381 irte.dest_id = IRTE_DEST(dest);
2384 * Modified the IRTE and flushes the Interrupt entry cache.
2386 modify_irte(irq, &irte);
2388 if (cfg->move_in_progress)
2389 send_cleanup_vector(cfg);
2391 cpumask_copy(desc->affinity, mask);
2397 * Migrates the IRQ destination in the process context.
2399 static int set_ir_ioapic_affinity_irq_desc(struct irq_desc *desc,
2400 const struct cpumask *mask)
2402 return migrate_ioapic_irq_desc(desc, mask);
2404 static int set_ir_ioapic_affinity_irq(unsigned int irq,
2405 const struct cpumask *mask)
2407 struct irq_desc *desc = irq_to_desc(irq);
2409 return set_ir_ioapic_affinity_irq_desc(desc, mask);
2412 static inline int set_ir_ioapic_affinity_irq_desc(struct irq_desc *desc,
2413 const struct cpumask *mask)
2419 asmlinkage void smp_irq_move_cleanup_interrupt(void)
2421 unsigned vector, me;
2427 me = smp_processor_id();
2428 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
2431 struct irq_desc *desc;
2432 struct irq_cfg *cfg;
2433 irq = __get_cpu_var(vector_irq)[vector];
2438 desc = irq_to_desc(irq);
2443 raw_spin_lock(&desc->lock);
2446 * Check if the irq migration is in progress. If so, we
2447 * haven't received the cleanup request yet for this irq.
2449 if (cfg->move_in_progress)
2452 if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
2455 irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
2457 * Check if the vector that needs to be cleanedup is
2458 * registered at the cpu's IRR. If so, then this is not
2459 * the best time to clean it up. Lets clean it up in the
2460 * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
2463 if (irr & (1 << (vector % 32))) {
2464 apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
2467 __get_cpu_var(vector_irq)[vector] = -1;
2469 raw_spin_unlock(&desc->lock);
2475 static void __irq_complete_move(struct irq_desc **descp, unsigned vector)
2477 struct irq_desc *desc = *descp;
2478 struct irq_cfg *cfg = desc->chip_data;
2481 if (likely(!cfg->move_in_progress))
2484 me = smp_processor_id();
2486 if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
2487 send_cleanup_vector(cfg);
2490 static void irq_complete_move(struct irq_desc **descp)
2492 __irq_complete_move(descp, ~get_irq_regs()->orig_ax);
2495 void irq_force_complete_move(int irq)
2497 struct irq_desc *desc = irq_to_desc(irq);
2498 struct irq_cfg *cfg = desc->chip_data;
2500 __irq_complete_move(&desc, cfg->vector);
2503 static inline void irq_complete_move(struct irq_desc **descp) {}
2506 static void ack_apic_edge(unsigned int irq)
2508 struct irq_desc *desc = irq_to_desc(irq);
2510 irq_complete_move(&desc);
2511 move_native_irq(irq);
2515 atomic_t irq_mis_count;
2518 * IO-APIC versions below 0x20 don't support EOI register.
2519 * For the record, here is the information about various versions:
2521 * 1Xh I/OAPIC or I/O(x)APIC which are not PCI 2.2 Compliant
2522 * 2Xh I/O(x)APIC which is PCI 2.2 Compliant
2525 * Some of the Intel ICH Specs (ICH2 to ICH5) documents the io-apic
2526 * version as 0x2. This is an error with documentation and these ICH chips
2527 * use io-apic's of version 0x20.
2529 * For IO-APIC's with EOI register, we use that to do an explicit EOI.
2530 * Otherwise, we simulate the EOI message manually by changing the trigger
2531 * mode to edge and then back to level, with RTE being masked during this.
2533 static void __eoi_ioapic_irq(unsigned int irq, struct irq_cfg *cfg)
2535 struct irq_pin_list *entry;
2537 for_each_irq_pin(entry, cfg->irq_2_pin) {
2538 if (mp_ioapics[entry->apic].apicver >= 0x20) {
2540 * Intr-remapping uses pin number as the virtual vector
2541 * in the RTE. Actual vector is programmed in
2542 * intr-remapping table entry. Hence for the io-apic
2543 * EOI we use the pin number.
2545 if (irq_remapped(irq))
2546 io_apic_eoi(entry->apic, entry->pin);
2548 io_apic_eoi(entry->apic, cfg->vector);
2550 __mask_and_edge_IO_APIC_irq(entry);
2551 __unmask_and_level_IO_APIC_irq(entry);
2556 static void eoi_ioapic_irq(struct irq_desc *desc)
2558 struct irq_cfg *cfg;
2559 unsigned long flags;
2563 cfg = desc->chip_data;
2565 spin_lock_irqsave(&ioapic_lock, flags);
2566 __eoi_ioapic_irq(irq, cfg);
2567 spin_unlock_irqrestore(&ioapic_lock, flags);
2570 static void ack_apic_level(unsigned int irq)
2572 struct irq_desc *desc = irq_to_desc(irq);
2575 struct irq_cfg *cfg;
2576 int do_unmask_irq = 0;
2578 irq_complete_move(&desc);
2579 #ifdef CONFIG_GENERIC_PENDING_IRQ
2580 /* If we are moving the irq we need to mask it */
2581 if (unlikely(desc->status & IRQ_MOVE_PENDING)) {
2583 mask_IO_APIC_irq_desc(desc);
2588 * It appears there is an erratum which affects at least version 0x11
2589 * of I/O APIC (that's the 82093AA and cores integrated into various
2590 * chipsets). Under certain conditions a level-triggered interrupt is
2591 * erroneously delivered as edge-triggered one but the respective IRR
2592 * bit gets set nevertheless. As a result the I/O unit expects an EOI
2593 * message but it will never arrive and further interrupts are blocked
2594 * from the source. The exact reason is so far unknown, but the
2595 * phenomenon was observed when two consecutive interrupt requests
2596 * from a given source get delivered to the same CPU and the source is
2597 * temporarily disabled in between.
2599 * A workaround is to simulate an EOI message manually. We achieve it
2600 * by setting the trigger mode to edge and then to level when the edge
2601 * trigger mode gets detected in the TMR of a local APIC for a
2602 * level-triggered interrupt. We mask the source for the time of the
2603 * operation to prevent an edge-triggered interrupt escaping meanwhile.
2604 * The idea is from Manfred Spraul. --macro
2606 * Also in the case when cpu goes offline, fixup_irqs() will forward
2607 * any unhandled interrupt on the offlined cpu to the new cpu
2608 * destination that is handling the corresponding interrupt. This
2609 * interrupt forwarding is done via IPI's. Hence, in this case also
2610 * level-triggered io-apic interrupt will be seen as an edge
2611 * interrupt in the IRR. And we can't rely on the cpu's EOI
2612 * to be broadcasted to the IO-APIC's which will clear the remoteIRR
2613 * corresponding to the level-triggered interrupt. Hence on IO-APIC's
2614 * supporting EOI register, we do an explicit EOI to clear the
2615 * remote IRR and on IO-APIC's which don't have an EOI register,
2616 * we use the above logic (mask+edge followed by unmask+level) from
2617 * Manfred Spraul to clear the remote IRR.
2619 cfg = desc->chip_data;
2621 v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
2624 * We must acknowledge the irq before we move it or the acknowledge will
2625 * not propagate properly.
2630 * Tail end of clearing remote IRR bit (either by delivering the EOI
2631 * message via io-apic EOI register write or simulating it using
2632 * mask+edge followed by unnask+level logic) manually when the
2633 * level triggered interrupt is seen as the edge triggered interrupt
2636 if (!(v & (1 << (i & 0x1f)))) {
2637 atomic_inc(&irq_mis_count);
2639 eoi_ioapic_irq(desc);
2642 /* Now we can move and renable the irq */
2643 if (unlikely(do_unmask_irq)) {
2644 /* Only migrate the irq if the ack has been received.
2646 * On rare occasions the broadcast level triggered ack gets
2647 * delayed going to ioapics, and if we reprogram the
2648 * vector while Remote IRR is still set the irq will never
2651 * To prevent this scenario we read the Remote IRR bit
2652 * of the ioapic. This has two effects.
2653 * - On any sane system the read of the ioapic will
2654 * flush writes (and acks) going to the ioapic from
2656 * - We get to see if the ACK has actually been delivered.
2658 * Based on failed experiments of reprogramming the
2659 * ioapic entry from outside of irq context starting
2660 * with masking the ioapic entry and then polling until
2661 * Remote IRR was clear before reprogramming the
2662 * ioapic I don't trust the Remote IRR bit to be
2663 * completey accurate.
2665 * However there appears to be no other way to plug
2666 * this race, so if the Remote IRR bit is not
2667 * accurate and is causing problems then it is a hardware bug
2668 * and you can go talk to the chipset vendor about it.
2670 cfg = desc->chip_data;
2671 if (!io_apic_level_ack_pending(cfg))
2672 move_masked_irq(irq);
2673 unmask_IO_APIC_irq_desc(desc);
2677 #ifdef CONFIG_INTR_REMAP
2678 static void ir_ack_apic_edge(unsigned int irq)
2683 static void ir_ack_apic_level(unsigned int irq)
2685 struct irq_desc *desc = irq_to_desc(irq);
2688 eoi_ioapic_irq(desc);
2690 #endif /* CONFIG_INTR_REMAP */
2692 static struct irq_chip ioapic_chip __read_mostly = {
2694 .startup = startup_ioapic_irq,
2695 .mask = mask_IO_APIC_irq,
2696 .unmask = unmask_IO_APIC_irq,
2697 .ack = ack_apic_edge,
2698 .eoi = ack_apic_level,
2700 .set_affinity = set_ioapic_affinity_irq,
2702 .retrigger = ioapic_retrigger_irq,
2705 static struct irq_chip ir_ioapic_chip __read_mostly = {
2706 .name = "IR-IO-APIC",
2707 .startup = startup_ioapic_irq,
2708 .mask = mask_IO_APIC_irq,
2709 .unmask = unmask_IO_APIC_irq,
2710 #ifdef CONFIG_INTR_REMAP
2711 .ack = ir_ack_apic_edge,
2712 .eoi = ir_ack_apic_level,
2714 .set_affinity = set_ir_ioapic_affinity_irq,
2717 .retrigger = ioapic_retrigger_irq,
2720 static inline void init_IO_APIC_traps(void)
2723 struct irq_desc *desc;
2724 struct irq_cfg *cfg;
2727 * NOTE! The local APIC isn't very good at handling
2728 * multiple interrupts at the same interrupt level.
2729 * As the interrupt level is determined by taking the
2730 * vector number and shifting that right by 4, we
2731 * want to spread these out a bit so that they don't
2732 * all fall in the same interrupt level.
2734 * Also, we've got to be careful not to trash gate
2735 * 0x80, because int 0x80 is hm, kind of importantish. ;)
2737 for_each_irq_desc(irq, desc) {
2738 cfg = desc->chip_data;
2739 if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) {
2741 * Hmm.. We don't have an entry for this,
2742 * so default to an old-fashioned 8259
2743 * interrupt if we can..
2745 if (irq < nr_legacy_irqs)
2746 make_8259A_irq(irq);
2748 /* Strange. Oh, well.. */
2749 desc->chip = &no_irq_chip;
2755 * The local APIC irq-chip implementation:
2758 static void mask_lapic_irq(unsigned int irq)
2762 v = apic_read(APIC_LVT0);
2763 apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
2766 static void unmask_lapic_irq(unsigned int irq)
2770 v = apic_read(APIC_LVT0);
2771 apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
2774 static void ack_lapic_irq(unsigned int irq)
2779 static struct irq_chip lapic_chip __read_mostly = {
2780 .name = "local-APIC",
2781 .mask = mask_lapic_irq,
2782 .unmask = unmask_lapic_irq,
2783 .ack = ack_lapic_irq,
2786 static void lapic_register_intr(int irq, struct irq_desc *desc)
2788 desc->status &= ~IRQ_LEVEL;
2789 set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
2793 static void __init setup_nmi(void)
2796 * Dirty trick to enable the NMI watchdog ...
2797 * We put the 8259A master into AEOI mode and
2798 * unmask on all local APICs LVT0 as NMI.
2800 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
2801 * is from Maciej W. Rozycki - so we do not have to EOI from
2802 * the NMI handler or the timer interrupt.
2804 apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
2806 enable_NMI_through_LVT0();
2808 apic_printk(APIC_VERBOSE, " done.\n");
2812 * This looks a bit hackish but it's about the only one way of sending
2813 * a few INTA cycles to 8259As and any associated glue logic. ICR does
2814 * not support the ExtINT mode, unfortunately. We need to send these
2815 * cycles as some i82489DX-based boards have glue logic that keeps the
2816 * 8259A interrupt line asserted until INTA. --macro
2818 static inline void __init unlock_ExtINT_logic(void)
2821 struct IO_APIC_route_entry entry0, entry1;
2822 unsigned char save_control, save_freq_select;
2824 pin = find_isa_irq_pin(8, mp_INT);
2829 apic = find_isa_irq_apic(8, mp_INT);
2835 entry0 = ioapic_read_entry(apic, pin);
2836 clear_IO_APIC_pin(apic, pin);
2838 memset(&entry1, 0, sizeof(entry1));
2840 entry1.dest_mode = 0; /* physical delivery */
2841 entry1.mask = 0; /* unmask IRQ now */
2842 entry1.dest = hard_smp_processor_id();
2843 entry1.delivery_mode = dest_ExtINT;
2844 entry1.polarity = entry0.polarity;
2848 ioapic_write_entry(apic, pin, entry1);
2850 save_control = CMOS_READ(RTC_CONTROL);
2851 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
2852 CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
2854 CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
2859 if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
2863 CMOS_WRITE(save_control, RTC_CONTROL);
2864 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
2865 clear_IO_APIC_pin(apic, pin);
2867 ioapic_write_entry(apic, pin, entry0);
2870 static int disable_timer_pin_1 __initdata;
2871 /* Actually the next is obsolete, but keep it for paranoid reasons -AK */
2872 static int __init disable_timer_pin_setup(char *arg)
2874 disable_timer_pin_1 = 1;
2877 early_param("disable_timer_pin_1", disable_timer_pin_setup);
2879 int timer_through_8259 __initdata;
2882 * This code may look a bit paranoid, but it's supposed to cooperate with
2883 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
2884 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
2885 * fanatically on his truly buggy board.
2887 * FIXME: really need to revamp this for all platforms.
2889 static inline void __init check_timer(void)
2891 struct irq_desc *desc = irq_to_desc(0);
2892 struct irq_cfg *cfg = desc->chip_data;
2893 int node = cpu_to_node(boot_cpu_id);
2894 int apic1, pin1, apic2, pin2;
2895 unsigned long flags;
2898 local_irq_save(flags);
2901 * get/set the timer IRQ vector:
2903 disable_8259A_irq(0);
2904 assign_irq_vector(0, cfg, apic->target_cpus());
2907 * As IRQ0 is to be enabled in the 8259A, the virtual
2908 * wire has to be disabled in the local APIC. Also
2909 * timer interrupts need to be acknowledged manually in
2910 * the 8259A for the i82489DX when using the NMI
2911 * watchdog as that APIC treats NMIs as level-triggered.
2912 * The AEOI mode will finish them in the 8259A
2915 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
2917 #ifdef CONFIG_X86_32
2921 ver = apic_read(APIC_LVR);
2922 ver = GET_APIC_VERSION(ver);
2923 timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver));
2927 pin1 = find_isa_irq_pin(0, mp_INT);
2928 apic1 = find_isa_irq_apic(0, mp_INT);
2929 pin2 = ioapic_i8259.pin;
2930 apic2 = ioapic_i8259.apic;
2932 apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X "
2933 "apic1=%d pin1=%d apic2=%d pin2=%d\n",
2934 cfg->vector, apic1, pin1, apic2, pin2);
2937 * Some BIOS writers are clueless and report the ExtINTA
2938 * I/O APIC input from the cascaded 8259A as the timer
2939 * interrupt input. So just in case, if only one pin
2940 * was found above, try it both directly and through the
2944 if (intr_remapping_enabled)
2945 panic("BIOS bug: timer not connected to IO-APIC");
2949 } else if (pin2 == -1) {
2956 * Ok, does IRQ0 through the IOAPIC work?
2959 add_pin_to_irq_node(cfg, node, apic1, pin1);
2960 setup_timer_IRQ0_pin(apic1, pin1, cfg->vector);
2962 /* for edge trigger, setup_IO_APIC_irq already
2963 * leave it unmasked.
2964 * so only need to unmask if it is level-trigger
2965 * do we really have level trigger timer?
2968 idx = find_irq_entry(apic1, pin1, mp_INT);
2969 if (idx != -1 && irq_trigger(idx))
2970 unmask_IO_APIC_irq_desc(desc);
2972 if (timer_irq_works()) {
2973 if (nmi_watchdog == NMI_IO_APIC) {
2975 enable_8259A_irq(0);
2977 if (disable_timer_pin_1 > 0)
2978 clear_IO_APIC_pin(0, pin1);
2981 if (intr_remapping_enabled)
2982 panic("timer doesn't work through Interrupt-remapped IO-APIC");
2983 local_irq_disable();
2984 clear_IO_APIC_pin(apic1, pin1);
2986 apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: "
2987 "8254 timer not connected to IO-APIC\n");
2989 apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer "
2990 "(IRQ0) through the 8259A ...\n");
2991 apic_printk(APIC_QUIET, KERN_INFO
2992 "..... (found apic %d pin %d) ...\n", apic2, pin2);
2994 * legacy devices should be connected to IO APIC #0
2996 replace_pin_at_irq_node(cfg, node, apic1, pin1, apic2, pin2);
2997 setup_timer_IRQ0_pin(apic2, pin2, cfg->vector);
2998 enable_8259A_irq(0);
2999 if (timer_irq_works()) {
3000 apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
3001 timer_through_8259 = 1;
3002 if (nmi_watchdog == NMI_IO_APIC) {
3003 disable_8259A_irq(0);
3005 enable_8259A_irq(0);
3010 * Cleanup, just in case ...
3012 local_irq_disable();
3013 disable_8259A_irq(0);
3014 clear_IO_APIC_pin(apic2, pin2);
3015 apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n");
3018 if (nmi_watchdog == NMI_IO_APIC) {
3019 apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work "
3020 "through the IO-APIC - disabling NMI Watchdog!\n");
3021 nmi_watchdog = NMI_NONE;
3023 #ifdef CONFIG_X86_32
3027 apic_printk(APIC_QUIET, KERN_INFO
3028 "...trying to set up timer as Virtual Wire IRQ...\n");
3030 lapic_register_intr(0, desc);
3031 apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */
3032 enable_8259A_irq(0);
3034 if (timer_irq_works()) {
3035 apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
3038 local_irq_disable();
3039 disable_8259A_irq(0);
3040 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector);
3041 apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n");
3043 apic_printk(APIC_QUIET, KERN_INFO
3044 "...trying to set up timer as ExtINT IRQ...\n");
3048 apic_write(APIC_LVT0, APIC_DM_EXTINT);
3050 unlock_ExtINT_logic();
3052 if (timer_irq_works()) {
3053 apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
3056 local_irq_disable();
3057 apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
3058 panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
3059 "report. Then try booting with the 'noapic' option.\n");
3061 local_irq_restore(flags);
3065 * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
3066 * to devices. However there may be an I/O APIC pin available for
3067 * this interrupt regardless. The pin may be left unconnected, but
3068 * typically it will be reused as an ExtINT cascade interrupt for
3069 * the master 8259A. In the MPS case such a pin will normally be
3070 * reported as an ExtINT interrupt in the MP table. With ACPI
3071 * there is no provision for ExtINT interrupts, and in the absence
3072 * of an override it would be treated as an ordinary ISA I/O APIC
3073 * interrupt, that is edge-triggered and unmasked by default. We
3074 * used to do this, but it caused problems on some systems because
3075 * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
3076 * the same ExtINT cascade interrupt to drive the local APIC of the
3077 * bootstrap processor. Therefore we refrain from routing IRQ2 to
3078 * the I/O APIC in all cases now. No actual device should request
3079 * it anyway. --macro
3081 #define PIC_IRQS (1UL << PIC_CASCADE_IR)
3083 void __init setup_IO_APIC(void)
3087 * calling enable_IO_APIC() is moved to setup_local_APIC for BP
3089 io_apic_irqs = nr_legacy_irqs ? ~PIC_IRQS : ~0UL;
3091 apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n");
3093 * Set up IO-APIC IRQ routing.
3095 x86_init.mpparse.setup_ioapic_ids();
3098 setup_IO_APIC_irqs();
3099 init_IO_APIC_traps();
3105 * Called after all the initialization is done. If we didnt find any
3106 * APIC bugs then we can allow the modify fast path
3109 static int __init io_apic_bug_finalize(void)
3111 if (sis_apic_bug == -1)
3116 late_initcall(io_apic_bug_finalize);
3118 struct sysfs_ioapic_data {
3119 struct sys_device dev;
3120 struct IO_APIC_route_entry entry[0];
3122 static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];
3124 static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
3126 struct IO_APIC_route_entry *entry;
3127 struct sysfs_ioapic_data *data;
3130 data = container_of(dev, struct sysfs_ioapic_data, dev);
3131 entry = data->entry;
3132 for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ )
3133 *entry = ioapic_read_entry(dev->id, i);
3138 static int ioapic_resume(struct sys_device *dev)
3140 struct IO_APIC_route_entry *entry;
3141 struct sysfs_ioapic_data *data;
3142 unsigned long flags;
3143 union IO_APIC_reg_00 reg_00;
3146 data = container_of(dev, struct sysfs_ioapic_data, dev);
3147 entry = data->entry;
3149 spin_lock_irqsave(&ioapic_lock, flags);
3150 reg_00.raw = io_apic_read(dev->id, 0);
3151 if (reg_00.bits.ID != mp_ioapics[dev->id].apicid) {
3152 reg_00.bits.ID = mp_ioapics[dev->id].apicid;
3153 io_apic_write(dev->id, 0, reg_00.raw);
3155 spin_unlock_irqrestore(&ioapic_lock, flags);
3156 for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
3157 ioapic_write_entry(dev->id, i, entry[i]);
3162 static struct sysdev_class ioapic_sysdev_class = {
3164 .suspend = ioapic_suspend,
3165 .resume = ioapic_resume,
3168 static int __init ioapic_init_sysfs(void)
3170 struct sys_device * dev;
3173 error = sysdev_class_register(&ioapic_sysdev_class);
3177 for (i = 0; i < nr_ioapics; i++ ) {
3178 size = sizeof(struct sys_device) + nr_ioapic_registers[i]
3179 * sizeof(struct IO_APIC_route_entry);
3180 mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
3181 if (!mp_ioapic_data[i]) {
3182 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
3185 dev = &mp_ioapic_data[i]->dev;
3187 dev->cls = &ioapic_sysdev_class;
3188 error = sysdev_register(dev);
3190 kfree(mp_ioapic_data[i]);
3191 mp_ioapic_data[i] = NULL;
3192 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
3200 device_initcall(ioapic_init_sysfs);
3203 * Dynamic irq allocate and deallocation
3205 unsigned int create_irq_nr(unsigned int irq_want, int node)
3207 /* Allocate an unused irq */
3210 unsigned long flags;
3211 struct irq_cfg *cfg_new = NULL;
3212 struct irq_desc *desc_new = NULL;
3215 if (irq_want < nr_irqs_gsi)
3216 irq_want = nr_irqs_gsi;
3218 spin_lock_irqsave(&vector_lock, flags);
3219 for (new = irq_want; new < nr_irqs; new++) {
3220 desc_new = irq_to_desc_alloc_node(new, node);
3222 printk(KERN_INFO "can not get irq_desc for %d\n", new);
3225 cfg_new = desc_new->chip_data;
3227 if (cfg_new->vector != 0)
3230 desc_new = move_irq_desc(desc_new, node);
3231 cfg_new = desc_new->chip_data;
3233 if (__assign_irq_vector(new, cfg_new, apic->target_cpus()) == 0)
3237 spin_unlock_irqrestore(&vector_lock, flags);
3240 dynamic_irq_init(irq);
3241 /* restore it, in case dynamic_irq_init clear it */
3243 desc_new->chip_data = cfg_new;
3248 int create_irq(void)
3250 int node = cpu_to_node(boot_cpu_id);
3251 unsigned int irq_want;
3254 irq_want = nr_irqs_gsi;
3255 irq = create_irq_nr(irq_want, node);
3263 void destroy_irq(unsigned int irq)
3265 unsigned long flags;
3266 struct irq_cfg *cfg;
3267 struct irq_desc *desc;
3269 /* store it, in case dynamic_irq_cleanup clear it */
3270 desc = irq_to_desc(irq);
3271 cfg = desc->chip_data;
3272 dynamic_irq_cleanup(irq);
3273 /* connect back irq_cfg */
3274 desc->chip_data = cfg;
3277 spin_lock_irqsave(&vector_lock, flags);
3278 __clear_irq_vector(irq, cfg);
3279 spin_unlock_irqrestore(&vector_lock, flags);
3283 * MSI message composition
3285 #ifdef CONFIG_PCI_MSI
3286 static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq,
3287 struct msi_msg *msg, u8 hpet_id)
3289 struct irq_cfg *cfg;
3297 err = assign_irq_vector(irq, cfg, apic->target_cpus());
3301 dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
3303 if (irq_remapped(irq)) {
3308 ir_index = map_irq_to_irte_handle(irq, &sub_handle);
3309 BUG_ON(ir_index == -1);
3311 memset (&irte, 0, sizeof(irte));
3314 irte.dst_mode = apic->irq_dest_mode;
3315 irte.trigger_mode = 0; /* edge */
3316 irte.dlvry_mode = apic->irq_delivery_mode;
3317 irte.vector = cfg->vector;
3318 irte.dest_id = IRTE_DEST(dest);
3320 /* Set source-id of interrupt request */
3322 set_msi_sid(&irte, pdev);
3324 set_hpet_sid(&irte, hpet_id);
3326 modify_irte(irq, &irte);
3328 msg->address_hi = MSI_ADDR_BASE_HI;
3329 msg->data = sub_handle;
3330 msg->address_lo = MSI_ADDR_BASE_LO | MSI_ADDR_IR_EXT_INT |
3332 MSI_ADDR_IR_INDEX1(ir_index) |
3333 MSI_ADDR_IR_INDEX2(ir_index);
3335 if (x2apic_enabled())
3336 msg->address_hi = MSI_ADDR_BASE_HI |
3337 MSI_ADDR_EXT_DEST_ID(dest);
3339 msg->address_hi = MSI_ADDR_BASE_HI;
3343 ((apic->irq_dest_mode == 0) ?
3344 MSI_ADDR_DEST_MODE_PHYSICAL:
3345 MSI_ADDR_DEST_MODE_LOGICAL) |
3346 ((apic->irq_delivery_mode != dest_LowestPrio) ?
3347 MSI_ADDR_REDIRECTION_CPU:
3348 MSI_ADDR_REDIRECTION_LOWPRI) |
3349 MSI_ADDR_DEST_ID(dest);
3352 MSI_DATA_TRIGGER_EDGE |
3353 MSI_DATA_LEVEL_ASSERT |
3354 ((apic->irq_delivery_mode != dest_LowestPrio) ?
3355 MSI_DATA_DELIVERY_FIXED:
3356 MSI_DATA_DELIVERY_LOWPRI) |
3357 MSI_DATA_VECTOR(cfg->vector);
3363 static int set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
3365 struct irq_desc *desc = irq_to_desc(irq);
3366 struct irq_cfg *cfg;
3370 if (set_desc_affinity(desc, mask, &dest))
3373 cfg = desc->chip_data;
3375 read_msi_msg_desc(desc, &msg);
3377 msg.data &= ~MSI_DATA_VECTOR_MASK;
3378 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3379 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3380 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3382 write_msi_msg_desc(desc, &msg);
3386 #ifdef CONFIG_INTR_REMAP
3388 * Migrate the MSI irq to another cpumask. This migration is
3389 * done in the process context using interrupt-remapping hardware.
3392 ir_set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
3394 struct irq_desc *desc = irq_to_desc(irq);
3395 struct irq_cfg *cfg = desc->chip_data;
3399 if (get_irte(irq, &irte))
3402 if (set_desc_affinity(desc, mask, &dest))
3405 irte.vector = cfg->vector;
3406 irte.dest_id = IRTE_DEST(dest);
3409 * atomically update the IRTE with the new destination and vector.
3411 modify_irte(irq, &irte);
3414 * After this point, all the interrupts will start arriving
3415 * at the new destination. So, time to cleanup the previous
3416 * vector allocation.
3418 if (cfg->move_in_progress)
3419 send_cleanup_vector(cfg);
3425 #endif /* CONFIG_SMP */
3428 * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
3429 * which implement the MSI or MSI-X Capability Structure.
3431 static struct irq_chip msi_chip = {
3433 .unmask = unmask_msi_irq,
3434 .mask = mask_msi_irq,
3435 .ack = ack_apic_edge,
3437 .set_affinity = set_msi_irq_affinity,
3439 .retrigger = ioapic_retrigger_irq,
3442 static struct irq_chip msi_ir_chip = {
3443 .name = "IR-PCI-MSI",
3444 .unmask = unmask_msi_irq,
3445 .mask = mask_msi_irq,
3446 #ifdef CONFIG_INTR_REMAP
3447 .ack = ir_ack_apic_edge,
3449 .set_affinity = ir_set_msi_irq_affinity,
3452 .retrigger = ioapic_retrigger_irq,
3456 * Map the PCI dev to the corresponding remapping hardware unit
3457 * and allocate 'nvec' consecutive interrupt-remapping table entries
3460 static int msi_alloc_irte(struct pci_dev *dev, int irq, int nvec)
3462 struct intel_iommu *iommu;
3465 iommu = map_dev_to_ir(dev);
3468 "Unable to map PCI %s to iommu\n", pci_name(dev));
3472 index = alloc_irte(iommu, irq, nvec);
3475 "Unable to allocate %d IRTE for PCI %s\n", nvec,
3482 static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)
3487 ret = msi_compose_msg(dev, irq, &msg, -1);
3491 set_irq_msi(irq, msidesc);
3492 write_msi_msg(irq, &msg);
3494 if (irq_remapped(irq)) {
3495 struct irq_desc *desc = irq_to_desc(irq);
3497 * irq migration in process context
3499 desc->status |= IRQ_MOVE_PCNTXT;
3500 set_irq_chip_and_handler_name(irq, &msi_ir_chip, handle_edge_irq, "edge");
3502 set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge");
3504 dev_printk(KERN_DEBUG, &dev->dev, "irq %d for MSI/MSI-X\n", irq);
3509 int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
3512 int ret, sub_handle;
3513 struct msi_desc *msidesc;
3514 unsigned int irq_want;
3515 struct intel_iommu *iommu = NULL;
3519 /* x86 doesn't support multiple MSI yet */
3520 if (type == PCI_CAP_ID_MSI && nvec > 1)
3523 node = dev_to_node(&dev->dev);
3524 irq_want = nr_irqs_gsi;
3526 list_for_each_entry(msidesc, &dev->msi_list, list) {
3527 irq = create_irq_nr(irq_want, node);
3531 if (!intr_remapping_enabled)
3536 * allocate the consecutive block of IRTE's
3539 index = msi_alloc_irte(dev, irq, nvec);
3545 iommu = map_dev_to_ir(dev);
3551 * setup the mapping between the irq and the IRTE
3552 * base index, the sub_handle pointing to the
3553 * appropriate interrupt remap table entry.
3555 set_irte_irq(irq, iommu, index, sub_handle);
3558 ret = setup_msi_irq(dev, msidesc, irq);
3570 void arch_teardown_msi_irq(unsigned int irq)
3575 #if defined (CONFIG_DMAR) || defined (CONFIG_INTR_REMAP)
3577 static int dmar_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
3579 struct irq_desc *desc = irq_to_desc(irq);
3580 struct irq_cfg *cfg;
3584 if (set_desc_affinity(desc, mask, &dest))
3587 cfg = desc->chip_data;
3589 dmar_msi_read(irq, &msg);
3591 msg.data &= ~MSI_DATA_VECTOR_MASK;
3592 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3593 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3594 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3596 dmar_msi_write(irq, &msg);
3601 #endif /* CONFIG_SMP */
3603 static struct irq_chip dmar_msi_type = {
3605 .unmask = dmar_msi_unmask,
3606 .mask = dmar_msi_mask,
3607 .ack = ack_apic_edge,
3609 .set_affinity = dmar_msi_set_affinity,
3611 .retrigger = ioapic_retrigger_irq,
3614 int arch_setup_dmar_msi(unsigned int irq)
3619 ret = msi_compose_msg(NULL, irq, &msg, -1);
3622 dmar_msi_write(irq, &msg);
3623 set_irq_chip_and_handler_name(irq, &dmar_msi_type, handle_edge_irq,
3629 #ifdef CONFIG_HPET_TIMER
3632 static int hpet_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
3634 struct irq_desc *desc = irq_to_desc(irq);
3635 struct irq_cfg *cfg;
3639 if (set_desc_affinity(desc, mask, &dest))
3642 cfg = desc->chip_data;
3644 hpet_msi_read(irq, &msg);
3646 msg.data &= ~MSI_DATA_VECTOR_MASK;
3647 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3648 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3649 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3651 hpet_msi_write(irq, &msg);
3656 #endif /* CONFIG_SMP */
3658 static struct irq_chip ir_hpet_msi_type = {
3659 .name = "IR-HPET_MSI",
3660 .unmask = hpet_msi_unmask,
3661 .mask = hpet_msi_mask,
3662 #ifdef CONFIG_INTR_REMAP
3663 .ack = ir_ack_apic_edge,
3665 .set_affinity = ir_set_msi_irq_affinity,
3668 .retrigger = ioapic_retrigger_irq,
3671 static struct irq_chip hpet_msi_type = {
3673 .unmask = hpet_msi_unmask,
3674 .mask = hpet_msi_mask,
3675 .ack = ack_apic_edge,
3677 .set_affinity = hpet_msi_set_affinity,
3679 .retrigger = ioapic_retrigger_irq,
3682 int arch_setup_hpet_msi(unsigned int irq, unsigned int id)
3686 struct irq_desc *desc = irq_to_desc(irq);
3688 if (intr_remapping_enabled) {
3689 struct intel_iommu *iommu = map_hpet_to_ir(id);
3695 index = alloc_irte(iommu, irq, 1);
3700 ret = msi_compose_msg(NULL, irq, &msg, id);
3704 hpet_msi_write(irq, &msg);
3705 desc->status |= IRQ_MOVE_PCNTXT;
3706 if (irq_remapped(irq))
3707 set_irq_chip_and_handler_name(irq, &ir_hpet_msi_type,
3708 handle_edge_irq, "edge");
3710 set_irq_chip_and_handler_name(irq, &hpet_msi_type,
3711 handle_edge_irq, "edge");
3717 #endif /* CONFIG_PCI_MSI */
3719 * Hypertransport interrupt support
3721 #ifdef CONFIG_HT_IRQ
3725 static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector)
3727 struct ht_irq_msg msg;
3728 fetch_ht_irq_msg(irq, &msg);
3730 msg.address_lo &= ~(HT_IRQ_LOW_VECTOR_MASK | HT_IRQ_LOW_DEST_ID_MASK);
3731 msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
3733 msg.address_lo |= HT_IRQ_LOW_VECTOR(vector) | HT_IRQ_LOW_DEST_ID(dest);
3734 msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest);
3736 write_ht_irq_msg(irq, &msg);
3739 static int set_ht_irq_affinity(unsigned int irq, const struct cpumask *mask)
3741 struct irq_desc *desc = irq_to_desc(irq);
3742 struct irq_cfg *cfg;
3745 if (set_desc_affinity(desc, mask, &dest))
3748 cfg = desc->chip_data;
3750 target_ht_irq(irq, dest, cfg->vector);
3757 static struct irq_chip ht_irq_chip = {
3759 .mask = mask_ht_irq,
3760 .unmask = unmask_ht_irq,
3761 .ack = ack_apic_edge,
3763 .set_affinity = set_ht_irq_affinity,
3765 .retrigger = ioapic_retrigger_irq,
3768 int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
3770 struct irq_cfg *cfg;
3777 err = assign_irq_vector(irq, cfg, apic->target_cpus());
3779 struct ht_irq_msg msg;
3782 dest = apic->cpu_mask_to_apicid_and(cfg->domain,
3783 apic->target_cpus());
3785 msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest);
3789 HT_IRQ_LOW_DEST_ID(dest) |
3790 HT_IRQ_LOW_VECTOR(cfg->vector) |
3791 ((apic->irq_dest_mode == 0) ?
3792 HT_IRQ_LOW_DM_PHYSICAL :
3793 HT_IRQ_LOW_DM_LOGICAL) |
3794 HT_IRQ_LOW_RQEOI_EDGE |
3795 ((apic->irq_delivery_mode != dest_LowestPrio) ?
3796 HT_IRQ_LOW_MT_FIXED :
3797 HT_IRQ_LOW_MT_ARBITRATED) |
3798 HT_IRQ_LOW_IRQ_MASKED;
3800 write_ht_irq_msg(irq, &msg);
3802 set_irq_chip_and_handler_name(irq, &ht_irq_chip,
3803 handle_edge_irq, "edge");
3805 dev_printk(KERN_DEBUG, &dev->dev, "irq %d for HT\n", irq);
3809 #endif /* CONFIG_HT_IRQ */
3811 int __init io_apic_get_redir_entries (int ioapic)
3813 union IO_APIC_reg_01 reg_01;
3814 unsigned long flags;
3816 spin_lock_irqsave(&ioapic_lock, flags);
3817 reg_01.raw = io_apic_read(ioapic, 1);
3818 spin_unlock_irqrestore(&ioapic_lock, flags);
3820 return reg_01.bits.entries;
3823 void __init probe_nr_irqs_gsi(void)
3827 nr = acpi_probe_gsi();
3828 if (nr > nr_irqs_gsi) {
3831 /* for acpi=off or acpi is not compiled in */
3835 for (idx = 0; idx < nr_ioapics; idx++)
3836 nr += io_apic_get_redir_entries(idx) + 1;
3838 if (nr > nr_irqs_gsi)
3842 printk(KERN_DEBUG "nr_irqs_gsi: %d\n", nr_irqs_gsi);
3845 #ifdef CONFIG_SPARSE_IRQ
3846 int __init arch_probe_nr_irqs(void)
3850 if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
3851 nr_irqs = NR_VECTORS * nr_cpu_ids;
3853 nr = nr_irqs_gsi + 8 * nr_cpu_ids;
3854 #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
3856 * for MSI and HT dyn irq
3858 nr += nr_irqs_gsi * 16;
3867 static int __io_apic_set_pci_routing(struct device *dev, int irq,
3868 struct io_apic_irq_attr *irq_attr)
3870 struct irq_desc *desc;
3871 struct irq_cfg *cfg;
3874 int trigger, polarity;
3876 ioapic = irq_attr->ioapic;
3877 if (!IO_APIC_IRQ(irq)) {
3878 apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
3884 node = dev_to_node(dev);
3886 node = cpu_to_node(boot_cpu_id);
3888 desc = irq_to_desc_alloc_node(irq, node);
3890 printk(KERN_INFO "can not get irq_desc %d\n", irq);
3894 pin = irq_attr->ioapic_pin;
3895 trigger = irq_attr->trigger;
3896 polarity = irq_attr->polarity;
3899 * IRQs < 16 are already in the irq_2_pin[] map
3901 if (irq >= nr_legacy_irqs) {
3902 cfg = desc->chip_data;
3903 if (add_pin_to_irq_node_nopanic(cfg, node, ioapic, pin)) {
3904 printk(KERN_INFO "can not add pin %d for irq %d\n",
3910 setup_IO_APIC_irq(ioapic, pin, irq, desc, trigger, polarity);
3915 int io_apic_set_pci_routing(struct device *dev, int irq,
3916 struct io_apic_irq_attr *irq_attr)
3920 * Avoid pin reprogramming. PRTs typically include entries
3921 * with redundant pin->gsi mappings (but unique PCI devices);
3922 * we only program the IOAPIC on the first.
3924 ioapic = irq_attr->ioapic;
3925 pin = irq_attr->ioapic_pin;
3926 if (test_bit(pin, mp_ioapic_routing[ioapic].pin_programmed)) {
3927 pr_debug("Pin %d-%d already programmed\n",
3928 mp_ioapics[ioapic].apicid, pin);
3931 set_bit(pin, mp_ioapic_routing[ioapic].pin_programmed);
3933 return __io_apic_set_pci_routing(dev, irq, irq_attr);
3936 u8 __init io_apic_unique_id(u8 id)
3938 #ifdef CONFIG_X86_32
3939 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
3940 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
3941 return io_apic_get_unique_id(nr_ioapics, id);
3946 DECLARE_BITMAP(used, 256);
3948 bitmap_zero(used, 256);
3949 for (i = 0; i < nr_ioapics; i++) {
3950 struct mpc_ioapic *ia = &mp_ioapics[i];
3951 __set_bit(ia->apicid, used);
3953 if (!test_bit(id, used))
3955 return find_first_zero_bit(used, 256);
3959 #ifdef CONFIG_X86_32
3960 int __init io_apic_get_unique_id(int ioapic, int apic_id)
3962 union IO_APIC_reg_00 reg_00;
3963 static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
3965 unsigned long flags;
3969 * The P4 platform supports up to 256 APIC IDs on two separate APIC
3970 * buses (one for LAPICs, one for IOAPICs), where predecessors only
3971 * supports up to 16 on one shared APIC bus.
3973 * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
3974 * advantage of new APIC bus architecture.
3977 if (physids_empty(apic_id_map))
3978 apic->ioapic_phys_id_map(&phys_cpu_present_map, &apic_id_map);
3980 spin_lock_irqsave(&ioapic_lock, flags);
3981 reg_00.raw = io_apic_read(ioapic, 0);
3982 spin_unlock_irqrestore(&ioapic_lock, flags);
3984 if (apic_id >= get_physical_broadcast()) {
3985 printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
3986 "%d\n", ioapic, apic_id, reg_00.bits.ID);
3987 apic_id = reg_00.bits.ID;
3991 * Every APIC in a system must have a unique ID or we get lots of nice
3992 * 'stuck on smp_invalidate_needed IPI wait' messages.
3994 if (apic->check_apicid_used(&apic_id_map, apic_id)) {
3996 for (i = 0; i < get_physical_broadcast(); i++) {
3997 if (!apic->check_apicid_used(&apic_id_map, i))
4001 if (i == get_physical_broadcast())
4002 panic("Max apic_id exceeded!\n");
4004 printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
4005 "trying %d\n", ioapic, apic_id, i);
4010 apic->apicid_to_cpu_present(apic_id, &tmp);
4011 physids_or(apic_id_map, apic_id_map, tmp);
4013 if (reg_00.bits.ID != apic_id) {
4014 reg_00.bits.ID = apic_id;
4016 spin_lock_irqsave(&ioapic_lock, flags);
4017 io_apic_write(ioapic, 0, reg_00.raw);
4018 reg_00.raw = io_apic_read(ioapic, 0);
4019 spin_unlock_irqrestore(&ioapic_lock, flags);
4022 if (reg_00.bits.ID != apic_id) {
4023 printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
4028 apic_printk(APIC_VERBOSE, KERN_INFO
4029 "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
4035 int __init io_apic_get_version(int ioapic)
4037 union IO_APIC_reg_01 reg_01;
4038 unsigned long flags;
4040 spin_lock_irqsave(&ioapic_lock, flags);
4041 reg_01.raw = io_apic_read(ioapic, 1);
4042 spin_unlock_irqrestore(&ioapic_lock, flags);
4044 return reg_01.bits.version;
4047 int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity)
4051 if (skip_ioapic_setup)
4054 for (i = 0; i < mp_irq_entries; i++)
4055 if (mp_irqs[i].irqtype == mp_INT &&
4056 mp_irqs[i].srcbusirq == bus_irq)
4058 if (i >= mp_irq_entries)
4061 *trigger = irq_trigger(i);
4062 *polarity = irq_polarity(i);
4067 * This function currently is only a helper for the i386 smp boot process where
4068 * we need to reprogram the ioredtbls to cater for the cpus which have come online
4069 * so mask in all cases should simply be apic->target_cpus()
4072 void __init setup_ioapic_dest(void)
4074 int pin, ioapic = 0, irq, irq_entry;
4075 struct irq_desc *desc;
4076 const struct cpumask *mask;
4078 if (skip_ioapic_setup == 1)
4082 if (!acpi_disabled && acpi_ioapic) {
4083 ioapic = mp_find_ioapic(0);
4089 for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
4090 irq_entry = find_irq_entry(ioapic, pin, mp_INT);
4091 if (irq_entry == -1)
4093 irq = pin_2_irq(irq_entry, ioapic, pin);
4095 desc = irq_to_desc(irq);
4098 * Honour affinities which have been set in early boot
4101 (IRQ_NO_BALANCING | IRQ_AFFINITY_SET))
4102 mask = desc->affinity;
4104 mask = apic->target_cpus();
4106 if (intr_remapping_enabled)
4107 set_ir_ioapic_affinity_irq_desc(desc, mask);
4109 set_ioapic_affinity_irq_desc(desc, mask);
4115 #define IOAPIC_RESOURCE_NAME_SIZE 11
4117 static struct resource *ioapic_resources;
4119 static struct resource * __init ioapic_setup_resources(int nr_ioapics)
4122 struct resource *res;
4126 if (nr_ioapics <= 0)
4129 n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource);
4132 mem = alloc_bootmem(n);
4135 mem += sizeof(struct resource) * nr_ioapics;
4137 for (i = 0; i < nr_ioapics; i++) {
4139 res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY;
4140 snprintf(mem, IOAPIC_RESOURCE_NAME_SIZE, "IOAPIC %u", i);
4141 mem += IOAPIC_RESOURCE_NAME_SIZE;
4144 ioapic_resources = res;
4149 void __init ioapic_init_mappings(void)
4151 unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
4152 struct resource *ioapic_res;
4155 ioapic_res = ioapic_setup_resources(nr_ioapics);
4156 for (i = 0; i < nr_ioapics; i++) {
4157 if (smp_found_config) {
4158 ioapic_phys = mp_ioapics[i].apicaddr;
4159 #ifdef CONFIG_X86_32
4162 "WARNING: bogus zero IO-APIC "
4163 "address found in MPTABLE, "
4164 "disabling IO/APIC support!\n");
4165 smp_found_config = 0;
4166 skip_ioapic_setup = 1;
4167 goto fake_ioapic_page;
4171 #ifdef CONFIG_X86_32
4174 ioapic_phys = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
4175 ioapic_phys = __pa(ioapic_phys);
4177 set_fixmap_nocache(idx, ioapic_phys);
4178 apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n",
4179 __fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK),
4183 ioapic_res->start = ioapic_phys;
4184 ioapic_res->end = ioapic_phys + IO_APIC_SLOT_SIZE - 1;
4189 void __init ioapic_insert_resources(void)
4192 struct resource *r = ioapic_resources;
4197 "IO APIC resources couldn't be allocated.\n");
4201 for (i = 0; i < nr_ioapics; i++) {
4202 insert_resource(&iomem_resource, r);
4207 int mp_find_ioapic(int gsi)
4211 /* Find the IOAPIC that manages this GSI. */
4212 for (i = 0; i < nr_ioapics; i++) {
4213 if ((gsi >= mp_gsi_routing[i].gsi_base)
4214 && (gsi <= mp_gsi_routing[i].gsi_end))
4218 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
4222 int mp_find_ioapic_pin(int ioapic, int gsi)
4224 if (WARN_ON(ioapic == -1))
4226 if (WARN_ON(gsi > mp_gsi_routing[ioapic].gsi_end))
4229 return gsi - mp_gsi_routing[ioapic].gsi_base;
4232 static int bad_ioapic(unsigned long address)
4234 if (nr_ioapics >= MAX_IO_APICS) {
4235 printk(KERN_WARNING "WARING: Max # of I/O APICs (%d) exceeded "
4236 "(found %d), skipping\n", MAX_IO_APICS, nr_ioapics);
4240 printk(KERN_WARNING "WARNING: Bogus (zero) I/O APIC address"
4241 " found in table, skipping!\n");
4247 void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
4251 if (bad_ioapic(address))
4256 mp_ioapics[idx].type = MP_IOAPIC;
4257 mp_ioapics[idx].flags = MPC_APIC_USABLE;
4258 mp_ioapics[idx].apicaddr = address;
4260 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
4261 mp_ioapics[idx].apicid = io_apic_unique_id(id);
4262 mp_ioapics[idx].apicver = io_apic_get_version(idx);
4265 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
4266 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
4268 mp_gsi_routing[idx].gsi_base = gsi_base;
4269 mp_gsi_routing[idx].gsi_end = gsi_base +
4270 io_apic_get_redir_entries(idx);
4272 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
4273 "GSI %d-%d\n", idx, mp_ioapics[idx].apicid,
4274 mp_ioapics[idx].apicver, mp_ioapics[idx].apicaddr,
4275 mp_gsi_routing[idx].gsi_base, mp_gsi_routing[idx].gsi_end);