Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  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  */
 12 
 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>
 18 
 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
 29 
 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 };
 38 
 39 static union irq_ctx *hardirq_ctx[NR_CPUS];
 40 static union irq_ctx *softirq_ctx[NR_CPUS];
 41 #endif
 42 
 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 & 0xff;
 52 #ifdef CONFIG_4KSTACKS
 53         union irq_ctx *curctx, *irqctx;
 54         u32 *isp;
 55 #endif
 56 
 57         irq_enter();
 58 #ifdef CONFIG_DEBUG_STACKOVERFLOW
 59         /* Debugging check for stack overflow: is there less than 1KB free? */
 60         {
 61                 long esp;
 62 
 63                 __asm__ __volatile__("andl %%esp,%0" :
 64                                         "=r" (esp) : "" (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
 72 
 73 #ifdef CONFIG_4KSTACKS
 74 
 75         curctx = (union irq_ctx *) current_thread_info();
 76         irqctx = hardirq_ctx[smp_processor_id()];
 77 
 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;
 86 
 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;
 91 
 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                         :  "" (irq),   "1" (regs),  "2" (isp)
 98                         : "memory", "cc", "ecx"
 99                 );
100         } else
101 #endif
102                 __do_IRQ(irq, regs);
103 
104         irq_exit();
105 
106         return 1;
107 }
108 
109 #ifdef CONFIG_4KSTACKS
110 
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)));
117 
118 static char hardirq_stack[NR_CPUS * THREAD_SIZE]
119                 __attribute__((__aligned__(THREAD_SIZE)));
120 
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;
127 
128         if (hardirq_ctx[cpu])
129                 return;
130 
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);
137 
138         hardirq_ctx[cpu] = irqctx;
139 
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);
146 
147         softirq_ctx[cpu] = irqctx;
148 
149         printk("CPU %u irqstacks, hard=%p soft=%p\n",
150                 cpu,hardirq_ctx[cpu],softirq_ctx[cpu]);
151 }
152 
153 extern asmlinkage void __do_softirq(void);
154 
155 asmlinkage void do_softirq(void)
156 {
157         unsigned long flags;
158         struct thread_info *curctx;
159         union irq_ctx *irqctx;
160         u32 *isp;
161 
162         if (in_interrupt())
163                 return;
164 
165         local_irq_save(flags);
166 
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;
172 
173                 /* build the stack frame on the softirq stack */
174                 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
175 
176                 asm volatile(
177                         "       xchgl   %%ebx,%%esp     \n"
178                         "       call    __do_softirq    \n"
179                         "       movl    %%ebx,%%esp     \n"
180                         : "=b"(isp)
181                         : ""(isp)
182                         : "memory", "cc", "edx", "ecx", "eax"
183                 );
184         }
185 
186         local_irq_restore(flags);
187 }
188 
189 EXPORT_SYMBOL(do_softirq);
190 #endif
191 
192 /*
193  * Interrupt statistics:
194  */
195 
196 atomic_t irq_err_count;
197 
198 /*
199  * /proc/interrupts printing:
200  */
201 
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;
207 
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         }
215 
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);
231 
232                 for (action=action->next; action; action = action->next)
233                         seq_printf(p, ", %s", action->name);
234 
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 }
259 
  This page was automatically generated by the LXR engine.