[PARISC] Fix uniprocessor build by dummying smp_send_all_nop()
[pandora-kernel.git] / arch / parisc / kernel / irq.c
1 /* 
2  * Code to handle x86 style IRQs plus some generic interrupt stuff.
3  *
4  * Copyright (C) 1992 Linus Torvalds
5  * Copyright (C) 1994, 1995, 1996, 1997, 1998 Ralf Baechle
6  * Copyright (C) 1999 SuSE GmbH (Philipp Rumpf, prumpf@tux.org)
7  * Copyright (C) 1999-2000 Grant Grundler
8  * Copyright (c) 2005 Matthew Wilcox
9  *
10  *    This program is free software; you can redistribute it and/or modify
11  *    it under the terms of the GNU General Public License as published by
12  *    the Free Software Foundation; either version 2, or (at your option)
13  *    any later version.
14  *
15  *    This program is distributed in the hope that it will be useful,
16  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *    GNU General Public License for more details.
19  *
20  *    You should have received a copy of the GNU General Public License
21  *    along with this program; if not, write to the Free Software
22  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 #include <linux/bitops.h>
25 #include <linux/config.h>
26 #include <linux/errno.h>
27 #include <linux/init.h>
28 #include <linux/interrupt.h>
29 #include <linux/kernel_stat.h>
30 #include <linux/seq_file.h>
31 #include <linux/spinlock.h>
32 #include <linux/types.h>
33
34 #include <asm/smp.h>
35
36 #undef PARISC_IRQ_CR16_COUNTS
37
38 extern irqreturn_t timer_interrupt(int, void *, struct pt_regs *);
39 extern irqreturn_t ipi_interrupt(int, void *, struct pt_regs *);
40
41 #define EIEM_MASK(irq)       (1UL<<(CPU_IRQ_MAX - irq))
42
43 /* Bits in EIEM correlate with cpu_irq_action[].
44 ** Numbered *Big Endian*! (ie bit 0 is MSB)
45 */
46 static volatile unsigned long cpu_eiem = 0;
47
48 static void cpu_disable_irq(unsigned int irq)
49 {
50         unsigned long eirr_bit = EIEM_MASK(irq);
51
52         cpu_eiem &= ~eirr_bit;
53         /* Do nothing on the other CPUs.  If they get this interrupt,
54          * The & cpu_eiem in the do_cpu_irq_mask() ensures they won't
55          * handle it, and the set_eiem() at the bottom will ensure it
56          * then gets disabled */
57 }
58
59 static void cpu_enable_irq(unsigned int irq)
60 {
61         unsigned long eirr_bit = EIEM_MASK(irq);
62
63         cpu_eiem |= eirr_bit;
64
65         /* FIXME: while our interrupts aren't nested, we cannot reset
66          * the eiem mask if we're already in an interrupt.  Once we
67          * implement nested interrupts, this can go away
68          */
69         if (!in_interrupt())
70                 set_eiem(cpu_eiem);
71
72         /* This is just a simple NOP IPI.  But what it does is cause
73          * all the other CPUs to do a set_eiem(cpu_eiem) at the end
74          * of the interrupt handler */
75         smp_send_all_nop();
76 }
77
78 static unsigned int cpu_startup_irq(unsigned int irq)
79 {
80         cpu_enable_irq(irq);
81         return 0;
82 }
83
84 void no_ack_irq(unsigned int irq) { }
85 void no_end_irq(unsigned int irq) { }
86
87 static struct hw_interrupt_type cpu_interrupt_type = {
88         .typename       = "CPU",
89         .startup        = cpu_startup_irq,
90         .shutdown       = cpu_disable_irq,
91         .enable         = cpu_enable_irq,
92         .disable        = cpu_disable_irq,
93         .ack            = no_ack_irq,
94         .end            = no_end_irq,
95 //      .set_affinity   = cpu_set_affinity_irq,
96 };
97
98 int show_interrupts(struct seq_file *p, void *v)
99 {
100         int i = *(loff_t *) v, j;
101         unsigned long flags;
102
103         if (i == 0) {
104                 seq_puts(p, "    ");
105                 for_each_online_cpu(j)
106                         seq_printf(p, "       CPU%d", j);
107
108 #ifdef PARISC_IRQ_CR16_COUNTS
109                 seq_printf(p, " [min/avg/max] (CPU cycle counts)");
110 #endif
111                 seq_putc(p, '\n');
112         }
113
114         if (i < NR_IRQS) {
115                 struct irqaction *action;
116
117                 spin_lock_irqsave(&irq_desc[i].lock, flags);
118                 action = irq_desc[i].action;
119                 if (!action)
120                         goto skip;
121                 seq_printf(p, "%3d: ", i);
122 #ifdef CONFIG_SMP
123                 for_each_online_cpu(j)
124                         seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
125 #else
126                 seq_printf(p, "%10u ", kstat_irqs(i));
127 #endif
128
129                 seq_printf(p, " %14s", irq_desc[i].handler->typename);
130 #ifndef PARISC_IRQ_CR16_COUNTS
131                 seq_printf(p, "  %s", action->name);
132
133                 while ((action = action->next))
134                         seq_printf(p, ", %s", action->name);
135 #else
136                 for ( ;action; action = action->next) {
137                         unsigned int k, avg, min, max;
138
139                         min = max = action->cr16_hist[0];
140
141                         for (avg = k = 0; k < PARISC_CR16_HIST_SIZE; k++) {
142                                 int hist = action->cr16_hist[k];
143
144                                 if (hist) {
145                                         avg += hist;
146                                 } else
147                                         break;
148
149                                 if (hist > max) max = hist;
150                                 if (hist < min) min = hist;
151                         }
152
153                         avg /= k;
154                         seq_printf(p, " %s[%d/%d/%d]", action->name,
155                                         min,avg,max);
156                 }
157 #endif
158
159                 seq_putc(p, '\n');
160  skip:
161                 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
162         }
163
164         return 0;
165 }
166
167
168
169 /*
170 ** The following form a "set": Virtual IRQ, Transaction Address, Trans Data.
171 ** Respectively, these map to IRQ region+EIRR, Processor HPA, EIRR bit.
172 **
173 ** To use txn_XXX() interfaces, get a Virtual IRQ first.
174 ** Then use that to get the Transaction address and data.
175 */
176
177 int cpu_claim_irq(unsigned int irq, struct hw_interrupt_type *type, void *data)
178 {
179         if (irq_desc[irq].action)
180                 return -EBUSY;
181         if (irq_desc[irq].handler != &cpu_interrupt_type)
182                 return -EBUSY;
183
184         if (type) {
185                 irq_desc[irq].handler = type;
186                 irq_desc[irq].handler_data = data;
187                 cpu_interrupt_type.enable(irq);
188         }
189         return 0;
190 }
191
192 int txn_claim_irq(int irq)
193 {
194         return cpu_claim_irq(irq, NULL, NULL) ? -1 : irq;
195 }
196
197 /*
198  * The bits_wide parameter accommodates the limitations of the HW/SW which
199  * use these bits:
200  * Legacy PA I/O (GSC/NIO): 5 bits (architected EIM register)
201  * V-class (EPIC):          6 bits
202  * N/L/A-class (iosapic):   8 bits
203  * PCI 2.2 MSI:            16 bits
204  * Some PCI devices:       32 bits (Symbios SCSI/ATM/HyperFabric)
205  *
206  * On the service provider side:
207  * o PA 1.1 (and PA2.0 narrow mode)     5-bits (width of EIR register)
208  * o PA 2.0 wide mode                   6-bits (per processor)
209  * o IA64                               8-bits (0-256 total)
210  *
211  * So a Legacy PA I/O device on a PA 2.0 box can't use all the bits supported
212  * by the processor...and the N/L-class I/O subsystem supports more bits than
213  * PA2.0 has. The first case is the problem.
214  */
215 int txn_alloc_irq(unsigned int bits_wide)
216 {
217         int irq;
218
219         /* never return irq 0 cause that's the interval timer */
220         for (irq = CPU_IRQ_BASE + 1; irq <= CPU_IRQ_MAX; irq++) {
221                 if (cpu_claim_irq(irq, NULL, NULL) < 0)
222                         continue;
223                 if ((irq - CPU_IRQ_BASE) >= (1 << bits_wide))
224                         continue;
225                 return irq;
226         }
227
228         /* unlikely, but be prepared */
229         return -1;
230 }
231
232 unsigned long txn_alloc_addr(unsigned int virt_irq)
233 {
234         static int next_cpu = -1;
235
236         next_cpu++; /* assign to "next" CPU we want this bugger on */
237
238         /* validate entry */
239         while ((next_cpu < NR_CPUS) && (!cpu_data[next_cpu].txn_addr || 
240                 !cpu_online(next_cpu)))
241                 next_cpu++;
242
243         if (next_cpu >= NR_CPUS) 
244                 next_cpu = 0;   /* nothing else, assign monarch */
245
246         return cpu_data[next_cpu].txn_addr;
247 }
248
249
250 unsigned int txn_alloc_data(unsigned int virt_irq)
251 {
252         return virt_irq - CPU_IRQ_BASE;
253 }
254
255 /* ONLY called from entry.S:intr_extint() */
256 void do_cpu_irq_mask(struct pt_regs *regs)
257 {
258         unsigned long eirr_val;
259
260         irq_enter();
261
262         /*
263          * Don't allow TIMER or IPI nested interrupts.
264          * Allowing any single interrupt to nest can lead to that CPU
265          * handling interrupts with all enabled interrupts unmasked.
266          */
267         set_eiem(0UL);
268
269         /* 1) only process IRQs that are enabled/unmasked (cpu_eiem)
270          * 2) We loop here on EIRR contents in order to avoid
271          *    nested interrupts or having to take another interrupt
272          *    when we could have just handled it right away.
273          */
274         for (;;) {
275                 unsigned long bit = (1UL << (BITS_PER_LONG - 1));
276                 unsigned int irq;
277                 eirr_val = mfctl(23) & cpu_eiem;
278                 if (!eirr_val)
279                         break;
280
281                 mtctl(eirr_val, 23); /* reset bits we are going to process */
282
283                 /* Work our way from MSb to LSb...same order we alloc EIRs */
284                 for (irq = TIMER_IRQ; eirr_val && bit; bit>>=1, irq++) {
285                         if (!(bit & eirr_val))
286                                 continue;
287
288                         /* clear bit in mask - can exit loop sooner */
289                         eirr_val &= ~bit;
290
291                         __do_IRQ(irq, regs);
292                 }
293         }
294
295         set_eiem(cpu_eiem);     /* restore original mask */
296         irq_exit();
297 }
298
299
300 static struct irqaction timer_action = {
301         .handler = timer_interrupt,
302         .name = "timer",
303         .flags = SA_INTERRUPT,
304 };
305
306 #ifdef CONFIG_SMP
307 static struct irqaction ipi_action = {
308         .handler = ipi_interrupt,
309         .name = "IPI",
310         .flags = SA_INTERRUPT,
311 };
312 #endif
313
314 static void claim_cpu_irqs(void)
315 {
316         int i;
317         for (i = CPU_IRQ_BASE; i <= CPU_IRQ_MAX; i++) {
318                 irq_desc[i].handler = &cpu_interrupt_type;
319         }
320
321         irq_desc[TIMER_IRQ].action = &timer_action;
322         irq_desc[TIMER_IRQ].status |= IRQ_PER_CPU;
323 #ifdef CONFIG_SMP
324         irq_desc[IPI_IRQ].action = &ipi_action;
325         irq_desc[IPI_IRQ].status = IRQ_PER_CPU;
326 #endif
327 }
328
329 void __init init_IRQ(void)
330 {
331         local_irq_disable();    /* PARANOID - should already be disabled */
332         mtctl(~0UL, 23);        /* EIRR : clear all pending external intr */
333         claim_cpu_irqs();
334 #ifdef CONFIG_SMP
335         if (!cpu_eiem)
336                 cpu_eiem = EIEM_MASK(IPI_IRQ) | EIEM_MASK(TIMER_IRQ);
337 #else
338         cpu_eiem = EIEM_MASK(TIMER_IRQ);
339 #endif
340         set_eiem(cpu_eiem);     /* EIEM : enable all external intr */
341
342 }
343
344 void hw_resend_irq(struct hw_interrupt_type *type, unsigned int irq)
345 {
346         /* XXX: Needs to be written.  We managed without it so far, but
347          * we really ought to write it.
348          */
349 }
350
351 void ack_bad_irq(unsigned int irq)
352 {
353         printk("unexpected IRQ %d\n", irq);
354 }