debuggers.hg

view linux-2.6.10-xen-sparse/arch/xen/i386/kernel/irq.c @ 3370:72b23176fb04

bitkeeper revision 1.1159.1.506 (41d00f89OifvQoN_EcnO5XuQN0RRjA)

Update to Linux 2.6.10.
author cl349@arcadians.cl.cam.ac.uk
date Mon Dec 27 13:35:05 2004 +0000 (2004-12-27)
parents
children 0a4b76b6b5a0
line source
1 /*
2 * linux/arch/i386/kernel/irq.c
3 *
4 * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
5 *
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
10 * io_apic.c.)
11 */
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
20 /*
21 * 'what should we do if we get a hw irq event on an illegal vector'.
22 * each architecture has to answer this themselves.
23 */
24 void ack_bad_irq(unsigned int irq)
25 {
26 printk("unexpected IRQ trap at vector %02x\n", irq);
27 }
28 #endif
30 #ifdef CONFIG_4KSTACKS
31 /*
32 * per-CPU IRQ handling contexts (thread information and stack)
33 */
34 union irq_ctx {
35 struct thread_info tinfo;
36 u32 stack[THREAD_SIZE/sizeof(u32)];
37 };
39 static union irq_ctx *hardirq_ctx[NR_CPUS];
40 static union irq_ctx *softirq_ctx[NR_CPUS];
41 #endif
43 /*
44 * do_IRQ handles all normal device IRQ's (the special
45 * SMP cross-CPU interrupts have their own specific
46 * handlers).
47 */
48 fastcall unsigned int do_IRQ(struct pt_regs *regs)
49 {
50 /* high bits used in ret_from_ code */
51 int irq = regs->orig_eax & __IRQ_MASK(HARDIRQ_BITS);
52 #ifdef CONFIG_4KSTACKS
53 union irq_ctx *curctx, *irqctx;
54 u32 *isp;
55 #endif
57 irq_enter();
58 #ifdef CONFIG_DEBUG_STACKOVERFLOW
59 /* Debugging check for stack overflow: is there less than 1KB free? */
60 {
61 long esp;
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));
68 dump_stack();
69 }
70 }
71 #endif
73 #ifdef CONFIG_4KSTACKS
75 curctx = (union irq_ctx *) current_thread_info();
76 irqctx = hardirq_ctx[smp_processor_id()];
78 /*
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)
83 */
84 if (curctx != irqctx) {
85 int arg1, arg2, ebx;
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;
92 asm volatile(
93 " xchgl %%ebx,%%esp \n"
94 " call __do_IRQ \n"
95 " movl %%ebx,%%esp \n"
96 : "=a" (arg1), "=d" (arg2), "=b" (ebx)
97 : "0" (irq), "1" (regs), "2" (isp)
98 : "memory", "cc", "ecx"
99 );
100 } else
101 #endif
102 __do_IRQ(irq, regs);
104 irq_exit();
106 return 1;
107 }
109 #ifdef CONFIG_4KSTACKS
111 /*
112 * These should really be __section__(".bss.page_aligned") as well, but
113 * gcc's 3.0 and earlier don't handle that correctly.
114 */
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)));
121 /*
122 * allocate per-cpu stacks for hardirq and for softirq processing
123 */
124 void irq_ctx_init(int cpu)
125 {
126 union irq_ctx *irqctx;
128 if (hardirq_ctx[cpu])
129 return;
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]);
151 }
153 extern asmlinkage void __do_softirq(void);
155 asmlinkage void do_softirq(void)
156 {
157 unsigned long flags;
158 struct thread_info *curctx;
159 union irq_ctx *irqctx;
160 u32 *isp;
162 if (in_interrupt())
163 return;
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));
176 asm volatile(
177 " xchgl %%ebx,%%esp \n"
178 " call __do_softirq \n"
179 " movl %%ebx,%%esp \n"
180 : "=b"(isp)
181 : "0"(isp)
182 : "memory", "cc", "edx", "ecx", "eax"
183 );
184 }
186 local_irq_restore(flags);
187 }
189 EXPORT_SYMBOL(do_softirq);
190 #endif
192 /*
193 * Interrupt statistics:
194 */
196 atomic_t irq_err_count;
198 /*
199 * /proc/interrupts printing:
200 */
202 int show_interrupts(struct seq_file *p, void *v)
203 {
204 int i = *(loff_t *) v, j;
205 struct irqaction * action;
206 unsigned long flags;
208 if (i == 0) {
209 seq_printf(p, " ");
210 for (j=0; j<NR_CPUS; j++)
211 if (cpu_online(j))
212 seq_printf(p, "CPU%d ",j);
213 seq_putc(p, '\n');
214 }
216 if (i < NR_IRQS) {
217 spin_lock_irqsave(&irq_desc[i].lock, flags);
218 action = irq_desc[i].action;
219 if (!action)
220 goto skip;
221 seq_printf(p, "%3d: ",i);
222 #ifndef CONFIG_SMP
223 seq_printf(p, "%10u ", kstat_irqs(i));
224 #else
225 for (j = 0; j < NR_CPUS; j++)
226 if (cpu_online(j))
227 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
228 #endif
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);
235 seq_putc(p, '\n');
236 skip:
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++)
241 if (cpu_online(j))
242 seq_printf(p, "%10u ", nmi_count(j));
243 seq_putc(p, '\n');
244 #ifdef CONFIG_X86_LOCAL_APIC
245 seq_printf(p, "LOC: ");
246 for (j = 0; j < NR_CPUS; j++)
247 if (cpu_online(j))
248 seq_printf(p, "%10u ",
249 irq_stat[j].apic_timer_irqs);
250 seq_putc(p, '\n');
251 #endif
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));
255 #endif
256 }
257 return 0;
258 }