Merge commit 'v2.6.29-rc4' into perfcounters/core
[safe/jmp/linux-2.6] / arch / x86 / kernel / irqinit_32.c
1 #include <linux/errno.h>
2 #include <linux/signal.h>
3 #include <linux/sched.h>
4 #include <linux/ioport.h>
5 #include <linux/interrupt.h>
6 #include <linux/slab.h>
7 #include <linux/random.h>
8 #include <linux/init.h>
9 #include <linux/kernel_stat.h>
10 #include <linux/sysdev.h>
11 #include <linux/bitops.h>
12 #include <linux/io.h>
13 #include <linux/delay.h>
14
15 #include <asm/atomic.h>
16 #include <asm/system.h>
17 #include <asm/timer.h>
18 #include <asm/pgtable.h>
19 #include <asm/desc.h>
20 #include <asm/apic.h>
21 #include <asm/arch_hooks.h>
22 #include <asm/i8259.h>
23 #include <asm/traps.h>
24
25
26 /*
27  * Note that on a 486, we don't want to do a SIGFPE on an irq13
28  * as the irq is unreliable, and exception 16 works correctly
29  * (ie as explained in the intel literature). On a 386, you
30  * can't use exception 16 due to bad IBM design, so we have to
31  * rely on the less exact irq13.
32  *
33  * Careful.. Not only is IRQ13 unreliable, but it is also
34  * leads to races. IBM designers who came up with it should
35  * be shot.
36  */
37
38 static irqreturn_t math_error_irq(int cpl, void *dev_id)
39 {
40         outb(0, 0xF0);
41         if (ignore_fpu_irq || !boot_cpu_data.hard_math)
42                 return IRQ_NONE;
43         math_error((void __user *)get_irq_regs()->ip);
44         return IRQ_HANDLED;
45 }
46
47 /*
48  * New motherboards sometimes make IRQ 13 be a PCI interrupt,
49  * so allow interrupt sharing.
50  */
51 static struct irqaction fpu_irq = {
52         .handler = math_error_irq,
53         .mask = CPU_MASK_NONE,
54         .name = "fpu",
55 };
56
57 void __init init_ISA_irqs(void)
58 {
59         int i;
60
61 #ifdef CONFIG_X86_LOCAL_APIC
62         init_bsp_APIC();
63 #endif
64         init_8259A(0);
65
66         /*
67          * 16 old-style INTA-cycle interrupts:
68          */
69         for (i = 0; i < NR_IRQS_LEGACY; i++) {
70                 struct irq_desc *desc = irq_to_desc(i);
71
72                 desc->status = IRQ_DISABLED;
73                 desc->action = NULL;
74                 desc->depth = 1;
75
76                 set_irq_chip_and_handler_name(i, &i8259A_chip,
77                                               handle_level_irq, "XT");
78         }
79 }
80
81 DEFINE_PER_CPU(vector_irq_t, vector_irq) = {
82         [0 ... IRQ0_VECTOR - 1] = -1,
83         [IRQ0_VECTOR] = 0,
84         [IRQ1_VECTOR] = 1,
85         [IRQ2_VECTOR] = 2,
86         [IRQ3_VECTOR] = 3,
87         [IRQ4_VECTOR] = 4,
88         [IRQ5_VECTOR] = 5,
89         [IRQ6_VECTOR] = 6,
90         [IRQ7_VECTOR] = 7,
91         [IRQ8_VECTOR] = 8,
92         [IRQ9_VECTOR] = 9,
93         [IRQ10_VECTOR] = 10,
94         [IRQ11_VECTOR] = 11,
95         [IRQ12_VECTOR] = 12,
96         [IRQ13_VECTOR] = 13,
97         [IRQ14_VECTOR] = 14,
98         [IRQ15_VECTOR] = 15,
99         [IRQ15_VECTOR + 1 ... NR_VECTORS - 1] = -1
100 };
101
102 int vector_used_by_percpu_irq(unsigned int vector)
103 {
104         int cpu;
105
106         for_each_online_cpu(cpu) {
107                 if (per_cpu(vector_irq, cpu)[vector] != -1)
108                         return 1;
109         }
110
111         return 0;
112 }
113
114 static void __init smp_intr_init(void)
115 {
116 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_SMP)
117         /*
118          * The reschedule interrupt is a CPU-to-CPU reschedule-helper
119          * IPI, driven by wakeup.
120          */
121         alloc_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt);
122
123         /* IPIs for invalidation */
124         alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+0, invalidate_interrupt0);
125         alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+1, invalidate_interrupt1);
126         alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+2, invalidate_interrupt2);
127         alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+3, invalidate_interrupt3);
128         alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+4, invalidate_interrupt4);
129         alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+5, invalidate_interrupt5);
130         alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+6, invalidate_interrupt6);
131         alloc_intr_gate(INVALIDATE_TLB_VECTOR_START+7, invalidate_interrupt7);
132
133         /* IPI for generic function call */
134         alloc_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt);
135
136         /* IPI for single call function */
137         alloc_intr_gate(CALL_FUNCTION_SINGLE_VECTOR,
138                                  call_function_single_interrupt);
139
140         /* Low priority IPI to cleanup after moving an irq */
141         set_intr_gate(IRQ_MOVE_CLEANUP_VECTOR, irq_move_cleanup_interrupt);
142         set_bit(IRQ_MOVE_CLEANUP_VECTOR, used_vectors);
143 #endif
144 }
145
146 static void __init apic_intr_init(void)
147 {
148         smp_intr_init();
149
150 #ifdef CONFIG_X86_LOCAL_APIC
151         /* self generated IPI for local APIC timer */
152         alloc_intr_gate(LOCAL_TIMER_VECTOR, apic_timer_interrupt);
153
154         /* IPI vectors for APIC spurious and error interrupts */
155         alloc_intr_gate(SPURIOUS_APIC_VECTOR, spurious_interrupt);
156         alloc_intr_gate(ERROR_APIC_VECTOR, error_interrupt);
157 # ifdef CONFIG_PERF_COUNTERS
158         alloc_intr_gate(LOCAL_PERF_VECTOR, perf_counter_interrupt);
159 # endif
160
161 # ifdef CONFIG_X86_MCE_P4THERMAL
162         /* thermal monitor LVT interrupt */
163         alloc_intr_gate(THERMAL_APIC_VECTOR, thermal_interrupt);
164 # endif
165 #endif
166 }
167
168 /* Overridden in paravirt.c */
169 void init_IRQ(void) __attribute__((weak, alias("native_init_IRQ")));
170
171 void __init native_init_IRQ(void)
172 {
173         int i;
174
175         /* all the set up before the call gates are initialised */
176         pre_intr_init_hook();
177
178         apic_intr_init();
179
180         /*
181          * Cover the whole vector space, no vector can escape
182          * us. (some of these will be overridden and become
183          * 'special' SMP interrupts)
184          */
185         for (i = 0; i < (NR_VECTORS - FIRST_EXTERNAL_VECTOR); i++) {
186                 int vector = FIRST_EXTERNAL_VECTOR + i;
187                 /* SYSCALL_VECTOR was reserved in trap_init. */
188                 if (!test_bit(vector, used_vectors))
189                         set_intr_gate(vector, interrupt[i]);
190         }
191
192         /* setup after call gates are initialised (usually add in
193          * the architecture specific gates)
194          */
195         intr_init_hook();
196
197         /*
198          * External FPU? Set up irq13 if so, for
199          * original braindamaged IBM FERR coupling.
200          */
201         if (boot_cpu_data.hard_math && !cpu_has_fpu)
202                 setup_irq(FPU_IRQ, &fpu_irq);
203
204         irq_ctx_init(smp_processor_id());
205 }