Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / arch / x86_64 / kernel / irq-xen.c
1 /*
2  *      linux/arch/x86_64/kernel/irq.c
3  *
4  *      Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
5  *
6  * This file contains the lowest level x86_64-specific interrupt
7  * entry and irq statistics code. All the remaining irq logic is
8  * done by the generic kernel/irq/ code and in the
9  * x86_64-specific irq controller code. (e.g. i8259.c and
10  * io_apic.c.)
11  */
12
13 #include <linux/kernel_stat.h>
14 #include <linux/interrupt.h>
15 #include <linux/seq_file.h>
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/vs_context.h>
19 #include <asm/uaccess.h>
20 #include <asm/io_apic.h>
21 #include <asm/idle.h>
22
23 atomic_t irq_err_count;
24 #ifdef CONFIG_X86_IO_APIC
25 #ifdef APIC_MISMATCH_DEBUG
26 atomic_t irq_mis_count;
27 #endif
28 #endif
29
30 #ifdef CONFIG_DEBUG_STACKOVERFLOW
31 /*
32  * Probabilistic stack overflow check:
33  *
34  * Only check the stack in process context, because everything else
35  * runs on the big interrupt stacks. Checking reliably is too expensive,
36  * so we just check from interrupts.
37  */
38 static inline void stack_overflow_check(struct pt_regs *regs)
39 {
40         u64 curbase = (u64) current->thread_info;
41         static unsigned long warned = -60*HZ;
42
43         if (regs->rsp >= curbase && regs->rsp <= curbase + THREAD_SIZE &&
44             regs->rsp <  curbase + sizeof(struct thread_info) + 128 &&
45             time_after(jiffies, warned + 60*HZ)) {
46                 printk("do_IRQ: %s near stack overflow (cur:%Lx,rsp:%lx)\n",
47                        current->comm, curbase, regs->rsp);
48                 show_stack(NULL,NULL);
49                 warned = jiffies;
50         }
51 }
52 #endif
53
54 /*
55  * Generic, controller-independent functions:
56  */
57
58 int show_interrupts(struct seq_file *p, void *v)
59 {
60         int i = *(loff_t *) v, j;
61         struct irqaction * action;
62         unsigned long flags;
63
64         if (i == 0) {
65                 seq_printf(p, "           ");
66                 for_each_online_cpu(j)
67                         seq_printf(p, "CPU%-8d       ",j);
68                 seq_putc(p, '\n');
69         }
70
71         if (i < NR_IRQS) {
72                 spin_lock_irqsave(&irq_desc[i].lock, flags);
73                 action = irq_desc[i].action;
74                 if (!action) 
75                         goto skip;
76                 seq_printf(p, "%3d: ",i);
77 #ifndef CONFIG_SMP
78                 seq_printf(p, "%10u ", kstat_irqs(i));
79 #else
80                 for_each_online_cpu(j)
81                         seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
82 #endif
83                 seq_printf(p, " %14s", irq_desc[i].chip->typename);
84
85                 seq_printf(p, "  %s", action->name);
86                 for (action=action->next; action; action = action->next)
87                         seq_printf(p, ", %s", action->name);
88                 seq_putc(p, '\n');
89 skip:
90                 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
91         } else if (i == NR_IRQS) {
92                 seq_printf(p, "NMI: ");
93                 for_each_online_cpu(j)
94                         seq_printf(p, "%10u ", cpu_pda(j)->__nmi_count);
95                 seq_putc(p, '\n');
96 #ifdef CONFIG_X86_LOCAL_APIC
97                 seq_printf(p, "LOC: ");
98                 for_each_online_cpu(j)
99                         seq_printf(p, "%10u ", cpu_pda(j)->apic_timer_irqs);
100                 seq_putc(p, '\n');
101 #endif
102                 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
103 #ifdef CONFIG_X86_IO_APIC
104 #ifdef APIC_MISMATCH_DEBUG
105                 seq_printf(p, "MIS: %10u\n", atomic_read(&irq_mis_count));
106 #endif
107 #endif
108         }
109         return 0;
110 }
111
112 /*
113  * do_IRQ handles all normal device IRQ's (the special
114  * SMP cross-CPU interrupts have their own specific
115  * handlers).
116  */
117 asmlinkage unsigned int do_IRQ(struct pt_regs *regs)
118 {       
119         /* high bit used in ret_from_ code  */
120         unsigned irq = ~regs->orig_rax;
121         struct vx_info_save vxis;
122
123         if (unlikely(irq >= NR_IRQS)) {
124                 printk(KERN_EMERG "%s: cannot handle IRQ %d\n",
125                                         __FUNCTION__, irq);
126                 BUG();
127         }
128
129         exit_idle();
130         irq_enter();
131
132 #ifdef CONFIG_DEBUG_STACKOVERFLOW
133         stack_overflow_check(regs);
134 #endif
135         __enter_vx_admin(&vxis);
136         __do_IRQ(irq, regs);
137         __leave_vx_admin(&vxis);
138         irq_exit();
139
140         return 1;
141 }
142
143 #ifdef CONFIG_HOTPLUG_CPU
144 void fixup_irqs(cpumask_t map)
145 {
146         unsigned int irq;
147         static int warned;
148
149         for (irq = 0; irq < NR_IRQS; irq++) {
150                 cpumask_t mask;
151                 if (irq == 2)
152                         continue;
153
154                 cpus_and(mask, irq_desc[irq].affinity, map);
155                 if (any_online_cpu(mask) == NR_CPUS) {
156                         printk("Breaking affinity for irq %i\n", irq);
157                         mask = map;
158                 }
159                 if (irq_desc[irq].chip->set_affinity)
160                         irq_desc[irq].chip->set_affinity(irq, mask);
161                 else if (irq_desc[irq].action && !(warned++))
162                         printk("Cannot set affinity for irq %i\n", irq);
163         }
164
165         /* That doesn't seem sufficient.  Give it 1ms. */
166         local_irq_enable();
167         mdelay(1);
168         local_irq_disable();
169 }
170 #endif
171
172 extern void call_softirq(void);
173
174 asmlinkage void do_softirq(void)
175 {
176         __u32 pending;
177         unsigned long flags;
178
179         if (in_interrupt())
180                 return;
181
182         local_irq_save(flags);
183         pending = local_softirq_pending();
184         /* Switch to interrupt stack */
185         if (pending) {
186                 call_softirq();
187                 WARN_ON_ONCE(softirq_count());
188         }
189         local_irq_restore(flags);
190 }
191 EXPORT_SYMBOL(do_softirq);
192
193 #ifndef CONFIG_X86_LOCAL_APIC
194 /*
195  * 'what should we do if we get a hw irq event on an illegal vector'.
196  * each architecture has to answer this themselves.
197  */
198 void ack_bad_irq(unsigned int irq)
199 {
200         printk("unexpected IRQ trap at vector %02x\n", irq);
201 }
202 #endif