blob: 626977200a584c9b89f672a6c9d9e41c5c39443b [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/slab.h>
9#include <linux/random.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/init.h>
11#include <linux/kernel_stat.h>
12#include <linux/sysdev.h>
13#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/atomic.h>
19#include <asm/system.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/timer.h>
Pekka Enberg77883862009-04-09 11:52:26 +030021#include <asm/hw_irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/pgtable.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <asm/desc.h>
24#include <asm/apic.h>
Ingo Molnar8e6dafd2009-02-23 00:34:39 +010025#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/i8259.h>
Jaswinder Singh Rajputaa09e6c2009-01-04 16:35:17 +053027#include <asm/traps.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 */
33
34/*
35 * 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
Pekka Enberg320fd992009-04-09 11:52:25 +030045#ifdef CONFIG_X86_32
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/*
47 * Note that on a 486, we don't want to do a SIGFPE on an irq13
48 * as the irq is unreliable, and exception 16 works correctly
49 * (ie as explained in the intel literature). On a 386, you
50 * can't use exception 16 due to bad IBM design, so we have to
51 * rely on the less exact irq13.
52 *
53 * Careful.. Not only is IRQ13 unreliable, but it is also
54 * leads to races. IBM designers who came up with it should
55 * be shot.
56 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
David Howells7d12e782006-10-05 14:55:46 +010058static irqreturn_t math_error_irq(int cpl, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
Jaswinder Singh Rajputaa09e6c2009-01-04 16:35:17 +053060 outb(0, 0xF0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 if (ignore_fpu_irq || !boot_cpu_data.hard_math)
62 return IRQ_NONE;
H. Peter Anvin65ea5b02008-01-30 13:30:56 +010063 math_error((void __user *)get_irq_regs()->ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 return IRQ_HANDLED;
65}
66
67/*
68 * New motherboards sometimes make IRQ 13 be a PCI interrupt,
69 * so allow interrupt sharing.
70 */
Thomas Gleixner6a61f6a2007-10-17 18:04:36 +020071static struct irqaction fpu_irq = {
72 .handler = math_error_irq,
Thomas Gleixner6a61f6a2007-10-17 18:04:36 +020073 .name = "fpu",
74};
Pekka Enberg320fd992009-04-09 11:52:25 +030075#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040077/*
78 * IRQ2 is cascade interrupt to second interrupt controller
79 */
80static struct irqaction irq2 = {
81 .handler = no_action,
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +040082 .name = "cascade",
83};
84
Yinghai Lu497c9a12008-08-19 20:50:28 -070085DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
86 [0 ... IRQ0_VECTOR - 1] = -1,
87 [IRQ0_VECTOR] = 0,
88 [IRQ1_VECTOR] = 1,
89 [IRQ2_VECTOR] = 2,
90 [IRQ3_VECTOR] = 3,
91 [IRQ4_VECTOR] = 4,
92 [IRQ5_VECTOR] = 5,
93 [IRQ6_VECTOR] = 6,
94 [IRQ7_VECTOR] = 7,
95 [IRQ8_VECTOR] = 8,
96 [IRQ9_VECTOR] = 9,
97 [IRQ10_VECTOR] = 10,
98 [IRQ11_VECTOR] = 11,
99 [IRQ12_VECTOR] = 12,
100 [IRQ13_VECTOR] = 13,
101 [IRQ14_VECTOR] = 14,
102 [IRQ15_VECTOR] = 15,
103 [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1
104};
105
Yinghai Lub77b8812008-12-19 15:23:44 -0800106int vector_used_by_percpu_irq(unsigned int vector)
107{
108 int cpu;
109
110 for_each_online_cpu(cpu) {
111 if (per_cpu(vector_irq, cpu)[vector] != -1)
112 return 1;
113 }
114
115 return 0;
116}
117
Pekka Enberg7371d9f2009-04-09 11:52:19 +0300118static void __init init_ISA_irqs(void)
119{
120 int i;
121
Pekka Enberg598c73d2009-04-09 11:52:24 +0300122#if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
Pekka Enberg7371d9f2009-04-09 11:52:19 +0300123 init_bsp_APIC();
124#endif
125 init_8259A(0);
126
127 /*
128 * 16 old-style INTA-cycle interrupts:
129 */
130 for (i = 0; i < NR_IRQS_LEGACY; i++) {
131 struct irq_desc *desc = irq_to_desc(i);
132
133 desc->status = IRQ_DISABLED;
134 desc->action = NULL;
135 desc->depth = 1;
136
137 set_irq_chip_and_handler_name(i, &i8259A_chip,
138 handle_level_irq, "XT");
139 }
140}
141
Rusty Russelld3561b72006-12-07 02:14:07 +0100142/* Overridden in paravirt.c */
143void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ")));
144
Pekka Enberg36290d82009-04-09 11:52:20 +0300145static void __init smp_intr_init(void)
146{
Pekka Enbergb0096bb2009-04-09 11:52:23 +0300147#ifdef CONFIG_SMP
148#if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
Pekka Enberg36290d82009-04-09 11:52:20 +0300149 /*
150 * The reschedule interrupt is a CPU-to-CPU reschedule-helper
151 * IPI, driven by wakeup.
152 */
153 alloc_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
154
155 /* IPIs for invalidation */
156 alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+0, invalidate_interrupt0);
157 alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+1, invalidate_interrupt1);
158 alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+2, invalidate_interrupt2);
159 alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+3, invalidate_interrupt3);
160 alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+4, invalidate_interrupt4);
161 alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+5, invalidate_interrupt5);
162 alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+6, invalidate_interrupt6);
163 alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+7, invalidate_interrupt7);
164
165 /* IPI for generic function call */
166 alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
167
Pekka Enbergb0096bb2009-04-09 11:52:23 +0300168 /* IPI for generic single function call */
Pekka Enberg36290d82009-04-09 11:52:20 +0300169 alloc_intr_gate(CALL_FUNCTION_SINGLE_VECTOR,
Pekka Enbergb0096bb2009-04-09 11:52:23 +0300170 call_function_single_interrupt);
Pekka Enberg36290d82009-04-09 11:52:20 +0300171
172 /* Low priority IPI to cleanup after moving an irq */
173 set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt);
174 set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors);
175#endif
Pekka Enbergb0096bb2009-04-09 11:52:23 +0300176#endif /* CONFIG_SMP */
Pekka Enberg36290d82009-04-09 11:52:20 +0300177}
178
Pekka Enberg22813c42009-04-09 11:52:21 +0300179static void __init apic_intr_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
Pekka Enberg36290d82009-04-09 11:52:20 +0300181 smp_intr_init();
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +0400182
Pekka Enbergab19c252009-04-09 11:52:27 +0300183#ifdef CONFIG_X86_64
184 alloc_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
185 alloc_intr_gate(THRESHOLD_APIC_VECTOR, threshold_interrupt);
186#endif
187
188#if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +0400189 /* self generated IPI for local APIC timer */
190 alloc_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
191
Dimitri Sivanichacaabe72009-03-04 12:56:05 -0600192 /* generic IPI for platform specific use */
193 alloc_intr_gate(GENERIC_INTERRUPT_VECTOR, generic_interrupt);
194
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +0400195 /* IPI vectors for APIC spurious and error interrupts */
196 alloc_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
197 alloc_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
198#endif
199
Pekka Enbergab19c252009-04-09 11:52:27 +0300200#ifdef CONFIG_X86_32
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +0400201#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_MCE_P4THERMAL)
202 /* thermal monitor LVT interrupt */
203 alloc_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
204#endif
Pekka Enbergab19c252009-04-09 11:52:27 +0300205#endif
Pekka Enberg22813c42009-04-09 11:52:21 +0300206}
207
Pekka Enberg320fd992009-04-09 11:52:25 +0300208/**
209 * x86_quirk_pre_intr_init - initialisation prior to setting up interrupt vectors
210 *
211 * Description:
212 * Perform any necessary interrupt initialisation prior to setting up
213 * the "ordinary" interrupt call gates. For legacy reasons, the ISA
214 * interrupts should be initialised here if the machine emulates a PC
215 * in any way.
216 **/
217static void __init x86_quirk_pre_intr_init(void)
218{
Pekka Enbergabdb5a52009-04-09 11:52:30 +0300219#ifdef CONFIG_X86_32
Pekka Enberg320fd992009-04-09 11:52:25 +0300220 if (x86_quirks->arch_pre_intr_init) {
221 if (x86_quirks->arch_pre_intr_init())
222 return;
223 }
Pekka Enbergabdb5a52009-04-09 11:52:30 +0300224#endif
Pekka Enberg320fd992009-04-09 11:52:25 +0300225 init_ISA_irqs();
226}
Pekka Enberg320fd992009-04-09 11:52:25 +0300227
Pekka Enberg22813c42009-04-09 11:52:21 +0300228void __init native_init_IRQ(void)
229{
230 int i;
231
232 /* Execute any quirks before the call gates are initialised: */
233 x86_quirk_pre_intr_init();
234
235 /*
236 * Cover the whole vector space, no vector can escape
237 * us. (some of these will be overridden and become
238 * 'special' SMP interrupts)
239 */
Pekka Enbergd3496c82009-04-09 11:52:22 +0300240 for (i = FIRST_EXTERNAL_VECTOR; i < NR_VECTORS; i++) {
Pekka Enberg320fd992009-04-09 11:52:25 +0300241 /* IA32_SYSCALL_VECTOR was reserved in trap_init. */
242 if (i != IA32_SYSCALL_VECTOR)
243 set_intr_gate(i, interrupt[i-FIRST_EXTERNAL_VECTOR]);
Pekka Enberg22813c42009-04-09 11:52:21 +0300244 }
245
246 apic_intr_init();
Cyrill Gorcunov2ae111c2008-08-11 18:34:08 +0400247
248 if (!acpi_ioapic)
249 setup_irq(2, &irq2);
250
Pekka Enberg320fd992009-04-09 11:52:25 +0300251#ifdef CONFIG_X86_32
Ingo Molnar8e6dafd2009-02-23 00:34:39 +0100252 /*
253 * Call quirks after call gates are initialised (usually add in
254 * the architecture specific gates):
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 */
Ingo Molnar8e6dafd2009-02-23 00:34:39 +0100256 x86_quirk_intr_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 * External FPU? Set up irq13 if so, for
260 * original braindamaged IBM FERR coupling.
261 */
262 if (boot_cpu_data.hard_math && !cpu_has_fpu)
263 setup_irq(FPU_IRQ, &fpu_irq);
264
265 irq_ctx_init(smp_processor_id());
Pekka Enberg320fd992009-04-09 11:52:25 +0300266#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}