xref: /openbmc/linux/arch/x86/kernel/irqinit.c (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
231cb45efSPekka Enberg #include <linux/linkage.h>
331cb45efSPekka Enberg #include <linux/errno.h>
431cb45efSPekka Enberg #include <linux/signal.h>
531cb45efSPekka Enberg #include <linux/sched.h>
631cb45efSPekka Enberg #include <linux/ioport.h>
731cb45efSPekka Enberg #include <linux/interrupt.h>
8447ae316SNicolai Stange #include <linux/irq.h>
931cb45efSPekka Enberg #include <linux/timex.h>
1031cb45efSPekka Enberg #include <linux/random.h>
1147f16ca7SIngo Molnar #include <linux/kprobes.h>
1231cb45efSPekka Enberg #include <linux/init.h>
1331cb45efSPekka Enberg #include <linux/kernel_stat.h>
14edbaa603SKay Sievers #include <linux/device.h>
1531cb45efSPekka Enberg #include <linux/bitops.h>
1631cb45efSPekka Enberg #include <linux/acpi.h>
1731cb45efSPekka Enberg #include <linux/io.h>
1831cb45efSPekka Enberg #include <linux/delay.h>
1965fddcfcSMike Rapoport #include <linux/pgtable.h>
2031cb45efSPekka Enberg 
2160063497SArun Sharma #include <linux/atomic.h>
2231cb45efSPekka Enberg #include <asm/timer.h>
2331cb45efSPekka Enberg #include <asm/hw_irq.h>
2431cb45efSPekka Enberg #include <asm/desc.h>
2513c01139SIngo Molnar #include <asm/io_apic.h>
2613c01139SIngo Molnar #include <asm/acpi.h>
2731cb45efSPekka Enberg #include <asm/apic.h>
2831cb45efSPekka Enberg #include <asm/setup.h>
2931cb45efSPekka Enberg #include <asm/i8259.h>
3031cb45efSPekka Enberg #include <asm/traps.h>
313879a6f3SSebastian Andrzej Siewior #include <asm/prom.h>
3231cb45efSPekka Enberg 
3331cb45efSPekka Enberg /*
3431cb45efSPekka Enberg  * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts:
3531cb45efSPekka Enberg  * (these are usually mapped to vectors 0x30-0x3f)
3631cb45efSPekka Enberg  */
3731cb45efSPekka Enberg 
3831cb45efSPekka Enberg /*
3931cb45efSPekka Enberg  * The IO-APIC gives us many more interrupt sources. Most of these
4031cb45efSPekka Enberg  * are unused but an SMP system is supposed to have enough memory ...
4131cb45efSPekka Enberg  * sometimes (mostly wrt. hw bugs) we get corrupted vectors all
4231cb45efSPekka Enberg  * across the spectrum, so we really want to be prepared to get all
4331cb45efSPekka Enberg  * of these. Plus, more powerful systems might have more than 64
4431cb45efSPekka Enberg  * IO-APIC registers.
4531cb45efSPekka Enberg  *
4631cb45efSPekka Enberg  * (these are usually mapped into the 0x30-0xff vector range)
4731cb45efSPekka Enberg  */
4831cb45efSPekka Enberg 
4931cb45efSPekka Enberg DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
507276c6a2SThomas Gleixner 	[0 ... NR_VECTORS - 1] = VECTOR_UNUSED,
5131cb45efSPekka Enberg };
5231cb45efSPekka Enberg 
init_ISA_irqs(void)53d9112f43SThomas Gleixner void __init init_ISA_irqs(void)
5431cb45efSPekka Enberg {
55011d578fSThomas Gleixner 	struct irq_chip *chip = legacy_pic->chip;
5631cb45efSPekka Enberg 	int i;
5731cb45efSPekka Enberg 
58ccf5355dSDou Liyang 	/*
59ccf5355dSDou Liyang 	 * Try to set up the through-local-APIC virtual wire mode earlier.
60ccf5355dSDou Liyang 	 *
61ccf5355dSDou Liyang 	 * On some 32-bit UP machines, whose APIC has been disabled by BIOS
62ccf5355dSDou Liyang 	 * and then got re-enabled by "lapic", it hangs at boot time without this.
63ccf5355dSDou Liyang 	 */
64fc90ccfdSVille Syrjälä 	init_bsp_APIC();
65ccf5355dSDou Liyang 
66b81bb373SJacob Pan 	legacy_pic->init(0);
6731cb45efSPekka Enberg 
68*5fa55950SThomas Gleixner 	for (i = 0; i < nr_legacy_irqs(); i++) {
6960e684f0SMaciej W. Rozycki 		irq_set_chip_and_handler(i, chip, handle_level_irq);
70*5fa55950SThomas Gleixner 		irq_set_status_flags(i, IRQ_LEVEL);
71*5fa55950SThomas Gleixner 	}
7231cb45efSPekka Enberg }
7331cb45efSPekka Enberg 
init_IRQ(void)7454e2603fSThomas Gleixner void __init init_IRQ(void)
7566bcaf0bSThomas Gleixner {
7697943390SSuresh Siddha 	int i;
7797943390SSuresh Siddha 
7897943390SSuresh Siddha 	/*
798b455e65SBrian Gerst 	 * On cpu 0, Assign ISA_IRQ_VECTOR(irq) to IRQ 0..15.
8097943390SSuresh Siddha 	 * If these IRQ's are handled by legacy interrupt-controllers like PIC,
8197943390SSuresh Siddha 	 * then this configuration will likely be static after the boot. If
824d1d0977SMartin Molnar 	 * these IRQs are handled by more modern controllers like IO-APIC,
8397943390SSuresh Siddha 	 * then this vector space can be freed and re-used dynamically as the
8497943390SSuresh Siddha 	 * irq's migrate etc.
8597943390SSuresh Siddha 	 */
8695d76accSJiang Liu 	for (i = 0; i < nr_legacy_irqs(); i++)
87a782a7e4SThomas Gleixner 		per_cpu(vector_irq, 0)[ISA_IRQ_VECTOR(i)] = irq_to_desc(i);
8897943390SSuresh Siddha 
8966c7ceb4SThomas Gleixner 	BUG_ON(irq_init_percpu_irqstack(smp_processor_id()));
90451f743aSThomas Gleixner 
9166bcaf0bSThomas Gleixner 	x86_init.irqs.intr_init();
9266bcaf0bSThomas Gleixner }
9331cb45efSPekka Enberg 
native_init_IRQ(void)9431cb45efSPekka Enberg void __init native_init_IRQ(void)
9531cb45efSPekka Enberg {
9631cb45efSPekka Enberg 	/* Execute any quirks before the call gates are initialised: */
97d9112f43SThomas Gleixner 	x86_init.irqs.pre_vector_init();
9831cb45efSPekka Enberg 
99636a7598SThomas Gleixner 	idt_setup_apic_and_irq_gates();
1000fa115daSThomas Gleixner 	lapic_assign_system_vectors();
10177857dc0SYinghai Lu 
1024dd2a1b9Safzal mohammed 	if (!acpi_ioapic && !of_ioapic && nr_legacy_irqs()) {
1034dd2a1b9Safzal mohammed 		/* IRQ2 is cascade interrupt to second interrupt controller */
1044dd2a1b9Safzal mohammed 		if (request_irq(2, no_action, IRQF_NO_THREAD, "cascade", NULL))
1054dd2a1b9Safzal mohammed 			pr_err("%s: request_irq() failed\n", "cascade");
1064dd2a1b9Safzal mohammed 	}
10731cb45efSPekka Enberg }
108