1 /*
2 * linux/arch/m68k/amiga/amiints.c -- Amiga Linux interrupt handling code
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive
6 * for more details.
7 *
8 * 11/07/96: rewritten interrupt handling, irq lists are exists now only for
9 * this sources where it makes sense (VERTB/PORTS/EXTER) and you must
10 * be careful that dev_id for this sources is unique since this the
11 * only possibility to distinguish between different handlers for
12 * free_irq. irq lists also have different irq flags:
13 * - IRQ_FLG_FAST: handler is inserted at top of list (after other
14 * fast handlers)
15 * - IRQ_FLG_SLOW: handler is inserted at bottom of list and before
16 * they're executed irq level is set to the previous
17 * one, but handlers don't need to be reentrant, if
18 * reentrance occurred, slow handlers will be just
19 * called again.
20 * The whole interrupt handling for CIAs is moved to cia.c
21 * /Roman Zippel
22 *
23 * 07/08/99: rewamp of the interrupt handling - we now have two types of
24 * interrupts, normal and fast handlers, fast handlers being
25 * marked with SA_INTERRUPT and runs with all other interrupts
26 * disabled. Normal interrupts disable their own source but
27 * run with all other interrupt sources enabled.
28 * PORTS and EXTER interrupts are always shared even if the
29 * drivers do not explicitly mark this when calling
30 * request_irq which they really should do.
31 * This is similar to the way interrupts are handled on all
32 * other architectures and makes a ton of sense besides
33 * having the advantage of making it easier to share
34 * drivers.
35 * /Jes
36 */
37
38 #include <linux/config.h>
39 #include <linux/types.h>
40 #include <linux/kernel.h>
41 #include <linux/sched.h>
42 #include <linux/interrupt.h>
43 #include <linux/irq.h>
44 #include <linux/kernel_stat.h>
45 #include <linux/init.h>
46
47 #include <asm/system.h>
48 #include <asm/irq.h>
49 #include <asm/traps.h>
50 #include <asm/amigahw.h>
51 #include <asm/amigaints.h>
52 #include <asm/amipcmcia.h>
53
54 #ifdef CONFIG_APUS
55 #include <asm/amigappc.h>
56 #endif
57
58 extern int cia_request_irq(int irq,
59 void (*handler)(int, void *, struct pt_regs *),
60 unsigned long flags, const char *devname, void *dev_id);
61 extern void cia_free_irq(unsigned int irq, void *dev_id);
62 extern void cia_init_IRQ(struct ciabase *base);
63 extern int cia_get_irq_list(struct ciabase *base, char *buf);
64
65 unsigned short ami_intena_vals[AMI_STD_IRQS] = {
66 IF_VERTB, IF_COPER, IF_AUD0, IF_AUD1, IF_AUD2, IF_AUD3, IF_BLIT,
67 IF_DSKSYN, IF_DSKBLK, IF_RBF, IF_TBE, IF_SOFT, IF_PORTS, IF_EXTER
68 };
69 static const unsigned char ami_servers[AMI_STD_IRQS] = {
70 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
71 };
72
73 static short ami_ablecount[AMI_IRQS];
74
ami_badint(int irq,void * dev_id,struct pt_regs * fp)75 static void ami_badint(int irq, void *dev_id, struct pt_regs *fp)
76 {
77 /* num_spurious += 1;*/
78 }
79
80 /*
81 * void amiga_init_IRQ(void)
82 *
83 * Parameters: None
84 *
85 * Returns: Nothing
86 *
87 * This function should be called during kernel startup to initialize
88 * the amiga IRQ handling routines.
89 */
90
91 __init
amiga_init_IRQ(void)92 void amiga_init_IRQ(void)
93 {
94 int i;
95
96 for (i = 0; i < AMI_IRQS; i++)
97 ami_ablecount[i] = 0;
98
99 /* turn off PCMCIA interrupts */
100 if (AMIGAHW_PRESENT(PCMCIA))
101 gayle.inten = GAYLE_IRQ_IDE;
102
103 /* turn off all interrupts... */
104 custom.intena = 0x7fff;
105 custom.intreq = 0x7fff;
106
107 #ifdef CONFIG_APUS
108 /* Clear any inter-CPU interrupt requests. Circumvents bug in
109 Blizzard IPL emulation HW (or so it appears). */
110 APUS_WRITE(APUS_INT_LVL, INTLVL_SETRESET | INTLVL_MASK);
111
112 /* Init IPL emulation. */
113 APUS_WRITE(APUS_REG_INT, REGINT_INTMASTER | REGINT_ENABLEIPL);
114 APUS_WRITE(APUS_IPL_EMU, IPLEMU_DISABLEINT);
115 APUS_WRITE(APUS_IPL_EMU, IPLEMU_SETRESET | IPLEMU_IPLMASK);
116 #endif
117 /* ... and enable the master interrupt bit */
118 custom.intena = IF_SETCLR | IF_INTEN;
119
120 cia_init_IRQ(&ciaa_base);
121 cia_init_IRQ(&ciab_base);
122 }
123
124 /*
125 * Enable/disable a particular machine specific interrupt source.
126 * Note that this may affect other interrupts in case of a shared interrupt.
127 * This function should only be called for a _very_ short time to change some
128 * internal data, that may not be changed by the interrupt at the same time.
129 * ami_(enable|disable)_irq calls may also be nested.
130 */
131
amiga_enable_irq(unsigned int irq)132 void amiga_enable_irq(unsigned int irq)
133 {
134 if (irq >= AMI_IRQS) {
135 printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
136 return;
137 }
138
139 ami_ablecount[irq]--;
140 if (ami_ablecount[irq]<0)
141 ami_ablecount[irq]=0;
142 else if (ami_ablecount[irq])
143 return;
144
145 /* No action for auto-vector interrupts */
146 if (irq >= IRQ_AMIGA_AUTO){
147 printk("%s: Trying to enable auto-vector IRQ %i\n",
148 __FUNCTION__, irq - IRQ_AMIGA_AUTO);
149 return;
150 }
151
152 if (irq >= IRQ_AMIGA_CIAA) {
153 cia_set_irq(irq, 0);
154 cia_able_irq(irq, 1);
155 return;
156 }
157
158 /* enable the interrupt */
159 custom.intena = IF_SETCLR | ami_intena_vals[irq];
160 }
161
amiga_disable_irq(unsigned int irq)162 void amiga_disable_irq(unsigned int irq)
163 {
164 if (irq >= AMI_IRQS) {
165 printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
166 return;
167 }
168
169 if (ami_ablecount[irq]++)
170 return;
171
172 /* No action for auto-vector interrupts */
173 if (irq >= IRQ_AMIGA_AUTO) {
174 printk("%s: Trying to disable auto-vector IRQ %i\n",
175 __FUNCTION__, irq - IRQ_AMIGA_AUTO);
176 return;
177 }
178
179 if (irq >= IRQ_AMIGA_CIAA) {
180 cia_able_irq(irq, 0);
181 return;
182 }
183
184 /* disable the interrupt */
185 custom.intena = ami_intena_vals[irq];
186 }
187
amiga_do_irq(int irq,struct pt_regs * fp)188 inline void amiga_do_irq(int irq, struct pt_regs *fp)
189 {
190 irq_desc_t *desc = irq_desc + irq;
191 struct irqaction *action = desc->action;
192
193 kstat.irqs[0][irq]++;
194 action->handler(irq, action->dev_id, fp);
195 }
196
amiga_do_irq_list(int irq,struct pt_regs * fp)197 void amiga_do_irq_list(int irq, struct pt_regs *fp)
198 {
199 irq_desc_t *desc = irq_desc + irq;
200 struct irqaction *action;
201
202 kstat.irqs[0][irq]++;
203
204 custom.intreq = ami_intena_vals[irq];
205
206 for (action = desc->action; action; action = action->next)
207 action->handler(irq, action->dev_id, fp);
208 }
209
210 /*
211 * The builtin Amiga hardware interrupt handlers.
212 */
213
ami_int1(int irq,void * dev_id,struct pt_regs * fp)214 static void ami_int1(int irq, void *dev_id, struct pt_regs *fp)
215 {
216 unsigned short ints = custom.intreqr & custom.intenar;
217
218 /* if serial transmit buffer empty, interrupt */
219 if (ints & IF_TBE) {
220 custom.intreq = IF_TBE;
221 amiga_do_irq(IRQ_AMIGA_TBE, fp);
222 }
223
224 /* if floppy disk transfer complete, interrupt */
225 if (ints & IF_DSKBLK) {
226 custom.intreq = IF_DSKBLK;
227 amiga_do_irq(IRQ_AMIGA_DSKBLK, fp);
228 }
229
230 /* if software interrupt set, interrupt */
231 if (ints & IF_SOFT) {
232 custom.intreq = IF_SOFT;
233 amiga_do_irq(IRQ_AMIGA_SOFT, fp);
234 }
235 }
236
ami_int3(int irq,void * dev_id,struct pt_regs * fp)237 static void ami_int3(int irq, void *dev_id, struct pt_regs *fp)
238 {
239 unsigned short ints = custom.intreqr & custom.intenar;
240
241 /* if a blitter interrupt */
242 if (ints & IF_BLIT) {
243 custom.intreq = IF_BLIT;
244 amiga_do_irq(IRQ_AMIGA_BLIT, fp);
245 }
246
247 /* if a copper interrupt */
248 if (ints & IF_COPER) {
249 custom.intreq = IF_COPER;
250 amiga_do_irq(IRQ_AMIGA_COPPER, fp);
251 }
252
253 /* if a vertical blank interrupt */
254 if (ints & IF_VERTB)
255 amiga_do_irq_list(IRQ_AMIGA_VERTB, fp);
256 }
257
ami_int4(int irq,void * dev_id,struct pt_regs * fp)258 static void ami_int4(int irq, void *dev_id, struct pt_regs *fp)
259 {
260 unsigned short ints = custom.intreqr & custom.intenar;
261
262 /* if audio 0 interrupt */
263 if (ints & IF_AUD0) {
264 custom.intreq = IF_AUD0;
265 amiga_do_irq(IRQ_AMIGA_AUD0, fp);
266 }
267
268 /* if audio 1 interrupt */
269 if (ints & IF_AUD1) {
270 custom.intreq = IF_AUD1;
271 amiga_do_irq(IRQ_AMIGA_AUD1, fp);
272 }
273
274 /* if audio 2 interrupt */
275 if (ints & IF_AUD2) {
276 custom.intreq = IF_AUD2;
277 amiga_do_irq(IRQ_AMIGA_AUD2, fp);
278 }
279
280 /* if audio 3 interrupt */
281 if (ints & IF_AUD3) {
282 custom.intreq = IF_AUD3;
283 amiga_do_irq(IRQ_AMIGA_AUD3, fp);
284 }
285 }
286
ami_int5(int irq,void * dev_id,struct pt_regs * fp)287 static void ami_int5(int irq, void *dev_id, struct pt_regs *fp)
288 {
289 unsigned short ints = custom.intreqr & custom.intenar;
290
291 /* if serial receive buffer full interrupt */
292 if (ints & IF_RBF) {
293 /* acknowledge of IF_RBF must be done by the serial interrupt */
294 amiga_do_irq(IRQ_AMIGA_RBF, fp);
295 }
296
297 /* if a disk sync interrupt */
298 if (ints & IF_DSKSYN) {
299 custom.intreq = IF_DSKSYN;
300 amiga_do_irq(IRQ_AMIGA_DSKSYN, fp);
301 }
302 }
303
ami_int7(int irq,void * dev_id,struct pt_regs * fp)304 static void ami_int7(int irq, void *dev_id, struct pt_regs *fp)
305 {
306 panic ("level 7 interrupt received\n");
307 }
308
309 #ifdef CONFIG_APUS
310 /* The PPC irq handling links all handlers requested on the same vector
311 and executes them in a loop. Having ami_badint at the end of the chain
312 is a bad idea. */
313 struct irqaction amiga_sys_irqaction[AUTO_IRQS] = {
314 { handler: ami_badint, name: "spurious int" },
315 { handler: ami_int1, name: "int1 handler" },
316 { 0, /* CIAA */ },
317 { handler: ami_int3, name: "int3 handler" },
318 { handler: ami_int4, name: "int4 handler" },
319 { handler: ami_int5, name: "int5 handler" },
320 { 0, /* CIAB */ },
321 { handler: ami_int7, name: "int7 handler" },
322 };
323 #else
324 void (*amiga_default_handler[SYS_IRQS])(int, void *, struct pt_regs *) = {
325 ami_badint, ami_int1, ami_badint, ami_int3,
326 ami_int4, ami_int5, ami_badint, ami_int7
327 };
328 #endif
329