2 * linux/arch/i386/kernel/irq.c
4 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
6 * This file contains the lowest level x86-specific interrupt
7 * entry, irq-stacks and irq statistics code. All the remaining
8 * irq logic is done by the generic kernel/irq/ code and
9 * by the x86-specific irq controller code. (e.g. i8259.c and
13 #include <asm/uaccess.h>
14 #include <linux/module.h>
15 #include <linux/seq_file.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel_stat.h>
19 #ifndef CONFIG_X86_LOCAL_APIC
21 * 'what should we do if we get a hw irq event on an illegal vector'.
22 * each architecture has to answer this themselves.
24 void ack_bad_irq(unsigned int irq)
26 printk("unexpected IRQ trap at vector %02x\n", irq);
30 #ifdef CONFIG_4KSTACKS
32 * per-CPU IRQ handling contexts (thread information and stack)
35 struct thread_info tinfo;
36 u32 stack[THREAD_SIZE/sizeof(u32)];
39 static union irq_ctx *hardirq_ctx[NR_CPUS];
40 static union irq_ctx *softirq_ctx[NR_CPUS];
44 * do_IRQ handles all normal device IRQ's (the special
45 * SMP cross-CPU interrupts have their own specific
48 fastcall unsigned int do_IRQ(struct pt_regs *regs)
50 /* high bits used in ret_from_ code */
51 int irq = regs->orig_eax & 0xff;
52 #ifdef CONFIG_4KSTACKS
53 union irq_ctx *curctx, *irqctx;
58 #ifdef CONFIG_DEBUG_STACKOVERFLOW
59 /* Debugging check for stack overflow: is there less than 1KB free? */
63 __asm__ __volatile__("andl %%esp,%0" :
64 "=r" (esp) : "0" (THREAD_SIZE - 1));
65 if (unlikely(esp < (sizeof(struct thread_info) + STACK_WARN))) {
66 printk("do_IRQ: stack overflow: %ld\n",
67 esp - sizeof(struct thread_info));
73 #ifdef CONFIG_4KSTACKS
75 curctx = (union irq_ctx *) current_thread_info();
76 irqctx = hardirq_ctx[smp_processor_id()];
79 * this is where we switch to the IRQ stack. However, if we are
80 * already using the IRQ stack (because we interrupted a hardirq
81 * handler) we can't do that and just have to keep using the
82 * current stack (which is the irq stack already after all)
84 if (curctx != irqctx) {
87 /* build the stack frame on the IRQ stack */
88 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
89 irqctx->tinfo.task = curctx->tinfo.task;
90 irqctx->tinfo.previous_esp = current_stack_pointer;
93 " xchgl %%ebx,%%esp \n"
95 " movl %%ebx,%%esp \n"
96 : "=a" (arg1), "=d" (arg2), "=b" (ebx)
97 : "0" (irq), "1" (regs), "2" (isp)
98 : "memory", "cc", "ecx"
109 #ifdef CONFIG_4KSTACKS
112 * These should really be __section__(".bss.page_aligned") as well, but
113 * gcc's 3.0 and earlier don't handle that correctly.
115 static char softirq_stack[NR_CPUS * THREAD_SIZE]
116 __attribute__((__aligned__(THREAD_SIZE)));
118 static char hardirq_stack[NR_CPUS * THREAD_SIZE]
119 __attribute__((__aligned__(THREAD_SIZE)));
122 * allocate per-cpu stacks for hardirq and for softirq processing
124 void irq_ctx_init(int cpu)
126 union irq_ctx *irqctx;
128 if (hardirq_ctx[cpu])
131 irqctx = (union irq_ctx*) &hardirq_stack[cpu*THREAD_SIZE];
132 irqctx->tinfo.task = NULL;
133 irqctx->tinfo.exec_domain = NULL;
134 irqctx->tinfo.cpu = cpu;
135 irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
136 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
138 hardirq_ctx[cpu] = irqctx;
140 irqctx = (union irq_ctx*) &softirq_stack[cpu*THREAD_SIZE];
141 irqctx->tinfo.task = NULL;
142 irqctx->tinfo.exec_domain = NULL;
143 irqctx->tinfo.cpu = cpu;
144 irqctx->tinfo.preempt_count = SOFTIRQ_OFFSET;
145 irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
147 softirq_ctx[cpu] = irqctx;
149 printk("CPU %u irqstacks, hard=%p soft=%p\n",
150 cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
153 extern asmlinkage void __do_softirq(void);
155 asmlinkage void do_softirq(void)
158 struct thread_info *curctx;
159 union irq_ctx *irqctx;
165 local_irq_save(flags);
167 if (local_softirq_pending()) {
168 curctx = current_thread_info();
169 irqctx = softirq_ctx[smp_processor_id()];
170 irqctx->tinfo.task = curctx->task;
171 irqctx->tinfo.previous_esp = current_stack_pointer;
173 /* build the stack frame on the softirq stack */
174 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
177 " xchgl %%ebx,%%esp \n"
178 " call __do_softirq \n"
179 " movl %%ebx,%%esp \n"
182 : "memory", "cc", "edx", "ecx", "eax"
186 local_irq_restore(flags);
189 EXPORT_SYMBOL(do_softirq);
193 * Interrupt statistics:
196 atomic_t irq_err_count;
199 * /proc/interrupts printing:
202 int show_interrupts(struct seq_file *p, void *v)
204 int i = *(loff_t *) v, j;
205 struct irqaction * action;
210 for (j=0; j<NR_CPUS; j++)
212 seq_printf(p, "CPU%d ",j);
217 spin_lock_irqsave(&irq_desc[i].lock, flags);
218 action = irq_desc[i].action;
221 seq_printf(p, "%3d: ",i);
223 seq_printf(p, "%10u ", kstat_irqs(i));
225 for (j = 0; j < NR_CPUS; j++)
227 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
229 seq_printf(p, " %14s", irq_desc[i].handler->typename);
230 seq_printf(p, " %s", action->name);
232 for (action=action->next; action; action = action->next)
233 seq_printf(p, ", %s", action->name);
237 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
238 } else if (i == NR_IRQS) {
239 seq_printf(p, "NMI: ");
240 for (j = 0; j < NR_CPUS; j++)
242 seq_printf(p, "%10u ", nmi_count(j));
244 #ifdef CONFIG_X86_LOCAL_APIC
245 seq_printf(p, "LOC: ");
246 for (j = 0; j < NR_CPUS; j++)
248 seq_printf(p, "%10u ",
249 irq_stat[j].apic_timer_irqs);
252 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
253 #if defined(CONFIG_X86_IO_APIC)
254 seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));