blob: 218cd06f22f6da3bc7ecb6e4eddcae20931b396c [file] [log] [blame]
Pekka Enberg77883862009-04-09 11:52:26 +03001#include <linux/linkage.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#include <linux/errno.h>
3#include <linux/signal.h>
4#include <linux/sched.h>
5#include <linux/ioport.h>
6#include <linux/interrupt.h>
Pekka Enberg77883862009-04-09 11:52:26 +03007#include <linux/timex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/random.h>
Ingo Molnar47f16ca2009-04-10 14:58:05 +02009#include <linux/kprobes.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/init.h>
11#include <linux/kernel_stat.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080012#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/bitops.h>
Pekka Enberg77883862009-04-09 11:52:26 +030014#include <linux/acpi.h>
Jaswinder Singh Rajputaa09e6c2009-01-04 16:35:17 +053015#include <linux/io.h>
16#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Arun Sharma600634972011-07-26 16:09:06 -070018#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/timer.h>
Pekka Enberg77883862009-04-09 11:52:26 +030020#include <asm/hw_irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/desc.h>
23#include <asm/apic.h>
Ingo Molnar8e6dafd2009-02-23 00:34:39 +010024#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/i8259.h>
Jaswinder Singh Rajputaa09e6c2009-01-04 16:35:17 +053026#include <asm/traps.h>
Sebastian Andrzej Siewior3879a6f2011-02-22 21:07:40 +010027#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Pekka Enberg77883862009-04-09 11:52:26 +030029/*
30 * ISA PIC or low IO-APIC triggered (INTA-cycle or APIC) interrupts:
31 * (these are usually mapped to vectors 0x30-0x3f)
32 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34/*
Pekka Enberg77883862009-04-09 11:52:26 +030035 * The IO-APIC gives us many more interrupt sources. Most of these
36 * are unused but an SMP system is supposed to have enough memory ...
37 * sometimes (mostly wrt. hw bugs) we get corrupted vectors all
38 * across the spectrum, so we really want to be prepared to get all
39 * of these. Plus, more powerful systems might have more than 64
40 * IO-APIC registers.
41 *
42 * (these are usually mapped into the 0x30-0xff vector range)
43 */
44
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040045/*
46 * IRQ2 is cascade interrupt to second interrupt controller
47 */
48static struct irqaction irq2 = {
49 .handler = no_action,
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040050 .name = "cascade",
Thomas Gleixner9bbbff22011-01-27 18:17:01 +010051 .flags = IRQF_NO_THREAD,
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040052};
53
Yinghai Lu497c9a12008-08-19 20:50:28 -070054DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
Thomas Gleixner7276c6a2015-08-02 20:38:25 +000055 [0 ... NR_VECTORS - 1] = VECTOR_UNUSED,
Yinghai Lu497c9a12008-08-19 20:50:28 -070056};
57
Thomas Gleixnerd9112f42009-08-20 09:41:38 +020058void __init init_ISA_irqs(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Thomas Gleixner011d5782010-09-28 00:15:31 +020060 struct irq_chip *chip = legacy_pic->chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 int i;
62
Pekka Enberg598c73d2009-04-09 11:52:24 +030063#if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
Pekka Enberg7371d9f2009-04-09 11:52:19 +030064 init_bsp_APIC();
65#endif
Jacob Panb81bb372009-11-09 11:27:04 -080066 legacy_pic->init(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Jiang Liu95d76ac2014-06-09 16:19:48 +080068 for (i = 0; i < nr_legacy_irqs(); i++)
Maciej W. Rozycki60e684f2014-10-26 16:06:28 +000069 irq_set_chip_and_handler(i, chip, handle_level_irq);
Pekka Enberg7371d9f2009-04-09 11:52:19 +030070}
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Thomas Gleixner54e26032009-09-16 08:42:26 +020072void __init init_IRQ(void)
Thomas Gleixner66bcaf02009-08-20 09:59:09 +020073{
Suresh Siddha97943392010-01-19 12:20:54 -080074 int i;
75
76 /*
Brian Gerst8b455e62015-05-09 11:36:53 -040077 * On cpu 0, Assign ISA_IRQ_VECTOR(irq) to IRQ 0..15.
Suresh Siddha97943392010-01-19 12:20:54 -080078 * If these IRQ's are handled by legacy interrupt-controllers like PIC,
79 * then this configuration will likely be static after the boot. If
80 * these IRQ's are handled by more mordern controllers like IO-APIC,
81 * then this vector space can be freed and re-used dynamically as the
82 * irq's migrate etc.
83 */
Jiang Liu95d76ac2014-06-09 16:19:48 +080084 for (i = 0; i < nr_legacy_irqs(); i++)
Thomas Gleixnera782a7e2015-08-02 20:38:27 +000085 per_cpu(vector_irq, 0)[ISA_IRQ_VECTOR(i)] = irq_to_desc(i);
Suresh Siddha97943392010-01-19 12:20:54 -080086
Thomas Gleixner66bcaf02009-08-20 09:59:09 +020087 x86_init.irqs.intr_init();
88}
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040089
Pekka Enberg22813c42009-04-09 11:52:21 +030090void __init native_init_IRQ(void)
91{
92 int i;
93
94 /* Execute any quirks before the call gates are initialised: */
Thomas Gleixnerd9112f42009-08-20 09:41:38 +020095 x86_init.irqs.pre_vector_init();
Pekka Enberg22813c42009-04-09 11:52:21 +030096
Thomas Gleixner636a7592017-08-28 08:47:54 +020097 idt_setup_apic_and_irq_gates();
Yinghai Lu77857dc2009-04-15 11:57:01 -070098
Pekka Enberg22813c42009-04-09 11:52:21 +030099 /*
100 * Cover the whole vector space, no vector can escape
101 * us. (some of these will be overridden and become
102 * 'special' SMP interrupts)
103 */
Akinobu Mita0b2f4d42012-03-23 15:02:06 -0700104 i = FIRST_EXTERNAL_VECTOR;
Thomas Gleixner05161b92017-08-28 08:47:18 +0200105 for_each_clear_bit_from(i, used_vectors, FIRST_SYSTEM_VECTOR) {
Yinghai Lu77857dc2009-04-15 11:57:01 -0700106 /* IA32_SYSCALL_VECTOR could be used in trap_init already. */
Denys Vlasenko3304c9c2015-04-03 21:49:13 +0200107 set_intr_gate(i, irq_entries_start +
108 8 * (i - FIRST_EXTERNAL_VECTOR));
Pekka Enberg22813c42009-04-09 11:52:21 +0300109 }
Jan Beulich2414e022014-11-03 08:39:43 +0000110#ifdef CONFIG_X86_LOCAL_APIC
111 for_each_clear_bit_from(i, used_vectors, NR_VECTORS)
112 set_intr_gate(i, spurious_interrupt);
113#endif
Andi Kleen7856f6c2009-04-28 23:32:56 +0200114
Andy Shevchenkoa90b8582014-07-21 11:38:40 +0300115 if (!acpi_ioapic && !of_ioapic && nr_legacy_irqs())
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +0400116 setup_irq(2, &irq2);
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 irq_ctx_init(smp_processor_id());
119}