2 * Intel IO-APIC support for multi-Pentium hosts.
4 * Copyright (C) 1997, 1998, 1999, 2000 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/bootmem.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/pci.h>
35 #include <linux/msi.h>
36 #include <linux/htirq.h>
37 #include <linux/freezer.h>
38 #include <linux/kthread.h>
39 #include <linux/jiffies.h> /* time_after() */
44 #include <asm/timer.h>
45 #include <asm/i8259.h>
47 #include <asm/msidef.h>
48 #include <asm/hypertransport.h>
49 #include <asm/setup.h>
51 #include <mach_apic.h>
52 #include <mach_apicdef.h>
54 #define __apicdebuginit(type) static type __init
56 int (*ioapic_renumber_irq)(int ioapic, int irq);
57 atomic_t irq_mis_count;
59 /* Where if anywhere is the i8259 connect in external int mode */
60 static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
62 static DEFINE_SPINLOCK(ioapic_lock);
63 DEFINE_SPINLOCK(vector_lock);
65 int timer_through_8259 __initdata;
68 * Is the SiS APIC rmw bug present ?
69 * -1 = don't know, 0 = no, 1 = yes
71 int sis_apic_bug = -1;
75 * # of IRQ routing registers
77 int nr_ioapic_registers[MAX_IO_APICS];
79 /* I/O APIC entries */
80 struct mp_config_ioapic mp_ioapics[MAX_IO_APICS];
83 /* MP IRQ source entries */
84 struct mp_config_intsrc mp_irqs[MAX_IRQ_SOURCES];
86 /* # of MP IRQ source entries */
89 #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
90 int mp_bus_id_to_type[MAX_MP_BUSSES];
93 DECLARE_BITMAP(mp_bus_not_pci, MAX_MP_BUSSES);
95 static int disable_timer_pin_1 __initdata;
98 * Rough estimation of how many shared IRQs there are, can
104 * This is performance-critical, we want to do it O(1)
106 * the indexing order of this array favors 1:1 mappings
107 * between pins and IRQs.
110 static struct irq_pin_list {
114 DEFINE_DYN_ARRAY(irq_2_pin, sizeof(struct irq_pin_list), pin_map_size, 16, NULL);
118 unsigned int unused[3];
122 static __attribute_const__ struct io_apic __iomem *io_apic_base(int idx)
124 return (void __iomem *) __fix_to_virt(FIX_IO_APIC_BASE_0 + idx)
125 + (mp_ioapics[idx].mp_apicaddr & ~PAGE_MASK);
128 static inline unsigned int io_apic_read(unsigned int apic, unsigned int reg)
130 struct io_apic __iomem *io_apic = io_apic_base(apic);
131 writel(reg, &io_apic->index);
132 return readl(&io_apic->data);
135 static inline void io_apic_write(unsigned int apic, unsigned int reg, unsigned int value)
137 struct io_apic __iomem *io_apic = io_apic_base(apic);
138 writel(reg, &io_apic->index);
139 writel(value, &io_apic->data);
143 * Re-write a value: to be used for read-modify-write
144 * cycles where the read already set up the index register.
146 * Older SiS APIC requires we rewrite the index register
148 static inline void io_apic_modify(unsigned int apic, unsigned int reg, unsigned int value)
150 volatile struct io_apic __iomem *io_apic = io_apic_base(apic);
152 writel(reg, &io_apic->index);
153 writel(value, &io_apic->data);
157 struct { u32 w1, w2; };
158 struct IO_APIC_route_entry entry;
161 static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
163 union entry_union eu;
165 spin_lock_irqsave(&ioapic_lock, flags);
166 eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
167 eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
168 spin_unlock_irqrestore(&ioapic_lock, flags);
173 * When we write a new IO APIC routing entry, we need to write the high
174 * word first! If the mask bit in the low word is clear, we will enable
175 * the interrupt, and we need to make sure the entry is fully populated
176 * before that happens.
179 __ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
181 union entry_union eu;
183 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
184 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
187 static void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
190 spin_lock_irqsave(&ioapic_lock, flags);
191 __ioapic_write_entry(apic, pin, e);
192 spin_unlock_irqrestore(&ioapic_lock, flags);
196 * When we mask an IO APIC routing entry, we need to write the low
197 * word first, in order to set the mask bit before we change the
200 static void ioapic_mask_entry(int apic, int pin)
203 union entry_union eu = { .entry.mask = 1 };
205 spin_lock_irqsave(&ioapic_lock, flags);
206 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
207 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
208 spin_unlock_irqrestore(&ioapic_lock, flags);
212 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
213 * shared ISA-space IRQs, so we have to support them. We are super
214 * fast in the common case, and fast for shared ISA-space IRQs.
216 static void add_pin_to_irq(unsigned int irq, int apic, int pin)
218 struct irq_pin_list *entry = irq_2_pin + irq;
221 entry = irq_2_pin + entry->next;
223 if (entry->pin != -1) {
224 entry->next = first_free_entry;
225 entry = irq_2_pin + entry->next;
226 if (++first_free_entry >= pin_map_size)
227 panic("io_apic.c: whoops");
234 * Reroute an IRQ to a different pin.
236 static void __init replace_pin_at_irq(unsigned int irq,
237 int oldapic, int oldpin,
238 int newapic, int newpin)
240 struct irq_pin_list *entry = irq_2_pin + irq;
243 if (entry->apic == oldapic && entry->pin == oldpin) {
244 entry->apic = newapic;
249 entry = irq_2_pin + entry->next;
253 static void __modify_IO_APIC_irq(unsigned int irq, unsigned long enable, unsigned long disable)
255 struct irq_pin_list *entry = irq_2_pin + irq;
256 unsigned int pin, reg;
262 reg = io_apic_read(entry->apic, 0x10 + pin*2);
265 io_apic_modify(entry->apic, 0x10 + pin*2, reg);
268 entry = irq_2_pin + entry->next;
273 static void __mask_IO_APIC_irq(unsigned int irq)
275 __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED, 0);
279 static void __unmask_IO_APIC_irq(unsigned int irq)
281 __modify_IO_APIC_irq(irq, 0, IO_APIC_REDIR_MASKED);
284 /* mask = 1, trigger = 0 */
285 static void __mask_and_edge_IO_APIC_irq(unsigned int irq)
287 __modify_IO_APIC_irq(irq, IO_APIC_REDIR_MASKED,
288 IO_APIC_REDIR_LEVEL_TRIGGER);
291 /* mask = 0, trigger = 1 */
292 static void __unmask_and_level_IO_APIC_irq(unsigned int irq)
294 __modify_IO_APIC_irq(irq, IO_APIC_REDIR_LEVEL_TRIGGER,
295 IO_APIC_REDIR_MASKED);
298 static void mask_IO_APIC_irq(unsigned int irq)
302 spin_lock_irqsave(&ioapic_lock, flags);
303 __mask_IO_APIC_irq(irq);
304 spin_unlock_irqrestore(&ioapic_lock, flags);
307 static void unmask_IO_APIC_irq(unsigned int irq)
311 spin_lock_irqsave(&ioapic_lock, flags);
312 __unmask_IO_APIC_irq(irq);
313 spin_unlock_irqrestore(&ioapic_lock, flags);
316 static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
318 struct IO_APIC_route_entry entry;
320 /* Check delivery_mode to be sure we're not clearing an SMI pin */
321 entry = ioapic_read_entry(apic, pin);
322 if (entry.delivery_mode == dest_SMI)
326 * Disable it in the IO-APIC irq-routing table:
328 ioapic_mask_entry(apic, pin);
331 static void clear_IO_APIC(void)
335 for (apic = 0; apic < nr_ioapics; apic++)
336 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
337 clear_IO_APIC_pin(apic, pin);
341 static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t cpumask)
345 struct irq_pin_list *entry = irq_2_pin + irq;
346 unsigned int apicid_value;
348 struct irq_desc *desc;
350 cpus_and(tmp, cpumask, cpu_online_map);
354 cpus_and(cpumask, tmp, CPU_MASK_ALL);
356 apicid_value = cpu_mask_to_apicid(cpumask);
357 /* Prepare to do the io_apic_write */
358 apicid_value = apicid_value << 24;
359 spin_lock_irqsave(&ioapic_lock, flags);
364 io_apic_write(entry->apic, 0x10 + 1 + pin*2, apicid_value);
367 entry = irq_2_pin + entry->next;
369 desc = irq_to_desc(irq);
370 desc->affinity = cpumask;
371 spin_unlock_irqrestore(&ioapic_lock, flags);
374 #endif /* CONFIG_SMP */
377 void send_IPI_self(int vector)
384 apic_wait_icr_idle();
385 cfg = APIC_DM_FIXED | APIC_DEST_SELF | vector | APIC_DEST_LOGICAL;
387 * Send the IPI. The write to APIC_ICR fires this off.
389 apic_write(APIC_ICR, cfg);
391 #endif /* !CONFIG_SMP */
395 * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
396 * specific CPU-side IRQs.
400 static int pirq_entries [MAX_PIRQS];
401 static int pirqs_enabled;
402 int skip_ioapic_setup;
404 static int __init ioapic_pirq_setup(char *str)
407 int ints[MAX_PIRQS+1];
409 get_options(str, ARRAY_SIZE(ints), ints);
411 for (i = 0; i < MAX_PIRQS; i++)
412 pirq_entries[i] = -1;
415 apic_printk(APIC_VERBOSE, KERN_INFO
416 "PIRQ redirection, working around broken MP-BIOS.\n");
418 if (ints[0] < MAX_PIRQS)
421 for (i = 0; i < max; i++) {
422 apic_printk(APIC_VERBOSE, KERN_DEBUG
423 "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
425 * PIRQs are mapped upside down, usually.
427 pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
432 __setup("pirq=", ioapic_pirq_setup);
435 * Find the IRQ entry number of a certain pin.
437 static int find_irq_entry(int apic, int pin, int type)
441 for (i = 0; i < mp_irq_entries; i++)
442 if (mp_irqs[i].mp_irqtype == type &&
443 (mp_irqs[i].mp_dstapic == mp_ioapics[apic].mp_apicid ||
444 mp_irqs[i].mp_dstapic == MP_APIC_ALL) &&
445 mp_irqs[i].mp_dstirq == pin)
452 * Find the pin to which IRQ[irq] (ISA) is connected
454 static int __init find_isa_irq_pin(int irq, int type)
458 for (i = 0; i < mp_irq_entries; i++) {
459 int lbus = mp_irqs[i].mp_srcbus;
461 if (test_bit(lbus, mp_bus_not_pci) &&
462 (mp_irqs[i].mp_irqtype == type) &&
463 (mp_irqs[i].mp_srcbusirq == irq))
465 return mp_irqs[i].mp_dstirq;
470 static int __init find_isa_irq_apic(int irq, int type)
474 for (i = 0; i < mp_irq_entries; i++) {
475 int lbus = mp_irqs[i].mp_srcbus;
477 if (test_bit(lbus, mp_bus_not_pci) &&
478 (mp_irqs[i].mp_irqtype == type) &&
479 (mp_irqs[i].mp_srcbusirq == irq))
482 if (i < mp_irq_entries) {
484 for (apic = 0; apic < nr_ioapics; apic++) {
485 if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic)
494 * Find a specific PCI IRQ entry.
495 * Not an __init, possibly needed by modules
497 static int pin_2_irq(int idx, int apic, int pin);
499 int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
501 int apic, i, best_guess = -1;
503 apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, "
504 "slot:%d, pin:%d.\n", bus, slot, pin);
505 if (test_bit(bus, mp_bus_not_pci)) {
506 printk(KERN_WARNING "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
509 for (i = 0; i < mp_irq_entries; i++) {
510 int lbus = mp_irqs[i].mp_srcbus;
512 for (apic = 0; apic < nr_ioapics; apic++)
513 if (mp_ioapics[apic].mp_apicid == mp_irqs[i].mp_dstapic ||
514 mp_irqs[i].mp_dstapic == MP_APIC_ALL)
517 if (!test_bit(lbus, mp_bus_not_pci) &&
518 !mp_irqs[i].mp_irqtype &&
520 (slot == ((mp_irqs[i].mp_srcbusirq >> 2) & 0x1f))) {
521 int irq = pin_2_irq(i, apic, mp_irqs[i].mp_dstirq);
523 if (!(apic || IO_APIC_IRQ(irq)))
526 if (pin == (mp_irqs[i].mp_srcbusirq & 3))
529 * Use the first all-but-pin matching entry as a
530 * best-guess fuzzy result for broken mptables.
538 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
541 * This function currently is only a helper for the i386 smp boot process where
542 * we need to reprogram the ioredtbls to cater for the cpus which have come online
543 * so mask in all cases should simply be TARGET_CPUS
546 void __init setup_ioapic_dest(void)
548 int pin, ioapic, irq, irq_entry;
550 if (skip_ioapic_setup == 1)
553 for (ioapic = 0; ioapic < nr_ioapics; ioapic++) {
554 for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
555 irq_entry = find_irq_entry(ioapic, pin, mp_INT);
558 irq = pin_2_irq(irq_entry, ioapic, pin);
559 set_ioapic_affinity_irq(irq, TARGET_CPUS);
566 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
568 * EISA Edge/Level control register, ELCR
570 static int EISA_ELCR(unsigned int irq)
573 unsigned int port = 0x4d0 + (irq >> 3);
574 return (inb(port) >> (irq & 7)) & 1;
576 apic_printk(APIC_VERBOSE, KERN_INFO
577 "Broken MPtable reports ISA irq %d\n", irq);
582 /* ISA interrupts are always polarity zero edge triggered,
583 * when listed as conforming in the MP table. */
585 #define default_ISA_trigger(idx) (0)
586 #define default_ISA_polarity(idx) (0)
588 /* EISA interrupts are always polarity zero and can be edge or level
589 * trigger depending on the ELCR value. If an interrupt is listed as
590 * EISA conforming in the MP table, that means its trigger type must
591 * be read in from the ELCR */
593 #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].mp_srcbusirq))
594 #define default_EISA_polarity(idx) default_ISA_polarity(idx)
596 /* PCI interrupts are always polarity one level triggered,
597 * when listed as conforming in the MP table. */
599 #define default_PCI_trigger(idx) (1)
600 #define default_PCI_polarity(idx) (1)
602 /* MCA interrupts are always polarity zero level triggered,
603 * when listed as conforming in the MP table. */
605 #define default_MCA_trigger(idx) (1)
606 #define default_MCA_polarity(idx) default_ISA_polarity(idx)
608 static int MPBIOS_polarity(int idx)
610 int bus = mp_irqs[idx].mp_srcbus;
614 * Determine IRQ line polarity (high active or low active):
616 switch (mp_irqs[idx].mp_irqflag & 3) {
617 case 0: /* conforms, ie. bus-type dependent polarity */
619 polarity = test_bit(bus, mp_bus_not_pci)?
620 default_ISA_polarity(idx):
621 default_PCI_polarity(idx);
624 case 1: /* high active */
629 case 2: /* reserved */
631 printk(KERN_WARNING "broken BIOS!!\n");
635 case 3: /* low active */
640 default: /* invalid */
642 printk(KERN_WARNING "broken BIOS!!\n");
650 static int MPBIOS_trigger(int idx)
652 int bus = mp_irqs[idx].mp_srcbus;
656 * Determine IRQ trigger mode (edge or level sensitive):
658 switch ((mp_irqs[idx].mp_irqflag>>2) & 3) {
659 case 0: /* conforms, ie. bus-type dependent */
661 trigger = test_bit(bus, mp_bus_not_pci)?
662 default_ISA_trigger(idx):
663 default_PCI_trigger(idx);
664 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
665 switch (mp_bus_id_to_type[bus]) {
666 case MP_BUS_ISA: /* ISA pin */
668 /* set before the switch */
671 case MP_BUS_EISA: /* EISA pin */
673 trigger = default_EISA_trigger(idx);
676 case MP_BUS_PCI: /* PCI pin */
678 /* set before the switch */
681 case MP_BUS_MCA: /* MCA pin */
683 trigger = default_MCA_trigger(idx);
688 printk(KERN_WARNING "broken BIOS!!\n");
701 case 2: /* reserved */
703 printk(KERN_WARNING "broken BIOS!!\n");
712 default: /* invalid */
714 printk(KERN_WARNING "broken BIOS!!\n");
722 static inline int irq_polarity(int idx)
724 return MPBIOS_polarity(idx);
727 static inline int irq_trigger(int idx)
729 return MPBIOS_trigger(idx);
732 static int pin_2_irq(int idx, int apic, int pin)
735 int bus = mp_irqs[idx].mp_srcbus;
738 * Debugging check, we are in big trouble if this message pops up!
740 if (mp_irqs[idx].mp_dstirq != pin)
741 printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
743 if (test_bit(bus, mp_bus_not_pci))
744 irq = mp_irqs[idx].mp_srcbusirq;
747 * PCI IRQs are mapped in order
751 irq += nr_ioapic_registers[i++];
755 * For MPS mode, so far only needed by ES7000 platform
757 if (ioapic_renumber_irq)
758 irq = ioapic_renumber_irq(apic, irq);
762 * PCI IRQ command line redirection. Yes, limits are hardcoded.
764 if ((pin >= 16) && (pin <= 23)) {
765 if (pirq_entries[pin-16] != -1) {
766 if (!pirq_entries[pin-16]) {
767 apic_printk(APIC_VERBOSE, KERN_DEBUG
768 "disabling PIRQ%d\n", pin-16);
770 irq = pirq_entries[pin-16];
771 apic_printk(APIC_VERBOSE, KERN_DEBUG
772 "using PIRQ%d -> IRQ %d\n",
780 static inline int IO_APIC_irq_trigger(int irq)
784 for (apic = 0; apic < nr_ioapics; apic++) {
785 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
786 idx = find_irq_entry(apic, pin, mp_INT);
787 if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
788 return irq_trigger(idx);
792 * nonexistent IRQs are edge default
797 /* irq_vectors is indexed by the sum of all RTEs in all I/O APICs. */
798 static u8 irq_vector_init_first __initdata = FIRST_DEVICE_VECTOR;
799 static u8 *irq_vector;
801 static void __init irq_vector_init_work(void *data)
803 struct dyn_array *da = data;
809 irq_vec[0] = irq_vector_init_first;
812 DEFINE_DYN_ARRAY(irq_vector, sizeof(u8), nr_irqs, PAGE_SIZE, irq_vector_init_work);
814 static int __assign_irq_vector(int irq)
816 static int current_vector = FIRST_DEVICE_VECTOR, current_offset;
819 BUG_ON((unsigned)irq >= nr_irqs);
821 if (irq_vector[irq] > 0)
822 return irq_vector[irq];
824 vector = current_vector;
825 offset = current_offset;
828 if (vector >= first_system_vector) {
829 offset = (offset + 1) % 8;
830 vector = FIRST_DEVICE_VECTOR + offset;
832 if (vector == current_vector)
834 if (test_and_set_bit(vector, used_vectors))
837 current_vector = vector;
838 current_offset = offset;
839 irq_vector[irq] = vector;
844 static int assign_irq_vector(int irq)
849 spin_lock_irqsave(&vector_lock, flags);
850 vector = __assign_irq_vector(irq);
851 spin_unlock_irqrestore(&vector_lock, flags);
856 static struct irq_chip ioapic_chip;
858 #define IOAPIC_AUTO -1
859 #define IOAPIC_EDGE 0
860 #define IOAPIC_LEVEL 1
862 static void ioapic_register_intr(int irq, int vector, unsigned long trigger)
864 struct irq_desc *desc;
866 desc = irq_to_desc(irq);
867 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
868 trigger == IOAPIC_LEVEL) {
869 desc->status |= IRQ_LEVEL;
870 set_irq_chip_and_handler_name(irq, &ioapic_chip,
871 handle_fasteoi_irq, "fasteoi");
873 desc->status &= ~IRQ_LEVEL;
874 set_irq_chip_and_handler_name(irq, &ioapic_chip,
875 handle_edge_irq, "edge");
877 set_intr_gate(vector, interrupt[irq]);
880 static void __init setup_IO_APIC_irqs(void)
882 struct IO_APIC_route_entry entry;
883 int apic, pin, idx, irq, first_notcon = 1, vector;
885 apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
887 for (apic = 0; apic < nr_ioapics; apic++) {
888 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
891 * add it to the IO-APIC irq-routing table:
893 memset(&entry, 0, sizeof(entry));
895 entry.delivery_mode = INT_DELIVERY_MODE;
896 entry.dest_mode = INT_DEST_MODE;
897 entry.mask = 0; /* enable IRQ */
898 entry.dest.logical.logical_dest =
899 cpu_mask_to_apicid(TARGET_CPUS);
901 idx = find_irq_entry(apic, pin, mp_INT);
904 apic_printk(APIC_VERBOSE, KERN_DEBUG
905 " IO-APIC (apicid-pin) %d-%d",
906 mp_ioapics[apic].mp_apicid,
910 apic_printk(APIC_VERBOSE, ", %d-%d",
911 mp_ioapics[apic].mp_apicid, pin);
916 apic_printk(APIC_VERBOSE, " not connected.\n");
920 entry.trigger = irq_trigger(idx);
921 entry.polarity = irq_polarity(idx);
923 if (irq_trigger(idx)) {
928 irq = pin_2_irq(idx, apic, pin);
930 * skip adding the timer int on secondary nodes, which causes
931 * a small but painful rift in the time-space continuum
933 if (multi_timer_check(apic, irq))
936 add_pin_to_irq(irq, apic, pin);
938 if (!apic && !IO_APIC_IRQ(irq))
941 if (IO_APIC_IRQ(irq)) {
942 vector = assign_irq_vector(irq);
943 entry.vector = vector;
944 ioapic_register_intr(irq, vector, IOAPIC_AUTO);
946 if (!apic && (irq < 16))
947 disable_8259A_irq(irq);
949 ioapic_write_entry(apic, pin, entry);
954 apic_printk(APIC_VERBOSE, " not connected.\n");
958 * Set up the timer pin, possibly with the 8259A-master behind.
960 static void __init setup_timer_IRQ0_pin(unsigned int apic, unsigned int pin,
963 struct IO_APIC_route_entry entry;
965 memset(&entry, 0, sizeof(entry));
968 * We use logical delivery to get the timer IRQ
971 entry.dest_mode = INT_DEST_MODE;
972 entry.mask = 1; /* mask IRQ now */
973 entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
974 entry.delivery_mode = INT_DELIVERY_MODE;
977 entry.vector = vector;
980 * The timer IRQ doesn't have to know that behind the
981 * scene we may have a 8259A-master in AEOI mode ...
983 ioapic_register_intr(0, vector, IOAPIC_EDGE);
986 * Add it to the IO-APIC irq-routing table:
988 ioapic_write_entry(apic, pin, entry);
992 __apicdebuginit(void) print_IO_APIC(void)
995 union IO_APIC_reg_00 reg_00;
996 union IO_APIC_reg_01 reg_01;
997 union IO_APIC_reg_02 reg_02;
998 union IO_APIC_reg_03 reg_03;
1001 if (apic_verbosity == APIC_QUIET)
1004 printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
1005 for (i = 0; i < nr_ioapics; i++)
1006 printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
1007 mp_ioapics[i].mp_apicid, nr_ioapic_registers[i]);
1010 * We are a bit conservative about what we expect. We have to
1011 * know about every hardware change ASAP.
1013 printk(KERN_INFO "testing the IO APIC.......................\n");
1015 for (apic = 0; apic < nr_ioapics; apic++) {
1017 spin_lock_irqsave(&ioapic_lock, flags);
1018 reg_00.raw = io_apic_read(apic, 0);
1019 reg_01.raw = io_apic_read(apic, 1);
1020 if (reg_01.bits.version >= 0x10)
1021 reg_02.raw = io_apic_read(apic, 2);
1022 if (reg_01.bits.version >= 0x20)
1023 reg_03.raw = io_apic_read(apic, 3);
1024 spin_unlock_irqrestore(&ioapic_lock, flags);
1026 printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mp_apicid);
1027 printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
1028 printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
1029 printk(KERN_DEBUG "....... : Delivery Type: %X\n", reg_00.bits.delivery_type);
1030 printk(KERN_DEBUG "....... : LTS : %X\n", reg_00.bits.LTS);
1032 printk(KERN_DEBUG ".... register #01: %08X\n", reg_01.raw);
1033 printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
1035 printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
1036 printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
1039 * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
1040 * but the value of reg_02 is read as the previous read register
1041 * value, so ignore it if reg_02 == reg_01.
1043 if (reg_01.bits.version >= 0x10 && reg_02.raw != reg_01.raw) {
1044 printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
1045 printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
1049 * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
1050 * or reg_03, but the value of reg_0[23] is read as the previous read
1051 * register value, so ignore it if reg_03 == reg_0[12].
1053 if (reg_01.bits.version >= 0x20 && reg_03.raw != reg_02.raw &&
1054 reg_03.raw != reg_01.raw) {
1055 printk(KERN_DEBUG ".... register #03: %08X\n", reg_03.raw);
1056 printk(KERN_DEBUG "....... : Boot DT : %X\n", reg_03.bits.boot_DT);
1059 printk(KERN_DEBUG ".... IRQ redirection table:\n");
1061 printk(KERN_DEBUG " NR Log Phy Mask Trig IRR Pol"
1062 " Stat Dest Deli Vect: \n");
1064 for (i = 0; i <= reg_01.bits.entries; i++) {
1065 struct IO_APIC_route_entry entry;
1067 entry = ioapic_read_entry(apic, i);
1069 printk(KERN_DEBUG " %02x %03X %02X ",
1071 entry.dest.logical.logical_dest,
1072 entry.dest.physical.physical_dest
1075 printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
1080 entry.delivery_status,
1082 entry.delivery_mode,
1087 printk(KERN_DEBUG "IRQ to pin mappings:\n");
1088 for (i = 0; i < nr_irqs; i++) {
1089 struct irq_pin_list *entry = irq_2_pin + i;
1092 printk(KERN_DEBUG "IRQ%d ", i);
1094 printk("-> %d:%d", entry->apic, entry->pin);
1097 entry = irq_2_pin + entry->next;
1102 printk(KERN_INFO ".................................... done.\n");
1107 __apicdebuginit(void) print_APIC_bitfield(int base)
1112 if (apic_verbosity == APIC_QUIET)
1115 printk(KERN_DEBUG "0123456789abcdef0123456789abcdef\n" KERN_DEBUG);
1116 for (i = 0; i < 8; i++) {
1117 v = apic_read(base + i*0x10);
1118 for (j = 0; j < 32; j++) {
1128 __apicdebuginit(void) print_local_APIC(void *dummy)
1130 unsigned int v, ver, maxlvt;
1133 if (apic_verbosity == APIC_QUIET)
1136 printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
1137 smp_processor_id(), hard_smp_processor_id());
1138 v = apic_read(APIC_ID);
1139 printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v,
1141 v = apic_read(APIC_LVR);
1142 printk(KERN_INFO "... APIC VERSION: %08x\n", v);
1143 ver = GET_APIC_VERSION(v);
1144 maxlvt = lapic_get_maxlvt();
1146 v = apic_read(APIC_TASKPRI);
1147 printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
1149 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1150 v = apic_read(APIC_ARBPRI);
1151 printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
1152 v & APIC_ARBPRI_MASK);
1153 v = apic_read(APIC_PROCPRI);
1154 printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
1157 v = apic_read(APIC_EOI);
1158 printk(KERN_DEBUG "... APIC EOI: %08x\n", v);
1159 v = apic_read(APIC_RRR);
1160 printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
1161 v = apic_read(APIC_LDR);
1162 printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
1163 v = apic_read(APIC_DFR);
1164 printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
1165 v = apic_read(APIC_SPIV);
1166 printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
1168 printk(KERN_DEBUG "... APIC ISR field:\n");
1169 print_APIC_bitfield(APIC_ISR);
1170 printk(KERN_DEBUG "... APIC TMR field:\n");
1171 print_APIC_bitfield(APIC_TMR);
1172 printk(KERN_DEBUG "... APIC IRR field:\n");
1173 print_APIC_bitfield(APIC_IRR);
1175 if (APIC_INTEGRATED(ver)) { /* !82489DX */
1176 if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
1177 apic_write(APIC_ESR, 0);
1178 v = apic_read(APIC_ESR);
1179 printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
1182 icr = apic_icr_read();
1183 printk(KERN_DEBUG "... APIC ICR: %08x\n", icr);
1184 printk(KERN_DEBUG "... APIC ICR2: %08x\n", icr >> 32);
1186 v = apic_read(APIC_LVTT);
1187 printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
1189 if (maxlvt > 3) { /* PC is LVT#4. */
1190 v = apic_read(APIC_LVTPC);
1191 printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
1193 v = apic_read(APIC_LVT0);
1194 printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
1195 v = apic_read(APIC_LVT1);
1196 printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
1198 if (maxlvt > 2) { /* ERR is LVT#3. */
1199 v = apic_read(APIC_LVTERR);
1200 printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
1203 v = apic_read(APIC_TMICT);
1204 printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
1205 v = apic_read(APIC_TMCCT);
1206 printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
1207 v = apic_read(APIC_TDCR);
1208 printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
1212 __apicdebuginit(void) print_all_local_APICs(void)
1214 on_each_cpu(print_local_APIC, NULL, 1);
1217 __apicdebuginit(void) print_PIC(void)
1220 unsigned long flags;
1222 if (apic_verbosity == APIC_QUIET)
1225 printk(KERN_DEBUG "\nprinting PIC contents\n");
1227 spin_lock_irqsave(&i8259A_lock, flags);
1229 v = inb(0xa1) << 8 | inb(0x21);
1230 printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
1232 v = inb(0xa0) << 8 | inb(0x20);
1233 printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
1237 v = inb(0xa0) << 8 | inb(0x20);
1241 spin_unlock_irqrestore(&i8259A_lock, flags);
1243 printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
1245 v = inb(0x4d1) << 8 | inb(0x4d0);
1246 printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
1249 __apicdebuginit(int) print_all_ICs(void)
1252 print_all_local_APICs();
1258 fs_initcall(print_all_ICs);
1261 static void __init enable_IO_APIC(void)
1263 union IO_APIC_reg_01 reg_01;
1264 int i8259_apic, i8259_pin;
1266 unsigned long flags;
1268 for (i = 0; i < pin_map_size; i++) {
1269 irq_2_pin[i].pin = -1;
1270 irq_2_pin[i].next = 0;
1273 for (i = 0; i < MAX_PIRQS; i++)
1274 pirq_entries[i] = -1;
1277 * The number of IO-APIC IRQ registers (== #pins):
1279 for (apic = 0; apic < nr_ioapics; apic++) {
1280 spin_lock_irqsave(&ioapic_lock, flags);
1281 reg_01.raw = io_apic_read(apic, 1);
1282 spin_unlock_irqrestore(&ioapic_lock, flags);
1283 nr_ioapic_registers[apic] = reg_01.bits.entries+1;
1285 for (apic = 0; apic < nr_ioapics; apic++) {
1287 /* See if any of the pins is in ExtINT mode */
1288 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
1289 struct IO_APIC_route_entry entry;
1290 entry = ioapic_read_entry(apic, pin);
1293 /* If the interrupt line is enabled and in ExtInt mode
1294 * I have found the pin where the i8259 is connected.
1296 if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
1297 ioapic_i8259.apic = apic;
1298 ioapic_i8259.pin = pin;
1304 /* Look to see what if the MP table has reported the ExtINT */
1305 /* If we could not find the appropriate pin by looking at the ioapic
1306 * the i8259 probably is not connected the ioapic but give the
1307 * mptable a chance anyway.
1309 i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
1310 i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
1311 /* Trust the MP table if nothing is setup in the hardware */
1312 if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
1313 printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
1314 ioapic_i8259.pin = i8259_pin;
1315 ioapic_i8259.apic = i8259_apic;
1317 /* Complain if the MP table and the hardware disagree */
1318 if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
1319 (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
1321 printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
1325 * Do not trust the IO-APIC being empty at bootup
1331 * Not an __init, needed by the reboot code
1333 void disable_IO_APIC(void)
1336 * Clear the IO-APIC before rebooting:
1341 * If the i8259 is routed through an IOAPIC
1342 * Put that IOAPIC in virtual wire mode
1343 * so legacy interrupts can be delivered.
1345 if (ioapic_i8259.pin != -1) {
1346 struct IO_APIC_route_entry entry;
1348 memset(&entry, 0, sizeof(entry));
1349 entry.mask = 0; /* Enabled */
1350 entry.trigger = 0; /* Edge */
1352 entry.polarity = 0; /* High */
1353 entry.delivery_status = 0;
1354 entry.dest_mode = 0; /* Physical */
1355 entry.delivery_mode = dest_ExtINT; /* ExtInt */
1357 entry.dest.physical.physical_dest = read_apic_id();
1360 * Add it to the IO-APIC irq-routing table:
1362 ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
1364 disconnect_bsp_APIC(ioapic_i8259.pin != -1);
1368 * function to set the IO-APIC physical IDs based on the
1369 * values stored in the MPC table.
1371 * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
1374 static void __init setup_ioapic_ids_from_mpc(void)
1376 union IO_APIC_reg_00 reg_00;
1377 physid_mask_t phys_id_present_map;
1380 unsigned char old_id;
1381 unsigned long flags;
1383 if (x86_quirks->setup_ioapic_ids && x86_quirks->setup_ioapic_ids())
1387 * Don't check I/O APIC IDs for xAPIC systems. They have
1388 * no meaning without the serial APIC bus.
1390 if (!(boot_cpu_data.x86_vendor == X86_VENDOR_INTEL)
1391 || APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
1394 * This is broken; anything with a real cpu count has to
1395 * circumvent this idiocy regardless.
1397 phys_id_present_map = ioapic_phys_id_map(phys_cpu_present_map);
1400 * Set the IOAPIC ID to the value stored in the MPC table.
1402 for (apic = 0; apic < nr_ioapics; apic++) {
1404 /* Read the register 0 value */
1405 spin_lock_irqsave(&ioapic_lock, flags);
1406 reg_00.raw = io_apic_read(apic, 0);
1407 spin_unlock_irqrestore(&ioapic_lock, flags);
1409 old_id = mp_ioapics[apic].mp_apicid;
1411 if (mp_ioapics[apic].mp_apicid >= get_physical_broadcast()) {
1412 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
1413 apic, mp_ioapics[apic].mp_apicid);
1414 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
1416 mp_ioapics[apic].mp_apicid = reg_00.bits.ID;
1420 * Sanity check, is the ID really free? Every APIC in a
1421 * system must have a unique ID or we get lots of nice
1422 * 'stuck on smp_invalidate_needed IPI wait' messages.
1424 if (check_apicid_used(phys_id_present_map,
1425 mp_ioapics[apic].mp_apicid)) {
1426 printk(KERN_ERR "BIOS bug, IO-APIC#%d ID %d is already used!...\n",
1427 apic, mp_ioapics[apic].mp_apicid);
1428 for (i = 0; i < get_physical_broadcast(); i++)
1429 if (!physid_isset(i, phys_id_present_map))
1431 if (i >= get_physical_broadcast())
1432 panic("Max APIC ID exceeded!\n");
1433 printk(KERN_ERR "... fixing up to %d. (tell your hw vendor)\n",
1435 physid_set(i, phys_id_present_map);
1436 mp_ioapics[apic].mp_apicid = i;
1439 tmp = apicid_to_cpu_present(mp_ioapics[apic].mp_apicid);
1440 apic_printk(APIC_VERBOSE, "Setting %d in the "
1441 "phys_id_present_map\n",
1442 mp_ioapics[apic].mp_apicid);
1443 physids_or(phys_id_present_map, phys_id_present_map, tmp);
1448 * We need to adjust the IRQ routing table
1449 * if the ID changed.
1451 if (old_id != mp_ioapics[apic].mp_apicid)
1452 for (i = 0; i < mp_irq_entries; i++)
1453 if (mp_irqs[i].mp_dstapic == old_id)
1454 mp_irqs[i].mp_dstapic
1455 = mp_ioapics[apic].mp_apicid;
1458 * Read the right value from the MPC table and
1459 * write it into the ID register.
1461 apic_printk(APIC_VERBOSE, KERN_INFO
1462 "...changing IO-APIC physical APIC ID to %d ...",
1463 mp_ioapics[apic].mp_apicid);
1465 reg_00.bits.ID = mp_ioapics[apic].mp_apicid;
1466 spin_lock_irqsave(&ioapic_lock, flags);
1467 io_apic_write(apic, 0, reg_00.raw);
1468 spin_unlock_irqrestore(&ioapic_lock, flags);
1473 spin_lock_irqsave(&ioapic_lock, flags);
1474 reg_00.raw = io_apic_read(apic, 0);
1475 spin_unlock_irqrestore(&ioapic_lock, flags);
1476 if (reg_00.bits.ID != mp_ioapics[apic].mp_apicid)
1477 printk("could not set ID!\n");
1479 apic_printk(APIC_VERBOSE, " ok.\n");
1483 int no_timer_check __initdata;
1485 static int __init notimercheck(char *s)
1490 __setup("no_timer_check", notimercheck);
1493 * There is a nasty bug in some older SMP boards, their mptable lies
1494 * about the timer IRQ. We do the following to work around the situation:
1496 * - timer IRQ defaults to IO-APIC IRQ
1497 * - if this function detects that timer IRQs are defunct, then we fall
1498 * back to ISA timer IRQs
1500 static int __init timer_irq_works(void)
1502 unsigned long t1 = jiffies;
1503 unsigned long flags;
1508 local_save_flags(flags);
1510 /* Let ten ticks pass... */
1511 mdelay((10 * 1000) / HZ);
1512 local_irq_restore(flags);
1515 * Expect a few ticks at least, to be sure some possible
1516 * glue logic does not lock up after one or two first
1517 * ticks in a non-ExtINT mode. Also the local APIC
1518 * might have cached one ExtINT interrupt. Finally, at
1519 * least one tick may be lost due to delays.
1521 if (time_after(jiffies, t1 + 4))
1528 * In the SMP+IOAPIC case it might happen that there are an unspecified
1529 * number of pending IRQ events unhandled. These cases are very rare,
1530 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
1531 * better to do it this way as thus we do not have to be aware of
1532 * 'pending' interrupts in the IRQ path, except at this point.
1535 * Edge triggered needs to resend any interrupt
1536 * that was delayed but this is now handled in the device
1543 * Starting up a edge-triggered IO-APIC interrupt is
1544 * nasty - we need to make sure that we get the edge.
1545 * If it is already asserted for some reason, we need
1546 * return 1 to indicate that is was pending.
1548 * This is not complete - we should be able to fake
1549 * an edge even if it isn't on the 8259A...
1551 * (We do this for level-triggered IRQs too - it cannot hurt.)
1553 static unsigned int startup_ioapic_irq(unsigned int irq)
1555 int was_pending = 0;
1556 unsigned long flags;
1558 spin_lock_irqsave(&ioapic_lock, flags);
1560 disable_8259A_irq(irq);
1561 if (i8259A_irq_pending(irq))
1564 __unmask_IO_APIC_irq(irq);
1565 spin_unlock_irqrestore(&ioapic_lock, flags);
1570 static void ack_ioapic_irq(unsigned int irq)
1572 move_native_irq(irq);
1576 static void ack_ioapic_quirk_irq(unsigned int irq)
1581 move_native_irq(irq);
1583 * It appears there is an erratum which affects at least version 0x11
1584 * of I/O APIC (that's the 82093AA and cores integrated into various
1585 * chipsets). Under certain conditions a level-triggered interrupt is
1586 * erroneously delivered as edge-triggered one but the respective IRR
1587 * bit gets set nevertheless. As a result the I/O unit expects an EOI
1588 * message but it will never arrive and further interrupts are blocked
1589 * from the source. The exact reason is so far unknown, but the
1590 * phenomenon was observed when two consecutive interrupt requests
1591 * from a given source get delivered to the same CPU and the source is
1592 * temporarily disabled in between.
1594 * A workaround is to simulate an EOI message manually. We achieve it
1595 * by setting the trigger mode to edge and then to level when the edge
1596 * trigger mode gets detected in the TMR of a local APIC for a
1597 * level-triggered interrupt. We mask the source for the time of the
1598 * operation to prevent an edge-triggered interrupt escaping meanwhile.
1599 * The idea is from Manfred Spraul. --macro
1601 i = irq_vector[irq];
1603 v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
1607 if (!(v & (1 << (i & 0x1f)))) {
1608 atomic_inc(&irq_mis_count);
1609 spin_lock(&ioapic_lock);
1610 __mask_and_edge_IO_APIC_irq(irq);
1611 __unmask_and_level_IO_APIC_irq(irq);
1612 spin_unlock(&ioapic_lock);
1616 static int ioapic_retrigger_irq(unsigned int irq)
1618 send_IPI_self(irq_vector[irq]);
1623 static struct irq_chip ioapic_chip __read_mostly = {
1625 .startup = startup_ioapic_irq,
1626 .mask = mask_IO_APIC_irq,
1627 .unmask = unmask_IO_APIC_irq,
1628 .ack = ack_ioapic_irq,
1629 .eoi = ack_ioapic_quirk_irq,
1631 .set_affinity = set_ioapic_affinity_irq,
1633 .retrigger = ioapic_retrigger_irq,
1637 static inline void init_IO_APIC_traps(void)
1640 struct irq_desc *desc;
1643 * NOTE! The local APIC isn't very good at handling
1644 * multiple interrupts at the same interrupt level.
1645 * As the interrupt level is determined by taking the
1646 * vector number and shifting that right by 4, we
1647 * want to spread these out a bit so that they don't
1648 * all fall in the same interrupt level.
1650 * Also, we've got to be careful not to trash gate
1651 * 0x80, because int 0x80 is hm, kind of importantish. ;)
1653 for (irq = 0; irq < nr_irqs ; irq++) {
1654 if (IO_APIC_IRQ(irq) && !irq_vector[irq]) {
1656 * Hmm.. We don't have an entry for this,
1657 * so default to an old-fashioned 8259
1658 * interrupt if we can..
1661 make_8259A_irq(irq);
1663 desc = irq_to_desc(irq);
1664 /* Strange. Oh, well.. */
1665 desc->chip = &no_irq_chip;
1672 * The local APIC irq-chip implementation:
1675 static void ack_lapic_irq(unsigned int irq)
1680 static void mask_lapic_irq(unsigned int irq)
1684 v = apic_read(APIC_LVT0);
1685 apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
1688 static void unmask_lapic_irq(unsigned int irq)
1692 v = apic_read(APIC_LVT0);
1693 apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
1696 static struct irq_chip lapic_chip __read_mostly = {
1697 .name = "local-APIC",
1698 .mask = mask_lapic_irq,
1699 .unmask = unmask_lapic_irq,
1700 .ack = ack_lapic_irq,
1703 static void lapic_register_intr(int irq, int vector)
1705 struct irq_desc *desc;
1707 desc = irq_to_desc(irq);
1708 desc->status &= ~IRQ_LEVEL;
1709 set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
1711 set_intr_gate(vector, interrupt[irq]);
1714 static void __init setup_nmi(void)
1717 * Dirty trick to enable the NMI watchdog ...
1718 * We put the 8259A master into AEOI mode and
1719 * unmask on all local APICs LVT0 as NMI.
1721 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
1722 * is from Maciej W. Rozycki - so we do not have to EOI from
1723 * the NMI handler or the timer interrupt.
1725 apic_printk(APIC_VERBOSE, KERN_INFO "activating NMI Watchdog ...");
1727 enable_NMI_through_LVT0();
1729 apic_printk(APIC_VERBOSE, " done.\n");
1733 * This looks a bit hackish but it's about the only one way of sending
1734 * a few INTA cycles to 8259As and any associated glue logic. ICR does
1735 * not support the ExtINT mode, unfortunately. We need to send these
1736 * cycles as some i82489DX-based boards have glue logic that keeps the
1737 * 8259A interrupt line asserted until INTA. --macro
1739 static inline void __init unlock_ExtINT_logic(void)
1742 struct IO_APIC_route_entry entry0, entry1;
1743 unsigned char save_control, save_freq_select;
1745 pin = find_isa_irq_pin(8, mp_INT);
1750 apic = find_isa_irq_apic(8, mp_INT);
1756 entry0 = ioapic_read_entry(apic, pin);
1757 clear_IO_APIC_pin(apic, pin);
1759 memset(&entry1, 0, sizeof(entry1));
1761 entry1.dest_mode = 0; /* physical delivery */
1762 entry1.mask = 0; /* unmask IRQ now */
1763 entry1.dest.physical.physical_dest = hard_smp_processor_id();
1764 entry1.delivery_mode = dest_ExtINT;
1765 entry1.polarity = entry0.polarity;
1769 ioapic_write_entry(apic, pin, entry1);
1771 save_control = CMOS_READ(RTC_CONTROL);
1772 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
1773 CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
1775 CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
1780 if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
1784 CMOS_WRITE(save_control, RTC_CONTROL);
1785 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
1786 clear_IO_APIC_pin(apic, pin);
1788 ioapic_write_entry(apic, pin, entry0);
1792 * This code may look a bit paranoid, but it's supposed to cooperate with
1793 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
1794 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
1795 * fanatically on his truly buggy board.
1797 static inline void __init check_timer(void)
1799 int apic1, pin1, apic2, pin2;
1803 unsigned long flags;
1805 local_irq_save(flags);
1807 ver = apic_read(APIC_LVR);
1808 ver = GET_APIC_VERSION(ver);
1811 * get/set the timer IRQ vector:
1813 disable_8259A_irq(0);
1814 vector = assign_irq_vector(0);
1815 set_intr_gate(vector, interrupt[0]);
1818 * As IRQ0 is to be enabled in the 8259A, the virtual
1819 * wire has to be disabled in the local APIC. Also
1820 * timer interrupts need to be acknowledged manually in
1821 * the 8259A for the i82489DX when using the NMI
1822 * watchdog as that APIC treats NMIs as level-triggered.
1823 * The AEOI mode will finish them in the 8259A
1826 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
1828 timer_ack = (nmi_watchdog == NMI_IO_APIC && !APIC_INTEGRATED(ver));
1830 pin1 = find_isa_irq_pin(0, mp_INT);
1831 apic1 = find_isa_irq_apic(0, mp_INT);
1832 pin2 = ioapic_i8259.pin;
1833 apic2 = ioapic_i8259.apic;
1835 apic_printk(APIC_QUIET, KERN_INFO "..TIMER: vector=0x%02X "
1836 "apic1=%d pin1=%d apic2=%d pin2=%d\n",
1837 vector, apic1, pin1, apic2, pin2);
1840 * Some BIOS writers are clueless and report the ExtINTA
1841 * I/O APIC input from the cascaded 8259A as the timer
1842 * interrupt input. So just in case, if only one pin
1843 * was found above, try it both directly and through the
1850 } else if (pin2 == -1) {
1857 * Ok, does IRQ0 through the IOAPIC work?
1860 add_pin_to_irq(0, apic1, pin1);
1861 setup_timer_IRQ0_pin(apic1, pin1, vector);
1863 unmask_IO_APIC_irq(0);
1864 if (timer_irq_works()) {
1865 if (nmi_watchdog == NMI_IO_APIC) {
1867 enable_8259A_irq(0);
1869 if (disable_timer_pin_1 > 0)
1870 clear_IO_APIC_pin(0, pin1);
1873 clear_IO_APIC_pin(apic1, pin1);
1875 apic_printk(APIC_QUIET, KERN_ERR "..MP-BIOS bug: "
1876 "8254 timer not connected to IO-APIC\n");
1878 apic_printk(APIC_QUIET, KERN_INFO "...trying to set up timer "
1879 "(IRQ0) through the 8259A ...\n");
1880 apic_printk(APIC_QUIET, KERN_INFO
1881 "..... (found apic %d pin %d) ...\n", apic2, pin2);
1883 * legacy devices should be connected to IO APIC #0
1885 replace_pin_at_irq(0, apic1, pin1, apic2, pin2);
1886 setup_timer_IRQ0_pin(apic2, pin2, vector);
1887 unmask_IO_APIC_irq(0);
1888 enable_8259A_irq(0);
1889 if (timer_irq_works()) {
1890 apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
1891 timer_through_8259 = 1;
1892 if (nmi_watchdog == NMI_IO_APIC) {
1893 disable_8259A_irq(0);
1895 enable_8259A_irq(0);
1900 * Cleanup, just in case ...
1902 disable_8259A_irq(0);
1903 clear_IO_APIC_pin(apic2, pin2);
1904 apic_printk(APIC_QUIET, KERN_INFO "....... failed.\n");
1907 if (nmi_watchdog == NMI_IO_APIC) {
1908 apic_printk(APIC_QUIET, KERN_WARNING "timer doesn't work "
1909 "through the IO-APIC - disabling NMI Watchdog!\n");
1910 nmi_watchdog = NMI_NONE;
1914 apic_printk(APIC_QUIET, KERN_INFO
1915 "...trying to set up timer as Virtual Wire IRQ...\n");
1917 lapic_register_intr(0, vector);
1918 apic_write(APIC_LVT0, APIC_DM_FIXED | vector); /* Fixed mode */
1919 enable_8259A_irq(0);
1921 if (timer_irq_works()) {
1922 apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
1925 disable_8259A_irq(0);
1926 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector);
1927 apic_printk(APIC_QUIET, KERN_INFO "..... failed.\n");
1929 apic_printk(APIC_QUIET, KERN_INFO
1930 "...trying to set up timer as ExtINT IRQ...\n");
1934 apic_write(APIC_LVT0, APIC_DM_EXTINT);
1936 unlock_ExtINT_logic();
1938 if (timer_irq_works()) {
1939 apic_printk(APIC_QUIET, KERN_INFO "..... works.\n");
1942 apic_printk(APIC_QUIET, KERN_INFO "..... failed :(.\n");
1943 panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
1944 "report. Then try booting with the 'noapic' option.\n");
1946 local_irq_restore(flags);
1950 * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
1951 * to devices. However there may be an I/O APIC pin available for
1952 * this interrupt regardless. The pin may be left unconnected, but
1953 * typically it will be reused as an ExtINT cascade interrupt for
1954 * the master 8259A. In the MPS case such a pin will normally be
1955 * reported as an ExtINT interrupt in the MP table. With ACPI
1956 * there is no provision for ExtINT interrupts, and in the absence
1957 * of an override it would be treated as an ordinary ISA I/O APIC
1958 * interrupt, that is edge-triggered and unmasked by default. We
1959 * used to do this, but it caused problems on some systems because
1960 * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
1961 * the same ExtINT cascade interrupt to drive the local APIC of the
1962 * bootstrap processor. Therefore we refrain from routing IRQ2 to
1963 * the I/O APIC in all cases now. No actual device should request
1964 * it anyway. --macro
1966 #define PIC_IRQS (1 << PIC_CASCADE_IR)
1968 void __init setup_IO_APIC(void)
1972 /* Reserve all the system vectors. */
1973 for (i = first_system_vector; i < NR_VECTORS; i++)
1974 set_bit(i, used_vectors);
1978 io_apic_irqs = ~PIC_IRQS;
1980 printk("ENABLING IO-APIC IRQs\n");
1983 * Set up IO-APIC IRQ routing.
1986 setup_ioapic_ids_from_mpc();
1988 setup_IO_APIC_irqs();
1989 init_IO_APIC_traps();
1994 * Called after all the initialization is done. If we didnt find any
1995 * APIC bugs then we can allow the modify fast path
1998 static int __init io_apic_bug_finalize(void)
2000 if (sis_apic_bug == -1)
2005 late_initcall(io_apic_bug_finalize);
2007 struct sysfs_ioapic_data {
2008 struct sys_device dev;
2009 struct IO_APIC_route_entry entry[0];
2011 static struct sysfs_ioapic_data *mp_ioapic_data[MAX_IO_APICS];
2013 static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
2015 struct IO_APIC_route_entry *entry;
2016 struct sysfs_ioapic_data *data;
2019 data = container_of(dev, struct sysfs_ioapic_data, dev);
2020 entry = data->entry;
2021 for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
2022 entry[i] = ioapic_read_entry(dev->id, i);
2027 static int ioapic_resume(struct sys_device *dev)
2029 struct IO_APIC_route_entry *entry;
2030 struct sysfs_ioapic_data *data;
2031 unsigned long flags;
2032 union IO_APIC_reg_00 reg_00;
2035 data = container_of(dev, struct sysfs_ioapic_data, dev);
2036 entry = data->entry;
2038 spin_lock_irqsave(&ioapic_lock, flags);
2039 reg_00.raw = io_apic_read(dev->id, 0);
2040 if (reg_00.bits.ID != mp_ioapics[dev->id].mp_apicid) {
2041 reg_00.bits.ID = mp_ioapics[dev->id].mp_apicid;
2042 io_apic_write(dev->id, 0, reg_00.raw);
2044 spin_unlock_irqrestore(&ioapic_lock, flags);
2045 for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
2046 ioapic_write_entry(dev->id, i, entry[i]);
2051 static struct sysdev_class ioapic_sysdev_class = {
2053 .suspend = ioapic_suspend,
2054 .resume = ioapic_resume,
2057 static int __init ioapic_init_sysfs(void)
2059 struct sys_device *dev;
2060 int i, size, error = 0;
2062 error = sysdev_class_register(&ioapic_sysdev_class);
2066 for (i = 0; i < nr_ioapics; i++) {
2067 size = sizeof(struct sys_device) + nr_ioapic_registers[i]
2068 * sizeof(struct IO_APIC_route_entry);
2069 mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
2070 if (!mp_ioapic_data[i]) {
2071 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
2074 dev = &mp_ioapic_data[i]->dev;
2076 dev->cls = &ioapic_sysdev_class;
2077 error = sysdev_register(dev);
2079 kfree(mp_ioapic_data[i]);
2080 mp_ioapic_data[i] = NULL;
2081 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
2089 device_initcall(ioapic_init_sysfs);
2092 * Dynamic irq allocate and deallocation
2094 int create_irq(void)
2096 /* Allocate an unused irq */
2097 int irq, new, vector = 0;
2098 unsigned long flags;
2101 spin_lock_irqsave(&vector_lock, flags);
2102 for (new = (nr_irqs - 1); new >= 0; new--) {
2103 if (platform_legacy_irq(new))
2105 if (irq_vector[new] != 0)
2107 vector = __assign_irq_vector(new);
2108 if (likely(vector > 0))
2112 spin_unlock_irqrestore(&vector_lock, flags);
2115 set_intr_gate(vector, interrupt[irq]);
2116 dynamic_irq_init(irq);
2121 void destroy_irq(unsigned int irq)
2123 unsigned long flags;
2125 dynamic_irq_cleanup(irq);
2127 spin_lock_irqsave(&vector_lock, flags);
2128 clear_bit(irq_vector[irq], used_vectors);
2129 irq_vector[irq] = 0;
2130 spin_unlock_irqrestore(&vector_lock, flags);
2134 * MSI message composition
2136 #ifdef CONFIG_PCI_MSI
2137 static int msi_compose_msg(struct pci_dev *pdev, unsigned int irq, struct msi_msg *msg)
2142 vector = assign_irq_vector(irq);
2144 dest = cpu_mask_to_apicid(TARGET_CPUS);
2146 msg->address_hi = MSI_ADDR_BASE_HI;
2149 ((INT_DEST_MODE == 0) ?
2150 MSI_ADDR_DEST_MODE_PHYSICAL:
2151 MSI_ADDR_DEST_MODE_LOGICAL) |
2152 ((INT_DELIVERY_MODE != dest_LowestPrio) ?
2153 MSI_ADDR_REDIRECTION_CPU:
2154 MSI_ADDR_REDIRECTION_LOWPRI) |
2155 MSI_ADDR_DEST_ID(dest);
2158 MSI_DATA_TRIGGER_EDGE |
2159 MSI_DATA_LEVEL_ASSERT |
2160 ((INT_DELIVERY_MODE != dest_LowestPrio) ?
2161 MSI_DATA_DELIVERY_FIXED:
2162 MSI_DATA_DELIVERY_LOWPRI) |
2163 MSI_DATA_VECTOR(vector);
2169 static void set_msi_irq_affinity(unsigned int irq, cpumask_t mask)
2175 struct irq_desc *desc;
2177 cpus_and(tmp, mask, cpu_online_map);
2178 if (cpus_empty(tmp))
2181 vector = assign_irq_vector(irq);
2185 dest = cpu_mask_to_apicid(mask);
2187 read_msi_msg(irq, &msg);
2189 msg.data &= ~MSI_DATA_VECTOR_MASK;
2190 msg.data |= MSI_DATA_VECTOR(vector);
2191 msg.address_lo &= ~MSI_ADDR_DEST_ID_MASK;
2192 msg.address_lo |= MSI_ADDR_DEST_ID(dest);
2194 write_msi_msg(irq, &msg);
2195 desc = irq_to_desc(irq);
2196 desc->affinity = mask;
2198 #endif /* CONFIG_SMP */
2201 * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
2202 * which implement the MSI or MSI-X Capability Structure.
2204 static struct irq_chip msi_chip = {
2206 .unmask = unmask_msi_irq,
2207 .mask = mask_msi_irq,
2208 .ack = ack_ioapic_irq,
2210 .set_affinity = set_msi_irq_affinity,
2212 .retrigger = ioapic_retrigger_irq,
2215 int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc)
2223 ret = msi_compose_msg(dev, irq, &msg);
2229 set_irq_msi(irq, desc);
2230 write_msi_msg(irq, &msg);
2232 set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq,
2238 void arch_teardown_msi_irq(unsigned int irq)
2243 #endif /* CONFIG_PCI_MSI */
2246 * Hypertransport interrupt support
2248 #ifdef CONFIG_HT_IRQ
2252 static void target_ht_irq(unsigned int irq, unsigned int dest)
2254 struct ht_irq_msg msg;
2255 fetch_ht_irq_msg(irq, &msg);
2257 msg.address_lo &= ~(HT_IRQ_LOW_DEST_ID_MASK);
2258 msg.address_hi &= ~(HT_IRQ_HIGH_DEST_ID_MASK);
2260 msg.address_lo |= HT_IRQ_LOW_DEST_ID(dest);
2261 msg.address_hi |= HT_IRQ_HIGH_DEST_ID(dest);
2263 write_ht_irq_msg(irq, &msg);
2266 static void set_ht_irq_affinity(unsigned int irq, cpumask_t mask)
2270 struct irq_desc *desc;
2272 cpus_and(tmp, mask, cpu_online_map);
2273 if (cpus_empty(tmp))
2276 cpus_and(mask, tmp, CPU_MASK_ALL);
2278 dest = cpu_mask_to_apicid(mask);
2280 target_ht_irq(irq, dest);
2281 desc = irq_to_desc(irq);
2282 desc->affinity = mask;
2286 static struct irq_chip ht_irq_chip = {
2288 .mask = mask_ht_irq,
2289 .unmask = unmask_ht_irq,
2290 .ack = ack_ioapic_irq,
2292 .set_affinity = set_ht_irq_affinity,
2294 .retrigger = ioapic_retrigger_irq,
2297 int arch_setup_ht_irq(unsigned int irq, struct pci_dev *dev)
2301 vector = assign_irq_vector(irq);
2303 struct ht_irq_msg msg;
2308 cpu_set(vector >> 8, tmp);
2309 dest = cpu_mask_to_apicid(tmp);
2311 msg.address_hi = HT_IRQ_HIGH_DEST_ID(dest);
2315 HT_IRQ_LOW_DEST_ID(dest) |
2316 HT_IRQ_LOW_VECTOR(vector) |
2317 ((INT_DEST_MODE == 0) ?
2318 HT_IRQ_LOW_DM_PHYSICAL :
2319 HT_IRQ_LOW_DM_LOGICAL) |
2320 HT_IRQ_LOW_RQEOI_EDGE |
2321 ((INT_DELIVERY_MODE != dest_LowestPrio) ?
2322 HT_IRQ_LOW_MT_FIXED :
2323 HT_IRQ_LOW_MT_ARBITRATED) |
2324 HT_IRQ_LOW_IRQ_MASKED;
2326 write_ht_irq_msg(irq, &msg);
2328 set_irq_chip_and_handler_name(irq, &ht_irq_chip,
2329 handle_edge_irq, "edge");
2333 #endif /* CONFIG_HT_IRQ */
2335 /* --------------------------------------------------------------------------
2336 ACPI-based IOAPIC Configuration
2337 -------------------------------------------------------------------------- */
2341 int __init io_apic_get_unique_id(int ioapic, int apic_id)
2343 union IO_APIC_reg_00 reg_00;
2344 static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
2346 unsigned long flags;
2350 * The P4 platform supports up to 256 APIC IDs on two separate APIC
2351 * buses (one for LAPICs, one for IOAPICs), where predecessors only
2352 * supports up to 16 on one shared APIC bus.
2354 * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
2355 * advantage of new APIC bus architecture.
2358 if (physids_empty(apic_id_map))
2359 apic_id_map = ioapic_phys_id_map(phys_cpu_present_map);
2361 spin_lock_irqsave(&ioapic_lock, flags);
2362 reg_00.raw = io_apic_read(ioapic, 0);
2363 spin_unlock_irqrestore(&ioapic_lock, flags);
2365 if (apic_id >= get_physical_broadcast()) {
2366 printk(KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
2367 "%d\n", ioapic, apic_id, reg_00.bits.ID);
2368 apic_id = reg_00.bits.ID;
2372 * Every APIC in a system must have a unique ID or we get lots of nice
2373 * 'stuck on smp_invalidate_needed IPI wait' messages.
2375 if (check_apicid_used(apic_id_map, apic_id)) {
2377 for (i = 0; i < get_physical_broadcast(); i++) {
2378 if (!check_apicid_used(apic_id_map, i))
2382 if (i == get_physical_broadcast())
2383 panic("Max apic_id exceeded!\n");
2385 printk(KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
2386 "trying %d\n", ioapic, apic_id, i);
2391 tmp = apicid_to_cpu_present(apic_id);
2392 physids_or(apic_id_map, apic_id_map, tmp);
2394 if (reg_00.bits.ID != apic_id) {
2395 reg_00.bits.ID = apic_id;
2397 spin_lock_irqsave(&ioapic_lock, flags);
2398 io_apic_write(ioapic, 0, reg_00.raw);
2399 reg_00.raw = io_apic_read(ioapic, 0);
2400 spin_unlock_irqrestore(&ioapic_lock, flags);
2403 if (reg_00.bits.ID != apic_id) {
2404 printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic);
2409 apic_printk(APIC_VERBOSE, KERN_INFO
2410 "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
2416 int __init io_apic_get_version(int ioapic)
2418 union IO_APIC_reg_01 reg_01;
2419 unsigned long flags;
2421 spin_lock_irqsave(&ioapic_lock, flags);
2422 reg_01.raw = io_apic_read(ioapic, 1);
2423 spin_unlock_irqrestore(&ioapic_lock, flags);
2425 return reg_01.bits.version;
2429 int __init io_apic_get_redir_entries(int ioapic)
2431 union IO_APIC_reg_01 reg_01;
2432 unsigned long flags;
2434 spin_lock_irqsave(&ioapic_lock, flags);
2435 reg_01.raw = io_apic_read(ioapic, 1);
2436 spin_unlock_irqrestore(&ioapic_lock, flags);
2438 return reg_01.bits.entries;
2442 int io_apic_set_pci_routing(int ioapic, int pin, int irq, int edge_level, int active_high_low)
2444 struct IO_APIC_route_entry entry;
2446 if (!IO_APIC_IRQ(irq)) {
2447 printk(KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
2453 * Generate a PCI IRQ routing entry and program the IOAPIC accordingly.
2454 * Note that we mask (disable) IRQs now -- these get enabled when the
2455 * corresponding device driver registers for this IRQ.
2458 memset(&entry, 0, sizeof(entry));
2460 entry.delivery_mode = INT_DELIVERY_MODE;
2461 entry.dest_mode = INT_DEST_MODE;
2462 entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
2463 entry.trigger = edge_level;
2464 entry.polarity = active_high_low;
2468 * IRQs < 16 are already in the irq_2_pin[] map
2471 add_pin_to_irq(irq, ioapic, pin);
2473 entry.vector = assign_irq_vector(irq);
2475 apic_printk(APIC_DEBUG, KERN_DEBUG "IOAPIC[%d]: Set PCI routing entry "
2476 "(%d-%d -> 0x%x -> IRQ %d Mode:%i Active:%i)\n", ioapic,
2477 mp_ioapics[ioapic].mp_apicid, pin, entry.vector, irq,
2478 edge_level, active_high_low);
2480 ioapic_register_intr(irq, entry.vector, edge_level);
2482 if (!ioapic && (irq < 16))
2483 disable_8259A_irq(irq);
2485 ioapic_write_entry(ioapic, pin, entry);
2490 int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity)
2494 if (skip_ioapic_setup)
2497 for (i = 0; i < mp_irq_entries; i++)
2498 if (mp_irqs[i].mp_irqtype == mp_INT &&
2499 mp_irqs[i].mp_srcbusirq == bus_irq)
2501 if (i >= mp_irq_entries)
2504 *trigger = irq_trigger(i);
2505 *polarity = irq_polarity(i);
2509 #endif /* CONFIG_ACPI */
2511 static int __init parse_disable_timer_pin_1(char *arg)
2513 disable_timer_pin_1 = 1;
2516 early_param("disable_timer_pin_1", parse_disable_timer_pin_1);
2518 static int __init parse_enable_timer_pin_1(char *arg)
2520 disable_timer_pin_1 = -1;
2523 early_param("enable_timer_pin_1", parse_enable_timer_pin_1);
2525 static int __init parse_noapic(char *arg)
2527 /* disable IO-APIC */
2528 disable_ioapic_setup();
2531 early_param("noapic", parse_noapic);
2533 void __init ioapic_init_mappings(void)
2535 unsigned long ioapic_phys, idx = FIX_IO_APIC_BASE_0;
2538 for (i = 0; i < nr_ioapics; i++) {
2539 if (smp_found_config) {
2540 ioapic_phys = mp_ioapics[i].mp_apicaddr;
2543 "WARNING: bogus zero IO-APIC "
2544 "address found in MPTABLE, "
2545 "disabling IO/APIC support!\n");
2546 smp_found_config = 0;
2547 skip_ioapic_setup = 1;
2548 goto fake_ioapic_page;
2552 ioapic_phys = (unsigned long)
2553 alloc_bootmem_pages(PAGE_SIZE);
2554 ioapic_phys = __pa(ioapic_phys);
2556 set_fixmap_nocache(idx, ioapic_phys);
2557 printk(KERN_DEBUG "mapped IOAPIC to %08lx (%08lx)\n",
2558 __fix_to_virt(idx), ioapic_phys);