blob: 16919a9671fa93f89aac7ed279097898f6516b33 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Pekka Enberg77883862009-04-09 11:52:26 +03002#include <linux/linkage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003#include <linux/errno.h>
4#include <linux/signal.h>
5#include <linux/sched.h>
6#include <linux/ioport.h>
7#include <linux/interrupt.h>
Nicolai Stange447ae312018-07-29 12:15:33 +02008#include <linux/irq.h>
Pekka Enberg77883862009-04-09 11:52:26 +03009#include <linux/timex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/random.h>
Ingo Molnar47f16ca2009-04-10 14:58:05 +020011#include <linux/kprobes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/kernel_stat.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080014#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/bitops.h>
Pekka Enberg77883862009-04-09 11:52:26 +030016#include <linux/acpi.h>
Jaswinder Singh Rajputaa09e6c2009-01-04 16:35:17 +053017#include <linux/io.h>
18#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Arun Sharma600634972011-07-26 16:09:06 -070020#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/timer.h>
Pekka Enberg77883862009-04-09 11:52:26 +030022#include <asm/hw_irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/desc.h>
25#include <asm/apic.h>
Ingo Molnar8e6dafd2009-02-23 00:34:39 +010026#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <asm/i8259.h>
Jaswinder Singh Rajputaa09e6c2009-01-04 16:35:17 +053028#include <asm/traps.h>
Sebastian Andrzej Siewior3879a6f2011-02-22 21:07:40 +010029#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Pekka Enberg77883862009-04-09 11:52:26 +030031/*
32 * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts:
33 * (these are usually mapped to vectors 0x30-0x3f)
34 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36/*
Pekka Enberg77883862009-04-09 11:52:26 +030037 * The IO-APIC gives us many more interrupt sources. Most of these
38 * are unused but an SMP system is supposed to have enough memory ...
39 * sometimes (mostly wrt. hw bugs) we get corrupted vectors all
40 * across the spectrum, so we really want to be prepared to get all
41 * of these. Plus, more powerful systems might have more than 64
42 * IO-APIC registers.
43 *
44 * (these are usually mapped into the 0x30-0xff vector range)
45 */
46
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040047/*
48 * IRQ2 is cascade interrupt to second interrupt controller
49 */
50static struct irqaction irq2 = {
51 .handler = no_action,
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040052 .name = "cascade",
Thomas Gleixner9bbbff22011-01-27 18:17:01 +010053 .flags = IRQF_NO_THREAD,
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040054};
55
Yinghai Lu497c9a12008-08-19 20:50:28 -070056DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
Thomas Gleixner7276c6a2015-08-02 20:38:25 +000057 [0 ... NR_VECTORS - 1] = VECTOR_UNUSED,
Yinghai Lu497c9a12008-08-19 20:50:28 -070058};
59
Thomas Gleixnerd9112f42009-08-20 09:41:38 +020060void __init init_ISA_irqs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Thomas Gleixner011d5782010-09-28 00:15:31 +020062 struct irq_chip *chip = legacy_pic->chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 int i;
64
Dou Liyangccf53552018-01-17 15:37:48 +080065 /*
66 * Try to set up the through-local-APIC virtual wire mode earlier.
67 *
68 * On some 32-bit UP machines, whose APIC has been disabled by BIOS
69 * and then got re-enabled by "lapic", it hangs at boot time without this.
70 */
Ville Syrjäläfc90ccf2017-11-28 16:53:50 +020071 init_bsp_APIC();
Dou Liyangccf53552018-01-17 15:37:48 +080072
Jacob Panb81bb372009-11-09 11:27:04 -080073 legacy_pic->init(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Jiang Liu95d76ac2014-06-09 16:19:48 +080075 for (i = 0; i < nr_legacy_irqs(); i++)
Maciej W. Rozycki60e684f2014-10-26 16:06:28 +000076 irq_set_chip_and_handler(i, chip, handle_level_irq);
Pekka Enberg7371d9f2009-04-09 11:52:19 +030077}
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Thomas Gleixner54e26032009-09-16 08:42:26 +020079void __init init_IRQ(void)
Thomas Gleixner66bcaf02009-08-20 09:59:09 +020080{
Suresh Siddha97943392010-01-19 12:20:54 -080081 int i;
82
83 /*
Brian Gerst8b455e62015-05-09 11:36:53 -040084 * On cpu 0, Assign ISA_IRQ_VECTOR(irq) to IRQ 0..15.
Suresh Siddha97943392010-01-19 12:20:54 -080085 * If these IRQ's are handled by legacy interrupt-controllers like PIC,
86 * then this configuration will likely be static after the boot. If
87 * these IRQ's are handled by more mordern controllers like IO-APIC,
88 * then this vector space can be freed and re-used dynamically as the
89 * irq's migrate etc.
90 */
Jiang Liu95d76ac2014-06-09 16:19:48 +080091 for (i = 0; i < nr_legacy_irqs(); i++)
Thomas Gleixnera782a7e2015-08-02 20:38:27 +000092 per_cpu(vector_irq, 0)[ISA_IRQ_VECTOR(i)] = irq_to_desc(i);
Suresh Siddha97943392010-01-19 12:20:54 -080093
Thomas Gleixner66c7ceb2019-04-14 18:00:04 +020094 BUG_ON(irq_init_percpu_irqstack(smp_processor_id()));
Thomas Gleixner451f7432019-04-14 18:00:03 +020095
Thomas Gleixner66bcaf02009-08-20 09:59:09 +020096 x86_init.irqs.intr_init();
97}
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040098
Pekka Enberg22813c42009-04-09 11:52:21 +030099void __init native_init_IRQ(void)
100{
Pekka Enberg22813c42009-04-09 11:52:21 +0300101 /* Execute any quirks before the call gates are initialised: */
Thomas Gleixnerd9112f42009-08-20 09:41:38 +0200102 x86_init.irqs.pre_vector_init();
Pekka Enberg22813c42009-04-09 11:52:21 +0300103
Thomas Gleixner636a7592017-08-28 08:47:54 +0200104 idt_setup_apic_and_irq_gates();
Thomas Gleixner0fa115d2017-09-13 23:29:38 +0200105 lapic_assign_system_vectors();
Yinghai Lu77857dc2009-04-15 11:57:01 -0700106
Andy Shevchenkoa90b8582014-07-21 11:38:40 +0300107 if (!acpi_ioapic && !of_ioapic && nr_legacy_irqs())
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +0400108 setup_irq(2, &irq2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}