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