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/pci.h>
29 #include <linux/mc146818rtc.h>
30 #include <linux/acpi.h>
31 #include <linux/sysdev.h>
32 #include <linux/msi.h>
33 #include <linux/htirq.h>
34 #include <linux/dmar.h>
35 #include <linux/jiffies.h>
37 #include <acpi/acpi_bus.h>
39 #include <linux/bootmem.h>
40 #include <linux/dmar.h>
46 #include <asm/proto.h>
49 #include <asm/i8259.h>
51 #include <asm/msidef.h>
52 #include <asm/hypertransport.h>
53 #include <asm/irq_remapping.h>
56 #include <mach_apic.h>
58 #define __apicdebuginit(type) static type __init
65 struct irq_pin_list
*irq_2_pin
;
68 unsigned move_cleanup_count
;
70 u8 move_in_progress
: 1;
73 /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
74 static struct irq_cfg irq_cfg_legacy
[] __initdata
= {
75 [0] = { .irq
= 0, .domain
= CPU_MASK_ALL
, .vector
= IRQ0_VECTOR
, },
76 [1] = { .irq
= 1, .domain
= CPU_MASK_ALL
, .vector
= IRQ1_VECTOR
, },
77 [2] = { .irq
= 2, .domain
= CPU_MASK_ALL
, .vector
= IRQ2_VECTOR
, },
78 [3] = { .irq
= 3, .domain
= CPU_MASK_ALL
, .vector
= IRQ3_VECTOR
, },
79 [4] = { .irq
= 4, .domain
= CPU_MASK_ALL
, .vector
= IRQ4_VECTOR
, },
80 [5] = { .irq
= 5, .domain
= CPU_MASK_ALL
, .vector
= IRQ5_VECTOR
, },
81 [6] = { .irq
= 6, .domain
= CPU_MASK_ALL
, .vector
= IRQ6_VECTOR
, },
82 [7] = { .irq
= 7, .domain
= CPU_MASK_ALL
, .vector
= IRQ7_VECTOR
, },
83 [8] = { .irq
= 8, .domain
= CPU_MASK_ALL
, .vector
= IRQ8_VECTOR
, },
84 [9] = { .irq
= 9, .domain
= CPU_MASK_ALL
, .vector
= IRQ9_VECTOR
, },
85 [10] = { .irq
= 10, .domain
= CPU_MASK_ALL
, .vector
= IRQ10_VECTOR
, },
86 [11] = { .irq
= 11, .domain
= CPU_MASK_ALL
, .vector
= IRQ11_VECTOR
, },
87 [12] = { .irq
= 12, .domain
= CPU_MASK_ALL
, .vector
= IRQ12_VECTOR
, },
88 [13] = { .irq
= 13, .domain
= CPU_MASK_ALL
, .vector
= IRQ13_VECTOR
, },
89 [14] = { .irq
= 14, .domain
= CPU_MASK_ALL
, .vector
= IRQ14_VECTOR
, },
90 [15] = { .irq
= 15, .domain
= CPU_MASK_ALL
, .vector
= IRQ15_VECTOR
, },
93 static struct irq_cfg irq_cfg_init
= { .irq
= -1U, };
94 /* need to be biger than size of irq_cfg_legacy */
95 static int nr_irq_cfg
= 32;
97 static int __init
parse_nr_irq_cfg(char *arg
)
100 nr_irq_cfg
= simple_strtoul(arg
, NULL
, 0);
107 early_param("nr_irq_cfg", parse_nr_irq_cfg
);
109 static void init_one_irq_cfg(struct irq_cfg
*cfg
)
111 memcpy(cfg
, &irq_cfg_init
, sizeof(struct irq_cfg
));
114 static struct irq_cfg
*irq_cfgx
;
115 static struct irq_cfg
*irq_cfgx_free
;
116 static void __init
init_work(void *data
)
118 struct dyn_array
*da
= data
;
125 memcpy(cfg
, irq_cfg_legacy
, sizeof(irq_cfg_legacy
));
127 legacy_count
= sizeof(irq_cfg_legacy
)/sizeof(irq_cfg_legacy
[0]);
128 for (i
= legacy_count
; i
< *da
->nr
; i
++)
129 init_one_irq_cfg(&cfg
[i
]);
131 for (i
= 1; i
< *da
->nr
; i
++)
132 cfg
[i
-1].next
= &cfg
[i
];
134 irq_cfgx_free
= &irq_cfgx
[legacy_count
];
135 irq_cfgx
[legacy_count
- 1].next
= NULL
;
138 #define for_each_irq_cfg(cfg) \
139 for (cfg = irq_cfgx; cfg; cfg = cfg->next)
141 DEFINE_DYN_ARRAY(irq_cfgx
, sizeof(struct irq_cfg
), nr_irq_cfg
, PAGE_SIZE
, init_work
);
143 static struct irq_cfg
*irq_cfg(unsigned int irq
)
158 static struct irq_cfg
*irq_cfg_alloc(unsigned int irq
)
160 struct irq_cfg
*cfg
, *cfg_pri
;
164 cfg_pri
= cfg
= irq_cfgx
;
174 if (!irq_cfgx_free
) {
176 unsigned long total_bytes
;
178 * we run out of pre-allocate ones, allocate more
180 printk(KERN_DEBUG
"try to get more irq_cfg %d\n", nr_irq_cfg
);
182 total_bytes
= sizeof(struct irq_cfg
) * nr_irq_cfg
;
184 cfg
= kzalloc(total_bytes
, GFP_ATOMIC
);
186 cfg
= __alloc_bootmem_nopanic(total_bytes
, PAGE_SIZE
, 0);
189 panic("please boot with nr_irq_cfg= %d\n", count
* 2);
192 printk(KERN_DEBUG
"irq_irq ==> [%#lx - %#lx]\n", phys
, phys
+ total_bytes
);
194 for (i
= 0; i
< nr_irq_cfg
; i
++)
195 init_one_irq_cfg(&cfg
[i
]);
197 for (i
= 1; i
< nr_irq_cfg
; i
++)
198 cfg
[i
-1].next
= &cfg
[i
];
204 irq_cfgx_free
= irq_cfgx_free
->next
;
211 printk(KERN_DEBUG
"found new irq_cfg for irq %d\n", cfg
->irq
);
212 #ifdef CONFIG_HAVE_SPARSE_IRQ_DEBUG
214 /* dump the results */
217 unsigned long bytes
= sizeof(struct irq_cfg
);
219 printk(KERN_DEBUG
"=========================== %d\n", irq
);
220 printk(KERN_DEBUG
"irq_cfg dump after get that for %d\n", irq
);
221 for_each_irq_cfg(cfg
) {
223 printk(KERN_DEBUG
"irq_cfg %d ==> [%#lx - %#lx]\n", cfg
->irq
, phys
, phys
+ bytes
);
225 printk(KERN_DEBUG
"===========================\n");
231 static int assign_irq_vector(int irq
, cpumask_t mask
);
233 int first_system_vector
= 0xfe;
235 char system_vectors
[NR_VECTORS
] = { [0 ... NR_VECTORS
-1] = SYS_VECTOR_FREE
};
237 int sis_apic_bug
; /* not actually supported, dummy for compile */
239 static int no_timer_check
;
241 static int disable_timer_pin_1 __initdata
;
243 int timer_through_8259 __initdata
;
245 /* Where if anywhere is the i8259 connect in external int mode */
246 static struct { int pin
, apic
; } ioapic_i8259
= { -1, -1 };
248 static DEFINE_SPINLOCK(ioapic_lock
);
249 static DEFINE_SPINLOCK(vector_lock
);
252 * # of IRQ routing registers
254 int nr_ioapic_registers
[MAX_IO_APICS
];
256 /* I/O APIC RTE contents at the OS boot up */
257 struct IO_APIC_route_entry
*early_ioapic_entries
[MAX_IO_APICS
];
259 /* I/O APIC entries */
260 struct mp_config_ioapic mp_ioapics
[MAX_IO_APICS
];
263 /* MP IRQ source entries */
264 struct mp_config_intsrc mp_irqs
[MAX_IRQ_SOURCES
];
266 /* # of MP IRQ source entries */
269 DECLARE_BITMAP(mp_bus_not_pci
, MAX_MP_BUSSES
);
272 * Rough estimation of how many shared IRQs there are, can
273 * be changed anytime.
279 * This is performance-critical, we want to do it O(1)
281 * the indexing order of this array favors 1:1 mappings
282 * between pins and IRQs.
285 struct irq_pin_list
{
287 struct irq_pin_list
*next
;
290 static struct irq_pin_list
*irq_2_pin_head
;
291 /* fill one page ? */
292 static int nr_irq_2_pin
= 0x100;
293 static struct irq_pin_list
*irq_2_pin_ptr
;
294 static void __init
irq_2_pin_init_work(void *data
)
296 struct dyn_array
*da
= data
;
297 struct irq_pin_list
*pin
;
302 for (i
= 1; i
< *da
->nr
; i
++)
303 pin
[i
-1].next
= &pin
[i
];
305 irq_2_pin_ptr
= &pin
[0];
307 DEFINE_DYN_ARRAY(irq_2_pin_head
, sizeof(struct irq_pin_list
), nr_irq_2_pin
, PAGE_SIZE
, irq_2_pin_init_work
);
309 static struct irq_pin_list
*get_one_free_irq_2_pin(void)
311 struct irq_pin_list
*pin
;
317 irq_2_pin_ptr
= pin
->next
;
323 * we run out of pre-allocate ones, allocate more
325 printk(KERN_DEBUG
"try to get more irq_2_pin %d\n", nr_irq_2_pin
);
328 pin
= kzalloc(sizeof(struct irq_pin_list
)*nr_irq_2_pin
,
331 pin
= __alloc_bootmem_nopanic(sizeof(struct irq_pin_list
) *
332 nr_irq_2_pin
, PAGE_SIZE
, 0);
335 panic("can not get more irq_2_pin\n");
337 for (i
= 1; i
< nr_irq_2_pin
; i
++)
338 pin
[i
-1].next
= &pin
[i
];
340 irq_2_pin_ptr
= pin
->next
;
348 unsigned int unused
[3];
352 static __attribute_const__
struct io_apic __iomem
*io_apic_base(int idx
)
354 return (void __iomem
*) __fix_to_virt(FIX_IO_APIC_BASE_0
+ idx
)
355 + (mp_ioapics
[idx
].mp_apicaddr
& ~PAGE_MASK
);
358 static inline unsigned int io_apic_read(unsigned int apic
, unsigned int reg
)
360 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
361 writel(reg
, &io_apic
->index
);
362 return readl(&io_apic
->data
);
365 static inline void io_apic_write(unsigned int apic
, unsigned int reg
, unsigned int value
)
367 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
368 writel(reg
, &io_apic
->index
);
369 writel(value
, &io_apic
->data
);
373 * Re-write a value: to be used for read-modify-write
374 * cycles where the read already set up the index register.
376 static inline void io_apic_modify(unsigned int apic
, unsigned int value
)
378 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
379 writel(value
, &io_apic
->data
);
382 static bool io_apic_level_ack_pending(unsigned int irq
)
384 struct irq_pin_list
*entry
;
386 struct irq_cfg
*cfg
= irq_cfg(irq
);
388 spin_lock_irqsave(&ioapic_lock
, flags
);
389 entry
= cfg
->irq_2_pin
;
397 reg
= io_apic_read(entry
->apic
, 0x10 + pin
*2);
398 /* Is the remote IRR bit set? */
399 if (reg
& IO_APIC_REDIR_REMOTE_IRR
) {
400 spin_unlock_irqrestore(&ioapic_lock
, flags
);
407 spin_unlock_irqrestore(&ioapic_lock
, flags
);
413 * Synchronize the IO-APIC and the CPU by doing
414 * a dummy read from the IO-APIC
416 static inline void io_apic_sync(unsigned int apic
)
418 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
419 readl(&io_apic
->data
);
422 #define __DO_ACTION(R, ACTION, FINAL) \
426 struct irq_cfg *cfg; \
427 struct irq_pin_list *entry; \
429 cfg = irq_cfg(irq); \
430 entry = cfg->irq_2_pin; \
436 reg = io_apic_read(entry->apic, 0x10 + R + pin*2); \
438 io_apic_modify(entry->apic, reg); \
442 entry = entry->next; \
447 struct { u32 w1
, w2
; };
448 struct IO_APIC_route_entry entry
;
451 static struct IO_APIC_route_entry
ioapic_read_entry(int apic
, int pin
)
453 union entry_union eu
;
455 spin_lock_irqsave(&ioapic_lock
, flags
);
456 eu
.w1
= io_apic_read(apic
, 0x10 + 2 * pin
);
457 eu
.w2
= io_apic_read(apic
, 0x11 + 2 * pin
);
458 spin_unlock_irqrestore(&ioapic_lock
, flags
);
463 * When we write a new IO APIC routing entry, we need to write the high
464 * word first! If the mask bit in the low word is clear, we will enable
465 * the interrupt, and we need to make sure the entry is fully populated
466 * before that happens.
469 __ioapic_write_entry(int apic
, int pin
, struct IO_APIC_route_entry e
)
471 union entry_union eu
;
473 io_apic_write(apic
, 0x11 + 2*pin
, eu
.w2
);
474 io_apic_write(apic
, 0x10 + 2*pin
, eu
.w1
);
477 static void ioapic_write_entry(int apic
, int pin
, struct IO_APIC_route_entry e
)
480 spin_lock_irqsave(&ioapic_lock
, flags
);
481 __ioapic_write_entry(apic
, pin
, e
);
482 spin_unlock_irqrestore(&ioapic_lock
, flags
);
486 * When we mask an IO APIC routing entry, we need to write the low
487 * word first, in order to set the mask bit before we change the
490 static void ioapic_mask_entry(int apic
, int pin
)
493 union entry_union eu
= { .entry
.mask
= 1 };
495 spin_lock_irqsave(&ioapic_lock
, flags
);
496 io_apic_write(apic
, 0x10 + 2*pin
, eu
.w1
);
497 io_apic_write(apic
, 0x11 + 2*pin
, eu
.w2
);
498 spin_unlock_irqrestore(&ioapic_lock
, flags
);
502 static void __target_IO_APIC_irq(unsigned int irq
, unsigned int dest
, u8 vector
)
506 struct irq_pin_list
*entry
;
509 entry
= cfg
->irq_2_pin
;
519 * With interrupt-remapping, destination information comes
520 * from interrupt-remapping table entry.
522 if (!irq_remapped(irq
))
523 io_apic_write(apic
, 0x11 + pin
*2, dest
);
524 reg
= io_apic_read(apic
, 0x10 + pin
*2);
525 reg
&= ~IO_APIC_REDIR_VECTOR_MASK
;
527 io_apic_modify(apic
, reg
);
534 static void set_ioapic_affinity_irq(unsigned int irq
, cpumask_t mask
)
536 struct irq_cfg
*cfg
= irq_cfg(irq
);
540 struct irq_desc
*desc
;
542 cpus_and(tmp
, mask
, cpu_online_map
);
546 if (assign_irq_vector(irq
, mask
))
549 cpus_and(tmp
, cfg
->domain
, mask
);
550 dest
= cpu_mask_to_apicid(tmp
);
553 * Only the high 8 bits are valid.
555 dest
= SET_APIC_LOGICAL_ID(dest
);
557 desc
= irq_to_desc(irq
);
558 spin_lock_irqsave(&ioapic_lock
, flags
);
559 __target_IO_APIC_irq(irq
, dest
, cfg
->vector
);
560 desc
->affinity
= mask
;
561 spin_unlock_irqrestore(&ioapic_lock
, flags
);
566 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
567 * shared ISA-space IRQs, so we have to support them. We are super
568 * fast in the common case, and fast for shared ISA-space IRQs.
570 int first_free_entry
;
571 static void add_pin_to_irq(unsigned int irq
, int apic
, int pin
)
574 struct irq_pin_list
*entry
;
576 /* first time to refer irq_cfg, so with new */
577 cfg
= irq_cfg_alloc(irq
);
578 entry
= cfg
->irq_2_pin
;
580 entry
= get_one_free_irq_2_pin();
581 cfg
->irq_2_pin
= entry
;
584 printk(KERN_DEBUG
" 0 add_pin_to_irq: irq %d --> apic %d pin %d\n", irq
, apic
, pin
);
588 while (entry
->next
) {
589 /* not again, please */
590 if (entry
->apic
== apic
&& entry
->pin
== pin
)
596 entry
->next
= get_one_free_irq_2_pin();
600 printk(KERN_DEBUG
" x add_pin_to_irq: irq %d --> apic %d pin %d\n", irq
, apic
, pin
);
604 * Reroute an IRQ to a different pin.
606 static void __init
replace_pin_at_irq(unsigned int irq
,
607 int oldapic
, int oldpin
,
608 int newapic
, int newpin
)
610 struct irq_cfg
*cfg
= irq_cfg(irq
);
611 struct irq_pin_list
*entry
= cfg
->irq_2_pin
;
615 if (entry
->apic
== oldapic
&& entry
->pin
== oldpin
) {
616 entry
->apic
= newapic
;
619 /* every one is different, right? */
625 /* why? call replace before add? */
627 add_pin_to_irq(irq
, newapic
, newpin
);
631 #define DO_ACTION(name,R,ACTION, FINAL) \
633 static void name##_IO_APIC_irq (unsigned int irq) \
634 __DO_ACTION(R, ACTION, FINAL)
637 DO_ACTION(__mask
, 0, |= IO_APIC_REDIR_MASKED
, io_apic_sync(entry
->apic
))
640 DO_ACTION(__unmask
, 0, &= ~IO_APIC_REDIR_MASKED
, )
642 static void mask_IO_APIC_irq (unsigned int irq
)
646 spin_lock_irqsave(&ioapic_lock
, flags
);
647 __mask_IO_APIC_irq(irq
);
648 spin_unlock_irqrestore(&ioapic_lock
, flags
);
651 static void unmask_IO_APIC_irq (unsigned int irq
)
655 spin_lock_irqsave(&ioapic_lock
, flags
);
656 __unmask_IO_APIC_irq(irq
);
657 spin_unlock_irqrestore(&ioapic_lock
, flags
);
660 static void clear_IO_APIC_pin(unsigned int apic
, unsigned int pin
)
662 struct IO_APIC_route_entry entry
;
664 /* Check delivery_mode to be sure we're not clearing an SMI pin */
665 entry
= ioapic_read_entry(apic
, pin
);
666 if (entry
.delivery_mode
== dest_SMI
)
669 * Disable it in the IO-APIC irq-routing table:
671 ioapic_mask_entry(apic
, pin
);
674 static void clear_IO_APIC (void)
678 for (apic
= 0; apic
< nr_ioapics
; apic
++)
679 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++)
680 clear_IO_APIC_pin(apic
, pin
);
684 * Saves and masks all the unmasked IO-APIC RTE's
686 int save_mask_IO_APIC_setup(void)
688 union IO_APIC_reg_01 reg_01
;
693 * The number of IO-APIC IRQ registers (== #pins):
695 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
696 spin_lock_irqsave(&ioapic_lock
, flags
);
697 reg_01
.raw
= io_apic_read(apic
, 1);
698 spin_unlock_irqrestore(&ioapic_lock
, flags
);
699 nr_ioapic_registers
[apic
] = reg_01
.bits
.entries
+1;
702 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
703 early_ioapic_entries
[apic
] =
704 kzalloc(sizeof(struct IO_APIC_route_entry
) *
705 nr_ioapic_registers
[apic
], GFP_KERNEL
);
706 if (!early_ioapic_entries
[apic
])
710 for (apic
= 0; apic
< nr_ioapics
; apic
++)
711 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
712 struct IO_APIC_route_entry entry
;
714 entry
= early_ioapic_entries
[apic
][pin
] =
715 ioapic_read_entry(apic
, pin
);
718 ioapic_write_entry(apic
, pin
, entry
);
724 void restore_IO_APIC_setup(void)
728 for (apic
= 0; apic
< nr_ioapics
; apic
++)
729 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++)
730 ioapic_write_entry(apic
, pin
,
731 early_ioapic_entries
[apic
][pin
]);
734 void reinit_intr_remapped_IO_APIC(int intr_remapping
)
737 * for now plain restore of previous settings.
738 * TBD: In the case of OS enabling interrupt-remapping,
739 * IO-APIC RTE's need to be setup to point to interrupt-remapping
740 * table entries. for now, do a plain restore, and wait for
741 * the setup_IO_APIC_irqs() to do proper initialization.
743 restore_IO_APIC_setup();
746 int skip_ioapic_setup
;
749 static int __init
parse_noapic(char *str
)
751 disable_ioapic_setup();
754 early_param("noapic", parse_noapic
);
756 /* Actually the next is obsolete, but keep it for paranoid reasons -AK */
757 static int __init
disable_timer_pin_setup(char *arg
)
759 disable_timer_pin_1
= 1;
762 __setup("disable_timer_pin_1", disable_timer_pin_setup
);
766 * Find the IRQ entry number of a certain pin.
768 static int find_irq_entry(int apic
, int pin
, int type
)
772 for (i
= 0; i
< mp_irq_entries
; i
++)
773 if (mp_irqs
[i
].mp_irqtype
== type
&&
774 (mp_irqs
[i
].mp_dstapic
== mp_ioapics
[apic
].mp_apicid
||
775 mp_irqs
[i
].mp_dstapic
== MP_APIC_ALL
) &&
776 mp_irqs
[i
].mp_dstirq
== pin
)
783 * Find the pin to which IRQ[irq] (ISA) is connected
785 static int __init
find_isa_irq_pin(int irq
, int type
)
789 for (i
= 0; i
< mp_irq_entries
; i
++) {
790 int lbus
= mp_irqs
[i
].mp_srcbus
;
792 if (test_bit(lbus
, mp_bus_not_pci
) &&
793 (mp_irqs
[i
].mp_irqtype
== type
) &&
794 (mp_irqs
[i
].mp_srcbusirq
== irq
))
796 return mp_irqs
[i
].mp_dstirq
;
801 static int __init
find_isa_irq_apic(int irq
, int type
)
805 for (i
= 0; i
< mp_irq_entries
; i
++) {
806 int lbus
= mp_irqs
[i
].mp_srcbus
;
808 if (test_bit(lbus
, mp_bus_not_pci
) &&
809 (mp_irqs
[i
].mp_irqtype
== type
) &&
810 (mp_irqs
[i
].mp_srcbusirq
== irq
))
813 if (i
< mp_irq_entries
) {
815 for(apic
= 0; apic
< nr_ioapics
; apic
++) {
816 if (mp_ioapics
[apic
].mp_apicid
== mp_irqs
[i
].mp_dstapic
)
825 * Find a specific PCI IRQ entry.
826 * Not an __init, possibly needed by modules
828 static int pin_2_irq(int idx
, int apic
, int pin
);
830 int IO_APIC_get_PCI_irq_vector(int bus
, int slot
, int pin
)
832 int apic
, i
, best_guess
= -1;
834 apic_printk(APIC_DEBUG
, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
836 if (test_bit(bus
, mp_bus_not_pci
)) {
837 apic_printk(APIC_VERBOSE
, "PCI BIOS passed nonexistent PCI bus %d!\n", bus
);
840 for (i
= 0; i
< mp_irq_entries
; i
++) {
841 int lbus
= mp_irqs
[i
].mp_srcbus
;
843 for (apic
= 0; apic
< nr_ioapics
; apic
++)
844 if (mp_ioapics
[apic
].mp_apicid
== mp_irqs
[i
].mp_dstapic
||
845 mp_irqs
[i
].mp_dstapic
== MP_APIC_ALL
)
848 if (!test_bit(lbus
, mp_bus_not_pci
) &&
849 !mp_irqs
[i
].mp_irqtype
&&
851 (slot
== ((mp_irqs
[i
].mp_srcbusirq
>> 2) & 0x1f))) {
852 int irq
= pin_2_irq(i
,apic
,mp_irqs
[i
].mp_dstirq
);
854 if (!(apic
|| IO_APIC_IRQ(irq
)))
857 if (pin
== (mp_irqs
[i
].mp_srcbusirq
& 3))
860 * Use the first all-but-pin matching entry as a
861 * best-guess fuzzy result for broken mptables.
870 /* ISA interrupts are always polarity zero edge triggered,
871 * when listed as conforming in the MP table. */
873 #define default_ISA_trigger(idx) (0)
874 #define default_ISA_polarity(idx) (0)
876 /* PCI interrupts are always polarity one level triggered,
877 * when listed as conforming in the MP table. */
879 #define default_PCI_trigger(idx) (1)
880 #define default_PCI_polarity(idx) (1)
882 static int MPBIOS_polarity(int idx
)
884 int bus
= mp_irqs
[idx
].mp_srcbus
;
888 * Determine IRQ line polarity (high active or low active):
890 switch (mp_irqs
[idx
].mp_irqflag
& 3)
892 case 0: /* conforms, ie. bus-type dependent polarity */
893 if (test_bit(bus
, mp_bus_not_pci
))
894 polarity
= default_ISA_polarity(idx
);
896 polarity
= default_PCI_polarity(idx
);
898 case 1: /* high active */
903 case 2: /* reserved */
905 printk(KERN_WARNING
"broken BIOS!!\n");
909 case 3: /* low active */
914 default: /* invalid */
916 printk(KERN_WARNING
"broken BIOS!!\n");
924 static int MPBIOS_trigger(int idx
)
926 int bus
= mp_irqs
[idx
].mp_srcbus
;
930 * Determine IRQ trigger mode (edge or level sensitive):
932 switch ((mp_irqs
[idx
].mp_irqflag
>>2) & 3)
934 case 0: /* conforms, ie. bus-type dependent */
935 if (test_bit(bus
, mp_bus_not_pci
))
936 trigger
= default_ISA_trigger(idx
);
938 trigger
= default_PCI_trigger(idx
);
945 case 2: /* reserved */
947 printk(KERN_WARNING
"broken BIOS!!\n");
956 default: /* invalid */
958 printk(KERN_WARNING
"broken BIOS!!\n");
966 static inline int irq_polarity(int idx
)
968 return MPBIOS_polarity(idx
);
971 static inline int irq_trigger(int idx
)
973 return MPBIOS_trigger(idx
);
976 static int pin_2_irq(int idx
, int apic
, int pin
)
979 int bus
= mp_irqs
[idx
].mp_srcbus
;
982 * Debugging check, we are in big trouble if this message pops up!
984 if (mp_irqs
[idx
].mp_dstirq
!= pin
)
985 printk(KERN_ERR
"broken BIOS or MPTABLE parser, ayiee!!\n");
987 if (test_bit(bus
, mp_bus_not_pci
)) {
988 irq
= mp_irqs
[idx
].mp_srcbusirq
;
991 * PCI IRQs are mapped in order
995 irq
+= nr_ioapic_registers
[i
++];
1001 void lock_vector_lock(void)
1003 /* Used to the online set of cpus does not change
1004 * during assign_irq_vector.
1006 spin_lock(&vector_lock
);
1009 void unlock_vector_lock(void)
1011 spin_unlock(&vector_lock
);
1014 static int __assign_irq_vector(int irq
, cpumask_t mask
)
1017 * NOTE! The local APIC isn't very good at handling
1018 * multiple interrupts at the same interrupt level.
1019 * As the interrupt level is determined by taking the
1020 * vector number and shifting that right by 4, we
1021 * want to spread these out a bit so that they don't
1022 * all fall in the same interrupt level.
1024 * Also, we've got to be careful not to trash gate
1025 * 0x80, because int 0x80 is hm, kind of importantish. ;)
1027 static int current_vector
= FIRST_DEVICE_VECTOR
, current_offset
= 0;
1028 unsigned int old_vector
;
1030 struct irq_cfg
*cfg
;
1034 /* Only try and allocate irqs on cpus that are present */
1035 cpus_and(mask
, mask
, cpu_online_map
);
1037 if ((cfg
->move_in_progress
) || cfg
->move_cleanup_count
)
1040 old_vector
= cfg
->vector
;
1043 cpus_and(tmp
, cfg
->domain
, mask
);
1044 if (!cpus_empty(tmp
))
1048 for_each_cpu_mask_nr(cpu
, mask
) {
1049 cpumask_t domain
, new_mask
;
1053 domain
= vector_allocation_domain(cpu
);
1054 cpus_and(new_mask
, domain
, cpu_online_map
);
1056 vector
= current_vector
;
1057 offset
= current_offset
;
1060 if (vector
>= first_system_vector
) {
1061 /* If we run out of vectors on large boxen, must share them. */
1062 offset
= (offset
+ 1) % 8;
1063 vector
= FIRST_DEVICE_VECTOR
+ offset
;
1065 if (unlikely(current_vector
== vector
))
1067 if (vector
== IA32_SYSCALL_VECTOR
)
1069 for_each_cpu_mask_nr(new_cpu
, new_mask
)
1070 if (per_cpu(vector_irq
, new_cpu
)[vector
] != -1)
1073 current_vector
= vector
;
1074 current_offset
= offset
;
1076 cfg
->move_in_progress
= 1;
1077 cfg
->old_domain
= cfg
->domain
;
1079 for_each_cpu_mask_nr(new_cpu
, new_mask
)
1080 per_cpu(vector_irq
, new_cpu
)[vector
] = irq
;
1081 cfg
->vector
= vector
;
1082 cfg
->domain
= domain
;
1088 static int assign_irq_vector(int irq
, cpumask_t mask
)
1091 unsigned long flags
;
1093 spin_lock_irqsave(&vector_lock
, flags
);
1094 err
= __assign_irq_vector(irq
, mask
);
1095 spin_unlock_irqrestore(&vector_lock
, flags
);
1099 static void __clear_irq_vector(int irq
)
1101 struct irq_cfg
*cfg
;
1106 BUG_ON(!cfg
->vector
);
1108 vector
= cfg
->vector
;
1109 cpus_and(mask
, cfg
->domain
, cpu_online_map
);
1110 for_each_cpu_mask_nr(cpu
, mask
)
1111 per_cpu(vector_irq
, cpu
)[vector
] = -1;
1114 cpus_clear(cfg
->domain
);
1117 void __setup_vector_irq(int cpu
)
1119 /* Initialize vector_irq on a new cpu */
1120 /* This function must be called with vector_lock held */
1122 struct irq_cfg
*cfg
;
1124 /* Mark the inuse vectors */
1125 for_each_irq_cfg(cfg
) {
1126 if (!cpu_isset(cpu
, cfg
->domain
))
1128 vector
= cfg
->vector
;
1130 per_cpu(vector_irq
, cpu
)[vector
] = irq
;
1132 /* Mark the free vectors */
1133 for (vector
= 0; vector
< NR_VECTORS
; ++vector
) {
1134 irq
= per_cpu(vector_irq
, cpu
)[vector
];
1139 if (!cpu_isset(cpu
, cfg
->domain
))
1140 per_cpu(vector_irq
, cpu
)[vector
] = -1;
1144 static struct irq_chip ioapic_chip
;
1145 #ifdef CONFIG_INTR_REMAP
1146 static struct irq_chip ir_ioapic_chip
;
1149 static void ioapic_register_intr(int irq
, unsigned long trigger
)
1151 struct irq_desc
*desc
;
1153 /* first time to use this irq_desc */
1155 desc
= irq_to_desc(irq
);
1157 desc
= irq_to_desc_alloc(irq
);
1160 desc
->status
|= IRQ_LEVEL
;
1162 desc
->status
&= ~IRQ_LEVEL
;
1164 #ifdef CONFIG_INTR_REMAP
1165 if (irq_remapped(irq
)) {
1166 desc
->status
|= IRQ_MOVE_PCNTXT
;
1168 set_irq_chip_and_handler_name(irq
, &ir_ioapic_chip
,
1172 set_irq_chip_and_handler_name(irq
, &ir_ioapic_chip
,
1173 handle_edge_irq
, "edge");
1178 set_irq_chip_and_handler_name(irq
, &ioapic_chip
,
1182 set_irq_chip_and_handler_name(irq
, &ioapic_chip
,
1183 handle_edge_irq
, "edge");
1186 static int setup_ioapic_entry(int apic
, int irq
,
1187 struct IO_APIC_route_entry
*entry
,
1188 unsigned int destination
, int trigger
,
1189 int polarity
, int vector
)
1192 * add it to the IO-APIC irq-routing table:
1194 memset(entry
,0,sizeof(*entry
));
1196 #ifdef CONFIG_INTR_REMAP
1197 if (intr_remapping_enabled
) {
1198 struct intel_iommu
*iommu
= map_ioapic_to_ir(apic
);
1200 struct IR_IO_APIC_route_entry
*ir_entry
=
1201 (struct IR_IO_APIC_route_entry
*) entry
;
1205 panic("No mapping iommu for ioapic %d\n", apic
);
1207 index
= alloc_irte(iommu
, irq
, 1);
1209 panic("Failed to allocate IRTE for ioapic %d\n", apic
);
1211 memset(&irte
, 0, sizeof(irte
));
1214 irte
.dst_mode
= INT_DEST_MODE
;
1215 irte
.trigger_mode
= trigger
;
1216 irte
.dlvry_mode
= INT_DELIVERY_MODE
;
1217 irte
.vector
= vector
;
1218 irte
.dest_id
= IRTE_DEST(destination
);
1220 modify_irte(irq
, &irte
);
1222 ir_entry
->index2
= (index
>> 15) & 0x1;
1224 ir_entry
->format
= 1;
1225 ir_entry
->index
= (index
& 0x7fff);
1229 entry
->delivery_mode
= INT_DELIVERY_MODE
;
1230 entry
->dest_mode
= INT_DEST_MODE
;
1231 entry
->dest
= destination
;
1234 entry
->mask
= 0; /* enable IRQ */
1235 entry
->trigger
= trigger
;
1236 entry
->polarity
= polarity
;
1237 entry
->vector
= vector
;
1239 /* Mask level triggered irqs.
1240 * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
1247 static void setup_IO_APIC_irq(int apic
, int pin
, unsigned int irq
,
1248 int trigger
, int polarity
)
1250 struct irq_cfg
*cfg
;
1251 struct IO_APIC_route_entry entry
;
1254 if (!IO_APIC_IRQ(irq
))
1260 if (assign_irq_vector(irq
, mask
))
1263 cpus_and(mask
, cfg
->domain
, mask
);
1265 apic_printk(APIC_VERBOSE
,KERN_DEBUG
1266 "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
1267 "IRQ %d Mode:%i Active:%i)\n",
1268 apic
, mp_ioapics
[apic
].mp_apicid
, pin
, cfg
->vector
,
1269 irq
, trigger
, polarity
);
1272 if (setup_ioapic_entry(mp_ioapics
[apic
].mp_apicid
, irq
, &entry
,
1273 cpu_mask_to_apicid(mask
), trigger
, polarity
,
1275 printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
1276 mp_ioapics
[apic
].mp_apicid
, pin
);
1277 __clear_irq_vector(irq
);
1281 ioapic_register_intr(irq
, trigger
);
1283 disable_8259A_irq(irq
);
1285 ioapic_write_entry(apic
, pin
, entry
);
1288 static void __init
setup_IO_APIC_irqs(void)
1290 int apic
, pin
, idx
, irq
, first_notcon
= 1;
1292 apic_printk(APIC_VERBOSE
, KERN_DEBUG
"init IO_APIC IRQs\n");
1294 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
1295 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
1297 idx
= find_irq_entry(apic
,pin
,mp_INT
);
1300 apic_printk(APIC_VERBOSE
, KERN_DEBUG
" IO-APIC (apicid-pin) %d-%d", mp_ioapics
[apic
].mp_apicid
, pin
);
1303 apic_printk(APIC_VERBOSE
, ", %d-%d", mp_ioapics
[apic
].mp_apicid
, pin
);
1306 if (!first_notcon
) {
1307 apic_printk(APIC_VERBOSE
, " not connected.\n");
1311 irq
= pin_2_irq(idx
, apic
, pin
);
1312 add_pin_to_irq(irq
, apic
, pin
);
1314 setup_IO_APIC_irq(apic
, pin
, irq
,
1315 irq_trigger(idx
), irq_polarity(idx
));
1320 apic_printk(APIC_VERBOSE
, " not connected.\n");
1324 * Set up the timer pin, possibly with the 8259A-master behind.
1326 static void __init
setup_timer_IRQ0_pin(unsigned int apic
, unsigned int pin
,
1329 struct IO_APIC_route_entry entry
;
1331 if (intr_remapping_enabled
)
1334 memset(&entry
, 0, sizeof(entry
));
1337 * We use logical delivery to get the timer IRQ
1340 entry
.dest_mode
= INT_DEST_MODE
;
1341 entry
.mask
= 1; /* mask IRQ now */
1342 entry
.dest
= cpu_mask_to_apicid(TARGET_CPUS
);
1343 entry
.delivery_mode
= INT_DELIVERY_MODE
;
1346 entry
.vector
= vector
;
1349 * The timer IRQ doesn't have to know that behind the
1350 * scene we may have a 8259A-master in AEOI mode ...
1352 set_irq_chip_and_handler_name(0, &ioapic_chip
, handle_edge_irq
, "edge");
1355 * Add it to the IO-APIC irq-routing table:
1357 ioapic_write_entry(apic
, pin
, entry
);
1361 __apicdebuginit(void) print_IO_APIC(void)
1364 union IO_APIC_reg_00 reg_00
;
1365 union IO_APIC_reg_01 reg_01
;
1366 union IO_APIC_reg_02 reg_02
;
1367 unsigned long flags
;
1368 struct irq_cfg
*cfg
;
1370 if (apic_verbosity
== APIC_QUIET
)
1373 printk(KERN_DEBUG
"number of MP IRQ sources: %d.\n", mp_irq_entries
);
1374 for (i
= 0; i
< nr_ioapics
; i
++)
1375 printk(KERN_DEBUG
"number of IO-APIC #%d registers: %d.\n",
1376 mp_ioapics
[i
].mp_apicid
, nr_ioapic_registers
[i
]);
1379 * We are a bit conservative about what we expect. We have to
1380 * know about every hardware change ASAP.
1382 printk(KERN_INFO
"testing the IO APIC.......................\n");
1384 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
1386 spin_lock_irqsave(&ioapic_lock
, flags
);
1387 reg_00
.raw
= io_apic_read(apic
, 0);
1388 reg_01
.raw
= io_apic_read(apic
, 1);
1389 if (reg_01
.bits
.version
>= 0x10)
1390 reg_02
.raw
= io_apic_read(apic
, 2);
1391 spin_unlock_irqrestore(&ioapic_lock
, flags
);
1394 printk(KERN_DEBUG
"IO APIC #%d......\n", mp_ioapics
[apic
].mp_apicid
);
1395 printk(KERN_DEBUG
".... register #00: %08X\n", reg_00
.raw
);
1396 printk(KERN_DEBUG
"....... : physical APIC id: %02X\n", reg_00
.bits
.ID
);
1397 printk(KERN_DEBUG
"....... : Delivery Type: %X\n", reg_00
.bits
.delivery_type
);
1398 printk(KERN_DEBUG
"....... : LTS : %X\n", reg_00
.bits
.LTS
);
1400 printk(KERN_DEBUG
".... register #01: %08X\n", *(int *)®_01
);
1401 printk(KERN_DEBUG
"....... : max redirection entries: %04X\n", reg_01
.bits
.entries
);
1403 printk(KERN_DEBUG
"....... : PRQ implemented: %X\n", reg_01
.bits
.PRQ
);
1404 printk(KERN_DEBUG
"....... : IO APIC version: %04X\n", reg_01
.bits
.version
);
1406 if (reg_01
.bits
.version
>= 0x10) {
1407 printk(KERN_DEBUG
".... register #02: %08X\n", reg_02
.raw
);
1408 printk(KERN_DEBUG
"....... : arbitration: %02X\n", reg_02
.bits
.arbitration
);
1411 printk(KERN_DEBUG
".... IRQ redirection table:\n");
1413 printk(KERN_DEBUG
" NR Dst Mask Trig IRR Pol"
1414 " Stat Dmod Deli Vect: \n");
1416 for (i
= 0; i
<= reg_01
.bits
.entries
; i
++) {
1417 struct IO_APIC_route_entry entry
;
1419 entry
= ioapic_read_entry(apic
, i
);
1421 printk(KERN_DEBUG
" %02x %03X ",
1426 printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
1431 entry
.delivery_status
,
1433 entry
.delivery_mode
,
1438 printk(KERN_DEBUG
"IRQ to pin mappings:\n");
1439 for_each_irq_cfg(cfg
) {
1440 struct irq_pin_list
*entry
= cfg
->irq_2_pin
;
1443 printk(KERN_DEBUG
"IRQ%d ", cfg
->irq
);
1445 printk("-> %d:%d", entry
->apic
, entry
->pin
);
1448 entry
= entry
->next
;
1453 printk(KERN_INFO
".................................... done.\n");
1458 __apicdebuginit(void) print_APIC_bitfield(int base
)
1463 if (apic_verbosity
== APIC_QUIET
)
1466 printk(KERN_DEBUG
"0123456789abcdef0123456789abcdef\n" KERN_DEBUG
);
1467 for (i
= 0; i
< 8; i
++) {
1468 v
= apic_read(base
+ i
*0x10);
1469 for (j
= 0; j
< 32; j
++) {
1479 __apicdebuginit(void) print_local_APIC(void *dummy
)
1481 unsigned int v
, ver
, maxlvt
;
1484 if (apic_verbosity
== APIC_QUIET
)
1487 printk("\n" KERN_DEBUG
"printing local APIC contents on CPU#%d/%d:\n",
1488 smp_processor_id(), hard_smp_processor_id());
1489 v
= apic_read(APIC_ID
);
1490 printk(KERN_INFO
"... APIC ID: %08x (%01x)\n", v
, read_apic_id());
1491 v
= apic_read(APIC_LVR
);
1492 printk(KERN_INFO
"... APIC VERSION: %08x\n", v
);
1493 ver
= GET_APIC_VERSION(v
);
1494 maxlvt
= lapic_get_maxlvt();
1496 v
= apic_read(APIC_TASKPRI
);
1497 printk(KERN_DEBUG
"... APIC TASKPRI: %08x (%02x)\n", v
, v
& APIC_TPRI_MASK
);
1499 v
= apic_read(APIC_ARBPRI
);
1500 printk(KERN_DEBUG
"... APIC ARBPRI: %08x (%02x)\n", v
,
1501 v
& APIC_ARBPRI_MASK
);
1502 v
= apic_read(APIC_PROCPRI
);
1503 printk(KERN_DEBUG
"... APIC PROCPRI: %08x\n", v
);
1505 v
= apic_read(APIC_EOI
);
1506 printk(KERN_DEBUG
"... APIC EOI: %08x\n", v
);
1507 v
= apic_read(APIC_RRR
);
1508 printk(KERN_DEBUG
"... APIC RRR: %08x\n", v
);
1509 v
= apic_read(APIC_LDR
);
1510 printk(KERN_DEBUG
"... APIC LDR: %08x\n", v
);
1511 v
= apic_read(APIC_DFR
);
1512 printk(KERN_DEBUG
"... APIC DFR: %08x\n", v
);
1513 v
= apic_read(APIC_SPIV
);
1514 printk(KERN_DEBUG
"... APIC SPIV: %08x\n", v
);
1516 printk(KERN_DEBUG
"... APIC ISR field:\n");
1517 print_APIC_bitfield(APIC_ISR
);
1518 printk(KERN_DEBUG
"... APIC TMR field:\n");
1519 print_APIC_bitfield(APIC_TMR
);
1520 printk(KERN_DEBUG
"... APIC IRR field:\n");
1521 print_APIC_bitfield(APIC_IRR
);
1523 v
= apic_read(APIC_ESR
);
1524 printk(KERN_DEBUG
"... APIC ESR: %08x\n", v
);
1526 icr
= apic_icr_read();
1527 printk(KERN_DEBUG
"... APIC ICR: %08x\n", (u32
)icr
);
1528 printk(KERN_DEBUG
"... APIC ICR2: %08x\n", (u32
)(icr
>> 32));
1530 v
= apic_read(APIC_LVTT
);
1531 printk(KERN_DEBUG
"... APIC LVTT: %08x\n", v
);
1533 if (maxlvt
> 3) { /* PC is LVT#4. */
1534 v
= apic_read(APIC_LVTPC
);
1535 printk(KERN_DEBUG
"... APIC LVTPC: %08x\n", v
);
1537 v
= apic_read(APIC_LVT0
);
1538 printk(KERN_DEBUG
"... APIC LVT0: %08x\n", v
);
1539 v
= apic_read(APIC_LVT1
);
1540 printk(KERN_DEBUG
"... APIC LVT1: %08x\n", v
);
1542 if (maxlvt
> 2) { /* ERR is LVT#3. */
1543 v
= apic_read(APIC_LVTERR
);
1544 printk(KERN_DEBUG
"... APIC LVTERR: %08x\n", v
);
1547 v
= apic_read(APIC_TMICT
);
1548 printk(KERN_DEBUG
"... APIC TMICT: %08x\n", v
);
1549 v
= apic_read(APIC_TMCCT
);
1550 printk(KERN_DEBUG
"... APIC TMCCT: %08x\n", v
);
1551 v
= apic_read(APIC_TDCR
);
1552 printk(KERN_DEBUG
"... APIC TDCR: %08x\n", v
);
1556 __apicdebuginit(void) print_all_local_APICs(void)
1558 on_each_cpu(print_local_APIC
, NULL
, 1);
1561 __apicdebuginit(void) print_PIC(void)
1564 unsigned long flags
;
1566 if (apic_verbosity
== APIC_QUIET
)
1569 printk(KERN_DEBUG
"\nprinting PIC contents\n");
1571 spin_lock_irqsave(&i8259A_lock
, flags
);
1573 v
= inb(0xa1) << 8 | inb(0x21);
1574 printk(KERN_DEBUG
"... PIC IMR: %04x\n", v
);
1576 v
= inb(0xa0) << 8 | inb(0x20);
1577 printk(KERN_DEBUG
"... PIC IRR: %04x\n", v
);
1581 v
= inb(0xa0) << 8 | inb(0x20);
1585 spin_unlock_irqrestore(&i8259A_lock
, flags
);
1587 printk(KERN_DEBUG
"... PIC ISR: %04x\n", v
);
1589 v
= inb(0x4d1) << 8 | inb(0x4d0);
1590 printk(KERN_DEBUG
"... PIC ELCR: %04x\n", v
);
1593 __apicdebuginit(int) print_all_ICs(void)
1596 print_all_local_APICs();
1602 fs_initcall(print_all_ICs
);
1605 void __init
enable_IO_APIC(void)
1607 union IO_APIC_reg_01 reg_01
;
1608 int i8259_apic
, i8259_pin
;
1610 unsigned long flags
;
1613 * The number of IO-APIC IRQ registers (== #pins):
1615 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
1616 spin_lock_irqsave(&ioapic_lock
, flags
);
1617 reg_01
.raw
= io_apic_read(apic
, 1);
1618 spin_unlock_irqrestore(&ioapic_lock
, flags
);
1619 nr_ioapic_registers
[apic
] = reg_01
.bits
.entries
+1;
1621 for(apic
= 0; apic
< nr_ioapics
; apic
++) {
1623 /* See if any of the pins is in ExtINT mode */
1624 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
1625 struct IO_APIC_route_entry entry
;
1626 entry
= ioapic_read_entry(apic
, pin
);
1628 /* If the interrupt line is enabled and in ExtInt mode
1629 * I have found the pin where the i8259 is connected.
1631 if ((entry
.mask
== 0) && (entry
.delivery_mode
== dest_ExtINT
)) {
1632 ioapic_i8259
.apic
= apic
;
1633 ioapic_i8259
.pin
= pin
;
1639 /* Look to see what if the MP table has reported the ExtINT */
1640 i8259_pin
= find_isa_irq_pin(0, mp_ExtINT
);
1641 i8259_apic
= find_isa_irq_apic(0, mp_ExtINT
);
1642 /* Trust the MP table if nothing is setup in the hardware */
1643 if ((ioapic_i8259
.pin
== -1) && (i8259_pin
>= 0)) {
1644 printk(KERN_WARNING
"ExtINT not setup in hardware but reported by MP table\n");
1645 ioapic_i8259
.pin
= i8259_pin
;
1646 ioapic_i8259
.apic
= i8259_apic
;
1648 /* Complain if the MP table and the hardware disagree */
1649 if (((ioapic_i8259
.apic
!= i8259_apic
) || (ioapic_i8259
.pin
!= i8259_pin
)) &&
1650 (i8259_pin
>= 0) && (ioapic_i8259
.pin
>= 0))
1652 printk(KERN_WARNING
"ExtINT in hardware and MP table differ\n");
1656 * Do not trust the IO-APIC being empty at bootup
1662 * Not an __init, needed by the reboot code
1664 void disable_IO_APIC(void)
1667 * Clear the IO-APIC before rebooting:
1672 * If the i8259 is routed through an IOAPIC
1673 * Put that IOAPIC in virtual wire mode
1674 * so legacy interrupts can be delivered.
1676 if (ioapic_i8259
.pin
!= -1) {
1677 struct IO_APIC_route_entry entry
;
1679 memset(&entry
, 0, sizeof(entry
));
1680 entry
.mask
= 0; /* Enabled */
1681 entry
.trigger
= 0; /* Edge */
1683 entry
.polarity
= 0; /* High */
1684 entry
.delivery_status
= 0;
1685 entry
.dest_mode
= 0; /* Physical */
1686 entry
.delivery_mode
= dest_ExtINT
; /* ExtInt */
1688 entry
.dest
= read_apic_id();
1691 * Add it to the IO-APIC irq-routing table:
1693 ioapic_write_entry(ioapic_i8259
.apic
, ioapic_i8259
.pin
, entry
);
1696 disconnect_bsp_APIC(ioapic_i8259
.pin
!= -1);
1700 * There is a nasty bug in some older SMP boards, their mptable lies
1701 * about the timer IRQ. We do the following to work around the situation:
1703 * - timer IRQ defaults to IO-APIC IRQ
1704 * - if this function detects that timer IRQs are defunct, then we fall
1705 * back to ISA timer IRQs
1707 static int __init
timer_irq_works(void)
1709 unsigned long t1
= jiffies
;
1710 unsigned long flags
;
1712 local_save_flags(flags
);
1714 /* Let ten ticks pass... */
1715 mdelay((10 * 1000) / HZ
);
1716 local_irq_restore(flags
);
1719 * Expect a few ticks at least, to be sure some possible
1720 * glue logic does not lock up after one or two first
1721 * ticks in a non-ExtINT mode. Also the local APIC
1722 * might have cached one ExtINT interrupt. Finally, at
1723 * least one tick may be lost due to delays.
1727 if (time_after(jiffies
, t1
+ 4))
1733 * In the SMP+IOAPIC case it might happen that there are an unspecified
1734 * number of pending IRQ events unhandled. These cases are very rare,
1735 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
1736 * better to do it this way as thus we do not have to be aware of
1737 * 'pending' interrupts in the IRQ path, except at this point.
1740 * Edge triggered needs to resend any interrupt
1741 * that was delayed but this is now handled in the device
1746 * Starting up a edge-triggered IO-APIC interrupt is
1747 * nasty - we need to make sure that we get the edge.
1748 * If it is already asserted for some reason, we need
1749 * return 1 to indicate that is was pending.
1751 * This is not complete - we should be able to fake
1752 * an edge even if it isn't on the 8259A...
1755 static unsigned int startup_ioapic_irq(unsigned int irq
)
1757 int was_pending
= 0;
1758 unsigned long flags
;
1760 spin_lock_irqsave(&ioapic_lock
, flags
);
1762 disable_8259A_irq(irq
);
1763 if (i8259A_irq_pending(irq
))
1766 __unmask_IO_APIC_irq(irq
);
1767 spin_unlock_irqrestore(&ioapic_lock
, flags
);
1772 static int ioapic_retrigger_irq(unsigned int irq
)
1774 struct irq_cfg
*cfg
= irq_cfg(irq
);
1775 unsigned long flags
;
1777 spin_lock_irqsave(&vector_lock
, flags
);
1778 send_IPI_mask(cpumask_of_cpu(first_cpu(cfg
->domain
)), cfg
->vector
);
1779 spin_unlock_irqrestore(&vector_lock
, flags
);
1785 * Level and edge triggered IO-APIC interrupts need different handling,
1786 * so we use two separate IRQ descriptors. Edge triggered IRQs can be
1787 * handled with the level-triggered descriptor, but that one has slightly
1788 * more overhead. Level-triggered interrupts cannot be handled with the
1789 * edge-triggered handler, without risking IRQ storms and other ugly
1795 #ifdef CONFIG_INTR_REMAP
1796 static void ir_irq_migration(struct work_struct
*work
);
1798 static DECLARE_DELAYED_WORK(ir_migration_work
, ir_irq_migration
);
1801 * Migrate the IO-APIC irq in the presence of intr-remapping.
1803 * For edge triggered, irq migration is a simple atomic update(of vector
1804 * and cpu destination) of IRTE and flush the hardware cache.
1806 * For level triggered, we need to modify the io-apic RTE aswell with the update
1807 * vector information, along with modifying IRTE with vector and destination.
1808 * So irq migration for level triggered is little bit more complex compared to
1809 * edge triggered migration. But the good news is, we use the same algorithm
1810 * for level triggered migration as we have today, only difference being,
1811 * we now initiate the irq migration from process context instead of the
1812 * interrupt context.
1814 * In future, when we do a directed EOI (combined with cpu EOI broadcast
1815 * suppression) to the IO-APIC, level triggered irq migration will also be
1816 * as simple as edge triggered migration and we can do the irq migration
1817 * with a simple atomic update to IO-APIC RTE.
1819 static void migrate_ioapic_irq(int irq
, cpumask_t mask
)
1821 struct irq_cfg
*cfg
;
1822 struct irq_desc
*desc
;
1823 cpumask_t tmp
, cleanup_mask
;
1825 int modify_ioapic_rte
;
1827 unsigned long flags
;
1829 cpus_and(tmp
, mask
, cpu_online_map
);
1830 if (cpus_empty(tmp
))
1833 if (get_irte(irq
, &irte
))
1836 if (assign_irq_vector(irq
, mask
))
1840 cpus_and(tmp
, cfg
->domain
, mask
);
1841 dest
= cpu_mask_to_apicid(tmp
);
1843 desc
= irq_to_desc(irq
);
1844 modify_ioapic_rte
= desc
->status
& IRQ_LEVEL
;
1845 if (modify_ioapic_rte
) {
1846 spin_lock_irqsave(&ioapic_lock
, flags
);
1847 __target_IO_APIC_irq(irq
, dest
, cfg
->vector
);
1848 spin_unlock_irqrestore(&ioapic_lock
, flags
);
1851 irte
.vector
= cfg
->vector
;
1852 irte
.dest_id
= IRTE_DEST(dest
);
1855 * Modified the IRTE and flushes the Interrupt entry cache.
1857 modify_irte(irq
, &irte
);
1859 if (cfg
->move_in_progress
) {
1860 cpus_and(cleanup_mask
, cfg
->old_domain
, cpu_online_map
);
1861 cfg
->move_cleanup_count
= cpus_weight(cleanup_mask
);
1862 send_IPI_mask(cleanup_mask
, IRQ_MOVE_CLEANUP_VECTOR
);
1863 cfg
->move_in_progress
= 0;
1866 desc
->affinity
= mask
;
1869 static int migrate_irq_remapped_level(int irq
)
1872 struct irq_desc
*desc
= irq_to_desc(irq
);
1874 mask_IO_APIC_irq(irq
);
1876 if (io_apic_level_ack_pending(irq
)) {
1878 * Interrupt in progress. Migrating irq now will change the
1879 * vector information in the IO-APIC RTE and that will confuse
1880 * the EOI broadcast performed by cpu.
1881 * So, delay the irq migration to the next instance.
1883 schedule_delayed_work(&ir_migration_work
, 1);
1887 /* everthing is clear. we have right of way */
1888 migrate_ioapic_irq(irq
, desc
->pending_mask
);
1891 desc
->status
&= ~IRQ_MOVE_PENDING
;
1892 cpus_clear(desc
->pending_mask
);
1895 unmask_IO_APIC_irq(irq
);
1899 static void ir_irq_migration(struct work_struct
*work
)
1902 struct irq_desc
*desc
;
1904 for_each_irq_desc(irq
, desc
) {
1905 if (desc
->status
& IRQ_MOVE_PENDING
) {
1906 unsigned long flags
;
1908 spin_lock_irqsave(&desc
->lock
, flags
);
1909 if (!desc
->chip
->set_affinity
||
1910 !(desc
->status
& IRQ_MOVE_PENDING
)) {
1911 desc
->status
&= ~IRQ_MOVE_PENDING
;
1912 spin_unlock_irqrestore(&desc
->lock
, flags
);
1916 desc
->chip
->set_affinity(irq
, desc
->pending_mask
);
1917 spin_unlock_irqrestore(&desc
->lock
, flags
);
1923 * Migrates the IRQ destination in the process context.
1925 static void set_ir_ioapic_affinity_irq(unsigned int irq
, cpumask_t mask
)
1927 struct irq_desc
*desc
= irq_to_desc(irq
);
1929 if (desc
->status
& IRQ_LEVEL
) {
1930 desc
->status
|= IRQ_MOVE_PENDING
;
1931 desc
->pending_mask
= mask
;
1932 migrate_irq_remapped_level(irq
);
1936 migrate_ioapic_irq(irq
, mask
);
1940 asmlinkage
void smp_irq_move_cleanup_interrupt(void)
1942 unsigned vector
, me
;
1947 me
= smp_processor_id();
1948 for (vector
= FIRST_EXTERNAL_VECTOR
; vector
< NR_VECTORS
; vector
++) {
1950 struct irq_desc
*desc
;
1951 struct irq_cfg
*cfg
;
1952 irq
= __get_cpu_var(vector_irq
)[vector
];
1954 desc
= irq_to_desc(irq
);
1959 spin_lock(&desc
->lock
);
1960 if (!cfg
->move_cleanup_count
)
1963 if ((vector
== cfg
->vector
) && cpu_isset(me
, cfg
->domain
))
1966 __get_cpu_var(vector_irq
)[vector
] = -1;
1967 cfg
->move_cleanup_count
--;
1969 spin_unlock(&desc
->lock
);
1975 static void irq_complete_move(unsigned int irq
)
1977 struct irq_cfg
*cfg
= irq_cfg(irq
);
1978 unsigned vector
, me
;
1980 if (likely(!cfg
->move_in_progress
))
1983 vector
= ~get_irq_regs()->orig_ax
;
1984 me
= smp_processor_id();
1985 if ((vector
== cfg
->vector
) && cpu_isset(me
, cfg
->domain
)) {
1986 cpumask_t cleanup_mask
;
1988 cpus_and(cleanup_mask
, cfg
->old_domain
, cpu_online_map
);
1989 cfg
->move_cleanup_count
= cpus_weight(cleanup_mask
);
1990 send_IPI_mask(cleanup_mask
, IRQ_MOVE_CLEANUP_VECTOR
);
1991 cfg
->move_in_progress
= 0;
1995 static inline void irq_complete_move(unsigned int irq
) {}
1997 #ifdef CONFIG_INTR_REMAP
1998 static void ack_x2apic_level(unsigned int irq
)
2003 static void ack_x2apic_edge(unsigned int irq
)
2009 static void ack_apic_edge(unsigned int irq
)
2011 irq_complete_move(irq
);
2012 move_native_irq(irq
);
2016 static void ack_apic_level(unsigned int irq
)
2018 int do_unmask_irq
= 0;
2020 irq_complete_move(irq
);
2021 #ifdef CONFIG_GENERIC_PENDING_IRQ
2022 /* If we are moving the irq we need to mask it */
2023 if (unlikely(irq_to_desc(irq
)->status
& IRQ_MOVE_PENDING
)) {
2025 mask_IO_APIC_irq(irq
);
2030 * We must acknowledge the irq before we move it or the acknowledge will
2031 * not propagate properly.
2035 /* Now we can move and renable the irq */
2036 if (unlikely(do_unmask_irq
)) {
2037 /* Only migrate the irq if the ack has been received.
2039 * On rare occasions the broadcast level triggered ack gets
2040 * delayed going to ioapics, and if we reprogram the
2041 * vector while Remote IRR is still set the irq will never
2044 * To prevent this scenario we read the Remote IRR bit
2045 * of the ioapic. This has two effects.
2046 * - On any sane system the read of the ioapic will
2047 * flush writes (and acks) going to the ioapic from
2049 * - We get to see if the ACK has actually been delivered.
2051 * Based on failed experiments of reprogramming the
2052 * ioapic entry from outside of irq context starting
2053 * with masking the ioapic entry and then polling until
2054 * Remote IRR was clear before reprogramming the
2055 * ioapic I don't trust the Remote IRR bit to be
2056 * completey accurate.
2058 * However there appears to be no other way to plug
2059 * this race, so if the Remote IRR bit is not
2060 * accurate and is causing problems then it is a hardware bug
2061 * and you can go talk to the chipset vendor about it.
2063 if (!io_apic_level_ack_pending(irq
))
2064 move_masked_irq(irq
);
2065 unmask_IO_APIC_irq(irq
);
2069 static struct irq_chip ioapic_chip __read_mostly
= {
2071 .startup
= startup_ioapic_irq
,
2072 .mask
= mask_IO_APIC_irq
,
2073 .unmask
= unmask_IO_APIC_irq
,
2074 .ack
= ack_apic_edge
,
2075 .eoi
= ack_apic_level
,
2077 .set_affinity
= set_ioapic_affinity_irq
,
2079 .retrigger
= ioapic_retrigger_irq
,
2082 #ifdef CONFIG_INTR_REMAP
2083 static struct irq_chip ir_ioapic_chip __read_mostly
= {
2084 .name
= "IR-IO-APIC",
2085 .startup
= startup_ioapic_irq
,
2086 .mask
= mask_IO_APIC_irq
,
2087 .unmask
= unmask_IO_APIC_irq
,
2088 .ack
= ack_x2apic_edge
,
2089 .eoi
= ack_x2apic_level
,
2091 .set_affinity
= set_ir_ioapic_affinity_irq
,
2093 .retrigger
= ioapic_retrigger_irq
,
2097 static inline void init_IO_APIC_traps(void)
2100 struct irq_desc
*desc
;
2101 struct irq_cfg
*cfg
;
2104 * NOTE! The local APIC isn't very good at handling
2105 * multiple interrupts at the same interrupt level.
2106 * As the interrupt level is determined by taking the
2107 * vector number and shifting that right by 4, we
2108 * want to spread these out a bit so that they don't
2109 * all fall in the same interrupt level.
2111 * Also, we've got to be careful not to trash gate
2112 * 0x80, because int 0x80 is hm, kind of importantish. ;)
2114 for_each_irq_cfg(cfg
) {
2116 if (IO_APIC_IRQ(irq
) && !cfg
->vector
) {
2118 * Hmm.. We don't have an entry for this,
2119 * so default to an old-fashioned 8259
2120 * interrupt if we can..
2123 make_8259A_irq(irq
);
2125 desc
= irq_to_desc(irq
);
2126 /* Strange. Oh, well.. */
2127 desc
->chip
= &no_irq_chip
;
2133 static void unmask_lapic_irq(unsigned int irq
)
2137 v
= apic_read(APIC_LVT0
);
2138 apic_write(APIC_LVT0
, v
& ~APIC_LVT_MASKED
);
2141 static void mask_lapic_irq(unsigned int irq
)
2145 v
= apic_read(APIC_LVT0
);
2146 apic_write(APIC_LVT0
, v
| APIC_LVT_MASKED
);
2149 static void ack_lapic_irq (unsigned int irq
)
2154 static struct irq_chip lapic_chip __read_mostly
= {
2155 .name
= "local-APIC",
2156 .mask
= mask_lapic_irq
,
2157 .unmask
= unmask_lapic_irq
,
2158 .ack
= ack_lapic_irq
,
2161 static void lapic_register_intr(int irq
)
2163 struct irq_desc
*desc
;
2165 desc
= irq_to_desc(irq
);
2166 desc
->status
&= ~IRQ_LEVEL
;
2167 set_irq_chip_and_handler_name(irq
, &lapic_chip
, handle_edge_irq
,
2171 static void __init
setup_nmi(void)
2174 * Dirty trick to enable the NMI watchdog ...
2175 * We put the 8259A master into AEOI mode and
2176 * unmask on all local APICs LVT0 as NMI.
2178 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
2179 * is from Maciej W. Rozycki - so we do not have to EOI from
2180 * the NMI handler or the timer interrupt.
2182 printk(KERN_INFO
"activating NMI Watchdog ...");
2184 enable_NMI_through_LVT0();
2190 * This looks a bit hackish but it's about the only one way of sending
2191 * a few INTA cycles to 8259As and any associated glue logic. ICR does
2192 * not support the ExtINT mode, unfortunately. We need to send these
2193 * cycles as some i82489DX-based boards have glue logic that keeps the
2194 * 8259A interrupt line asserted until INTA. --macro
2196 static inline void __init
unlock_ExtINT_logic(void)
2199 struct IO_APIC_route_entry entry0
, entry1
;
2200 unsigned char save_control
, save_freq_select
;
2202 pin
= find_isa_irq_pin(8, mp_INT
);
2203 apic
= find_isa_irq_apic(8, mp_INT
);
2207 entry0
= ioapic_read_entry(apic
, pin
);
2209 clear_IO_APIC_pin(apic
, pin
);
2211 memset(&entry1
, 0, sizeof(entry1
));
2213 entry1
.dest_mode
= 0; /* physical delivery */
2214 entry1
.mask
= 0; /* unmask IRQ now */
2215 entry1
.dest
= hard_smp_processor_id();
2216 entry1
.delivery_mode
= dest_ExtINT
;
2217 entry1
.polarity
= entry0
.polarity
;
2221 ioapic_write_entry(apic
, pin
, entry1
);
2223 save_control
= CMOS_READ(RTC_CONTROL
);
2224 save_freq_select
= CMOS_READ(RTC_FREQ_SELECT
);
2225 CMOS_WRITE((save_freq_select
& ~RTC_RATE_SELECT
) | 0x6,
2227 CMOS_WRITE(save_control
| RTC_PIE
, RTC_CONTROL
);
2232 if ((CMOS_READ(RTC_INTR_FLAGS
) & RTC_PF
) == RTC_PF
)
2236 CMOS_WRITE(save_control
, RTC_CONTROL
);
2237 CMOS_WRITE(save_freq_select
, RTC_FREQ_SELECT
);
2238 clear_IO_APIC_pin(apic
, pin
);
2240 ioapic_write_entry(apic
, pin
, entry0
);
2244 * This code may look a bit paranoid, but it's supposed to cooperate with
2245 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
2246 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
2247 * fanatically on his truly buggy board.
2249 * FIXME: really need to revamp this for modern platforms only.
2251 static inline void __init
check_timer(void)
2253 struct irq_cfg
*cfg
= irq_cfg(0);
2254 int apic1
, pin1
, apic2
, pin2
;
2255 unsigned long flags
;
2258 local_irq_save(flags
);
2261 * get/set the timer IRQ vector:
2263 disable_8259A_irq(0);
2264 assign_irq_vector(0, TARGET_CPUS
);
2267 * As IRQ0 is to be enabled in the 8259A, the virtual
2268 * wire has to be disabled in the local APIC.
2270 apic_write(APIC_LVT0
, APIC_LVT_MASKED
| APIC_DM_EXTINT
);
2273 pin1
= find_isa_irq_pin(0, mp_INT
);
2274 apic1
= find_isa_irq_apic(0, mp_INT
);
2275 pin2
= ioapic_i8259
.pin
;
2276 apic2
= ioapic_i8259
.apic
;
2278 apic_printk(APIC_QUIET
, KERN_INFO
"..TIMER: vector=0x%02X "
2279 "apic1=%d pin1=%d apic2=%d pin2=%d\n",
2280 cfg
->vector
, apic1
, pin1
, apic2
, pin2
);
2283 * Some BIOS writers are clueless and report the ExtINTA
2284 * I/O APIC input from the cascaded 8259A as the timer
2285 * interrupt input. So just in case, if only one pin
2286 * was found above, try it both directly and through the
2290 if (intr_remapping_enabled
)
2291 panic("BIOS bug: timer not connected to IO-APIC");
2295 } else if (pin2
== -1) {
2302 * Ok, does IRQ0 through the IOAPIC work?
2305 add_pin_to_irq(0, apic1
, pin1
);
2306 setup_timer_IRQ0_pin(apic1
, pin1
, cfg
->vector
);
2308 unmask_IO_APIC_irq(0);
2309 if (!no_timer_check
&& timer_irq_works()) {
2310 if (nmi_watchdog
== NMI_IO_APIC
) {
2312 enable_8259A_irq(0);
2314 if (disable_timer_pin_1
> 0)
2315 clear_IO_APIC_pin(0, pin1
);
2318 if (intr_remapping_enabled
)
2319 panic("timer doesn't work through Interrupt-remapped IO-APIC");
2320 clear_IO_APIC_pin(apic1
, pin1
);
2322 apic_printk(APIC_QUIET
, KERN_ERR
"..MP-BIOS bug: "
2323 "8254 timer not connected to IO-APIC\n");
2325 apic_printk(APIC_QUIET
, KERN_INFO
"...trying to set up timer "
2326 "(IRQ0) through the 8259A ...\n");
2327 apic_printk(APIC_QUIET
, KERN_INFO
2328 "..... (found apic %d pin %d) ...\n", apic2
, pin2
);
2330 * legacy devices should be connected to IO APIC #0
2332 replace_pin_at_irq(0, apic1
, pin1
, apic2
, pin2
);
2333 setup_timer_IRQ0_pin(apic2
, pin2
, cfg
->vector
);
2334 unmask_IO_APIC_irq(0);
2335 enable_8259A_irq(0);
2336 if (timer_irq_works()) {
2337 apic_printk(APIC_QUIET
, KERN_INFO
"....... works.\n");
2338 timer_through_8259
= 1;
2339 if (nmi_watchdog
== NMI_IO_APIC
) {
2340 disable_8259A_irq(0);
2342 enable_8259A_irq(0);
2347 * Cleanup, just in case ...
2349 disable_8259A_irq(0);
2350 clear_IO_APIC_pin(apic2
, pin2
);
2351 apic_printk(APIC_QUIET
, KERN_INFO
"....... failed.\n");
2354 if (nmi_watchdog
== NMI_IO_APIC
) {
2355 apic_printk(APIC_QUIET
, KERN_WARNING
"timer doesn't work "
2356 "through the IO-APIC - disabling NMI Watchdog!\n");
2357 nmi_watchdog
= NMI_NONE
;
2360 apic_printk(APIC_QUIET
, KERN_INFO
2361 "...trying to set up timer as Virtual Wire IRQ...\n");
2363 lapic_register_intr(0);
2364 apic_write(APIC_LVT0
, APIC_DM_FIXED
| cfg
->vector
); /* Fixed mode */
2365 enable_8259A_irq(0);
2367 if (timer_irq_works()) {
2368 apic_printk(APIC_QUIET
, KERN_INFO
"..... works.\n");
2371 disable_8259A_irq(0);
2372 apic_write(APIC_LVT0
, APIC_LVT_MASKED
| APIC_DM_FIXED
| cfg
->vector
);
2373 apic_printk(APIC_QUIET
, KERN_INFO
"..... failed.\n");
2375 apic_printk(APIC_QUIET
, KERN_INFO
2376 "...trying to set up timer as ExtINT IRQ...\n");
2380 apic_write(APIC_LVT0
, APIC_DM_EXTINT
);
2382 unlock_ExtINT_logic();
2384 if (timer_irq_works()) {
2385 apic_printk(APIC_QUIET
, KERN_INFO
"..... works.\n");
2388 apic_printk(APIC_QUIET
, KERN_INFO
"..... failed :(.\n");
2389 panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
2390 "report. Then try booting with the 'noapic' option.\n");
2392 local_irq_restore(flags
);
2395 static int __init
notimercheck(char *s
)
2400 __setup("no_timer_check", notimercheck
);
2403 * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
2404 * to devices. However there may be an I/O APIC pin available for
2405 * this interrupt regardless. The pin may be left unconnected, but
2406 * typically it will be reused as an ExtINT cascade interrupt for
2407 * the master 8259A. In the MPS case such a pin will normally be
2408 * reported as an ExtINT interrupt in the MP table. With ACPI
2409 * there is no provision for ExtINT interrupts, and in the absence
2410 * of an override it would be treated as an ordinary ISA I/O APIC
2411 * interrupt, that is edge-triggered and unmasked by default. We
2412 * used to do this, but it caused problems on some systems because
2413 * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
2414 * the same ExtINT cascade interrupt to drive the local APIC of the
2415 * bootstrap processor. Therefore we refrain from routing IRQ2 to
2416 * the I/O APIC in all cases now. No actual device should request
2417 * it anyway. --macro
2419 #define PIC_IRQS (1<<2)
2421 void __init
setup_IO_APIC(void)
2425 * calling enable_IO_APIC() is moved to setup_local_APIC for BP
2428 io_apic_irqs
= ~PIC_IRQS
;
2430 apic_printk(APIC_VERBOSE
, "ENABLING IO-APIC IRQs\n");
2433 setup_IO_APIC_irqs();
2434 init_IO_APIC_traps();
2438 struct sysfs_ioapic_data
{
2439 struct sys_device dev
;
2440 struct IO_APIC_route_entry entry
[0];
2442 static struct sysfs_ioapic_data
* mp_ioapic_data
[MAX_IO_APICS
];
2444 static int ioapic_suspend(struct sys_device
*dev
, pm_message_t state
)
2446 struct IO_APIC_route_entry
*entry
;
2447 struct sysfs_ioapic_data
*data
;
2450 data
= container_of(dev
, struct sysfs_ioapic_data
, dev
);
2451 entry
= data
->entry
;
2452 for (i
= 0; i
< nr_ioapic_registers
[dev
->id
]; i
++, entry
++ )
2453 *entry
= ioapic_read_entry(dev
->id
, i
);
2458 static int ioapic_resume(struct sys_device
*dev
)
2460 struct IO_APIC_route_entry
*entry
;
2461 struct sysfs_ioapic_data
*data
;
2462 unsigned long flags
;
2463 union IO_APIC_reg_00 reg_00
;
2466 data
= container_of(dev
, struct sysfs_ioapic_data
, dev
);
2467 entry
= data
->entry
;
2469 spin_lock_irqsave(&ioapic_lock
, flags
);
2470 reg_00
.raw
= io_apic_read(dev
->id
, 0);
2471 if (reg_00
.bits
.ID
!= mp_ioapics
[dev
->id
].mp_apicid
) {
2472 reg_00
.bits
.ID
= mp_ioapics
[dev
->id
].mp_apicid
;
2473 io_apic_write(dev
->id
, 0, reg_00
.raw
);
2475 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2476 for (i
= 0; i
< nr_ioapic_registers
[dev
->id
]; i
++)
2477 ioapic_write_entry(dev
->id
, i
, entry
[i
]);
2482 static struct sysdev_class ioapic_sysdev_class
= {
2484 .suspend
= ioapic_suspend
,
2485 .resume
= ioapic_resume
,
2488 static int __init
ioapic_init_sysfs(void)
2490 struct sys_device
* dev
;
2493 error
= sysdev_class_register(&ioapic_sysdev_class
);
2497 for (i
= 0; i
< nr_ioapics
; i
++ ) {
2498 size
= sizeof(struct sys_device
) + nr_ioapic_registers
[i
]
2499 * sizeof(struct IO_APIC_route_entry
);
2500 mp_ioapic_data
[i
] = kzalloc(size
, GFP_KERNEL
);
2501 if (!mp_ioapic_data
[i
]) {
2502 printk(KERN_ERR
"Can't suspend/resume IOAPIC %d\n", i
);
2505 dev
= &mp_ioapic_data
[i
]->dev
;
2507 dev
->cls
= &ioapic_sysdev_class
;
2508 error
= sysdev_register(dev
);
2510 kfree(mp_ioapic_data
[i
]);
2511 mp_ioapic_data
[i
] = NULL
;
2512 printk(KERN_ERR
"Can't suspend/resume IOAPIC %d\n", i
);
2520 device_initcall(ioapic_init_sysfs
);
2523 * Dynamic irq allocate and deallocation
2525 unsigned int create_irq_nr(unsigned int irq_want
)
2527 /* Allocate an unused irq */
2530 unsigned long flags
;
2531 struct irq_cfg
*cfg_new
;
2533 #ifndef CONFIG_HAVE_SPARSE_IRQ
2534 irq_want
= nr_irqs
- 1;
2538 spin_lock_irqsave(&vector_lock
, flags
);
2539 for (new = irq_want
; new > 0; new--) {
2540 if (platform_legacy_irq(new))
2542 cfg_new
= irq_cfg(new);
2543 if (cfg_new
&& cfg_new
->vector
!= 0)
2545 /* check if need to create one */
2547 cfg_new
= irq_cfg_alloc(new);
2548 if (__assign_irq_vector(new, TARGET_CPUS
) == 0)
2552 spin_unlock_irqrestore(&vector_lock
, flags
);
2555 dynamic_irq_init(irq
);
2560 int create_irq(void)
2564 irq
= create_irq_nr(nr_irqs
- 1);
2572 void destroy_irq(unsigned int irq
)
2574 unsigned long flags
;
2576 dynamic_irq_cleanup(irq
);
2578 #ifdef CONFIG_INTR_REMAP
2581 spin_lock_irqsave(&vector_lock
, flags
);
2582 __clear_irq_vector(irq
);
2583 spin_unlock_irqrestore(&vector_lock
, flags
);
2587 * MSI message composition
2589 #ifdef CONFIG_PCI_MSI
2590 static int msi_compose_msg(struct pci_dev
*pdev
, unsigned int irq
, struct msi_msg
*msg
)
2592 struct irq_cfg
*cfg
;
2598 err
= assign_irq_vector(irq
, tmp
);
2603 cpus_and(tmp
, cfg
->domain
, tmp
);
2604 dest
= cpu_mask_to_apicid(tmp
);
2606 #ifdef CONFIG_INTR_REMAP
2607 if (irq_remapped(irq
)) {
2612 ir_index
= map_irq_to_irte_handle(irq
, &sub_handle
);
2613 BUG_ON(ir_index
== -1);
2615 memset (&irte
, 0, sizeof(irte
));
2618 irte
.dst_mode
= INT_DEST_MODE
;
2619 irte
.trigger_mode
= 0; /* edge */
2620 irte
.dlvry_mode
= INT_DELIVERY_MODE
;
2621 irte
.vector
= cfg
->vector
;
2622 irte
.dest_id
= IRTE_DEST(dest
);
2624 modify_irte(irq
, &irte
);
2626 msg
->address_hi
= MSI_ADDR_BASE_HI
;
2627 msg
->data
= sub_handle
;
2628 msg
->address_lo
= MSI_ADDR_BASE_LO
| MSI_ADDR_IR_EXT_INT
|
2630 MSI_ADDR_IR_INDEX1(ir_index
) |
2631 MSI_ADDR_IR_INDEX2(ir_index
);
2635 msg
->address_hi
= MSI_ADDR_BASE_HI
;
2638 ((INT_DEST_MODE
== 0) ?
2639 MSI_ADDR_DEST_MODE_PHYSICAL
:
2640 MSI_ADDR_DEST_MODE_LOGICAL
) |
2641 ((INT_DELIVERY_MODE
!= dest_LowestPrio
) ?
2642 MSI_ADDR_REDIRECTION_CPU
:
2643 MSI_ADDR_REDIRECTION_LOWPRI
) |
2644 MSI_ADDR_DEST_ID(dest
);
2647 MSI_DATA_TRIGGER_EDGE
|
2648 MSI_DATA_LEVEL_ASSERT
|
2649 ((INT_DELIVERY_MODE
!= dest_LowestPrio
) ?
2650 MSI_DATA_DELIVERY_FIXED
:
2651 MSI_DATA_DELIVERY_LOWPRI
) |
2652 MSI_DATA_VECTOR(cfg
->vector
);
2658 static void set_msi_irq_affinity(unsigned int irq
, cpumask_t mask
)
2660 struct irq_cfg
*cfg
;
2664 struct irq_desc
*desc
;
2666 cpus_and(tmp
, mask
, cpu_online_map
);
2667 if (cpus_empty(tmp
))
2670 if (assign_irq_vector(irq
, mask
))
2674 cpus_and(tmp
, cfg
->domain
, mask
);
2675 dest
= cpu_mask_to_apicid(tmp
);
2677 read_msi_msg(irq
, &msg
);
2679 msg
.data
&= ~MSI_DATA_VECTOR_MASK
;
2680 msg
.data
|= MSI_DATA_VECTOR(cfg
->vector
);
2681 msg
.address_lo
&= ~MSI_ADDR_DEST_ID_MASK
;
2682 msg
.address_lo
|= MSI_ADDR_DEST_ID(dest
);
2684 write_msi_msg(irq
, &msg
);
2685 desc
= irq_to_desc(irq
);
2686 desc
->affinity
= mask
;
2689 #ifdef CONFIG_INTR_REMAP
2691 * Migrate the MSI irq to another cpumask. This migration is
2692 * done in the process context using interrupt-remapping hardware.
2694 static void ir_set_msi_irq_affinity(unsigned int irq
, cpumask_t mask
)
2696 struct irq_cfg
*cfg
;
2698 cpumask_t tmp
, cleanup_mask
;
2700 struct irq_desc
*desc
;
2702 cpus_and(tmp
, mask
, cpu_online_map
);
2703 if (cpus_empty(tmp
))
2706 if (get_irte(irq
, &irte
))
2709 if (assign_irq_vector(irq
, mask
))
2713 cpus_and(tmp
, cfg
->domain
, mask
);
2714 dest
= cpu_mask_to_apicid(tmp
);
2716 irte
.vector
= cfg
->vector
;
2717 irte
.dest_id
= IRTE_DEST(dest
);
2720 * atomically update the IRTE with the new destination and vector.
2722 modify_irte(irq
, &irte
);
2725 * After this point, all the interrupts will start arriving
2726 * at the new destination. So, time to cleanup the previous
2727 * vector allocation.
2729 if (cfg
->move_in_progress
) {
2730 cpus_and(cleanup_mask
, cfg
->old_domain
, cpu_online_map
);
2731 cfg
->move_cleanup_count
= cpus_weight(cleanup_mask
);
2732 send_IPI_mask(cleanup_mask
, IRQ_MOVE_CLEANUP_VECTOR
);
2733 cfg
->move_in_progress
= 0;
2736 desc
= irq_to_desc(irq
);
2737 desc
->affinity
= mask
;
2740 #endif /* CONFIG_SMP */
2743 * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
2744 * which implement the MSI or MSI-X Capability Structure.
2746 static struct irq_chip msi_chip
= {
2748 .unmask
= unmask_msi_irq
,
2749 .mask
= mask_msi_irq
,
2750 .ack
= ack_apic_edge
,
2752 .set_affinity
= set_msi_irq_affinity
,
2754 .retrigger
= ioapic_retrigger_irq
,
2757 #ifdef CONFIG_INTR_REMAP
2758 static struct irq_chip msi_ir_chip
= {
2759 .name
= "IR-PCI-MSI",
2760 .unmask
= unmask_msi_irq
,
2761 .mask
= mask_msi_irq
,
2762 .ack
= ack_x2apic_edge
,
2764 .set_affinity
= ir_set_msi_irq_affinity
,
2766 .retrigger
= ioapic_retrigger_irq
,
2770 * Map the PCI dev to the corresponding remapping hardware unit
2771 * and allocate 'nvec' consecutive interrupt-remapping table entries
2774 static int msi_alloc_irte(struct pci_dev
*dev
, int irq
, int nvec
)
2776 struct intel_iommu
*iommu
;
2779 iommu
= map_dev_to_ir(dev
);
2782 "Unable to map PCI %s to iommu\n", pci_name(dev
));
2786 index
= alloc_irte(iommu
, irq
, nvec
);
2789 "Unable to allocate %d IRTE for PCI %s\n", nvec
,
2797 static int setup_msi_irq(struct pci_dev
*dev
, struct msi_desc
*desc
, int irq
)
2802 ret
= msi_compose_msg(dev
, irq
, &msg
);
2806 set_irq_msi(irq
, desc
);
2807 write_msi_msg(irq
, &msg
);
2809 #ifdef CONFIG_INTR_REMAP
2810 if (irq_remapped(irq
)) {
2811 struct irq_desc
*desc
= irq_to_desc(irq
);
2813 * irq migration in process context
2815 desc
->status
|= IRQ_MOVE_PCNTXT
;
2816 set_irq_chip_and_handler_name(irq
, &msi_ir_chip
, handle_edge_irq
, "edge");
2819 set_irq_chip_and_handler_name(irq
, &msi_chip
, handle_edge_irq
, "edge");
2824 static unsigned int build_irq_for_pci_dev(struct pci_dev
*dev
)
2828 irq
= dev
->bus
->number
;
2836 int arch_setup_msi_irq(struct pci_dev
*dev
, struct msi_desc
*desc
)
2840 unsigned int irq_want
;
2842 irq_want
= build_irq_for_pci_dev(dev
) + 0x100;
2844 irq
= create_irq_nr(irq_want
);
2848 #ifdef CONFIG_INTR_REMAP
2849 if (!intr_remapping_enabled
)
2852 ret
= msi_alloc_irte(dev
, irq
, 1);
2857 ret
= setup_msi_irq(dev
, desc
, irq
);
2864 #ifdef CONFIG_INTR_REMAP
2871 int arch_setup_msi_irqs(struct pci_dev
*dev
, int nvec
, int type
)
2874 int ret
, sub_handle
;
2875 struct msi_desc
*desc
;
2876 unsigned int irq_want
;
2878 #ifdef CONFIG_INTR_REMAP
2879 struct intel_iommu
*iommu
= 0;
2883 irq_want
= build_irq_for_pci_dev(dev
) + 0x100;
2885 list_for_each_entry(desc
, &dev
->msi_list
, list
) {
2886 irq
= create_irq_nr(irq_want
--);
2889 #ifdef CONFIG_INTR_REMAP
2890 if (!intr_remapping_enabled
)
2895 * allocate the consecutive block of IRTE's
2898 index
= msi_alloc_irte(dev
, irq
, nvec
);
2904 iommu
= map_dev_to_ir(dev
);
2910 * setup the mapping between the irq and the IRTE
2911 * base index, the sub_handle pointing to the
2912 * appropriate interrupt remap table entry.
2914 set_irte_irq(irq
, iommu
, index
, sub_handle
);
2918 ret
= setup_msi_irq(dev
, desc
, irq
);
2930 void arch_teardown_msi_irq(unsigned int irq
)
2937 static void dmar_msi_set_affinity(unsigned int irq
, cpumask_t mask
)
2939 struct irq_cfg
*cfg
;
2943 struct irq_desc
*desc
;
2945 cpus_and(tmp
, mask
, cpu_online_map
);
2946 if (cpus_empty(tmp
))
2949 if (assign_irq_vector(irq
, mask
))
2953 cpus_and(tmp
, cfg
->domain
, mask
);
2954 dest
= cpu_mask_to_apicid(tmp
);
2956 dmar_msi_read(irq
, &msg
);
2958 msg
.data
&= ~MSI_DATA_VECTOR_MASK
;
2959 msg
.data
|= MSI_DATA_VECTOR(cfg
->vector
);
2960 msg
.address_lo
&= ~MSI_ADDR_DEST_ID_MASK
;
2961 msg
.address_lo
|= MSI_ADDR_DEST_ID(dest
);
2963 dmar_msi_write(irq
, &msg
);
2964 desc
= irq_to_desc(irq
);
2965 desc
->affinity
= mask
;
2967 #endif /* CONFIG_SMP */
2969 struct irq_chip dmar_msi_type
= {
2971 .unmask
= dmar_msi_unmask
,
2972 .mask
= dmar_msi_mask
,
2973 .ack
= ack_apic_edge
,
2975 .set_affinity
= dmar_msi_set_affinity
,
2977 .retrigger
= ioapic_retrigger_irq
,
2980 int arch_setup_dmar_msi(unsigned int irq
)
2985 ret
= msi_compose_msg(NULL
, irq
, &msg
);
2988 dmar_msi_write(irq
, &msg
);
2989 set_irq_chip_and_handler_name(irq
, &dmar_msi_type
, handle_edge_irq
,
2995 #endif /* CONFIG_PCI_MSI */
2997 * Hypertransport interrupt support
2999 #ifdef CONFIG_HT_IRQ
3003 static void target_ht_irq(unsigned int irq
, unsigned int dest
, u8 vector
)
3005 struct ht_irq_msg msg
;
3006 fetch_ht_irq_msg(irq
, &msg
);
3008 msg
.address_lo
&= ~(HT_IRQ_LOW_VECTOR_MASK
| HT_IRQ_LOW_DEST_ID_MASK
);
3009 msg
.address_hi
&= ~(HT_IRQ_HIGH_DEST_ID_MASK
);
3011 msg
.address_lo
|= HT_IRQ_LOW_VECTOR(vector
) | HT_IRQ_LOW_DEST_ID(dest
);
3012 msg
.address_hi
|= HT_IRQ_HIGH_DEST_ID(dest
);
3014 write_ht_irq_msg(irq
, &msg
);
3017 static void set_ht_irq_affinity(unsigned int irq
, cpumask_t mask
)
3019 struct irq_cfg
*cfg
;
3022 struct irq_desc
*desc
;
3024 cpus_and(tmp
, mask
, cpu_online_map
);
3025 if (cpus_empty(tmp
))
3028 if (assign_irq_vector(irq
, mask
))
3032 cpus_and(tmp
, cfg
->domain
, mask
);
3033 dest
= cpu_mask_to_apicid(tmp
);
3035 target_ht_irq(irq
, dest
, cfg
->vector
);
3036 desc
= irq_to_desc(irq
);
3037 desc
->affinity
= mask
;
3041 static struct irq_chip ht_irq_chip
= {
3043 .mask
= mask_ht_irq
,
3044 .unmask
= unmask_ht_irq
,
3045 .ack
= ack_apic_edge
,
3047 .set_affinity
= set_ht_irq_affinity
,
3049 .retrigger
= ioapic_retrigger_irq
,
3052 int arch_setup_ht_irq(unsigned int irq
, struct pci_dev
*dev
)
3054 struct irq_cfg
*cfg
;
3059 err
= assign_irq_vector(irq
, tmp
);
3061 struct ht_irq_msg msg
;
3065 cpus_and(tmp
, cfg
->domain
, tmp
);
3066 dest
= cpu_mask_to_apicid(tmp
);
3068 msg
.address_hi
= HT_IRQ_HIGH_DEST_ID(dest
);
3072 HT_IRQ_LOW_DEST_ID(dest
) |
3073 HT_IRQ_LOW_VECTOR(cfg
->vector
) |
3074 ((INT_DEST_MODE
== 0) ?
3075 HT_IRQ_LOW_DM_PHYSICAL
:
3076 HT_IRQ_LOW_DM_LOGICAL
) |
3077 HT_IRQ_LOW_RQEOI_EDGE
|
3078 ((INT_DELIVERY_MODE
!= dest_LowestPrio
) ?
3079 HT_IRQ_LOW_MT_FIXED
:
3080 HT_IRQ_LOW_MT_ARBITRATED
) |
3081 HT_IRQ_LOW_IRQ_MASKED
;
3083 write_ht_irq_msg(irq
, &msg
);
3085 set_irq_chip_and_handler_name(irq
, &ht_irq_chip
,
3086 handle_edge_irq
, "edge");
3090 #endif /* CONFIG_HT_IRQ */
3092 /* --------------------------------------------------------------------------
3093 ACPI-based IOAPIC Configuration
3094 -------------------------------------------------------------------------- */
3098 #define IO_APIC_MAX_ID 0xFE
3100 int __init
io_apic_get_redir_entries (int ioapic
)
3102 union IO_APIC_reg_01 reg_01
;
3103 unsigned long flags
;
3105 spin_lock_irqsave(&ioapic_lock
, flags
);
3106 reg_01
.raw
= io_apic_read(ioapic
, 1);
3107 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3109 return reg_01
.bits
.entries
;
3113 int io_apic_set_pci_routing (int ioapic
, int pin
, int irq
, int triggering
, int polarity
)
3115 if (!IO_APIC_IRQ(irq
)) {
3116 apic_printk(APIC_QUIET
,KERN_ERR
"IOAPIC[%d]: Invalid reference to IRQ 0\n",
3122 * IRQs < 16 are already in the irq_2_pin[] map
3125 add_pin_to_irq(irq
, ioapic
, pin
);
3127 setup_IO_APIC_irq(ioapic
, pin
, irq
, triggering
, polarity
);
3133 int acpi_get_override_irq(int bus_irq
, int *trigger
, int *polarity
)
3137 if (skip_ioapic_setup
)
3140 for (i
= 0; i
< mp_irq_entries
; i
++)
3141 if (mp_irqs
[i
].mp_irqtype
== mp_INT
&&
3142 mp_irqs
[i
].mp_srcbusirq
== bus_irq
)
3144 if (i
>= mp_irq_entries
)
3147 *trigger
= irq_trigger(i
);
3148 *polarity
= irq_polarity(i
);
3152 #endif /* CONFIG_ACPI */
3155 * This function currently is only a helper for the i386 smp boot process where
3156 * we need to reprogram the ioredtbls to cater for the cpus which have come online
3157 * so mask in all cases should simply be TARGET_CPUS
3160 void __init
setup_ioapic_dest(void)
3162 int pin
, ioapic
, irq
, irq_entry
;
3163 struct irq_cfg
*cfg
;
3165 if (skip_ioapic_setup
== 1)
3168 for (ioapic
= 0; ioapic
< nr_ioapics
; ioapic
++) {
3169 for (pin
= 0; pin
< nr_ioapic_registers
[ioapic
]; pin
++) {
3170 irq_entry
= find_irq_entry(ioapic
, pin
, mp_INT
);
3171 if (irq_entry
== -1)
3173 irq
= pin_2_irq(irq_entry
, ioapic
, pin
);
3175 /* setup_IO_APIC_irqs could fail to get vector for some device
3176 * when you have too many devices, because at that time only boot
3181 setup_IO_APIC_irq(ioapic
, pin
, irq
,
3182 irq_trigger(irq_entry
),
3183 irq_polarity(irq_entry
));
3184 #ifdef CONFIG_INTR_REMAP
3185 else if (intr_remapping_enabled
)
3186 set_ir_ioapic_affinity_irq(irq
, TARGET_CPUS
);
3189 set_ioapic_affinity_irq(irq
, TARGET_CPUS
);
3196 #define IOAPIC_RESOURCE_NAME_SIZE 11
3198 static struct resource
*ioapic_resources
;
3200 static struct resource
* __init
ioapic_setup_resources(void)
3203 struct resource
*res
;
3207 if (nr_ioapics
<= 0)
3210 n
= IOAPIC_RESOURCE_NAME_SIZE
+ sizeof(struct resource
);
3213 mem
= alloc_bootmem(n
);
3217 mem
+= sizeof(struct resource
) * nr_ioapics
;
3219 for (i
= 0; i
< nr_ioapics
; i
++) {
3221 res
[i
].flags
= IORESOURCE_MEM
| IORESOURCE_BUSY
;
3222 sprintf(mem
, "IOAPIC %u", i
);
3223 mem
+= IOAPIC_RESOURCE_NAME_SIZE
;
3227 ioapic_resources
= res
;
3232 void __init
ioapic_init_mappings(void)
3234 unsigned long ioapic_phys
, idx
= FIX_IO_APIC_BASE_0
;
3235 struct resource
*ioapic_res
;
3238 ioapic_res
= ioapic_setup_resources();
3239 for (i
= 0; i
< nr_ioapics
; i
++) {
3240 if (smp_found_config
) {
3241 ioapic_phys
= mp_ioapics
[i
].mp_apicaddr
;
3243 ioapic_phys
= (unsigned long)
3244 alloc_bootmem_pages(PAGE_SIZE
);
3245 ioapic_phys
= __pa(ioapic_phys
);
3247 set_fixmap_nocache(idx
, ioapic_phys
);
3248 apic_printk(APIC_VERBOSE
,
3249 "mapped IOAPIC to %016lx (%016lx)\n",
3250 __fix_to_virt(idx
), ioapic_phys
);
3253 if (ioapic_res
!= NULL
) {
3254 ioapic_res
->start
= ioapic_phys
;
3255 ioapic_res
->end
= ioapic_phys
+ (4 * 1024) - 1;
3261 static int __init
ioapic_insert_resources(void)
3264 struct resource
*r
= ioapic_resources
;
3268 "IO APIC resources could be not be allocated.\n");
3272 for (i
= 0; i
< nr_ioapics
; i
++) {
3273 insert_resource(&iomem_resource
, r
);
3280 /* Insert the IO APIC resources after PCI initialization has occured to handle
3281 * IO APICS that are mapped in on a BAR in PCI space. */
3282 late_initcall(ioapic_insert_resources
);