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/compiler.h>
31 #include <linux/acpi.h>
32 #include <linux/module.h>
33 #include <linux/sysdev.h>
34 #include <linux/msi.h>
35 #include <linux/htirq.h>
36 #include <linux/freezer.h>
37 #include <linux/kthread.h>
38 #include <linux/jiffies.h> /* time_after() */
40 #include <acpi/acpi_bus.h>
42 #include <linux/bootmem.h>
43 #include <linux/dmar.h>
44 #include <linux/hpet.h>
51 #include <asm/proto.h>
54 #include <asm/timer.h>
55 #include <asm/i8259.h>
57 #include <asm/msidef.h>
58 #include <asm/hypertransport.h>
59 #include <asm/setup.h>
60 #include <asm/irq_remapping.h>
62 #include <asm/uv/uv_hub.h>
63 #include <asm/uv/uv_irq.h>
65 #include <asm/genapic.h>
67 #define __apicdebuginit(type) static type __init
70 * Is the SiS APIC rmw bug present ?
71 * -1 = don't know, 0 = no, 1 = yes
73 int sis_apic_bug
= -1;
75 static DEFINE_SPINLOCK(ioapic_lock
);
76 static DEFINE_SPINLOCK(vector_lock
);
79 * # of IRQ routing registers
81 int nr_ioapic_registers
[MAX_IO_APICS
];
83 /* I/O APIC entries */
84 struct mpc_ioapic mp_ioapics
[MAX_IO_APICS
];
87 /* MP IRQ source entries */
88 struct mpc_intsrc mp_irqs
[MAX_IRQ_SOURCES
];
90 /* # of MP IRQ source entries */
93 #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
94 int mp_bus_id_to_type
[MAX_MP_BUSSES
];
97 DECLARE_BITMAP(mp_bus_not_pci
, MAX_MP_BUSSES
);
99 int skip_ioapic_setup
;
101 static int __init
parse_noapic(char *str
)
103 /* disable IO-APIC */
104 disable_ioapic_setup();
107 early_param("noapic", parse_noapic
);
112 * This is performance-critical, we want to do it O(1)
114 * the indexing order of this array favors 1:1 mappings
115 * between pins and IRQs.
118 struct irq_pin_list
{
120 struct irq_pin_list
*next
;
123 static struct irq_pin_list
*get_one_free_irq_2_pin(int cpu
)
125 struct irq_pin_list
*pin
;
128 node
= cpu_to_node(cpu
);
130 pin
= kzalloc_node(sizeof(*pin
), GFP_ATOMIC
, node
);
136 struct irq_pin_list
*irq_2_pin
;
137 cpumask_var_t domain
;
138 cpumask_var_t old_domain
;
139 unsigned move_cleanup_count
;
141 u8 move_in_progress
: 1;
142 #ifdef CONFIG_NUMA_MIGRATE_IRQ_DESC
143 u8 move_desc_pending
: 1;
147 /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
148 #ifdef CONFIG_SPARSE_IRQ
149 static struct irq_cfg irq_cfgx
[] = {
151 static struct irq_cfg irq_cfgx
[NR_IRQS
] = {
153 [0] = { .vector
= IRQ0_VECTOR
, },
154 [1] = { .vector
= IRQ1_VECTOR
, },
155 [2] = { .vector
= IRQ2_VECTOR
, },
156 [3] = { .vector
= IRQ3_VECTOR
, },
157 [4] = { .vector
= IRQ4_VECTOR
, },
158 [5] = { .vector
= IRQ5_VECTOR
, },
159 [6] = { .vector
= IRQ6_VECTOR
, },
160 [7] = { .vector
= IRQ7_VECTOR
, },
161 [8] = { .vector
= IRQ8_VECTOR
, },
162 [9] = { .vector
= IRQ9_VECTOR
, },
163 [10] = { .vector
= IRQ10_VECTOR
, },
164 [11] = { .vector
= IRQ11_VECTOR
, },
165 [12] = { .vector
= IRQ12_VECTOR
, },
166 [13] = { .vector
= IRQ13_VECTOR
, },
167 [14] = { .vector
= IRQ14_VECTOR
, },
168 [15] = { .vector
= IRQ15_VECTOR
, },
171 int __init
arch_early_irq_init(void)
174 struct irq_desc
*desc
;
179 count
= ARRAY_SIZE(irq_cfgx
);
181 for (i
= 0; i
< count
; i
++) {
182 desc
= irq_to_desc(i
);
183 desc
->chip_data
= &cfg
[i
];
184 alloc_bootmem_cpumask_var(&cfg
[i
].domain
);
185 alloc_bootmem_cpumask_var(&cfg
[i
].old_domain
);
186 if (i
< NR_IRQS_LEGACY
)
187 cpumask_setall(cfg
[i
].domain
);
193 #ifdef CONFIG_SPARSE_IRQ
194 static struct irq_cfg
*irq_cfg(unsigned int irq
)
196 struct irq_cfg
*cfg
= NULL
;
197 struct irq_desc
*desc
;
199 desc
= irq_to_desc(irq
);
201 cfg
= desc
->chip_data
;
206 static struct irq_cfg
*get_one_free_irq_cfg(int cpu
)
211 node
= cpu_to_node(cpu
);
213 cfg
= kzalloc_node(sizeof(*cfg
), GFP_ATOMIC
, node
);
215 if (!alloc_cpumask_var_node(&cfg
->domain
, GFP_ATOMIC
, node
)) {
218 } else if (!alloc_cpumask_var_node(&cfg
->old_domain
,
220 free_cpumask_var(cfg
->domain
);
224 cpumask_clear(cfg
->domain
);
225 cpumask_clear(cfg
->old_domain
);
232 int arch_init_chip_data(struct irq_desc
*desc
, int cpu
)
236 cfg
= desc
->chip_data
;
238 desc
->chip_data
= get_one_free_irq_cfg(cpu
);
239 if (!desc
->chip_data
) {
240 printk(KERN_ERR
"can not alloc irq_cfg\n");
248 #ifdef CONFIG_NUMA_MIGRATE_IRQ_DESC
251 init_copy_irq_2_pin(struct irq_cfg
*old_cfg
, struct irq_cfg
*cfg
, int cpu
)
253 struct irq_pin_list
*old_entry
, *head
, *tail
, *entry
;
255 cfg
->irq_2_pin
= NULL
;
256 old_entry
= old_cfg
->irq_2_pin
;
260 entry
= get_one_free_irq_2_pin(cpu
);
264 entry
->apic
= old_entry
->apic
;
265 entry
->pin
= old_entry
->pin
;
268 old_entry
= old_entry
->next
;
270 entry
= get_one_free_irq_2_pin(cpu
);
278 /* still use the old one */
281 entry
->apic
= old_entry
->apic
;
282 entry
->pin
= old_entry
->pin
;
285 old_entry
= old_entry
->next
;
289 cfg
->irq_2_pin
= head
;
292 static void free_irq_2_pin(struct irq_cfg
*old_cfg
, struct irq_cfg
*cfg
)
294 struct irq_pin_list
*entry
, *next
;
296 if (old_cfg
->irq_2_pin
== cfg
->irq_2_pin
)
299 entry
= old_cfg
->irq_2_pin
;
306 old_cfg
->irq_2_pin
= NULL
;
309 void arch_init_copy_chip_data(struct irq_desc
*old_desc
,
310 struct irq_desc
*desc
, int cpu
)
313 struct irq_cfg
*old_cfg
;
315 cfg
= get_one_free_irq_cfg(cpu
);
320 desc
->chip_data
= cfg
;
322 old_cfg
= old_desc
->chip_data
;
324 memcpy(cfg
, old_cfg
, sizeof(struct irq_cfg
));
326 init_copy_irq_2_pin(old_cfg
, cfg
, cpu
);
329 static void free_irq_cfg(struct irq_cfg
*old_cfg
)
334 void arch_free_chip_data(struct irq_desc
*old_desc
, struct irq_desc
*desc
)
336 struct irq_cfg
*old_cfg
, *cfg
;
338 old_cfg
= old_desc
->chip_data
;
339 cfg
= desc
->chip_data
;
345 free_irq_2_pin(old_cfg
, cfg
);
346 free_irq_cfg(old_cfg
);
347 old_desc
->chip_data
= NULL
;
352 set_extra_move_desc(struct irq_desc
*desc
, const struct cpumask
*mask
)
354 struct irq_cfg
*cfg
= desc
->chip_data
;
356 if (!cfg
->move_in_progress
) {
357 /* it means that domain is not changed */
358 if (!cpumask_intersects(desc
->affinity
, mask
))
359 cfg
->move_desc_pending
= 1;
365 static struct irq_cfg
*irq_cfg(unsigned int irq
)
367 return irq
< nr_irqs
? irq_cfgx
+ irq
: NULL
;
372 #ifndef CONFIG_NUMA_MIGRATE_IRQ_DESC
374 set_extra_move_desc(struct irq_desc
*desc
, const struct cpumask
*mask
)
381 unsigned int unused
[3];
385 static __attribute_const__
struct io_apic __iomem
*io_apic_base(int idx
)
387 return (void __iomem
*) __fix_to_virt(FIX_IO_APIC_BASE_0
+ idx
)
388 + (mp_ioapics
[idx
].apicaddr
& ~PAGE_MASK
);
391 static inline unsigned int io_apic_read(unsigned int apic
, unsigned int reg
)
393 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
394 writel(reg
, &io_apic
->index
);
395 return readl(&io_apic
->data
);
398 static inline void io_apic_write(unsigned int apic
, unsigned int reg
, unsigned int value
)
400 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
401 writel(reg
, &io_apic
->index
);
402 writel(value
, &io_apic
->data
);
406 * Re-write a value: to be used for read-modify-write
407 * cycles where the read already set up the index register.
409 * Older SiS APIC requires we rewrite the index register
411 static inline void io_apic_modify(unsigned int apic
, unsigned int reg
, unsigned int value
)
413 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
416 writel(reg
, &io_apic
->index
);
417 writel(value
, &io_apic
->data
);
420 static bool io_apic_level_ack_pending(struct irq_cfg
*cfg
)
422 struct irq_pin_list
*entry
;
425 spin_lock_irqsave(&ioapic_lock
, flags
);
426 entry
= cfg
->irq_2_pin
;
434 reg
= io_apic_read(entry
->apic
, 0x10 + pin
*2);
435 /* Is the remote IRR bit set? */
436 if (reg
& IO_APIC_REDIR_REMOTE_IRR
) {
437 spin_unlock_irqrestore(&ioapic_lock
, flags
);
444 spin_unlock_irqrestore(&ioapic_lock
, flags
);
450 struct { u32 w1
, w2
; };
451 struct IO_APIC_route_entry entry
;
454 static struct IO_APIC_route_entry
ioapic_read_entry(int apic
, int pin
)
456 union entry_union eu
;
458 spin_lock_irqsave(&ioapic_lock
, flags
);
459 eu
.w1
= io_apic_read(apic
, 0x10 + 2 * pin
);
460 eu
.w2
= io_apic_read(apic
, 0x11 + 2 * pin
);
461 spin_unlock_irqrestore(&ioapic_lock
, flags
);
466 * When we write a new IO APIC routing entry, we need to write the high
467 * word first! If the mask bit in the low word is clear, we will enable
468 * the interrupt, and we need to make sure the entry is fully populated
469 * before that happens.
472 __ioapic_write_entry(int apic
, int pin
, struct IO_APIC_route_entry e
)
474 union entry_union eu
;
476 io_apic_write(apic
, 0x11 + 2*pin
, eu
.w2
);
477 io_apic_write(apic
, 0x10 + 2*pin
, eu
.w1
);
480 static void ioapic_write_entry(int apic
, int pin
, struct IO_APIC_route_entry e
)
483 spin_lock_irqsave(&ioapic_lock
, flags
);
484 __ioapic_write_entry(apic
, pin
, e
);
485 spin_unlock_irqrestore(&ioapic_lock
, flags
);
489 * When we mask an IO APIC routing entry, we need to write the low
490 * word first, in order to set the mask bit before we change the
493 static void ioapic_mask_entry(int apic
, int pin
)
496 union entry_union eu
= { .entry
.mask
= 1 };
498 spin_lock_irqsave(&ioapic_lock
, flags
);
499 io_apic_write(apic
, 0x10 + 2*pin
, eu
.w1
);
500 io_apic_write(apic
, 0x11 + 2*pin
, eu
.w2
);
501 spin_unlock_irqrestore(&ioapic_lock
, flags
);
505 static void send_cleanup_vector(struct irq_cfg
*cfg
)
507 cpumask_var_t cleanup_mask
;
509 if (unlikely(!alloc_cpumask_var(&cleanup_mask
, GFP_ATOMIC
))) {
511 cfg
->move_cleanup_count
= 0;
512 for_each_cpu_and(i
, cfg
->old_domain
, cpu_online_mask
)
513 cfg
->move_cleanup_count
++;
514 for_each_cpu_and(i
, cfg
->old_domain
, cpu_online_mask
)
515 apic
->send_IPI_mask(cpumask_of(i
), IRQ_MOVE_CLEANUP_VECTOR
);
517 cpumask_and(cleanup_mask
, cfg
->old_domain
, cpu_online_mask
);
518 cfg
->move_cleanup_count
= cpumask_weight(cleanup_mask
);
519 apic
->send_IPI_mask(cleanup_mask
, IRQ_MOVE_CLEANUP_VECTOR
);
520 free_cpumask_var(cleanup_mask
);
522 cfg
->move_in_progress
= 0;
525 static void __target_IO_APIC_irq(unsigned int irq
, unsigned int dest
, struct irq_cfg
*cfg
)
528 struct irq_pin_list
*entry
;
529 u8 vector
= cfg
->vector
;
531 entry
= cfg
->irq_2_pin
;
540 #ifdef CONFIG_INTR_REMAP
542 * With interrupt-remapping, destination information comes
543 * from interrupt-remapping table entry.
545 if (!irq_remapped(irq
))
546 io_apic_write(apic
, 0x11 + pin
*2, dest
);
548 io_apic_write(apic
, 0x11 + pin
*2, dest
);
550 reg
= io_apic_read(apic
, 0x10 + pin
*2);
551 reg
&= ~IO_APIC_REDIR_VECTOR_MASK
;
553 io_apic_modify(apic
, 0x10 + pin
*2, reg
);
561 assign_irq_vector(int irq
, struct irq_cfg
*cfg
, const struct cpumask
*mask
);
564 * Either sets desc->affinity to a valid value, and returns
565 * ->cpu_mask_to_apicid of that, or returns BAD_APICID and
566 * leaves desc->affinity untouched.
569 set_desc_affinity(struct irq_desc
*desc
, const struct cpumask
*mask
)
574 if (!cpumask_intersects(mask
, cpu_online_mask
))
578 cfg
= desc
->chip_data
;
579 if (assign_irq_vector(irq
, cfg
, mask
))
582 cpumask_and(desc
->affinity
, cfg
->domain
, mask
);
583 set_extra_move_desc(desc
, mask
);
585 return apic
->cpu_mask_to_apicid_and(desc
->affinity
, cpu_online_mask
);
589 set_ioapic_affinity_irq_desc(struct irq_desc
*desc
, const struct cpumask
*mask
)
597 cfg
= desc
->chip_data
;
599 spin_lock_irqsave(&ioapic_lock
, flags
);
600 dest
= set_desc_affinity(desc
, mask
);
601 if (dest
!= BAD_APICID
) {
602 /* Only the high 8 bits are valid. */
603 dest
= SET_APIC_LOGICAL_ID(dest
);
604 __target_IO_APIC_irq(irq
, dest
, cfg
);
606 spin_unlock_irqrestore(&ioapic_lock
, flags
);
610 set_ioapic_affinity_irq(unsigned int irq
, const struct cpumask
*mask
)
612 struct irq_desc
*desc
;
614 desc
= irq_to_desc(irq
);
616 set_ioapic_affinity_irq_desc(desc
, mask
);
618 #endif /* CONFIG_SMP */
621 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
622 * shared ISA-space IRQs, so we have to support them. We are super
623 * fast in the common case, and fast for shared ISA-space IRQs.
625 static void add_pin_to_irq_cpu(struct irq_cfg
*cfg
, int cpu
, int apic
, int pin
)
627 struct irq_pin_list
*entry
;
629 entry
= cfg
->irq_2_pin
;
631 entry
= get_one_free_irq_2_pin(cpu
);
633 printk(KERN_ERR
"can not alloc irq_2_pin to add %d - %d\n",
637 cfg
->irq_2_pin
= entry
;
643 while (entry
->next
) {
644 /* not again, please */
645 if (entry
->apic
== apic
&& entry
->pin
== pin
)
651 entry
->next
= get_one_free_irq_2_pin(cpu
);
658 * Reroute an IRQ to a different pin.
660 static void __init
replace_pin_at_irq_cpu(struct irq_cfg
*cfg
, int cpu
,
661 int oldapic
, int oldpin
,
662 int newapic
, int newpin
)
664 struct irq_pin_list
*entry
= cfg
->irq_2_pin
;
668 if (entry
->apic
== oldapic
&& entry
->pin
== oldpin
) {
669 entry
->apic
= newapic
;
672 /* every one is different, right? */
678 /* why? call replace before add? */
680 add_pin_to_irq_cpu(cfg
, cpu
, newapic
, newpin
);
683 static inline void io_apic_modify_irq(struct irq_cfg
*cfg
,
684 int mask_and
, int mask_or
,
685 void (*final
)(struct irq_pin_list
*entry
))
688 struct irq_pin_list
*entry
;
690 for (entry
= cfg
->irq_2_pin
; entry
!= NULL
; entry
= entry
->next
) {
693 reg
= io_apic_read(entry
->apic
, 0x10 + pin
* 2);
696 io_apic_modify(entry
->apic
, 0x10 + pin
* 2, reg
);
702 static void __unmask_IO_APIC_irq(struct irq_cfg
*cfg
)
704 io_apic_modify_irq(cfg
, ~IO_APIC_REDIR_MASKED
, 0, NULL
);
708 static void io_apic_sync(struct irq_pin_list
*entry
)
711 * Synchronize the IO-APIC and the CPU by doing
712 * a dummy read from the IO-APIC
714 struct io_apic __iomem
*io_apic
;
715 io_apic
= io_apic_base(entry
->apic
);
716 readl(&io_apic
->data
);
719 static void __mask_IO_APIC_irq(struct irq_cfg
*cfg
)
721 io_apic_modify_irq(cfg
, ~0, IO_APIC_REDIR_MASKED
, &io_apic_sync
);
723 #else /* CONFIG_X86_32 */
724 static void __mask_IO_APIC_irq(struct irq_cfg
*cfg
)
726 io_apic_modify_irq(cfg
, ~0, IO_APIC_REDIR_MASKED
, NULL
);
729 static void __mask_and_edge_IO_APIC_irq(struct irq_cfg
*cfg
)
731 io_apic_modify_irq(cfg
, ~IO_APIC_REDIR_LEVEL_TRIGGER
,
732 IO_APIC_REDIR_MASKED
, NULL
);
735 static void __unmask_and_level_IO_APIC_irq(struct irq_cfg
*cfg
)
737 io_apic_modify_irq(cfg
, ~IO_APIC_REDIR_MASKED
,
738 IO_APIC_REDIR_LEVEL_TRIGGER
, NULL
);
740 #endif /* CONFIG_X86_32 */
742 static void mask_IO_APIC_irq_desc(struct irq_desc
*desc
)
744 struct irq_cfg
*cfg
= desc
->chip_data
;
749 spin_lock_irqsave(&ioapic_lock
, flags
);
750 __mask_IO_APIC_irq(cfg
);
751 spin_unlock_irqrestore(&ioapic_lock
, flags
);
754 static void unmask_IO_APIC_irq_desc(struct irq_desc
*desc
)
756 struct irq_cfg
*cfg
= desc
->chip_data
;
759 spin_lock_irqsave(&ioapic_lock
, flags
);
760 __unmask_IO_APIC_irq(cfg
);
761 spin_unlock_irqrestore(&ioapic_lock
, flags
);
764 static void mask_IO_APIC_irq(unsigned int irq
)
766 struct irq_desc
*desc
= irq_to_desc(irq
);
768 mask_IO_APIC_irq_desc(desc
);
770 static void unmask_IO_APIC_irq(unsigned int irq
)
772 struct irq_desc
*desc
= irq_to_desc(irq
);
774 unmask_IO_APIC_irq_desc(desc
);
777 static void clear_IO_APIC_pin(unsigned int apic
, unsigned int pin
)
779 struct IO_APIC_route_entry entry
;
781 /* Check delivery_mode to be sure we're not clearing an SMI pin */
782 entry
= ioapic_read_entry(apic
, pin
);
783 if (entry
.delivery_mode
== dest_SMI
)
786 * Disable it in the IO-APIC irq-routing table:
788 ioapic_mask_entry(apic
, pin
);
791 static void clear_IO_APIC (void)
795 for (apic
= 0; apic
< nr_ioapics
; apic
++)
796 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++)
797 clear_IO_APIC_pin(apic
, pin
);
802 * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
803 * specific CPU-side IRQs.
807 static int pirq_entries
[MAX_PIRQS
];
808 static int pirqs_enabled
;
810 static int __init
ioapic_pirq_setup(char *str
)
813 int ints
[MAX_PIRQS
+1];
815 get_options(str
, ARRAY_SIZE(ints
), ints
);
817 for (i
= 0; i
< MAX_PIRQS
; i
++)
818 pirq_entries
[i
] = -1;
821 apic_printk(APIC_VERBOSE
, KERN_INFO
822 "PIRQ redirection, working around broken MP-BIOS.\n");
824 if (ints
[0] < MAX_PIRQS
)
827 for (i
= 0; i
< max
; i
++) {
828 apic_printk(APIC_VERBOSE
, KERN_DEBUG
829 "... PIRQ%d -> IRQ %d\n", i
, ints
[i
+1]);
831 * PIRQs are mapped upside down, usually.
833 pirq_entries
[MAX_PIRQS
-i
-1] = ints
[i
+1];
838 __setup("pirq=", ioapic_pirq_setup
);
839 #endif /* CONFIG_X86_32 */
841 #ifdef CONFIG_INTR_REMAP
842 /* I/O APIC RTE contents at the OS boot up */
843 static struct IO_APIC_route_entry
*early_ioapic_entries
[MAX_IO_APICS
];
846 * Saves and masks all the unmasked IO-APIC RTE's
848 int save_mask_IO_APIC_setup(void)
850 union IO_APIC_reg_01 reg_01
;
855 * The number of IO-APIC IRQ registers (== #pins):
857 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
858 spin_lock_irqsave(&ioapic_lock
, flags
);
859 reg_01
.raw
= io_apic_read(apic
, 1);
860 spin_unlock_irqrestore(&ioapic_lock
, flags
);
861 nr_ioapic_registers
[apic
] = reg_01
.bits
.entries
+1;
864 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
865 early_ioapic_entries
[apic
] =
866 kzalloc(sizeof(struct IO_APIC_route_entry
) *
867 nr_ioapic_registers
[apic
], GFP_KERNEL
);
868 if (!early_ioapic_entries
[apic
])
872 for (apic
= 0; apic
< nr_ioapics
; apic
++)
873 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
874 struct IO_APIC_route_entry entry
;
876 entry
= early_ioapic_entries
[apic
][pin
] =
877 ioapic_read_entry(apic
, pin
);
880 ioapic_write_entry(apic
, pin
, entry
);
888 kfree(early_ioapic_entries
[apic
--]);
889 memset(early_ioapic_entries
, 0,
890 ARRAY_SIZE(early_ioapic_entries
));
895 void restore_IO_APIC_setup(void)
899 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
900 if (!early_ioapic_entries
[apic
])
902 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++)
903 ioapic_write_entry(apic
, pin
,
904 early_ioapic_entries
[apic
][pin
]);
905 kfree(early_ioapic_entries
[apic
]);
906 early_ioapic_entries
[apic
] = NULL
;
910 void reinit_intr_remapped_IO_APIC(int intr_remapping
)
913 * for now plain restore of previous settings.
914 * TBD: In the case of OS enabling interrupt-remapping,
915 * IO-APIC RTE's need to be setup to point to interrupt-remapping
916 * table entries. for now, do a plain restore, and wait for
917 * the setup_IO_APIC_irqs() to do proper initialization.
919 restore_IO_APIC_setup();
924 * Find the IRQ entry number of a certain pin.
926 static int find_irq_entry(int apic
, int pin
, int type
)
930 for (i
= 0; i
< mp_irq_entries
; i
++)
931 if (mp_irqs
[i
].irqtype
== type
&&
932 (mp_irqs
[i
].dstapic
== mp_ioapics
[apic
].apicid
||
933 mp_irqs
[i
].dstapic
== MP_APIC_ALL
) &&
934 mp_irqs
[i
].dstirq
== pin
)
941 * Find the pin to which IRQ[irq] (ISA) is connected
943 static int __init
find_isa_irq_pin(int irq
, int type
)
947 for (i
= 0; i
< mp_irq_entries
; i
++) {
948 int lbus
= mp_irqs
[i
].srcbus
;
950 if (test_bit(lbus
, mp_bus_not_pci
) &&
951 (mp_irqs
[i
].irqtype
== type
) &&
952 (mp_irqs
[i
].srcbusirq
== irq
))
954 return mp_irqs
[i
].dstirq
;
959 static int __init
find_isa_irq_apic(int irq
, int type
)
963 for (i
= 0; i
< mp_irq_entries
; i
++) {
964 int lbus
= mp_irqs
[i
].srcbus
;
966 if (test_bit(lbus
, mp_bus_not_pci
) &&
967 (mp_irqs
[i
].irqtype
== type
) &&
968 (mp_irqs
[i
].srcbusirq
== irq
))
971 if (i
< mp_irq_entries
) {
973 for(apic
= 0; apic
< nr_ioapics
; apic
++) {
974 if (mp_ioapics
[apic
].apicid
== mp_irqs
[i
].dstapic
)
983 * Find a specific PCI IRQ entry.
984 * Not an __init, possibly needed by modules
986 static int pin_2_irq(int idx
, int apic
, int pin
);
988 int IO_APIC_get_PCI_irq_vector(int bus
, int slot
, int pin
)
990 int apic
, i
, best_guess
= -1;
992 apic_printk(APIC_DEBUG
, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
994 if (test_bit(bus
, mp_bus_not_pci
)) {
995 apic_printk(APIC_VERBOSE
, "PCI BIOS passed nonexistent PCI bus %d!\n", bus
);
998 for (i
= 0; i
< mp_irq_entries
; i
++) {
999 int lbus
= mp_irqs
[i
].srcbus
;
1001 for (apic
= 0; apic
< nr_ioapics
; apic
++)
1002 if (mp_ioapics
[apic
].apicid
== mp_irqs
[i
].dstapic
||
1003 mp_irqs
[i
].dstapic
== MP_APIC_ALL
)
1006 if (!test_bit(lbus
, mp_bus_not_pci
) &&
1007 !mp_irqs
[i
].irqtype
&&
1009 (slot
== ((mp_irqs
[i
].srcbusirq
>> 2) & 0x1f))) {
1010 int irq
= pin_2_irq(i
, apic
, mp_irqs
[i
].dstirq
);
1012 if (!(apic
|| IO_APIC_IRQ(irq
)))
1015 if (pin
== (mp_irqs
[i
].srcbusirq
& 3))
1018 * Use the first all-but-pin matching entry as a
1019 * best-guess fuzzy result for broken mptables.
1028 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector
);
1030 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
1032 * EISA Edge/Level control register, ELCR
1034 static int EISA_ELCR(unsigned int irq
)
1036 if (irq
< NR_IRQS_LEGACY
) {
1037 unsigned int port
= 0x4d0 + (irq
>> 3);
1038 return (inb(port
) >> (irq
& 7)) & 1;
1040 apic_printk(APIC_VERBOSE
, KERN_INFO
1041 "Broken MPtable reports ISA irq %d\n", irq
);
1047 /* ISA interrupts are always polarity zero edge triggered,
1048 * when listed as conforming in the MP table. */
1050 #define default_ISA_trigger(idx) (0)
1051 #define default_ISA_polarity(idx) (0)
1053 /* EISA interrupts are always polarity zero and can be edge or level
1054 * trigger depending on the ELCR value. If an interrupt is listed as
1055 * EISA conforming in the MP table, that means its trigger type must
1056 * be read in from the ELCR */
1058 #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].srcbusirq))
1059 #define default_EISA_polarity(idx) default_ISA_polarity(idx)
1061 /* PCI interrupts are always polarity one level triggered,
1062 * when listed as conforming in the MP table. */
1064 #define default_PCI_trigger(idx) (1)
1065 #define default_PCI_polarity(idx) (1)
1067 /* MCA interrupts are always polarity zero level triggered,
1068 * when listed as conforming in the MP table. */
1070 #define default_MCA_trigger(idx) (1)
1071 #define default_MCA_polarity(idx) default_ISA_polarity(idx)
1073 static int MPBIOS_polarity(int idx
)
1075 int bus
= mp_irqs
[idx
].srcbus
;
1079 * Determine IRQ line polarity (high active or low active):
1081 switch (mp_irqs
[idx
].irqflag
& 3)
1083 case 0: /* conforms, ie. bus-type dependent polarity */
1084 if (test_bit(bus
, mp_bus_not_pci
))
1085 polarity
= default_ISA_polarity(idx
);
1087 polarity
= default_PCI_polarity(idx
);
1089 case 1: /* high active */
1094 case 2: /* reserved */
1096 printk(KERN_WARNING
"broken BIOS!!\n");
1100 case 3: /* low active */
1105 default: /* invalid */
1107 printk(KERN_WARNING
"broken BIOS!!\n");
1115 static int MPBIOS_trigger(int idx
)
1117 int bus
= mp_irqs
[idx
].srcbus
;
1121 * Determine IRQ trigger mode (edge or level sensitive):
1123 switch ((mp_irqs
[idx
].irqflag
>>2) & 3)
1125 case 0: /* conforms, ie. bus-type dependent */
1126 if (test_bit(bus
, mp_bus_not_pci
))
1127 trigger
= default_ISA_trigger(idx
);
1129 trigger
= default_PCI_trigger(idx
);
1130 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
1131 switch (mp_bus_id_to_type
[bus
]) {
1132 case MP_BUS_ISA
: /* ISA pin */
1134 /* set before the switch */
1137 case MP_BUS_EISA
: /* EISA pin */
1139 trigger
= default_EISA_trigger(idx
);
1142 case MP_BUS_PCI
: /* PCI pin */
1144 /* set before the switch */
1147 case MP_BUS_MCA
: /* MCA pin */
1149 trigger
= default_MCA_trigger(idx
);
1154 printk(KERN_WARNING
"broken BIOS!!\n");
1166 case 2: /* reserved */
1168 printk(KERN_WARNING
"broken BIOS!!\n");
1177 default: /* invalid */
1179 printk(KERN_WARNING
"broken BIOS!!\n");
1187 static inline int irq_polarity(int idx
)
1189 return MPBIOS_polarity(idx
);
1192 static inline int irq_trigger(int idx
)
1194 return MPBIOS_trigger(idx
);
1197 int (*ioapic_renumber_irq
)(int ioapic
, int irq
);
1198 static int pin_2_irq(int idx
, int apic
, int pin
)
1201 int bus
= mp_irqs
[idx
].srcbus
;
1204 * Debugging check, we are in big trouble if this message pops up!
1206 if (mp_irqs
[idx
].dstirq
!= pin
)
1207 printk(KERN_ERR
"broken BIOS or MPTABLE parser, ayiee!!\n");
1209 if (test_bit(bus
, mp_bus_not_pci
)) {
1210 irq
= mp_irqs
[idx
].srcbusirq
;
1213 * PCI IRQs are mapped in order
1217 irq
+= nr_ioapic_registers
[i
++];
1220 * For MPS mode, so far only needed by ES7000 platform
1222 if (ioapic_renumber_irq
)
1223 irq
= ioapic_renumber_irq(apic
, irq
);
1226 #ifdef CONFIG_X86_32
1228 * PCI IRQ command line redirection. Yes, limits are hardcoded.
1230 if ((pin
>= 16) && (pin
<= 23)) {
1231 if (pirq_entries
[pin
-16] != -1) {
1232 if (!pirq_entries
[pin
-16]) {
1233 apic_printk(APIC_VERBOSE
, KERN_DEBUG
1234 "disabling PIRQ%d\n", pin
-16);
1236 irq
= pirq_entries
[pin
-16];
1237 apic_printk(APIC_VERBOSE
, KERN_DEBUG
1238 "using PIRQ%d -> IRQ %d\n",
1248 void lock_vector_lock(void)
1250 /* Used to the online set of cpus does not change
1251 * during assign_irq_vector.
1253 spin_lock(&vector_lock
);
1256 void unlock_vector_lock(void)
1258 spin_unlock(&vector_lock
);
1262 __assign_irq_vector(int irq
, struct irq_cfg
*cfg
, const struct cpumask
*mask
)
1265 * NOTE! The local APIC isn't very good at handling
1266 * multiple interrupts at the same interrupt level.
1267 * As the interrupt level is determined by taking the
1268 * vector number and shifting that right by 4, we
1269 * want to spread these out a bit so that they don't
1270 * all fall in the same interrupt level.
1272 * Also, we've got to be careful not to trash gate
1273 * 0x80, because int 0x80 is hm, kind of importantish. ;)
1275 static int current_vector
= FIRST_DEVICE_VECTOR
, current_offset
= 0;
1276 unsigned int old_vector
;
1278 cpumask_var_t tmp_mask
;
1280 if ((cfg
->move_in_progress
) || cfg
->move_cleanup_count
)
1283 if (!alloc_cpumask_var(&tmp_mask
, GFP_ATOMIC
))
1286 old_vector
= cfg
->vector
;
1288 cpumask_and(tmp_mask
, mask
, cpu_online_mask
);
1289 cpumask_and(tmp_mask
, cfg
->domain
, tmp_mask
);
1290 if (!cpumask_empty(tmp_mask
)) {
1291 free_cpumask_var(tmp_mask
);
1296 /* Only try and allocate irqs on cpus that are present */
1298 for_each_cpu_and(cpu
, mask
, cpu_online_mask
) {
1302 apic
->vector_allocation_domain(cpu
, tmp_mask
);
1304 vector
= current_vector
;
1305 offset
= current_offset
;
1308 if (vector
>= first_system_vector
) {
1309 /* If out of vectors on large boxen, must share them. */
1310 offset
= (offset
+ 1) % 8;
1311 vector
= FIRST_DEVICE_VECTOR
+ offset
;
1313 if (unlikely(current_vector
== vector
))
1316 if (test_bit(vector
, used_vectors
))
1319 for_each_cpu_and(new_cpu
, tmp_mask
, cpu_online_mask
)
1320 if (per_cpu(vector_irq
, new_cpu
)[vector
] != -1)
1323 current_vector
= vector
;
1324 current_offset
= offset
;
1326 cfg
->move_in_progress
= 1;
1327 cpumask_copy(cfg
->old_domain
, cfg
->domain
);
1329 for_each_cpu_and(new_cpu
, tmp_mask
, cpu_online_mask
)
1330 per_cpu(vector_irq
, new_cpu
)[vector
] = irq
;
1331 cfg
->vector
= vector
;
1332 cpumask_copy(cfg
->domain
, tmp_mask
);
1336 free_cpumask_var(tmp_mask
);
1341 assign_irq_vector(int irq
, struct irq_cfg
*cfg
, const struct cpumask
*mask
)
1344 unsigned long flags
;
1346 spin_lock_irqsave(&vector_lock
, flags
);
1347 err
= __assign_irq_vector(irq
, cfg
, mask
);
1348 spin_unlock_irqrestore(&vector_lock
, flags
);
1352 static void __clear_irq_vector(int irq
, struct irq_cfg
*cfg
)
1356 BUG_ON(!cfg
->vector
);
1358 vector
= cfg
->vector
;
1359 for_each_cpu_and(cpu
, cfg
->domain
, cpu_online_mask
)
1360 per_cpu(vector_irq
, cpu
)[vector
] = -1;
1363 cpumask_clear(cfg
->domain
);
1365 if (likely(!cfg
->move_in_progress
))
1367 for_each_cpu_and(cpu
, cfg
->old_domain
, cpu_online_mask
) {
1368 for (vector
= FIRST_EXTERNAL_VECTOR
; vector
< NR_VECTORS
;
1370 if (per_cpu(vector_irq
, cpu
)[vector
] != irq
)
1372 per_cpu(vector_irq
, cpu
)[vector
] = -1;
1376 cfg
->move_in_progress
= 0;
1379 void __setup_vector_irq(int cpu
)
1381 /* Initialize vector_irq on a new cpu */
1382 /* This function must be called with vector_lock held */
1384 struct irq_cfg
*cfg
;
1385 struct irq_desc
*desc
;
1387 /* Mark the inuse vectors */
1388 for_each_irq_desc(irq
, desc
) {
1389 cfg
= desc
->chip_data
;
1390 if (!cpumask_test_cpu(cpu
, cfg
->domain
))
1392 vector
= cfg
->vector
;
1393 per_cpu(vector_irq
, cpu
)[vector
] = irq
;
1395 /* Mark the free vectors */
1396 for (vector
= 0; vector
< NR_VECTORS
; ++vector
) {
1397 irq
= per_cpu(vector_irq
, cpu
)[vector
];
1402 if (!cpumask_test_cpu(cpu
, cfg
->domain
))
1403 per_cpu(vector_irq
, cpu
)[vector
] = -1;
1407 static struct irq_chip ioapic_chip
;
1408 #ifdef CONFIG_INTR_REMAP
1409 static struct irq_chip ir_ioapic_chip
;
1412 #define IOAPIC_AUTO -1
1413 #define IOAPIC_EDGE 0
1414 #define IOAPIC_LEVEL 1
1416 #ifdef CONFIG_X86_32
1417 static inline int IO_APIC_irq_trigger(int irq
)
1421 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
1422 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
1423 idx
= find_irq_entry(apic
, pin
, mp_INT
);
1424 if ((idx
!= -1) && (irq
== pin_2_irq(idx
, apic
, pin
)))
1425 return irq_trigger(idx
);
1429 * nonexistent IRQs are edge default
1434 static inline int IO_APIC_irq_trigger(int irq
)
1440 static void ioapic_register_intr(int irq
, struct irq_desc
*desc
, unsigned long trigger
)
1443 if ((trigger
== IOAPIC_AUTO
&& IO_APIC_irq_trigger(irq
)) ||
1444 trigger
== IOAPIC_LEVEL
)
1445 desc
->status
|= IRQ_LEVEL
;
1447 desc
->status
&= ~IRQ_LEVEL
;
1449 #ifdef CONFIG_INTR_REMAP
1450 if (irq_remapped(irq
)) {
1451 desc
->status
|= IRQ_MOVE_PCNTXT
;
1453 set_irq_chip_and_handler_name(irq
, &ir_ioapic_chip
,
1457 set_irq_chip_and_handler_name(irq
, &ir_ioapic_chip
,
1458 handle_edge_irq
, "edge");
1462 if ((trigger
== IOAPIC_AUTO
&& IO_APIC_irq_trigger(irq
)) ||
1463 trigger
== IOAPIC_LEVEL
)
1464 set_irq_chip_and_handler_name(irq
, &ioapic_chip
,
1468 set_irq_chip_and_handler_name(irq
, &ioapic_chip
,
1469 handle_edge_irq
, "edge");
1472 static int setup_ioapic_entry(int apic_id
, int irq
,
1473 struct IO_APIC_route_entry
*entry
,
1474 unsigned int destination
, int trigger
,
1475 int polarity
, int vector
)
1478 * add it to the IO-APIC irq-routing table:
1480 memset(entry
,0,sizeof(*entry
));
1482 #ifdef CONFIG_INTR_REMAP
1483 if (intr_remapping_enabled
) {
1484 struct intel_iommu
*iommu
= map_ioapic_to_ir(apic_id
);
1486 struct IR_IO_APIC_route_entry
*ir_entry
=
1487 (struct IR_IO_APIC_route_entry
*) entry
;
1491 panic("No mapping iommu for ioapic %d\n", apic_id
);
1493 index
= alloc_irte(iommu
, irq
, 1);
1495 panic("Failed to allocate IRTE for ioapic %d\n", apic_id
);
1497 memset(&irte
, 0, sizeof(irte
));
1500 irte
.dst_mode
= apic
->irq_dest_mode
;
1501 irte
.trigger_mode
= trigger
;
1502 irte
.dlvry_mode
= apic
->irq_delivery_mode
;
1503 irte
.vector
= vector
;
1504 irte
.dest_id
= IRTE_DEST(destination
);
1506 modify_irte(irq
, &irte
);
1508 ir_entry
->index2
= (index
>> 15) & 0x1;
1510 ir_entry
->format
= 1;
1511 ir_entry
->index
= (index
& 0x7fff);
1515 entry
->delivery_mode
= apic
->irq_delivery_mode
;
1516 entry
->dest_mode
= apic
->irq_dest_mode
;
1517 entry
->dest
= destination
;
1520 entry
->mask
= 0; /* enable IRQ */
1521 entry
->trigger
= trigger
;
1522 entry
->polarity
= polarity
;
1523 entry
->vector
= vector
;
1525 /* Mask level triggered irqs.
1526 * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
1533 static void setup_IO_APIC_irq(int apic_id
, int pin
, unsigned int irq
, struct irq_desc
*desc
,
1534 int trigger
, int polarity
)
1536 struct irq_cfg
*cfg
;
1537 struct IO_APIC_route_entry entry
;
1540 if (!IO_APIC_IRQ(irq
))
1543 cfg
= desc
->chip_data
;
1545 if (assign_irq_vector(irq
, cfg
, apic
->target_cpus()))
1548 dest
= apic
->cpu_mask_to_apicid_and(cfg
->domain
, apic
->target_cpus());
1550 apic_printk(APIC_VERBOSE
,KERN_DEBUG
1551 "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
1552 "IRQ %d Mode:%i Active:%i)\n",
1553 apic_id
, mp_ioapics
[apic_id
].apicid
, pin
, cfg
->vector
,
1554 irq
, trigger
, polarity
);
1557 if (setup_ioapic_entry(mp_ioapics
[apic_id
].apicid
, irq
, &entry
,
1558 dest
, trigger
, polarity
, cfg
->vector
)) {
1559 printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
1560 mp_ioapics
[apic_id
].apicid
, pin
);
1561 __clear_irq_vector(irq
, cfg
);
1565 ioapic_register_intr(irq
, desc
, trigger
);
1566 if (irq
< NR_IRQS_LEGACY
)
1567 disable_8259A_irq(irq
);
1569 ioapic_write_entry(apic_id
, pin
, entry
);
1572 static void __init
setup_IO_APIC_irqs(void)
1574 int apic_id
, pin
, idx
, irq
;
1576 struct irq_desc
*desc
;
1577 struct irq_cfg
*cfg
;
1578 int cpu
= boot_cpu_id
;
1580 apic_printk(APIC_VERBOSE
, KERN_DEBUG
"init IO_APIC IRQs\n");
1582 for (apic_id
= 0; apic_id
< nr_ioapics
; apic_id
++) {
1583 for (pin
= 0; pin
< nr_ioapic_registers
[apic_id
]; pin
++) {
1585 idx
= find_irq_entry(apic_id
, pin
, mp_INT
);
1589 apic_printk(APIC_VERBOSE
,
1590 KERN_DEBUG
" %d-%d",
1591 mp_ioapics
[apic_id
].apicid
, pin
);
1593 apic_printk(APIC_VERBOSE
, " %d-%d",
1594 mp_ioapics
[apic_id
].apicid
, pin
);
1598 apic_printk(APIC_VERBOSE
,
1599 " (apicid-pin) not connected\n");
1603 irq
= pin_2_irq(idx
, apic_id
, pin
);
1606 * Skip the timer IRQ if there's a quirk handler
1607 * installed and if it returns 1:
1609 if (apic
->multi_timer_check
&&
1610 apic
->multi_timer_check(apic_id
, irq
))
1613 desc
= irq_to_desc_alloc_cpu(irq
, cpu
);
1615 printk(KERN_INFO
"can not get irq_desc for %d\n", irq
);
1618 cfg
= desc
->chip_data
;
1619 add_pin_to_irq_cpu(cfg
, cpu
, apic_id
, pin
);
1621 setup_IO_APIC_irq(apic_id
, pin
, irq
, desc
,
1622 irq_trigger(idx
), irq_polarity(idx
));
1627 apic_printk(APIC_VERBOSE
,
1628 " (apicid-pin) not connected\n");
1632 * Set up the timer pin, possibly with the 8259A-master behind.
1634 static void __init
setup_timer_IRQ0_pin(unsigned int apic_id
, unsigned int pin
,
1637 struct IO_APIC_route_entry entry
;
1639 #ifdef CONFIG_INTR_REMAP
1640 if (intr_remapping_enabled
)
1644 memset(&entry
, 0, sizeof(entry
));
1647 * We use logical delivery to get the timer IRQ
1650 entry
.dest_mode
= apic
->irq_dest_mode
;
1651 entry
.mask
= 1; /* mask IRQ now */
1652 entry
.dest
= apic
->cpu_mask_to_apicid(apic
->target_cpus());
1653 entry
.delivery_mode
= apic
->irq_delivery_mode
;
1656 entry
.vector
= vector
;
1659 * The timer IRQ doesn't have to know that behind the
1660 * scene we may have a 8259A-master in AEOI mode ...
1662 set_irq_chip_and_handler_name(0, &ioapic_chip
, handle_edge_irq
, "edge");
1665 * Add it to the IO-APIC irq-routing table:
1667 ioapic_write_entry(apic_id
, pin
, entry
);
1671 __apicdebuginit(void) print_IO_APIC(void)
1674 union IO_APIC_reg_00 reg_00
;
1675 union IO_APIC_reg_01 reg_01
;
1676 union IO_APIC_reg_02 reg_02
;
1677 union IO_APIC_reg_03 reg_03
;
1678 unsigned long flags
;
1679 struct irq_cfg
*cfg
;
1680 struct irq_desc
*desc
;
1683 if (apic_verbosity
== APIC_QUIET
)
1686 printk(KERN_DEBUG
"number of MP IRQ sources: %d.\n", mp_irq_entries
);
1687 for (i
= 0; i
< nr_ioapics
; i
++)
1688 printk(KERN_DEBUG
"number of IO-APIC #%d registers: %d.\n",
1689 mp_ioapics
[i
].apicid
, nr_ioapic_registers
[i
]);
1692 * We are a bit conservative about what we expect. We have to
1693 * know about every hardware change ASAP.
1695 printk(KERN_INFO
"testing the IO APIC.......................\n");
1697 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
1699 spin_lock_irqsave(&ioapic_lock
, flags
);
1700 reg_00
.raw
= io_apic_read(apic
, 0);
1701 reg_01
.raw
= io_apic_read(apic
, 1);
1702 if (reg_01
.bits
.version
>= 0x10)
1703 reg_02
.raw
= io_apic_read(apic
, 2);
1704 if (reg_01
.bits
.version
>= 0x20)
1705 reg_03
.raw
= io_apic_read(apic
, 3);
1706 spin_unlock_irqrestore(&ioapic_lock
, flags
);
1709 printk(KERN_DEBUG
"IO APIC #%d......\n", mp_ioapics
[apic
].apicid
);
1710 printk(KERN_DEBUG
".... register #00: %08X\n", reg_00
.raw
);
1711 printk(KERN_DEBUG
"....... : physical APIC id: %02X\n", reg_00
.bits
.ID
);
1712 printk(KERN_DEBUG
"....... : Delivery Type: %X\n", reg_00
.bits
.delivery_type
);
1713 printk(KERN_DEBUG
"....... : LTS : %X\n", reg_00
.bits
.LTS
);
1715 printk(KERN_DEBUG
".... register #01: %08X\n", *(int *)®_01
);
1716 printk(KERN_DEBUG
"....... : max redirection entries: %04X\n", reg_01
.bits
.entries
);
1718 printk(KERN_DEBUG
"....... : PRQ implemented: %X\n", reg_01
.bits
.PRQ
);
1719 printk(KERN_DEBUG
"....... : IO APIC version: %04X\n", reg_01
.bits
.version
);
1722 * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
1723 * but the value of reg_02 is read as the previous read register
1724 * value, so ignore it if reg_02 == reg_01.
1726 if (reg_01
.bits
.version
>= 0x10 && reg_02
.raw
!= reg_01
.raw
) {
1727 printk(KERN_DEBUG
".... register #02: %08X\n", reg_02
.raw
);
1728 printk(KERN_DEBUG
"....... : arbitration: %02X\n", reg_02
.bits
.arbitration
);
1732 * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
1733 * or reg_03, but the value of reg_0[23] is read as the previous read
1734 * register value, so ignore it if reg_03 == reg_0[12].
1736 if (reg_01
.bits
.version
>= 0x20 && reg_03
.raw
!= reg_02
.raw
&&
1737 reg_03
.raw
!= reg_01
.raw
) {
1738 printk(KERN_DEBUG
".... register #03: %08X\n", reg_03
.raw
);
1739 printk(KERN_DEBUG
"....... : Boot DT : %X\n", reg_03
.bits
.boot_DT
);
1742 printk(KERN_DEBUG
".... IRQ redirection table:\n");
1744 printk(KERN_DEBUG
" NR Dst Mask Trig IRR Pol"
1745 " Stat Dmod Deli Vect: \n");
1747 for (i
= 0; i
<= reg_01
.bits
.entries
; i
++) {
1748 struct IO_APIC_route_entry entry
;
1750 entry
= ioapic_read_entry(apic
, i
);
1752 printk(KERN_DEBUG
" %02x %03X ",
1757 printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
1762 entry
.delivery_status
,
1764 entry
.delivery_mode
,
1769 printk(KERN_DEBUG
"IRQ to pin mappings:\n");
1770 for_each_irq_desc(irq
, desc
) {
1771 struct irq_pin_list
*entry
;
1773 cfg
= desc
->chip_data
;
1774 entry
= cfg
->irq_2_pin
;
1777 printk(KERN_DEBUG
"IRQ%d ", irq
);
1779 printk("-> %d:%d", entry
->apic
, entry
->pin
);
1782 entry
= entry
->next
;
1787 printk(KERN_INFO
".................................... done.\n");
1792 __apicdebuginit(void) print_APIC_bitfield(int base
)
1797 if (apic_verbosity
== APIC_QUIET
)
1800 printk(KERN_DEBUG
"0123456789abcdef0123456789abcdef\n" KERN_DEBUG
);
1801 for (i
= 0; i
< 8; i
++) {
1802 v
= apic_read(base
+ i
*0x10);
1803 for (j
= 0; j
< 32; j
++) {
1813 __apicdebuginit(void) print_local_APIC(void *dummy
)
1815 unsigned int v
, ver
, maxlvt
;
1818 if (apic_verbosity
== APIC_QUIET
)
1821 printk("\n" KERN_DEBUG
"printing local APIC contents on CPU#%d/%d:\n",
1822 smp_processor_id(), hard_smp_processor_id());
1823 v
= apic_read(APIC_ID
);
1824 printk(KERN_INFO
"... APIC ID: %08x (%01x)\n", v
, read_apic_id());
1825 v
= apic_read(APIC_LVR
);
1826 printk(KERN_INFO
"... APIC VERSION: %08x\n", v
);
1827 ver
= GET_APIC_VERSION(v
);
1828 maxlvt
= lapic_get_maxlvt();
1830 v
= apic_read(APIC_TASKPRI
);
1831 printk(KERN_DEBUG
"... APIC TASKPRI: %08x (%02x)\n", v
, v
& APIC_TPRI_MASK
);
1833 if (APIC_INTEGRATED(ver
)) { /* !82489DX */
1834 if (!APIC_XAPIC(ver
)) {
1835 v
= apic_read(APIC_ARBPRI
);
1836 printk(KERN_DEBUG
"... APIC ARBPRI: %08x (%02x)\n", v
,
1837 v
& APIC_ARBPRI_MASK
);
1839 v
= apic_read(APIC_PROCPRI
);
1840 printk(KERN_DEBUG
"... APIC PROCPRI: %08x\n", v
);
1844 * Remote read supported only in the 82489DX and local APIC for
1845 * Pentium processors.
1847 if (!APIC_INTEGRATED(ver
) || maxlvt
== 3) {
1848 v
= apic_read(APIC_RRR
);
1849 printk(KERN_DEBUG
"... APIC RRR: %08x\n", v
);
1852 v
= apic_read(APIC_LDR
);
1853 printk(KERN_DEBUG
"... APIC LDR: %08x\n", v
);
1854 if (!x2apic_enabled()) {
1855 v
= apic_read(APIC_DFR
);
1856 printk(KERN_DEBUG
"... APIC DFR: %08x\n", v
);
1858 v
= apic_read(APIC_SPIV
);
1859 printk(KERN_DEBUG
"... APIC SPIV: %08x\n", v
);
1861 printk(KERN_DEBUG
"... APIC ISR field:\n");
1862 print_APIC_bitfield(APIC_ISR
);
1863 printk(KERN_DEBUG
"... APIC TMR field:\n");
1864 print_APIC_bitfield(APIC_TMR
);
1865 printk(KERN_DEBUG
"... APIC IRR field:\n");
1866 print_APIC_bitfield(APIC_IRR
);
1868 if (APIC_INTEGRATED(ver
)) { /* !82489DX */
1869 if (maxlvt
> 3) /* Due to the Pentium erratum 3AP. */
1870 apic_write(APIC_ESR
, 0);
1872 v
= apic_read(APIC_ESR
);
1873 printk(KERN_DEBUG
"... APIC ESR: %08x\n", v
);
1876 icr
= apic_icr_read();
1877 printk(KERN_DEBUG
"... APIC ICR: %08x\n", (u32
)icr
);
1878 printk(KERN_DEBUG
"... APIC ICR2: %08x\n", (u32
)(icr
>> 32));
1880 v
= apic_read(APIC_LVTT
);
1881 printk(KERN_DEBUG
"... APIC LVTT: %08x\n", v
);
1883 if (maxlvt
> 3) { /* PC is LVT#4. */
1884 v
= apic_read(APIC_LVTPC
);
1885 printk(KERN_DEBUG
"... APIC LVTPC: %08x\n", v
);
1887 v
= apic_read(APIC_LVT0
);
1888 printk(KERN_DEBUG
"... APIC LVT0: %08x\n", v
);
1889 v
= apic_read(APIC_LVT1
);
1890 printk(KERN_DEBUG
"... APIC LVT1: %08x\n", v
);
1892 if (maxlvt
> 2) { /* ERR is LVT#3. */
1893 v
= apic_read(APIC_LVTERR
);
1894 printk(KERN_DEBUG
"... APIC LVTERR: %08x\n", v
);
1897 v
= apic_read(APIC_TMICT
);
1898 printk(KERN_DEBUG
"... APIC TMICT: %08x\n", v
);
1899 v
= apic_read(APIC_TMCCT
);
1900 printk(KERN_DEBUG
"... APIC TMCCT: %08x\n", v
);
1901 v
= apic_read(APIC_TDCR
);
1902 printk(KERN_DEBUG
"... APIC TDCR: %08x\n", v
);
1906 __apicdebuginit(void) print_all_local_APICs(void)
1911 for_each_online_cpu(cpu
)
1912 smp_call_function_single(cpu
, print_local_APIC
, NULL
, 1);
1916 __apicdebuginit(void) print_PIC(void)
1919 unsigned long flags
;
1921 if (apic_verbosity
== APIC_QUIET
)
1924 printk(KERN_DEBUG
"\nprinting PIC contents\n");
1926 spin_lock_irqsave(&i8259A_lock
, flags
);
1928 v
= inb(0xa1) << 8 | inb(0x21);
1929 printk(KERN_DEBUG
"... PIC IMR: %04x\n", v
);
1931 v
= inb(0xa0) << 8 | inb(0x20);
1932 printk(KERN_DEBUG
"... PIC IRR: %04x\n", v
);
1936 v
= inb(0xa0) << 8 | inb(0x20);
1940 spin_unlock_irqrestore(&i8259A_lock
, flags
);
1942 printk(KERN_DEBUG
"... PIC ISR: %04x\n", v
);
1944 v
= inb(0x4d1) << 8 | inb(0x4d0);
1945 printk(KERN_DEBUG
"... PIC ELCR: %04x\n", v
);
1948 __apicdebuginit(int) print_all_ICs(void)
1951 print_all_local_APICs();
1957 fs_initcall(print_all_ICs
);
1960 /* Where if anywhere is the i8259 connect in external int mode */
1961 static struct { int pin
, apic
; } ioapic_i8259
= { -1, -1 };
1963 void __init
enable_IO_APIC(void)
1965 union IO_APIC_reg_01 reg_01
;
1966 int i8259_apic
, i8259_pin
;
1968 unsigned long flags
;
1970 #ifdef CONFIG_X86_32
1973 for (i
= 0; i
< MAX_PIRQS
; i
++)
1974 pirq_entries
[i
] = -1;
1978 * The number of IO-APIC IRQ registers (== #pins):
1980 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
1981 spin_lock_irqsave(&ioapic_lock
, flags
);
1982 reg_01
.raw
= io_apic_read(apic
, 1);
1983 spin_unlock_irqrestore(&ioapic_lock
, flags
);
1984 nr_ioapic_registers
[apic
] = reg_01
.bits
.entries
+1;
1986 for(apic
= 0; apic
< nr_ioapics
; apic
++) {
1988 /* See if any of the pins is in ExtINT mode */
1989 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
1990 struct IO_APIC_route_entry entry
;
1991 entry
= ioapic_read_entry(apic
, pin
);
1993 /* If the interrupt line is enabled and in ExtInt mode
1994 * I have found the pin where the i8259 is connected.
1996 if ((entry
.mask
== 0) && (entry
.delivery_mode
== dest_ExtINT
)) {
1997 ioapic_i8259
.apic
= apic
;
1998 ioapic_i8259
.pin
= pin
;
2004 /* Look to see what if the MP table has reported the ExtINT */
2005 /* If we could not find the appropriate pin by looking at the ioapic
2006 * the i8259 probably is not connected the ioapic but give the
2007 * mptable a chance anyway.
2009 i8259_pin
= find_isa_irq_pin(0, mp_ExtINT
);
2010 i8259_apic
= find_isa_irq_apic(0, mp_ExtINT
);
2011 /* Trust the MP table if nothing is setup in the hardware */
2012 if ((ioapic_i8259
.pin
== -1) && (i8259_pin
>= 0)) {
2013 printk(KERN_WARNING
"ExtINT not setup in hardware but reported by MP table\n");
2014 ioapic_i8259
.pin
= i8259_pin
;
2015 ioapic_i8259
.apic
= i8259_apic
;
2017 /* Complain if the MP table and the hardware disagree */
2018 if (((ioapic_i8259
.apic
!= i8259_apic
) || (ioapic_i8259
.pin
!= i8259_pin
)) &&
2019 (i8259_pin
>= 0) && (ioapic_i8259
.pin
>= 0))
2021 printk(KERN_WARNING
"ExtINT in hardware and MP table differ\n");
2025 * Do not trust the IO-APIC being empty at bootup
2031 * Not an __init, needed by the reboot code
2033 void disable_IO_APIC(void)
2036 * Clear the IO-APIC before rebooting:
2041 * If the i8259 is routed through an IOAPIC
2042 * Put that IOAPIC in virtual wire mode
2043 * so legacy interrupts can be delivered.
2045 if (ioapic_i8259
.pin
!= -1) {
2046 struct IO_APIC_route_entry entry
;
2048 memset(&entry
, 0, sizeof(entry
));
2049 entry
.mask
= 0; /* Enabled */
2050 entry
.trigger
= 0; /* Edge */
2052 entry
.polarity
= 0; /* High */
2053 entry
.delivery_status
= 0;
2054 entry
.dest_mode
= 0; /* Physical */
2055 entry
.delivery_mode
= dest_ExtINT
; /* ExtInt */
2057 entry
.dest
= read_apic_id();
2060 * Add it to the IO-APIC irq-routing table:
2062 ioapic_write_entry(ioapic_i8259
.apic
, ioapic_i8259
.pin
, entry
);
2065 disconnect_bsp_APIC(ioapic_i8259
.pin
!= -1);
2068 #ifdef CONFIG_X86_32
2070 * function to set the IO-APIC physical IDs based on the
2071 * values stored in the MPC table.
2073 * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
2076 static void __init
setup_ioapic_ids_from_mpc(void)
2078 union IO_APIC_reg_00 reg_00
;
2079 physid_mask_t phys_id_present_map
;
2082 unsigned char old_id
;
2083 unsigned long flags
;
2085 if (x86_quirks
->setup_ioapic_ids
&& x86_quirks
->setup_ioapic_ids())
2089 * Don't check I/O APIC IDs for xAPIC systems. They have
2090 * no meaning without the serial APIC bus.
2092 if (!(boot_cpu_data
.x86_vendor
== X86_VENDOR_INTEL
)
2093 || APIC_XAPIC(apic_version
[boot_cpu_physical_apicid
]))
2096 * This is broken; anything with a real cpu count has to
2097 * circumvent this idiocy regardless.
2099 phys_id_present_map
= apic
->ioapic_phys_id_map(phys_cpu_present_map
);
2102 * Set the IOAPIC ID to the value stored in the MPC table.
2104 for (apic_id
= 0; apic_id
< nr_ioapics
; apic_id
++) {
2106 /* Read the register 0 value */
2107 spin_lock_irqsave(&ioapic_lock
, flags
);
2108 reg_00
.raw
= io_apic_read(apic_id
, 0);
2109 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2111 old_id
= mp_ioapics
[apic_id
].apicid
;
2113 if (mp_ioapics
[apic_id
].apicid
>= get_physical_broadcast()) {
2114 printk(KERN_ERR
"BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
2115 apic_id
, mp_ioapics
[apic_id
].apicid
);
2116 printk(KERN_ERR
"... fixing up to %d. (tell your hw vendor)\n",
2118 mp_ioapics
[apic_id
].apicid
= reg_00
.bits
.ID
;
2122 * Sanity check, is the ID really free? Every APIC in a
2123 * system must have a unique ID or we get lots of nice
2124 * 'stuck on smp_invalidate_needed IPI wait' messages.
2126 if (apic
->check_apicid_used(phys_id_present_map
,
2127 mp_ioapics
[apic_id
].apicid
)) {
2128 printk(KERN_ERR
"BIOS bug, IO-APIC#%d ID %d is already used!...\n",
2129 apic_id
, mp_ioapics
[apic_id
].apicid
);
2130 for (i
= 0; i
< get_physical_broadcast(); i
++)
2131 if (!physid_isset(i
, phys_id_present_map
))
2133 if (i
>= get_physical_broadcast())
2134 panic("Max APIC ID exceeded!\n");
2135 printk(KERN_ERR
"... fixing up to %d. (tell your hw vendor)\n",
2137 physid_set(i
, phys_id_present_map
);
2138 mp_ioapics
[apic_id
].apicid
= i
;
2141 tmp
= apic
->apicid_to_cpu_present(mp_ioapics
[apic_id
].apicid
);
2142 apic_printk(APIC_VERBOSE
, "Setting %d in the "
2143 "phys_id_present_map\n",
2144 mp_ioapics
[apic_id
].apicid
);
2145 physids_or(phys_id_present_map
, phys_id_present_map
, tmp
);
2150 * We need to adjust the IRQ routing table
2151 * if the ID changed.
2153 if (old_id
!= mp_ioapics
[apic_id
].apicid
)
2154 for (i
= 0; i
< mp_irq_entries
; i
++)
2155 if (mp_irqs
[i
].dstapic
== old_id
)
2157 = mp_ioapics
[apic_id
].apicid
;
2160 * Read the right value from the MPC table and
2161 * write it into the ID register.
2163 apic_printk(APIC_VERBOSE
, KERN_INFO
2164 "...changing IO-APIC physical APIC ID to %d ...",
2165 mp_ioapics
[apic_id
].apicid
);
2167 reg_00
.bits
.ID
= mp_ioapics
[apic_id
].apicid
;
2168 spin_lock_irqsave(&ioapic_lock
, flags
);
2169 io_apic_write(apic_id
, 0, reg_00
.raw
);
2170 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2175 spin_lock_irqsave(&ioapic_lock
, flags
);
2176 reg_00
.raw
= io_apic_read(apic_id
, 0);
2177 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2178 if (reg_00
.bits
.ID
!= mp_ioapics
[apic_id
].apicid
)
2179 printk("could not set ID!\n");
2181 apic_printk(APIC_VERBOSE
, " ok.\n");
2186 int no_timer_check __initdata
;
2188 static int __init
notimercheck(char *s
)
2193 __setup("no_timer_check", notimercheck
);
2196 * There is a nasty bug in some older SMP boards, their mptable lies
2197 * about the timer IRQ. We do the following to work around the situation:
2199 * - timer IRQ defaults to IO-APIC IRQ
2200 * - if this function detects that timer IRQs are defunct, then we fall
2201 * back to ISA timer IRQs
2203 static int __init
timer_irq_works(void)
2205 unsigned long t1
= jiffies
;
2206 unsigned long flags
;
2211 local_save_flags(flags
);
2213 /* Let ten ticks pass... */
2214 mdelay((10 * 1000) / HZ
);
2215 local_irq_restore(flags
);
2218 * Expect a few ticks at least, to be sure some possible
2219 * glue logic does not lock up after one or two first
2220 * ticks in a non-ExtINT mode. Also the local APIC
2221 * might have cached one ExtINT interrupt. Finally, at
2222 * least one tick may be lost due to delays.
2226 if (time_after(jiffies
, t1
+ 4))
2232 * In the SMP+IOAPIC case it might happen that there are an unspecified
2233 * number of pending IRQ events unhandled. These cases are very rare,
2234 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
2235 * better to do it this way as thus we do not have to be aware of
2236 * 'pending' interrupts in the IRQ path, except at this point.
2239 * Edge triggered needs to resend any interrupt
2240 * that was delayed but this is now handled in the device
2245 * Starting up a edge-triggered IO-APIC interrupt is
2246 * nasty - we need to make sure that we get the edge.
2247 * If it is already asserted for some reason, we need
2248 * return 1 to indicate that is was pending.
2250 * This is not complete - we should be able to fake
2251 * an edge even if it isn't on the 8259A...
2254 static unsigned int startup_ioapic_irq(unsigned int irq
)
2256 int was_pending
= 0;
2257 unsigned long flags
;
2258 struct irq_cfg
*cfg
;
2260 spin_lock_irqsave(&ioapic_lock
, flags
);
2261 if (irq
< NR_IRQS_LEGACY
) {
2262 disable_8259A_irq(irq
);
2263 if (i8259A_irq_pending(irq
))
2267 __unmask_IO_APIC_irq(cfg
);
2268 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2273 #ifdef CONFIG_X86_64
2274 static int ioapic_retrigger_irq(unsigned int irq
)
2277 struct irq_cfg
*cfg
= irq_cfg(irq
);
2278 unsigned long flags
;
2280 spin_lock_irqsave(&vector_lock
, flags
);
2281 apic
->send_IPI_mask(cpumask_of(cpumask_first(cfg
->domain
)), cfg
->vector
);
2282 spin_unlock_irqrestore(&vector_lock
, flags
);
2287 static int ioapic_retrigger_irq(unsigned int irq
)
2289 apic
->send_IPI_self(irq_cfg(irq
)->vector
);
2296 * Level and edge triggered IO-APIC interrupts need different handling,
2297 * so we use two separate IRQ descriptors. Edge triggered IRQs can be
2298 * handled with the level-triggered descriptor, but that one has slightly
2299 * more overhead. Level-triggered interrupts cannot be handled with the
2300 * edge-triggered handler, without risking IRQ storms and other ugly
2306 #ifdef CONFIG_INTR_REMAP
2307 static void ir_irq_migration(struct work_struct
*work
);
2309 static DECLARE_DELAYED_WORK(ir_migration_work
, ir_irq_migration
);
2312 * Migrate the IO-APIC irq in the presence of intr-remapping.
2314 * For edge triggered, irq migration is a simple atomic update(of vector
2315 * and cpu destination) of IRTE and flush the hardware cache.
2317 * For level triggered, we need to modify the io-apic RTE aswell with the update
2318 * vector information, along with modifying IRTE with vector and destination.
2319 * So irq migration for level triggered is little bit more complex compared to
2320 * edge triggered migration. But the good news is, we use the same algorithm
2321 * for level triggered migration as we have today, only difference being,
2322 * we now initiate the irq migration from process context instead of the
2323 * interrupt context.
2325 * In future, when we do a directed EOI (combined with cpu EOI broadcast
2326 * suppression) to the IO-APIC, level triggered irq migration will also be
2327 * as simple as edge triggered migration and we can do the irq migration
2328 * with a simple atomic update to IO-APIC RTE.
2331 migrate_ioapic_irq_desc(struct irq_desc
*desc
, const struct cpumask
*mask
)
2333 struct irq_cfg
*cfg
;
2335 int modify_ioapic_rte
;
2337 unsigned long flags
;
2340 if (!cpumask_intersects(mask
, cpu_online_mask
))
2344 if (get_irte(irq
, &irte
))
2347 cfg
= desc
->chip_data
;
2348 if (assign_irq_vector(irq
, cfg
, mask
))
2351 set_extra_move_desc(desc
, mask
);
2353 dest
= apic
->cpu_mask_to_apicid_and(cfg
->domain
, mask
);
2355 modify_ioapic_rte
= desc
->status
& IRQ_LEVEL
;
2356 if (modify_ioapic_rte
) {
2357 spin_lock_irqsave(&ioapic_lock
, flags
);
2358 __target_IO_APIC_irq(irq
, dest
, cfg
);
2359 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2362 irte
.vector
= cfg
->vector
;
2363 irte
.dest_id
= IRTE_DEST(dest
);
2366 * Modified the IRTE and flushes the Interrupt entry cache.
2368 modify_irte(irq
, &irte
);
2370 if (cfg
->move_in_progress
)
2371 send_cleanup_vector(cfg
);
2373 cpumask_copy(desc
->affinity
, mask
);
2376 static int migrate_irq_remapped_level_desc(struct irq_desc
*desc
)
2379 struct irq_cfg
*cfg
= desc
->chip_data
;
2381 mask_IO_APIC_irq_desc(desc
);
2383 if (io_apic_level_ack_pending(cfg
)) {
2385 * Interrupt in progress. Migrating irq now will change the
2386 * vector information in the IO-APIC RTE and that will confuse
2387 * the EOI broadcast performed by cpu.
2388 * So, delay the irq migration to the next instance.
2390 schedule_delayed_work(&ir_migration_work
, 1);
2394 /* everthing is clear. we have right of way */
2395 migrate_ioapic_irq_desc(desc
, desc
->pending_mask
);
2398 desc
->status
&= ~IRQ_MOVE_PENDING
;
2399 cpumask_clear(desc
->pending_mask
);
2402 unmask_IO_APIC_irq_desc(desc
);
2407 static void ir_irq_migration(struct work_struct
*work
)
2410 struct irq_desc
*desc
;
2412 for_each_irq_desc(irq
, desc
) {
2413 if (desc
->status
& IRQ_MOVE_PENDING
) {
2414 unsigned long flags
;
2416 spin_lock_irqsave(&desc
->lock
, flags
);
2417 if (!desc
->chip
->set_affinity
||
2418 !(desc
->status
& IRQ_MOVE_PENDING
)) {
2419 desc
->status
&= ~IRQ_MOVE_PENDING
;
2420 spin_unlock_irqrestore(&desc
->lock
, flags
);
2424 desc
->chip
->set_affinity(irq
, desc
->pending_mask
);
2425 spin_unlock_irqrestore(&desc
->lock
, flags
);
2431 * Migrates the IRQ destination in the process context.
2433 static void set_ir_ioapic_affinity_irq_desc(struct irq_desc
*desc
,
2434 const struct cpumask
*mask
)
2436 if (desc
->status
& IRQ_LEVEL
) {
2437 desc
->status
|= IRQ_MOVE_PENDING
;
2438 cpumask_copy(desc
->pending_mask
, mask
);
2439 migrate_irq_remapped_level_desc(desc
);
2443 migrate_ioapic_irq_desc(desc
, mask
);
2445 static void set_ir_ioapic_affinity_irq(unsigned int irq
,
2446 const struct cpumask
*mask
)
2448 struct irq_desc
*desc
= irq_to_desc(irq
);
2450 set_ir_ioapic_affinity_irq_desc(desc
, mask
);
2454 asmlinkage
void smp_irq_move_cleanup_interrupt(void)
2456 unsigned vector
, me
;
2462 me
= smp_processor_id();
2463 for (vector
= FIRST_EXTERNAL_VECTOR
; vector
< NR_VECTORS
; vector
++) {
2465 struct irq_desc
*desc
;
2466 struct irq_cfg
*cfg
;
2467 irq
= __get_cpu_var(vector_irq
)[vector
];
2472 desc
= irq_to_desc(irq
);
2477 spin_lock(&desc
->lock
);
2478 if (!cfg
->move_cleanup_count
)
2481 if (vector
== cfg
->vector
&& cpumask_test_cpu(me
, cfg
->domain
))
2484 __get_cpu_var(vector_irq
)[vector
] = -1;
2485 cfg
->move_cleanup_count
--;
2487 spin_unlock(&desc
->lock
);
2493 static void irq_complete_move(struct irq_desc
**descp
)
2495 struct irq_desc
*desc
= *descp
;
2496 struct irq_cfg
*cfg
= desc
->chip_data
;
2497 unsigned vector
, me
;
2499 if (likely(!cfg
->move_in_progress
)) {
2500 #ifdef CONFIG_NUMA_MIGRATE_IRQ_DESC
2501 if (likely(!cfg
->move_desc_pending
))
2504 /* domain has not changed, but affinity did */
2505 me
= smp_processor_id();
2506 if (cpumask_test_cpu(me
, desc
->affinity
)) {
2507 *descp
= desc
= move_irq_desc(desc
, me
);
2508 /* get the new one */
2509 cfg
= desc
->chip_data
;
2510 cfg
->move_desc_pending
= 0;
2516 vector
= ~get_irq_regs()->orig_ax
;
2517 me
= smp_processor_id();
2518 #ifdef CONFIG_NUMA_MIGRATE_IRQ_DESC
2519 *descp
= desc
= move_irq_desc(desc
, me
);
2520 /* get the new one */
2521 cfg
= desc
->chip_data
;
2524 if (vector
== cfg
->vector
&& cpumask_test_cpu(me
, cfg
->domain
))
2525 send_cleanup_vector(cfg
);
2528 static inline void irq_complete_move(struct irq_desc
**descp
) {}
2531 #ifdef CONFIG_INTR_REMAP
2532 static void ack_x2apic_level(unsigned int irq
)
2537 static void ack_x2apic_edge(unsigned int irq
)
2544 static void ack_apic_edge(unsigned int irq
)
2546 struct irq_desc
*desc
= irq_to_desc(irq
);
2548 irq_complete_move(&desc
);
2549 move_native_irq(irq
);
2553 atomic_t irq_mis_count
;
2555 static void ack_apic_level(unsigned int irq
)
2557 struct irq_desc
*desc
= irq_to_desc(irq
);
2559 #ifdef CONFIG_X86_32
2563 struct irq_cfg
*cfg
;
2564 int do_unmask_irq
= 0;
2566 irq_complete_move(&desc
);
2567 #ifdef CONFIG_GENERIC_PENDING_IRQ
2568 /* If we are moving the irq we need to mask it */
2569 if (unlikely(desc
->status
& IRQ_MOVE_PENDING
)) {
2571 mask_IO_APIC_irq_desc(desc
);
2575 #ifdef CONFIG_X86_32
2577 * It appears there is an erratum which affects at least version 0x11
2578 * of I/O APIC (that's the 82093AA and cores integrated into various
2579 * chipsets). Under certain conditions a level-triggered interrupt is
2580 * erroneously delivered as edge-triggered one but the respective IRR
2581 * bit gets set nevertheless. As a result the I/O unit expects an EOI
2582 * message but it will never arrive and further interrupts are blocked
2583 * from the source. The exact reason is so far unknown, but the
2584 * phenomenon was observed when two consecutive interrupt requests
2585 * from a given source get delivered to the same CPU and the source is
2586 * temporarily disabled in between.
2588 * A workaround is to simulate an EOI message manually. We achieve it
2589 * by setting the trigger mode to edge and then to level when the edge
2590 * trigger mode gets detected in the TMR of a local APIC for a
2591 * level-triggered interrupt. We mask the source for the time of the
2592 * operation to prevent an edge-triggered interrupt escaping meanwhile.
2593 * The idea is from Manfred Spraul. --macro
2595 cfg
= desc
->chip_data
;
2598 v
= apic_read(APIC_TMR
+ ((i
& ~0x1f) >> 1));
2602 * We must acknowledge the irq before we move it or the acknowledge will
2603 * not propagate properly.
2607 /* Now we can move and renable the irq */
2608 if (unlikely(do_unmask_irq
)) {
2609 /* Only migrate the irq if the ack has been received.
2611 * On rare occasions the broadcast level triggered ack gets
2612 * delayed going to ioapics, and if we reprogram the
2613 * vector while Remote IRR is still set the irq will never
2616 * To prevent this scenario we read the Remote IRR bit
2617 * of the ioapic. This has two effects.
2618 * - On any sane system the read of the ioapic will
2619 * flush writes (and acks) going to the ioapic from
2621 * - We get to see if the ACK has actually been delivered.
2623 * Based on failed experiments of reprogramming the
2624 * ioapic entry from outside of irq context starting
2625 * with masking the ioapic entry and then polling until
2626 * Remote IRR was clear before reprogramming the
2627 * ioapic I don't trust the Remote IRR bit to be
2628 * completey accurate.
2630 * However there appears to be no other way to plug
2631 * this race, so if the Remote IRR bit is not
2632 * accurate and is causing problems then it is a hardware bug
2633 * and you can go talk to the chipset vendor about it.
2635 cfg
= desc
->chip_data
;
2636 if (!io_apic_level_ack_pending(cfg
))
2637 move_masked_irq(irq
);
2638 unmask_IO_APIC_irq_desc(desc
);
2641 #ifdef CONFIG_X86_32
2642 if (!(v
& (1 << (i
& 0x1f)))) {
2643 atomic_inc(&irq_mis_count
);
2644 spin_lock(&ioapic_lock
);
2645 __mask_and_edge_IO_APIC_irq(cfg
);
2646 __unmask_and_level_IO_APIC_irq(cfg
);
2647 spin_unlock(&ioapic_lock
);
2652 static struct irq_chip ioapic_chip __read_mostly
= {
2654 .startup
= startup_ioapic_irq
,
2655 .mask
= mask_IO_APIC_irq
,
2656 .unmask
= unmask_IO_APIC_irq
,
2657 .ack
= ack_apic_edge
,
2658 .eoi
= ack_apic_level
,
2660 .set_affinity
= set_ioapic_affinity_irq
,
2662 .retrigger
= ioapic_retrigger_irq
,
2665 #ifdef CONFIG_INTR_REMAP
2666 static struct irq_chip ir_ioapic_chip __read_mostly
= {
2667 .name
= "IR-IO-APIC",
2668 .startup
= startup_ioapic_irq
,
2669 .mask
= mask_IO_APIC_irq
,
2670 .unmask
= unmask_IO_APIC_irq
,
2671 .ack
= ack_x2apic_edge
,
2672 .eoi
= ack_x2apic_level
,
2674 .set_affinity
= set_ir_ioapic_affinity_irq
,
2676 .retrigger
= ioapic_retrigger_irq
,
2680 static inline void init_IO_APIC_traps(void)
2683 struct irq_desc
*desc
;
2684 struct irq_cfg
*cfg
;
2687 * NOTE! The local APIC isn't very good at handling
2688 * multiple interrupts at the same interrupt level.
2689 * As the interrupt level is determined by taking the
2690 * vector number and shifting that right by 4, we
2691 * want to spread these out a bit so that they don't
2692 * all fall in the same interrupt level.
2694 * Also, we've got to be careful not to trash gate
2695 * 0x80, because int 0x80 is hm, kind of importantish. ;)
2697 for_each_irq_desc(irq
, desc
) {
2698 cfg
= desc
->chip_data
;
2699 if (IO_APIC_IRQ(irq
) && cfg
&& !cfg
->vector
) {
2701 * Hmm.. We don't have an entry for this,
2702 * so default to an old-fashioned 8259
2703 * interrupt if we can..
2705 if (irq
< NR_IRQS_LEGACY
)
2706 make_8259A_irq(irq
);
2708 /* Strange. Oh, well.. */
2709 desc
->chip
= &no_irq_chip
;
2715 * The local APIC irq-chip implementation:
2718 static void mask_lapic_irq(unsigned int irq
)
2722 v
= apic_read(APIC_LVT0
);
2723 apic_write(APIC_LVT0
, v
| APIC_LVT_MASKED
);
2726 static void unmask_lapic_irq(unsigned int irq
)
2730 v
= apic_read(APIC_LVT0
);
2731 apic_write(APIC_LVT0
, v
& ~APIC_LVT_MASKED
);
2734 static void ack_lapic_irq(unsigned int irq
)
2739 static struct irq_chip lapic_chip __read_mostly
= {
2740 .name
= "local-APIC",
2741 .mask
= mask_lapic_irq
,
2742 .unmask
= unmask_lapic_irq
,
2743 .ack
= ack_lapic_irq
,
2746 static void lapic_register_intr(int irq
, struct irq_desc
*desc
)
2748 desc
->status
&= ~IRQ_LEVEL
;
2749 set_irq_chip_and_handler_name(irq
, &lapic_chip
, handle_edge_irq
,
2753 static void __init
setup_nmi(void)
2756 * Dirty trick to enable the NMI watchdog ...
2757 * We put the 8259A master into AEOI mode and
2758 * unmask on all local APICs LVT0 as NMI.
2760 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
2761 * is from Maciej W. Rozycki - so we do not have to EOI from
2762 * the NMI handler or the timer interrupt.
2764 apic_printk(APIC_VERBOSE
, KERN_INFO
"activating NMI Watchdog ...");
2766 enable_NMI_through_LVT0();
2768 apic_printk(APIC_VERBOSE
, " done.\n");
2772 * This looks a bit hackish but it's about the only one way of sending
2773 * a few INTA cycles to 8259As and any associated glue logic. ICR does
2774 * not support the ExtINT mode, unfortunately. We need to send these
2775 * cycles as some i82489DX-based boards have glue logic that keeps the
2776 * 8259A interrupt line asserted until INTA. --macro
2778 static inline void __init
unlock_ExtINT_logic(void)
2781 struct IO_APIC_route_entry entry0
, entry1
;
2782 unsigned char save_control
, save_freq_select
;
2784 pin
= find_isa_irq_pin(8, mp_INT
);
2789 apic
= find_isa_irq_apic(8, mp_INT
);
2795 entry0
= ioapic_read_entry(apic
, pin
);
2796 clear_IO_APIC_pin(apic
, pin
);
2798 memset(&entry1
, 0, sizeof(entry1
));
2800 entry1
.dest_mode
= 0; /* physical delivery */
2801 entry1
.mask
= 0; /* unmask IRQ now */
2802 entry1
.dest
= hard_smp_processor_id();
2803 entry1
.delivery_mode
= dest_ExtINT
;
2804 entry1
.polarity
= entry0
.polarity
;
2808 ioapic_write_entry(apic
, pin
, entry1
);
2810 save_control
= CMOS_READ(RTC_CONTROL
);
2811 save_freq_select
= CMOS_READ(RTC_FREQ_SELECT
);
2812 CMOS_WRITE((save_freq_select
& ~RTC_RATE_SELECT
) | 0x6,
2814 CMOS_WRITE(save_control
| RTC_PIE
, RTC_CONTROL
);
2819 if ((CMOS_READ(RTC_INTR_FLAGS
) & RTC_PF
) == RTC_PF
)
2823 CMOS_WRITE(save_control
, RTC_CONTROL
);
2824 CMOS_WRITE(save_freq_select
, RTC_FREQ_SELECT
);
2825 clear_IO_APIC_pin(apic
, pin
);
2827 ioapic_write_entry(apic
, pin
, entry0
);
2830 static int disable_timer_pin_1 __initdata
;
2831 /* Actually the next is obsolete, but keep it for paranoid reasons -AK */
2832 static int __init
disable_timer_pin_setup(char *arg
)
2834 disable_timer_pin_1
= 1;
2837 early_param("disable_timer_pin_1", disable_timer_pin_setup
);
2839 int timer_through_8259 __initdata
;
2842 * This code may look a bit paranoid, but it's supposed to cooperate with
2843 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
2844 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
2845 * fanatically on his truly buggy board.
2847 * FIXME: really need to revamp this for all platforms.
2849 static inline void __init
check_timer(void)
2851 struct irq_desc
*desc
= irq_to_desc(0);
2852 struct irq_cfg
*cfg
= desc
->chip_data
;
2853 int cpu
= boot_cpu_id
;
2854 int apic1
, pin1
, apic2
, pin2
;
2855 unsigned long flags
;
2859 local_irq_save(flags
);
2861 ver
= apic_read(APIC_LVR
);
2862 ver
= GET_APIC_VERSION(ver
);
2865 * get/set the timer IRQ vector:
2867 disable_8259A_irq(0);
2868 assign_irq_vector(0, cfg
, apic
->target_cpus());
2871 * As IRQ0 is to be enabled in the 8259A, the virtual
2872 * wire has to be disabled in the local APIC. Also
2873 * timer interrupts need to be acknowledged manually in
2874 * the 8259A for the i82489DX when using the NMI
2875 * watchdog as that APIC treats NMIs as level-triggered.
2876 * The AEOI mode will finish them in the 8259A
2879 apic_write(APIC_LVT0
, APIC_LVT_MASKED
| APIC_DM_EXTINT
);
2881 #ifdef CONFIG_X86_32
2882 timer_ack
= (nmi_watchdog
== NMI_IO_APIC
&& !APIC_INTEGRATED(ver
));
2885 pin1
= find_isa_irq_pin(0, mp_INT
);
2886 apic1
= find_isa_irq_apic(0, mp_INT
);
2887 pin2
= ioapic_i8259
.pin
;
2888 apic2
= ioapic_i8259
.apic
;
2890 apic_printk(APIC_QUIET
, KERN_INFO
"..TIMER: vector=0x%02X "
2891 "apic1=%d pin1=%d apic2=%d pin2=%d\n",
2892 cfg
->vector
, apic1
, pin1
, apic2
, pin2
);
2895 * Some BIOS writers are clueless and report the ExtINTA
2896 * I/O APIC input from the cascaded 8259A as the timer
2897 * interrupt input. So just in case, if only one pin
2898 * was found above, try it both directly and through the
2902 #ifdef CONFIG_INTR_REMAP
2903 if (intr_remapping_enabled
)
2904 panic("BIOS bug: timer not connected to IO-APIC");
2909 } else if (pin2
== -1) {
2916 * Ok, does IRQ0 through the IOAPIC work?
2919 add_pin_to_irq_cpu(cfg
, cpu
, apic1
, pin1
);
2920 setup_timer_IRQ0_pin(apic1
, pin1
, cfg
->vector
);
2922 unmask_IO_APIC_irq_desc(desc
);
2923 if (timer_irq_works()) {
2924 if (nmi_watchdog
== NMI_IO_APIC
) {
2926 enable_8259A_irq(0);
2928 if (disable_timer_pin_1
> 0)
2929 clear_IO_APIC_pin(0, pin1
);
2932 #ifdef CONFIG_INTR_REMAP
2933 if (intr_remapping_enabled
)
2934 panic("timer doesn't work through Interrupt-remapped IO-APIC");
2936 clear_IO_APIC_pin(apic1
, pin1
);
2938 apic_printk(APIC_QUIET
, KERN_ERR
"..MP-BIOS bug: "
2939 "8254 timer not connected to IO-APIC\n");
2941 apic_printk(APIC_QUIET
, KERN_INFO
"...trying to set up timer "
2942 "(IRQ0) through the 8259A ...\n");
2943 apic_printk(APIC_QUIET
, KERN_INFO
2944 "..... (found apic %d pin %d) ...\n", apic2
, pin2
);
2946 * legacy devices should be connected to IO APIC #0
2948 replace_pin_at_irq_cpu(cfg
, cpu
, apic1
, pin1
, apic2
, pin2
);
2949 setup_timer_IRQ0_pin(apic2
, pin2
, cfg
->vector
);
2950 unmask_IO_APIC_irq_desc(desc
);
2951 enable_8259A_irq(0);
2952 if (timer_irq_works()) {
2953 apic_printk(APIC_QUIET
, KERN_INFO
"....... works.\n");
2954 timer_through_8259
= 1;
2955 if (nmi_watchdog
== NMI_IO_APIC
) {
2956 disable_8259A_irq(0);
2958 enable_8259A_irq(0);
2963 * Cleanup, just in case ...
2965 disable_8259A_irq(0);
2966 clear_IO_APIC_pin(apic2
, pin2
);
2967 apic_printk(APIC_QUIET
, KERN_INFO
"....... failed.\n");
2970 if (nmi_watchdog
== NMI_IO_APIC
) {
2971 apic_printk(APIC_QUIET
, KERN_WARNING
"timer doesn't work "
2972 "through the IO-APIC - disabling NMI Watchdog!\n");
2973 nmi_watchdog
= NMI_NONE
;
2975 #ifdef CONFIG_X86_32
2979 apic_printk(APIC_QUIET
, KERN_INFO
2980 "...trying to set up timer as Virtual Wire IRQ...\n");
2982 lapic_register_intr(0, desc
);
2983 apic_write(APIC_LVT0
, APIC_DM_FIXED
| cfg
->vector
); /* Fixed mode */
2984 enable_8259A_irq(0);
2986 if (timer_irq_works()) {
2987 apic_printk(APIC_QUIET
, KERN_INFO
"..... works.\n");
2990 disable_8259A_irq(0);
2991 apic_write(APIC_LVT0
, APIC_LVT_MASKED
| APIC_DM_FIXED
| cfg
->vector
);
2992 apic_printk(APIC_QUIET
, KERN_INFO
"..... failed.\n");
2994 apic_printk(APIC_QUIET
, KERN_INFO
2995 "...trying to set up timer as ExtINT IRQ...\n");
2999 apic_write(APIC_LVT0
, APIC_DM_EXTINT
);
3001 unlock_ExtINT_logic();
3003 if (timer_irq_works()) {
3004 apic_printk(APIC_QUIET
, KERN_INFO
"..... works.\n");
3007 apic_printk(APIC_QUIET
, KERN_INFO
"..... failed :(.\n");
3008 panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
3009 "report. Then try booting with the 'noapic' option.\n");
3011 local_irq_restore(flags
);
3015 * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
3016 * to devices. However there may be an I/O APIC pin available for
3017 * this interrupt regardless. The pin may be left unconnected, but
3018 * typically it will be reused as an ExtINT cascade interrupt for
3019 * the master 8259A. In the MPS case such a pin will normally be
3020 * reported as an ExtINT interrupt in the MP table. With ACPI
3021 * there is no provision for ExtINT interrupts, and in the absence
3022 * of an override it would be treated as an ordinary ISA I/O APIC
3023 * interrupt, that is edge-triggered and unmasked by default. We
3024 * used to do this, but it caused problems on some systems because
3025 * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
3026 * the same ExtINT cascade interrupt to drive the local APIC of the
3027 * bootstrap processor. Therefore we refrain from routing IRQ2 to
3028 * the I/O APIC in all cases now. No actual device should request
3029 * it anyway. --macro
3031 #define PIC_IRQS (1 << PIC_CASCADE_IR)
3033 void __init
setup_IO_APIC(void)
3036 #ifdef CONFIG_X86_32
3040 * calling enable_IO_APIC() is moved to setup_local_APIC for BP
3044 io_apic_irqs
= ~PIC_IRQS
;
3046 apic_printk(APIC_VERBOSE
, "ENABLING IO-APIC IRQs\n");
3048 * Set up IO-APIC IRQ routing.
3050 #ifdef CONFIG_X86_32
3052 setup_ioapic_ids_from_mpc();
3055 setup_IO_APIC_irqs();
3056 init_IO_APIC_traps();
3061 * Called after all the initialization is done. If we didnt find any
3062 * APIC bugs then we can allow the modify fast path
3065 static int __init
io_apic_bug_finalize(void)
3067 if (sis_apic_bug
== -1)
3072 late_initcall(io_apic_bug_finalize
);
3074 struct sysfs_ioapic_data
{
3075 struct sys_device dev
;
3076 struct IO_APIC_route_entry entry
[0];
3078 static struct sysfs_ioapic_data
* mp_ioapic_data
[MAX_IO_APICS
];
3080 static int ioapic_suspend(struct sys_device
*dev
, pm_message_t state
)
3082 struct IO_APIC_route_entry
*entry
;
3083 struct sysfs_ioapic_data
*data
;
3086 data
= container_of(dev
, struct sysfs_ioapic_data
, dev
);
3087 entry
= data
->entry
;
3088 for (i
= 0; i
< nr_ioapic_registers
[dev
->id
]; i
++, entry
++ )
3089 *entry
= ioapic_read_entry(dev
->id
, i
);
3094 static int ioapic_resume(struct sys_device
*dev
)
3096 struct IO_APIC_route_entry
*entry
;
3097 struct sysfs_ioapic_data
*data
;
3098 unsigned long flags
;
3099 union IO_APIC_reg_00 reg_00
;
3102 data
= container_of(dev
, struct sysfs_ioapic_data
, dev
);
3103 entry
= data
->entry
;
3105 spin_lock_irqsave(&ioapic_lock
, flags
);
3106 reg_00
.raw
= io_apic_read(dev
->id
, 0);
3107 if (reg_00
.bits
.ID
!= mp_ioapics
[dev
->id
].apicid
) {
3108 reg_00
.bits
.ID
= mp_ioapics
[dev
->id
].apicid
;
3109 io_apic_write(dev
->id
, 0, reg_00
.raw
);
3111 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3112 for (i
= 0; i
< nr_ioapic_registers
[dev
->id
]; i
++)
3113 ioapic_write_entry(dev
->id
, i
, entry
[i
]);
3118 static struct sysdev_class ioapic_sysdev_class
= {
3120 .suspend
= ioapic_suspend
,
3121 .resume
= ioapic_resume
,
3124 static int __init
ioapic_init_sysfs(void)
3126 struct sys_device
* dev
;
3129 error
= sysdev_class_register(&ioapic_sysdev_class
);
3133 for (i
= 0; i
< nr_ioapics
; i
++ ) {
3134 size
= sizeof(struct sys_device
) + nr_ioapic_registers
[i
]
3135 * sizeof(struct IO_APIC_route_entry
);
3136 mp_ioapic_data
[i
] = kzalloc(size
, GFP_KERNEL
);
3137 if (!mp_ioapic_data
[i
]) {
3138 printk(KERN_ERR
"Can't suspend/resume IOAPIC %d\n", i
);
3141 dev
= &mp_ioapic_data
[i
]->dev
;
3143 dev
->cls
= &ioapic_sysdev_class
;
3144 error
= sysdev_register(dev
);
3146 kfree(mp_ioapic_data
[i
]);
3147 mp_ioapic_data
[i
] = NULL
;
3148 printk(KERN_ERR
"Can't suspend/resume IOAPIC %d\n", i
);
3156 device_initcall(ioapic_init_sysfs
);
3159 * Dynamic irq allocate and deallocation
3161 unsigned int create_irq_nr(unsigned int irq_want
)
3163 /* Allocate an unused irq */
3166 unsigned long flags
;
3167 struct irq_cfg
*cfg_new
= NULL
;
3168 int cpu
= boot_cpu_id
;
3169 struct irq_desc
*desc_new
= NULL
;
3172 spin_lock_irqsave(&vector_lock
, flags
);
3173 for (new = irq_want
; new < nr_irqs
; new++) {
3174 if (platform_legacy_irq(new))
3177 desc_new
= irq_to_desc_alloc_cpu(new, cpu
);
3179 printk(KERN_INFO
"can not get irq_desc for %d\n", new);
3182 cfg_new
= desc_new
->chip_data
;
3184 if (cfg_new
->vector
!= 0)
3186 if (__assign_irq_vector(new, cfg_new
, apic
->target_cpus()) == 0)
3190 spin_unlock_irqrestore(&vector_lock
, flags
);
3193 dynamic_irq_init(irq
);
3194 /* restore it, in case dynamic_irq_init clear it */
3196 desc_new
->chip_data
= cfg_new
;
3201 static int nr_irqs_gsi
= NR_IRQS_LEGACY
;
3202 int create_irq(void)
3204 unsigned int irq_want
;
3207 irq_want
= nr_irqs_gsi
;
3208 irq
= create_irq_nr(irq_want
);
3216 void destroy_irq(unsigned int irq
)
3218 unsigned long flags
;
3219 struct irq_cfg
*cfg
;
3220 struct irq_desc
*desc
;
3222 /* store it, in case dynamic_irq_cleanup clear it */
3223 desc
= irq_to_desc(irq
);
3224 cfg
= desc
->chip_data
;
3225 dynamic_irq_cleanup(irq
);
3226 /* connect back irq_cfg */
3228 desc
->chip_data
= cfg
;
3230 #ifdef CONFIG_INTR_REMAP
3233 spin_lock_irqsave(&vector_lock
, flags
);
3234 __clear_irq_vector(irq
, cfg
);
3235 spin_unlock_irqrestore(&vector_lock
, flags
);
3239 * MSI message composition
3241 #ifdef CONFIG_PCI_MSI
3242 static int msi_compose_msg(struct pci_dev
*pdev
, unsigned int irq
, struct msi_msg
*msg
)
3244 struct irq_cfg
*cfg
;
3252 err
= assign_irq_vector(irq
, cfg
, apic
->target_cpus());
3256 dest
= apic
->cpu_mask_to_apicid_and(cfg
->domain
, apic
->target_cpus());
3258 #ifdef CONFIG_INTR_REMAP
3259 if (irq_remapped(irq
)) {
3264 ir_index
= map_irq_to_irte_handle(irq
, &sub_handle
);
3265 BUG_ON(ir_index
== -1);
3267 memset (&irte
, 0, sizeof(irte
));
3270 irte
.dst_mode
= apic
->irq_dest_mode
;
3271 irte
.trigger_mode
= 0; /* edge */
3272 irte
.dlvry_mode
= apic
->irq_delivery_mode
;
3273 irte
.vector
= cfg
->vector
;
3274 irte
.dest_id
= IRTE_DEST(dest
);
3276 modify_irte(irq
, &irte
);
3278 msg
->address_hi
= MSI_ADDR_BASE_HI
;
3279 msg
->data
= sub_handle
;
3280 msg
->address_lo
= MSI_ADDR_BASE_LO
| MSI_ADDR_IR_EXT_INT
|
3282 MSI_ADDR_IR_INDEX1(ir_index
) |
3283 MSI_ADDR_IR_INDEX2(ir_index
);
3287 msg
->address_hi
= MSI_ADDR_BASE_HI
;
3290 ((apic
->irq_dest_mode
== 0) ?
3291 MSI_ADDR_DEST_MODE_PHYSICAL
:
3292 MSI_ADDR_DEST_MODE_LOGICAL
) |
3293 ((apic
->irq_delivery_mode
!= dest_LowestPrio
) ?
3294 MSI_ADDR_REDIRECTION_CPU
:
3295 MSI_ADDR_REDIRECTION_LOWPRI
) |
3296 MSI_ADDR_DEST_ID(dest
);
3299 MSI_DATA_TRIGGER_EDGE
|
3300 MSI_DATA_LEVEL_ASSERT
|
3301 ((apic
->irq_delivery_mode
!= dest_LowestPrio
) ?
3302 MSI_DATA_DELIVERY_FIXED
:
3303 MSI_DATA_DELIVERY_LOWPRI
) |
3304 MSI_DATA_VECTOR(cfg
->vector
);
3310 static void set_msi_irq_affinity(unsigned int irq
, const struct cpumask
*mask
)
3312 struct irq_desc
*desc
= irq_to_desc(irq
);
3313 struct irq_cfg
*cfg
;
3317 dest
= set_desc_affinity(desc
, mask
);
3318 if (dest
== BAD_APICID
)
3321 cfg
= desc
->chip_data
;
3323 read_msi_msg_desc(desc
, &msg
);
3325 msg
.data
&= ~MSI_DATA_VECTOR_MASK
;
3326 msg
.data
|= MSI_DATA_VECTOR(cfg
->vector
);
3327 msg
.address_lo
&= ~MSI_ADDR_DEST_ID_MASK
;
3328 msg
.address_lo
|= MSI_ADDR_DEST_ID(dest
);
3330 write_msi_msg_desc(desc
, &msg
);
3332 #ifdef CONFIG_INTR_REMAP
3334 * Migrate the MSI irq to another cpumask. This migration is
3335 * done in the process context using interrupt-remapping hardware.
3338 ir_set_msi_irq_affinity(unsigned int irq
, const struct cpumask
*mask
)
3340 struct irq_desc
*desc
= irq_to_desc(irq
);
3341 struct irq_cfg
*cfg
= desc
->chip_data
;
3345 if (get_irte(irq
, &irte
))
3348 dest
= set_desc_affinity(desc
, mask
);
3349 if (dest
== BAD_APICID
)
3352 irte
.vector
= cfg
->vector
;
3353 irte
.dest_id
= IRTE_DEST(dest
);
3356 * atomically update the IRTE with the new destination and vector.
3358 modify_irte(irq
, &irte
);
3361 * After this point, all the interrupts will start arriving
3362 * at the new destination. So, time to cleanup the previous
3363 * vector allocation.
3365 if (cfg
->move_in_progress
)
3366 send_cleanup_vector(cfg
);
3370 #endif /* CONFIG_SMP */
3373 * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
3374 * which implement the MSI or MSI-X Capability Structure.
3376 static struct irq_chip msi_chip
= {
3378 .unmask
= unmask_msi_irq
,
3379 .mask
= mask_msi_irq
,
3380 .ack
= ack_apic_edge
,
3382 .set_affinity
= set_msi_irq_affinity
,
3384 .retrigger
= ioapic_retrigger_irq
,
3387 #ifdef CONFIG_INTR_REMAP
3388 static struct irq_chip msi_ir_chip
= {
3389 .name
= "IR-PCI-MSI",
3390 .unmask
= unmask_msi_irq
,
3391 .mask
= mask_msi_irq
,
3392 .ack
= ack_x2apic_edge
,
3394 .set_affinity
= ir_set_msi_irq_affinity
,
3396 .retrigger
= ioapic_retrigger_irq
,
3400 * Map the PCI dev to the corresponding remapping hardware unit
3401 * and allocate 'nvec' consecutive interrupt-remapping table entries
3404 static int msi_alloc_irte(struct pci_dev
*dev
, int irq
, int nvec
)
3406 struct intel_iommu
*iommu
;
3409 iommu
= map_dev_to_ir(dev
);
3412 "Unable to map PCI %s to iommu\n", pci_name(dev
));
3416 index
= alloc_irte(iommu
, irq
, nvec
);
3419 "Unable to allocate %d IRTE for PCI %s\n", nvec
,
3427 static int setup_msi_irq(struct pci_dev
*dev
, struct msi_desc
*msidesc
, int irq
)
3432 ret
= msi_compose_msg(dev
, irq
, &msg
);
3436 set_irq_msi(irq
, msidesc
);
3437 write_msi_msg(irq
, &msg
);
3439 #ifdef CONFIG_INTR_REMAP
3440 if (irq_remapped(irq
)) {
3441 struct irq_desc
*desc
= irq_to_desc(irq
);
3443 * irq migration in process context
3445 desc
->status
|= IRQ_MOVE_PCNTXT
;
3446 set_irq_chip_and_handler_name(irq
, &msi_ir_chip
, handle_edge_irq
, "edge");
3449 set_irq_chip_and_handler_name(irq
, &msi_chip
, handle_edge_irq
, "edge");
3451 dev_printk(KERN_DEBUG
, &dev
->dev
, "irq %d for MSI/MSI-X\n", irq
);
3456 int arch_setup_msi_irqs(struct pci_dev
*dev
, int nvec
, int type
)
3459 int ret
, sub_handle
;
3460 struct msi_desc
*msidesc
;
3461 unsigned int irq_want
;
3463 #ifdef CONFIG_INTR_REMAP
3464 struct intel_iommu
*iommu
= 0;
3468 irq_want
= nr_irqs_gsi
;
3470 list_for_each_entry(msidesc
, &dev
->msi_list
, list
) {
3471 irq
= create_irq_nr(irq_want
);
3475 #ifdef CONFIG_INTR_REMAP
3476 if (!intr_remapping_enabled
)
3481 * allocate the consecutive block of IRTE's
3484 index
= msi_alloc_irte(dev
, irq
, nvec
);
3490 iommu
= map_dev_to_ir(dev
);
3496 * setup the mapping between the irq and the IRTE
3497 * base index, the sub_handle pointing to the
3498 * appropriate interrupt remap table entry.
3500 set_irte_irq(irq
, iommu
, index
, sub_handle
);
3504 ret
= setup_msi_irq(dev
, msidesc
, irq
);
3516 void arch_teardown_msi_irq(unsigned int irq
)
3523 static void dmar_msi_set_affinity(unsigned int irq
, const struct cpumask
*mask
)
3525 struct irq_desc
*desc
= irq_to_desc(irq
);
3526 struct irq_cfg
*cfg
;
3530 dest
= set_desc_affinity(desc
, mask
);
3531 if (dest
== BAD_APICID
)
3534 cfg
= desc
->chip_data
;
3536 dmar_msi_read(irq
, &msg
);
3538 msg
.data
&= ~MSI_DATA_VECTOR_MASK
;
3539 msg
.data
|= MSI_DATA_VECTOR(cfg
->vector
);
3540 msg
.address_lo
&= ~MSI_ADDR_DEST_ID_MASK
;
3541 msg
.address_lo
|= MSI_ADDR_DEST_ID(dest
);
3543 dmar_msi_write(irq
, &msg
);
3546 #endif /* CONFIG_SMP */
3548 struct irq_chip dmar_msi_type
= {
3550 .unmask
= dmar_msi_unmask
,
3551 .mask
= dmar_msi_mask
,
3552 .ack
= ack_apic_edge
,
3554 .set_affinity
= dmar_msi_set_affinity
,
3556 .retrigger
= ioapic_retrigger_irq
,
3559 int arch_setup_dmar_msi(unsigned int irq
)
3564 ret
= msi_compose_msg(NULL
, irq
, &msg
);
3567 dmar_msi_write(irq
, &msg
);
3568 set_irq_chip_and_handler_name(irq
, &dmar_msi_type
, handle_edge_irq
,
3574 #ifdef CONFIG_HPET_TIMER
3577 static void hpet_msi_set_affinity(unsigned int irq
, const struct cpumask
*mask
)
3579 struct irq_desc
*desc
= irq_to_desc(irq
);
3580 struct irq_cfg
*cfg
;
3584 dest
= set_desc_affinity(desc
, mask
);
3585 if (dest
== BAD_APICID
)
3588 cfg
= desc
->chip_data
;
3590 hpet_msi_read(irq
, &msg
);
3592 msg
.data
&= ~MSI_DATA_VECTOR_MASK
;
3593 msg
.data
|= MSI_DATA_VECTOR(cfg
->vector
);
3594 msg
.address_lo
&= ~MSI_ADDR_DEST_ID_MASK
;
3595 msg
.address_lo
|= MSI_ADDR_DEST_ID(dest
);
3597 hpet_msi_write(irq
, &msg
);
3600 #endif /* CONFIG_SMP */
3602 struct irq_chip hpet_msi_type
= {
3604 .unmask
= hpet_msi_unmask
,
3605 .mask
= hpet_msi_mask
,
3606 .ack
= ack_apic_edge
,
3608 .set_affinity
= hpet_msi_set_affinity
,
3610 .retrigger
= ioapic_retrigger_irq
,
3613 int arch_setup_hpet_msi(unsigned int irq
)
3618 ret
= msi_compose_msg(NULL
, irq
, &msg
);
3622 hpet_msi_write(irq
, &msg
);
3623 set_irq_chip_and_handler_name(irq
, &hpet_msi_type
, handle_edge_irq
,
3630 #endif /* CONFIG_PCI_MSI */
3632 * Hypertransport interrupt support
3634 #ifdef CONFIG_HT_IRQ
3638 static void target_ht_irq(unsigned int irq
, unsigned int dest
, u8 vector
)
3640 struct ht_irq_msg msg
;
3641 fetch_ht_irq_msg(irq
, &msg
);
3643 msg
.address_lo
&= ~(HT_IRQ_LOW_VECTOR_MASK
| HT_IRQ_LOW_DEST_ID_MASK
);
3644 msg
.address_hi
&= ~(HT_IRQ_HIGH_DEST_ID_MASK
);
3646 msg
.address_lo
|= HT_IRQ_LOW_VECTOR(vector
) | HT_IRQ_LOW_DEST_ID(dest
);
3647 msg
.address_hi
|= HT_IRQ_HIGH_DEST_ID(dest
);
3649 write_ht_irq_msg(irq
, &msg
);
3652 static void set_ht_irq_affinity(unsigned int irq
, const struct cpumask
*mask
)
3654 struct irq_desc
*desc
= irq_to_desc(irq
);
3655 struct irq_cfg
*cfg
;
3658 dest
= set_desc_affinity(desc
, mask
);
3659 if (dest
== BAD_APICID
)
3662 cfg
= desc
->chip_data
;
3664 target_ht_irq(irq
, dest
, cfg
->vector
);
3669 static struct irq_chip ht_irq_chip
= {
3671 .mask
= mask_ht_irq
,
3672 .unmask
= unmask_ht_irq
,
3673 .ack
= ack_apic_edge
,
3675 .set_affinity
= set_ht_irq_affinity
,
3677 .retrigger
= ioapic_retrigger_irq
,
3680 int arch_setup_ht_irq(unsigned int irq
, struct pci_dev
*dev
)
3682 struct irq_cfg
*cfg
;
3689 err
= assign_irq_vector(irq
, cfg
, apic
->target_cpus());
3691 struct ht_irq_msg msg
;
3694 dest
= apic
->cpu_mask_to_apicid_and(cfg
->domain
,
3695 apic
->target_cpus());
3697 msg
.address_hi
= HT_IRQ_HIGH_DEST_ID(dest
);
3701 HT_IRQ_LOW_DEST_ID(dest
) |
3702 HT_IRQ_LOW_VECTOR(cfg
->vector
) |
3703 ((apic
->irq_dest_mode
== 0) ?
3704 HT_IRQ_LOW_DM_PHYSICAL
:
3705 HT_IRQ_LOW_DM_LOGICAL
) |
3706 HT_IRQ_LOW_RQEOI_EDGE
|
3707 ((apic
->irq_delivery_mode
!= dest_LowestPrio
) ?
3708 HT_IRQ_LOW_MT_FIXED
:
3709 HT_IRQ_LOW_MT_ARBITRATED
) |
3710 HT_IRQ_LOW_IRQ_MASKED
;
3712 write_ht_irq_msg(irq
, &msg
);
3714 set_irq_chip_and_handler_name(irq
, &ht_irq_chip
,
3715 handle_edge_irq
, "edge");
3717 dev_printk(KERN_DEBUG
, &dev
->dev
, "irq %d for HT\n", irq
);
3721 #endif /* CONFIG_HT_IRQ */
3723 #ifdef CONFIG_X86_UV
3725 * Re-target the irq to the specified CPU and enable the specified MMR located
3726 * on the specified blade to allow the sending of MSIs to the specified CPU.
3728 int arch_enable_uv_irq(char *irq_name
, unsigned int irq
, int cpu
, int mmr_blade
,
3729 unsigned long mmr_offset
)
3731 const struct cpumask
*eligible_cpu
= cpumask_of(cpu
);
3732 struct irq_cfg
*cfg
;
3734 unsigned long mmr_value
;
3735 struct uv_IO_APIC_route_entry
*entry
;
3736 unsigned long flags
;
3741 err
= assign_irq_vector(irq
, cfg
, eligible_cpu
);
3745 spin_lock_irqsave(&vector_lock
, flags
);
3746 set_irq_chip_and_handler_name(irq
, &uv_irq_chip
, handle_percpu_irq
,
3748 spin_unlock_irqrestore(&vector_lock
, flags
);
3751 entry
= (struct uv_IO_APIC_route_entry
*)&mmr_value
;
3752 BUG_ON(sizeof(struct uv_IO_APIC_route_entry
) != sizeof(unsigned long));
3754 entry
->vector
= cfg
->vector
;
3755 entry
->delivery_mode
= apic
->irq_delivery_mode
;
3756 entry
->dest_mode
= apic
->irq_dest_mode
;
3757 entry
->polarity
= 0;
3760 entry
->dest
= apic
->cpu_mask_to_apicid(eligible_cpu
);
3762 mmr_pnode
= uv_blade_to_pnode(mmr_blade
);
3763 uv_write_global_mmr64(mmr_pnode
, mmr_offset
, mmr_value
);
3769 * Disable the specified MMR located on the specified blade so that MSIs are
3770 * longer allowed to be sent.
3772 void arch_disable_uv_irq(int mmr_blade
, unsigned long mmr_offset
)
3774 unsigned long mmr_value
;
3775 struct uv_IO_APIC_route_entry
*entry
;
3779 entry
= (struct uv_IO_APIC_route_entry
*)&mmr_value
;
3780 BUG_ON(sizeof(struct uv_IO_APIC_route_entry
) != sizeof(unsigned long));
3784 mmr_pnode
= uv_blade_to_pnode(mmr_blade
);
3785 uv_write_global_mmr64(mmr_pnode
, mmr_offset
, mmr_value
);
3787 #endif /* CONFIG_X86_64 */
3789 int __init
io_apic_get_redir_entries (int ioapic
)
3791 union IO_APIC_reg_01 reg_01
;
3792 unsigned long flags
;
3794 spin_lock_irqsave(&ioapic_lock
, flags
);
3795 reg_01
.raw
= io_apic_read(ioapic
, 1);
3796 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3798 return reg_01
.bits
.entries
;
3801 void __init
probe_nr_irqs_gsi(void)
3806 for (idx
= 0; idx
< nr_ioapics
; idx
++)
3807 nr
+= io_apic_get_redir_entries(idx
) + 1;
3809 if (nr
> nr_irqs_gsi
)
3813 #ifdef CONFIG_SPARSE_IRQ
3814 int __init
arch_probe_nr_irqs(void)
3818 nr
= ((8 * nr_cpu_ids
) > (32 * nr_ioapics
) ?
3819 (NR_VECTORS
+ (8 * nr_cpu_ids
)) :
3820 (NR_VECTORS
+ (32 * nr_ioapics
)));
3822 if (nr
< nr_irqs
&& nr
> nr_irqs_gsi
)
3829 /* --------------------------------------------------------------------------
3830 ACPI-based IOAPIC Configuration
3831 -------------------------------------------------------------------------- */
3835 #ifdef CONFIG_X86_32
3836 int __init
io_apic_get_unique_id(int ioapic
, int apic_id
)
3838 union IO_APIC_reg_00 reg_00
;
3839 static physid_mask_t apic_id_map
= PHYSID_MASK_NONE
;
3841 unsigned long flags
;
3845 * The P4 platform supports up to 256 APIC IDs on two separate APIC
3846 * buses (one for LAPICs, one for IOAPICs), where predecessors only
3847 * supports up to 16 on one shared APIC bus.
3849 * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
3850 * advantage of new APIC bus architecture.
3853 if (physids_empty(apic_id_map
))
3854 apic_id_map
= apic
->ioapic_phys_id_map(phys_cpu_present_map
);
3856 spin_lock_irqsave(&ioapic_lock
, flags
);
3857 reg_00
.raw
= io_apic_read(ioapic
, 0);
3858 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3860 if (apic_id
>= get_physical_broadcast()) {
3861 printk(KERN_WARNING
"IOAPIC[%d]: Invalid apic_id %d, trying "
3862 "%d\n", ioapic
, apic_id
, reg_00
.bits
.ID
);
3863 apic_id
= reg_00
.bits
.ID
;
3867 * Every APIC in a system must have a unique ID or we get lots of nice
3868 * 'stuck on smp_invalidate_needed IPI wait' messages.
3870 if (apic
->check_apicid_used(apic_id_map
, apic_id
)) {
3872 for (i
= 0; i
< get_physical_broadcast(); i
++) {
3873 if (!apic
->check_apicid_used(apic_id_map
, i
))
3877 if (i
== get_physical_broadcast())
3878 panic("Max apic_id exceeded!\n");
3880 printk(KERN_WARNING
"IOAPIC[%d]: apic_id %d already used, "
3881 "trying %d\n", ioapic
, apic_id
, i
);
3886 tmp
= apic
->apicid_to_cpu_present(apic_id
);
3887 physids_or(apic_id_map
, apic_id_map
, tmp
);
3889 if (reg_00
.bits
.ID
!= apic_id
) {
3890 reg_00
.bits
.ID
= apic_id
;
3892 spin_lock_irqsave(&ioapic_lock
, flags
);
3893 io_apic_write(ioapic
, 0, reg_00
.raw
);
3894 reg_00
.raw
= io_apic_read(ioapic
, 0);
3895 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3898 if (reg_00
.bits
.ID
!= apic_id
) {
3899 printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic
);
3904 apic_printk(APIC_VERBOSE
, KERN_INFO
3905 "IOAPIC[%d]: Assigned apic_id %d\n", ioapic
, apic_id
);
3910 int __init
io_apic_get_version(int ioapic
)
3912 union IO_APIC_reg_01 reg_01
;
3913 unsigned long flags
;
3915 spin_lock_irqsave(&ioapic_lock
, flags
);
3916 reg_01
.raw
= io_apic_read(ioapic
, 1);
3917 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3919 return reg_01
.bits
.version
;
3923 int io_apic_set_pci_routing (int ioapic
, int pin
, int irq
, int triggering
, int polarity
)
3925 struct irq_desc
*desc
;
3926 struct irq_cfg
*cfg
;
3927 int cpu
= boot_cpu_id
;
3929 if (!IO_APIC_IRQ(irq
)) {
3930 apic_printk(APIC_QUIET
,KERN_ERR
"IOAPIC[%d]: Invalid reference to IRQ 0\n",
3935 desc
= irq_to_desc_alloc_cpu(irq
, cpu
);
3937 printk(KERN_INFO
"can not get irq_desc %d\n", irq
);
3942 * IRQs < 16 are already in the irq_2_pin[] map
3944 if (irq
>= NR_IRQS_LEGACY
) {
3945 cfg
= desc
->chip_data
;
3946 add_pin_to_irq_cpu(cfg
, cpu
, ioapic
, pin
);
3949 setup_IO_APIC_irq(ioapic
, pin
, irq
, desc
, triggering
, polarity
);
3955 int acpi_get_override_irq(int bus_irq
, int *trigger
, int *polarity
)
3959 if (skip_ioapic_setup
)
3962 for (i
= 0; i
< mp_irq_entries
; i
++)
3963 if (mp_irqs
[i
].irqtype
== mp_INT
&&
3964 mp_irqs
[i
].srcbusirq
== bus_irq
)
3966 if (i
>= mp_irq_entries
)
3969 *trigger
= irq_trigger(i
);
3970 *polarity
= irq_polarity(i
);
3974 #endif /* CONFIG_ACPI */
3977 * This function currently is only a helper for the i386 smp boot process where
3978 * we need to reprogram the ioredtbls to cater for the cpus which have come online
3979 * so mask in all cases should simply be apic->target_cpus()
3982 void __init
setup_ioapic_dest(void)
3984 int pin
, ioapic
, irq
, irq_entry
;
3985 struct irq_desc
*desc
;
3986 struct irq_cfg
*cfg
;
3987 const struct cpumask
*mask
;
3989 if (skip_ioapic_setup
== 1)
3992 for (ioapic
= 0; ioapic
< nr_ioapics
; ioapic
++) {
3993 for (pin
= 0; pin
< nr_ioapic_registers
[ioapic
]; pin
++) {
3994 irq_entry
= find_irq_entry(ioapic
, pin
, mp_INT
);
3995 if (irq_entry
== -1)
3997 irq
= pin_2_irq(irq_entry
, ioapic
, pin
);
3999 /* setup_IO_APIC_irqs could fail to get vector for some device
4000 * when you have too many devices, because at that time only boot
4003 desc
= irq_to_desc(irq
);
4004 cfg
= desc
->chip_data
;
4006 setup_IO_APIC_irq(ioapic
, pin
, irq
, desc
,
4007 irq_trigger(irq_entry
),
4008 irq_polarity(irq_entry
));
4014 * Honour affinities which have been set in early boot
4017 (IRQ_NO_BALANCING
| IRQ_AFFINITY_SET
))
4018 mask
= desc
->affinity
;
4020 mask
= apic
->target_cpus();
4022 #ifdef CONFIG_INTR_REMAP
4023 if (intr_remapping_enabled
)
4024 set_ir_ioapic_affinity_irq_desc(desc
, mask
);
4027 set_ioapic_affinity_irq_desc(desc
, mask
);
4034 #define IOAPIC_RESOURCE_NAME_SIZE 11
4036 static struct resource
*ioapic_resources
;
4038 static struct resource
* __init
ioapic_setup_resources(void)
4041 struct resource
*res
;
4045 if (nr_ioapics
<= 0)
4048 n
= IOAPIC_RESOURCE_NAME_SIZE
+ sizeof(struct resource
);
4051 mem
= alloc_bootmem(n
);
4055 mem
+= sizeof(struct resource
) * nr_ioapics
;
4057 for (i
= 0; i
< nr_ioapics
; i
++) {
4059 res
[i
].flags
= IORESOURCE_MEM
| IORESOURCE_BUSY
;
4060 sprintf(mem
, "IOAPIC %u", i
);
4061 mem
+= IOAPIC_RESOURCE_NAME_SIZE
;
4065 ioapic_resources
= res
;
4070 void __init
ioapic_init_mappings(void)
4072 unsigned long ioapic_phys
, idx
= FIX_IO_APIC_BASE_0
;
4073 struct resource
*ioapic_res
;
4076 ioapic_res
= ioapic_setup_resources();
4077 for (i
= 0; i
< nr_ioapics
; i
++) {
4078 if (smp_found_config
) {
4079 ioapic_phys
= mp_ioapics
[i
].apicaddr
;
4080 #ifdef CONFIG_X86_32
4083 "WARNING: bogus zero IO-APIC "
4084 "address found in MPTABLE, "
4085 "disabling IO/APIC support!\n");
4086 smp_found_config
= 0;
4087 skip_ioapic_setup
= 1;
4088 goto fake_ioapic_page
;
4092 #ifdef CONFIG_X86_32
4095 ioapic_phys
= (unsigned long)
4096 alloc_bootmem_pages(PAGE_SIZE
);
4097 ioapic_phys
= __pa(ioapic_phys
);
4099 set_fixmap_nocache(idx
, ioapic_phys
);
4100 apic_printk(APIC_VERBOSE
,
4101 "mapped IOAPIC to %08lx (%08lx)\n",
4102 __fix_to_virt(idx
), ioapic_phys
);
4105 if (ioapic_res
!= NULL
) {
4106 ioapic_res
->start
= ioapic_phys
;
4107 ioapic_res
->end
= ioapic_phys
+ (4 * 1024) - 1;
4113 static int __init
ioapic_insert_resources(void)
4116 struct resource
*r
= ioapic_resources
;
4120 "IO APIC resources could be not be allocated.\n");
4124 for (i
= 0; i
< nr_ioapics
; i
++) {
4125 insert_resource(&iomem_resource
, r
);
4132 /* Insert the IO APIC resources after PCI initialization has occured to handle
4133 * IO APICS that are mapped in on a BAR in PCI space. */
4134 late_initcall(ioapic_insert_resources
);