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 / xtensa / kernel / irq.c
1 /*
2  * linux/arch/xtensa/kernel/irq.c
3  *
4  * Xtensa built-in interrupt controller and some generic functions copied
5  * from i386.
6  *
7  * Copyright (C) 2002 - 2005 Tensilica, Inc.
8  * Copyright (C) 1992, 1998 Linus Torvalds, Ingo Molnar
9  *
10  *
11  * Chris Zankel <chris@zankel.net>
12  * Kevin Chea
13  *
14  */
15
16 #include <linux/module.h>
17 #include <linux/seq_file.h>
18 #include <linux/interrupt.h>
19 #include <linux/irq.h>
20 #include <linux/kernel_stat.h>
21
22 #include <asm/uaccess.h>
23 #include <asm/platform.h>
24
25 static void enable_xtensa_irq(unsigned int irq);
26 static void disable_xtensa_irq(unsigned int irq);
27 static void mask_and_ack_xtensa(unsigned int irq);
28 static void end_xtensa_irq(unsigned int irq);
29
30 static unsigned int cached_irq_mask;
31
32 atomic_t irq_err_count;
33
34 /*
35  * 'what should we do if we get a hw irq event on an illegal vector'.
36  * each architecture has to answer this themselves.
37  */
38 void ack_bad_irq(unsigned int irq)
39 {
40           printk("unexpected IRQ trap at vector %02x\n", irq);
41 }
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
49 unsigned int  do_IRQ(int irq, struct pt_regs *regs)
50 {
51         irq_enter();
52
53 #ifdef CONFIG_DEBUG_STACKOVERFLOW
54         /* Debugging check for stack overflow: is there less than 1KB free? */
55         {
56                 unsigned long sp;
57
58                 __asm__ __volatile__ ("mov %0, a1\n" : "=a" (sp));
59                 sp &= THREAD_SIZE - 1;
60
61                 if (unlikely(sp < (sizeof(thread_info) + 1024)))
62                         printk("Stack overflow in do_IRQ: %ld\n",
63                                sp - sizeof(struct thread_info));
64         }
65 #endif
66         __do_IRQ(irq, regs);
67         irq_exit();
68
69         return 1;
70 }
71
72 /*
73  * Generic, controller-independent functions:
74  */
75
76 int show_interrupts(struct seq_file *p, void *v)
77 {
78         int i = *(loff_t *) v, j;
79         struct irqaction * action;
80         unsigned long flags;
81
82         if (i == 0) {
83                 seq_printf(p, "           ");
84                 for_each_online_cpu(j)
85                         seq_printf(p, "CPU%d       ",j);
86                 seq_putc(p, '\n');
87         }
88
89         if (i < NR_IRQS) {
90                 spin_lock_irqsave(&irq_desc[i].lock, flags);
91                 action = irq_desc[i].action;
92                 if (!action)
93                         goto skip;
94                 seq_printf(p, "%3d: ",i);
95 #ifndef CONFIG_SMP
96                 seq_printf(p, "%10u ", kstat_irqs(i));
97 #else
98                 for_each_online_cpu(j)
99                         seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
100 #endif
101                 seq_printf(p, " %14s", irq_desc[i].chip->typename);
102                 seq_printf(p, "  %s", action->name);
103
104                 for (action=action->next; action; action = action->next)
105                         seq_printf(p, ", %s", action->name);
106
107                 seq_putc(p, '\n');
108 skip:
109                 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
110         } else if (i == NR_IRQS) {
111                 seq_printf(p, "NMI: ");
112                 for_each_online_cpu(j)
113                         seq_printf(p, "%10u ", nmi_count(j));
114                 seq_putc(p, '\n');
115                 seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
116         }
117         return 0;
118 }
119 /* shutdown is same as "disable" */
120 #define shutdown_xtensa_irq disable_xtensa_irq
121
122 static unsigned int startup_xtensa_irq(unsigned int irq)
123 {
124         enable_xtensa_irq(irq);
125         return 0;               /* never anything pending */
126 }
127
128 static struct hw_interrupt_type xtensa_irq_type = {
129         "Xtensa-IRQ",
130         startup_xtensa_irq,
131         shutdown_xtensa_irq,
132         enable_xtensa_irq,
133         disable_xtensa_irq,
134         mask_and_ack_xtensa,
135         end_xtensa_irq
136 };
137
138 static inline void mask_irq(unsigned int irq)
139 {
140         cached_irq_mask &= ~(1 << irq);
141         set_sr (cached_irq_mask, INTENABLE);
142 }
143
144 static inline void unmask_irq(unsigned int irq)
145 {
146         cached_irq_mask |= 1 << irq;
147         set_sr (cached_irq_mask, INTENABLE);
148 }
149
150 static void disable_xtensa_irq(unsigned int irq)
151 {
152         unsigned long flags;
153         local_save_flags(flags);
154         mask_irq(irq);
155         local_irq_restore(flags);
156 }
157
158 static void enable_xtensa_irq(unsigned int irq)
159 {
160         unsigned long flags;
161         local_save_flags(flags);
162         unmask_irq(irq);
163         local_irq_restore(flags);
164 }
165
166 static void mask_and_ack_xtensa(unsigned int irq)
167 {
168         disable_xtensa_irq(irq);
169 }
170
171 static void end_xtensa_irq(unsigned int irq)
172 {
173         enable_xtensa_irq(irq);
174 }
175
176
177 void __init init_IRQ(void)
178 {
179         int i;
180
181         for (i=0; i < XTENSA_NR_IRQS; i++)
182                 irq_desc[i].chip = &xtensa_irq_type;
183
184         cached_irq_mask = 0;
185
186         platform_init_irq();
187 }