]>
Commit | Line | Data |
---|---|---|
6b39ba77 TG |
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> | |
4722d194 | 7 | #include <linux/of.h> |
6b39ba77 | 8 | #include <linux/seq_file.h> |
6a02e710 | 9 | #include <linux/smp.h> |
7c1d7cdc | 10 | #include <linux/ftrace.h> |
ca444564 | 11 | #include <linux/delay.h> |
69c60c88 | 12 | #include <linux/export.h> |
6b39ba77 | 13 | |
7b6aa335 | 14 | #include <asm/apic.h> |
6b39ba77 | 15 | #include <asm/io_apic.h> |
c3d80000 | 16 | #include <asm/irq.h> |
7c1d7cdc | 17 | #include <asm/idle.h> |
01ca79f1 | 18 | #include <asm/mce.h> |
2c1b284e | 19 | #include <asm/hw_irq.h> |
cf910e83 | 20 | #include <asm/trace/irq_vectors.h> |
6b39ba77 TG |
21 | |
22 | atomic_t irq_err_count; | |
23 | ||
acaabe79 | 24 | /* Function pointer for generic interrupt vector handling */ |
4a4de9c7 | 25 | void (*x86_platform_ipi_callback)(void) = NULL; |
acaabe79 | 26 | |
249f6d9e TG |
27 | /* |
28 | * 'what should we do if we get a hw irq event on an illegal vector'. | |
29 | * each architecture has to answer this themselves. | |
30 | */ | |
31 | void ack_bad_irq(unsigned int irq) | |
32 | { | |
edea7148 CG |
33 | if (printk_ratelimit()) |
34 | pr_err("unexpected IRQ trap at vector %02x\n", irq); | |
249f6d9e | 35 | |
249f6d9e TG |
36 | /* |
37 | * Currently unexpected vectors happen only on SMP and APIC. | |
38 | * We _must_ ack these because every local APIC has only N | |
39 | * irq slots per priority level, and a 'hanging, unacked' IRQ | |
40 | * holds up an irq slot - in excessive cases (when multiple | |
41 | * unexpected vectors occur) that might lock up the APIC | |
42 | * completely. | |
43 | * But only ack when the APIC is enabled -AK | |
44 | */ | |
08306ce6 | 45 | ack_APIC_irq(); |
249f6d9e TG |
46 | } |
47 | ||
1b437c8c | 48 | #define irq_stats(x) (&per_cpu(irq_stat, x)) |
6b39ba77 | 49 | /* |
517e4981 | 50 | * /proc/interrupts printing for arch specific interrupts |
6b39ba77 | 51 | */ |
517e4981 | 52 | int arch_show_interrupts(struct seq_file *p, int prec) |
6b39ba77 TG |
53 | { |
54 | int j; | |
55 | ||
7a81d9a7 | 56 | seq_printf(p, "%*s: ", prec, "NMI"); |
6b39ba77 TG |
57 | for_each_online_cpu(j) |
58 | seq_printf(p, "%10u ", irq_stats(j)->__nmi_count); | |
59 | seq_printf(p, " Non-maskable interrupts\n"); | |
60 | #ifdef CONFIG_X86_LOCAL_APIC | |
7a81d9a7 | 61 | seq_printf(p, "%*s: ", prec, "LOC"); |
6b39ba77 TG |
62 | for_each_online_cpu(j) |
63 | seq_printf(p, "%10u ", irq_stats(j)->apic_timer_irqs); | |
64 | seq_printf(p, " Local timer interrupts\n"); | |
474e56b8 JSR |
65 | |
66 | seq_printf(p, "%*s: ", prec, "SPU"); | |
67 | for_each_online_cpu(j) | |
68 | seq_printf(p, "%10u ", irq_stats(j)->irq_spurious_count); | |
69 | seq_printf(p, " Spurious interrupts\n"); | |
89ccf465 | 70 | seq_printf(p, "%*s: ", prec, "PMI"); |
241771ef IM |
71 | for_each_online_cpu(j) |
72 | seq_printf(p, "%10u ", irq_stats(j)->apic_perf_irqs); | |
89ccf465 | 73 | seq_printf(p, " Performance monitoring interrupts\n"); |
e360adbe | 74 | seq_printf(p, "%*s: ", prec, "IWI"); |
b6276f35 | 75 | for_each_online_cpu(j) |
e360adbe PZ |
76 | seq_printf(p, "%10u ", irq_stats(j)->apic_irq_work_irqs); |
77 | seq_printf(p, " IRQ work interrupts\n"); | |
346b46be FLVC |
78 | seq_printf(p, "%*s: ", prec, "RTR"); |
79 | for_each_online_cpu(j) | |
b49d7d87 | 80 | seq_printf(p, "%10u ", irq_stats(j)->icr_read_retry_count); |
346b46be | 81 | seq_printf(p, " APIC ICR read retries\n"); |
6b39ba77 | 82 | #endif |
4a4de9c7 | 83 | if (x86_platform_ipi_callback) { |
59d13812 | 84 | seq_printf(p, "%*s: ", prec, "PLT"); |
acaabe79 | 85 | for_each_online_cpu(j) |
4a4de9c7 | 86 | seq_printf(p, "%10u ", irq_stats(j)->x86_platform_ipis); |
acaabe79 DS |
87 | seq_printf(p, " Platform interrupts\n"); |
88 | } | |
6b39ba77 | 89 | #ifdef CONFIG_SMP |
7a81d9a7 | 90 | seq_printf(p, "%*s: ", prec, "RES"); |
6b39ba77 TG |
91 | for_each_online_cpu(j) |
92 | seq_printf(p, "%10u ", irq_stats(j)->irq_resched_count); | |
93 | seq_printf(p, " Rescheduling interrupts\n"); | |
7a81d9a7 | 94 | seq_printf(p, "%*s: ", prec, "CAL"); |
6b39ba77 | 95 | for_each_online_cpu(j) |
fd0f5869 TS |
96 | seq_printf(p, "%10u ", irq_stats(j)->irq_call_count - |
97 | irq_stats(j)->irq_tlb_count); | |
6b39ba77 | 98 | seq_printf(p, " Function call interrupts\n"); |
7a81d9a7 | 99 | seq_printf(p, "%*s: ", prec, "TLB"); |
6b39ba77 TG |
100 | for_each_online_cpu(j) |
101 | seq_printf(p, "%10u ", irq_stats(j)->irq_tlb_count); | |
102 | seq_printf(p, " TLB shootdowns\n"); | |
103 | #endif | |
0444c9bd | 104 | #ifdef CONFIG_X86_THERMAL_VECTOR |
7a81d9a7 | 105 | seq_printf(p, "%*s: ", prec, "TRM"); |
6b39ba77 TG |
106 | for_each_online_cpu(j) |
107 | seq_printf(p, "%10u ", irq_stats(j)->irq_thermal_count); | |
108 | seq_printf(p, " Thermal event interrupts\n"); | |
0444c9bd JB |
109 | #endif |
110 | #ifdef CONFIG_X86_MCE_THRESHOLD | |
7a81d9a7 | 111 | seq_printf(p, "%*s: ", prec, "THR"); |
6b39ba77 TG |
112 | for_each_online_cpu(j) |
113 | seq_printf(p, "%10u ", irq_stats(j)->irq_threshold_count); | |
114 | seq_printf(p, " Threshold APIC interrupts\n"); | |
01ca79f1 | 115 | #endif |
c1ebf835 | 116 | #ifdef CONFIG_X86_MCE |
01ca79f1 AK |
117 | seq_printf(p, "%*s: ", prec, "MCE"); |
118 | for_each_online_cpu(j) | |
119 | seq_printf(p, "%10u ", per_cpu(mce_exception_count, j)); | |
120 | seq_printf(p, " Machine check exceptions\n"); | |
ca84f696 AK |
121 | seq_printf(p, "%*s: ", prec, "MCP"); |
122 | for_each_online_cpu(j) | |
123 | seq_printf(p, "%10u ", per_cpu(mce_poll_count, j)); | |
124 | seq_printf(p, " Machine check polls\n"); | |
6b39ba77 | 125 | #endif |
7a81d9a7 | 126 | seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count)); |
6b39ba77 | 127 | #if defined(CONFIG_X86_IO_APIC) |
7a81d9a7 | 128 | seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count)); |
6b39ba77 TG |
129 | #endif |
130 | return 0; | |
131 | } | |
132 | ||
6b39ba77 TG |
133 | /* |
134 | * /proc/stat helpers | |
135 | */ | |
136 | u64 arch_irq_stat_cpu(unsigned int cpu) | |
137 | { | |
138 | u64 sum = irq_stats(cpu)->__nmi_count; | |
139 | ||
140 | #ifdef CONFIG_X86_LOCAL_APIC | |
141 | sum += irq_stats(cpu)->apic_timer_irqs; | |
474e56b8 | 142 | sum += irq_stats(cpu)->irq_spurious_count; |
241771ef | 143 | sum += irq_stats(cpu)->apic_perf_irqs; |
e360adbe | 144 | sum += irq_stats(cpu)->apic_irq_work_irqs; |
b49d7d87 | 145 | sum += irq_stats(cpu)->icr_read_retry_count; |
6b39ba77 | 146 | #endif |
4a4de9c7 DS |
147 | if (x86_platform_ipi_callback) |
148 | sum += irq_stats(cpu)->x86_platform_ipis; | |
6b39ba77 TG |
149 | #ifdef CONFIG_SMP |
150 | sum += irq_stats(cpu)->irq_resched_count; | |
151 | sum += irq_stats(cpu)->irq_call_count; | |
6b39ba77 | 152 | #endif |
0444c9bd | 153 | #ifdef CONFIG_X86_THERMAL_VECTOR |
6b39ba77 | 154 | sum += irq_stats(cpu)->irq_thermal_count; |
0444c9bd JB |
155 | #endif |
156 | #ifdef CONFIG_X86_MCE_THRESHOLD | |
6b39ba77 | 157 | sum += irq_stats(cpu)->irq_threshold_count; |
8051dbd2 | 158 | #endif |
c1ebf835 | 159 | #ifdef CONFIG_X86_MCE |
8051dbd2 HS |
160 | sum += per_cpu(mce_exception_count, cpu); |
161 | sum += per_cpu(mce_poll_count, cpu); | |
6b39ba77 TG |
162 | #endif |
163 | return sum; | |
164 | } | |
165 | ||
166 | u64 arch_irq_stat(void) | |
167 | { | |
168 | u64 sum = atomic_read(&irq_err_count); | |
6b39ba77 TG |
169 | return sum; |
170 | } | |
c3d80000 | 171 | |
7c1d7cdc JF |
172 | |
173 | /* | |
174 | * do_IRQ handles all normal device IRQ's (the special | |
175 | * SMP cross-CPU interrupts have their own specific | |
176 | * handlers). | |
177 | */ | |
178 | unsigned int __irq_entry do_IRQ(struct pt_regs *regs) | |
179 | { | |
180 | struct pt_regs *old_regs = set_irq_regs(regs); | |
181 | ||
182 | /* high bit used in ret_from_ code */ | |
183 | unsigned vector = ~regs->orig_ax; | |
184 | unsigned irq; | |
185 | ||
7c1d7cdc | 186 | irq_enter(); |
98ad1cc1 | 187 | exit_idle(); |
7c1d7cdc | 188 | |
0a3aee0d | 189 | irq = __this_cpu_read(vector_irq[vector]); |
7c1d7cdc JF |
190 | |
191 | if (!handle_irq(irq, regs)) { | |
08306ce6 | 192 | ack_APIC_irq(); |
7c1d7cdc JF |
193 | |
194 | if (printk_ratelimit()) | |
edea7148 CG |
195 | pr_emerg("%s: %d.%d No irq handler for vector (irq %d)\n", |
196 | __func__, smp_processor_id(), vector, irq); | |
7c1d7cdc JF |
197 | } |
198 | ||
199 | irq_exit(); | |
200 | ||
201 | set_irq_regs(old_regs); | |
202 | return 1; | |
203 | } | |
204 | ||
acaabe79 | 205 | /* |
4a4de9c7 | 206 | * Handler for X86_PLATFORM_IPI_VECTOR. |
acaabe79 | 207 | */ |
eddc0e92 | 208 | void __smp_x86_platform_ipi(void) |
acaabe79 | 209 | { |
4a4de9c7 | 210 | inc_irq_stat(x86_platform_ipis); |
acaabe79 | 211 | |
4a4de9c7 DS |
212 | if (x86_platform_ipi_callback) |
213 | x86_platform_ipi_callback(); | |
eddc0e92 | 214 | } |
acaabe79 | 215 | |
eddc0e92 SA |
216 | void smp_x86_platform_ipi(struct pt_regs *regs) |
217 | { | |
218 | struct pt_regs *old_regs = set_irq_regs(regs); | |
acaabe79 | 219 | |
eddc0e92 SA |
220 | entering_ack_irq(); |
221 | __smp_x86_platform_ipi(); | |
222 | exiting_irq(); | |
acaabe79 DS |
223 | set_irq_regs(old_regs); |
224 | } | |
225 | ||
d78f2664 YZ |
226 | #ifdef CONFIG_HAVE_KVM |
227 | /* | |
228 | * Handler for POSTED_INTERRUPT_VECTOR. | |
229 | */ | |
230 | void smp_kvm_posted_intr_ipi(struct pt_regs *regs) | |
231 | { | |
232 | struct pt_regs *old_regs = set_irq_regs(regs); | |
233 | ||
234 | ack_APIC_irq(); | |
235 | ||
236 | irq_enter(); | |
237 | ||
238 | exit_idle(); | |
239 | ||
240 | inc_irq_stat(kvm_posted_intr_ipis); | |
241 | ||
242 | irq_exit(); | |
243 | ||
244 | set_irq_regs(old_regs); | |
245 | } | |
246 | #endif | |
247 | ||
cf910e83 SA |
248 | void smp_trace_x86_platform_ipi(struct pt_regs *regs) |
249 | { | |
250 | struct pt_regs *old_regs = set_irq_regs(regs); | |
251 | ||
252 | entering_ack_irq(); | |
253 | trace_x86_platform_ipi_entry(X86_PLATFORM_IPI_VECTOR); | |
254 | __smp_x86_platform_ipi(); | |
255 | trace_x86_platform_ipi_exit(X86_PLATFORM_IPI_VECTOR); | |
256 | exiting_irq(); | |
257 | set_irq_regs(old_regs); | |
258 | } | |
259 | ||
c3d80000 | 260 | EXPORT_SYMBOL_GPL(vector_used_by_percpu_irq); |
7a7732bc SS |
261 | |
262 | #ifdef CONFIG_HOTPLUG_CPU | |
263 | /* A cpu has been removed from cpu_online_mask. Reset irq affinities. */ | |
264 | void fixup_irqs(void) | |
265 | { | |
5231a686 | 266 | unsigned int irq, vector; |
7a7732bc SS |
267 | static int warned; |
268 | struct irq_desc *desc; | |
a3c08e5d | 269 | struct irq_data *data; |
51c43ac6 | 270 | struct irq_chip *chip; |
7a7732bc SS |
271 | |
272 | for_each_irq_desc(irq, desc) { | |
273 | int break_affinity = 0; | |
274 | int set_affinity = 1; | |
275 | const struct cpumask *affinity; | |
276 | ||
277 | if (!desc) | |
278 | continue; | |
279 | if (irq == 2) | |
280 | continue; | |
281 | ||
282 | /* interrupt's are disabled at this point */ | |
239007b8 | 283 | raw_spin_lock(&desc->lock); |
7a7732bc | 284 | |
51c43ac6 | 285 | data = irq_desc_get_irq_data(desc); |
a3c08e5d | 286 | affinity = data->affinity; |
b87ba87c | 287 | if (!irq_has_action(irq) || irqd_is_per_cpu(data) || |
58bff947 | 288 | cpumask_subset(affinity, cpu_online_mask)) { |
239007b8 | 289 | raw_spin_unlock(&desc->lock); |
7a7732bc SS |
290 | continue; |
291 | } | |
292 | ||
a5e74b84 SS |
293 | /* |
294 | * Complete the irq move. This cpu is going down and for | |
295 | * non intr-remapping case, we can't wait till this interrupt | |
296 | * arrives at this cpu before completing the irq move. | |
297 | */ | |
298 | irq_force_complete_move(irq); | |
299 | ||
7a7732bc SS |
300 | if (cpumask_any_and(affinity, cpu_online_mask) >= nr_cpu_ids) { |
301 | break_affinity = 1; | |
2530cd4f | 302 | affinity = cpu_online_mask; |
7a7732bc SS |
303 | } |
304 | ||
51c43ac6 TG |
305 | chip = irq_data_get_irq_chip(data); |
306 | if (!irqd_can_move_in_process_context(data) && chip->irq_mask) | |
307 | chip->irq_mask(data); | |
7a7732bc | 308 | |
51c43ac6 TG |
309 | if (chip->irq_set_affinity) |
310 | chip->irq_set_affinity(data, affinity, true); | |
7a7732bc SS |
311 | else if (!(warned++)) |
312 | set_affinity = 0; | |
313 | ||
99dd5497 LC |
314 | /* |
315 | * We unmask if the irq was not marked masked by the | |
316 | * core code. That respects the lazy irq disable | |
317 | * behaviour. | |
318 | */ | |
983bbf1a | 319 | if (!irqd_can_move_in_process_context(data) && |
99dd5497 | 320 | !irqd_irq_masked(data) && chip->irq_unmask) |
51c43ac6 | 321 | chip->irq_unmask(data); |
7a7732bc | 322 | |
239007b8 | 323 | raw_spin_unlock(&desc->lock); |
7a7732bc SS |
324 | |
325 | if (break_affinity && set_affinity) | |
c767a54b | 326 | pr_notice("Broke affinity for irq %i\n", irq); |
7a7732bc | 327 | else if (!set_affinity) |
c767a54b | 328 | pr_notice("Cannot set affinity for irq %i\n", irq); |
7a7732bc SS |
329 | } |
330 | ||
5231a686 SS |
331 | /* |
332 | * We can remove mdelay() and then send spuriuous interrupts to | |
333 | * new cpu targets for all the irqs that were handled previously by | |
334 | * this cpu. While it works, I have seen spurious interrupt messages | |
335 | * (nothing wrong but still...). | |
336 | * | |
337 | * So for now, retain mdelay(1) and check the IRR and then send those | |
338 | * interrupts to new targets as this cpu is already offlined... | |
339 | */ | |
7a7732bc | 340 | mdelay(1); |
5231a686 SS |
341 | |
342 | for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) { | |
343 | unsigned int irr; | |
344 | ||
0a3aee0d | 345 | if (__this_cpu_read(vector_irq[vector]) < 0) |
5231a686 SS |
346 | continue; |
347 | ||
348 | irr = apic_read(APIC_IRR + (vector / 32 * 0x10)); | |
349 | if (irr & (1 << (vector % 32))) { | |
0a3aee0d | 350 | irq = __this_cpu_read(vector_irq[vector]); |
5231a686 | 351 | |
5117348d | 352 | desc = irq_to_desc(irq); |
51c43ac6 TG |
353 | data = irq_desc_get_irq_data(desc); |
354 | chip = irq_data_get_irq_chip(data); | |
239007b8 | 355 | raw_spin_lock(&desc->lock); |
51c43ac6 TG |
356 | if (chip->irq_retrigger) |
357 | chip->irq_retrigger(data); | |
239007b8 | 358 | raw_spin_unlock(&desc->lock); |
5231a686 | 359 | } |
1d44b30f | 360 | __this_cpu_write(vector_irq[vector], -1); |
5231a686 | 361 | } |
7a7732bc SS |
362 | } |
363 | #endif |