[PATCH] i386: Page-align the GDT
[deliverable/linux.git] / arch / i386 / kernel / irq.c
CommitLineData
1da177e4
LT
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
1da177e4
LT
13#include <linux/module.h>
14#include <linux/seq_file.h>
15#include <linux/interrupt.h>
16#include <linux/kernel_stat.h>
f3705136
ZM
17#include <linux/notifier.h>
18#include <linux/cpu.h>
19#include <linux/delay.h>
1da177e4 20
e05d723f
TG
21#include <asm/apic.h>
22#include <asm/uaccess.h>
23
22fc6ecc 24DEFINE_PER_CPU(irq_cpustat_t, irq_stat) ____cacheline_internodealigned_in_smp;
1da177e4
LT
25EXPORT_PER_CPU_SYMBOL(irq_stat);
26
1da177e4
LT
27/*
28 * 'what should we do if we get a hw irq event on an illegal vector'.
29 * each architecture has to answer this themselves.
30 */
31void ack_bad_irq(unsigned int irq)
32{
e05d723f
TG
33 printk(KERN_ERR "unexpected IRQ trap at vector %02x\n", irq);
34
35#ifdef CONFIG_X86_LOCAL_APIC
36 /*
37 * Currently unexpected vectors happen only on SMP and APIC.
38 * We _must_ ack these because every local APIC has only N
39 * irq slots per priority level, and a 'hanging, unacked' IRQ
40 * holds up an irq slot - in excessive cases (when multiple
41 * unexpected vectors occur) that might lock up the APIC
42 * completely.
43 * But only ack when the APIC is enabled -AK
44 */
45 if (cpu_has_apic)
46 ack_APIC_irq();
1da177e4 47#endif
e05d723f 48}
1da177e4
LT
49
50#ifdef CONFIG_4KSTACKS
51/*
52 * per-CPU IRQ handling contexts (thread information and stack)
53 */
54union irq_ctx {
55 struct thread_info tinfo;
56 u32 stack[THREAD_SIZE/sizeof(u32)];
57};
58
22722051
AM
59static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
60static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
1da177e4
LT
61#endif
62
63/*
64 * do_IRQ handles all normal device IRQ's (the special
65 * SMP cross-CPU interrupts have their own specific
66 * handlers).
67 */
68fastcall unsigned int do_IRQ(struct pt_regs *regs)
69{
7d12e780 70 struct pt_regs *old_regs;
19eadf98
RR
71 /* high bit used in ret_from_ code */
72 int irq = ~regs->orig_eax;
f5b9ed7a 73 struct irq_desc *desc = irq_desc + irq;
1da177e4
LT
74#ifdef CONFIG_4KSTACKS
75 union irq_ctx *curctx, *irqctx;
76 u32 *isp;
77#endif
78
a052b68b
AM
79 if (unlikely((unsigned)irq >= NR_IRQS)) {
80 printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
81 __FUNCTION__, irq);
82 BUG();
83 }
84
7d12e780 85 old_regs = set_irq_regs(regs);
1da177e4
LT
86 irq_enter();
87#ifdef CONFIG_DEBUG_STACKOVERFLOW
88 /* Debugging check for stack overflow: is there less than 1KB free? */
89 {
90 long esp;
91
92 __asm__ __volatile__("andl %%esp,%0" :
93 "=r" (esp) : "0" (THREAD_SIZE - 1));
94 if (unlikely(esp < (sizeof(struct thread_info) + STACK_WARN))) {
95 printk("do_IRQ: stack overflow: %ld\n",
96 esp - sizeof(struct thread_info));
97 dump_stack();
98 }
99 }
100#endif
101
102#ifdef CONFIG_4KSTACKS
103
104 curctx = (union irq_ctx *) current_thread_info();
105 irqctx = hardirq_ctx[smp_processor_id()];
106
107 /*
108 * this is where we switch to the IRQ stack. However, if we are
109 * already using the IRQ stack (because we interrupted a hardirq
110 * handler) we can't do that and just have to keep using the
111 * current stack (which is the irq stack already after all)
112 */
113 if (curctx != irqctx) {
7d12e780 114 int arg1, arg2, ebx;
1da177e4
LT
115
116 /* build the stack frame on the IRQ stack */
117 isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
118 irqctx->tinfo.task = curctx->tinfo.task;
119 irqctx->tinfo.previous_esp = current_stack_pointer;
120