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/smp_lock.h>
29 #include <linux/mc146818rtc.h>
30 #include <linux/acpi.h>
31 #include <linux/sysdev.h>
33 #include <acpi/acpi_bus.h>
39 #include <asm/proto.h>
40 #include <asm/mach_apic.h>
45 #define __apicdebuginit __init
47 int sis_apic_bug; /* not actually supported, dummy for compile */
49 static int no_timer_check;
51 static int disable_timer_pin_1 __initdata;
53 int timer_over_8254 __initdata = 0;
55 /* Where if anywhere is the i8259 connect in external int mode */
56 static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
58 static DEFINE_SPINLOCK(ioapic_lock);
59 static DEFINE_SPINLOCK(vector_lock);
62 * # of IRQ routing registers
64 int nr_ioapic_registers[MAX_IO_APICS];
67 * Rough estimation of how many shared IRQs there are, can
70 #define MAX_PLUS_SHARED_IRQS NR_IRQ_VECTORS
71 #define PIN_MAP_SIZE (MAX_PLUS_SHARED_IRQS + NR_IRQS)
74 * This is performance-critical, we want to do it O(1)
76 * the indexing order of this array favors 1:1 mappings
77 * between pins and IRQs.
80 static struct irq_pin_list {
81 short apic, pin, next;
82 } irq_2_pin[PIN_MAP_SIZE];
84 int vector_irq[NR_VECTORS] __read_mostly = { [0 ... NR_VECTORS - 1] = -1};
86 #define vector_to_irq(vector) \
87 (platform_legacy_irq(vector) ? vector : vector_irq[vector])
89 #define vector_to_irq(vector) (vector)
92 #define __DO_ACTION(R, ACTION, FINAL) \
96 struct irq_pin_list *entry = irq_2_pin + irq; \
98 BUG_ON(irq >= NR_IRQS); \
104 reg = io_apic_read(entry->apic, 0x10 + R + pin*2); \
106 io_apic_modify(entry->apic, reg); \
109 entry = irq_2_pin + entry->next; \
115 struct { u32 w1, w2; };
116 struct IO_APIC_route_entry entry;
119 static struct IO_APIC_route_entry ioapic_read_entry(int apic, int pin)
121 union entry_union eu;
123 spin_lock_irqsave(&ioapic_lock, flags);
124 eu.w1 = io_apic_read(apic, 0x10 + 2 * pin);
125 eu.w2 = io_apic_read(apic, 0x11 + 2 * pin);
126 spin_unlock_irqrestore(&ioapic_lock, flags);
130 static void ioapic_write_entry(int apic, int pin, struct IO_APIC_route_entry e)
133 union entry_union eu;
135 spin_lock_irqsave(&ioapic_lock, flags);
136 io_apic_write(apic, 0x10 + 2*pin, eu.w1);
137 io_apic_write(apic, 0x11 + 2*pin, eu.w2);
138 spin_unlock_irqrestore(&ioapic_lock, flags);
142 static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t mask)
148 cpus_and(tmp, mask, cpu_online_map);
152 cpus_and(mask, tmp, CPU_MASK_ALL);
154 dest = cpu_mask_to_apicid(mask);
157 * Only the high 8 bits are valid.
159 dest = SET_APIC_LOGICAL_ID(dest);
161 spin_lock_irqsave(&ioapic_lock, flags);
162 __DO_ACTION(1, = dest, )
163 set_irq_info(irq, mask);
164 spin_unlock_irqrestore(&ioapic_lock, flags);
168 static u8 gsi_2_irq[NR_IRQ_VECTORS] = { [0 ... NR_IRQ_VECTORS-1] = 0xFF };
171 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
172 * shared ISA-space IRQs, so we have to support them. We are super
173 * fast in the common case, and fast for shared ISA-space IRQs.
175 static void add_pin_to_irq(unsigned int irq, int apic, int pin)
177 static int first_free_entry = NR_IRQS;
178 struct irq_pin_list *entry = irq_2_pin + irq;
180 BUG_ON(irq >= NR_IRQS);
182 entry = irq_2_pin + entry->next;
184 if (entry->pin != -1) {
185 entry->next = first_free_entry;
186 entry = irq_2_pin + entry->next;
187 if (++first_free_entry >= PIN_MAP_SIZE)
188 panic("io_apic.c: ran out of irq_2_pin entries!");
195 #define DO_ACTION(name,R,ACTION, FINAL) \
197 static void name##_IO_APIC_irq (unsigned int irq) \
198 __DO_ACTION(R, ACTION, FINAL)
200 DO_ACTION( __mask, 0, |= 0x00010000, io_apic_sync(entry->apic) )
202 DO_ACTION( __unmask, 0, &= 0xfffeffff, )
205 static void mask_IO_APIC_irq (unsigned int irq)
209 spin_lock_irqsave(&ioapic_lock, flags);
210 __mask_IO_APIC_irq(irq);
211 spin_unlock_irqrestore(&ioapic_lock, flags);
214 static void unmask_IO_APIC_irq (unsigned int irq)
218 spin_lock_irqsave(&ioapic_lock, flags);
219 __unmask_IO_APIC_irq(irq);
220 spin_unlock_irqrestore(&ioapic_lock, flags);
223 static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
225 struct IO_APIC_route_entry entry;
227 /* Check delivery_mode to be sure we're not clearing an SMI pin */
228 entry = ioapic_read_entry(apic, pin);
229 if (entry.delivery_mode == dest_SMI)
232 * Disable it in the IO-APIC irq-routing table:
234 memset(&entry, 0, sizeof(entry));
236 ioapic_write_entry(apic, pin, entry);
239 static void clear_IO_APIC (void)
243 for (apic = 0; apic < nr_ioapics; apic++)
244 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
245 clear_IO_APIC_pin(apic, pin);
248 int skip_ioapic_setup;
251 /* dummy parsing: see setup.c */
253 static int __init disable_ioapic_setup(char *str)
255 skip_ioapic_setup = 1;
258 early_param("noapic", disable_ioapic_setup);
260 /* Actually the next is obsolete, but keep it for paranoid reasons -AK */
261 static int __init disable_timer_pin_setup(char *arg)
263 disable_timer_pin_1 = 1;
266 __setup("disable_timer_pin_1", disable_timer_pin_setup);
268 static int __init setup_disable_8254_timer(char *s)
270 timer_over_8254 = -1;
273 static int __init setup_enable_8254_timer(char *s)
279 __setup("disable_8254_timer", setup_disable_8254_timer);
280 __setup("enable_8254_timer", setup_enable_8254_timer);
284 * Find the IRQ entry number of a certain pin.
286 static int find_irq_entry(int apic, int pin, int type)
290 for (i = 0; i < mp_irq_entries; i++)
291 if (mp_irqs[i].mpc_irqtype == type &&
292 (mp_irqs[i].mpc_dstapic == mp_ioapics[apic].mpc_apicid ||
293 mp_irqs[i].mpc_dstapic == MP_APIC_ALL) &&
294 mp_irqs[i].mpc_dstirq == pin)
301 * Find the pin to which IRQ[irq] (ISA) is connected
303 static int __init find_isa_irq_pin(int irq, int type)
307 for (i = 0; i < mp_irq_entries; i++) {
308 int lbus = mp_irqs[i].mpc_srcbus;
310 if (test_bit(lbus, mp_bus_not_pci) &&
311 (mp_irqs[i].mpc_irqtype == type) &&
312 (mp_irqs[i].mpc_srcbusirq == irq))
314 return mp_irqs[i].mpc_dstirq;
319 static int __init find_isa_irq_apic(int irq, int type)
323 for (i = 0; i < mp_irq_entries; i++) {
324 int lbus = mp_irqs[i].mpc_srcbus;
326 if (test_bit(lbus, mp_bus_not_pci) &&
327 (mp_irqs[i].mpc_irqtype == type) &&
328 (mp_irqs[i].mpc_srcbusirq == irq))
331 if (i < mp_irq_entries) {
333 for(apic = 0; apic < nr_ioapics; apic++) {
334 if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic)
343 * Find a specific PCI IRQ entry.
344 * Not an __init, possibly needed by modules
346 static int pin_2_irq(int idx, int apic, int pin);
348 int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
350 int apic, i, best_guess = -1;
352 apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
354 if (mp_bus_id_to_pci_bus[bus] == -1) {
355 apic_printk(APIC_VERBOSE, "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
358 for (i = 0; i < mp_irq_entries; i++) {
359 int lbus = mp_irqs[i].mpc_srcbus;
361 for (apic = 0; apic < nr_ioapics; apic++)
362 if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic ||
363 mp_irqs[i].mpc_dstapic == MP_APIC_ALL)
366 if (!test_bit(lbus, mp_bus_not_pci) &&
367 !mp_irqs[i].mpc_irqtype &&
369 (slot == ((mp_irqs[i].mpc_srcbusirq >> 2) & 0x1f))) {
370 int irq = pin_2_irq(i,apic,mp_irqs[i].mpc_dstirq);
372 if (!(apic || IO_APIC_IRQ(irq)))
375 if (pin == (mp_irqs[i].mpc_srcbusirq & 3))
378 * Use the first all-but-pin matching entry as a
379 * best-guess fuzzy result for broken mptables.
385 BUG_ON(best_guess >= NR_IRQS);
389 /* ISA interrupts are always polarity zero edge triggered,
390 * when listed as conforming in the MP table. */
392 #define default_ISA_trigger(idx) (0)
393 #define default_ISA_polarity(idx) (0)
395 /* PCI interrupts are always polarity one level triggered,
396 * when listed as conforming in the MP table. */
398 #define default_PCI_trigger(idx) (1)
399 #define default_PCI_polarity(idx) (1)
401 static int __init MPBIOS_polarity(int idx)
403 int bus = mp_irqs[idx].mpc_srcbus;
407 * Determine IRQ line polarity (high active or low active):
409 switch (mp_irqs[idx].mpc_irqflag & 3)
411 case 0: /* conforms, ie. bus-type dependent polarity */
412 if (test_bit(bus, mp_bus_not_pci))
413 polarity = default_ISA_polarity(idx);
415 polarity = default_PCI_polarity(idx);
417 case 1: /* high active */
422 case 2: /* reserved */
424 printk(KERN_WARNING "broken BIOS!!\n");
428 case 3: /* low active */
433 default: /* invalid */
435 printk(KERN_WARNING "broken BIOS!!\n");
443 static int MPBIOS_trigger(int idx)
445 int bus = mp_irqs[idx].mpc_srcbus;
449 * Determine IRQ trigger mode (edge or level sensitive):
451 switch ((mp_irqs[idx].mpc_irqflag>>2) & 3)
453 case 0: /* conforms, ie. bus-type dependent */
454 if (test_bit(bus, mp_bus_not_pci))
455 trigger = default_ISA_trigger(idx);
457 trigger = default_PCI_trigger(idx);
464 case 2: /* reserved */
466 printk(KERN_WARNING "broken BIOS!!\n");
475 default: /* invalid */
477 printk(KERN_WARNING "broken BIOS!!\n");
485 static inline int irq_polarity(int idx)
487 return MPBIOS_polarity(idx);
490 static inline int irq_trigger(int idx)
492 return MPBIOS_trigger(idx);
495 static int next_irq = 16;
498 * gsi_irq_sharing -- Name overload! "irq" can be either a legacy IRQ
499 * in the range 0-15, a linux IRQ in the range 0-223, or a GSI number
500 * from ACPI, which can reach 800 in large boxen.
502 * Compact the sparse GSI space into a sequential IRQ series and reuse
503 * vectors if possible.
505 int gsi_irq_sharing(int gsi)
507 int i, tries, vector;
509 BUG_ON(gsi >= NR_IRQ_VECTORS);
511 if (platform_legacy_irq(gsi))
514 if (gsi_2_irq[gsi] != 0xFF)
515 return (int)gsi_2_irq[gsi];
519 vector = assign_irq_vector(gsi);
522 * Sharing vectors means sharing IRQs, so scan irq_vectors for previous
523 * use of vector and if found, return that IRQ. However, we never want
524 * to share legacy IRQs, which usually have a different trigger mode
527 for (i = 0; i < NR_IRQS; i++)
528 if (IO_APIC_VECTOR(i) == vector)
530 if (platform_legacy_irq(i)) {
532 IO_APIC_VECTOR(i) = 0;
535 panic("gsi_irq_sharing: didn't find an IRQ using vector 0x%02X for GSI %d", vector, gsi);
539 printk(KERN_INFO "GSI %d sharing vector 0x%02X and IRQ %d\n",
545 BUG_ON(i >= NR_IRQS);
547 IO_APIC_VECTOR(i) = vector;
548 printk(KERN_INFO "GSI %d assigned vector 0x%02X and IRQ %d\n",
553 static int pin_2_irq(int idx, int apic, int pin)
556 int bus = mp_irqs[idx].mpc_srcbus;
559 * Debugging check, we are in big trouble if this message pops up!
561 if (mp_irqs[idx].mpc_dstirq != pin)
562 printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
564 if (test_bit(bus, mp_bus_not_pci)) {
565 irq = mp_irqs[idx].mpc_srcbusirq;
568 * PCI IRQs are mapped in order
572 irq += nr_ioapic_registers[i++];
574 irq = gsi_irq_sharing(irq);
576 BUG_ON(irq >= NR_IRQS);
580 static inline int IO_APIC_irq_trigger(int irq)
584 for (apic = 0; apic < nr_ioapics; apic++) {
585 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
586 idx = find_irq_entry(apic,pin,mp_INT);
587 if ((idx != -1) && (irq == pin_2_irq(idx,apic,pin)))
588 return irq_trigger(idx);
592 * nonexistent IRQs are edge default
597 /* irq_vectors is indexed by the sum of all RTEs in all I/O APICs. */
598 u8 irq_vector[NR_IRQ_VECTORS] __read_mostly = { FIRST_DEVICE_VECTOR , 0 };
600 int assign_irq_vector(int irq)
602 static int current_vector = FIRST_DEVICE_VECTOR, offset = 0;
606 BUG_ON(irq != AUTO_ASSIGN && (unsigned)irq >= NR_IRQ_VECTORS);
608 spin_lock_irqsave(&vector_lock, flags);
610 if (irq != AUTO_ASSIGN && IO_APIC_VECTOR(irq) > 0) {
611 spin_unlock_irqrestore(&vector_lock, flags);
612 return IO_APIC_VECTOR(irq);
616 if (current_vector == IA32_SYSCALL_VECTOR)
619 if (current_vector >= FIRST_SYSTEM_VECTOR) {
620 /* If we run out of vectors on large boxen, must share them. */
621 offset = (offset + 1) % 8;
622 current_vector = FIRST_DEVICE_VECTOR + offset;
625 vector = current_vector;
626 vector_irq[vector] = irq;
627 if (irq != AUTO_ASSIGN)
628 IO_APIC_VECTOR(irq) = vector;
630 spin_unlock_irqrestore(&vector_lock, flags);
635 extern void (*interrupt[NR_IRQS])(void);
636 static struct hw_interrupt_type ioapic_level_type;
637 static struct hw_interrupt_type ioapic_edge_type;
639 #define IOAPIC_AUTO -1
640 #define IOAPIC_EDGE 0
641 #define IOAPIC_LEVEL 1
643 static void ioapic_register_intr(int irq, int vector, unsigned long trigger)
647 idx = use_pci_vector() && !platform_legacy_irq(irq) ? vector : irq;
649 if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
650 trigger == IOAPIC_LEVEL)
651 irq_desc[idx].chip = &ioapic_level_type;
653 irq_desc[idx].chip = &ioapic_edge_type;
654 set_intr_gate(vector, interrupt[idx]);
657 static void __init setup_IO_APIC_irqs(void)
659 struct IO_APIC_route_entry entry;
660 int apic, pin, idx, irq, first_notcon = 1, vector;
663 apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
665 for (apic = 0; apic < nr_ioapics; apic++) {
666 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
669 * add it to the IO-APIC irq-routing table:
671 memset(&entry,0,sizeof(entry));
673 entry.delivery_mode = INT_DELIVERY_MODE;
674 entry.dest_mode = INT_DEST_MODE;
675 entry.mask = 0; /* enable IRQ */
676 entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
678 idx = find_irq_entry(apic,pin,mp_INT);
681 apic_printk(APIC_VERBOSE, KERN_DEBUG " IO-APIC (apicid-pin) %d-%d", mp_ioapics[apic].mpc_apicid, pin);
684 apic_printk(APIC_VERBOSE, ", %d-%d", mp_ioapics[apic].mpc_apicid, pin);
688 entry.trigger = irq_trigger(idx);
689 entry.polarity = irq_polarity(idx);
691 if (irq_trigger(idx)) {
694 entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
697 irq = pin_2_irq(idx, apic, pin);
698 add_pin_to_irq(irq, apic, pin);
700 if (!apic && !IO_APIC_IRQ(irq))
703 if (IO_APIC_IRQ(irq)) {
704 vector = assign_irq_vector(irq);
705 entry.vector = vector;
707 ioapic_register_intr(irq, vector, IOAPIC_AUTO);
708 if (!apic && (irq < 16))
709 disable_8259A_irq(irq);
711 ioapic_write_entry(apic, pin, entry);
713 spin_lock_irqsave(&ioapic_lock, flags);
714 set_native_irq_info(irq, TARGET_CPUS);
715 spin_unlock_irqrestore(&ioapic_lock, flags);
720 apic_printk(APIC_VERBOSE," not connected.\n");
724 * Set up the 8259A-master output pin as broadcast to all
727 static void __init setup_ExtINT_IRQ0_pin(unsigned int apic, unsigned int pin, int vector)
729 struct IO_APIC_route_entry entry;
732 memset(&entry,0,sizeof(entry));
734 disable_8259A_irq(0);
737 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
740 * We use logical delivery to get the timer IRQ
743 entry.dest_mode = INT_DEST_MODE;
744 entry.mask = 0; /* unmask IRQ now */
745 entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
746 entry.delivery_mode = INT_DELIVERY_MODE;
749 entry.vector = vector;
752 * The timer IRQ doesn't have to know that behind the
753 * scene we have a 8259A-master in AEOI mode ...
755 irq_desc[0].chip = &ioapic_edge_type;
758 * Add it to the IO-APIC irq-routing table:
760 spin_lock_irqsave(&ioapic_lock, flags);
761 io_apic_write(apic, 0x11+2*pin, *(((int *)&entry)+1));
762 io_apic_write(apic, 0x10+2*pin, *(((int *)&entry)+0));
763 spin_unlock_irqrestore(&ioapic_lock, flags);
768 void __init UNEXPECTED_IO_APIC(void)
772 void __apicdebuginit print_IO_APIC(void)
775 union IO_APIC_reg_00 reg_00;
776 union IO_APIC_reg_01 reg_01;
777 union IO_APIC_reg_02 reg_02;
780 if (apic_verbosity == APIC_QUIET)
783 printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
784 for (i = 0; i < nr_ioapics; i++)
785 printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
786 mp_ioapics[i].mpc_apicid, nr_ioapic_registers[i]);
789 * We are a bit conservative about what we expect. We have to
790 * know about every hardware change ASAP.
792 printk(KERN_INFO "testing the IO APIC.......................\n");
794 for (apic = 0; apic < nr_ioapics; apic++) {
796 spin_lock_irqsave(&ioapic_lock, flags);
797 reg_00.raw = io_apic_read(apic, 0);
798 reg_01.raw = io_apic_read(apic, 1);
799 if (reg_01.bits.version >= 0x10)
800 reg_02.raw = io_apic_read(apic, 2);
801 spin_unlock_irqrestore(&ioapic_lock, flags);
804 printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mpc_apicid);
805 printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
806 printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
807 if (reg_00.bits.__reserved_1 || reg_00.bits.__reserved_2)
808 UNEXPECTED_IO_APIC();
810 printk(KERN_DEBUG ".... register #01: %08X\n", *(int *)®_01);
811 printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
812 if ( (reg_01.bits.entries != 0x0f) && /* older (Neptune) boards */
813 (reg_01.bits.entries != 0x17) && /* typical ISA+PCI boards */
814 (reg_01.bits.entries != 0x1b) && /* Compaq Proliant boards */
815 (reg_01.bits.entries != 0x1f) && /* dual Xeon boards */
816 (reg_01.bits.entries != 0x22) && /* bigger Xeon boards */
817 (reg_01.bits.entries != 0x2E) &&
818 (reg_01.bits.entries != 0x3F) &&
819 (reg_01.bits.entries != 0x03)
821 UNEXPECTED_IO_APIC();
823 printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
824 printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
825 if ( (reg_01.bits.version != 0x01) && /* 82489DX IO-APICs */
826 (reg_01.bits.version != 0x02) && /* 82801BA IO-APICs (ICH2) */
827 (reg_01.bits.version != 0x10) && /* oldest IO-APICs */
828 (reg_01.bits.version != 0x11) && /* Pentium/Pro IO-APICs */
829 (reg_01.bits.version != 0x13) && /* Xeon IO-APICs */
830 (reg_01.bits.version != 0x20) /* Intel P64H (82806 AA) */
832 UNEXPECTED_IO_APIC();
833 if (reg_01.bits.__reserved_1 || reg_01.bits.__reserved_2)
834 UNEXPECTED_IO_APIC();
836 if (reg_01.bits.version >= 0x10) {
837 printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
838 printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
839 if (reg_02.bits.__reserved_1 || reg_02.bits.__reserved_2)
840 UNEXPECTED_IO_APIC();
843 printk(KERN_DEBUG ".... IRQ redirection table:\n");
845 printk(KERN_DEBUG " NR Log Phy Mask Trig IRR Pol"
846 " Stat Dest Deli Vect: \n");
848 for (i = 0; i <= reg_01.bits.entries; i++) {
849 struct IO_APIC_route_entry entry;
851 entry = ioapic_read_entry(apic, i);
853 printk(KERN_DEBUG " %02x %03X %02X ",
855 entry.dest.logical.logical_dest,
856 entry.dest.physical.physical_dest
859 printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
864 entry.delivery_status,
871 if (use_pci_vector())
872 printk(KERN_INFO "Using vector-based indexing\n");
873 printk(KERN_DEBUG "IRQ to pin mappings:\n");
874 for (i = 0; i < NR_IRQS; i++) {
875 struct irq_pin_list *entry = irq_2_pin + i;
878 if (use_pci_vector() && !platform_legacy_irq(i))
879 printk(KERN_DEBUG "IRQ%d ", IO_APIC_VECTOR(i));
881 printk(KERN_DEBUG "IRQ%d ", i);
883 printk("-> %d:%d", entry->apic, entry->pin);
886 entry = irq_2_pin + entry->next;
891 printk(KERN_INFO ".................................... done.\n");
898 static __apicdebuginit void print_APIC_bitfield (int base)
903 if (apic_verbosity == APIC_QUIET)
906 printk(KERN_DEBUG "0123456789abcdef0123456789abcdef\n" KERN_DEBUG);
907 for (i = 0; i < 8; i++) {
908 v = apic_read(base + i*0x10);
909 for (j = 0; j < 32; j++) {
919 void __apicdebuginit print_local_APIC(void * dummy)
921 unsigned int v, ver, maxlvt;
923 if (apic_verbosity == APIC_QUIET)
926 printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
927 smp_processor_id(), hard_smp_processor_id());
928 v = apic_read(APIC_ID);
929 printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, GET_APIC_ID(v));
930 v = apic_read(APIC_LVR);
931 printk(KERN_INFO "... APIC VERSION: %08x\n", v);
932 ver = GET_APIC_VERSION(v);
933 maxlvt = get_maxlvt();
935 v = apic_read(APIC_TASKPRI);
936 printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
938 v = apic_read(APIC_ARBPRI);
939 printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
940 v & APIC_ARBPRI_MASK);
941 v = apic_read(APIC_PROCPRI);
942 printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
944 v = apic_read(APIC_EOI);
945 printk(KERN_DEBUG "... APIC EOI: %08x\n", v);
946 v = apic_read(APIC_RRR);
947 printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
948 v = apic_read(APIC_LDR);
949 printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
950 v = apic_read(APIC_DFR);
951 printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
952 v = apic_read(APIC_SPIV);
953 printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
955 printk(KERN_DEBUG "... APIC ISR field:\n");
956 print_APIC_bitfield(APIC_ISR);
957 printk(KERN_DEBUG "... APIC TMR field:\n");
958 print_APIC_bitfield(APIC_TMR);
959 printk(KERN_DEBUG "... APIC IRR field:\n");
960 print_APIC_bitfield(APIC_IRR);
962 v = apic_read(APIC_ESR);
963 printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
965 v = apic_read(APIC_ICR);
966 printk(KERN_DEBUG "... APIC ICR: %08x\n", v);
967 v = apic_read(APIC_ICR2);
968 printk(KERN_DEBUG "... APIC ICR2: %08x\n", v);
970 v = apic_read(APIC_LVTT);
971 printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
973 if (maxlvt > 3) { /* PC is LVT#4. */
974 v = apic_read(APIC_LVTPC);
975 printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
977 v = apic_read(APIC_LVT0);
978 printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
979 v = apic_read(APIC_LVT1);
980 printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
982 if (maxlvt > 2) { /* ERR is LVT#3. */
983 v = apic_read(APIC_LVTERR);
984 printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
987 v = apic_read(APIC_TMICT);
988 printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
989 v = apic_read(APIC_TMCCT);
990 printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
991 v = apic_read(APIC_TDCR);
992 printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
996 void print_all_local_APICs (void)
998 on_each_cpu(print_local_APIC, NULL, 1, 1);
1001 void __apicdebuginit print_PIC(void)
1004 unsigned long flags;
1006 if (apic_verbosity == APIC_QUIET)
1009 printk(KERN_DEBUG "\nprinting PIC contents\n");
1011 spin_lock_irqsave(&i8259A_lock, flags);
1013 v = inb(0xa1) << 8 | inb(0x21);
1014 printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
1016 v = inb(0xa0) << 8 | inb(0x20);
1017 printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
1021 v = inb(0xa0) << 8 | inb(0x20);
1025 spin_unlock_irqrestore(&i8259A_lock, flags);
1027 printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
1029 v = inb(0x4d1) << 8 | inb(0x4d0);
1030 printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
1035 static void __init enable_IO_APIC(void)
1037 union IO_APIC_reg_01 reg_01;
1038 int i8259_apic, i8259_pin;
1040 unsigned long flags;
1042 for (i = 0; i < PIN_MAP_SIZE; i++) {
1043 irq_2_pin[i].pin = -1;
1044 irq_2_pin[i].next = 0;
1048 * The number of IO-APIC IRQ registers (== #pins):
1050 for (apic = 0; apic < nr_ioapics; apic++) {
1051 spin_lock_irqsave(&ioapic_lock, flags);
1052 reg_01.raw = io_apic_read(apic, 1);
1053 spin_unlock_irqrestore(&ioapic_lock, flags);
1054 nr_ioapic_registers[apic] = reg_01.bits.entries+1;
1056 for(apic = 0; apic < nr_ioapics; apic++) {
1058 /* See if any of the pins is in ExtINT mode */
1059 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
1060 struct IO_APIC_route_entry entry;
1061 entry = ioapic_read_entry(apic, pin);
1063 /* If the interrupt line is enabled and in ExtInt mode
1064 * I have found the pin where the i8259 is connected.
1066 if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
1067 ioapic_i8259.apic = apic;
1068 ioapic_i8259.pin = pin;
1074 /* Look to see what if the MP table has reported the ExtINT */
1075 i8259_pin = find_isa_irq_pin(0, mp_ExtINT);
1076 i8259_apic = find_isa_irq_apic(0, mp_ExtINT);
1077 /* Trust the MP table if nothing is setup in the hardware */
1078 if ((ioapic_i8259.pin == -1) && (i8259_pin >= 0)) {
1079 printk(KERN_WARNING "ExtINT not setup in hardware but reported by MP table\n");
1080 ioapic_i8259.pin = i8259_pin;
1081 ioapic_i8259.apic = i8259_apic;
1083 /* Complain if the MP table and the hardware disagree */
1084 if (((ioapic_i8259.apic != i8259_apic) || (ioapic_i8259.pin != i8259_pin)) &&
1085 (i8259_pin >= 0) && (ioapic_i8259.pin >= 0))
1087 printk(KERN_WARNING "ExtINT in hardware and MP table differ\n");
1091 * Do not trust the IO-APIC being empty at bootup
1097 * Not an __init, needed by the reboot code
1099 void disable_IO_APIC(void)
1102 * Clear the IO-APIC before rebooting:
1107 * If the i8259 is routed through an IOAPIC
1108 * Put that IOAPIC in virtual wire mode
1109 * so legacy interrupts can be delivered.
1111 if (ioapic_i8259.pin != -1) {
1112 struct IO_APIC_route_entry entry;
1114 memset(&entry, 0, sizeof(entry));
1115 entry.mask = 0; /* Enabled */
1116 entry.trigger = 0; /* Edge */
1118 entry.polarity = 0; /* High */
1119 entry.delivery_status = 0;
1120 entry.dest_mode = 0; /* Physical */
1121 entry.delivery_mode = dest_ExtINT; /* ExtInt */
1123 entry.dest.physical.physical_dest =
1124 GET_APIC_ID(apic_read(APIC_ID));
1127 * Add it to the IO-APIC irq-routing table:
1129 ioapic_write_entry(ioapic_i8259.apic, ioapic_i8259.pin, entry);
1132 disconnect_bsp_APIC(ioapic_i8259.pin != -1);
1136 * There is a nasty bug in some older SMP boards, their mptable lies
1137 * about the timer IRQ. We do the following to work around the situation:
1139 * - timer IRQ defaults to IO-APIC IRQ
1140 * - if this function detects that timer IRQs are defunct, then we fall
1141 * back to ISA timer IRQs
1143 static int __init timer_irq_works(void)
1145 unsigned long t1 = jiffies;
1148 /* Let ten ticks pass... */
1149 mdelay((10 * 1000) / HZ);
1152 * Expect a few ticks at least, to be sure some possible
1153 * glue logic does not lock up after one or two first
1154 * ticks in a non-ExtINT mode. Also the local APIC
1155 * might have cached one ExtINT interrupt. Finally, at
1156 * least one tick may be lost due to delays.
1160 if (jiffies - t1 > 4)
1166 * In the SMP+IOAPIC case it might happen that there are an unspecified
1167 * number of pending IRQ events unhandled. These cases are very rare,
1168 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
1169 * better to do it this way as thus we do not have to be aware of
1170 * 'pending' interrupts in the IRQ path, except at this point.
1173 * Edge triggered needs to resend any interrupt
1174 * that was delayed but this is now handled in the device
1179 * Starting up a edge-triggered IO-APIC interrupt is
1180 * nasty - we need to make sure that we get the edge.
1181 * If it is already asserted for some reason, we need
1182 * return 1 to indicate that is was pending.
1184 * This is not complete - we should be able to fake
1185 * an edge even if it isn't on the 8259A...
1188 static unsigned int startup_edge_ioapic_irq(unsigned int irq)
1190 int was_pending = 0;
1191 unsigned long flags;
1193 spin_lock_irqsave(&ioapic_lock, flags);
1195 disable_8259A_irq(irq);
1196 if (i8259A_irq_pending(irq))
1199 __unmask_IO_APIC_irq(irq);
1200 spin_unlock_irqrestore(&ioapic_lock, flags);
1206 * Once we have recorded IRQ_PENDING already, we can mask the
1207 * interrupt for real. This prevents IRQ storms from unhandled
1210 static void ack_edge_ioapic_irq(unsigned int irq)
1213 if ((irq_desc[irq].status & (IRQ_PENDING | IRQ_DISABLED))
1214 == (IRQ_PENDING | IRQ_DISABLED))
1215 mask_IO_APIC_irq(irq);
1220 * Level triggered interrupts can just be masked,
1221 * and shutting down and starting up the interrupt
1222 * is the same as enabling and disabling them -- except
1223 * with a startup need to return a "was pending" value.
1225 * Level triggered interrupts are special because we
1226 * do not touch any IO-APIC register while handling
1227 * them. We ack the APIC in the end-IRQ handler, not
1228 * in the start-IRQ-handler. Protection against reentrance
1229 * from the same interrupt is still provided, both by the
1230 * generic IRQ layer and by the fact that an unacked local
1231 * APIC does not accept IRQs.
1233 static unsigned int startup_level_ioapic_irq (unsigned int irq)
1235 unmask_IO_APIC_irq(irq);
1237 return 0; /* don't check for pending */
1240 static void end_level_ioapic_irq (unsigned int irq)
1246 #ifdef CONFIG_PCI_MSI
1247 static unsigned int startup_edge_ioapic_vector(unsigned int vector)
1249 int irq = vector_to_irq(vector);
1251 return startup_edge_ioapic_irq(irq);
1254 static void ack_edge_ioapic_vector(unsigned int vector)
1256 int irq = vector_to_irq(vector);
1258 move_native_irq(vector);
1259 ack_edge_ioapic_irq(irq);
1262 static unsigned int startup_level_ioapic_vector (unsigned int vector)
1264 int irq = vector_to_irq(vector);
1266 return startup_level_ioapic_irq (irq);
1269 static void end_level_ioapic_vector (unsigned int vector)
1271 int irq = vector_to_irq(vector);
1273 move_native_irq(vector);
1274 end_level_ioapic_irq(irq);
1277 static void mask_IO_APIC_vector (unsigned int vector)
1279 int irq = vector_to_irq(vector);
1281 mask_IO_APIC_irq(irq);
1284 static void unmask_IO_APIC_vector (unsigned int vector)
1286 int irq = vector_to_irq(vector);
1288 unmask_IO_APIC_irq(irq);
1292 static void set_ioapic_affinity_vector (unsigned int vector,
1295 int irq = vector_to_irq(vector);
1297 set_native_irq_info(vector, cpu_mask);
1298 set_ioapic_affinity_irq(irq, cpu_mask);
1300 #endif // CONFIG_SMP
1301 #endif // CONFIG_PCI_MSI
1303 static int ioapic_retrigger(unsigned int irq)
1305 send_IPI_self(IO_APIC_VECTOR(irq));
1311 * Level and edge triggered IO-APIC interrupts need different handling,
1312 * so we use two separate IRQ descriptors. Edge triggered IRQs can be
1313 * handled with the level-triggered descriptor, but that one has slightly
1314 * more overhead. Level-triggered interrupts cannot be handled with the
1315 * edge-triggered handler, without risking IRQ storms and other ugly
1319 static struct hw_interrupt_type ioapic_edge_type __read_mostly = {
1320 .typename = "IO-APIC-edge",
1321 .startup = startup_edge_ioapic,
1322 .shutdown = shutdown_edge_ioapic,
1323 .enable = enable_edge_ioapic,
1324 .disable = disable_edge_ioapic,
1325 .ack = ack_edge_ioapic,
1326 .end = end_edge_ioapic,
1328 .set_affinity = set_ioapic_affinity,
1330 .retrigger = ioapic_retrigger,
1333 static struct hw_interrupt_type ioapic_level_type __read_mostly = {
1334 .typename = "IO-APIC-level",
1335 .startup = startup_level_ioapic,
1336 .shutdown = shutdown_level_ioapic,
1337 .enable = enable_level_ioapic,
1338 .disable = disable_level_ioapic,
1339 .ack = mask_and_ack_level_ioapic,
1340 .end = end_level_ioapic,
1342 .set_affinity = set_ioapic_affinity,
1344 .retrigger = ioapic_retrigger,
1347 static inline void init_IO_APIC_traps(void)
1352 * NOTE! The local APIC isn't very good at handling
1353 * multiple interrupts at the same interrupt level.
1354 * As the interrupt level is determined by taking the
1355 * vector number and shifting that right by 4, we
1356 * want to spread these out a bit so that they don't
1357 * all fall in the same interrupt level.
1359 * Also, we've got to be careful not to trash gate
1360 * 0x80, because int 0x80 is hm, kind of importantish. ;)
1362 for (irq = 0; irq < NR_IRQS ; irq++) {
1364 if (use_pci_vector()) {
1365 if (!platform_legacy_irq(tmp))
1366 if ((tmp = vector_to_irq(tmp)) == -1)
1369 if (IO_APIC_IRQ(tmp) && !IO_APIC_VECTOR(tmp)) {
1371 * Hmm.. We don't have an entry for this,
1372 * so default to an old-fashioned 8259
1373 * interrupt if we can..
1376 make_8259A_irq(irq);
1378 /* Strange. Oh, well.. */
1379 irq_desc[irq].chip = &no_irq_type;
1384 static void enable_lapic_irq (unsigned int irq)
1388 v = apic_read(APIC_LVT0);
1389 apic_write(APIC_LVT0, v & ~APIC_LVT_MASKED);
1392 static void disable_lapic_irq (unsigned int irq)
1396 v = apic_read(APIC_LVT0);
1397 apic_write(APIC_LVT0, v | APIC_LVT_MASKED);
1400 static void ack_lapic_irq (unsigned int irq)
1405 static void end_lapic_irq (unsigned int i) { /* nothing */ }
1407 static struct hw_interrupt_type lapic_irq_type __read_mostly = {
1408 .typename = "local-APIC-edge",
1409 .startup = NULL, /* startup_irq() not used for IRQ0 */
1410 .shutdown = NULL, /* shutdown_irq() not used for IRQ0 */
1411 .enable = enable_lapic_irq,
1412 .disable = disable_lapic_irq,
1413 .ack = ack_lapic_irq,
1414 .end = end_lapic_irq,
1417 static void setup_nmi (void)
1420 * Dirty trick to enable the NMI watchdog ...
1421 * We put the 8259A master into AEOI mode and
1422 * unmask on all local APICs LVT0 as NMI.
1424 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
1425 * is from Maciej W. Rozycki - so we do not have to EOI from
1426 * the NMI handler or the timer interrupt.
1428 printk(KERN_INFO "activating NMI Watchdog ...");
1430 enable_NMI_through_LVT0(NULL);
1436 * This looks a bit hackish but it's about the only one way of sending
1437 * a few INTA cycles to 8259As and any associated glue logic. ICR does
1438 * not support the ExtINT mode, unfortunately. We need to send these
1439 * cycles as some i82489DX-based boards have glue logic that keeps the
1440 * 8259A interrupt line asserted until INTA. --macro
1442 static inline void unlock_ExtINT_logic(void)
1445 struct IO_APIC_route_entry entry0, entry1;
1446 unsigned char save_control, save_freq_select;
1447 unsigned long flags;
1449 pin = find_isa_irq_pin(8, mp_INT);
1450 apic = find_isa_irq_apic(8, mp_INT);
1454 spin_lock_irqsave(&ioapic_lock, flags);
1455 *(((int *)&entry0) + 1) = io_apic_read(apic, 0x11 + 2 * pin);
1456 *(((int *)&entry0) + 0) = io_apic_read(apic, 0x10 + 2 * pin);
1457 spin_unlock_irqrestore(&ioapic_lock, flags);
1458 clear_IO_APIC_pin(apic, pin);
1460 memset(&entry1, 0, sizeof(entry1));
1462 entry1.dest_mode = 0; /* physical delivery */
1463 entry1.mask = 0; /* unmask IRQ now */
1464 entry1.dest.physical.physical_dest = hard_smp_processor_id();
1465 entry1.delivery_mode = dest_ExtINT;
1466 entry1.polarity = entry0.polarity;
1470 spin_lock_irqsave(&ioapic_lock, flags);
1471 io_apic_write(apic, 0x11 + 2 * pin, *(((int *)&entry1) + 1));
1472 io_apic_write(apic, 0x10 + 2 * pin, *(((int *)&entry1) + 0));
1473 spin_unlock_irqrestore(&ioapic_lock, flags);
1475 save_control = CMOS_READ(RTC_CONTROL);
1476 save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
1477 CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
1479 CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
1484 if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
1488 CMOS_WRITE(save_control, RTC_CONTROL);
1489 CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
1490 clear_IO_APIC_pin(apic, pin);
1492 spin_lock_irqsave(&ioapic_lock, flags);
1493 io_apic_write(apic, 0x11 + 2 * pin, *(((int *)&entry0) + 1));
1494 io_apic_write(apic, 0x10 + 2 * pin, *(((int *)&entry0) + 0));
1495 spin_unlock_irqrestore(&ioapic_lock, flags);
1498 int timer_uses_ioapic_pin_0;
1501 * This code may look a bit paranoid, but it's supposed to cooperate with
1502 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
1503 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
1504 * fanatically on his truly buggy board.
1506 * FIXME: really need to revamp this for modern platforms only.
1508 static inline void check_timer(void)
1510 int apic1, pin1, apic2, pin2;
1514 * get/set the timer IRQ vector:
1516 disable_8259A_irq(0);
1517 vector = assign_irq_vector(0);
1518 set_intr_gate(vector, interrupt[0]);
1521 * Subtle, code in do_timer_interrupt() expects an AEOI
1522 * mode for the 8259A whenever interrupts are routed
1523 * through I/O APICs. Also IRQ0 has to be enabled in
1524 * the 8259A which implies the virtual wire has to be
1525 * disabled in the local APIC.
1527 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
1529 if (timer_over_8254 > 0)
1530 enable_8259A_irq(0);
1532 pin1 = find_isa_irq_pin(0, mp_INT);
1533 apic1 = find_isa_irq_apic(0, mp_INT);
1534 pin2 = ioapic_i8259.pin;
1535 apic2 = ioapic_i8259.apic;
1538 timer_uses_ioapic_pin_0 = 1;
1540 apic_printk(APIC_VERBOSE,KERN_INFO "..TIMER: vector=0x%02X apic1=%d pin1=%d apic2=%d pin2=%d\n",
1541 vector, apic1, pin1, apic2, pin2);
1545 * Ok, does IRQ0 through the IOAPIC work?
1547 unmask_IO_APIC_irq(0);
1548 if (!no_timer_check && timer_irq_works()) {
1549 nmi_watchdog_default();
1550 if (nmi_watchdog == NMI_IO_APIC) {
1551 disable_8259A_irq(0);
1553 enable_8259A_irq(0);
1555 if (disable_timer_pin_1 > 0)
1556 clear_IO_APIC_pin(0, pin1);
1559 clear_IO_APIC_pin(apic1, pin1);
1560 apic_printk(APIC_QUIET,KERN_ERR "..MP-BIOS bug: 8254 timer not "
1561 "connected to IO-APIC\n");
1564 apic_printk(APIC_VERBOSE,KERN_INFO "...trying to set up timer (IRQ0) "
1565 "through the 8259A ... ");
1567 apic_printk(APIC_VERBOSE,"\n..... (found apic %d pin %d) ...",
1570 * legacy devices should be connected to IO APIC #0
1572 setup_ExtINT_IRQ0_pin(apic2, pin2, vector);
1573 if (timer_irq_works()) {
1574 apic_printk(APIC_VERBOSE," works.\n");
1575 nmi_watchdog_default();
1576 if (nmi_watchdog == NMI_IO_APIC) {
1582 * Cleanup, just in case ...
1584 clear_IO_APIC_pin(apic2, pin2);
1586 apic_printk(APIC_VERBOSE," failed.\n");
1588 if (nmi_watchdog == NMI_IO_APIC) {
1589 printk(KERN_WARNING "timer doesn't work through the IO-APIC - disabling NMI Watchdog!\n");
1593 apic_printk(APIC_VERBOSE, KERN_INFO "...trying to set up timer as Virtual Wire IRQ...");
1595 disable_8259A_irq(0);
1596 irq_desc[0].chip = &lapic_irq_type;
1597 apic_write(APIC_LVT0, APIC_DM_FIXED | vector); /* Fixed mode */
1598 enable_8259A_irq(0);
1600 if (timer_irq_works()) {
1601 apic_printk(APIC_VERBOSE," works.\n");
1604 apic_write(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector);
1605 apic_printk(APIC_VERBOSE," failed.\n");
1607 apic_printk(APIC_VERBOSE, KERN_INFO "...trying to set up timer as ExtINT IRQ...");
1611 apic_write(APIC_LVT0, APIC_DM_EXTINT);
1613 unlock_ExtINT_logic();
1615 if (timer_irq_works()) {
1616 apic_printk(APIC_VERBOSE," works.\n");
1619 apic_printk(APIC_VERBOSE," failed :(.\n");
1620 panic("IO-APIC + timer doesn't work! Try using the 'noapic' kernel parameter\n");
1623 static int __init notimercheck(char *s)
1628 __setup("no_timer_check", notimercheck);
1632 * IRQ's that are handled by the PIC in the MPS IOAPIC case.
1633 * - IRQ2 is the cascade IRQ, and cannot be a io-apic IRQ.
1634 * Linux doesn't really care, as it's not actually used
1635 * for any interrupt handling anyway.
1637 #define PIC_IRQS (1<<2)
1639 void __init setup_IO_APIC(void)
1644 io_apic_irqs = ~0; /* all IRQs go through IOAPIC */
1646 io_apic_irqs = ~PIC_IRQS;
1648 apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n");
1651 setup_IO_APIC_irqs();
1652 init_IO_APIC_traps();
1658 struct sysfs_ioapic_data {
1659 struct sys_device dev;
1660 struct IO_APIC_route_entry entry[0];
1662 static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];
1664 static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
1666 struct IO_APIC_route_entry *entry;
1667 struct sysfs_ioapic_data *data;
1670 data = container_of(dev, struct sysfs_ioapic_data, dev);
1671 entry = data->entry;
1672 for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ )
1673 *entry = ioapic_read_entry(dev->id, i);
1678 static int ioapic_resume(struct sys_device *dev)
1680 struct IO_APIC_route_entry *entry;
1681 struct sysfs_ioapic_data *data;
1682 unsigned long flags;
1683 union IO_APIC_reg_00 reg_00;
1686 data = container_of(dev, struct sysfs_ioapic_data, dev);
1687 entry = data->entry;
1689 spin_lock_irqsave(&ioapic_lock, flags);
1690 reg_00.raw = io_apic_read(dev->id, 0);
1691 if (reg_00.bits.ID != mp_ioapics[dev->id].mpc_apicid) {
1692 reg_00.bits.ID = mp_ioapics[dev->id].mpc_apicid;
1693 io_apic_write(dev->id, 0, reg_00.raw);
1695 spin_unlock_irqrestore(&ioapic_lock, flags);
1696 for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
1697 ioapic_write_entry(dev->id, i, entry[i]);
1702 static struct sysdev_class ioapic_sysdev_class = {
1703 set_kset_name("ioapic"),
1704 .suspend = ioapic_suspend,
1705 .resume = ioapic_resume,
1708 static int __init ioapic_init_sysfs(void)
1710 struct sys_device * dev;
1711 int i, size, error = 0;
1713 error = sysdev_class_register(&ioapic_sysdev_class);
1717 for (i = 0; i < nr_ioapics; i++ ) {
1718 size = sizeof(struct sys_device) + nr_ioapic_registers[i]
1719 * sizeof(struct IO_APIC_route_entry);
1720 mp_ioapic_data[i] = kmalloc(size, GFP_KERNEL);
1721 if (!mp_ioapic_data[i]) {
1722 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
1725 memset(mp_ioapic_data[i], 0, size);
1726 dev = &mp_ioapic_data[i]->dev;
1728 dev->cls = &ioapic_sysdev_class;
1729 error = sysdev_register(dev);
1731 kfree(mp_ioapic_data[i]);
1732 mp_ioapic_data[i] = NULL;
1733 printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
1741 device_initcall(ioapic_init_sysfs);
1743 /* --------------------------------------------------------------------------
1744 ACPI-based IOAPIC Configuration
1745 -------------------------------------------------------------------------- */
1749 #define IO_APIC_MAX_ID 0xFE
1751 int __init io_apic_get_redir_entries (int ioapic)
1753 union IO_APIC_reg_01 reg_01;
1754 unsigned long flags;
1756 spin_lock_irqsave(&ioapic_lock, flags);
1757 reg_01.raw = io_apic_read(ioapic, 1);
1758 spin_unlock_irqrestore(&ioapic_lock, flags);
1760 return reg_01.bits.entries;
1764 int io_apic_set_pci_routing (int ioapic, int pin, int irq, int triggering, int polarity)
1766 struct IO_APIC_route_entry entry;
1767 unsigned long flags;
1769 if (!IO_APIC_IRQ(irq)) {
1770 apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
1776 * Generate a PCI IRQ routing entry and program the IOAPIC accordingly.
1777 * Note that we mask (disable) IRQs now -- these get enabled when the
1778 * corresponding device driver registers for this IRQ.
1781 memset(&entry,0,sizeof(entry));
1783 entry.delivery_mode = INT_DELIVERY_MODE;
1784 entry.dest_mode = INT_DEST_MODE;
1785 entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
1786 entry.trigger = triggering;
1787 entry.polarity = polarity;
1788 entry.mask = 1; /* Disabled (masked) */
1790 irq = gsi_irq_sharing(irq);
1792 * IRQs < 16 are already in the irq_2_pin[] map
1795 add_pin_to_irq(irq, ioapic, pin);
1797 entry.vector = assign_irq_vector(irq);
1799 apic_printk(APIC_VERBOSE,KERN_DEBUG "IOAPIC[%d]: Set PCI routing entry (%d-%d -> 0x%x -> "
1800 "IRQ %d Mode:%i Active:%i)\n", ioapic,
1801 mp_ioapics[ioapic].mpc_apicid, pin, entry.vector, irq,
1802 triggering, polarity);
1804 ioapic_register_intr(irq, entry.vector, triggering);
1806 if (!ioapic && (irq < 16))
1807 disable_8259A_irq(irq);
1809 ioapic_write_entry(ioapic, pin, entry);
1811 spin_lock_irqsave(&ioapic_lock, flags);
1812 set_native_irq_info(use_pci_vector() ? entry.vector : irq, TARGET_CPUS);
1813 spin_unlock_irqrestore(&ioapic_lock, flags);
1818 #endif /* CONFIG_ACPI */
1822 * This function currently is only a helper for the i386 smp boot process where
1823 * we need to reprogram the ioredtbls to cater for the cpus which have come online
1824 * so mask in all cases should simply be TARGET_CPUS
1827 void __init setup_ioapic_dest(void)
1829 int pin, ioapic, irq, irq_entry;
1831 if (skip_ioapic_setup == 1)
1834 for (ioapic = 0; ioapic < nr_ioapics; ioapic++) {
1835 for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
1836 irq_entry = find_irq_entry(ioapic, pin, mp_INT);
1837 if (irq_entry == -1)
1839 irq = pin_2_irq(irq_entry, ioapic, pin);
1840 set_ioapic_affinity_irq(irq, TARGET_CPUS);