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() */
39 #include <linux/slab.h>
41 #include <acpi/acpi_bus.h>
43 #include <linux/bootmem.h>
44 #include <linux/dmar.h>
45 #include <linux/hpet.h>
52 #include <asm/proto.h>
55 #include <asm/timer.h>
56 #include <asm/i8259.h>
58 #include <asm/msidef.h>
59 #include <asm/hypertransport.h>
60 #include <asm/setup.h>
61 #include <asm/irq_remapping.h>
63 #include <asm/hw_irq.h>
67 #define __apicdebuginit(type) static type __init
68 #define for_each_irq_pin(entry, head) \
69 for (entry = head; entry; entry = entry->next)
72 * Is the SiS APIC rmw bug present ?
73 * -1 = don't know, 0 = no, 1 = yes
75 int sis_apic_bug = -1;
77 static DEFINE_RAW_SPINLOCK(ioapic_lock);
78 static DEFINE_RAW_SPINLOCK(vector_lock);
81 * # of IRQ routing registers
83 int nr_ioapic_registers[MAX_IO_APICS];
85 /* I/O APIC entries */
86 struct mpc_ioapic mp_ioapics[MAX_IO_APICS];
89 /* IO APIC gsi routing info */
90 struct mp_ioapic_gsi mp_gsi_routing[MAX_IO_APICS];
92 /* The one past the highest gsi number used */
95 /* MP IRQ source entries */
96 struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES];
98 /* # of MP IRQ source entries */
102 static int nr_irqs_gsi = NR_IRQS_LEGACY;
104 #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
105 int mp_bus_id_to_type[MAX_MP_BUSSES];
108 DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
110 int skip_ioapic_setup;
112 void arch_disable_smp_support(void)
116 noioapicreroute = -1;
118 skip_ioapic_setup = 1;
121 static int __init parse_noapic(char *str)
123 /* disable IO-APIC */
124 arch_disable_smp_support();
127 early_param("noapic", parse_noapic);
129 struct irq_pin_list {
131 struct irq_pin_list *next;
134 static struct irq_pin_list *get_one_free_irq_2_pin(int node)
136 struct irq_pin_list *pin;
138 pin = kzalloc_node(sizeof(*pin), GFP_ATOMIC, node);
143 /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
144 #ifdef CONFIG_SPARSE_IRQ
145 static struct irq_cfg irq_cfgx[NR_IRQS_LEGACY];
147 static struct irq_cfg irq_cfgx[NR_IRQS];
150 int __init arch_early_irq_init(void)
155 if (!legacy_pic->nr_legacy_irqs) {
161 count = ARRAY_SIZE(irq_cfgx);
162 node = cpu_to_node(0);
164 for (i = 0; i < count; i++) {
165 set_irq_chip_data(i, &cfg[i]);
166 zalloc_cpumask_var_node(&cfg[i].domain, GFP_NOWAIT, node);
167 zalloc_cpumask_var_node(&cfg[i].old_domain, GFP_NOWAIT, node);
169 * For legacy IRQ's, start with assigning irq0 to irq15 to
170 * IRQ0_VECTOR to IRQ15_VECTOR on cpu 0.
172 if (i < legacy_pic->nr_legacy_irqs) {
173 cfg[i].vector = IRQ0_VECTOR + i;
174 cpumask_set_cpu(0, cfg[i].domain);
181 #ifdef CONFIG_SPARSE_IRQ
182 struct irq_cfg *irq_cfg(unsigned int irq)
184 return get_irq_chip_data(irq);
187 static struct irq_cfg *get_one_free_irq_cfg(int node)
191 cfg = kzalloc_node(sizeof(*cfg), GFP_ATOMIC, node);
193 if (!zalloc_cpumask_var_node(&cfg->domain, GFP_ATOMIC, node)) {
196 } else if (!zalloc_cpumask_var_node(&cfg->old_domain,
198 free_cpumask_var(cfg->domain);
207 int arch_init_chip_data(struct irq_desc *desc, int node)
211 cfg = get_irq_desc_chip_data(desc);
213 cfg = get_one_free_irq_cfg(node);
214 desc->chip_data = cfg;
216 printk(KERN_ERR "can not alloc irq_cfg\n");
224 /* for move_irq_desc */
226 init_copy_irq_2_pin(struct irq_cfg *old_cfg, struct irq_cfg *cfg, int node)
228 struct irq_pin_list *old_entry, *head, *tail, *entry;
230 cfg->irq_2_pin = NULL;
231 old_entry = old_cfg->irq_2_pin;
235 entry = get_one_free_irq_2_pin(node);
239 entry->apic = old_entry->apic;
240 entry->pin = old_entry->pin;
243 old_entry = old_entry->next;
245 entry = get_one_free_irq_2_pin(node);
253 /* still use the old one */
256 entry->apic = old_entry->apic;
257 entry->pin = old_entry->pin;
260 old_entry = old_entry->next;
264 cfg->irq_2_pin = head;
267 static void free_irq_2_pin(struct irq_cfg *old_cfg, struct irq_cfg *cfg)
269 struct irq_pin_list *entry, *next;
271 if (old_cfg->irq_2_pin == cfg->irq_2_pin)
274 entry = old_cfg->irq_2_pin;
281 old_cfg->irq_2_pin = NULL;
284 void arch_init_copy_chip_data(struct irq_desc *old_desc,
285 struct irq_desc *desc, int node)
288 struct irq_cfg *old_cfg;
290 cfg = get_one_free_irq_cfg(node);
295 desc->chip_data = cfg;
297 old_cfg = old_desc->chip_data;
299 cfg->vector = old_cfg->vector;
300 cfg->move_in_progress = old_cfg->move_in_progress;
301 cpumask_copy(cfg->domain, old_cfg->domain);
302 cpumask_copy(cfg->old_domain, old_cfg->old_domain);
304 init_copy_irq_2_pin(old_cfg, cfg, node);
307 static void free_irq_cfg(struct irq_cfg *cfg)
309 free_cpumask_var(cfg->domain);
310 free_cpumask_var(cfg->old_domain);
314 void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc)
316 struct irq_cfg *old_cfg, *cfg;
318 old_cfg = get_irq_desc_chip_data(old_desc);
319 cfg = get_irq_desc_chip_data(desc);
325 free_irq_2_pin(old_cfg, cfg);
326 free_irq_cfg(old_cfg);
327 old_desc->chip_data = NULL;
330 /* end for move_irq_desc */
333 struct irq_cfg *irq_cfg(unsigned int irq)
335 return irq < nr_irqs ? irq_cfgx + irq : NULL;
342 unsigned int unused[3];
344 unsigned int unused2[11];
348 static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
350 return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
351 + (mp_ioapics[idx].apicaddr & ~PAGE_MASK);
354 static inline void io_apic_eoi(unsigned int apic, unsigned int vector)
356 struct io_apic __iomem *io_apic = io_apic_base(apic);
357 writel(vector, &io_apic->eoi);
360 static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
362 struct io_apic __iomem *io_apic = io_apic_base(apic);
363 writel(reg, &io_apic->index);
364 return readl(&io_apic->data);
367 static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value)
369 struct io_apic __iomem *io_apic = io_apic_base(apic);
370 writel(reg, &io_apic->index);
371 writel(value, &io_apic->data);
375 * Re-write a value: to be used for read-modify-write
376 * cycles where the read already set up the index register.
378 * Older SiS APIC requires we rewrite the index register
380 static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
382 struct io_apic __iomem *io_apic = io_apic_base(apic);
385 writel(reg, &io_apic->index);
386 writel(value, &io_apic->data);
389 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
391 struct irq_pin_list *entry;
394 raw_spin_lock_irqsave(&ioapic_lock, flags);
395 for_each_irq_pin(entry, cfg->irq_2_pin) {
400 reg = io_apic_read(entry->apic, 0x10 + pin*2);
401 /* Is the remote IRR bit set? */
402 if (reg & IO_APIC_REDIR_REMOTE_IRR) {
403 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
407 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
413 struct { u32 w1, w2; };
414 struct IO_APIC_route_entry entry;
417 static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
419 union entry_union eu;
421 raw_spin_lock_irqsave(&ioapic_lock, flags);
422 eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
423 eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
424 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
429 * When we write a new IO APIC routing entry, we need to write the high
430 * word first! If the mask bit in the low word is clear, we will enable
431 * the interrupt, and we need to make sure the entry is fully populated
432 * before that happens.
435 __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
437 union entry_union eu = {{0, 0}};
440 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
441 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
444 void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
447 raw_spin_lock_irqsave(&ioapic_lock, flags);
448 __ioapic_write_entry(apic, pin, e);
449 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
453 * When we mask an IO APIC routing entry, we need to write the low
454 * word first, in order to set the mask bit before we change the
457 static void ioapic_mask_entry(int apic, int pin)
460 union entry_union eu = { .entry.mask = 1 };
462 raw_spin_lock_irqsave(&ioapic_lock, flags);
463 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
464 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
465 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
469 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
470 * shared ISA-space IRQs, so we have to support them. We are super
471 * fast in the common case, and fast for shared ISA-space IRQs.
474 add_pin_to_irq_node_nopanic(struct irq_cfg *cfg, int node, int apic, int pin)
476 struct irq_pin_list **last, *entry;
478 /* don't allow duplicates */
479 last = &cfg->irq_2_pin;
480 for_each_irq_pin(entry, cfg->irq_2_pin) {
481 if (entry->apic == apic && entry->pin == pin)
486 entry = get_one_free_irq_2_pin(node);
488 printk(KERN_ERR "can not alloc irq_pin_list (%d,%d,%d)\n",
499 static void add_pin_to_irq_node(struct irq_cfg *cfg, int node, int apic, int pin)
501 if (add_pin_to_irq_node_nopanic(cfg, node, apic, pin))
502 panic("IO-APIC: failed to add irq-pin. Can not proceed\n");
506 * Reroute an IRQ to a different pin.
508 static void __init replace_pin_at_irq_node(struct irq_cfg *cfg, int node,
509 int oldapic, int oldpin,
510 int newapic, int newpin)
512 struct irq_pin_list *entry;
514 for_each_irq_pin(entry, cfg->irq_2_pin) {
515 if (entry->apic == oldapic && entry->pin == oldpin) {
516 entry->apic = newapic;
518 /* every one is different, right? */
523 /* old apic/pin didn't exist, so just add new ones */
524 add_pin_to_irq_node(cfg, node, newapic, newpin);
527 static void __io_apic_modify_irq(struct irq_pin_list *entry,
528 int mask_and, int mask_or,
529 void (*final)(struct irq_pin_list *entry))
531 unsigned int reg, pin;
534 reg = io_apic_read(entry->apic, 0x10 + pin * 2);
537 io_apic_modify(entry->apic, 0x10 + pin * 2, reg);
542 static void io_apic_modify_irq(struct irq_cfg *cfg,
543 int mask_and, int mask_or,
544 void (*final)(struct irq_pin_list *entry))
546 struct irq_pin_list *entry;
548 for_each_irq_pin(entry, cfg->irq_2_pin)
549 __io_apic_modify_irq(entry, mask_and, mask_or, final);
552 static void __mask_and_edge_IO_APIC_irq(struct irq_pin_list *entry)
554 __io_apic_modify_irq(entry, ~IO_APIC_REDIR_LEVEL_TRIGGER,
555 IO_APIC_REDIR_MASKED, NULL);
558 static void __unmask_and_level_IO_APIC_irq(struct irq_pin_list *entry)
560 __io_apic_modify_irq(entry, ~IO_APIC_REDIR_MASKED,
561 IO_APIC_REDIR_LEVEL_TRIGGER, NULL);
564 static void io_apic_sync(struct irq_pin_list *entry)
567 * Synchronize the IO-APIC and the CPU by doing
568 * a dummy read from the IO-APIC
570 struct io_apic __iomem *io_apic;
571 io_apic = io_apic_base(entry->apic);
572 readl(&io_apic->data);
575 static void mask_ioapic(struct irq_cfg *cfg)
579 raw_spin_lock_irqsave(&ioapic_lock, flags);
580 io_apic_modify_irq(cfg, ~0, IO_APIC_REDIR_MASKED, &io_apic_sync);
581 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
584 static void mask_ioapic_irq(struct irq_data *data)
586 mask_ioapic(data->chip_data);
589 static void __unmask_ioapic(struct irq_cfg *cfg)
591 io_apic_modify_irq(cfg, ~IO_APIC_REDIR_MASKED, 0, NULL);
594 static void unmask_ioapic(struct irq_cfg *cfg)
598 raw_spin_lock_irqsave(&ioapic_lock, flags);
599 __unmask_ioapic(cfg);
600 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
603 static void unmask_ioapic_irq(struct irq_data *data)
605 unmask_ioapic(data->chip_data);
608 static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
610 struct IO_APIC_route_entry entry;
612 /* Check delivery_mode to be sure we're not clearing an SMI pin */
613 entry = ioapic_read_entry(apic, pin);
614 if (entry.delivery_mode == dest_SMI)
617 * Disable it in the IO-APIC irq-routing table:
619 ioapic_mask_entry(apic, pin);
622 static void clear_IO_APIC (void)
626 for (apic = 0; apic < nr_ioapics; apic++)
627 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
628 clear_IO_APIC_pin(apic, pin);
633 * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
634 * specific CPU-side IRQs.
638 static int pirq_entries[MAX_PIRQS] = {
639 [0 ... MAX_PIRQS - 1] = -1
642 static int __init ioapic_pirq_setup(char *str)
645 int ints[MAX_PIRQS+1];
647 get_options(str, ARRAY_SIZE(ints), ints);
649 apic_printk(APIC_VERBOSE, KERN_INFO
650 "PIRQ redirection, working around broken MP-BIOS.\n");
652 if (ints[0] < MAX_PIRQS)
655 for (i = 0; i < max; i++) {
656 apic_printk(APIC_VERBOSE, KERN_DEBUG
657 "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
659 * PIRQs are mapped upside down, usually.
661 pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
666 __setup("pirq=", ioapic_pirq_setup);
667 #endif /* CONFIG_X86_32 */
669 struct IO_APIC_route_entry **alloc_ioapic_entries(void)
672 struct IO_APIC_route_entry **ioapic_entries;
674 ioapic_entries = kzalloc(sizeof(*ioapic_entries) * nr_ioapics,
679 for (apic = 0; apic < nr_ioapics; apic++) {
680 ioapic_entries[apic] =
681 kzalloc(sizeof(struct IO_APIC_route_entry) *
682 nr_ioapic_registers[apic], GFP_ATOMIC);
683 if (!ioapic_entries[apic])
687 return ioapic_entries;
691 kfree(ioapic_entries[apic]);
692 kfree(ioapic_entries);
698 * Saves all the IO-APIC RTE's
700 int save_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
707 for (apic = 0; apic < nr_ioapics; apic++) {
708 if (!ioapic_entries[apic])
711 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
712 ioapic_entries[apic][pin] =
713 ioapic_read_entry(apic, pin);
720 * Mask all IO APIC entries.
722 void mask_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
729 for (apic = 0; apic < nr_ioapics; apic++) {
730 if (!ioapic_entries[apic])
733 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
734 struct IO_APIC_route_entry entry;
736 entry = ioapic_entries[apic][pin];
739 ioapic_write_entry(apic, pin, entry);
746 * Restore IO APIC entries which was saved in ioapic_entries.
748 int restore_IO_APIC_setup(struct IO_APIC_route_entry **ioapic_entries)
755 for (apic = 0; apic < nr_ioapics; apic++) {
756 if (!ioapic_entries[apic])
759 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
760 ioapic_write_entry(apic, pin,
761 ioapic_entries[apic][pin]);
766 void free_ioapic_entries(struct IO_APIC_route_entry **ioapic_entries)
770 for (apic = 0; apic < nr_ioapics; apic++)
771 kfree(ioapic_entries[apic]);
773 kfree(ioapic_entries);
777 * Find the IRQ entry number of a certain pin.
779 static int find_irq_entry(int apic, int pin, int type)
783 for (i = 0; i < mp_irq_entries; i++)
784 if (mp_irqs[i].irqtype == type &&
785 (mp_irqs[i].dstapic == mp_ioapics[apic].apicid ||
786 mp_irqs[i].dstapic == MP_APIC_ALL) &&
787 mp_irqs[i].dstirq == pin)
794 * Find the pin to which IRQ[irq] (ISA) is connected
796 static int __init find_isa_irq_pin(int irq, int type)
800 for (i = 0; i < mp_irq_entries; i++) {
801 int lbus = mp_irqs[i].srcbus;
803 if (test_bit(lbus, mp_bus_not_pci) &&
804 (mp_irqs[i].irqtype == type) &&
805 (mp_irqs[i].srcbusirq == irq))
807 return mp_irqs[i].dstirq;
812 static int __init find_isa_irq_apic(int irq, int type)
816 for (i = 0; i < mp_irq_entries; i++) {
817 int lbus = mp_irqs[i].srcbus;
819 if (test_bit(lbus, mp_bus_not_pci) &&
820 (mp_irqs[i].irqtype == type) &&
821 (mp_irqs[i].srcbusirq == irq))
824 if (i < mp_irq_entries) {
826 for(apic = 0; apic < nr_ioapics; apic++) {
827 if (mp_ioapics[apic].apicid == mp_irqs[i].dstapic)
835 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
837 * EISA Edge/Level control register, ELCR
839 static int EISA_ELCR(unsigned int irq)
841 if (irq < legacy_pic->nr_legacy_irqs) {
842 unsigned int port = 0x4d0 + (irq >> 3);
843 return (inb(port) >> (irq & 7)) & 1;
845 apic_printk(APIC_VERBOSE, KERN_INFO
846 "Broken MPtable reports ISA irq %d\n", irq);
852 /* ISA interrupts are always polarity zero edge triggered,
853 * when listed as conforming in the MP table. */
855 #define default_ISA_trigger(idx) (0)
856 #define default_ISA_polarity(idx) (0)
858 /* EISA interrupts are always polarity zero and can be edge or level
859 * trigger depending on the ELCR value. If an interrupt is listed as
860 * EISA conforming in the MP table, that means its trigger type must
861 * be read in from the ELCR */
863 #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].srcbusirq))
864 #define default_EISA_polarity(idx) default_ISA_polarity(idx)
866 /* PCI interrupts are always polarity one level triggered,
867 * when listed as conforming in the MP table. */
869 #define default_PCI_trigger(idx) (1)
870 #define default_PCI_polarity(idx) (1)
872 /* MCA interrupts are always polarity zero level triggered,
873 * when listed as conforming in the MP table. */
875 #define default_MCA_trigger(idx) (1)
876 #define default_MCA_polarity(idx) default_ISA_polarity(idx)
878 static int MPBIOS_polarity(int idx)
880 int bus = mp_irqs[idx].srcbus;
884 * Determine IRQ line polarity (high active or low active):
886 switch (mp_irqs[idx].irqflag & 3)
888 case 0: /* conforms, ie. bus-type dependent polarity */
889 if (test_bit(bus, mp_bus_not_pci))
890 polarity = default_ISA_polarity(idx);
892 polarity = default_PCI_polarity(idx);
894 case 1: /* high active */
899 case 2: /* reserved */
901 printk(KERN_WARNING "broken BIOS!!\n");
905 case 3: /* low active */
910 default: /* invalid */
912 printk(KERN_WARNING "broken BIOS!!\n");
920 static int MPBIOS_trigger(int idx)
922 int bus = mp_irqs[idx].srcbus;
926 * Determine IRQ trigger mode (edge or level sensitive):
928 switch ((mp_irqs[idx].irqflag>>2) & 3)
930 case 0: /* conforms, ie. bus-type dependent */
931 if (test_bit(bus, mp_bus_not_pci))
932 trigger = default_ISA_trigger(idx);
934 trigger = default_PCI_trigger(idx);
935 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
936 switch (mp_bus_id_to_type[bus]) {
937 case MP_BUS_ISA: /* ISA pin */
939 /* set before the switch */
942 case MP_BUS_EISA: /* EISA pin */
944 trigger = default_EISA_trigger(idx);
947 case MP_BUS_PCI: /* PCI pin */
949 /* set before the switch */
952 case MP_BUS_MCA: /* MCA pin */
954 trigger = default_MCA_trigger(idx);
959 printk(KERN_WARNING "broken BIOS!!\n");
971 case 2: /* reserved */
973 printk(KERN_WARNING "broken BIOS!!\n");
982 default: /* invalid */
984 printk(KERN_WARNING "broken BIOS!!\n");
992 static inline int irq_polarity(int idx)
994 return MPBIOS_polarity(idx);
997 static inline int irq_trigger(int idx)
999 return MPBIOS_trigger(idx);
1002 static int pin_2_irq(int idx, int apic, int pin)
1005 int bus = mp_irqs[idx].srcbus;
1008 * Debugging check, we are in big trouble if this message pops up!
1010 if (mp_irqs[idx].dstirq != pin)
1011 printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
1013 if (test_bit(bus, mp_bus_not_pci)) {
1014 irq = mp_irqs[idx].srcbusirq;
1016 u32 gsi = mp_gsi_routing[apic].gsi_base + pin;
1018 if (gsi >= NR_IRQS_LEGACY)
1021 irq = gsi_top + gsi;
1024 #ifdef CONFIG_X86_32
1026 * PCI IRQ command line redirection. Yes, limits are hardcoded.
1028 if ((pin >= 16) && (pin <= 23)) {
1029 if (pirq_entries[pin-16] != -1) {
1030 if (!pirq_entries[pin-16]) {
1031 apic_printk(APIC_VERBOSE, KERN_DEBUG
1032 "disabling PIRQ%d\n", pin-16);
1034 irq = pirq_entries[pin-16];
1035 apic_printk(APIC_VERBOSE, KERN_DEBUG
1036 "using PIRQ%d -> IRQ %d\n",
1047 * Find a specific PCI IRQ entry.
1048 * Not an __init, possibly needed by modules
1050 int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
1051 struct io_apic_irq_attr *irq_attr)
1053 int apic, i, best_guess = -1;
1055 apic_printk(APIC_DEBUG,
1056 "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
1058 if (test_bit(bus, mp_bus_not_pci)) {
1059 apic_printk(APIC_VERBOSE,
1060 "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
1063 for (i = 0; i < mp_irq_entries; i++) {
1064 int lbus = mp_irqs[i].srcbus;
1066 for (apic = 0; apic < nr_ioapics; apic++)
1067 if (mp_ioapics[apic].apicid == mp_irqs[i].dstapic ||
1068 mp_irqs[i].dstapic == MP_APIC_ALL)
1071 if (!test_bit(lbus, mp_bus_not_pci) &&
1072 !mp_irqs[i].irqtype &&
1074 (slot == ((mp_irqs[i].srcbusirq >> 2) & 0x1f))) {
1075 int irq = pin_2_irq(i, apic, mp_irqs[i].dstirq);
1077 if (!(apic || IO_APIC_IRQ(irq)))
1080 if (pin == (mp_irqs[i].srcbusirq & 3)) {
1081 set_io_apic_irq_attr(irq_attr, apic,
1088 * Use the first all-but-pin matching entry as a
1089 * best-guess fuzzy result for broken mptables.
1091 if (best_guess < 0) {
1092 set_io_apic_irq_attr(irq_attr, apic,
1102 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
1104 void lock_vector_lock(void)
1106 /* Used to the online set of cpus does not change
1107 * during assign_irq_vector.
1109 raw_spin_lock(&vector_lock);
1112 void unlock_vector_lock(void)
1114 raw_spin_unlock(&vector_lock);
1118 __assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
1121 * NOTE! The local APIC isn't very good at handling
1122 * multiple interrupts at the same interrupt level.
1123 * As the interrupt level is determined by taking the
1124 * vector number and shifting that right by 4, we
1125 * want to spread these out a bit so that they don't
1126 * all fall in the same interrupt level.
1128 * Also, we've got to be careful not to trash gate
1129 * 0x80, because int 0x80 is hm, kind of importantish. ;)
1131 static int current_vector = FIRST_EXTERNAL_VECTOR + VECTOR_OFFSET_START;
1132 static int current_offset = VECTOR_OFFSET_START % 8;
1133 unsigned int old_vector;
1135 cpumask_var_t tmp_mask;
1137 if (cfg->move_in_progress)
1140 if (!alloc_cpumask_var(&tmp_mask, GFP_ATOMIC))
1143 old_vector = cfg->vector;
1145 cpumask_and(tmp_mask, mask, cpu_online_mask);
1146 cpumask_and(tmp_mask, cfg->domain, tmp_mask);
1147 if (!cpumask_empty(tmp_mask)) {
1148 free_cpumask_var(tmp_mask);
1153 /* Only try and allocate irqs on cpus that are present */
1155 for_each_cpu_and(cpu, mask, cpu_online_mask) {
1159 apic->vector_allocation_domain(cpu, tmp_mask);
1161 vector = current_vector;
1162 offset = current_offset;
1165 if (vector >= first_system_vector) {
1166 /* If out of vectors on large boxen, must share them. */
1167 offset = (offset + 1) % 8;
1168 vector = FIRST_EXTERNAL_VECTOR + offset;
1170 if (unlikely(current_vector == vector))
1173 if (test_bit(vector, used_vectors))
1176 for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
1177 if (per_cpu(vector_irq, new_cpu)[vector] != -1)
1180 current_vector = vector;
1181 current_offset = offset;
1183 cfg->move_in_progress = 1;
1184 cpumask_copy(cfg->old_domain, cfg->domain);
1186 for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
1187 per_cpu(vector_irq, new_cpu)[vector] = irq;
1188 cfg->vector = vector;
1189 cpumask_copy(cfg->domain, tmp_mask);
1193 free_cpumask_var(tmp_mask);
1197 int assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
1200 unsigned long flags;
1202 raw_spin_lock_irqsave(&vector_lock, flags);
1203 err = __assign_irq_vector(irq, cfg, mask);
1204 raw_spin_unlock_irqrestore(&vector_lock, flags);
1208 static void __clear_irq_vector(int irq, struct irq_cfg *cfg)
1212 BUG_ON(!cfg->vector);
1214 vector = cfg->vector;
1215 for_each_cpu_and(cpu, cfg->domain, cpu_online_mask)
1216 per_cpu(vector_irq, cpu)[vector] = -1;
1219 cpumask_clear(cfg->domain);
1221 if (likely(!cfg->move_in_progress))
1223 for_each_cpu_and(cpu, cfg->old_domain, cpu_online_mask) {
1224 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS;
1226 if (per_cpu(vector_irq, cpu)[vector] != irq)
1228 per_cpu(vector_irq, cpu)[vector] = -1;
1232 cfg->move_in_progress = 0;
1235 void __setup_vector_irq(int cpu)
1237 /* Initialize vector_irq on a new cpu */
1239 struct irq_cfg *cfg;
1240 struct irq_desc *desc;
1243 * vector_lock will make sure that we don't run into irq vector
1244 * assignments that might be happening on another cpu in parallel,
1245 * while we setup our initial vector to irq mappings.
1247 raw_spin_lock(&vector_lock);
1248 /* Mark the inuse vectors */
1249 for_each_irq_desc(irq, desc) {
1250 cfg = get_irq_desc_chip_data(desc);
1253 * If it is a legacy IRQ handled by the legacy PIC, this cpu
1254 * will be part of the irq_cfg's domain.
1256 if (irq < legacy_pic->nr_legacy_irqs && !IO_APIC_IRQ(irq))
1257 cpumask_set_cpu(cpu, cfg->domain);
1259 if (!cpumask_test_cpu(cpu, cfg->domain))
1261 vector = cfg->vector;
1262 per_cpu(vector_irq, cpu)[vector] = irq;
1264 /* Mark the free vectors */
1265 for (vector = 0; vector < NR_VECTORS; ++vector) {
1266 irq = per_cpu(vector_irq, cpu)[vector];
1271 if (!cpumask_test_cpu(cpu, cfg->domain))
1272 per_cpu(vector_irq, cpu)[vector] = -1;
1274 raw_spin_unlock(&vector_lock);
1277 static struct irq_chip ioapic_chip;
1278 static struct irq_chip ir_ioapic_chip;
1280 #define IOAPIC_AUTO -1
1281 #define IOAPIC_EDGE 0
1282 #define IOAPIC_LEVEL 1
1284 #ifdef CONFIG_X86_32
1285 static inline int IO_APIC_irq_trigger(int irq)
1289 for (apic = 0; apic < nr_ioapics; apic++) {
1290 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
1291 idx = find_irq_entry(apic, pin, mp_INT);
1292 if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
1293 return irq_trigger(idx);
1297 * nonexistent IRQs are edge default
1302 static inline int IO_APIC_irq_trigger(int irq)
1308 static void ioapic_register_intr(unsigned int irq, unsigned long trigger)
1311 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
1312 trigger == IOAPIC_LEVEL)
1313 irq_set_status_flags(irq, IRQ_LEVEL);
1315 irq_clear_status_flags(irq, IRQ_LEVEL);
1317 if (irq_remapped(irq)) {
1318 irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
1320 set_irq_chip_and_handler_name(irq, &ir_ioapic_chip,
1324 set_irq_chip_and_handler_name(irq, &ir_ioapic_chip,
1325 handle_edge_irq, "edge");
1329 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
1330 trigger == IOAPIC_LEVEL)
1331 set_irq_chip_and_handler_name(irq, &ioapic_chip,
1335 set_irq_chip_and_handler_name(irq, &ioapic_chip,
1336 handle_edge_irq, "edge");
1339 int setup_ioapic_entry(int apic_id, int irq,
1340 struct IO_APIC_route_entry *entry,
1341 unsigned int destination, int trigger,
1342 int polarity, int vector, int pin)
1345 * add it to the IO-APIC irq-routing table:
1347 memset(entry,0,sizeof(*entry));
1349 if (intr_remapping_enabled) {
1350 struct intel_iommu *iommu = map_ioapic_to_ir(apic_id);
1352 struct IR_IO_APIC_route_entry *ir_entry =
1353 (struct IR_IO_APIC_route_entry *) entry;
1357 panic("No mapping iommu for ioapic %d\n", apic_id);
1359 index = alloc_irte(iommu, irq, 1);
1361 panic("Failed to allocate IRTE for ioapic %d\n", apic_id);
1363 prepare_irte(&irte, vector, destination);
1365 /* Set source-id of interrupt request */
1366 set_ioapic_sid(&irte, apic_id);
1368 modify_irte(irq, &irte);
1370 ir_entry->index2 = (index >> 15) & 0x1;
1372 ir_entry->format = 1;
1373 ir_entry->index = (index & 0x7fff);
1375 * IO-APIC RTE will be configured with virtual vector.
1376 * irq handler will do the explicit EOI to the io-apic.
1378 ir_entry->vector = pin;
1380 entry->delivery_mode = apic->irq_delivery_mode;
1381 entry->dest_mode = apic->irq_dest_mode;
1382 entry->dest = destination;
1383 entry->vector = vector;
1386 entry->mask = 0; /* enable IRQ */
1387 entry->trigger = trigger;
1388 entry->polarity = polarity;
1390 /* Mask level triggered irqs.
1391 * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
1398 static void setup_ioapic_irq(int apic_id, int pin, unsigned int irq,
1399 struct irq_cfg *cfg, int trigger, int polarity)
1401 struct IO_APIC_route_entry entry;
1404 if (!IO_APIC_IRQ(irq))
1407 * For legacy irqs, cfg->domain starts with cpu 0 for legacy
1408 * controllers like 8259. Now that IO-APIC can handle this irq, update
1411 if (irq < legacy_pic->nr_legacy_irqs && cpumask_test_cpu(0, cfg->domain))
1412 apic->vector_allocation_domain(0, cfg->domain);
1414 if (assign_irq_vector(irq, cfg, apic->target_cpus()))
1417 dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
1419 apic_printk(APIC_VERBOSE,KERN_DEBUG
1420 "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
1421 "IRQ %d Mode:%i Active:%i)\n",
1422 apic_id, mp_ioapics[apic_id].apicid, pin, cfg->vector,
1423 irq, trigger, polarity);
1426 if (setup_ioapic_entry(mp_ioapics[apic_id].apicid, irq, &entry,
1427 dest, trigger, polarity, cfg->vector, pin)) {
1428 printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
1429 mp_ioapics[apic_id].apicid, pin);
1430 __clear_irq_vector(irq, cfg);
1434 ioapic_register_intr(irq, trigger);
1435 if (irq < legacy_pic->nr_legacy_irqs)
1436 legacy_pic->mask(irq);
1438 ioapic_write_entry(apic_id, pin, entry);
1442 DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
1443 } mp_ioapic_routing[MAX_IO_APICS];
1445 static void __init setup_IO_APIC_irqs(void)
1447 int apic_id, pin, idx, irq;
1449 struct irq_desc *desc;
1450 struct irq_cfg *cfg;
1451 int node = cpu_to_node(0);
1453 apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
1455 for (apic_id = 0; apic_id < nr_ioapics; apic_id++)
1456 for (pin = 0; pin < nr_ioapic_registers[apic_id]; pin++) {
1457 idx = find_irq_entry(apic_id, pin, mp_INT);
1461 apic_printk(APIC_VERBOSE,
1462 KERN_DEBUG " %d-%d",
1463 mp_ioapics[apic_id].apicid, pin);
1465 apic_printk(APIC_VERBOSE, " %d-%d",
1466 mp_ioapics[apic_id].apicid, pin);
1470 apic_printk(APIC_VERBOSE,
1471 " (apicid-pin) not connected\n");
1475 irq = pin_2_irq(idx, apic_id, pin);
1477 if ((apic_id > 0) && (irq > 16))
1481 * Skip the timer IRQ if there's a quirk handler
1482 * installed and if it returns 1:
1484 if (apic->multi_timer_check &&
1485 apic->multi_timer_check(apic_id, irq))
1488 desc = irq_to_desc_alloc_node(irq, node);
1490 printk(KERN_INFO "can not get irq_desc for %d\n", irq);
1493 cfg = get_irq_desc_chip_data(desc);
1494 add_pin_to_irq_node(cfg, node, apic_id, pin);
1496 * don't mark it in pin_programmed, so later acpi could
1497 * set it correctly when irq < 16
1499 setup_ioapic_irq(apic_id, pin, irq, cfg, irq_trigger(idx),
1504 apic_printk(APIC_VERBOSE,
1505 " (apicid-pin) not connected\n");
1509 * for the gsit that is not in first ioapic
1510 * but could not use acpi_register_gsi()
1511 * like some special sci in IBM x3330
1513 void setup_IO_APIC_irq_extra(u32 gsi)
1515 int apic_id = 0, pin, idx, irq;
1516 int node = cpu_to_node(0);
1517 struct irq_desc *desc;
1518 struct irq_cfg *cfg;
1521 * Convert 'gsi' to 'ioapic.pin'.
1523 apic_id = mp_find_ioapic(gsi);
1527 pin = mp_find_ioapic_pin(apic_id, gsi);
1528 idx = find_irq_entry(apic_id, pin, mp_INT);
1532 irq = pin_2_irq(idx, apic_id, pin);
1533 #ifdef CONFIG_SPARSE_IRQ
1534 desc = irq_to_desc(irq);
1538 desc = irq_to_desc_alloc_node(irq, node);
1540 printk(KERN_INFO "can not get irq_desc for %d\n", irq);
1544 cfg = get_irq_desc_chip_data(desc);
1545 add_pin_to_irq_node(cfg, node, apic_id, pin);
1547 if (test_bit(pin, mp_ioapic_routing[apic_id].pin_programmed)) {
1548 pr_debug("Pin %d-%d already programmed\n",
1549 mp_ioapics[apic_id].apicid, pin);
1552 set_bit(pin, mp_ioapic_routing[apic_id].pin_programmed);
1554 setup_ioapic_irq(apic_id, pin, irq, cfg,
1555 irq_trigger(idx), irq_polarity(idx));
1559 * Set up the timer pin, possibly with the 8259A-master behind.
1561 static void __init setup_timer_IRQ0_pin(unsigned int apic_id, unsigned int pin,
1564 struct IO_APIC_route_entry entry;
1566 if (intr_remapping_enabled)
1569 memset(&entry, 0, sizeof(entry));
1572 * We use logical delivery to get the timer IRQ
1575 entry.dest_mode = apic->irq_dest_mode;
1576 entry.mask = 0; /* don't mask IRQ for edge */
1577 entry.dest = apic->cpu_mask_to_apicid(apic->target_cpus());
1578 entry.delivery_mode = apic->irq_delivery_mode;
1581 entry.vector = vector;
1584 * The timer IRQ doesn't have to know that behind the
1585 * scene we may have a 8259A-master in AEOI mode ...
1587 set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge");
1590 * Add it to the IO-APIC irq-routing table:
1592 ioapic_write_entry(apic_id, pin, entry);
1596 __apicdebuginit(void) print_IO_APIC(void)
1599 union IO_APIC_reg_00 reg_00;
1600 union IO_APIC_reg_01 reg_01;
1601 union IO_APIC_reg_02 reg_02;
1602 union IO_APIC_reg_03 reg_03;
1603 unsigned long flags;
1604 struct irq_cfg *cfg;
1605 struct irq_desc *desc;
1608 printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
1609 for (i = 0; i < nr_ioapics; i++)
1610 printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
1611 mp_ioapics[i].apicid, nr_ioapic_registers[i]);
1614 * We are a bit conservative about what we expect. We have to
1615 * know about every hardware change ASAP.
1617 printk(KERN_INFO "testing the IO APIC.......................\n");
1619 for (apic = 0; apic < nr_ioapics; apic++) {
1621 raw_spin_lock_irqsave(&ioapic_lock, flags);
1622 reg_00.raw = io_apic_read(apic, 0);
1623 reg_01.raw = io_apic_read(apic, 1);
1624 if (reg_01.bits.version >= 0x10)
1625 reg_02.raw = io_apic_read(apic, 2);
1626 if (reg_01.bits.version >= 0x20)
1627 reg_03.raw = io_apic_read(apic, 3);
1628 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
1631 printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].apicid);
1632 printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
1633 printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
1634 printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type);
1635 printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS);
1637 printk(KERN_DEBUG ".... register #01: %08X\n", *(int *)®_01);
1638 printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
1640 printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
1641 printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
1644 * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
1645 * but the value of reg_02 is read as the previous read register
1646 * value, so ignore it if reg_02 == reg_01.
1648 if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) {
1649 printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
1650 printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
1654 * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
1655 * or reg_03, but the value of reg_0[23] is read as the previous read
1656 * register value, so ignore it if reg_03 == reg_0[12].
1658 if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw &&
1659 reg_03.raw != reg_01.raw) {
1660 printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw);
1661 printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT);
1664 printk(KERN_DEBUG ".... IRQ redirection table:\n");
1666 printk(KERN_DEBUG " NR Dst Mask Trig IRR Pol"
1667 " Stat Dmod Deli Vect:\n");
1669 for (i = 0; i <= reg_01.bits.entries; i++) {
1670 struct IO_APIC_route_entry entry;
1672 entry = ioapic_read_entry(apic, i);
1674 printk(KERN_DEBUG " %02x %03X ",
1679 printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
1684 entry.delivery_status,
1686 entry.delivery_mode,
1691 printk(KERN_DEBUG "IRQ to pin mappings:\n");
1692 for_each_irq_desc(irq, desc) {
1693 struct irq_pin_list *entry;
1695 cfg = get_irq_desc_chip_data(desc);
1698 entry = cfg->irq_2_pin;
1701 printk(KERN_DEBUG "IRQ%d ", irq);
1702 for_each_irq_pin(entry, cfg->irq_2_pin)
1703 printk("-> %d:%d", entry->apic, entry->pin);
1707 printk(KERN_INFO ".................................... done.\n");
1712 __apicdebuginit(void) print_APIC_field(int base)
1718 for (i = 0; i < 8; i++)
1719 printk(KERN_CONT "%08x", apic_read(base + i*0x10));
1721 printk(KERN_CONT "\n");
1724 __apicdebuginit(void) print_local_APIC(void *dummy)
1726 unsigned int i, v, ver, maxlvt;
1729 printk(KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
1730 smp_processor_id(), hard_smp_processor_id());
1731 v = apic_read(APIC_ID);
1732 printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, read_apic_id());
1733 v = apic_read(APIC_LVR);
1734 printk(KERN_INFO "... APIC VERSION: %08x\n", v);
1735 ver = GET_APIC_VERSION(v);
1736 maxlvt = lapic_get_maxlvt();
1738 v = apic_read(APIC_TASKPRI);
1739 printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
1741 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1742 if (!APIC_XAPIC(ver)) {
1743 v = apic_read(APIC_ARBPRI);
1744 printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
1745 v & APIC_ARBPRI_MASK);
1747 v = apic_read(APIC_PROCPRI);
1748 printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
1752 * Remote read supported only in the 82489DX and local APIC for
1753 * Pentium processors.
1755 if (!APIC_INTEGRATED(ver) || maxlvt == 3) {
1756 v = apic_read(APIC_RRR);
1757 printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
1760 v = apic_read(APIC_LDR);
1761 printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
1762 if (!x2apic_enabled()) {
1763 v = apic_read(APIC_DFR);
1764 printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
1766 v = apic_read(APIC_SPIV);
1767 printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
1769 printk(KERN_DEBUG "... APIC ISR field:\n");
1770 print_APIC_field(APIC_ISR);
1771 printk(KERN_DEBUG "... APIC TMR field:\n");
1772 print_APIC_field(APIC_TMR);
1773 printk(KERN_DEBUG "... APIC IRR field:\n");
1774 print_APIC_field(APIC_IRR);
1776 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1777 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
1778 apic_write(APIC_ESR, 0);
1780 v = apic_read(APIC_ESR);
1781 printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
1784 icr = apic_icr_read();
1785 printk(KERN_DEBUG "... APIC ICR: %08x\n", (u32)icr);
1786 printk(KERN_DEBUG "... APIC ICR2: %08x\n", (u32)(icr >> 32));
1788 v = apic_read(APIC_LVTT);
1789 printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
1791 if (maxlvt > 3) { /* PC is LVT#4. */
1792 v = apic_read(APIC_LVTPC);
1793 printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
1795 v = apic_read(APIC_LVT0);
1796 printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
1797 v = apic_read(APIC_LVT1);
1798 printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
1800 if (maxlvt > 2) { /* ERR is LVT#3. */
1801 v = apic_read(APIC_LVTERR);
1802 printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
1805 v = apic_read(APIC_TMICT);
1806 printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
1807 v = apic_read(APIC_TMCCT);
1808 printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
1809 v = apic_read(APIC_TDCR);
1810 printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
1812 if (boot_cpu_has(X86_FEATURE_EXTAPIC)) {
1813 v = apic_read(APIC_EFEAT);
1814 maxlvt = (v >> 16) & 0xff;
1815 printk(KERN_DEBUG "... APIC EFEAT: %08x\n", v);
1816 v = apic_read(APIC_ECTRL);
1817 printk(KERN_DEBUG "... APIC ECTRL: %08x\n", v);
1818 for (i = 0; i < maxlvt; i++) {
1819 v = apic_read(APIC_EILVTn(i));
1820 printk(KERN_DEBUG "... APIC EILVT%d: %08x\n", i, v);
1826 __apicdebuginit(void) print_local_APICs(int maxcpu)
1834 for_each_online_cpu(cpu) {
1837 smp_call_function_single(cpu, print_local_APIC, NULL, 1);
1842 __apicdebuginit(void) print_PIC(void)
1845 unsigned long flags;
1847 if (!legacy_pic->nr_legacy_irqs)
1850 printk(KERN_DEBUG "\nprinting PIC contents\n");
1852 raw_spin_lock_irqsave(&i8259A_lock, flags);
1854 v = inb(0xa1) << 8 | inb(0x21);
1855 printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
1857 v = inb(0xa0) << 8 | inb(0x20);
1858 printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
1862 v = inb(0xa0) << 8 | inb(0x20);
1866 raw_spin_unlock_irqrestore(&i8259A_lock, flags);
1868 printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
1870 v = inb(0x4d1) << 8 | inb(0x4d0);
1871 printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
1874 static int __initdata show_lapic = 1;
1875 static __init int setup_show_lapic(char *arg)
1879 if (strcmp(arg, "all") == 0) {
1880 show_lapic = CONFIG_NR_CPUS;
1882 get_option(&arg, &num);
1889 __setup("show_lapic=", setup_show_lapic);
1891 __apicdebuginit(int) print_ICs(void)
1893 if (apic_verbosity == APIC_QUIET)
1898 /* don't print out if apic is not there */
1899 if (!cpu_has_apic && !apic_from_smp_config())
1902 print_local_APICs(show_lapic);
1908 fs_initcall(print_ICs);
1911 /* Where if anywhere is the i8259 connect in external int mode */
1912 static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
1914 void __init enable_IO_APIC(void)
1916 int i8259_apic, i8259_pin;
1919 if (!legacy_pic->nr_legacy_irqs)
1922 for(apic = 0; apic < nr_ioapics; apic++) {
1924 /* See if any of the pins is in ExtINT mode */
1925 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
1926 struct IO_APIC_route_entry entry;
1927 entry = ioapic_read_entry(apic, pin);
1929 /* If the interrupt line is enabled and in ExtInt mode
1930 * I have found the pin where the i8259 is connected.
1932 if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
1933 ioapic_i8259.apic = apic;
1934 ioapic_i8259.pin = pin;
1940 /* Look to see what if the MP table has reported the ExtINT */
1941 /* If we could not find the appropriate pin by looking at the ioapic
1942 * the i8259 probably is not connected the ioapic but give the
1943 * mptable a chance anyway.
1945 i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
1946 i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
1947 /* Trust the MP table if nothing is setup in the hardware */
1948 if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
1949 printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
1950 ioapic_i8259.pin = i8259_pin;
1951 ioapic_i8259.apic = i8259_apic;
1953 /* Complain if the MP table and the hardware disagree */
1954 if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
1955 (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
1957 printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
1961 * Do not trust the IO-APIC being empty at bootup
1967 * Not an __init, needed by the reboot code
1969 void disable_IO_APIC(void)
1972 * Clear the IO-APIC before rebooting:
1976 if (!legacy_pic->nr_legacy_irqs)
1980 * If the i8259 is routed through an IOAPIC
1981 * Put that IOAPIC in virtual wire mode
1982 * so legacy interrupts can be delivered.
1984 * With interrupt-remapping, for now we will use virtual wire A mode,
1985 * as virtual wire B is little complex (need to configure both
1986 * IOAPIC RTE aswell as interrupt-remapping table entry).
1987 * As this gets called during crash dump, keep this simple for now.
1989 if (ioapic_i8259.pin != -1 && !intr_remapping_enabled) {
1990 struct IO_APIC_route_entry entry;
1992 memset(&entry, 0, sizeof(entry));
1993 entry.mask = 0; /* Enabled */
1994 entry.trigger = 0; /* Edge */
1996 entry.polarity = 0; /* High */
1997 entry.delivery_status = 0;
1998 entry.dest_mode = 0; /* Physical */
1999 entry.delivery_mode = dest_ExtINT; /* ExtInt */
2001 entry.dest = read_apic_id();
2004 * Add it to the IO-APIC irq-routing table:
2006 ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
2010 * Use virtual wire A mode when interrupt remapping is enabled.
2012 if (cpu_has_apic || apic_from_smp_config())
2013 disconnect_bsp_APIC(!intr_remapping_enabled &&
2014 ioapic_i8259.pin != -1);
2017 #ifdef CONFIG_X86_32
2019 * function to set the IO-APIC physical IDs based on the
2020 * values stored in the MPC table.
2022 * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
2025 void __init setup_ioapic_ids_from_mpc(void)
2027 union IO_APIC_reg_00 reg_00;
2028 physid_mask_t phys_id_present_map;
2031 unsigned char old_id;
2032 unsigned long flags;
2037 * Don't check I/O APIC IDs for xAPIC systems. They have
2038 * no meaning without the serial APIC bus.
2040 if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
2041 || APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
2044 * This is broken; anything with a real cpu count has to
2045 * circumvent this idiocy regardless.
2047 apic->ioapic_phys_id_map(&phys_cpu_present_map, &phys_id_present_map);
2050 * Set the IOAPIC ID to the value stored in the MPC table.
2052 for (apic_id = 0; apic_id < nr_ioapics; apic_id++) {
2054 /* Read the register 0 value */
2055 raw_spin_lock_irqsave(&ioapic_lock, flags);
2056 reg_00.raw = io_apic_read(apic_id, 0);
2057 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
2059 old_id = mp_ioapics[apic_id].apicid;
2061 if (mp_ioapics[apic_id].apicid >= get_physical_broadcast()) {
2062 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
2063 apic_id, mp_ioapics[apic_id].apicid);
2064 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
2066 mp_ioapics[apic_id].apicid = reg_00.bits.ID;
2070 * Sanity check, is the ID really free? Every APIC in a
2071 * system must have a unique ID or we get lots of nice
2072 * 'stuck on smp_invalidate_needed IPI wait' messages.
2074 if (apic->check_apicid_used(&phys_id_present_map,
2075 mp_ioapics[apic_id].apicid)) {
2076 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
2077 apic_id, mp_ioapics[apic_id].apicid);
2078 for (i = 0; i < get_physical_broadcast(); i++)
2079 if (!physid_isset(i, phys_id_present_map))
2081 if (i >= get_physical_broadcast())
2082 panic("Max APIC ID exceeded!\n");
2083 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
2085 physid_set(i, phys_id_present_map);
2086 mp_ioapics[apic_id].apicid = i;
2089 apic->apicid_to_cpu_present(mp_ioapics[apic_id].apicid, &tmp);
2090 apic_printk(APIC_VERBOSE, "Setting %d in the "
2091 "phys_id_present_map\n",
2092 mp_ioapics[apic_id].apicid);
2093 physids_or(phys_id_present_map, phys_id_present_map, tmp);
2098 * We need to adjust the IRQ routing table
2099 * if the ID changed.
2101 if (old_id != mp_ioapics[apic_id].apicid)
2102 for (i = 0; i < mp_irq_entries; i++)
2103 if (mp_irqs[i].dstapic == old_id)
2105 = mp_ioapics[apic_id].apicid;
2108 * Read the right value from the MPC table and
2109 * write it into the ID register.
2111 apic_printk(APIC_VERBOSE, KERN_INFO
2112 "...changing IO-APIC physical APIC ID to %d ...",
2113 mp_ioapics[apic_id].apicid);
2115 reg_00.bits.ID = mp_ioapics[apic_id].apicid;
2116 raw_spin_lock_irqsave(&ioapic_lock, flags);
2117 io_apic_write(apic_id, 0, reg_00.raw);
2118 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
2123 raw_spin_lock_irqsave(&ioapic_lock, flags);
2124 reg_00.raw = io_apic_read(apic_id, 0);
2125 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
2126 if (reg_00.bits.ID != mp_ioapics[apic_id].apicid)
2127 printk("could not set ID!\n");
2129 apic_printk(APIC_VERBOSE, " ok.\n");
2134 int no_timer_check __initdata;
2136 static int __init notimercheck(char *s)
2141 __setup("no_timer_check", notimercheck);
2144 * There is a nasty bug in some older SMP boards, their mptable lies
2145 * about the timer IRQ. We do the following to work around the situation:
2147 * - timer IRQ defaults to IO-APIC IRQ
2148 * - if this function detects that timer IRQs are defunct, then we fall
2149 * back to ISA timer IRQs
2151 static int __init timer_irq_works(void)
2153 unsigned long t1 = jiffies;
2154 unsigned long flags;
2159 local_save_flags(flags);
2161 /* Let ten ticks pass... */
2162 mdelay((10 * 1000) / HZ);
2163 local_irq_restore(flags);
2166 * Expect a few ticks at least, to be sure some possible
2167 * glue logic does not lock up after one or two first
2168 * ticks in a non-ExtINT mode. Also the local APIC
2169 * might have cached one ExtINT interrupt. Finally, at
2170 * least one tick may be lost due to delays.
2174 if (time_after(jiffies, t1 + 4))
2180 * In the SMP+IOAPIC case it might happen that there are an unspecified
2181 * number of pending IRQ events unhandled. These cases are very rare,
2182 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
2183 * better to do it this way as thus we do not have to be aware of
2184 * 'pending' interrupts in the IRQ path, except at this point.
2187 * Edge triggered needs to resend any interrupt
2188 * that was delayed but this is now handled in the device
2193 * Starting up a edge-triggered IO-APIC interrupt is
2194 * nasty - we need to make sure that we get the edge.
2195 * If it is already asserted for some reason, we need
2196 * return 1 to indicate that is was pending.
2198 * This is not complete - we should be able to fake
2199 * an edge even if it isn't on the 8259A...
2202 static unsigned int startup_ioapic_irq(struct irq_data *data)
2204 int was_pending = 0, irq = data->irq;
2205 unsigned long flags;
2207 raw_spin_lock_irqsave(&ioapic_lock, flags);
2208 if (irq < legacy_pic->nr_legacy_irqs) {
2209 legacy_pic->mask(irq);
2210 if (legacy_pic->irq_pending(irq))
2213 __unmask_ioapic(data->chip_data);
2214 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
2219 static int ioapic_retrigger_irq(struct irq_data *data)
2221 struct irq_cfg *cfg = data->chip_data;
2222 unsigned long flags;
2224 raw_spin_lock_irqsave(&vector_lock, flags);
2225 apic->send_IPI_mask(cpumask_of(cpumask_first(cfg->domain)), cfg->vector);
2226 raw_spin_unlock_irqrestore(&vector_lock, flags);
2232 * Level and edge triggered IO-APIC interrupts need different handling,
2233 * so we use two separate IRQ descriptors. Edge triggered IRQs can be
2234 * handled with the level-triggered descriptor, but that one has slightly
2235 * more overhead. Level-triggered interrupts cannot be handled with the
2236 * edge-triggered handler, without risking IRQ storms and other ugly
2241 void send_cleanup_vector(struct irq_cfg *cfg)
2243 cpumask_var_t cleanup_mask;
2245 if (unlikely(!alloc_cpumask_var(&cleanup_mask, GFP_ATOMIC))) {
2247 for_each_cpu_and(i, cfg->old_domain, cpu_online_mask)
2248 apic->send_IPI_mask(cpumask_of(i), IRQ_MOVE_CLEANUP_VECTOR);
2250 cpumask_and(cleanup_mask, cfg->old_domain, cpu_online_mask);
2251 apic->send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
2252 free_cpumask_var(cleanup_mask);
2254 cfg->move_in_progress = 0;
2257 static void __target_IO_APIC_irq(unsigned int irq, unsigned int dest, struct irq_cfg *cfg)
2260 struct irq_pin_list *entry;
2261 u8 vector = cfg->vector;
2263 for_each_irq_pin(entry, cfg->irq_2_pin) {
2269 * With interrupt-remapping, destination information comes
2270 * from interrupt-remapping table entry.
2272 if (!irq_remapped(irq))
2273 io_apic_write(apic, 0x11 + pin*2, dest);
2274 reg = io_apic_read(apic, 0x10 + pin*2);
2275 reg &= ~IO_APIC_REDIR_VECTOR_MASK;
2277 io_apic_modify(apic, 0x10 + pin*2, reg);
2282 * Either sets data->affinity to a valid value, and returns
2283 * ->cpu_mask_to_apicid of that in dest_id, or returns -1 and
2284 * leaves data->affinity untouched.
2286 int __ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
2287 unsigned int *dest_id)
2289 struct irq_cfg *cfg = data->chip_data;
2291 if (!cpumask_intersects(mask, cpu_online_mask))
2294 if (assign_irq_vector(data->irq, data->chip_data, mask))
2297 cpumask_copy(data->affinity, mask);
2299 *dest_id = apic->cpu_mask_to_apicid_and(mask, cfg->domain);
2304 ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
2307 unsigned int dest, irq = data->irq;
2308 unsigned long flags;
2311 raw_spin_lock_irqsave(&ioapic_lock, flags);
2312 ret = __ioapic_set_affinity(data, mask, &dest);
2314 /* Only the high 8 bits are valid. */
2315 dest = SET_APIC_LOGICAL_ID(dest);
2316 __target_IO_APIC_irq(irq, dest, data->chip_data);
2318 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
2322 #ifdef CONFIG_INTR_REMAP
2325 * Migrate the IO-APIC irq in the presence of intr-remapping.
2327 * For both level and edge triggered, irq migration is a simple atomic
2328 * update(of vector and cpu destination) of IRTE and flush the hardware cache.
2330 * For level triggered, we eliminate the io-apic RTE modification (with the
2331 * updated vector information), by using a virtual vector (io-apic pin number).
2332 * Real vector that is used for interrupting cpu will be coming from
2333 * the interrupt-remapping table entry.
2336 ir_ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
2339 struct irq_cfg *cfg = data->chip_data;
2340 unsigned int dest, irq = data->irq;
2343 if (!cpumask_intersects(mask, cpu_online_mask))
2346 if (get_irte(irq, &irte))
2349 if (assign_irq_vector(irq, cfg, mask))
2352 dest = apic->cpu_mask_to_apicid_and(cfg->domain, mask);
2354 irte.vector = cfg->vector;
2355 irte.dest_id = IRTE_DEST(dest);
2358 * Modified the IRTE and flushes the Interrupt entry cache.
2360 modify_irte(irq, &irte);
2362 if (cfg->move_in_progress)
2363 send_cleanup_vector(cfg);
2365 cpumask_copy(data->affinity, mask);
2371 ir_ioapic_set_affinity(struct irq_data *data, const struct cpumask *mask,
2378 asmlinkage void smp_irq_move_cleanup_interrupt(void)
2380 unsigned vector, me;
2386 me = smp_processor_id();
2387 for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
2390 struct irq_desc *desc;
2391 struct irq_cfg *cfg;
2392 irq = __get_cpu_var(vector_irq)[vector];
2397 desc = irq_to_desc(irq);
2402 raw_spin_lock(&desc->lock);
2405 * Check if the irq migration is in progress. If so, we
2406 * haven't received the cleanup request yet for this irq.
2408 if (cfg->move_in_progress)
2411 if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
2414 irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
2416 * Check if the vector that needs to be cleanedup is
2417 * registered at the cpu's IRR. If so, then this is not
2418 * the best time to clean it up. Lets clean it up in the
2419 * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
2422 if (irr & (1 << (vector % 32))) {
2423 apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
2426 __get_cpu_var(vector_irq)[vector] = -1;
2428 raw_spin_unlock(&desc->lock);
2434 static void __irq_complete_move(struct irq_cfg *cfg, unsigned vector)
2438 if (likely(!cfg->move_in_progress))
2441 me = smp_processor_id();
2443 if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
2444 send_cleanup_vector(cfg);
2447 static void irq_complete_move(struct irq_cfg *cfg)
2449 __irq_complete_move(cfg, ~get_irq_regs()->orig_ax);
2452 void irq_force_complete_move(int irq)
2454 struct irq_cfg *cfg = get_irq_chip_data(irq);
2459 __irq_complete_move(cfg, cfg->vector);
2462 static inline void irq_complete_move(struct irq_cfg *cfg) { }
2465 static void ack_apic_edge(struct irq_data *data)
2467 irq_complete_move(data->chip_data);
2468 move_native_irq(data->irq);
2472 atomic_t irq_mis_count;
2475 * IO-APIC versions below 0x20 don't support EOI register.
2476 * For the record, here is the information about various versions:
2478 * 1Xh I/OAPIC or I/O(x)APIC which are not PCI 2.2 Compliant
2479 * 2Xh I/O(x)APIC which is PCI 2.2 Compliant
2482 * Some of the Intel ICH Specs (ICH2 to ICH5) documents the io-apic
2483 * version as 0x2. This is an error with documentation and these ICH chips
2484 * use io-apic's of version 0x20.
2486 * For IO-APIC's with EOI register, we use that to do an explicit EOI.
2487 * Otherwise, we simulate the EOI message manually by changing the trigger
2488 * mode to edge and then back to level, with RTE being masked during this.
2490 static void eoi_ioapic_irq(unsigned int irq, struct irq_cfg *cfg)
2492 struct irq_pin_list *entry;
2493 unsigned long flags;
2495 raw_spin_lock_irqsave(&ioapic_lock, flags);
2496 for_each_irq_pin(entry, cfg->irq_2_pin) {
2497 if (mp_ioapics[entry->apic].apicver >= 0x20) {
2499 * Intr-remapping uses pin number as the virtual vector
2500 * in the RTE. Actual vector is programmed in
2501 * intr-remapping table entry. Hence for the io-apic
2502 * EOI we use the pin number.
2504 if (irq_remapped(irq))
2505 io_apic_eoi(entry->apic, entry->pin);
2507 io_apic_eoi(entry->apic, cfg->vector);
2509 __mask_and_edge_IO_APIC_irq(entry);
2510 __unmask_and_level_IO_APIC_irq(entry);
2513 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
2516 static void ack_apic_level(struct irq_data *data)
2518 struct irq_cfg *cfg = data->chip_data;
2519 int i, do_unmask_irq = 0, irq = data->irq;
2520 struct irq_desc *desc = irq_to_desc(irq);
2523 irq_complete_move(cfg);
2524 #ifdef CONFIG_GENERIC_PENDING_IRQ
2525 /* If we are moving the irq we need to mask it */
2526 if (unlikely(desc->status & IRQ_MOVE_PENDING)) {
2533 * It appears there is an erratum which affects at least version 0x11
2534 * of I/O APIC (that's the 82093AA and cores integrated into various
2535 * chipsets). Under certain conditions a level-triggered interrupt is
2536 * erroneously delivered as edge-triggered one but the respective IRR
2537 * bit gets set nevertheless. As a result the I/O unit expects an EOI
2538 * message but it will never arrive and further interrupts are blocked
2539 * from the source. The exact reason is so far unknown, but the
2540 * phenomenon was observed when two consecutive interrupt requests
2541 * from a given source get delivered to the same CPU and the source is
2542 * temporarily disabled in between.
2544 * A workaround is to simulate an EOI message manually. We achieve it
2545 * by setting the trigger mode to edge and then to level when the edge
2546 * trigger mode gets detected in the TMR of a local APIC for a
2547 * level-triggered interrupt. We mask the source for the time of the
2548 * operation to prevent an edge-triggered interrupt escaping meanwhile.
2549 * The idea is from Manfred Spraul. --macro
2551 * Also in the case when cpu goes offline, fixup_irqs() will forward
2552 * any unhandled interrupt on the offlined cpu to the new cpu
2553 * destination that is handling the corresponding interrupt. This
2554 * interrupt forwarding is done via IPI's. Hence, in this case also
2555 * level-triggered io-apic interrupt will be seen as an edge
2556 * interrupt in the IRR. And we can't rely on the cpu's EOI
2557 * to be broadcasted to the IO-APIC's which will clear the remoteIRR
2558 * corresponding to the level-triggered interrupt. Hence on IO-APIC's
2559 * supporting EOI register, we do an explicit EOI to clear the
2560 * remote IRR and on IO-APIC's which don't have an EOI register,
2561 * we use the above logic (mask+edge followed by unmask+level) from
2562 * Manfred Spraul to clear the remote IRR.
2565 v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
2568 * We must acknowledge the irq before we move it or the acknowledge will
2569 * not propagate properly.
2574 * Tail end of clearing remote IRR bit (either by delivering the EOI
2575 * message via io-apic EOI register write or simulating it using
2576 * mask+edge followed by unnask+level logic) manually when the
2577 * level triggered interrupt is seen as the edge triggered interrupt
2580 if (!(v & (1 << (i & 0x1f)))) {
2581 atomic_inc(&irq_mis_count);
2583 eoi_ioapic_irq(irq, cfg);
2586 /* Now we can move and renable the irq */
2587 if (unlikely(do_unmask_irq)) {
2588 /* Only migrate the irq if the ack has been received.
2590 * On rare occasions the broadcast level triggered ack gets
2591 * delayed going to ioapics, and if we reprogram the
2592 * vector while Remote IRR is still set the irq will never
2595 * To prevent this scenario we read the Remote IRR bit
2596 * of the ioapic. This has two effects.
2597 * - On any sane system the read of the ioapic will
2598 * flush writes (and acks) going to the ioapic from
2600 * - We get to see if the ACK has actually been delivered.
2602 * Based on failed experiments of reprogramming the
2603 * ioapic entry from outside of irq context starting
2604 * with masking the ioapic entry and then polling until
2605 * Remote IRR was clear before reprogramming the
2606 * ioapic I don't trust the Remote IRR bit to be
2607 * completey accurate.
2609 * However there appears to be no other way to plug
2610 * this race, so if the Remote IRR bit is not
2611 * accurate and is causing problems then it is a hardware bug
2612 * and you can go talk to the chipset vendor about it.
2614 if (!io_apic_level_ack_pending(cfg))
2615 move_masked_irq(irq);
2620 #ifdef CONFIG_INTR_REMAP
2621 static void ir_ack_apic_edge(struct irq_data *data)
2626 static void ir_ack_apic_level(struct irq_data *data)
2629 eoi_ioapic_irq(data->irq, data->chip_data);
2631 #endif /* CONFIG_INTR_REMAP */
2633 static struct irq_chip ioapic_chip __read_mostly = {
2635 .irq_startup = startup_ioapic_irq,
2636 .irq_mask = mask_ioapic_irq,
2637 .irq_unmask = unmask_ioapic_irq,
2638 .irq_ack = ack_apic_edge,
2639 .irq_eoi = ack_apic_level,
2641 .irq_set_affinity = ioapic_set_affinity,
2643 .irq_retrigger = ioapic_retrigger_irq,
2646 static struct irq_chip ir_ioapic_chip __read_mostly = {
2647 .name = "IR-IO-APIC",
2648 .irq_startup = startup_ioapic_irq,
2649 .irq_mask = mask_ioapic_irq,
2650 .irq_unmask = unmask_ioapic_irq,
2651 #ifdef CONFIG_INTR_REMAP
2652 .irq_ack = ir_ack_apic_edge,
2653 .irq_eoi = ir_ack_apic_level,
2655 .irq_set_affinity = ir_ioapic_set_affinity,
2658 .irq_retrigger = ioapic_retrigger_irq,
2661 static inline void init_IO_APIC_traps(void)
2664 struct irq_desc *desc;
2665 struct irq_cfg *cfg;
2668 * NOTE! The local APIC isn't very good at handling
2669 * multiple interrupts at the same interrupt level.
2670 * As the interrupt level is determined by taking the
2671 * vector number and shifting that right by 4, we
2672 * want to spread these out a bit so that they don't
2673 * all fall in the same interrupt level.
2675 * Also, we've got to be careful not to trash gate
2676 * 0x80, because int 0x80 is hm, kind of importantish. ;)
2678 for_each_irq_desc(irq, desc) {
2679 cfg = get_irq_desc_chip_data(desc);
2680 if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) {
2682 * Hmm.. We don't have an entry for this,
2683 * so default to an old-fashioned 8259
2684 * interrupt if we can..
2686 if (irq < legacy_pic->nr_legacy_irqs)
2687 legacy_pic->make_irq(irq);
2689 /* Strange. Oh, well.. */
2690 desc->chip = &no_irq_chip;
2696 * The local APIC irq-chip implementation:
2699 static void mask_lapic_irq(struct irq_data *data)
2703 v = apic_read(APIC_LVT0);
2704 apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
2707 static void unmask_lapic_irq(struct irq_data *data)
2711 v = apic_read(APIC_LVT0);
2712 apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
2715 static void ack_lapic_irq(struct irq_data *data)
2720 static struct irq_chip lapic_chip __read_mostly = {
2721 .name = "local-APIC",
2722 .irq_mask = mask_lapic_irq,
2723 .irq_unmask = unmask_lapic_irq,
2724 .irq_ack = ack_lapic_irq,
2727 static void lapic_register_intr(int irq)
2729 irq_clear_status_flags(irq, IRQ_LEVEL);
2730 set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
2734 static void __init setup_nmi(void)
2737 * Dirty trick to enable the NMI watchdog ...
2738 * We put the 8259A master into AEOI mode and
2739 * unmask on all local APICs LVT0 as NMI.
2741 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
2742 * is from Maciej W. Rozycki - so we do not have to EOI from
2743 * the NMI handler or the timer interrupt.
2745 apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
2747 enable_NMI_through_LVT0();
2749 apic_printk(APIC_VERBOSE, " done.\n");
2753 * This looks a bit hackish but it's about the only one way of sending
2754 * a few INTA cycles to 8259As and any associated glue logic. ICR does
2755 * not support the ExtINT mode, unfortunately. We need to send these
2756 * cycles as some i82489DX-based boards have glue logic that keeps the
2757 * 8259A interrupt line asserted until INTA. --macro
2759 static inline void __init unlock_ExtINT_logic(void)
2762 struct IO_APIC_route_entry entry0, entry1;
2763 unsigned char save_control, save_freq_select;
2765 pin = find_isa_irq_pin(8, mp_INT);
2770 apic = find_isa_irq_apic(8, mp_INT);
2776 entry0 = ioapic_read_entry(apic, pin);
2777 clear_IO_APIC_pin(apic, pin);
2779 memset(&entry1, 0, sizeof(entry1));
2781 entry1.dest_mode = 0; /* physical delivery */
2782 entry1.mask = 0; /* unmask IRQ now */
2783 entry1.dest = hard_smp_processor_id();
2784 entry1.delivery_mode = dest_ExtINT;
2785 entry1.polarity = entry0.polarity;
2789 ioapic_write_entry(apic, pin, entry1);
2791 save_control = CMOS_READ(RTC_CONTROL);
2792 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
2793 CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
2795 CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
2800 if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
2804 CMOS_WRITE(save_control, RTC_CONTROL);
2805 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
2806 clear_IO_APIC_pin(apic, pin);
2808 ioapic_write_entry(apic, pin, entry0);
2811 static int disable_timer_pin_1 __initdata;
2812 /* Actually the next is obsolete, but keep it for paranoid reasons -AK */
2813 static int __init disable_timer_pin_setup(char *arg)
2815 disable_timer_pin_1 = 1;
2818 early_param("disable_timer_pin_1", disable_timer_pin_setup);
2820 int timer_through_8259 __initdata;
2823 * This code may look a bit paranoid, but it's supposed to cooperate with
2824 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
2825 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
2826 * fanatically on his truly buggy board.
2828 * FIXME: really need to revamp this for all platforms.
2830 static inline void __init check_timer(void)
2832 struct irq_cfg *cfg = get_irq_chip_data(0);
2833 int node = cpu_to_node(0);
2834 int apic1, pin1, apic2, pin2;
2835 unsigned long flags;
2838 local_irq_save(flags);
2841 * get/set the timer IRQ vector:
2843 legacy_pic->mask(0);
2844 assign_irq_vector(0, cfg, apic->target_cpus());
2847 * As IRQ0 is to be enabled in the 8259A, the virtual
2848 * wire has to be disabled in the local APIC. Also
2849 * timer interrupts need to be acknowledged manually in
2850 * the 8259A for the i82489DX when using the NMI
2851 * watchdog as that APIC treats NMIs as level-triggered.
2852 * The AEOI mode will finish them in the 8259A
2855 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
2856 legacy_pic->init(1);
2857 #ifdef CONFIG_X86_32
2861 ver = apic_read(APIC_LVR);
2862 ver = GET_APIC_VERSION(ver);
2863 timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver));
2867 pin1 = find_isa_irq_pin(0, mp_INT);
2868 apic1 = find_isa_irq_apic(0, mp_INT);
2869 pin2 = ioapic_i8259.pin;
2870 apic2 = ioapic_i8259.apic;
2872 apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X "
2873 "apic1=%d pin1=%d apic2=%d pin2=%d\n",
2874 cfg->vector, apic1, pin1, apic2, pin2);
2877 * Some BIOS writers are clueless and report the ExtINTA
2878 * I/O APIC input from the cascaded 8259A as the timer
2879 * interrupt input. So just in case, if only one pin
2880 * was found above, try it both directly and through the
2884 if (intr_remapping_enabled)
2885 panic("BIOS bug: timer not connected to IO-APIC");
2889 } else if (pin2 == -1) {
2896 * Ok, does IRQ0 through the IOAPIC work?
2899 add_pin_to_irq_node(cfg, node, apic1, pin1);
2900 setup_timer_IRQ0_pin(apic1, pin1, cfg->vector);
2902 /* for edge trigger, setup_ioapic_irq already
2903 * leave it unmasked.
2904 * so only need to unmask if it is level-trigger
2905 * do we really have level trigger timer?
2908 idx = find_irq_entry(apic1, pin1, mp_INT);
2909 if (idx != -1 && irq_trigger(idx))
2912 if (timer_irq_works()) {
2913 if (nmi_watchdog == NMI_IO_APIC) {
2915 legacy_pic->unmask(0);
2917 if (disable_timer_pin_1 > 0)
2918 clear_IO_APIC_pin(0, pin1);
2921 if (intr_remapping_enabled)
2922 panic("timer doesn't work through Interrupt-remapped IO-APIC");
2923 local_irq_disable();
2924 clear_IO_APIC_pin(apic1, pin1);
2926 apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: "
2927 "8254 timer not connected to IO-APIC\n");
2929 apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer "
2930 "(IRQ0) through the 8259A ...\n");
2931 apic_printk(APIC_QUIET, KERN_INFO
2932 "..... (found apic %d pin %d) ...\n", apic2, pin2);
2934 * legacy devices should be connected to IO APIC #0
2936 replace_pin_at_irq_node(cfg, node, apic1, pin1, apic2, pin2);
2937 setup_timer_IRQ0_pin(apic2, pin2, cfg->vector);
2938 legacy_pic->unmask(0);
2939 if (timer_irq_works()) {
2940 apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
2941 timer_through_8259 = 1;
2942 if (nmi_watchdog == NMI_IO_APIC) {
2943 legacy_pic->mask(0);
2945 legacy_pic->unmask(0);
2950 * Cleanup, just in case ...
2952 local_irq_disable();
2953 legacy_pic->mask(0);
2954 clear_IO_APIC_pin(apic2, pin2);
2955 apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n");
2958 if (nmi_watchdog == NMI_IO_APIC) {
2959 apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work "
2960 "through the IO-APIC - disabling NMI Watchdog!\n");
2961 nmi_watchdog = NMI_NONE;
2963 #ifdef CONFIG_X86_32
2967 apic_printk(APIC_QUIET, KERN_INFO
2968 "...trying to set up timer as Virtual Wire IRQ...\n");
2970 lapic_register_intr(0);
2971 apic_write(APIC_LVT0, APIC_DM_FIXED | cfg->vector); /* Fixed mode */
2972 legacy_pic->unmask(0);
2974 if (timer_irq_works()) {
2975 apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
2978 local_irq_disable();
2979 legacy_pic->mask(0);
2980 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | cfg->vector);
2981 apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n");
2983 apic_printk(APIC_QUIET, KERN_INFO
2984 "...trying to set up timer as ExtINT IRQ...\n");
2986 legacy_pic->init(0);
2987 legacy_pic->make_irq(0);
2988 apic_write(APIC_LVT0, APIC_DM_EXTINT);
2990 unlock_ExtINT_logic();
2992 if (timer_irq_works()) {
2993 apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
2996 local_irq_disable();
2997 apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
2998 panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
2999 "report. Then try booting with the 'noapic' option.\n");
3001 local_irq_restore(flags);
3005 * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
3006 * to devices. However there may be an I/O APIC pin available for
3007 * this interrupt regardless. The pin may be left unconnected, but
3008 * typically it will be reused as an ExtINT cascade interrupt for
3009 * the master 8259A. In the MPS case such a pin will normally be
3010 * reported as an ExtINT interrupt in the MP table. With ACPI
3011 * there is no provision for ExtINT interrupts, and in the absence
3012 * of an override it would be treated as an ordinary ISA I/O APIC
3013 * interrupt, that is edge-triggered and unmasked by default. We
3014 * used to do this, but it caused problems on some systems because
3015 * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
3016 * the same ExtINT cascade interrupt to drive the local APIC of the
3017 * bootstrap processor. Therefore we refrain from routing IRQ2 to
3018 * the I/O APIC in all cases now. No actual device should request
3019 * it anyway. --macro
3021 #define PIC_IRQS (1UL << PIC_CASCADE_IR)
3023 void __init setup_IO_APIC(void)
3027 * calling enable_IO_APIC() is moved to setup_local_APIC for BP
3029 io_apic_irqs = legacy_pic->nr_legacy_irqs ? ~PIC_IRQS : ~0UL;
3031 apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n");
3033 * Set up IO-APIC IRQ routing.
3035 x86_init.mpparse.setup_ioapic_ids();
3038 setup_IO_APIC_irqs();
3039 init_IO_APIC_traps();
3040 if (legacy_pic->nr_legacy_irqs)
3045 * Called after all the initialization is done. If we didnt find any
3046 * APIC bugs then we can allow the modify fast path
3049 static int __init io_apic_bug_finalize(void)
3051 if (sis_apic_bug == -1)
3056 late_initcall(io_apic_bug_finalize);
3058 struct sysfs_ioapic_data {
3059 struct sys_device dev;
3060 struct IO_APIC_route_entry entry[0];
3062 static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];
3064 static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
3066 struct IO_APIC_route_entry *entry;
3067 struct sysfs_ioapic_data *data;
3070 data = container_of(dev, struct sysfs_ioapic_data, dev);
3071 entry = data->entry;
3072 for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ )
3073 *entry = ioapic_read_entry(dev->id, i);
3078 static int ioapic_resume(struct sys_device *dev)
3080 struct IO_APIC_route_entry *entry;
3081 struct sysfs_ioapic_data *data;
3082 unsigned long flags;
3083 union IO_APIC_reg_00 reg_00;
3086 data = container_of(dev, struct sysfs_ioapic_data, dev);
3087 entry = data->entry;
3089 raw_spin_lock_irqsave(&ioapic_lock, flags);
3090 reg_00.raw = io_apic_read(dev->id, 0);
3091 if (reg_00.bits.ID != mp_ioapics[dev->id].apicid) {
3092 reg_00.bits.ID = mp_ioapics[dev->id].apicid;
3093 io_apic_write(dev->id, 0, reg_00.raw);
3095 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
3096 for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
3097 ioapic_write_entry(dev->id, i, entry[i]);
3102 static struct sysdev_class ioapic_sysdev_class = {
3104 .suspend = ioapic_suspend,
3105 .resume = ioapic_resume,
3108 static int __init ioapic_init_sysfs(void)
3110 struct sys_device * dev;
3113 error = sysdev_class_register(&ioapic_sysdev_class);
3117 for (i = 0; i < nr_ioapics; i++ ) {
3118 size = sizeof(struct sys_device) + nr_ioapic_registers[i]
3119 * sizeof(struct IO_APIC_route_entry);
3120 mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
3121 if (!mp_ioapic_data[i]) {
3122 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
3125 dev = &mp_ioapic_data[i]->dev;
3127 dev->cls = &ioapic_sysdev_class;
3128 error = sysdev_register(dev);
3130 kfree(mp_ioapic_data[i]);
3131 mp_ioapic_data[i] = NULL;
3132 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
3140 device_initcall(ioapic_init_sysfs);
3143 * Dynamic irq allocate and deallocation
3145 unsigned int create_irq_nr(unsigned int irq_want, int node)
3147 /* Allocate an unused irq */
3150 unsigned long flags;
3151 struct irq_cfg *cfg_new = NULL;
3152 struct irq_desc *desc_new = NULL;
3155 if (irq_want < nr_irqs_gsi)
3156 irq_want = nr_irqs_gsi;
3158 raw_spin_lock_irqsave(&vector_lock, flags);
3159 for (new = irq_want; new < nr_irqs; new++) {
3160 desc_new = irq_to_desc_alloc_node(new, node);
3162 printk(KERN_INFO "can not get irq_desc for %d\n", new);
3165 cfg_new = get_irq_desc_chip_data(desc_new);
3167 if (cfg_new->vector != 0)
3170 desc_new = move_irq_desc(desc_new, node);
3171 cfg_new = get_irq_desc_chip_data(desc_new);
3173 if (__assign_irq_vector(new, cfg_new, apic->target_cpus()) == 0)
3177 raw_spin_unlock_irqrestore(&vector_lock, flags);
3180 dynamic_irq_init_keep_chip_data(irq);
3185 int create_irq(void)
3187 int node = cpu_to_node(0);
3188 unsigned int irq_want;
3191 irq_want = nr_irqs_gsi;
3192 irq = create_irq_nr(irq_want, node);
3200 void destroy_irq(unsigned int irq)
3202 unsigned long flags;
3204 dynamic_irq_cleanup_keep_chip_data(irq);
3207 raw_spin_lock_irqsave(&vector_lock, flags);
3208 __clear_irq_vector(irq, get_irq_chip_data(irq));
3209 raw_spin_unlock_irqrestore(&vector_lock, flags);
3213 * MSI message composition
3215 #ifdef CONFIG_PCI_MSI
3216 static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq,
3217 struct msi_msg *msg, u8 hpet_id)
3219 struct irq_cfg *cfg;
3227 err = assign_irq_vector(irq, cfg, apic->target_cpus());
3231 dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
3233 if (irq_remapped(irq)) {
3238 ir_index = map_irq_to_irte_handle(irq, &sub_handle);
3239 BUG_ON(ir_index == -1);
3241 prepare_irte(&irte, cfg->vector, dest);
3243 /* Set source-id of interrupt request */
3245 set_msi_sid(&irte, pdev);
3247 set_hpet_sid(&irte, hpet_id);
3249 modify_irte(irq, &irte);
3251 msg->address_hi = MSI_ADDR_BASE_HI;
3252 msg->data = sub_handle;
3253 msg->address_lo = MSI_ADDR_BASE_LO | MSI_ADDR_IR_EXT_INT |
3255 MSI_ADDR_IR_INDEX1(ir_index) |
3256 MSI_ADDR_IR_INDEX2(ir_index);
3258 if (x2apic_enabled())
3259 msg->address_hi = MSI_ADDR_BASE_HI |
3260 MSI_ADDR_EXT_DEST_ID(dest);
3262 msg->address_hi = MSI_ADDR_BASE_HI;
3266 ((apic->irq_dest_mode == 0) ?
3267 MSI_ADDR_DEST_MODE_PHYSICAL:
3268 MSI_ADDR_DEST_MODE_LOGICAL) |
3269 ((apic->irq_delivery_mode != dest_LowestPrio) ?
3270 MSI_ADDR_REDIRECTION_CPU:
3271 MSI_ADDR_REDIRECTION_LOWPRI) |
3272 MSI_ADDR_DEST_ID(dest);
3275 MSI_DATA_TRIGGER_EDGE |
3276 MSI_DATA_LEVEL_ASSERT |
3277 ((apic->irq_delivery_mode != dest_LowestPrio) ?
3278 MSI_DATA_DELIVERY_FIXED:
3279 MSI_DATA_DELIVERY_LOWPRI) |
3280 MSI_DATA_VECTOR(cfg->vector);
3287 msi_set_affinity(struct irq_data *data, const struct cpumask *mask, bool force)
3289 struct irq_cfg *cfg = data->chip_data;
3293 if (__ioapic_set_affinity(data, mask, &dest))
3296 __get_cached_msi_msg(data->msi_desc, &msg);
3298 msg.data &= ~MSI_DATA_VECTOR_MASK;
3299 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3300 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3301 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3303 __write_msi_msg(data->msi_desc, &msg);
3307 #ifdef CONFIG_INTR_REMAP
3309 * Migrate the MSI irq to another cpumask. This migration is
3310 * done in the process context using interrupt-remapping hardware.
3313 ir_set_msi_irq_affinity(unsigned int irq, const struct cpumask *mask)
3315 struct irq_desc *desc = irq_to_desc(irq);
3316 struct irq_cfg *cfg = get_irq_desc_chip_data(desc);
3320 if (get_irte(irq, &irte))
3323 if (__ioapic_set_affinity(&desc->irq_data, mask, &dest))
3326 irte.vector = cfg->vector;
3327 irte.dest_id = IRTE_DEST(dest);
3330 * atomically update the IRTE with the new destination and vector.
3332 modify_irte(irq, &irte);
3335 * After this point, all the interrupts will start arriving
3336 * at the new destination. So, time to cleanup the previous
3337 * vector allocation.
3339 if (cfg->move_in_progress)
3340 send_cleanup_vector(cfg);
3346 #endif /* CONFIG_SMP */
3349 * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
3350 * which implement the MSI or MSI-X Capability Structure.
3352 static struct irq_chip msi_chip = {
3354 .irq_unmask = unmask_msi_irq,
3355 .irq_mask = mask_msi_irq,
3356 .irq_ack = ack_apic_edge,
3358 .irq_set_affinity = msi_set_affinity,
3360 .irq_retrigger = ioapic_retrigger_irq,
3363 static struct irq_chip msi_ir_chip = {
3364 .name = "IR-PCI-MSI",
3365 .irq_unmask = unmask_msi_irq,
3366 .irq_mask = mask_msi_irq,
3367 #ifdef CONFIG_INTR_REMAP
3368 .irq_ack = ir_ack_apic_edge,
3370 .set_affinity = ir_set_msi_irq_affinity,
3373 .irq_retrigger = ioapic_retrigger_irq,
3377 * Map the PCI dev to the corresponding remapping hardware unit
3378 * and allocate 'nvec' consecutive interrupt-remapping table entries
3381 static int msi_alloc_irte(struct pci_dev *dev, int irq, int nvec)
3383 struct intel_iommu *iommu;
3386 iommu = map_dev_to_ir(dev);
3389 "Unable to map PCI %s to iommu\n", pci_name(dev));
3393 index = alloc_irte(iommu, irq, nvec);
3396 "Unable to allocate %d IRTE for PCI %s\n", nvec,
3403 static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)
3408 ret = msi_compose_msg(dev, irq, &msg, -1);
3412 set_irq_msi(irq, msidesc);
3413 write_msi_msg(irq, &msg);
3415 if (irq_remapped(irq)) {
3416 irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
3417 set_irq_chip_and_handler_name(irq, &msi_ir_chip, handle_edge_irq, "edge");
3419 set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge");
3421 dev_printk(KERN_DEBUG, &dev->dev, "irq %d for MSI/MSI-X\n", irq);
3426 int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
3428 int node, ret, sub_handle, index = 0;
3429 unsigned int irq, irq_want;
3430 struct msi_desc *msidesc;
3431 struct intel_iommu *iommu = NULL;
3433 /* x86 doesn't support multiple MSI yet */
3434 if (type == PCI_CAP_ID_MSI && nvec > 1)
3437 node = dev_to_node(&dev->dev);
3438 irq_want = nr_irqs_gsi;
3440 list_for_each_entry(msidesc, &dev->msi_list, list) {
3441 irq = create_irq_nr(irq_want, node);
3445 if (!intr_remapping_enabled)
3450 * allocate the consecutive block of IRTE's
3453 index = msi_alloc_irte(dev, irq, nvec);
3459 iommu = map_dev_to_ir(dev);
3465 * setup the mapping between the irq and the IRTE
3466 * base index, the sub_handle pointing to the
3467 * appropriate interrupt remap table entry.
3469 set_irte_irq(irq, iommu, index, sub_handle);
3472 ret = setup_msi_irq(dev, msidesc, irq);
3484 void arch_teardown_msi_irq(unsigned int irq)
3489 #if defined (CONFIG_DMAR) || defined (CONFIG_INTR_REMAP)
3491 static int dmar_msi_set_affinity(unsigned int irq, const struct cpumask *mask)
3493 struct irq_desc *desc = irq_to_desc(irq);
3494 struct irq_cfg *cfg;
3498 if (__ioapic_set_affinity(&desc->irq_data, mask, &dest))
3501 cfg = get_irq_desc_chip_data(desc);
3503 dmar_msi_read(irq, &msg);
3505 msg.data &= ~MSI_DATA_VECTOR_MASK;
3506 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3507 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3508 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3510 dmar_msi_write(irq, &msg);
3515 #endif /* CONFIG_SMP */
3517 static struct irq_chip dmar_msi_type = {
3519 .irq_unmask = dmar_msi_unmask,
3520 .irq_mask = dmar_msi_mask,
3521 .irq_ack = ack_apic_edge,
3523 .set_affinity = dmar_msi_set_affinity,
3525 .irq_retrigger = ioapic_retrigger_irq,
3528 int arch_setup_dmar_msi(unsigned int irq)
3533 ret = msi_compose_msg(NULL, irq, &msg, -1);
3536 dmar_msi_write(irq, &msg);
3537 set_irq_chip_and_handler_name(irq, &dmar_msi_type, handle_edge_irq,
3543 #ifdef CONFIG_HPET_TIMER
3546 static int hpet_msi_set_affinity(struct irq_data *data,
3547 const struct cpumask *mask, bool force)
3549 struct irq_desc *desc = irq_to_desc(data->irq);
3550 struct irq_cfg *cfg = data->chip_data;
3554 if (__ioapic_set_affinity(&desc->irq_data, mask, &dest))
3557 hpet_msi_read(data->handler_data, &msg);
3559 msg.data &= ~MSI_DATA_VECTOR_MASK;
3560 msg.data |= MSI_DATA_VECTOR(cfg->vector);
3561 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
3562 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
3564 hpet_msi_write(data->handler_data, &msg);
3569 #endif /* CONFIG_SMP */
3571 static struct irq_chip ir_hpet_msi_type = {
3572 .name = "IR-HPET_MSI",
3573 .irq_unmask = hpet_msi_unmask,
3574 .irq_mask = hpet_msi_mask,
3575 #ifdef CONFIG_INTR_REMAP
3576 .irq_ack = ir_ack_apic_edge,
3578 .set_affinity = ir_set_msi_irq_affinity,
3581 .irq_retrigger = ioapic_retrigger_irq,
3584 static struct irq_chip hpet_msi_type = {
3586 .irq_unmask = hpet_msi_unmask,
3587 .irq_mask = hpet_msi_mask,
3588 .irq_ack = ack_apic_edge,
3590 .irq_set_affinity = hpet_msi_set_affinity,
3592 .irq_retrigger = ioapic_retrigger_irq,
3595 int arch_setup_hpet_msi(unsigned int irq, unsigned int id)
3600 if (intr_remapping_enabled) {
3601 struct intel_iommu *iommu = map_hpet_to_ir(id);
3607 index = alloc_irte(iommu, irq, 1);
3612 ret = msi_compose_msg(NULL, irq, &msg, id);
3616 hpet_msi_write(get_irq_data(irq), &msg);
3617 irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
3618 if (irq_remapped(irq))
3619 set_irq_chip_and_handler_name(irq, &ir_hpet_msi_type,
3620 handle_edge_irq, "edge");
3622 set_irq_chip_and_handler_name(irq, &hpet_msi_type,
3623 handle_edge_irq, "edge");
3629 #endif /* CONFIG_PCI_MSI */
3631 * Hypertransport interrupt support
3633 #ifdef CONFIG_HT_IRQ
3637 static void target_ht_irq(unsigned int irq, unsigned int dest, u8 vector)
3639 struct ht_irq_msg msg;
3640 fetch_ht_irq_msg(irq, &msg);
3642 msg.address_lo &= ~(HT_IRQ_LOW_VECTOR_MASK | HT_IRQ_LOW_DEST_ID_MASK);
3643 msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
3645 msg.address_lo |= HT_IRQ_LOW_VECTOR(vector) | HT_IRQ_LOW_DEST_ID(dest);
3646 msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest);
3648 write_ht_irq_msg(irq, &msg);
3651 static int set_ht_irq_affinity(unsigned int irq, const struct cpumask *mask)
3653 struct irq_desc *desc = irq_to_desc(irq);
3654 struct irq_cfg *cfg;
3657 if (__ioapic_set_affinity(&desc->irq_data, mask, &dest))
3660 cfg = get_irq_desc_chip_data(desc);
3662 target_ht_irq(irq, dest, cfg->vector);
3669 static struct irq_chip ht_irq_chip = {
3671 .irq_mask = mask_ht_irq,
3672 .irq_unmask = unmask_ht_irq,
3673 .irq_ack = ack_apic_edge,
3675 .set_affinity = set_ht_irq_affinity,
3677 .irq_retrigger = ioapic_retrigger_irq,
3680 int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
3682 struct irq_cfg *cfg;
3689 err = assign_irq_vector(irq, cfg, apic->target_cpus());
3691 struct ht_irq_msg msg;
3694 dest = apic->cpu_mask_to_apicid_and(cfg->domain,
3695 apic->target_cpus());
3697 msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest);
3701 HT_IRQ_LOW_DEST_ID(dest) |
3702 HT_IRQ_LOW_VECTOR(cfg->vector) |
3703 ((apic->irq_dest_mode == 0) ?
3704 HT_IRQ_LOW_DM_PHYSICAL :
3705 HT_IRQ_LOW_DM_LOGICAL) |
3706 HT_IRQ_LOW_RQEOI_EDGE |
3707 ((apic->irq_delivery_mode != dest_LowestPrio) ?
3708 HT_IRQ_LOW_MT_FIXED :
3709 HT_IRQ_LOW_MT_ARBITRATED) |
3710 HT_IRQ_LOW_IRQ_MASKED;
3712 write_ht_irq_msg(irq, &msg);
3714 set_irq_chip_and_handler_name(irq, &ht_irq_chip,
3715 handle_edge_irq, "edge");
3717 dev_printk(KERN_DEBUG, &dev->dev, "irq %d for HT\n", irq);
3721 #endif /* CONFIG_HT_IRQ */
3723 int __init io_apic_get_redir_entries (int ioapic)
3725 union IO_APIC_reg_01 reg_01;
3726 unsigned long flags;
3728 raw_spin_lock_irqsave(&ioapic_lock, flags);
3729 reg_01.raw = io_apic_read(ioapic, 1);
3730 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
3732 /* The register returns the maximum index redir index
3733 * supported, which is one less than the total number of redir
3736 return reg_01.bits.entries + 1;
3739 void __init probe_nr_irqs_gsi(void)
3743 nr = gsi_top + NR_IRQS_LEGACY;
3744 if (nr > nr_irqs_gsi)
3747 printk(KERN_DEBUG "nr_irqs_gsi: %d\n", nr_irqs_gsi);
3750 #ifdef CONFIG_SPARSE_IRQ
3751 int __init arch_probe_nr_irqs(void)
3755 if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
3756 nr_irqs = NR_VECTORS * nr_cpu_ids;
3758 nr = nr_irqs_gsi + 8 * nr_cpu_ids;
3759 #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
3761 * for MSI and HT dyn irq
3763 nr += nr_irqs_gsi * 16;
3768 return NR_IRQS_LEGACY;
3772 static int __io_apic_set_pci_routing(struct device *dev, int irq,
3773 struct io_apic_irq_attr *irq_attr)
3775 struct irq_desc *desc;
3776 struct irq_cfg *cfg;
3779 int trigger, polarity;
3781 ioapic = irq_attr->ioapic;
3782 if (!IO_APIC_IRQ(irq)) {
3783 apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
3789 node = dev_to_node(dev);
3791 node = cpu_to_node(0);
3793 desc = irq_to_desc_alloc_node(irq, node);
3795 printk(KERN_INFO "can not get irq_desc %d\n", irq);
3799 pin = irq_attr->ioapic_pin;
3800 trigger = irq_attr->trigger;
3801 polarity = irq_attr->polarity;
3803 cfg = get_irq_desc_chip_data(desc);
3806 * IRQs < 16 are already in the irq_2_pin[] map
3808 if (irq >= legacy_pic->nr_legacy_irqs) {
3809 if (add_pin_to_irq_node_nopanic(cfg, node, ioapic, pin)) {
3810 printk(KERN_INFO "can not add pin %d for irq %d\n",
3816 setup_ioapic_irq(ioapic, pin, irq, cfg, trigger, polarity);
3821 int io_apic_set_pci_routing(struct device *dev, int irq,
3822 struct io_apic_irq_attr *irq_attr)
3826 * Avoid pin reprogramming. PRTs typically include entries
3827 * with redundant pin->gsi mappings (but unique PCI devices);
3828 * we only program the IOAPIC on the first.
3830 ioapic = irq_attr->ioapic;
3831 pin = irq_attr->ioapic_pin;
3832 if (test_bit(pin, mp_ioapic_routing[ioapic].pin_programmed)) {
3833 pr_debug("Pin %d-%d already programmed\n",
3834 mp_ioapics[ioapic].apicid, pin);
3837 set_bit(pin, mp_ioapic_routing[ioapic].pin_programmed);
3839 return __io_apic_set_pci_routing(dev, irq, irq_attr);
3842 u8 __init io_apic_unique_id(u8 id)
3844 #ifdef CONFIG_X86_32
3845 if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
3846 !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
3847 return io_apic_get_unique_id(nr_ioapics, id);
3852 DECLARE_BITMAP(used, 256);
3854 bitmap_zero(used, 256);
3855 for (i = 0; i < nr_ioapics; i++) {
3856 struct mpc_ioapic *ia = &mp_ioapics[i];
3857 __set_bit(ia->apicid, used);
3859 if (!test_bit(id, used))
3861 return find_first_zero_bit(used, 256);
3865 #ifdef CONFIG_X86_32
3866 int __init io_apic_get_unique_id(int ioapic, int apic_id)
3868 union IO_APIC_reg_00 reg_00;
3869 static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
3871 unsigned long flags;
3875 * The P4 platform supports up to 256 APIC IDs on two separate APIC
3876 * buses (one for LAPICs, one for IOAPICs), where predecessors only
3877 * supports up to 16 on one shared APIC bus.
3879 * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
3880 * advantage of new APIC bus architecture.
3883 if (physids_empty(apic_id_map))
3884 apic->ioapic_phys_id_map(&phys_cpu_present_map, &apic_id_map);
3886 raw_spin_lock_irqsave(&ioapic_lock, flags);
3887 reg_00.raw = io_apic_read(ioapic, 0);
3888 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
3890 if (apic_id >= get_physical_broadcast()) {
3891 printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
3892 "%d\n", ioapic, apic_id, reg_00.bits.ID);
3893 apic_id = reg_00.bits.ID;
3897 * Every APIC in a system must have a unique ID or we get lots of nice
3898 * 'stuck on smp_invalidate_needed IPI wait' messages.
3900 if (apic->check_apicid_used(&apic_id_map, apic_id)) {
3902 for (i = 0; i < get_physical_broadcast(); i++) {
3903 if (!apic->check_apicid_used(&apic_id_map, i))
3907 if (i == get_physical_broadcast())
3908 panic("Max apic_id exceeded!\n");
3910 printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
3911 "trying %d\n", ioapic, apic_id, i);
3916 apic->apicid_to_cpu_present(apic_id, &tmp);
3917 physids_or(apic_id_map, apic_id_map, tmp);
3919 if (reg_00.bits.ID != apic_id) {
3920 reg_00.bits.ID = apic_id;
3922 raw_spin_lock_irqsave(&ioapic_lock, flags);
3923 io_apic_write(ioapic, 0, reg_00.raw);
3924 reg_00.raw = io_apic_read(ioapic, 0);
3925 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
3928 if (reg_00.bits.ID != apic_id) {
3929 printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
3934 apic_printk(APIC_VERBOSE, KERN_INFO
3935 "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
3941 int __init io_apic_get_version(int ioapic)
3943 union IO_APIC_reg_01 reg_01;
3944 unsigned long flags;
3946 raw_spin_lock_irqsave(&ioapic_lock, flags);
3947 reg_01.raw = io_apic_read(ioapic, 1);
3948 raw_spin_unlock_irqrestore(&ioapic_lock, flags);
3950 return reg_01.bits.version;
3953 int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity)
3955 int ioapic, pin, idx;
3957 if (skip_ioapic_setup)
3960 ioapic = mp_find_ioapic(gsi);
3964 pin = mp_find_ioapic_pin(ioapic, gsi);
3968 idx = find_irq_entry(ioapic, pin, mp_INT);
3972 *trigger = irq_trigger(idx);
3973 *polarity = irq_polarity(idx);
3978 * This function currently is only a helper for the i386 smp boot process where
3979 * we need to reprogram the ioredtbls to cater for the cpus which have come online
3980 * so mask in all cases should simply be apic->target_cpus()
3983 void __init setup_ioapic_dest(void)
3985 int pin, ioapic, irq, irq_entry;
3986 struct irq_desc *desc;
3987 const struct cpumask *mask;
3989 if (skip_ioapic_setup == 1)
3992 for (ioapic = 0; ioapic < nr_ioapics; ioapic++)
3993 for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
3994 irq_entry = find_irq_entry(ioapic, pin, mp_INT);
3995 if (irq_entry == -1)
3997 irq = pin_2_irq(irq_entry, ioapic, pin);
3999 if ((ioapic > 0) && (irq > 16))
4002 desc = irq_to_desc(irq);
4005 * Honour affinities which have been set in early boot
4008 (IRQ_NO_BALANCING | IRQ_AFFINITY_SET))
4009 mask = desc->irq_data.affinity;
4011 mask = apic->target_cpus();
4013 if (intr_remapping_enabled)
4014 ir_ioapic_set_affinity(&desc->irq_data, mask, false);
4016 ioapic_set_affinity(&desc->irq_data, mask, false);
4022 #define IOAPIC_RESOURCE_NAME_SIZE 11
4024 static struct resource *ioapic_resources;
4026 static struct resource * __init ioapic_setup_resources(int nr_ioapics)
4029 struct resource *res;
4033 if (nr_ioapics <= 0)
4036 n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource);
4039 mem = alloc_bootmem(n);
4042 mem += sizeof(struct resource) * nr_ioapics;
4044 for (i = 0; i < nr_ioapics; i++) {
4046 res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY;
4047 snprintf(mem, IOAPIC_RESOURCE_NAME_SIZE, "IOAPIC %u", i);
4048 mem += IOAPIC_RESOURCE_NAME_SIZE;
4051 ioapic_resources = res;
4056 void __init ioapic_init_mappings(void)
4058 unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
4059 struct resource *ioapic_res;
4062 ioapic_res = ioapic_setup_resources(nr_ioapics);
4063 for (i = 0; i < nr_ioapics; i++) {
4064 if (smp_found_config) {
4065 ioapic_phys = mp_ioapics[i].apicaddr;
4066 #ifdef CONFIG_X86_32
4069 "WARNING: bogus zero IO-APIC "
4070 "address found in MPTABLE, "
4071 "disabling IO/APIC support!\n");
4072 smp_found_config = 0;
4073 skip_ioapic_setup = 1;
4074 goto fake_ioapic_page;
4078 #ifdef CONFIG_X86_32
4081 ioapic_phys = (unsigned long)alloc_bootmem_pages(PAGE_SIZE);
4082 ioapic_phys = __pa(ioapic_phys);
4084 set_fixmap_nocache(idx, ioapic_phys);
4085 apic_printk(APIC_VERBOSE, "mapped IOAPIC to %08lx (%08lx)\n",
4086 __fix_to_virt(idx) + (ioapic_phys & ~PAGE_MASK),
4090 ioapic_res->start = ioapic_phys;
4091 ioapic_res->end = ioapic_phys + IO_APIC_SLOT_SIZE - 1;
4096 void __init ioapic_insert_resources(void)
4099 struct resource *r = ioapic_resources;
4104 "IO APIC resources couldn't be allocated.\n");
4108 for (i = 0; i < nr_ioapics; i++) {
4109 insert_resource(&iomem_resource, r);
4114 int mp_find_ioapic(u32 gsi)
4118 /* Find the IOAPIC that manages this GSI. */
4119 for (i = 0; i < nr_ioapics; i++) {
4120 if ((gsi >= mp_gsi_routing[i].gsi_base)
4121 && (gsi <= mp_gsi_routing[i].gsi_end))
4125 printk(KERN_ERR "ERROR: Unable to locate IOAPIC for GSI %d\n", gsi);
4129 int mp_find_ioapic_pin(int ioapic, u32 gsi)
4131 if (WARN_ON(ioapic == -1))
4133 if (WARN_ON(gsi > mp_gsi_routing[ioapic].gsi_end))
4136 return gsi - mp_gsi_routing[ioapic].gsi_base;
4139 static int bad_ioapic(unsigned long address)
4141 if (nr_ioapics >= MAX_IO_APICS) {
4142 printk(KERN_WARNING "WARING: Max # of I/O APICs (%d) exceeded "
4143 "(found %d), skipping\n", MAX_IO_APICS, nr_ioapics);
4147 printk(KERN_WARNING "WARNING: Bogus (zero) I/O APIC address"
4148 " found in table, skipping!\n");
4154 void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
4159 if (bad_ioapic(address))
4164 mp_ioapics[idx].type = MP_IOAPIC;
4165 mp_ioapics[idx].flags = MPC_APIC_USABLE;
4166 mp_ioapics[idx].apicaddr = address;
4168 set_fixmap_nocache(FIX_IO_APIC_BASE_0 + idx, address);
4169 mp_ioapics[idx].apicid = io_apic_unique_id(id);
4170 mp_ioapics[idx].apicver = io_apic_get_version(idx);
4173 * Build basic GSI lookup table to facilitate gsi->io_apic lookups
4174 * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
4176 entries = io_apic_get_redir_entries(idx);
4177 mp_gsi_routing[idx].gsi_base = gsi_base;
4178 mp_gsi_routing[idx].gsi_end = gsi_base + entries - 1;
4181 * The number of IO-APIC IRQ registers (== #pins):
4183 nr_ioapic_registers[idx] = entries;
4185 if (mp_gsi_routing[idx].gsi_end >= gsi_top)
4186 gsi_top = mp_gsi_routing[idx].gsi_end + 1;
4188 printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
4189 "GSI %d-%d\n", idx, mp_ioapics[idx].apicid,
4190 mp_ioapics[idx].apicver, mp_ioapics[idx].apicaddr,
4191 mp_gsi_routing[idx].gsi_base, mp_gsi_routing[idx].gsi_end);
4196 /* Enable IOAPIC early just for system timer */
4197 void __init pre_init_apic_IRQ0(void)
4199 struct irq_cfg *cfg;
4201 printk(KERN_INFO "Early APIC setup for system timer0\n");
4203 phys_cpu_present_map = physid_mask_of_physid(boot_cpu_physical_apicid);
4205 irq_to_desc_alloc_node(0, 0);
4210 add_pin_to_irq_node(cfg, 0, 0, 0);
4211 set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge");
4213 setup_ioapic_irq(0, 0, 0, cfg, 0, 0);