irq: remove >= nr_irqs checking with config_have_sparse_irq
[deliverable/linux.git] / arch / x86 / kernel / irq_64.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
3 *
4 * This file contains the lowest level x86_64-specific interrupt
5 * entry and irq statistics code. All the remaining irq logic is
6 * done by the generic kernel/irq/ code and in the
7 * x86_64-specific irq controller code. (e.g. i8259.c and
8 * io_apic.c.)
9 */
10
11#include <linux/kernel_stat.h>
12#include <linux/interrupt.h>
13#include <linux/seq_file.h>
14#include <linux/module.h>
76e4f660 15#include <linux/delay.h>
1da177e4
LT
16#include <asm/uaccess.h>
17#include <asm/io_apic.h>
95833c83 18#include <asm/idle.h>
2fb12a9b 19#include <asm/smp.h>
1da177e4
LT
20
21atomic_t irq_err_count;
1da177e4 22
87ebecf1
TG
23/*
24 * 'what should we do if we get a hw irq event on an illegal vector'.
25 * each architecture has to answer this themselves.
26 */
27void ack_bad_irq(unsigned int irq)
28{
29 printk(KERN_WARNING "unexpected IRQ trap at vector %02x\n", irq);
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 don't ack when the APIC is disabled. -AK
38 */
39 if (!disable_apic)
40 ack_APIC_irq();
41}
42
4961f10e
ES
43#ifdef CONFIG_DEBUG_STACKOVERFLOW
44/*
45 * Probabilistic stack overflow check:
46 *
47 * Only check the stack in process context, because everything else
48 * runs on the big interrupt stacks. Checking reliably is too expensive,
49 * so we just check from interrupts.
50 */
51static inline void stack_overflow_check(struct pt_regs *regs)
52{
c9f4f06d 53 u64 curbase = (u64)task_stack_page(current);
4961f10e
ES
54 static unsigned long warned = -60*HZ;
55
65ea5b03
PA
56 if (regs->sp >= curbase && regs->sp <= curbase + THREAD_SIZE &&
57 regs->sp < curbase + sizeof(struct thread_info) + 128 &&
4961f10e 58 time_after(jiffies, warned + 60*HZ)) {
65ea5b03
PA
59 printk("do_IRQ: %s near stack overflow (cur:%Lx,sp:%lx)\n",
60 current->comm, curbase, regs->sp);
4961f10e
ES
61 show_stack(NULL,NULL);
62 warned = jiffies;
63 }
64}
65#endif
66
1da177e4
LT
67/*
68 * Generic, controller-independent functions:
69 */
70
71int show_interrupts(struct seq_file *p, void *v)
72{
73 int i = *(loff_t *) v, j;
74 struct irqaction * action;
75 unsigned long flags;
76
77 if (i == 0) {
78 seq_printf(p, " ");
394e3902 79 for_each_online_cpu(j)
bdbdaa79 80 seq_printf(p, "CPU%-8d",j);
1da177e4
LT
81 seq_putc(p, '\n');
82 }
83
0799e432 84 if (i < nr_irqs) {
072f5d82 85 unsigned any_count = 0;
08678b08 86 struct irq_desc *desc = irq_to_desc(i);
072f5d82 87
08678b08 88 spin_lock_irqsave(&desc->lock, flags);
072f5d82
JB
89#ifndef CONFIG_SMP
90 any_count = kstat_irqs(i);
91#else
92 for_each_online_cpu(j)
7f95ec9e 93 any_count |= kstat_irqs_cpu(i, j);
072f5d82 94#endif
08678b08 95 action = desc->action;
072f5d82 96 if (!action && !any_count)
1da177e4
LT
97 goto skip;
98 seq_printf(p, "%3d: ",i);
99#ifndef CONFIG_SMP
100 seq_printf(p, "%10u ", kstat_irqs(i));
101#else
394e3902 102 for_each_online_cpu(j)
7f95ec9e 103 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
1da177e4 104#endif
08678b08
YL
105 seq_printf(p, " %8s", desc->chip->name);
106 seq_printf(p, "-%-8s", desc->name);
1da177e4 107
072f5d82
JB
108 if (action) {
109 seq_printf(p, " %s", action->name);
110 while ((action = action->next) != NULL)
111 seq_printf(p, ", %s", action->name);
112 }
1da177e4
LT
113 seq_putc(p, '\n');
114skip:
08678b08 115 spin_unlock_irqrestore(&desc->lock, flags);
0799e432 116 } else if (i == nr_irqs) {
1da177e4 117 seq_printf(p, "NMI: ");
394e3902
AM
118 for_each_online_cpu(j)
119 seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
38e760a1 120 seq_printf(p, " Non-maskable interrupts\n");
1da177e4 121 seq_printf(p, "LOC: ");
394e3902
AM
122 for_each_online_cpu(j)
123 seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
38e760a1
JK
124 seq_printf(p, " Local timer interrupts\n");
125#ifdef CONFIG_SMP
126 seq_printf(p, "RES: ");
127 for_each_online_cpu(j)
128 seq_printf(p, "%10u ", cpu_pda(j)->irq_resched_count);
129 seq_printf(p, " Rescheduling interrupts\n");
130 seq_printf(p, "CAL: ");
131 for_each_online_cpu(j)
132 seq_printf(p, "%10u ", cpu_pda(j)->irq_call_count);
dc44e659 133 seq_printf(p, " Function call interrupts\n");
38e760a1
JK
134 seq_printf(p, "TLB: ");
135 for_each_online_cpu(j)
136 seq_printf(p, "%10u ", cpu_pda(j)->irq_tlb_count);
137 seq_printf(p, " TLB shootdowns\n");
138#endif
a2eddfa9 139#ifdef CONFIG_X86_MCE
38e760a1
JK
140 seq_printf(p, "TRM: ");
141 for_each_online_cpu(j)
142 seq_printf(p, "%10u ", cpu_pda(j)->irq_thermal_count);
143 seq_printf(p, " Thermal event interrupts\n");
144 seq_printf(p, "THR: ");
145 for_each_online_cpu(j)
146 seq_printf(p, "%10u ", cpu_pda(j)->irq_threshold_count);
147 seq_printf(p, " Threshold APIC interrupts\n");
a2eddfa9 148#endif
38e760a1
JK
149 seq_printf(p, "SPU: ");
150 for_each_online_cpu(j)
151 seq_printf(p, "%10u ", cpu_pda(j)->irq_spurious_count);
152 seq_printf(p, " Spurious interrupts\n");
1da177e4 153 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
1da177e4
LT
154 }
155 return 0;
156}
157
a2eddfa9
JB
158/*
159 * /proc/stat helpers
160 */
161u64 arch_irq_stat_cpu(unsigned int cpu)
162{
163 u64 sum = cpu_pda(cpu)->__nmi_count;
164
165 sum += cpu_pda(cpu)->apic_timer_irqs;
166#ifdef CONFIG_SMP
167 sum += cpu_pda(cpu)->irq_resched_count;
168 sum += cpu_pda(cpu)->irq_call_count;
169 sum += cpu_pda(cpu)->irq_tlb_count;
170#endif
171#ifdef CONFIG_X86_MCE
172 sum += cpu_pda(cpu)->irq_thermal_count;
173 sum += cpu_pda(cpu)->irq_threshold_count;
174#endif
175 sum += cpu_pda(cpu)->irq_spurious_count;
176 return sum;
177}
178
179u64 arch_irq_stat(void)
180{
181 return atomic_read(&irq_err_count);
182}
183
1da177e4
LT
184/*
185 * do_IRQ handles all normal device IRQ's (the special
186 * SMP cross-CPU interrupts have their own specific
187 * handlers).
188 */
189asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
7d12e780
DH
190{
191 struct pt_regs *old_regs = set_irq_regs(regs);
192
19eadf98 193 /* high bit used in ret_from_ code */
65ea5b03 194 unsigned vector = ~regs->orig_ax;
e500f574
EB
195 unsigned irq;
196
197 exit_idle();
198 irq_enter();
550f2299 199 irq = __get_cpu_var(vector_irq)[vector];
1da177e4 200
4961f10e
ES
201#ifdef CONFIG_DEBUG_STACKOVERFLOW
202 stack_overflow_check(regs);
203#endif
d3696cf7 204
7d94f7ca 205 if (likely(__irq_to_desc(irq)))
d3696cf7 206 generic_handle_irq(irq);
2fb12a9b
EB
207 else {
208 if (!disable_apic)
209 ack_APIC_irq();
210
211 if (printk_ratelimit())
212 printk(KERN_EMERG "%s: %d.%d No irq handler for vector\n",
213 __func__, smp_processor_id(), vector);
214 }
d3696cf7 215
1da177e4
LT
216 irq_exit();
217
7d12e780 218 set_irq_regs(old_regs);
1da177e4
LT
219 return 1;
220}
221
76e4f660
AR
222#ifdef CONFIG_HOTPLUG_CPU
223void fixup_irqs(cpumask_t map)
224{
225 unsigned int irq;
226 static int warned;
2c6927a3 227 struct irq_desc *desc;
76e4f660 228
2c6927a3 229 for_each_irq_desc(irq, desc) {
76e4f660 230 cpumask_t mask;
48d8d7ee
SS
231 int break_affinity = 0;
232 int set_affinity = 1;
233
76e4f660
AR
234 if (irq == 2)
235 continue;
236
48d8d7ee 237 /* interrupt's are disabled at this point */
08678b08 238 spin_lock(&desc->lock);
48d8d7ee
SS
239
240 if (!irq_has_action(irq) ||
08678b08
YL
241 cpus_equal(desc->affinity, map)) {
242 spin_unlock(&desc->lock);
48d8d7ee
SS
243 continue;
244 }
245
08678b08 246 cpus_and(mask, desc->affinity, map);
48d8d7ee
SS
247 if (cpus_empty(mask)) {
248 break_affinity = 1;
76e4f660
AR
249 mask = map;
250 }
48d8d7ee 251
08678b08
YL
252 if (desc->chip->mask)
253 desc->chip->mask(irq);
48d8d7ee 254
08678b08
YL
255 if (desc->chip->set_affinity)
256 desc->chip->set_affinity(irq, mask);
48d8d7ee
SS
257 else if (!(warned++))
258 set_affinity = 0;
259
08678b08
YL
260 if (desc->chip->unmask)
261 desc->chip->unmask(irq);
48d8d7ee 262
08678b08 263 spin_unlock(&desc->lock);
48d8d7ee
SS
264
265 if (break_affinity && set_affinity)
266 printk("Broke affinity for irq %i\n", irq);
267 else if (!set_affinity)
76e4f660
AR
268 printk("Cannot set affinity for irq %i\n", irq);
269 }
270
271 /* That doesn't seem sufficient. Give it 1ms. */
272 local_irq_enable();
273 mdelay(1);
274 local_irq_disable();
275}
276#endif
ed6b676c
AK
277
278extern void call_softirq(void);
279
280asmlinkage void do_softirq(void)
281{
282 __u32 pending;
283 unsigned long flags;
284
285 if (in_interrupt())
286 return;
287
288 local_irq_save(flags);
289 pending = local_softirq_pending();
290 /* Switch to interrupt stack */
2601e64d 291 if (pending) {
ed6b676c 292 call_softirq();
2601e64d
IM
293 WARN_ON_ONCE(softirq_count());
294 }
ed6b676c
AK
295 local_irq_restore(flags);
296}
This page took 0.449339 seconds and 5 git commands to generate.