]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/kernel/irq_32.c
x86: unify show_interrupts() and proc helpers
[linux-2.6-omap-h63xx.git] / arch / x86 / kernel / irq_32.c
1 /*
2  *      Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
3  *
4  * This file contains the lowest level x86-specific interrupt
5  * entry, irq-stacks and irq statistics code. All the remaining
6  * irq logic is done by the generic kernel/irq/ code and
7  * by the x86-specific irq controller code. (e.g. i8259.c and
8  * io_apic.c.)
9  */
10
11 #include <linux/module.h>
12 #include <linux/seq_file.h>
13 #include <linux/interrupt.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/notifier.h>
16 #include <linux/cpu.h>
17 #include <linux/delay.h>
18
19 #include <asm/apic.h>
20 #include <asm/uaccess.h>
21
22 DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
23 EXPORT_PER_CPU_SYMBOL(irq_stat);
24
25 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
26 EXPORT_PER_CPU_SYMBOL(irq_regs);
27
28 /*
29  * 'what should we do if we get a hw irq event on an illegal vector'.
30  * each architecture has to answer this themselves.
31  */
32 void ack_bad_irq(unsigned int irq)
33 {
34         printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
35
36 #ifdef CONFIG_X86_LOCAL_APIC
37         /*
38          * Currently unexpected vectors happen only on SMP and APIC.
39          * We _must_ ack these because every local APIC has only N
40          * irq slots per priority level, and a 'hanging, unacked' IRQ
41          * holds up an irq slot - in excessive cases (when multiple
42          * unexpected vectors occur) that might lock up the APIC
43          * completely.
44          * But only ack when the APIC is enabled -AK
45          */
46         if (cpu_has_apic)
47                 ack_APIC_irq();
48 #endif
49 }
50
51 #ifdef CONFIG_DEBUG_STACKOVERFLOW
52 /* Debugging check for stack overflow: is there less than 1KB free? */
53 static int check_stack_overflow(void)
54 {
55         long sp;
56
57         __asm__ __volatile__("andl %%esp,%0" :
58                              "=r" (sp) : "0" (THREAD_SIZE - 1));
59
60         return sp < (sizeof(struct thread_info) + STACK_WARN);
61 }
62
63 static void print_stack_overflow(void)
64 {
65         printk(KERN_WARNING "low stack detected by irq handler\n");
66         dump_stack();
67 }
68
69 #else
70 static inline int check_stack_overflow(void) { return 0; }
71 static inline void print_stack_overflow(void) { }
72 #endif
73
74 #ifdef CONFIG_4KSTACKS
75 /*
76  * per-CPU IRQ handling contexts (thread information and stack)
77  */
78 union irq_ctx {
79         struct thread_info      tinfo;
80         u32                     stack[THREAD_SIZE/sizeof(u32)];
81 };
82
83 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
84 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
85
86 static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
87 static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
88
89 static void call_on_stack(void *func, void *stack)
90 {
91         asm volatile("xchgl     %%ebx,%%esp     \n"
92                      "call      *%%edi          \n"
93                      "movl      %%ebx,%%esp     \n"
94                      : "=b" (stack)
95                      : "0" (stack),
96                        "D"(func)
97                      : "memory", "cc", "edx", "ecx", "eax");
98 }
99
100 static inline int
101 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
102 {
103         union irq_ctx *curctx, *irqctx;
104         u32 *isp, arg1, arg2;
105
106         curctx = (union irq_ctx *) current_thread_info();
107         irqctx = hardirq_ctx[smp_processor_id()];
108
109         /*
110          * this is where we switch to the IRQ stack. However, if we are
111          * already using the IRQ stack (because we interrupted a hardirq
112          * handler) we can't do that and just have to keep using the
113          * current stack (which is the irq stack already after all)
114          */
115         if (unlikely(curctx == irqctx))
116                 return 0;
117
118         /* build the stack frame on the IRQ stack */
119         isp = (u32 *) ((char*)irqctx + sizeof(*irqctx));
120         irqctx->tinfo.task = curctx->tinfo.task;
121         irqctx->tinfo.previous_esp = current_stack_pointer;
122
123         /*
124          * Copy the softirq bits in preempt_count so that the
125          * softirq checks work in the hardirq context.
126          */
127         irqctx->tinfo.preempt_count =
128                 (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
129                 (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
130
131         if (unlikely(overflow))
132                 call_on_stack(print_stack_overflow, isp);
133
134         asm volatile("xchgl     %%ebx,%%esp     \n"
135                      "call      *%%edi          \n"
136                      "movl      %%ebx,%%esp     \n"
137                      : "=a" (arg1), "=d" (arg2), "=b" (isp)
138                      :  "0" (irq),   "1" (desc),  "2" (isp),
139                         "D" (desc->handle_irq)
140                      : "memory", "cc", "ecx");
141         return 1;
142 }
143
144 /*
145  * allocate per-cpu stacks for hardirq and for softirq processing
146  */
147 void __cpuinit irq_ctx_init(int cpu)
148 {
149         union irq_ctx *irqctx;
150
151         if (hardirq_ctx[cpu])
152                 return;
153
154         irqctx = (union irq_ctx*) &hardirq_stack[cpu*THREAD_SIZE];
155         irqctx->tinfo.task              = NULL;
156         irqctx->tinfo.exec_domain       = NULL;
157         irqctx->tinfo.cpu               = cpu;
158         irqctx->tinfo.preempt_count     = HARDIRQ_OFFSET;
159         irqctx->tinfo.addr_limit        = MAKE_MM_SEG(0);
160
161         hardirq_ctx[cpu] = irqctx;
162
163         irqctx = (union irq_ctx*) &softirq_stack[cpu*THREAD_SIZE];
164         irqctx->tinfo.task              = NULL;
165         irqctx->tinfo.exec_domain       = NULL;
166         irqctx->tinfo.cpu               = cpu;
167         irqctx->tinfo.preempt_count     = 0;
168         irqctx->tinfo.addr_limit        = MAKE_MM_SEG(0);
169
170         softirq_ctx[cpu] = irqctx;
171
172         printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
173                cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
174 }
175
176 void irq_ctx_exit(int cpu)
177 {
178         hardirq_ctx[cpu] = NULL;
179 }
180
181 asmlinkage void do_softirq(void)
182 {
183         unsigned long flags;
184         struct thread_info *curctx;
185         union irq_ctx *irqctx;
186         u32 *isp;
187
188         if (in_interrupt())
189                 return;
190
191         local_irq_save(flags);
192
193         if (local_softirq_pending()) {
194                 curctx = current_thread_info();
195                 irqctx = softirq_ctx[smp_processor_id()];
196                 irqctx->tinfo.task = curctx->task;
197                 irqctx->tinfo.previous_esp = current_stack_pointer;
198
199                 /* build the stack frame on the softirq stack */
200                 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
201
202                 call_on_stack(__do_softirq, isp);
203                 /*
204                  * Shouldnt happen, we returned above if in_interrupt():
205                  */
206                 WARN_ON_ONCE(softirq_count());
207         }
208
209         local_irq_restore(flags);
210 }
211
212 #else
213 static inline int
214 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq) { return 0; }
215 #endif
216
217 /*
218  * do_IRQ handles all normal device IRQ's (the special
219  * SMP cross-CPU interrupts have their own specific
220  * handlers).
221  */
222 unsigned int do_IRQ(struct pt_regs *regs)
223 {
224         struct pt_regs *old_regs;
225         /* high bit used in ret_from_ code */
226         int overflow;
227         unsigned vector = ~regs->orig_ax;
228         struct irq_desc *desc;
229         unsigned irq;
230
231
232         old_regs = set_irq_regs(regs);
233         irq_enter();
234         irq = __get_cpu_var(vector_irq)[vector];
235
236         overflow = check_stack_overflow();
237
238         desc = irq_to_desc(irq);
239         if (unlikely(!desc)) {
240                 printk(KERN_EMERG "%s: cannot handle IRQ %d vector %#x cpu %d\n",
241                                         __func__, irq, vector, smp_processor_id());
242                 BUG();
243         }
244
245         if (!execute_on_irq_stack(overflow, desc, irq)) {
246                 if (unlikely(overflow))
247                         print_stack_overflow();
248                 desc->handle_irq(irq, desc);
249         }
250
251         irq_exit();
252         set_irq_regs(old_regs);
253         return 1;
254 }
255
256 #ifdef CONFIG_HOTPLUG_CPU
257 #include <mach_apic.h>
258
259 void fixup_irqs(cpumask_t map)
260 {
261         unsigned int irq;
262         static int warned;
263         struct irq_desc *desc;
264
265         for_each_irq_desc(irq, desc) {
266                 cpumask_t mask;
267
268                 if (irq == 2)
269                         continue;
270
271                 cpus_and(mask, desc->affinity, map);
272                 if (any_online_cpu(mask) == NR_CPUS) {
273                         printk("Breaking affinity for irq %i\n", irq);
274                         mask = map;
275                 }
276                 if (desc->chip->set_affinity)
277                         desc->chip->set_affinity(irq, mask);
278                 else if (desc->action && !(warned++))
279                         printk("Cannot set affinity for irq %i\n", irq);
280         }
281
282 #if 0
283         barrier();
284         /* Ingo Molnar says: "after the IO-APIC masks have been redirected
285            [note the nop - the interrupt-enable boundary on x86 is two
286            instructions from sti] - to flush out pending hardirqs and
287            IPIs. After this point nothing is supposed to reach this CPU." */
288         __asm__ __volatile__("sti; nop; cli");
289         barrier();
290 #else
291         /* That doesn't seem sufficient.  Give it 1ms. */
292         local_irq_enable();
293         mdelay(1);
294         local_irq_disable();
295 #endif
296 }
297 #endif
298