2 * Intel IO-APIC support for multi-Pentium hosts.
4 * Copyright (C) 1997, 1998, 1999, 2000, 2009 Ingo Molnar, Hajnalka Szabo
6 * Many thanks to Stig Venaas for trying out countless experimental
7 * patches and reporting/debugging problems patiently!
9 * (c) 1999, Multiple IO-APIC support, developed by
10 * Ken-ichi Yaku <yaku@css1.kbnes.nec.co.jp> and
11 * Hidemi Kishimoto <kisimoto@css1.kbnes.nec.co.jp>,
12 * further tested and cleaned up by Zach Brown <zab@redhat.com>
13 * and Ingo Molnar <mingo@redhat.com>
16 * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
17 * thanks to Eric Gilmore
19 * for testing these extensively
20 * Paul Diefenbaugh : Added full ACPI support
24 #include <linux/interrupt.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/sched.h>
28 #include <linux/pci.h>
29 #include <linux/mc146818rtc.h>
30 #include <linux/compiler.h>
31 #include <linux/acpi.h>
32 #include <linux/module.h>
33 #include <linux/sysdev.h>
34 #include <linux/msi.h>
35 #include <linux/htirq.h>
36 #include <linux/freezer.h>
37 #include <linux/kthread.h>
38 #include <linux/jiffies.h> /* time_after() */
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>
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 void arch_disable_smp_support(void)
105 noioapicreroute
= -1;
107 skip_ioapic_setup
= 1;
110 static int __init
parse_noapic(char *str
)
112 /* disable IO-APIC */
113 arch_disable_smp_support();
116 early_param("noapic", parse_noapic
);
121 * This is performance-critical, we want to do it O(1)
123 * the indexing order of this array favors 1:1 mappings
124 * between pins and IRQs.
127 struct irq_pin_list
{
129 struct irq_pin_list
*next
;
132 static struct irq_pin_list
*get_one_free_irq_2_pin(int cpu
)
134 struct irq_pin_list
*pin
;
137 node
= cpu_to_node(cpu
);
139 pin
= kzalloc_node(sizeof(*pin
), GFP_ATOMIC
, node
);
145 struct irq_pin_list
*irq_2_pin
;
146 cpumask_var_t domain
;
147 cpumask_var_t old_domain
;
148 unsigned move_cleanup_count
;
150 u8 move_in_progress
: 1;
153 /* irq_cfg is indexed by the sum of all RTEs in all I/O APICs. */
154 #ifdef CONFIG_SPARSE_IRQ
155 static struct irq_cfg irq_cfgx
[] = {
157 static struct irq_cfg irq_cfgx
[NR_IRQS
] = {
159 [0] = { .vector
= IRQ0_VECTOR
, },
160 [1] = { .vector
= IRQ1_VECTOR
, },
161 [2] = { .vector
= IRQ2_VECTOR
, },
162 [3] = { .vector
= IRQ3_VECTOR
, },
163 [4] = { .vector
= IRQ4_VECTOR
, },
164 [5] = { .vector
= IRQ5_VECTOR
, },
165 [6] = { .vector
= IRQ6_VECTOR
, },
166 [7] = { .vector
= IRQ7_VECTOR
, },
167 [8] = { .vector
= IRQ8_VECTOR
, },
168 [9] = { .vector
= IRQ9_VECTOR
, },
169 [10] = { .vector
= IRQ10_VECTOR
, },
170 [11] = { .vector
= IRQ11_VECTOR
, },
171 [12] = { .vector
= IRQ12_VECTOR
, },
172 [13] = { .vector
= IRQ13_VECTOR
, },
173 [14] = { .vector
= IRQ14_VECTOR
, },
174 [15] = { .vector
= IRQ15_VECTOR
, },
177 int __init
arch_early_irq_init(void)
180 struct irq_desc
*desc
;
185 count
= ARRAY_SIZE(irq_cfgx
);
187 for (i
= 0; i
< count
; i
++) {
188 desc
= irq_to_desc(i
);
189 desc
->chip_data
= &cfg
[i
];
190 alloc_bootmem_cpumask_var(&cfg
[i
].domain
);
191 alloc_bootmem_cpumask_var(&cfg
[i
].old_domain
);
192 if (i
< NR_IRQS_LEGACY
)
193 cpumask_setall(cfg
[i
].domain
);
199 #ifdef CONFIG_SPARSE_IRQ
200 static struct irq_cfg
*irq_cfg(unsigned int irq
)
202 struct irq_cfg
*cfg
= NULL
;
203 struct irq_desc
*desc
;
205 desc
= irq_to_desc(irq
);
207 cfg
= desc
->chip_data
;
212 static struct irq_cfg
*get_one_free_irq_cfg(int cpu
)
217 node
= cpu_to_node(cpu
);
219 cfg
= kzalloc_node(sizeof(*cfg
), GFP_ATOMIC
, node
);
221 if (!alloc_cpumask_var_node(&cfg
->domain
, GFP_ATOMIC
, node
)) {
224 } else if (!alloc_cpumask_var_node(&cfg
->old_domain
,
226 free_cpumask_var(cfg
->domain
);
230 cpumask_clear(cfg
->domain
);
231 cpumask_clear(cfg
->old_domain
);
238 int arch_init_chip_data(struct irq_desc
*desc
, int cpu
)
242 cfg
= desc
->chip_data
;
244 desc
->chip_data
= get_one_free_irq_cfg(cpu
);
245 if (!desc
->chip_data
) {
246 printk(KERN_ERR
"can not alloc irq_cfg\n");
254 /* for move_irq_desc */
256 init_copy_irq_2_pin(struct irq_cfg
*old_cfg
, struct irq_cfg
*cfg
, int cpu
)
258 struct irq_pin_list
*old_entry
, *head
, *tail
, *entry
;
260 cfg
->irq_2_pin
= NULL
;
261 old_entry
= old_cfg
->irq_2_pin
;
265 entry
= get_one_free_irq_2_pin(cpu
);
269 entry
->apic
= old_entry
->apic
;
270 entry
->pin
= old_entry
->pin
;
273 old_entry
= old_entry
->next
;
275 entry
= get_one_free_irq_2_pin(cpu
);
283 /* still use the old one */
286 entry
->apic
= old_entry
->apic
;
287 entry
->pin
= old_entry
->pin
;
290 old_entry
= old_entry
->next
;
294 cfg
->irq_2_pin
= head
;
297 static void free_irq_2_pin(struct irq_cfg
*old_cfg
, struct irq_cfg
*cfg
)
299 struct irq_pin_list
*entry
, *next
;
301 if (old_cfg
->irq_2_pin
== cfg
->irq_2_pin
)
304 entry
= old_cfg
->irq_2_pin
;
311 old_cfg
->irq_2_pin
= NULL
;
314 void arch_init_copy_chip_data(struct irq_desc
*old_desc
,
315 struct irq_desc
*desc
, int cpu
)
318 struct irq_cfg
*old_cfg
;
320 cfg
= get_one_free_irq_cfg(cpu
);
325 desc
->chip_data
= cfg
;
327 old_cfg
= old_desc
->chip_data
;
329 memcpy(cfg
, old_cfg
, sizeof(struct irq_cfg
));
331 init_copy_irq_2_pin(old_cfg
, cfg
, cpu
);
334 static void free_irq_cfg(struct irq_cfg
*old_cfg
)
339 void arch_free_chip_data(struct irq_desc
*old_desc
, struct irq_desc
*desc
)
341 struct irq_cfg
*old_cfg
, *cfg
;
343 old_cfg
= old_desc
->chip_data
;
344 cfg
= desc
->chip_data
;
350 free_irq_2_pin(old_cfg
, cfg
);
351 free_irq_cfg(old_cfg
);
352 old_desc
->chip_data
= NULL
;
355 /* end for move_irq_desc */
358 static struct irq_cfg
*irq_cfg(unsigned int irq
)
360 return irq
< nr_irqs
? irq_cfgx
+ irq
: NULL
;
367 unsigned int unused
[3];
369 unsigned int unused2
[11];
373 static __attribute_const__
struct io_apic __iomem
*io_apic_base(int idx
)
375 return (void __iomem
*) __fix_to_virt(FIX_IO_APIC_BASE_0
+ idx
)
376 + (mp_ioapics
[idx
].apicaddr
& ~PAGE_MASK
);
379 static inline void io_apic_eoi(unsigned int apic
, unsigned int vector
)
381 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
382 writel(vector
, &io_apic
->eoi
);
385 static inline unsigned int io_apic_read(unsigned int apic
, unsigned int reg
)
387 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
388 writel(reg
, &io_apic
->index
);
389 return readl(&io_apic
->data
);
392 static inline void io_apic_write(unsigned int apic
, unsigned int reg
, unsigned int value
)
394 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
395 writel(reg
, &io_apic
->index
);
396 writel(value
, &io_apic
->data
);
400 * Re-write a value: to be used for read-modify-write
401 * cycles where the read already set up the index register.
403 * Older SiS APIC requires we rewrite the index register
405 static inline void io_apic_modify(unsigned int apic
, unsigned int reg
, unsigned int value
)
407 struct io_apic __iomem
*io_apic
= io_apic_base(apic
);
410 writel(reg
, &io_apic
->index
);
411 writel(value
, &io_apic
->data
);
414 static bool io_apic_level_ack_pending(struct irq_cfg
*cfg
)
416 struct irq_pin_list
*entry
;
419 spin_lock_irqsave(&ioapic_lock
, flags
);
420 entry
= cfg
->irq_2_pin
;
428 reg
= io_apic_read(entry
->apic
, 0x10 + pin
*2);
429 /* Is the remote IRR bit set? */
430 if (reg
& IO_APIC_REDIR_REMOTE_IRR
) {
431 spin_unlock_irqrestore(&ioapic_lock
, flags
);
438 spin_unlock_irqrestore(&ioapic_lock
, flags
);
444 struct { u32 w1
, w2
; };
445 struct IO_APIC_route_entry entry
;
448 static struct IO_APIC_route_entry
ioapic_read_entry(int apic
, int pin
)
450 union entry_union eu
;
452 spin_lock_irqsave(&ioapic_lock
, flags
);
453 eu
.w1
= io_apic_read(apic
, 0x10 + 2 * pin
);
454 eu
.w2
= io_apic_read(apic
, 0x11 + 2 * pin
);
455 spin_unlock_irqrestore(&ioapic_lock
, flags
);
460 * When we write a new IO APIC routing entry, we need to write the high
461 * word first! If the mask bit in the low word is clear, we will enable
462 * the interrupt, and we need to make sure the entry is fully populated
463 * before that happens.
466 __ioapic_write_entry(int apic
, int pin
, struct IO_APIC_route_entry e
)
468 union entry_union eu
;
470 io_apic_write(apic
, 0x11 + 2*pin
, eu
.w2
);
471 io_apic_write(apic
, 0x10 + 2*pin
, eu
.w1
);
474 void ioapic_write_entry(int apic
, int pin
, struct IO_APIC_route_entry e
)
477 spin_lock_irqsave(&ioapic_lock
, flags
);
478 __ioapic_write_entry(apic
, pin
, e
);
479 spin_unlock_irqrestore(&ioapic_lock
, flags
);
483 * When we mask an IO APIC routing entry, we need to write the low
484 * word first, in order to set the mask bit before we change the
487 static void ioapic_mask_entry(int apic
, int pin
)
490 union entry_union eu
= { .entry
.mask
= 1 };
492 spin_lock_irqsave(&ioapic_lock
, flags
);
493 io_apic_write(apic
, 0x10 + 2*pin
, eu
.w1
);
494 io_apic_write(apic
, 0x11 + 2*pin
, eu
.w2
);
495 spin_unlock_irqrestore(&ioapic_lock
, flags
);
499 static void send_cleanup_vector(struct irq_cfg
*cfg
)
501 cpumask_var_t cleanup_mask
;
503 if (unlikely(!alloc_cpumask_var(&cleanup_mask
, GFP_ATOMIC
))) {
505 cfg
->move_cleanup_count
= 0;
506 for_each_cpu_and(i
, cfg
->old_domain
, cpu_online_mask
)
507 cfg
->move_cleanup_count
++;
508 for_each_cpu_and(i
, cfg
->old_domain
, cpu_online_mask
)
509 apic
->send_IPI_mask(cpumask_of(i
), IRQ_MOVE_CLEANUP_VECTOR
);
511 cpumask_and(cleanup_mask
, cfg
->old_domain
, cpu_online_mask
);
512 cfg
->move_cleanup_count
= cpumask_weight(cleanup_mask
);
513 apic
->send_IPI_mask(cleanup_mask
, IRQ_MOVE_CLEANUP_VECTOR
);
514 free_cpumask_var(cleanup_mask
);
516 cfg
->move_in_progress
= 0;
519 static void __target_IO_APIC_irq(unsigned int irq
, unsigned int dest
, struct irq_cfg
*cfg
)
522 struct irq_pin_list
*entry
;
523 u8 vector
= cfg
->vector
;
525 entry
= cfg
->irq_2_pin
;
535 * With interrupt-remapping, destination information comes
536 * from interrupt-remapping table entry.
538 if (!irq_remapped(irq
))
539 io_apic_write(apic
, 0x11 + pin
*2, dest
);
540 reg
= io_apic_read(apic
, 0x10 + pin
*2);
541 reg
&= ~IO_APIC_REDIR_VECTOR_MASK
;
543 io_apic_modify(apic
, 0x10 + pin
*2, reg
);
551 assign_irq_vector(int irq
, struct irq_cfg
*cfg
, const struct cpumask
*mask
);
554 * Either sets desc->affinity to a valid value, and returns
555 * ->cpu_mask_to_apicid of that, or returns BAD_APICID and
556 * leaves desc->affinity untouched.
559 set_desc_affinity(struct irq_desc
*desc
, const struct cpumask
*mask
)
564 if (!cpumask_intersects(mask
, cpu_online_mask
))
568 cfg
= desc
->chip_data
;
569 if (assign_irq_vector(irq
, cfg
, mask
))
572 cpumask_copy(desc
->affinity
, mask
);
574 return apic
->cpu_mask_to_apicid_and(desc
->affinity
, cfg
->domain
);
578 set_ioapic_affinity_irq_desc(struct irq_desc
*desc
, const struct cpumask
*mask
)
587 cfg
= desc
->chip_data
;
589 spin_lock_irqsave(&ioapic_lock
, flags
);
590 dest
= set_desc_affinity(desc
, mask
);
591 if (dest
!= BAD_APICID
) {
592 /* Only the high 8 bits are valid. */
593 dest
= SET_APIC_LOGICAL_ID(dest
);
594 __target_IO_APIC_irq(irq
, dest
, cfg
);
597 spin_unlock_irqrestore(&ioapic_lock
, flags
);
603 set_ioapic_affinity_irq(unsigned int irq
, const struct cpumask
*mask
)
605 struct irq_desc
*desc
;
607 desc
= irq_to_desc(irq
);
609 return set_ioapic_affinity_irq_desc(desc
, mask
);
611 #endif /* CONFIG_SMP */
614 * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
615 * shared ISA-space IRQs, so we have to support them. We are super
616 * fast in the common case, and fast for shared ISA-space IRQs.
618 static void add_pin_to_irq_cpu(struct irq_cfg
*cfg
, int cpu
, int apic
, int pin
)
620 struct irq_pin_list
*entry
;
622 entry
= cfg
->irq_2_pin
;
624 entry
= get_one_free_irq_2_pin(cpu
);
626 printk(KERN_ERR
"can not alloc irq_2_pin to add %d - %d\n",
630 cfg
->irq_2_pin
= entry
;
636 while (entry
->next
) {
637 /* not again, please */
638 if (entry
->apic
== apic
&& entry
->pin
== pin
)
644 entry
->next
= get_one_free_irq_2_pin(cpu
);
651 * Reroute an IRQ to a different pin.
653 static void __init
replace_pin_at_irq_cpu(struct irq_cfg
*cfg
, int cpu
,
654 int oldapic
, int oldpin
,
655 int newapic
, int newpin
)
657 struct irq_pin_list
*entry
= cfg
->irq_2_pin
;
661 if (entry
->apic
== oldapic
&& entry
->pin
== oldpin
) {
662 entry
->apic
= newapic
;
665 /* every one is different, right? */
671 /* why? call replace before add? */
673 add_pin_to_irq_cpu(cfg
, cpu
, newapic
, newpin
);
676 static inline void io_apic_modify_irq(struct irq_cfg
*cfg
,
677 int mask_and
, int mask_or
,
678 void (*final
)(struct irq_pin_list
*entry
))
681 struct irq_pin_list
*entry
;
683 for (entry
= cfg
->irq_2_pin
; entry
!= NULL
; entry
= entry
->next
) {
686 reg
= io_apic_read(entry
->apic
, 0x10 + pin
* 2);
689 io_apic_modify(entry
->apic
, 0x10 + pin
* 2, reg
);
695 static void __unmask_IO_APIC_irq(struct irq_cfg
*cfg
)
697 io_apic_modify_irq(cfg
, ~IO_APIC_REDIR_MASKED
, 0, NULL
);
701 static void io_apic_sync(struct irq_pin_list
*entry
)
704 * Synchronize the IO-APIC and the CPU by doing
705 * a dummy read from the IO-APIC
707 struct io_apic __iomem
*io_apic
;
708 io_apic
= io_apic_base(entry
->apic
);
709 readl(&io_apic
->data
);
712 static void __mask_IO_APIC_irq(struct irq_cfg
*cfg
)
714 io_apic_modify_irq(cfg
, ~0, IO_APIC_REDIR_MASKED
, &io_apic_sync
);
716 #else /* CONFIG_X86_32 */
717 static void __mask_IO_APIC_irq(struct irq_cfg
*cfg
)
719 io_apic_modify_irq(cfg
, ~0, IO_APIC_REDIR_MASKED
, NULL
);
722 static void __mask_and_edge_IO_APIC_irq(struct irq_cfg
*cfg
)
724 io_apic_modify_irq(cfg
, ~IO_APIC_REDIR_LEVEL_TRIGGER
,
725 IO_APIC_REDIR_MASKED
, NULL
);
728 static void __unmask_and_level_IO_APIC_irq(struct irq_cfg
*cfg
)
730 io_apic_modify_irq(cfg
, ~IO_APIC_REDIR_MASKED
,
731 IO_APIC_REDIR_LEVEL_TRIGGER
, NULL
);
733 #endif /* CONFIG_X86_32 */
735 static void mask_IO_APIC_irq_desc(struct irq_desc
*desc
)
737 struct irq_cfg
*cfg
= desc
->chip_data
;
742 spin_lock_irqsave(&ioapic_lock
, flags
);
743 __mask_IO_APIC_irq(cfg
);
744 spin_unlock_irqrestore(&ioapic_lock
, flags
);
747 static void unmask_IO_APIC_irq_desc(struct irq_desc
*desc
)
749 struct irq_cfg
*cfg
= desc
->chip_data
;
752 spin_lock_irqsave(&ioapic_lock
, flags
);
753 __unmask_IO_APIC_irq(cfg
);
754 spin_unlock_irqrestore(&ioapic_lock
, flags
);
757 static void mask_IO_APIC_irq(unsigned int irq
)
759 struct irq_desc
*desc
= irq_to_desc(irq
);
761 mask_IO_APIC_irq_desc(desc
);
763 static void unmask_IO_APIC_irq(unsigned int irq
)
765 struct irq_desc
*desc
= irq_to_desc(irq
);
767 unmask_IO_APIC_irq_desc(desc
);
770 static void clear_IO_APIC_pin(unsigned int apic
, unsigned int pin
)
772 struct IO_APIC_route_entry entry
;
774 /* Check delivery_mode to be sure we're not clearing an SMI pin */
775 entry
= ioapic_read_entry(apic
, pin
);
776 if (entry
.delivery_mode
== dest_SMI
)
779 * Disable it in the IO-APIC irq-routing table:
781 ioapic_mask_entry(apic
, pin
);
784 static void clear_IO_APIC (void)
788 for (apic
= 0; apic
< nr_ioapics
; apic
++)
789 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++)
790 clear_IO_APIC_pin(apic
, pin
);
795 * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
796 * specific CPU-side IRQs.
800 static int pirq_entries
[MAX_PIRQS
] = {
801 [0 ... MAX_PIRQS
- 1] = -1
804 static int __init
ioapic_pirq_setup(char *str
)
807 int ints
[MAX_PIRQS
+1];
809 get_options(str
, ARRAY_SIZE(ints
), ints
);
811 apic_printk(APIC_VERBOSE
, KERN_INFO
812 "PIRQ redirection, working around broken MP-BIOS.\n");
814 if (ints
[0] < MAX_PIRQS
)
817 for (i
= 0; i
< max
; i
++) {
818 apic_printk(APIC_VERBOSE
, KERN_DEBUG
819 "... PIRQ%d -> IRQ %d\n", i
, ints
[i
+1]);
821 * PIRQs are mapped upside down, usually.
823 pirq_entries
[MAX_PIRQS
-i
-1] = ints
[i
+1];
828 __setup("pirq=", ioapic_pirq_setup
);
829 #endif /* CONFIG_X86_32 */
831 #ifdef CONFIG_INTR_REMAP
832 struct IO_APIC_route_entry
**alloc_ioapic_entries(void)
835 struct IO_APIC_route_entry
**ioapic_entries
;
837 ioapic_entries
= kzalloc(sizeof(*ioapic_entries
) * nr_ioapics
,
842 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
843 ioapic_entries
[apic
] =
844 kzalloc(sizeof(struct IO_APIC_route_entry
) *
845 nr_ioapic_registers
[apic
], GFP_ATOMIC
);
846 if (!ioapic_entries
[apic
])
850 return ioapic_entries
;
854 kfree(ioapic_entries
[apic
]);
855 kfree(ioapic_entries
);
861 * Saves all the IO-APIC RTE's
863 int save_IO_APIC_setup(struct IO_APIC_route_entry
**ioapic_entries
)
870 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
871 if (!ioapic_entries
[apic
])
874 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++)
875 ioapic_entries
[apic
][pin
] =
876 ioapic_read_entry(apic
, pin
);
883 * Mask all IO APIC entries.
885 void mask_IO_APIC_setup(struct IO_APIC_route_entry
**ioapic_entries
)
892 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
893 if (!ioapic_entries
[apic
])
896 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
897 struct IO_APIC_route_entry entry
;
899 entry
= ioapic_entries
[apic
][pin
];
902 ioapic_write_entry(apic
, pin
, entry
);
909 * Restore IO APIC entries which was saved in ioapic_entries.
911 int restore_IO_APIC_setup(struct IO_APIC_route_entry
**ioapic_entries
)
918 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
919 if (!ioapic_entries
[apic
])
922 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++)
923 ioapic_write_entry(apic
, pin
,
924 ioapic_entries
[apic
][pin
]);
929 void reinit_intr_remapped_IO_APIC(int intr_remapping
,
930 struct IO_APIC_route_entry
**ioapic_entries
)
934 * for now plain restore of previous settings.
935 * TBD: In the case of OS enabling interrupt-remapping,
936 * IO-APIC RTE's need to be setup to point to interrupt-remapping
937 * table entries. for now, do a plain restore, and wait for
938 * the setup_IO_APIC_irqs() to do proper initialization.
940 restore_IO_APIC_setup(ioapic_entries
);
943 void free_ioapic_entries(struct IO_APIC_route_entry
**ioapic_entries
)
947 for (apic
= 0; apic
< nr_ioapics
; apic
++)
948 kfree(ioapic_entries
[apic
]);
950 kfree(ioapic_entries
);
955 * Find the IRQ entry number of a certain pin.
957 static int find_irq_entry(int apic
, int pin
, int type
)
961 for (i
= 0; i
< mp_irq_entries
; i
++)
962 if (mp_irqs
[i
].irqtype
== type
&&
963 (mp_irqs
[i
].dstapic
== mp_ioapics
[apic
].apicid
||
964 mp_irqs
[i
].dstapic
== MP_APIC_ALL
) &&
965 mp_irqs
[i
].dstirq
== pin
)
972 * Find the pin to which IRQ[irq] (ISA) is connected
974 static int __init
find_isa_irq_pin(int irq
, int type
)
978 for (i
= 0; i
< mp_irq_entries
; i
++) {
979 int lbus
= mp_irqs
[i
].srcbus
;
981 if (test_bit(lbus
, mp_bus_not_pci
) &&
982 (mp_irqs
[i
].irqtype
== type
) &&
983 (mp_irqs
[i
].srcbusirq
== irq
))
985 return mp_irqs
[i
].dstirq
;
990 static int __init
find_isa_irq_apic(int irq
, int type
)
994 for (i
= 0; i
< mp_irq_entries
; i
++) {
995 int lbus
= mp_irqs
[i
].srcbus
;
997 if (test_bit(lbus
, mp_bus_not_pci
) &&
998 (mp_irqs
[i
].irqtype
== type
) &&
999 (mp_irqs
[i
].srcbusirq
== irq
))
1002 if (i
< mp_irq_entries
) {
1004 for(apic
= 0; apic
< nr_ioapics
; apic
++) {
1005 if (mp_ioapics
[apic
].apicid
== mp_irqs
[i
].dstapic
)
1014 * Find a specific PCI IRQ entry.
1015 * Not an __init, possibly needed by modules
1017 static int pin_2_irq(int idx
, int apic
, int pin
);
1019 int IO_APIC_get_PCI_irq_vector(int bus
, int slot
, int pin
)
1021 int apic
, i
, best_guess
= -1;
1023 apic_printk(APIC_DEBUG
, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
1025 if (test_bit(bus
, mp_bus_not_pci
)) {
1026 apic_printk(APIC_VERBOSE
, "PCI BIOS passed nonexistent PCI bus %d!\n", bus
);
1029 for (i
= 0; i
< mp_irq_entries
; i
++) {
1030 int lbus
= mp_irqs
[i
].srcbus
;
1032 for (apic
= 0; apic
< nr_ioapics
; apic
++)
1033 if (mp_ioapics
[apic
].apicid
== mp_irqs
[i
].dstapic
||
1034 mp_irqs
[i
].dstapic
== MP_APIC_ALL
)
1037 if (!test_bit(lbus
, mp_bus_not_pci
) &&
1038 !mp_irqs
[i
].irqtype
&&
1040 (slot
== ((mp_irqs
[i
].srcbusirq
>> 2) & 0x1f))) {
1041 int irq
= pin_2_irq(i
, apic
, mp_irqs
[i
].dstirq
);
1043 if (!(apic
|| IO_APIC_IRQ(irq
)))
1046 if (pin
== (mp_irqs
[i
].srcbusirq
& 3))
1049 * Use the first all-but-pin matching entry as a
1050 * best-guess fuzzy result for broken mptables.
1059 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector
);
1061 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
1063 * EISA Edge/Level control register, ELCR
1065 static int EISA_ELCR(unsigned int irq
)
1067 if (irq
< NR_IRQS_LEGACY
) {
1068 unsigned int port
= 0x4d0 + (irq
>> 3);
1069 return (inb(port
) >> (irq
& 7)) & 1;
1071 apic_printk(APIC_VERBOSE
, KERN_INFO
1072 "Broken MPtable reports ISA irq %d\n", irq
);
1078 /* ISA interrupts are always polarity zero edge triggered,
1079 * when listed as conforming in the MP table. */
1081 #define default_ISA_trigger(idx) (0)
1082 #define default_ISA_polarity(idx) (0)
1084 /* EISA interrupts are always polarity zero and can be edge or level
1085 * trigger depending on the ELCR value. If an interrupt is listed as
1086 * EISA conforming in the MP table, that means its trigger type must
1087 * be read in from the ELCR */
1089 #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].srcbusirq))
1090 #define default_EISA_polarity(idx) default_ISA_polarity(idx)
1092 /* PCI interrupts are always polarity one level triggered,
1093 * when listed as conforming in the MP table. */
1095 #define default_PCI_trigger(idx) (1)
1096 #define default_PCI_polarity(idx) (1)
1098 /* MCA interrupts are always polarity zero level triggered,
1099 * when listed as conforming in the MP table. */
1101 #define default_MCA_trigger(idx) (1)
1102 #define default_MCA_polarity(idx) default_ISA_polarity(idx)
1104 static int MPBIOS_polarity(int idx
)
1106 int bus
= mp_irqs
[idx
].srcbus
;
1110 * Determine IRQ line polarity (high active or low active):
1112 switch (mp_irqs
[idx
].irqflag
& 3)
1114 case 0: /* conforms, ie. bus-type dependent polarity */
1115 if (test_bit(bus
, mp_bus_not_pci
))
1116 polarity
= default_ISA_polarity(idx
);
1118 polarity
= default_PCI_polarity(idx
);
1120 case 1: /* high active */
1125 case 2: /* reserved */
1127 printk(KERN_WARNING
"broken BIOS!!\n");
1131 case 3: /* low active */
1136 default: /* invalid */
1138 printk(KERN_WARNING
"broken BIOS!!\n");
1146 static int MPBIOS_trigger(int idx
)
1148 int bus
= mp_irqs
[idx
].srcbus
;
1152 * Determine IRQ trigger mode (edge or level sensitive):
1154 switch ((mp_irqs
[idx
].irqflag
>>2) & 3)
1156 case 0: /* conforms, ie. bus-type dependent */
1157 if (test_bit(bus
, mp_bus_not_pci
))
1158 trigger
= default_ISA_trigger(idx
);
1160 trigger
= default_PCI_trigger(idx
);
1161 #if defined(CONFIG_EISA) || defined(CONFIG_MCA)
1162 switch (mp_bus_id_to_type
[bus
]) {
1163 case MP_BUS_ISA
: /* ISA pin */
1165 /* set before the switch */
1168 case MP_BUS_EISA
: /* EISA pin */
1170 trigger
= default_EISA_trigger(idx
);
1173 case MP_BUS_PCI
: /* PCI pin */
1175 /* set before the switch */
1178 case MP_BUS_MCA
: /* MCA pin */
1180 trigger
= default_MCA_trigger(idx
);
1185 printk(KERN_WARNING
"broken BIOS!!\n");
1197 case 2: /* reserved */
1199 printk(KERN_WARNING
"broken BIOS!!\n");
1208 default: /* invalid */
1210 printk(KERN_WARNING
"broken BIOS!!\n");
1218 static inline int irq_polarity(int idx
)
1220 return MPBIOS_polarity(idx
);
1223 static inline int irq_trigger(int idx
)
1225 return MPBIOS_trigger(idx
);
1228 int (*ioapic_renumber_irq
)(int ioapic
, int irq
);
1229 static int pin_2_irq(int idx
, int apic
, int pin
)
1232 int bus
= mp_irqs
[idx
].srcbus
;
1235 * Debugging check, we are in big trouble if this message pops up!
1237 if (mp_irqs
[idx
].dstirq
!= pin
)
1238 printk(KERN_ERR
"broken BIOS or MPTABLE parser, ayiee!!\n");
1240 if (test_bit(bus
, mp_bus_not_pci
)) {
1241 irq
= mp_irqs
[idx
].srcbusirq
;
1244 * PCI IRQs are mapped in order
1248 irq
+= nr_ioapic_registers
[i
++];
1251 * For MPS mode, so far only needed by ES7000 platform
1253 if (ioapic_renumber_irq
)
1254 irq
= ioapic_renumber_irq(apic
, irq
);
1257 #ifdef CONFIG_X86_32
1259 * PCI IRQ command line redirection. Yes, limits are hardcoded.
1261 if ((pin
>= 16) && (pin
<= 23)) {
1262 if (pirq_entries
[pin
-16] != -1) {
1263 if (!pirq_entries
[pin
-16]) {
1264 apic_printk(APIC_VERBOSE
, KERN_DEBUG
1265 "disabling PIRQ%d\n", pin
-16);
1267 irq
= pirq_entries
[pin
-16];
1268 apic_printk(APIC_VERBOSE
, KERN_DEBUG
1269 "using PIRQ%d -> IRQ %d\n",
1279 void lock_vector_lock(void)
1281 /* Used to the online set of cpus does not change
1282 * during assign_irq_vector.
1284 spin_lock(&vector_lock
);
1287 void unlock_vector_lock(void)
1289 spin_unlock(&vector_lock
);
1293 __assign_irq_vector(int irq
, struct irq_cfg
*cfg
, const struct cpumask
*mask
)
1296 * NOTE! The local APIC isn't very good at handling
1297 * multiple interrupts at the same interrupt level.
1298 * As the interrupt level is determined by taking the
1299 * vector number and shifting that right by 4, we
1300 * want to spread these out a bit so that they don't
1301 * all fall in the same interrupt level.
1303 * Also, we've got to be careful not to trash gate
1304 * 0x80, because int 0x80 is hm, kind of importantish. ;)
1306 static int current_vector
= FIRST_DEVICE_VECTOR
, current_offset
= 0;
1307 unsigned int old_vector
;
1309 cpumask_var_t tmp_mask
;
1311 if ((cfg
->move_in_progress
) || cfg
->move_cleanup_count
)
1314 if (!alloc_cpumask_var(&tmp_mask
, GFP_ATOMIC
))
1317 old_vector
= cfg
->vector
;
1319 cpumask_and(tmp_mask
, mask
, cpu_online_mask
);
1320 cpumask_and(tmp_mask
, cfg
->domain
, tmp_mask
);
1321 if (!cpumask_empty(tmp_mask
)) {
1322 free_cpumask_var(tmp_mask
);
1327 /* Only try and allocate irqs on cpus that are present */
1329 for_each_cpu_and(cpu
, mask
, cpu_online_mask
) {
1333 apic
->vector_allocation_domain(cpu
, tmp_mask
);
1335 vector
= current_vector
;
1336 offset
= current_offset
;
1339 if (vector
>= first_system_vector
) {
1340 /* If out of vectors on large boxen, must share them. */
1341 offset
= (offset
+ 1) % 8;
1342 vector
= FIRST_DEVICE_VECTOR
+ offset
;
1344 if (unlikely(current_vector
== vector
))
1347 if (test_bit(vector
, used_vectors
))
1350 for_each_cpu_and(new_cpu
, tmp_mask
, cpu_online_mask
)
1351 if (per_cpu(vector_irq
, new_cpu
)[vector
] != -1)
1354 current_vector
= vector
;
1355 current_offset
= offset
;
1357 cfg
->move_in_progress
= 1;
1358 cpumask_copy(cfg
->old_domain
, cfg
->domain
);
1360 for_each_cpu_and(new_cpu
, tmp_mask
, cpu_online_mask
)
1361 per_cpu(vector_irq
, new_cpu
)[vector
] = irq
;
1362 cfg
->vector
= vector
;
1363 cpumask_copy(cfg
->domain
, tmp_mask
);
1367 free_cpumask_var(tmp_mask
);
1372 assign_irq_vector(int irq
, struct irq_cfg
*cfg
, const struct cpumask
*mask
)
1375 unsigned long flags
;
1377 spin_lock_irqsave(&vector_lock
, flags
);
1378 err
= __assign_irq_vector(irq
, cfg
, mask
);
1379 spin_unlock_irqrestore(&vector_lock
, flags
);
1383 static void __clear_irq_vector(int irq
, struct irq_cfg
*cfg
)
1387 BUG_ON(!cfg
->vector
);
1389 vector
= cfg
->vector
;
1390 for_each_cpu_and(cpu
, cfg
->domain
, cpu_online_mask
)
1391 per_cpu(vector_irq
, cpu
)[vector
] = -1;
1394 cpumask_clear(cfg
->domain
);
1396 if (likely(!cfg
->move_in_progress
))
1398 for_each_cpu_and(cpu
, cfg
->old_domain
, cpu_online_mask
) {
1399 for (vector
= FIRST_EXTERNAL_VECTOR
; vector
< NR_VECTORS
;
1401 if (per_cpu(vector_irq
, cpu
)[vector
] != irq
)
1403 per_cpu(vector_irq
, cpu
)[vector
] = -1;
1407 cfg
->move_in_progress
= 0;
1410 void __setup_vector_irq(int cpu
)
1412 /* Initialize vector_irq on a new cpu */
1413 /* This function must be called with vector_lock held */
1415 struct irq_cfg
*cfg
;
1416 struct irq_desc
*desc
;
1418 /* Mark the inuse vectors */
1419 for_each_irq_desc(irq
, desc
) {
1420 cfg
= desc
->chip_data
;
1421 if (!cpumask_test_cpu(cpu
, cfg
->domain
))
1423 vector
= cfg
->vector
;
1424 per_cpu(vector_irq
, cpu
)[vector
] = irq
;
1426 /* Mark the free vectors */
1427 for (vector
= 0; vector
< NR_VECTORS
; ++vector
) {
1428 irq
= per_cpu(vector_irq
, cpu
)[vector
];
1433 if (!cpumask_test_cpu(cpu
, cfg
->domain
))
1434 per_cpu(vector_irq
, cpu
)[vector
] = -1;
1438 static struct irq_chip ioapic_chip
;
1439 static struct irq_chip ir_ioapic_chip
;
1441 #define IOAPIC_AUTO -1
1442 #define IOAPIC_EDGE 0
1443 #define IOAPIC_LEVEL 1
1445 #ifdef CONFIG_X86_32
1446 static inline int IO_APIC_irq_trigger(int irq
)
1450 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
1451 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
1452 idx
= find_irq_entry(apic
, pin
, mp_INT
);
1453 if ((idx
!= -1) && (irq
== pin_2_irq(idx
, apic
, pin
)))
1454 return irq_trigger(idx
);
1458 * nonexistent IRQs are edge default
1463 static inline int IO_APIC_irq_trigger(int irq
)
1469 static void ioapic_register_intr(int irq
, struct irq_desc
*desc
, unsigned long trigger
)
1472 if ((trigger
== IOAPIC_AUTO
&& IO_APIC_irq_trigger(irq
)) ||
1473 trigger
== IOAPIC_LEVEL
)
1474 desc
->status
|= IRQ_LEVEL
;
1476 desc
->status
&= ~IRQ_LEVEL
;
1478 if (irq_remapped(irq
)) {
1479 desc
->status
|= IRQ_MOVE_PCNTXT
;
1481 set_irq_chip_and_handler_name(irq
, &ir_ioapic_chip
,
1485 set_irq_chip_and_handler_name(irq
, &ir_ioapic_chip
,
1486 handle_edge_irq
, "edge");
1490 if ((trigger
== IOAPIC_AUTO
&& IO_APIC_irq_trigger(irq
)) ||
1491 trigger
== IOAPIC_LEVEL
)
1492 set_irq_chip_and_handler_name(irq
, &ioapic_chip
,
1496 set_irq_chip_and_handler_name(irq
, &ioapic_chip
,
1497 handle_edge_irq
, "edge");
1500 int setup_ioapic_entry(int apic_id
, int irq
,
1501 struct IO_APIC_route_entry
*entry
,
1502 unsigned int destination
, int trigger
,
1503 int polarity
, int vector
, int pin
)
1506 * add it to the IO-APIC irq-routing table:
1508 memset(entry
,0,sizeof(*entry
));
1510 if (intr_remapping_enabled
) {
1511 struct intel_iommu
*iommu
= map_ioapic_to_ir(apic_id
);
1513 struct IR_IO_APIC_route_entry
*ir_entry
=
1514 (struct IR_IO_APIC_route_entry
*) entry
;
1518 panic("No mapping iommu for ioapic %d\n", apic_id
);
1520 index
= alloc_irte(iommu
, irq
, 1);
1522 panic("Failed to allocate IRTE for ioapic %d\n", apic_id
);
1524 memset(&irte
, 0, sizeof(irte
));
1527 irte
.dst_mode
= apic
->irq_dest_mode
;
1529 * Trigger mode in the IRTE will always be edge, and the
1530 * actual level or edge trigger will be setup in the IO-APIC
1531 * RTE. This will help simplify level triggered irq migration.
1532 * For more details, see the comments above explainig IO-APIC
1533 * irq migration in the presence of interrupt-remapping.
1535 irte
.trigger_mode
= 0;
1536 irte
.dlvry_mode
= apic
->irq_delivery_mode
;
1537 irte
.vector
= vector
;
1538 irte
.dest_id
= IRTE_DEST(destination
);
1540 modify_irte(irq
, &irte
);
1542 ir_entry
->index2
= (index
>> 15) & 0x1;
1544 ir_entry
->format
= 1;
1545 ir_entry
->index
= (index
& 0x7fff);
1547 * IO-APIC RTE will be configured with virtual vector.
1548 * irq handler will do the explicit EOI to the io-apic.
1550 ir_entry
->vector
= pin
;
1552 entry
->delivery_mode
= apic
->irq_delivery_mode
;
1553 entry
->dest_mode
= apic
->irq_dest_mode
;
1554 entry
->dest
= destination
;
1555 entry
->vector
= vector
;
1558 entry
->mask
= 0; /* enable IRQ */
1559 entry
->trigger
= trigger
;
1560 entry
->polarity
= polarity
;
1562 /* Mask level triggered irqs.
1563 * Use IRQ_DELAYED_DISABLE for edge triggered irqs.
1570 static void setup_IO_APIC_irq(int apic_id
, int pin
, unsigned int irq
, struct irq_desc
*desc
,
1571 int trigger
, int polarity
)
1573 struct irq_cfg
*cfg
;
1574 struct IO_APIC_route_entry entry
;
1577 if (!IO_APIC_IRQ(irq
))
1580 cfg
= desc
->chip_data
;
1582 if (assign_irq_vector(irq
, cfg
, apic
->target_cpus()))
1585 dest
= apic
->cpu_mask_to_apicid_and(cfg
->domain
, apic
->target_cpus());
1587 apic_printk(APIC_VERBOSE
,KERN_DEBUG
1588 "IOAPIC[%d]: Set routing entry (%d-%d -> 0x%x -> "
1589 "IRQ %d Mode:%i Active:%i)\n",
1590 apic_id
, mp_ioapics
[apic_id
].apicid
, pin
, cfg
->vector
,
1591 irq
, trigger
, polarity
);
1594 if (setup_ioapic_entry(mp_ioapics
[apic_id
].apicid
, irq
, &entry
,
1595 dest
, trigger
, polarity
, cfg
->vector
, pin
)) {
1596 printk("Failed to setup ioapic entry for ioapic %d, pin %d\n",
1597 mp_ioapics
[apic_id
].apicid
, pin
);
1598 __clear_irq_vector(irq
, cfg
);
1602 ioapic_register_intr(irq
, desc
, trigger
);
1603 if (irq
< NR_IRQS_LEGACY
)
1604 disable_8259A_irq(irq
);
1606 ioapic_write_entry(apic_id
, pin
, entry
);
1609 static void __init
setup_IO_APIC_irqs(void)
1611 int apic_id
, pin
, idx
, irq
;
1613 struct irq_desc
*desc
;
1614 struct irq_cfg
*cfg
;
1615 int cpu
= boot_cpu_id
;
1617 apic_printk(APIC_VERBOSE
, KERN_DEBUG
"init IO_APIC IRQs\n");
1619 for (apic_id
= 0; apic_id
< nr_ioapics
; apic_id
++) {
1620 for (pin
= 0; pin
< nr_ioapic_registers
[apic_id
]; pin
++) {
1622 idx
= find_irq_entry(apic_id
, pin
, mp_INT
);
1626 apic_printk(APIC_VERBOSE
,
1627 KERN_DEBUG
" %d-%d",
1628 mp_ioapics
[apic_id
].apicid
, pin
);
1630 apic_printk(APIC_VERBOSE
, " %d-%d",
1631 mp_ioapics
[apic_id
].apicid
, pin
);
1635 apic_printk(APIC_VERBOSE
,
1636 " (apicid-pin) not connected\n");
1640 irq
= pin_2_irq(idx
, apic_id
, pin
);
1643 * Skip the timer IRQ if there's a quirk handler
1644 * installed and if it returns 1:
1646 if (apic
->multi_timer_check
&&
1647 apic
->multi_timer_check(apic_id
, irq
))
1650 desc
= irq_to_desc_alloc_cpu(irq
, cpu
);
1652 printk(KERN_INFO
"can not get irq_desc for %d\n", irq
);
1655 cfg
= desc
->chip_data
;
1656 add_pin_to_irq_cpu(cfg
, cpu
, apic_id
, pin
);
1658 setup_IO_APIC_irq(apic_id
, pin
, irq
, desc
,
1659 irq_trigger(idx
), irq_polarity(idx
));
1664 apic_printk(APIC_VERBOSE
,
1665 " (apicid-pin) not connected\n");
1669 * Set up the timer pin, possibly with the 8259A-master behind.
1671 static void __init
setup_timer_IRQ0_pin(unsigned int apic_id
, unsigned int pin
,
1674 struct IO_APIC_route_entry entry
;
1676 if (intr_remapping_enabled
)
1679 memset(&entry
, 0, sizeof(entry
));
1682 * We use logical delivery to get the timer IRQ
1685 entry
.dest_mode
= apic
->irq_dest_mode
;
1686 entry
.mask
= 0; /* don't mask IRQ for edge */
1687 entry
.dest
= apic
->cpu_mask_to_apicid(apic
->target_cpus());
1688 entry
.delivery_mode
= apic
->irq_delivery_mode
;
1691 entry
.vector
= vector
;
1694 * The timer IRQ doesn't have to know that behind the
1695 * scene we may have a 8259A-master in AEOI mode ...
1697 set_irq_chip_and_handler_name(0, &ioapic_chip
, handle_edge_irq
, "edge");
1700 * Add it to the IO-APIC irq-routing table:
1702 ioapic_write_entry(apic_id
, pin
, entry
);
1706 __apicdebuginit(void) print_IO_APIC(void)
1709 union IO_APIC_reg_00 reg_00
;
1710 union IO_APIC_reg_01 reg_01
;
1711 union IO_APIC_reg_02 reg_02
;
1712 union IO_APIC_reg_03 reg_03
;
1713 unsigned long flags
;
1714 struct irq_cfg
*cfg
;
1715 struct irq_desc
*desc
;
1718 if (apic_verbosity
== APIC_QUIET
)
1721 printk(KERN_DEBUG
"number of MP IRQ sources: %d.\n", mp_irq_entries
);
1722 for (i
= 0; i
< nr_ioapics
; i
++)
1723 printk(KERN_DEBUG
"number of IO-APIC #%d registers: %d.\n",
1724 mp_ioapics
[i
].apicid
, nr_ioapic_registers
[i
]);
1727 * We are a bit conservative about what we expect. We have to
1728 * know about every hardware change ASAP.
1730 printk(KERN_INFO
"testing the IO APIC.......................\n");
1732 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
1734 spin_lock_irqsave(&ioapic_lock
, flags
);
1735 reg_00
.raw
= io_apic_read(apic
, 0);
1736 reg_01
.raw
= io_apic_read(apic
, 1);
1737 if (reg_01
.bits
.version
>= 0x10)
1738 reg_02
.raw
= io_apic_read(apic
, 2);
1739 if (reg_01
.bits
.version
>= 0x20)
1740 reg_03
.raw
= io_apic_read(apic
, 3);
1741 spin_unlock_irqrestore(&ioapic_lock
, flags
);
1744 printk(KERN_DEBUG
"IO APIC #%d......\n", mp_ioapics
[apic
].apicid
);
1745 printk(KERN_DEBUG
".... register #00: %08X\n", reg_00
.raw
);
1746 printk(KERN_DEBUG
"....... : physical APIC id: %02X\n", reg_00
.bits
.ID
);
1747 printk(KERN_DEBUG
"....... : Delivery Type: %X\n", reg_00
.bits
.delivery_type
);
1748 printk(KERN_DEBUG
"....... : LTS : %X\n", reg_00
.bits
.LTS
);
1750 printk(KERN_DEBUG
".... register #01: %08X\n", *(int *)®_01
);
1751 printk(KERN_DEBUG
"....... : max redirection entries: %04X\n", reg_01
.bits
.entries
);
1753 printk(KERN_DEBUG
"....... : PRQ implemented: %X\n", reg_01
.bits
.PRQ
);
1754 printk(KERN_DEBUG
"....... : IO APIC version: %04X\n", reg_01
.bits
.version
);
1757 * Some Intel chipsets with IO APIC VERSION of 0x1? don't have reg_02,
1758 * but the value of reg_02 is read as the previous read register
1759 * value, so ignore it if reg_02 == reg_01.
1761 if (reg_01
.bits
.version
>= 0x10 && reg_02
.raw
!= reg_01
.raw
) {
1762 printk(KERN_DEBUG
".... register #02: %08X\n", reg_02
.raw
);
1763 printk(KERN_DEBUG
"....... : arbitration: %02X\n", reg_02
.bits
.arbitration
);
1767 * Some Intel chipsets with IO APIC VERSION of 0x2? don't have reg_02
1768 * or reg_03, but the value of reg_0[23] is read as the previous read
1769 * register value, so ignore it if reg_03 == reg_0[12].
1771 if (reg_01
.bits
.version
>= 0x20 && reg_03
.raw
!= reg_02
.raw
&&
1772 reg_03
.raw
!= reg_01
.raw
) {
1773 printk(KERN_DEBUG
".... register #03: %08X\n", reg_03
.raw
);
1774 printk(KERN_DEBUG
"....... : Boot DT : %X\n", reg_03
.bits
.boot_DT
);
1777 printk(KERN_DEBUG
".... IRQ redirection table:\n");
1779 printk(KERN_DEBUG
" NR Dst Mask Trig IRR Pol"
1780 " Stat Dmod Deli Vect: \n");
1782 for (i
= 0; i
<= reg_01
.bits
.entries
; i
++) {
1783 struct IO_APIC_route_entry entry
;
1785 entry
= ioapic_read_entry(apic
, i
);
1787 printk(KERN_DEBUG
" %02x %03X ",
1792 printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
1797 entry
.delivery_status
,
1799 entry
.delivery_mode
,
1804 printk(KERN_DEBUG
"IRQ to pin mappings:\n");
1805 for_each_irq_desc(irq
, desc
) {
1806 struct irq_pin_list
*entry
;
1808 cfg
= desc
->chip_data
;
1809 entry
= cfg
->irq_2_pin
;
1812 printk(KERN_DEBUG
"IRQ%d ", irq
);
1814 printk("-> %d:%d", entry
->apic
, entry
->pin
);
1817 entry
= entry
->next
;
1822 printk(KERN_INFO
".................................... done.\n");
1827 __apicdebuginit(void) print_APIC_bitfield(int base
)
1832 if (apic_verbosity
== APIC_QUIET
)
1835 printk(KERN_DEBUG
"0123456789abcdef0123456789abcdef\n" KERN_DEBUG
);
1836 for (i
= 0; i
< 8; i
++) {
1837 v
= apic_read(base
+ i
*0x10);
1838 for (j
= 0; j
< 32; j
++) {
1848 __apicdebuginit(void) print_local_APIC(void *dummy
)
1850 unsigned int v
, ver
, maxlvt
;
1853 if (apic_verbosity
== APIC_QUIET
)
1856 printk("\n" KERN_DEBUG
"printing local APIC contents on CPU#%d/%d:\n",
1857 smp_processor_id(), hard_smp_processor_id());
1858 v
= apic_read(APIC_ID
);
1859 printk(KERN_INFO
"... APIC ID: %08x (%01x)\n", v
, read_apic_id());
1860 v
= apic_read(APIC_LVR
);
1861 printk(KERN_INFO
"... APIC VERSION: %08x\n", v
);
1862 ver
= GET_APIC_VERSION(v
);
1863 maxlvt
= lapic_get_maxlvt();
1865 v
= apic_read(APIC_TASKPRI
);
1866 printk(KERN_DEBUG
"... APIC TASKPRI: %08x (%02x)\n", v
, v
& APIC_TPRI_MASK
);
1868 if (APIC_INTEGRATED(ver
)) { /* !82489DX */
1869 if (!APIC_XAPIC(ver
)) {
1870 v
= apic_read(APIC_ARBPRI
);
1871 printk(KERN_DEBUG
"... APIC ARBPRI: %08x (%02x)\n", v
,
1872 v
& APIC_ARBPRI_MASK
);
1874 v
= apic_read(APIC_PROCPRI
);
1875 printk(KERN_DEBUG
"... APIC PROCPRI: %08x\n", v
);
1879 * Remote read supported only in the 82489DX and local APIC for
1880 * Pentium processors.
1882 if (!APIC_INTEGRATED(ver
) || maxlvt
== 3) {
1883 v
= apic_read(APIC_RRR
);
1884 printk(KERN_DEBUG
"... APIC RRR: %08x\n", v
);
1887 v
= apic_read(APIC_LDR
);
1888 printk(KERN_DEBUG
"... APIC LDR: %08x\n", v
);
1889 if (!x2apic_enabled()) {
1890 v
= apic_read(APIC_DFR
);
1891 printk(KERN_DEBUG
"... APIC DFR: %08x\n", v
);
1893 v
= apic_read(APIC_SPIV
);
1894 printk(KERN_DEBUG
"... APIC SPIV: %08x\n", v
);
1896 printk(KERN_DEBUG
"... APIC ISR field:\n");
1897 print_APIC_bitfield(APIC_ISR
);
1898 printk(KERN_DEBUG
"... APIC TMR field:\n");
1899 print_APIC_bitfield(APIC_TMR
);
1900 printk(KERN_DEBUG
"... APIC IRR field:\n");
1901 print_APIC_bitfield(APIC_IRR
);
1903 if (APIC_INTEGRATED(ver
)) { /* !82489DX */
1904 if (maxlvt
> 3) /* Due to the Pentium erratum 3AP. */
1905 apic_write(APIC_ESR
, 0);
1907 v
= apic_read(APIC_ESR
);
1908 printk(KERN_DEBUG
"... APIC ESR: %08x\n", v
);
1911 icr
= apic_icr_read();
1912 printk(KERN_DEBUG
"... APIC ICR: %08x\n", (u32
)icr
);
1913 printk(KERN_DEBUG
"... APIC ICR2: %08x\n", (u32
)(icr
>> 32));
1915 v
= apic_read(APIC_LVTT
);
1916 printk(KERN_DEBUG
"... APIC LVTT: %08x\n", v
);
1918 if (maxlvt
> 3) { /* PC is LVT#4. */
1919 v
= apic_read(APIC_LVTPC
);
1920 printk(KERN_DEBUG
"... APIC LVTPC: %08x\n", v
);
1922 v
= apic_read(APIC_LVT0
);
1923 printk(KERN_DEBUG
"... APIC LVT0: %08x\n", v
);
1924 v
= apic_read(APIC_LVT1
);
1925 printk(KERN_DEBUG
"... APIC LVT1: %08x\n", v
);
1927 if (maxlvt
> 2) { /* ERR is LVT#3. */
1928 v
= apic_read(APIC_LVTERR
);
1929 printk(KERN_DEBUG
"... APIC LVTERR: %08x\n", v
);
1932 v
= apic_read(APIC_TMICT
);
1933 printk(KERN_DEBUG
"... APIC TMICT: %08x\n", v
);
1934 v
= apic_read(APIC_TMCCT
);
1935 printk(KERN_DEBUG
"... APIC TMCCT: %08x\n", v
);
1936 v
= apic_read(APIC_TDCR
);
1937 printk(KERN_DEBUG
"... APIC TDCR: %08x\n", v
);
1941 __apicdebuginit(void) print_all_local_APICs(void)
1946 for_each_online_cpu(cpu
)
1947 smp_call_function_single(cpu
, print_local_APIC
, NULL
, 1);
1951 __apicdebuginit(void) print_PIC(void)
1954 unsigned long flags
;
1956 if (apic_verbosity
== APIC_QUIET
)
1959 printk(KERN_DEBUG
"\nprinting PIC contents\n");
1961 spin_lock_irqsave(&i8259A_lock
, flags
);
1963 v
= inb(0xa1) << 8 | inb(0x21);
1964 printk(KERN_DEBUG
"... PIC IMR: %04x\n", v
);
1966 v
= inb(0xa0) << 8 | inb(0x20);
1967 printk(KERN_DEBUG
"... PIC IRR: %04x\n", v
);
1971 v
= inb(0xa0) << 8 | inb(0x20);
1975 spin_unlock_irqrestore(&i8259A_lock
, flags
);
1977 printk(KERN_DEBUG
"... PIC ISR: %04x\n", v
);
1979 v
= inb(0x4d1) << 8 | inb(0x4d0);
1980 printk(KERN_DEBUG
"... PIC ELCR: %04x\n", v
);
1983 __apicdebuginit(int) print_all_ICs(void)
1986 print_all_local_APICs();
1992 fs_initcall(print_all_ICs
);
1995 /* Where if anywhere is the i8259 connect in external int mode */
1996 static struct { int pin
, apic
; } ioapic_i8259
= { -1, -1 };
1998 void __init
enable_IO_APIC(void)
2000 union IO_APIC_reg_01 reg_01
;
2001 int i8259_apic
, i8259_pin
;
2003 unsigned long flags
;
2006 * The number of IO-APIC IRQ registers (== #pins):
2008 for (apic
= 0; apic
< nr_ioapics
; apic
++) {
2009 spin_lock_irqsave(&ioapic_lock
, flags
);
2010 reg_01
.raw
= io_apic_read(apic
, 1);
2011 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2012 nr_ioapic_registers
[apic
] = reg_01
.bits
.entries
+1;
2014 for(apic
= 0; apic
< nr_ioapics
; apic
++) {
2016 /* See if any of the pins is in ExtINT mode */
2017 for (pin
= 0; pin
< nr_ioapic_registers
[apic
]; pin
++) {
2018 struct IO_APIC_route_entry entry
;
2019 entry
= ioapic_read_entry(apic
, pin
);
2021 /* If the interrupt line is enabled and in ExtInt mode
2022 * I have found the pin where the i8259 is connected.
2024 if ((entry
.mask
== 0) && (entry
.delivery_mode
== dest_ExtINT
)) {
2025 ioapic_i8259
.apic
= apic
;
2026 ioapic_i8259
.pin
= pin
;
2032 /* Look to see what if the MP table has reported the ExtINT */
2033 /* If we could not find the appropriate pin by looking at the ioapic
2034 * the i8259 probably is not connected the ioapic but give the
2035 * mptable a chance anyway.
2037 i8259_pin
= find_isa_irq_pin(0, mp_ExtINT
);
2038 i8259_apic
= find_isa_irq_apic(0, mp_ExtINT
);
2039 /* Trust the MP table if nothing is setup in the hardware */
2040 if ((ioapic_i8259
.pin
== -1) && (i8259_pin
>= 0)) {
2041 printk(KERN_WARNING
"ExtINT not setup in hardware but reported by MP table\n");
2042 ioapic_i8259
.pin
= i8259_pin
;
2043 ioapic_i8259
.apic
= i8259_apic
;
2045 /* Complain if the MP table and the hardware disagree */
2046 if (((ioapic_i8259
.apic
!= i8259_apic
) || (ioapic_i8259
.pin
!= i8259_pin
)) &&
2047 (i8259_pin
>= 0) && (ioapic_i8259
.pin
>= 0))
2049 printk(KERN_WARNING
"ExtINT in hardware and MP table differ\n");
2053 * Do not trust the IO-APIC being empty at bootup
2059 * Not an __init, needed by the reboot code
2061 void disable_IO_APIC(void)
2064 * Clear the IO-APIC before rebooting:
2069 * If the i8259 is routed through an IOAPIC
2070 * Put that IOAPIC in virtual wire mode
2071 * so legacy interrupts can be delivered.
2073 * With interrupt-remapping, for now we will use virtual wire A mode,
2074 * as virtual wire B is little complex (need to configure both
2075 * IOAPIC RTE aswell as interrupt-remapping table entry).
2076 * As this gets called during crash dump, keep this simple for now.
2078 if (ioapic_i8259
.pin
!= -1 && !intr_remapping_enabled
) {
2079 struct IO_APIC_route_entry entry
;
2081 memset(&entry
, 0, sizeof(entry
));
2082 entry
.mask
= 0; /* Enabled */
2083 entry
.trigger
= 0; /* Edge */
2085 entry
.polarity
= 0; /* High */
2086 entry
.delivery_status
= 0;
2087 entry
.dest_mode
= 0; /* Physical */
2088 entry
.delivery_mode
= dest_ExtINT
; /* ExtInt */
2090 entry
.dest
= read_apic_id();
2093 * Add it to the IO-APIC irq-routing table:
2095 ioapic_write_entry(ioapic_i8259
.apic
, ioapic_i8259
.pin
, entry
);
2099 * Use virtual wire A mode when interrupt remapping is enabled.
2101 disconnect_bsp_APIC(!intr_remapping_enabled
&& ioapic_i8259
.pin
!= -1);
2104 #ifdef CONFIG_X86_32
2106 * function to set the IO-APIC physical IDs based on the
2107 * values stored in the MPC table.
2109 * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
2112 static void __init
setup_ioapic_ids_from_mpc(void)
2114 union IO_APIC_reg_00 reg_00
;
2115 physid_mask_t phys_id_present_map
;
2118 unsigned char old_id
;
2119 unsigned long flags
;
2121 if (x86_quirks
->setup_ioapic_ids
&& x86_quirks
->setup_ioapic_ids())
2125 * Don't check I/O APIC IDs for xAPIC systems. They have
2126 * no meaning without the serial APIC bus.
2128 if (!(boot_cpu_data
.x86_vendor
== X86_VENDOR_INTEL
)
2129 || APIC_XAPIC(apic_version
[boot_cpu_physical_apicid
]))
2132 * This is broken; anything with a real cpu count has to
2133 * circumvent this idiocy regardless.
2135 phys_id_present_map
= apic
->ioapic_phys_id_map(phys_cpu_present_map
);
2138 * Set the IOAPIC ID to the value stored in the MPC table.
2140 for (apic_id
= 0; apic_id
< nr_ioapics
; apic_id
++) {
2142 /* Read the register 0 value */
2143 spin_lock_irqsave(&ioapic_lock
, flags
);
2144 reg_00
.raw
= io_apic_read(apic_id
, 0);
2145 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2147 old_id
= mp_ioapics
[apic_id
].apicid
;
2149 if (mp_ioapics
[apic_id
].apicid
>= get_physical_broadcast()) {
2150 printk(KERN_ERR
"BIOS bug, IO-APIC#%d ID is %d in the MPC table!...\n",
2151 apic_id
, mp_ioapics
[apic_id
].apicid
);
2152 printk(KERN_ERR
"... fixing up to %d. (tell your hw vendor)\n",
2154 mp_ioapics
[apic_id
].apicid
= reg_00
.bits
.ID
;
2158 * Sanity check, is the ID really free? Every APIC in a
2159 * system must have a unique ID or we get lots of nice
2160 * 'stuck on smp_invalidate_needed IPI wait' messages.
2162 if (apic
->check_apicid_used(phys_id_present_map
,
2163 mp_ioapics
[apic_id
].apicid
)) {
2164 printk(KERN_ERR
"BIOS bug, IO-APIC#%d ID %d is already used!...\n",
2165 apic_id
, mp_ioapics
[apic_id
].apicid
);
2166 for (i
= 0; i
< get_physical_broadcast(); i
++)
2167 if (!physid_isset(i
, phys_id_present_map
))
2169 if (i
>= get_physical_broadcast())
2170 panic("Max APIC ID exceeded!\n");
2171 printk(KERN_ERR
"... fixing up to %d. (tell your hw vendor)\n",
2173 physid_set(i
, phys_id_present_map
);
2174 mp_ioapics
[apic_id
].apicid
= i
;
2177 tmp
= apic
->apicid_to_cpu_present(mp_ioapics
[apic_id
].apicid
);
2178 apic_printk(APIC_VERBOSE
, "Setting %d in the "
2179 "phys_id_present_map\n",
2180 mp_ioapics
[apic_id
].apicid
);
2181 physids_or(phys_id_present_map
, phys_id_present_map
, tmp
);
2186 * We need to adjust the IRQ routing table
2187 * if the ID changed.
2189 if (old_id
!= mp_ioapics
[apic_id
].apicid
)
2190 for (i
= 0; i
< mp_irq_entries
; i
++)
2191 if (mp_irqs
[i
].dstapic
== old_id
)
2193 = mp_ioapics
[apic_id
].apicid
;
2196 * Read the right value from the MPC table and
2197 * write it into the ID register.
2199 apic_printk(APIC_VERBOSE
, KERN_INFO
2200 "...changing IO-APIC physical APIC ID to %d ...",
2201 mp_ioapics
[apic_id
].apicid
);
2203 reg_00
.bits
.ID
= mp_ioapics
[apic_id
].apicid
;
2204 spin_lock_irqsave(&ioapic_lock
, flags
);
2205 io_apic_write(apic_id
, 0, reg_00
.raw
);
2206 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2211 spin_lock_irqsave(&ioapic_lock
, flags
);
2212 reg_00
.raw
= io_apic_read(apic_id
, 0);
2213 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2214 if (reg_00
.bits
.ID
!= mp_ioapics
[apic_id
].apicid
)
2215 printk("could not set ID!\n");
2217 apic_printk(APIC_VERBOSE
, " ok.\n");
2222 int no_timer_check __initdata
;
2224 static int __init
notimercheck(char *s
)
2229 __setup("no_timer_check", notimercheck
);
2232 * There is a nasty bug in some older SMP boards, their mptable lies
2233 * about the timer IRQ. We do the following to work around the situation:
2235 * - timer IRQ defaults to IO-APIC IRQ
2236 * - if this function detects that timer IRQs are defunct, then we fall
2237 * back to ISA timer IRQs
2239 static int __init
timer_irq_works(void)
2241 unsigned long t1
= jiffies
;
2242 unsigned long flags
;
2247 local_save_flags(flags
);
2249 /* Let ten ticks pass... */
2250 mdelay((10 * 1000) / HZ
);
2251 local_irq_restore(flags
);
2254 * Expect a few ticks at least, to be sure some possible
2255 * glue logic does not lock up after one or two first
2256 * ticks in a non-ExtINT mode. Also the local APIC
2257 * might have cached one ExtINT interrupt. Finally, at
2258 * least one tick may be lost due to delays.
2262 if (time_after(jiffies
, t1
+ 4))
2268 * In the SMP+IOAPIC case it might happen that there are an unspecified
2269 * number of pending IRQ events unhandled. These cases are very rare,
2270 * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
2271 * better to do it this way as thus we do not have to be aware of
2272 * 'pending' interrupts in the IRQ path, except at this point.
2275 * Edge triggered needs to resend any interrupt
2276 * that was delayed but this is now handled in the device
2281 * Starting up a edge-triggered IO-APIC interrupt is
2282 * nasty - we need to make sure that we get the edge.
2283 * If it is already asserted for some reason, we need
2284 * return 1 to indicate that is was pending.
2286 * This is not complete - we should be able to fake
2287 * an edge even if it isn't on the 8259A...
2290 static unsigned int startup_ioapic_irq(unsigned int irq
)
2292 int was_pending
= 0;
2293 unsigned long flags
;
2294 struct irq_cfg
*cfg
;
2296 spin_lock_irqsave(&ioapic_lock
, flags
);
2297 if (irq
< NR_IRQS_LEGACY
) {
2298 disable_8259A_irq(irq
);
2299 if (i8259A_irq_pending(irq
))
2303 __unmask_IO_APIC_irq(cfg
);
2304 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2309 #ifdef CONFIG_X86_64
2310 static int ioapic_retrigger_irq(unsigned int irq
)
2313 struct irq_cfg
*cfg
= irq_cfg(irq
);
2314 unsigned long flags
;
2316 spin_lock_irqsave(&vector_lock
, flags
);
2317 apic
->send_IPI_mask(cpumask_of(cpumask_first(cfg
->domain
)), cfg
->vector
);
2318 spin_unlock_irqrestore(&vector_lock
, flags
);
2323 static int ioapic_retrigger_irq(unsigned int irq
)
2325 apic
->send_IPI_self(irq_cfg(irq
)->vector
);
2332 * Level and edge triggered IO-APIC interrupts need different handling,
2333 * so we use two separate IRQ descriptors. Edge triggered IRQs can be
2334 * handled with the level-triggered descriptor, but that one has slightly
2335 * more overhead. Level-triggered interrupts cannot be handled with the
2336 * edge-triggered handler, without risking IRQ storms and other ugly
2342 #ifdef CONFIG_INTR_REMAP
2345 * Migrate the IO-APIC irq in the presence of intr-remapping.
2347 * For both level and edge triggered, irq migration is a simple atomic
2348 * update(of vector and cpu destination) of IRTE and flush the hardware cache.
2350 * For level triggered, we eliminate the io-apic RTE modification (with the
2351 * updated vector information), by using a virtual vector (io-apic pin number).
2352 * Real vector that is used for interrupting cpu will be coming from
2353 * the interrupt-remapping table entry.
2356 migrate_ioapic_irq_desc(struct irq_desc
*desc
, const struct cpumask
*mask
)
2358 struct irq_cfg
*cfg
;
2364 if (!cpumask_intersects(mask
, cpu_online_mask
))
2368 if (get_irte(irq
, &irte
))
2371 cfg
= desc
->chip_data
;
2372 if (assign_irq_vector(irq
, cfg
, mask
))
2375 dest
= apic
->cpu_mask_to_apicid_and(cfg
->domain
, mask
);
2377 irte
.vector
= cfg
->vector
;
2378 irte
.dest_id
= IRTE_DEST(dest
);
2381 * Modified the IRTE and flushes the Interrupt entry cache.
2383 modify_irte(irq
, &irte
);
2385 if (cfg
->move_in_progress
)
2386 send_cleanup_vector(cfg
);
2388 cpumask_copy(desc
->affinity
, mask
);
2394 * Migrates the IRQ destination in the process context.
2396 static int set_ir_ioapic_affinity_irq_desc(struct irq_desc
*desc
,
2397 const struct cpumask
*mask
)
2399 return migrate_ioapic_irq_desc(desc
, mask
);
2401 static int set_ir_ioapic_affinity_irq(unsigned int irq
,
2402 const struct cpumask
*mask
)
2404 struct irq_desc
*desc
= irq_to_desc(irq
);
2406 return set_ir_ioapic_affinity_irq_desc(desc
, mask
);
2409 static inline int set_ir_ioapic_affinity_irq_desc(struct irq_desc
*desc
,
2410 const struct cpumask
*mask
)
2416 asmlinkage
void smp_irq_move_cleanup_interrupt(void)
2418 unsigned vector
, me
;
2424 me
= smp_processor_id();
2425 for (vector
= FIRST_EXTERNAL_VECTOR
; vector
< NR_VECTORS
; vector
++) {
2428 struct irq_desc
*desc
;
2429 struct irq_cfg
*cfg
;
2430 irq
= __get_cpu_var(vector_irq
)[vector
];
2435 desc
= irq_to_desc(irq
);
2440 spin_lock(&desc
->lock
);
2441 if (!cfg
->move_cleanup_count
)
2444 if (vector
== cfg
->vector
&& cpumask_test_cpu(me
, cfg
->domain
))
2447 irr
= apic_read(APIC_IRR
+ (vector
/ 32 * 0x10));
2449 * Check if the vector that needs to be cleanedup is
2450 * registered at the cpu's IRR. If so, then this is not
2451 * the best time to clean it up. Lets clean it up in the
2452 * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
2455 if (irr
& (1 << (vector
% 32))) {
2456 apic
->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR
);
2459 __get_cpu_var(vector_irq
)[vector
] = -1;
2460 cfg
->move_cleanup_count
--;
2462 spin_unlock(&desc
->lock
);
2468 static void irq_complete_move(struct irq_desc
**descp
)
2470 struct irq_desc
*desc
= *descp
;
2471 struct irq_cfg
*cfg
= desc
->chip_data
;
2472 unsigned vector
, me
;
2474 if (likely(!cfg
->move_in_progress
))
2477 vector
= ~get_irq_regs()->orig_ax
;
2478 me
= smp_processor_id();
2480 if (vector
== cfg
->vector
&& cpumask_test_cpu(me
, cfg
->domain
))
2481 send_cleanup_vector(cfg
);
2484 static inline void irq_complete_move(struct irq_desc
**descp
) {}
2487 static void __eoi_ioapic_irq(unsigned int irq
, struct irq_cfg
*cfg
)
2490 struct irq_pin_list
*entry
;
2492 entry
= cfg
->irq_2_pin
;
2500 io_apic_eoi(apic
, pin
);
2501 entry
= entry
->next
;
2506 eoi_ioapic_irq(struct irq_desc
*desc
)
2508 struct irq_cfg
*cfg
;
2509 unsigned long flags
;
2513 cfg
= desc
->chip_data
;
2515 spin_lock_irqsave(&ioapic_lock
, flags
);
2516 __eoi_ioapic_irq(irq
, cfg
);
2517 spin_unlock_irqrestore(&ioapic_lock
, flags
);
2520 #ifdef CONFIG_X86_X2APIC
2521 static void ack_x2apic_level(unsigned int irq
)
2523 struct irq_desc
*desc
= irq_to_desc(irq
);
2525 eoi_ioapic_irq(desc
);
2528 static void ack_x2apic_edge(unsigned int irq
)
2534 static void ack_apic_edge(unsigned int irq
)
2536 struct irq_desc
*desc
= irq_to_desc(irq
);
2538 irq_complete_move(&desc
);
2539 move_native_irq(irq
);
2543 atomic_t irq_mis_count
;
2545 static void ack_apic_level(unsigned int irq
)
2547 struct irq_desc
*desc
= irq_to_desc(irq
);
2549 #ifdef CONFIG_X86_32
2553 struct irq_cfg
*cfg
;
2554 int do_unmask_irq
= 0;
2556 irq_complete_move(&desc
);
2557 #ifdef CONFIG_GENERIC_PENDING_IRQ
2558 /* If we are moving the irq we need to mask it */
2559 if (unlikely(desc
->status
& IRQ_MOVE_PENDING
)) {
2561 mask_IO_APIC_irq_desc(desc
);
2565 #ifdef CONFIG_X86_32
2567 * It appears there is an erratum which affects at least version 0x11
2568 * of I/O APIC (that's the 82093AA and cores integrated into various
2569 * chipsets). Under certain conditions a level-triggered interrupt is
2570 * erroneously delivered as edge-triggered one but the respective IRR
2571 * bit gets set nevertheless. As a result the I/O unit expects an EOI
2572 * message but it will never arrive and further interrupts are blocked
2573 * from the source. The exact reason is so far unknown, but the
2574 * phenomenon was observed when two consecutive interrupt requests
2575 * from a given source get delivered to the same CPU and the source is
2576 * temporarily disabled in between.
2578 * A workaround is to simulate an EOI message manually. We achieve it
2579 * by setting the trigger mode to edge and then to level when the edge
2580 * trigger mode gets detected in the TMR of a local APIC for a
2581 * level-triggered interrupt. We mask the source for the time of the
2582 * operation to prevent an edge-triggered interrupt escaping meanwhile.
2583 * The idea is from Manfred Spraul. --macro
2585 cfg
= desc
->chip_data
;
2588 v
= apic_read(APIC_TMR
+ ((i
& ~0x1f) >> 1));
2592 * We must acknowledge the irq before we move it or the acknowledge will
2593 * not propagate properly.
2597 if (irq_remapped(irq
))
2598 eoi_ioapic_irq(desc
);
2600 /* Now we can move and renable the irq */
2601 if (unlikely(do_unmask_irq
)) {
2602 /* Only migrate the irq if the ack has been received.
2604 * On rare occasions the broadcast level triggered ack gets
2605 * delayed going to ioapics, and if we reprogram the
2606 * vector while Remote IRR is still set the irq will never
2609 * To prevent this scenario we read the Remote IRR bit
2610 * of the ioapic. This has two effects.
2611 * - On any sane system the read of the ioapic will
2612 * flush writes (and acks) going to the ioapic from
2614 * - We get to see if the ACK has actually been delivered.
2616 * Based on failed experiments of reprogramming the
2617 * ioapic entry from outside of irq context starting
2618 * with masking the ioapic entry and then polling until
2619 * Remote IRR was clear before reprogramming the
2620 * ioapic I don't trust the Remote IRR bit to be
2621 * completey accurate.
2623 * However there appears to be no other way to plug
2624 * this race, so if the Remote IRR bit is not
2625 * accurate and is causing problems then it is a hardware bug
2626 * and you can go talk to the chipset vendor about it.
2628 cfg
= desc
->chip_data
;
2629 if (!io_apic_level_ack_pending(cfg
))
2630 move_masked_irq(irq
);
2631 unmask_IO_APIC_irq_desc(desc
);
2634 #ifdef CONFIG_X86_32
2635 if (!(v
& (1 << (i
& 0x1f)))) {
2636 atomic_inc(&irq_mis_count
);
2637 spin_lock(&ioapic_lock
);
2638 __mask_and_edge_IO_APIC_irq(cfg
);
2639 __unmask_and_level_IO_APIC_irq(cfg
);
2640 spin_unlock(&ioapic_lock
);
2645 #ifdef CONFIG_INTR_REMAP
2646 static void ir_ack_apic_edge(unsigned int irq
)
2648 #ifdef CONFIG_X86_X2APIC
2649 if (x2apic_enabled())
2650 return ack_x2apic_edge(irq
);
2652 return ack_apic_edge(irq
);
2655 static void ir_ack_apic_level(unsigned int irq
)
2657 #ifdef CONFIG_X86_X2APIC
2658 if (x2apic_enabled())
2659 return ack_x2apic_level(irq
);
2661 return ack_apic_level(irq
);
2663 #endif /* CONFIG_INTR_REMAP */
2665 static struct irq_chip ioapic_chip __read_mostly
= {
2667 .startup
= startup_ioapic_irq
,
2668 .mask
= mask_IO_APIC_irq
,
2669 .unmask
= unmask_IO_APIC_irq
,
2670 .ack
= ack_apic_edge
,
2671 .eoi
= ack_apic_level
,
2673 .set_affinity
= set_ioapic_affinity_irq
,
2675 .retrigger
= ioapic_retrigger_irq
,
2678 static struct irq_chip ir_ioapic_chip __read_mostly
= {
2679 .name
= "IR-IO-APIC",
2680 .startup
= startup_ioapic_irq
,
2681 .mask
= mask_IO_APIC_irq
,
2682 .unmask
= unmask_IO_APIC_irq
,
2683 #ifdef CONFIG_INTR_REMAP
2684 .ack
= ir_ack_apic_edge
,
2685 .eoi
= ir_ack_apic_level
,
2687 .set_affinity
= set_ir_ioapic_affinity_irq
,
2690 .retrigger
= ioapic_retrigger_irq
,
2693 static inline void init_IO_APIC_traps(void)
2696 struct irq_desc
*desc
;
2697 struct irq_cfg
*cfg
;
2700 * NOTE! The local APIC isn't very good at handling
2701 * multiple interrupts at the same interrupt level.
2702 * As the interrupt level is determined by taking the
2703 * vector number and shifting that right by 4, we
2704 * want to spread these out a bit so that they don't
2705 * all fall in the same interrupt level.
2707 * Also, we've got to be careful not to trash gate
2708 * 0x80, because int 0x80 is hm, kind of importantish. ;)
2710 for_each_irq_desc(irq
, desc
) {
2711 cfg
= desc
->chip_data
;
2712 if (IO_APIC_IRQ(irq
) && cfg
&& !cfg
->vector
) {
2714 * Hmm.. We don't have an entry for this,
2715 * so default to an old-fashioned 8259
2716 * interrupt if we can..
2718 if (irq
< NR_IRQS_LEGACY
)
2719 make_8259A_irq(irq
);
2721 /* Strange. Oh, well.. */
2722 desc
->chip
= &no_irq_chip
;
2728 * The local APIC irq-chip implementation:
2731 static void mask_lapic_irq(unsigned int irq
)
2735 v
= apic_read(APIC_LVT0
);
2736 apic_write(APIC_LVT0
, v
| APIC_LVT_MASKED
);
2739 static void unmask_lapic_irq(unsigned int irq
)
2743 v
= apic_read(APIC_LVT0
);
2744 apic_write(APIC_LVT0
, v
& ~APIC_LVT_MASKED
);
2747 static void ack_lapic_irq(unsigned int irq
)
2752 static struct irq_chip lapic_chip __read_mostly
= {
2753 .name
= "local-APIC",
2754 .mask
= mask_lapic_irq
,
2755 .unmask
= unmask_lapic_irq
,
2756 .ack
= ack_lapic_irq
,
2759 static void lapic_register_intr(int irq
, struct irq_desc
*desc
)
2761 desc
->status
&= ~IRQ_LEVEL
;
2762 set_irq_chip_and_handler_name(irq
, &lapic_chip
, handle_edge_irq
,
2766 static void __init
setup_nmi(void)
2769 * Dirty trick to enable the NMI watchdog ...
2770 * We put the 8259A master into AEOI mode and
2771 * unmask on all local APICs LVT0 as NMI.
2773 * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
2774 * is from Maciej W. Rozycki - so we do not have to EOI from
2775 * the NMI handler or the timer interrupt.
2777 apic_printk(APIC_VERBOSE
, KERN_INFO
"activating NMI Watchdog ...");
2779 enable_NMI_through_LVT0();
2781 apic_printk(APIC_VERBOSE
, " done.\n");
2785 * This looks a bit hackish but it's about the only one way of sending
2786 * a few INTA cycles to 8259As and any associated glue logic. ICR does
2787 * not support the ExtINT mode, unfortunately. We need to send these
2788 * cycles as some i82489DX-based boards have glue logic that keeps the
2789 * 8259A interrupt line asserted until INTA. --macro
2791 static inline void __init
unlock_ExtINT_logic(void)
2794 struct IO_APIC_route_entry entry0
, entry1
;
2795 unsigned char save_control
, save_freq_select
;
2797 pin
= find_isa_irq_pin(8, mp_INT
);
2802 apic
= find_isa_irq_apic(8, mp_INT
);
2808 entry0
= ioapic_read_entry(apic
, pin
);
2809 clear_IO_APIC_pin(apic
, pin
);
2811 memset(&entry1
, 0, sizeof(entry1
));
2813 entry1
.dest_mode
= 0; /* physical delivery */
2814 entry1
.mask
= 0; /* unmask IRQ now */
2815 entry1
.dest
= hard_smp_processor_id();
2816 entry1
.delivery_mode
= dest_ExtINT
;
2817 entry1
.polarity
= entry0
.polarity
;
2821 ioapic_write_entry(apic
, pin
, entry1
);
2823 save_control
= CMOS_READ(RTC_CONTROL
);
2824 save_freq_select
= CMOS_READ(RTC_FREQ_SELECT
);
2825 CMOS_WRITE((save_freq_select
& ~RTC_RATE_SELECT
) | 0x6,
2827 CMOS_WRITE(save_control
| RTC_PIE
, RTC_CONTROL
);
2832 if ((CMOS_READ(RTC_INTR_FLAGS
) & RTC_PF
) == RTC_PF
)
2836 CMOS_WRITE(save_control
, RTC_CONTROL
);
2837 CMOS_WRITE(save_freq_select
, RTC_FREQ_SELECT
);
2838 clear_IO_APIC_pin(apic
, pin
);
2840 ioapic_write_entry(apic
, pin
, entry0
);
2843 static int disable_timer_pin_1 __initdata
;
2844 /* Actually the next is obsolete, but keep it for paranoid reasons -AK */
2845 static int __init
disable_timer_pin_setup(char *arg
)
2847 disable_timer_pin_1
= 1;
2850 early_param("disable_timer_pin_1", disable_timer_pin_setup
);
2852 int timer_through_8259 __initdata
;
2855 * This code may look a bit paranoid, but it's supposed to cooperate with
2856 * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
2857 * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
2858 * fanatically on his truly buggy board.
2860 * FIXME: really need to revamp this for all platforms.
2862 static inline void __init
check_timer(void)
2864 struct irq_desc
*desc
= irq_to_desc(0);
2865 struct irq_cfg
*cfg
= desc
->chip_data
;
2866 int cpu
= boot_cpu_id
;
2867 int apic1
, pin1
, apic2
, pin2
;
2868 unsigned long flags
;
2871 local_irq_save(flags
);
2874 * get/set the timer IRQ vector:
2876 disable_8259A_irq(0);
2877 assign_irq_vector(0, cfg
, apic
->target_cpus());
2880 * As IRQ0 is to be enabled in the 8259A, the virtual
2881 * wire has to be disabled in the local APIC. Also
2882 * timer interrupts need to be acknowledged manually in
2883 * the 8259A for the i82489DX when using the NMI
2884 * watchdog as that APIC treats NMIs as level-triggered.
2885 * The AEOI mode will finish them in the 8259A
2888 apic_write(APIC_LVT0
, APIC_LVT_MASKED
| APIC_DM_EXTINT
);
2890 #ifdef CONFIG_X86_32
2894 ver
= apic_read(APIC_LVR
);
2895 ver
= GET_APIC_VERSION(ver
);
2896 timer_ack
= (nmi_watchdog
== NMI_IO_APIC
&& !APIC_INTEGRATED(ver
));
2900 pin1
= find_isa_irq_pin(0, mp_INT
);
2901 apic1
= find_isa_irq_apic(0, mp_INT
);
2902 pin2
= ioapic_i8259
.pin
;
2903 apic2
= ioapic_i8259
.apic
;
2905 apic_printk(APIC_QUIET
, KERN_INFO
"..TIMER: vector=0x%02X "
2906 "apic1=%d pin1=%d apic2=%d pin2=%d\n",
2907 cfg
->vector
, apic1
, pin1
, apic2
, pin2
);
2910 * Some BIOS writers are clueless and report the ExtINTA
2911 * I/O APIC input from the cascaded 8259A as the timer
2912 * interrupt input. So just in case, if only one pin
2913 * was found above, try it both directly and through the
2917 if (intr_remapping_enabled
)
2918 panic("BIOS bug: timer not connected to IO-APIC");
2922 } else if (pin2
== -1) {
2929 * Ok, does IRQ0 through the IOAPIC work?
2932 add_pin_to_irq_cpu(cfg
, cpu
, apic1
, pin1
);
2933 setup_timer_IRQ0_pin(apic1
, pin1
, cfg
->vector
);
2935 /* for edge trigger, setup_IO_APIC_irq already
2936 * leave it unmasked.
2937 * so only need to unmask if it is level-trigger
2938 * do we really have level trigger timer?
2941 idx
= find_irq_entry(apic1
, pin1
, mp_INT
);
2942 if (idx
!= -1 && irq_trigger(idx
))
2943 unmask_IO_APIC_irq_desc(desc
);
2945 if (timer_irq_works()) {
2946 if (nmi_watchdog
== NMI_IO_APIC
) {
2948 enable_8259A_irq(0);
2950 if (disable_timer_pin_1
> 0)
2951 clear_IO_APIC_pin(0, pin1
);
2954 if (intr_remapping_enabled
)
2955 panic("timer doesn't work through Interrupt-remapped IO-APIC");
2956 local_irq_disable();
2957 clear_IO_APIC_pin(apic1
, pin1
);
2959 apic_printk(APIC_QUIET
, KERN_ERR
"..MP-BIOS bug: "
2960 "8254 timer not connected to IO-APIC\n");
2962 apic_printk(APIC_QUIET
, KERN_INFO
"...trying to set up timer "
2963 "(IRQ0) through the 8259A ...\n");
2964 apic_printk(APIC_QUIET
, KERN_INFO
2965 "..... (found apic %d pin %d) ...\n", apic2
, pin2
);
2967 * legacy devices should be connected to IO APIC #0
2969 replace_pin_at_irq_cpu(cfg
, cpu
, apic1
, pin1
, apic2
, pin2
);
2970 setup_timer_IRQ0_pin(apic2
, pin2
, cfg
->vector
);
2971 enable_8259A_irq(0);
2972 if (timer_irq_works()) {
2973 apic_printk(APIC_QUIET
, KERN_INFO
"....... works.\n");
2974 timer_through_8259
= 1;
2975 if (nmi_watchdog
== NMI_IO_APIC
) {
2976 disable_8259A_irq(0);
2978 enable_8259A_irq(0);
2983 * Cleanup, just in case ...
2985 local_irq_disable();
2986 disable_8259A_irq(0);
2987 clear_IO_APIC_pin(apic2
, pin2
);
2988 apic_printk(APIC_QUIET
, KERN_INFO
"....... failed.\n");
2991 if (nmi_watchdog
== NMI_IO_APIC
) {
2992 apic_printk(APIC_QUIET
, KERN_WARNING
"timer doesn't work "
2993 "through the IO-APIC - disabling NMI Watchdog!\n");
2994 nmi_watchdog
= NMI_NONE
;
2996 #ifdef CONFIG_X86_32
3000 apic_printk(APIC_QUIET
, KERN_INFO
3001 "...trying to set up timer as Virtual Wire IRQ...\n");
3003 lapic_register_intr(0, desc
);
3004 apic_write(APIC_LVT0
, APIC_DM_FIXED
| cfg
->vector
); /* Fixed mode */
3005 enable_8259A_irq(0);
3007 if (timer_irq_works()) {
3008 apic_printk(APIC_QUIET
, KERN_INFO
"..... works.\n");
3011 local_irq_disable();
3012 disable_8259A_irq(0);
3013 apic_write(APIC_LVT0
, APIC_LVT_MASKED
| APIC_DM_FIXED
| cfg
->vector
);
3014 apic_printk(APIC_QUIET
, KERN_INFO
"..... failed.\n");
3016 apic_printk(APIC_QUIET
, KERN_INFO
3017 "...trying to set up timer as ExtINT IRQ...\n");
3021 apic_write(APIC_LVT0
, APIC_DM_EXTINT
);
3023 unlock_ExtINT_logic();
3025 if (timer_irq_works()) {
3026 apic_printk(APIC_QUIET
, KERN_INFO
"..... works.\n");
3029 local_irq_disable();
3030 apic_printk(APIC_QUIET
, KERN_INFO
"..... failed :(.\n");
3031 panic("IO-APIC + timer doesn't work! Boot with apic=debug and send a "
3032 "report. Then try booting with the 'noapic' option.\n");
3034 local_irq_restore(flags
);
3038 * Traditionally ISA IRQ2 is the cascade IRQ, and is not available
3039 * to devices. However there may be an I/O APIC pin available for
3040 * this interrupt regardless. The pin may be left unconnected, but
3041 * typically it will be reused as an ExtINT cascade interrupt for
3042 * the master 8259A. In the MPS case such a pin will normally be
3043 * reported as an ExtINT interrupt in the MP table. With ACPI
3044 * there is no provision for ExtINT interrupts, and in the absence
3045 * of an override it would be treated as an ordinary ISA I/O APIC
3046 * interrupt, that is edge-triggered and unmasked by default. We
3047 * used to do this, but it caused problems on some systems because
3048 * of the NMI watchdog and sometimes IRQ0 of the 8254 timer using
3049 * the same ExtINT cascade interrupt to drive the local APIC of the
3050 * bootstrap processor. Therefore we refrain from routing IRQ2 to
3051 * the I/O APIC in all cases now. No actual device should request
3052 * it anyway. --macro
3054 #define PIC_IRQS (1 << PIC_CASCADE_IR)
3056 void __init
setup_IO_APIC(void)
3060 * calling enable_IO_APIC() is moved to setup_local_APIC for BP
3063 io_apic_irqs
= ~PIC_IRQS
;
3065 apic_printk(APIC_VERBOSE
, "ENABLING IO-APIC IRQs\n");
3067 * Set up IO-APIC IRQ routing.
3069 #ifdef CONFIG_X86_32
3071 setup_ioapic_ids_from_mpc();
3074 setup_IO_APIC_irqs();
3075 init_IO_APIC_traps();
3080 * Called after all the initialization is done. If we didnt find any
3081 * APIC bugs then we can allow the modify fast path
3084 static int __init
io_apic_bug_finalize(void)
3086 if (sis_apic_bug
== -1)
3091 late_initcall(io_apic_bug_finalize
);
3093 struct sysfs_ioapic_data
{
3094 struct sys_device dev
;
3095 struct IO_APIC_route_entry entry
[0];
3097 static struct sysfs_ioapic_data
* mp_ioapic_data
[MAX_IO_APICS
];
3099 static int ioapic_suspend(struct sys_device
*dev
, pm_message_t state
)
3101 struct IO_APIC_route_entry
*entry
;
3102 struct sysfs_ioapic_data
*data
;
3105 data
= container_of(dev
, struct sysfs_ioapic_data
, dev
);
3106 entry
= data
->entry
;
3107 for (i
= 0; i
< nr_ioapic_registers
[dev
->id
]; i
++, entry
++ )
3108 *entry
= ioapic_read_entry(dev
->id
, i
);
3113 static int ioapic_resume(struct sys_device
*dev
)
3115 struct IO_APIC_route_entry
*entry
;
3116 struct sysfs_ioapic_data
*data
;
3117 unsigned long flags
;
3118 union IO_APIC_reg_00 reg_00
;
3121 data
= container_of(dev
, struct sysfs_ioapic_data
, dev
);
3122 entry
= data
->entry
;
3124 spin_lock_irqsave(&ioapic_lock
, flags
);
3125 reg_00
.raw
= io_apic_read(dev
->id
, 0);
3126 if (reg_00
.bits
.ID
!= mp_ioapics
[dev
->id
].apicid
) {
3127 reg_00
.bits
.ID
= mp_ioapics
[dev
->id
].apicid
;
3128 io_apic_write(dev
->id
, 0, reg_00
.raw
);
3130 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3131 for (i
= 0; i
< nr_ioapic_registers
[dev
->id
]; i
++)
3132 ioapic_write_entry(dev
->id
, i
, entry
[i
]);
3137 static struct sysdev_class ioapic_sysdev_class
= {
3139 .suspend
= ioapic_suspend
,
3140 .resume
= ioapic_resume
,
3143 static int __init
ioapic_init_sysfs(void)
3145 struct sys_device
* dev
;
3148 error
= sysdev_class_register(&ioapic_sysdev_class
);
3152 for (i
= 0; i
< nr_ioapics
; i
++ ) {
3153 size
= sizeof(struct sys_device
) + nr_ioapic_registers
[i
]
3154 * sizeof(struct IO_APIC_route_entry
);
3155 mp_ioapic_data
[i
] = kzalloc(size
, GFP_KERNEL
);
3156 if (!mp_ioapic_data
[i
]) {
3157 printk(KERN_ERR
"Can't suspend/resume IOAPIC %d\n", i
);
3160 dev
= &mp_ioapic_data
[i
]->dev
;
3162 dev
->cls
= &ioapic_sysdev_class
;
3163 error
= sysdev_register(dev
);
3165 kfree(mp_ioapic_data
[i
]);
3166 mp_ioapic_data
[i
] = NULL
;
3167 printk(KERN_ERR
"Can't suspend/resume IOAPIC %d\n", i
);
3175 device_initcall(ioapic_init_sysfs
);
3177 static int nr_irqs_gsi
= NR_IRQS_LEGACY
;
3179 * Dynamic irq allocate and deallocation
3181 unsigned int create_irq_nr(unsigned int irq_want
)
3183 /* Allocate an unused irq */
3186 unsigned long flags
;
3187 struct irq_cfg
*cfg_new
= NULL
;
3188 int cpu
= boot_cpu_id
;
3189 struct irq_desc
*desc_new
= NULL
;
3192 if (irq_want
< nr_irqs_gsi
)
3193 irq_want
= nr_irqs_gsi
;
3195 spin_lock_irqsave(&vector_lock
, flags
);
3196 for (new = irq_want
; new < nr_irqs
; new++) {
3197 desc_new
= irq_to_desc_alloc_cpu(new, cpu
);
3199 printk(KERN_INFO
"can not get irq_desc for %d\n", new);
3202 cfg_new
= desc_new
->chip_data
;
3204 if (cfg_new
->vector
!= 0)
3206 if (__assign_irq_vector(new, cfg_new
, apic
->target_cpus()) == 0)
3210 spin_unlock_irqrestore(&vector_lock
, flags
);
3213 dynamic_irq_init(irq
);
3214 /* restore it, in case dynamic_irq_init clear it */
3216 desc_new
->chip_data
= cfg_new
;
3221 int create_irq(void)
3223 unsigned int irq_want
;
3226 irq_want
= nr_irqs_gsi
;
3227 irq
= create_irq_nr(irq_want
);
3235 void destroy_irq(unsigned int irq
)
3237 unsigned long flags
;
3238 struct irq_cfg
*cfg
;
3239 struct irq_desc
*desc
;
3241 /* store it, in case dynamic_irq_cleanup clear it */
3242 desc
= irq_to_desc(irq
);
3243 cfg
= desc
->chip_data
;
3244 dynamic_irq_cleanup(irq
);
3245 /* connect back irq_cfg */
3247 desc
->chip_data
= cfg
;
3250 spin_lock_irqsave(&vector_lock
, flags
);
3251 __clear_irq_vector(irq
, cfg
);
3252 spin_unlock_irqrestore(&vector_lock
, flags
);
3256 * MSI message composition
3258 #ifdef CONFIG_PCI_MSI
3259 static int msi_compose_msg(struct pci_dev
*pdev
, unsigned int irq
, struct msi_msg
*msg
)
3261 struct irq_cfg
*cfg
;
3269 err
= assign_irq_vector(irq
, cfg
, apic
->target_cpus());
3273 dest
= apic
->cpu_mask_to_apicid_and(cfg
->domain
, apic
->target_cpus());
3275 if (irq_remapped(irq
)) {
3280 ir_index
= map_irq_to_irte_handle(irq
, &sub_handle
);
3281 BUG_ON(ir_index
== -1);
3283 memset (&irte
, 0, sizeof(irte
));
3286 irte
.dst_mode
= apic
->irq_dest_mode
;
3287 irte
.trigger_mode
= 0; /* edge */
3288 irte
.dlvry_mode
= apic
->irq_delivery_mode
;
3289 irte
.vector
= cfg
->vector
;
3290 irte
.dest_id
= IRTE_DEST(dest
);
3292 modify_irte(irq
, &irte
);
3294 msg
->address_hi
= MSI_ADDR_BASE_HI
;
3295 msg
->data
= sub_handle
;
3296 msg
->address_lo
= MSI_ADDR_BASE_LO
| MSI_ADDR_IR_EXT_INT
|
3298 MSI_ADDR_IR_INDEX1(ir_index
) |
3299 MSI_ADDR_IR_INDEX2(ir_index
);
3301 if (x2apic_enabled())
3302 msg
->address_hi
= MSI_ADDR_BASE_HI
|
3303 MSI_ADDR_EXT_DEST_ID(dest
);
3305 msg
->address_hi
= MSI_ADDR_BASE_HI
;
3309 ((apic
->irq_dest_mode
== 0) ?
3310 MSI_ADDR_DEST_MODE_PHYSICAL
:
3311 MSI_ADDR_DEST_MODE_LOGICAL
) |
3312 ((apic
->irq_delivery_mode
!= dest_LowestPrio
) ?
3313 MSI_ADDR_REDIRECTION_CPU
:
3314 MSI_ADDR_REDIRECTION_LOWPRI
) |
3315 MSI_ADDR_DEST_ID(dest
);
3318 MSI_DATA_TRIGGER_EDGE
|
3319 MSI_DATA_LEVEL_ASSERT
|
3320 ((apic
->irq_delivery_mode
!= dest_LowestPrio
) ?
3321 MSI_DATA_DELIVERY_FIXED
:
3322 MSI_DATA_DELIVERY_LOWPRI
) |
3323 MSI_DATA_VECTOR(cfg
->vector
);
3329 static int set_msi_irq_affinity(unsigned int irq
, const struct cpumask
*mask
)
3331 struct irq_desc
*desc
= irq_to_desc(irq
);
3332 struct irq_cfg
*cfg
;
3336 dest
= set_desc_affinity(desc
, mask
);
3337 if (dest
== BAD_APICID
)
3340 cfg
= desc
->chip_data
;
3342 read_msi_msg_desc(desc
, &msg
);
3344 msg
.data
&= ~MSI_DATA_VECTOR_MASK
;
3345 msg
.data
|= MSI_DATA_VECTOR(cfg
->vector
);
3346 msg
.address_lo
&= ~MSI_ADDR_DEST_ID_MASK
;
3347 msg
.address_lo
|= MSI_ADDR_DEST_ID(dest
);
3349 write_msi_msg_desc(desc
, &msg
);
3353 #ifdef CONFIG_INTR_REMAP
3355 * Migrate the MSI irq to another cpumask. This migration is
3356 * done in the process context using interrupt-remapping hardware.
3359 ir_set_msi_irq_affinity(unsigned int irq
, const struct cpumask
*mask
)
3361 struct irq_desc
*desc
= irq_to_desc(irq
);
3362 struct irq_cfg
*cfg
= desc
->chip_data
;
3366 if (get_irte(irq
, &irte
))
3369 dest
= set_desc_affinity(desc
, mask
);
3370 if (dest
== BAD_APICID
)
3373 irte
.vector
= cfg
->vector
;
3374 irte
.dest_id
= IRTE_DEST(dest
);
3377 * atomically update the IRTE with the new destination and vector.
3379 modify_irte(irq
, &irte
);
3382 * After this point, all the interrupts will start arriving
3383 * at the new destination. So, time to cleanup the previous
3384 * vector allocation.
3386 if (cfg
->move_in_progress
)
3387 send_cleanup_vector(cfg
);
3393 #endif /* CONFIG_SMP */
3396 * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
3397 * which implement the MSI or MSI-X Capability Structure.
3399 static struct irq_chip msi_chip
= {
3401 .unmask
= unmask_msi_irq
,
3402 .mask
= mask_msi_irq
,
3403 .ack
= ack_apic_edge
,
3405 .set_affinity
= set_msi_irq_affinity
,
3407 .retrigger
= ioapic_retrigger_irq
,
3410 static struct irq_chip msi_ir_chip
= {
3411 .name
= "IR-PCI-MSI",
3412 .unmask
= unmask_msi_irq
,
3413 .mask
= mask_msi_irq
,
3414 #ifdef CONFIG_INTR_REMAP
3415 .ack
= ir_ack_apic_edge
,
3417 .set_affinity
= ir_set_msi_irq_affinity
,
3420 .retrigger
= ioapic_retrigger_irq
,
3424 * Map the PCI dev to the corresponding remapping hardware unit
3425 * and allocate 'nvec' consecutive interrupt-remapping table entries
3428 static int msi_alloc_irte(struct pci_dev
*dev
, int irq
, int nvec
)
3430 struct intel_iommu
*iommu
;
3433 iommu
= map_dev_to_ir(dev
);
3436 "Unable to map PCI %s to iommu\n", pci_name(dev
));
3440 index
= alloc_irte(iommu
, irq
, nvec
);
3443 "Unable to allocate %d IRTE for PCI %s\n", nvec
,
3450 static int setup_msi_irq(struct pci_dev
*dev
, struct msi_desc
*msidesc
, int irq
)
3455 ret
= msi_compose_msg(dev
, irq
, &msg
);
3459 set_irq_msi(irq
, msidesc
);
3460 write_msi_msg(irq
, &msg
);
3462 if (irq_remapped(irq
)) {
3463 struct irq_desc
*desc
= irq_to_desc(irq
);
3465 * irq migration in process context
3467 desc
->status
|= IRQ_MOVE_PCNTXT
;
3468 set_irq_chip_and_handler_name(irq
, &msi_ir_chip
, handle_edge_irq
, "edge");
3470 set_irq_chip_and_handler_name(irq
, &msi_chip
, handle_edge_irq
, "edge");
3472 dev_printk(KERN_DEBUG
, &dev
->dev
, "irq %d for MSI/MSI-X\n", irq
);
3477 int arch_setup_msi_irqs(struct pci_dev
*dev
, int nvec
, int type
)
3480 int ret
, sub_handle
;
3481 struct msi_desc
*msidesc
;
3482 unsigned int irq_want
;
3483 struct intel_iommu
*iommu
= NULL
;
3486 /* x86 doesn't support multiple MSI yet */
3487 if (type
== PCI_CAP_ID_MSI
&& nvec
> 1)
3490 irq_want
= nr_irqs_gsi
;
3492 list_for_each_entry(msidesc
, &dev
->msi_list
, list
) {
3493 irq
= create_irq_nr(irq_want
);
3497 if (!intr_remapping_enabled
)
3502 * allocate the consecutive block of IRTE's
3505 index
= msi_alloc_irte(dev
, irq
, nvec
);
3511 iommu
= map_dev_to_ir(dev
);
3517 * setup the mapping between the irq and the IRTE
3518 * base index, the sub_handle pointing to the
3519 * appropriate interrupt remap table entry.
3521 set_irte_irq(irq
, iommu
, index
, sub_handle
);
3524 ret
= setup_msi_irq(dev
, msidesc
, irq
);
3536 void arch_teardown_msi_irq(unsigned int irq
)
3541 #if defined (CONFIG_DMAR) || defined (CONFIG_INTR_REMAP)
3543 static int dmar_msi_set_affinity(unsigned int irq
, const struct cpumask
*mask
)
3545 struct irq_desc
*desc
= irq_to_desc(irq
);
3546 struct irq_cfg
*cfg
;
3550 dest
= set_desc_affinity(desc
, mask
);
3551 if (dest
== BAD_APICID
)
3554 cfg
= desc
->chip_data
;
3556 dmar_msi_read(irq
, &msg
);
3558 msg
.data
&= ~MSI_DATA_VECTOR_MASK
;
3559 msg
.data
|= MSI_DATA_VECTOR(cfg
->vector
);
3560 msg
.address_lo
&= ~MSI_ADDR_DEST_ID_MASK
;
3561 msg
.address_lo
|= MSI_ADDR_DEST_ID(dest
);
3563 dmar_msi_write(irq
, &msg
);
3568 #endif /* CONFIG_SMP */
3570 struct irq_chip dmar_msi_type
= {
3572 .unmask
= dmar_msi_unmask
,
3573 .mask
= dmar_msi_mask
,
3574 .ack
= ack_apic_edge
,
3576 .set_affinity
= dmar_msi_set_affinity
,
3578 .retrigger
= ioapic_retrigger_irq
,
3581 int arch_setup_dmar_msi(unsigned int irq
)
3586 ret
= msi_compose_msg(NULL
, irq
, &msg
);
3589 dmar_msi_write(irq
, &msg
);
3590 set_irq_chip_and_handler_name(irq
, &dmar_msi_type
, handle_edge_irq
,
3596 #ifdef CONFIG_HPET_TIMER
3599 static int hpet_msi_set_affinity(unsigned int irq
, const struct cpumask
*mask
)
3601 struct irq_desc
*desc
= irq_to_desc(irq
);
3602 struct irq_cfg
*cfg
;
3606 dest
= set_desc_affinity(desc
, mask
);
3607 if (dest
== BAD_APICID
)
3610 cfg
= desc
->chip_data
;
3612 hpet_msi_read(irq
, &msg
);
3614 msg
.data
&= ~MSI_DATA_VECTOR_MASK
;
3615 msg
.data
|= MSI_DATA_VECTOR(cfg
->vector
);
3616 msg
.address_lo
&= ~MSI_ADDR_DEST_ID_MASK
;
3617 msg
.address_lo
|= MSI_ADDR_DEST_ID(dest
);
3619 hpet_msi_write(irq
, &msg
);
3624 #endif /* CONFIG_SMP */
3626 static struct irq_chip hpet_msi_type
= {
3628 .unmask
= hpet_msi_unmask
,
3629 .mask
= hpet_msi_mask
,
3630 .ack
= ack_apic_edge
,
3632 .set_affinity
= hpet_msi_set_affinity
,
3634 .retrigger
= ioapic_retrigger_irq
,
3637 int arch_setup_hpet_msi(unsigned int irq
)
3641 struct irq_desc
*desc
= irq_to_desc(irq
);
3643 ret
= msi_compose_msg(NULL
, irq
, &msg
);
3647 hpet_msi_write(irq
, &msg
);
3648 desc
->status
|= IRQ_MOVE_PCNTXT
;
3649 set_irq_chip_and_handler_name(irq
, &hpet_msi_type
, handle_edge_irq
,
3656 #endif /* CONFIG_PCI_MSI */
3658 * Hypertransport interrupt support
3660 #ifdef CONFIG_HT_IRQ
3664 static void target_ht_irq(unsigned int irq
, unsigned int dest
, u8 vector
)
3666 struct ht_irq_msg msg
;
3667 fetch_ht_irq_msg(irq
, &msg
);
3669 msg
.address_lo
&= ~(HT_IRQ_LOW_VECTOR_MASK
| HT_IRQ_LOW_DEST_ID_MASK
);
3670 msg
.address_hi
&= ~(HT_IRQ_HIGH_DEST_ID_MASK
);
3672 msg
.address_lo
|= HT_IRQ_LOW_VECTOR(vector
) | HT_IRQ_LOW_DEST_ID(dest
);
3673 msg
.address_hi
|= HT_IRQ_HIGH_DEST_ID(dest
);
3675 write_ht_irq_msg(irq
, &msg
);
3678 static int set_ht_irq_affinity(unsigned int irq
, const struct cpumask
*mask
)
3680 struct irq_desc
*desc
= irq_to_desc(irq
);
3681 struct irq_cfg
*cfg
;
3684 dest
= set_desc_affinity(desc
, mask
);
3685 if (dest
== BAD_APICID
)
3688 cfg
= desc
->chip_data
;
3690 target_ht_irq(irq
, dest
, cfg
->vector
);
3697 static struct irq_chip ht_irq_chip
= {
3699 .mask
= mask_ht_irq
,
3700 .unmask
= unmask_ht_irq
,
3701 .ack
= ack_apic_edge
,
3703 .set_affinity
= set_ht_irq_affinity
,
3705 .retrigger
= ioapic_retrigger_irq
,
3708 int arch_setup_ht_irq(unsigned int irq
, struct pci_dev
*dev
)
3710 struct irq_cfg
*cfg
;
3717 err
= assign_irq_vector(irq
, cfg
, apic
->target_cpus());
3719 struct ht_irq_msg msg
;
3722 dest
= apic
->cpu_mask_to_apicid_and(cfg
->domain
,
3723 apic
->target_cpus());
3725 msg
.address_hi
= HT_IRQ_HIGH_DEST_ID(dest
);
3729 HT_IRQ_LOW_DEST_ID(dest
) |
3730 HT_IRQ_LOW_VECTOR(cfg
->vector
) |
3731 ((apic
->irq_dest_mode
== 0) ?
3732 HT_IRQ_LOW_DM_PHYSICAL
:
3733 HT_IRQ_LOW_DM_LOGICAL
) |
3734 HT_IRQ_LOW_RQEOI_EDGE
|
3735 ((apic
->irq_delivery_mode
!= dest_LowestPrio
) ?
3736 HT_IRQ_LOW_MT_FIXED
:
3737 HT_IRQ_LOW_MT_ARBITRATED
) |
3738 HT_IRQ_LOW_IRQ_MASKED
;
3740 write_ht_irq_msg(irq
, &msg
);
3742 set_irq_chip_and_handler_name(irq
, &ht_irq_chip
,
3743 handle_edge_irq
, "edge");
3745 dev_printk(KERN_DEBUG
, &dev
->dev
, "irq %d for HT\n", irq
);
3749 #endif /* CONFIG_HT_IRQ */
3751 #ifdef CONFIG_X86_UV
3753 * Re-target the irq to the specified CPU and enable the specified MMR located
3754 * on the specified blade to allow the sending of MSIs to the specified CPU.
3756 int arch_enable_uv_irq(char *irq_name
, unsigned int irq
, int cpu
, int mmr_blade
,
3757 unsigned long mmr_offset
)
3759 const struct cpumask
*eligible_cpu
= cpumask_of(cpu
);
3760 struct irq_cfg
*cfg
;
3762 unsigned long mmr_value
;
3763 struct uv_IO_APIC_route_entry
*entry
;
3764 unsigned long flags
;
3769 err
= assign_irq_vector(irq
, cfg
, eligible_cpu
);
3773 spin_lock_irqsave(&vector_lock
, flags
);
3774 set_irq_chip_and_handler_name(irq
, &uv_irq_chip
, handle_percpu_irq
,
3776 spin_unlock_irqrestore(&vector_lock
, flags
);
3779 entry
= (struct uv_IO_APIC_route_entry
*)&mmr_value
;
3780 BUG_ON(sizeof(struct uv_IO_APIC_route_entry
) != sizeof(unsigned long));
3782 entry
->vector
= cfg
->vector
;
3783 entry
->delivery_mode
= apic
->irq_delivery_mode
;
3784 entry
->dest_mode
= apic
->irq_dest_mode
;
3785 entry
->polarity
= 0;
3788 entry
->dest
= apic
->cpu_mask_to_apicid(eligible_cpu
);
3790 mmr_pnode
= uv_blade_to_pnode(mmr_blade
);
3791 uv_write_global_mmr64(mmr_pnode
, mmr_offset
, mmr_value
);
3797 * Disable the specified MMR located on the specified blade so that MSIs are
3798 * longer allowed to be sent.
3800 void arch_disable_uv_irq(int mmr_blade
, unsigned long mmr_offset
)
3802 unsigned long mmr_value
;
3803 struct uv_IO_APIC_route_entry
*entry
;
3807 entry
= (struct uv_IO_APIC_route_entry
*)&mmr_value
;
3808 BUG_ON(sizeof(struct uv_IO_APIC_route_entry
) != sizeof(unsigned long));
3812 mmr_pnode
= uv_blade_to_pnode(mmr_blade
);
3813 uv_write_global_mmr64(mmr_pnode
, mmr_offset
, mmr_value
);
3815 #endif /* CONFIG_X86_64 */
3817 int __init
io_apic_get_redir_entries (int ioapic
)
3819 union IO_APIC_reg_01 reg_01
;
3820 unsigned long flags
;
3822 spin_lock_irqsave(&ioapic_lock
, flags
);
3823 reg_01
.raw
= io_apic_read(ioapic
, 1);
3824 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3826 return reg_01
.bits
.entries
;
3829 void __init
probe_nr_irqs_gsi(void)
3833 nr
= acpi_probe_gsi();
3834 if (nr
> nr_irqs_gsi
) {
3837 /* for acpi=off or acpi is not compiled in */
3841 for (idx
= 0; idx
< nr_ioapics
; idx
++)
3842 nr
+= io_apic_get_redir_entries(idx
) + 1;
3844 if (nr
> nr_irqs_gsi
)
3848 printk(KERN_DEBUG
"nr_irqs_gsi: %d\n", nr_irqs_gsi
);
3851 #ifdef CONFIG_SPARSE_IRQ
3852 int __init
arch_probe_nr_irqs(void)
3856 if (nr_irqs
> (NR_VECTORS
* nr_cpu_ids
))
3857 nr_irqs
= NR_VECTORS
* nr_cpu_ids
;
3859 nr
= nr_irqs_gsi
+ 8 * nr_cpu_ids
;
3860 #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
3862 * for MSI and HT dyn irq
3864 nr
+= nr_irqs_gsi
* 16;
3873 /* --------------------------------------------------------------------------
3874 ACPI-based IOAPIC Configuration
3875 -------------------------------------------------------------------------- */
3879 #ifdef CONFIG_X86_32
3880 int __init
io_apic_get_unique_id(int ioapic
, int apic_id
)
3882 union IO_APIC_reg_00 reg_00
;
3883 static physid_mask_t apic_id_map
= PHYSID_MASK_NONE
;
3885 unsigned long flags
;
3889 * The P4 platform supports up to 256 APIC IDs on two separate APIC
3890 * buses (one for LAPICs, one for IOAPICs), where predecessors only
3891 * supports up to 16 on one shared APIC bus.
3893 * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
3894 * advantage of new APIC bus architecture.
3897 if (physids_empty(apic_id_map
))
3898 apic_id_map
= apic
->ioapic_phys_id_map(phys_cpu_present_map
);
3900 spin_lock_irqsave(&ioapic_lock
, flags
);
3901 reg_00
.raw
= io_apic_read(ioapic
, 0);
3902 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3904 if (apic_id
>= get_physical_broadcast()) {
3905 printk(KERN_WARNING
"IOAPIC[%d]: Invalid apic_id %d, trying "
3906 "%d\n", ioapic
, apic_id
, reg_00
.bits
.ID
);
3907 apic_id
= reg_00
.bits
.ID
;
3911 * Every APIC in a system must have a unique ID or we get lots of nice
3912 * 'stuck on smp_invalidate_needed IPI wait' messages.
3914 if (apic
->check_apicid_used(apic_id_map
, apic_id
)) {
3916 for (i
= 0; i
< get_physical_broadcast(); i
++) {
3917 if (!apic
->check_apicid_used(apic_id_map
, i
))
3921 if (i
== get_physical_broadcast())
3922 panic("Max apic_id exceeded!\n");
3924 printk(KERN_WARNING
"IOAPIC[%d]: apic_id %d already used, "
3925 "trying %d\n", ioapic
, apic_id
, i
);
3930 tmp
= apic
->apicid_to_cpu_present(apic_id
);
3931 physids_or(apic_id_map
, apic_id_map
, tmp
);
3933 if (reg_00
.bits
.ID
!= apic_id
) {
3934 reg_00
.bits
.ID
= apic_id
;
3936 spin_lock_irqsave(&ioapic_lock
, flags
);
3937 io_apic_write(ioapic
, 0, reg_00
.raw
);
3938 reg_00
.raw
= io_apic_read(ioapic
, 0);
3939 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3942 if (reg_00
.bits
.ID
!= apic_id
) {
3943 printk("IOAPIC[%d]: Unable to change apic_id!\n", ioapic
);
3948 apic_printk(APIC_VERBOSE
, KERN_INFO
3949 "IOAPIC[%d]: Assigned apic_id %d\n", ioapic
, apic_id
);
3954 int __init
io_apic_get_version(int ioapic
)
3956 union IO_APIC_reg_01 reg_01
;
3957 unsigned long flags
;
3959 spin_lock_irqsave(&ioapic_lock
, flags
);
3960 reg_01
.raw
= io_apic_read(ioapic
, 1);
3961 spin_unlock_irqrestore(&ioapic_lock
, flags
);
3963 return reg_01
.bits
.version
;
3967 int io_apic_set_pci_routing (int ioapic
, int pin
, int irq
, int triggering
, int polarity
)
3969 struct irq_desc
*desc
;
3970 struct irq_cfg
*cfg
;
3971 int cpu
= boot_cpu_id
;
3973 if (!IO_APIC_IRQ(irq
)) {
3974 apic_printk(APIC_QUIET
,KERN_ERR
"IOAPIC[%d]: Invalid reference to IRQ 0\n",
3979 desc
= irq_to_desc_alloc_cpu(irq
, cpu
);
3981 printk(KERN_INFO
"can not get irq_desc %d\n", irq
);
3986 * IRQs < 16 are already in the irq_2_pin[] map
3988 if (irq
>= NR_IRQS_LEGACY
) {
3989 cfg
= desc
->chip_data
;
3990 add_pin_to_irq_cpu(cfg
, cpu
, ioapic
, pin
);
3993 setup_IO_APIC_irq(ioapic
, pin
, irq
, desc
, triggering
, polarity
);
3999 int acpi_get_override_irq(int bus_irq
, int *trigger
, int *polarity
)
4003 if (skip_ioapic_setup
)
4006 for (i
= 0; i
< mp_irq_entries
; i
++)
4007 if (mp_irqs
[i
].irqtype
== mp_INT
&&
4008 mp_irqs
[i
].srcbusirq
== bus_irq
)
4010 if (i
>= mp_irq_entries
)
4013 *trigger
= irq_trigger(i
);
4014 *polarity
= irq_polarity(i
);
4018 #endif /* CONFIG_ACPI */
4021 * This function currently is only a helper for the i386 smp boot process where
4022 * we need to reprogram the ioredtbls to cater for the cpus which have come online
4023 * so mask in all cases should simply be apic->target_cpus()
4026 void __init
setup_ioapic_dest(void)
4028 int pin
, ioapic
, irq
, irq_entry
;
4029 struct irq_desc
*desc
;
4030 struct irq_cfg
*cfg
;
4031 const struct cpumask
*mask
;
4033 if (skip_ioapic_setup
== 1)
4036 for (ioapic
= 0; ioapic
< nr_ioapics
; ioapic
++) {
4037 for (pin
= 0; pin
< nr_ioapic_registers
[ioapic
]; pin
++) {
4038 irq_entry
= find_irq_entry(ioapic
, pin
, mp_INT
);
4039 if (irq_entry
== -1)
4041 irq
= pin_2_irq(irq_entry
, ioapic
, pin
);
4043 /* setup_IO_APIC_irqs could fail to get vector for some device
4044 * when you have too many devices, because at that time only boot
4047 desc
= irq_to_desc(irq
);
4048 cfg
= desc
->chip_data
;
4050 setup_IO_APIC_irq(ioapic
, pin
, irq
, desc
,
4051 irq_trigger(irq_entry
),
4052 irq_polarity(irq_entry
));
4058 * Honour affinities which have been set in early boot
4061 (IRQ_NO_BALANCING
| IRQ_AFFINITY_SET
))
4062 mask
= desc
->affinity
;
4064 mask
= apic
->target_cpus();
4066 if (intr_remapping_enabled
)
4067 set_ir_ioapic_affinity_irq_desc(desc
, mask
);
4069 set_ioapic_affinity_irq_desc(desc
, mask
);
4076 #define IOAPIC_RESOURCE_NAME_SIZE 11
4078 static struct resource
*ioapic_resources
;
4080 static struct resource
* __init
ioapic_setup_resources(void)
4083 struct resource
*res
;
4087 if (nr_ioapics
<= 0)
4090 n
= IOAPIC_RESOURCE_NAME_SIZE
+ sizeof(struct resource
);
4093 mem
= alloc_bootmem(n
);
4097 mem
+= sizeof(struct resource
) * nr_ioapics
;
4099 for (i
= 0; i
< nr_ioapics
; i
++) {
4101 res
[i
].flags
= IORESOURCE_MEM
| IORESOURCE_BUSY
;
4102 sprintf(mem
, "IOAPIC %u", i
);
4103 mem
+= IOAPIC_RESOURCE_NAME_SIZE
;
4107 ioapic_resources
= res
;
4112 void __init
ioapic_init_mappings(void)
4114 unsigned long ioapic_phys
, idx
= FIX_IO_APIC_BASE_0
;
4115 struct resource
*ioapic_res
;
4118 ioapic_res
= ioapic_setup_resources();
4119 for (i
= 0; i
< nr_ioapics
; i
++) {
4120 if (smp_found_config
) {
4121 ioapic_phys
= mp_ioapics
[i
].apicaddr
;
4122 #ifdef CONFIG_X86_32
4125 "WARNING: bogus zero IO-APIC "
4126 "address found in MPTABLE, "
4127 "disabling IO/APIC support!\n");
4128 smp_found_config
= 0;
4129 skip_ioapic_setup
= 1;
4130 goto fake_ioapic_page
;
4134 #ifdef CONFIG_X86_32
4137 ioapic_phys
= (unsigned long)
4138 alloc_bootmem_pages(PAGE_SIZE
);
4139 ioapic_phys
= __pa(ioapic_phys
);
4141 set_fixmap_nocache(idx
, ioapic_phys
);
4142 apic_printk(APIC_VERBOSE
,
4143 "mapped IOAPIC to %08lx (%08lx)\n",
4144 __fix_to_virt(idx
), ioapic_phys
);
4147 if (ioapic_res
!= NULL
) {
4148 ioapic_res
->start
= ioapic_phys
;
4149 ioapic_res
->end
= ioapic_phys
+ (4 * 1024) - 1;
4155 static int __init
ioapic_insert_resources(void)
4158 struct resource
*r
= ioapic_resources
;
4161 if (nr_ioapics
> 0) {
4163 "IO APIC resources couldn't be allocated.\n");
4169 for (i
= 0; i
< nr_ioapics
; i
++) {
4170 insert_resource(&iomem_resource
, r
);
4177 /* Insert the IO APIC resources after PCI initialization has occured to handle
4178 * IO APICS that are mapped in on a BAR in PCI space. */
4179 late_initcall(ioapic_insert_resources
);