Merge branch 'upstream-fixes-jgarzik' of git://lost.foo-projects.org/~ahkok/git/netde...
[linux-2.6] / arch / mips / kernel / irq-rm9000.c
1 /*
2  * Copyright (C) 2003 Ralf Baechle
3  *
4  * This program is free software; you can redistribute  it and/or modify it
5  * under  the terms of  the GNU General  Public License as published by the
6  * Free Software Foundation;  either version 2 of the  License, or (at your
7  * option) any later version.
8  *
9  * Handler for RM9000 extended interrupts.  These are a non-standard
10  * feature so we handle them separately from standard interrupts.
11  */
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16
17 #include <asm/irq_cpu.h>
18 #include <asm/mipsregs.h>
19 #include <asm/system.h>
20
21 static int irq_base;
22
23 static inline void unmask_rm9k_irq(unsigned int irq)
24 {
25         set_c0_intcontrol(0x1000 << (irq - irq_base));
26 }
27
28 static inline void mask_rm9k_irq(unsigned int irq)
29 {
30         clear_c0_intcontrol(0x1000 << (irq - irq_base));
31 }
32
33 static inline void rm9k_cpu_irq_enable(unsigned int irq)
34 {
35         unsigned long flags;
36
37         local_irq_save(flags);
38         unmask_rm9k_irq(irq);
39         local_irq_restore(flags);
40 }
41
42 static void rm9k_cpu_irq_disable(unsigned int irq)
43 {
44         unsigned long flags;
45
46         local_irq_save(flags);
47         mask_rm9k_irq(irq);
48         local_irq_restore(flags);
49 }
50
51 static unsigned int rm9k_cpu_irq_startup(unsigned int irq)
52 {
53         rm9k_cpu_irq_enable(irq);
54
55         return 0;
56 }
57
58 #define rm9k_cpu_irq_shutdown   rm9k_cpu_irq_disable
59
60 /*
61  * Performance counter interrupts are global on all processors.
62  */
63 static void local_rm9k_perfcounter_irq_startup(void *args)
64 {
65         unsigned int irq = (unsigned int) args;
66
67         rm9k_cpu_irq_enable(irq);
68 }
69
70 static unsigned int rm9k_perfcounter_irq_startup(unsigned int irq)
71 {
72         on_each_cpu(local_rm9k_perfcounter_irq_startup, (void *) irq, 0, 1);
73
74         return 0;
75 }
76
77 static void local_rm9k_perfcounter_irq_shutdown(void *args)
78 {
79         unsigned int irq = (unsigned int) args;
80         unsigned long flags;
81
82         local_irq_save(flags);
83         mask_rm9k_irq(irq);
84         local_irq_restore(flags);
85 }
86
87 static void rm9k_perfcounter_irq_shutdown(unsigned int irq)
88 {
89         on_each_cpu(local_rm9k_perfcounter_irq_shutdown, (void *) irq, 0, 1);
90 }
91
92
93 /*
94  * While we ack the interrupt interrupts are disabled and thus we don't need
95  * to deal with concurrency issues.  Same for rm9k_cpu_irq_end.
96  */
97 static void rm9k_cpu_irq_ack(unsigned int irq)
98 {
99         mask_rm9k_irq(irq);
100 }
101
102 static void rm9k_cpu_irq_end(unsigned int irq)
103 {
104         if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
105                 unmask_rm9k_irq(irq);
106 }
107
108 static struct irq_chip rm9k_irq_controller = {
109         .typename = "RM9000",
110         .startup = rm9k_cpu_irq_startup,
111         .shutdown = rm9k_cpu_irq_shutdown,
112         .enable = rm9k_cpu_irq_enable,
113         .disable = rm9k_cpu_irq_disable,
114         .ack = rm9k_cpu_irq_ack,
115         .end = rm9k_cpu_irq_end,
116 };
117
118 static struct irq_chip rm9k_perfcounter_irq = {
119         .typename = "RM9000",
120         .startup = rm9k_perfcounter_irq_startup,
121         .shutdown = rm9k_perfcounter_irq_shutdown,
122         .enable = rm9k_cpu_irq_enable,
123         .disable = rm9k_cpu_irq_disable,
124         .ack = rm9k_cpu_irq_ack,
125         .end = rm9k_cpu_irq_end,
126 };
127
128 unsigned int rm9000_perfcount_irq;
129
130 EXPORT_SYMBOL(rm9000_perfcount_irq);
131
132 void __init rm9k_cpu_irq_init(int base)
133 {
134         int i;
135
136         clear_c0_intcontrol(0x0000f000);                /* Mask all */
137
138         for (i = base; i < base + 4; i++) {
139                 irq_desc[i].status = IRQ_DISABLED;
140                 irq_desc[i].action = NULL;
141                 irq_desc[i].depth = 1;
142                 irq_desc[i].chip = &rm9k_irq_controller;
143         }
144
145         rm9000_perfcount_irq = base + 1;
146         irq_desc[rm9000_perfcount_irq].chip = &rm9k_perfcounter_irq;
147
148         irq_base = base;
149 }