Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6] / arch / x86 / kernel / irq.c
1 /*
2  * Common interrupt code for 32 and 64 bit
3  */
4 #include <linux/cpu.h>
5 #include <linux/interrupt.h>
6 #include <linux/kernel_stat.h>
7 #include <linux/seq_file.h>
8 #include <linux/smp.h>
9 #include <linux/ftrace.h>
10
11 #include <asm/apic.h>
12 #include <asm/io_apic.h>
13 #include <asm/irq.h>
14 #include <asm/idle.h>
15 #include <asm/hw_irq.h>
16
17 atomic_t irq_err_count;
18
19 /* Function pointer for generic interrupt vector handling */
20 void (*generic_interrupt_extension)(void) = NULL;
21
22 /*
23  * 'what should we do if we get a hw irq event on an illegal vector'.
24  * each architecture has to answer this themselves.
25  */
26 void ack_bad_irq(unsigned int irq)
27 {
28         if (printk_ratelimit())
29                 pr_err("unexpected IRQ trap at vector %02x\n", irq);
30
31         /*
32          * Currently unexpected vectors happen only on SMP and APIC.
33          * We _must_ ack these because every local APIC has only N
34          * irq slots per priority level, and a 'hanging, unacked' IRQ
35          * holds up an irq slot - in excessive cases (when multiple
36          * unexpected vectors occur) that might lock up the APIC
37          * completely.
38          * But only ack when the APIC is enabled -AK
39          */
40         ack_APIC_irq();
41 }
42
43 #define irq_stats(x)            (&per_cpu(irq_stat, x))
44 /*
45  * /proc/interrupts printing:
46  */
47 static int show_other_interrupts(struct seq_file *p, int prec)
48 {
49         int j;
50
51         seq_printf(p, "%*s: ", prec, "NMI");
52         for_each_online_cpu(j)
53                 seq_printf(p, "%10u ", irq_stats(j)->__nmi_count);
54         seq_printf(p, "  Non-maskable interrupts\n");
55 #ifdef CONFIG_X86_LOCAL_APIC
56         seq_printf(p, "%*s: ", prec, "LOC");
57         for_each_online_cpu(j)
58                 seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs);
59         seq_printf(p, "  Local timer interrupts\n");
60
61         seq_printf(p, "%*s: ", prec, "SPU");
62         for_each_online_cpu(j)
63                 seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count);
64         seq_printf(p, "  Spurious interrupts\n");
65 #endif
66         if (generic_interrupt_extension) {
67                 seq_printf(p, "%*s: ", prec, "PLT");
68                 for_each_online_cpu(j)
69                         seq_printf(p, "%10u ", irq_stats(j)->generic_irqs);
70                 seq_printf(p, "  Platform interrupts\n");
71         }
72 #ifdef CONFIG_SMP
73         seq_printf(p, "%*s: ", prec, "RES");
74         for_each_online_cpu(j)
75                 seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count);
76         seq_printf(p, "  Rescheduling interrupts\n");
77         seq_printf(p, "%*s: ", prec, "CAL");
78         for_each_online_cpu(j)
79                 seq_printf(p, "%10u ", irq_stats(j)->irq_call_count);
80         seq_printf(p, "  Function call interrupts\n");
81         seq_printf(p, "%*s: ", prec, "TLB");
82         for_each_online_cpu(j)
83                 seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count);
84         seq_printf(p, "  TLB shootdowns\n");
85 #endif
86 #ifdef CONFIG_X86_MCE
87         seq_printf(p, "%*s: ", prec, "TRM");
88         for_each_online_cpu(j)
89                 seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count);
90         seq_printf(p, "  Thermal event interrupts\n");
91 # ifdef CONFIG_X86_64
92         seq_printf(p, "%*s: ", prec, "THR");
93         for_each_online_cpu(j)
94                 seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count);
95         seq_printf(p, "  Threshold APIC interrupts\n");
96 # endif
97 #endif
98         seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
99 #if defined(CONFIG_X86_IO_APIC)
100         seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
101 #endif
102         return 0;
103 }
104
105 int show_interrupts(struct seq_file *p, void *v)
106 {
107         unsigned long flags, any_count = 0;
108         int i = *(loff_t *) v, j, prec;
109         struct irqaction *action;
110         struct irq_desc *desc;
111
112         if (i > nr_irqs)
113                 return 0;
114
115         for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
116                 j *= 10;
117
118         if (i == nr_irqs)
119                 return show_other_interrupts(p, prec);
120
121         /* print header */
122         if (i == 0) {
123                 seq_printf(p, "%*s", prec + 8, "");
124                 for_each_online_cpu(j)
125                         seq_printf(p, "CPU%-8d", j);
126                 seq_putc(p, '\n');
127         }
128
129         desc = irq_to_desc(i);
130         if (!desc)
131                 return 0;
132
133         spin_lock_irqsave(&desc->lock, flags);
134         for_each_online_cpu(j)
135                 any_count |= kstat_irqs_cpu(i, j);
136         action = desc->action;
137         if (!action && !any_count)
138                 goto out;
139
140         seq_printf(p, "%*d: ", prec, i);
141         for_each_online_cpu(j)
142                 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
143         seq_printf(p, " %8s", desc->chip->name);
144         seq_printf(p, "-%-8s", desc->name);
145
146         if (action) {
147                 seq_printf(p, "  %s", action->name);
148                 while ((action = action->next) != NULL)
149                         seq_printf(p, ", %s", action->name);
150         }
151
152         seq_putc(p, '\n');
153 out:
154         spin_unlock_irqrestore(&desc->lock, flags);
155         return 0;
156 }
157
158 /*
159  * /proc/stat helpers
160  */
161 u64 arch_irq_stat_cpu(unsigned int cpu)
162 {
163         u64 sum = irq_stats(cpu)->__nmi_count;
164
165 #ifdef CONFIG_X86_LOCAL_APIC
166         sum += irq_stats(cpu)->apic_timer_irqs;
167         sum += irq_stats(cpu)->irq_spurious_count;
168 #endif
169         if (generic_interrupt_extension)
170                 sum += irq_stats(cpu)->generic_irqs;
171 #ifdef CONFIG_SMP
172         sum += irq_stats(cpu)->irq_resched_count;
173         sum += irq_stats(cpu)->irq_call_count;
174         sum += irq_stats(cpu)->irq_tlb_count;
175 #endif
176 #ifdef CONFIG_X86_MCE
177         sum += irq_stats(cpu)->irq_thermal_count;
178 # ifdef CONFIG_X86_64
179         sum += irq_stats(cpu)->irq_threshold_count;
180 # endif
181 #endif
182         return sum;
183 }
184
185 u64 arch_irq_stat(void)
186 {
187         u64 sum = atomic_read(&irq_err_count);
188
189 #ifdef CONFIG_X86_IO_APIC
190         sum += atomic_read(&irq_mis_count);
191 #endif
192         return sum;
193 }
194
195
196 /*
197  * do_IRQ handles all normal device IRQ's (the special
198  * SMP cross-CPU interrupts have their own specific
199  * handlers).
200  */
201 unsigned int __irq_entry do_IRQ(struct pt_regs *regs)
202 {
203         struct pt_regs *old_regs = set_irq_regs(regs);
204
205         /* high bit used in ret_from_ code  */
206         unsigned vector = ~regs->orig_ax;
207         unsigned irq;
208
209         exit_idle();
210         irq_enter();
211
212         irq = __get_cpu_var(vector_irq)[vector];
213
214         if (!handle_irq(irq, regs)) {
215                 ack_APIC_irq();
216
217                 if (printk_ratelimit())
218                         pr_emerg("%s: %d.%d No irq handler for vector (irq %d)\n",
219                                 __func__, smp_processor_id(), vector, irq);
220         }
221
222         irq_exit();
223
224         set_irq_regs(old_regs);
225         return 1;
226 }
227
228 /*
229  * Handler for GENERIC_INTERRUPT_VECTOR.
230  */
231 void smp_generic_interrupt(struct pt_regs *regs)
232 {
233         struct pt_regs *old_regs = set_irq_regs(regs);
234
235         ack_APIC_irq();
236
237         exit_idle();
238
239         irq_enter();
240
241         inc_irq_stat(generic_irqs);
242
243         if (generic_interrupt_extension)
244                 generic_interrupt_extension();
245
246         irq_exit();
247
248         set_irq_regs(old_regs);
249 }
250
251 EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq);