~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/m68k/amiga/amiints.c

Version: ~ [ linux-5.2-rc1 ] ~ [ linux-5.1.2 ] ~ [ linux-5.0.16 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.43 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.119 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.176 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.179 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.139 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.67 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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/types.h>
 39 #include <linux/kernel.h>
 40 #include <linux/sched.h>
 41 #include <linux/kernel_stat.h>
 42 #include <linux/init.h>
 43 #include <linux/errno.h>
 44 #include <linux/seq_file.h>
 45 
 46 #include <asm/system.h>
 47 #include <asm/irq.h>
 48 #include <asm/traps.h>
 49 #include <asm/amigahw.h>
 50 #include <asm/amigaints.h>
 51 #include <asm/amipcmcia.h>
 52 
 53 extern int cia_request_irq(struct ciabase *base,int irq,
 54                            irqreturn_t (*handler)(int, void *, struct pt_regs *),
 55                            unsigned long flags, const char *devname, void *dev_id);
 56 extern void cia_free_irq(struct ciabase *base, unsigned int irq, void *dev_id);
 57 extern void cia_init_IRQ(struct ciabase *base);
 58 extern int cia_get_irq_list(struct ciabase *base, struct seq_file *p);
 59 
 60 /* irq node variables for amiga interrupt sources */
 61 static irq_node_t *ami_irq_list[AMI_STD_IRQS];
 62 
 63 static unsigned short amiga_intena_vals[AMI_STD_IRQS] = {
 64         IF_VERTB, IF_COPER, IF_AUD0, IF_AUD1, IF_AUD2, IF_AUD3, IF_BLIT,
 65         IF_DSKSYN, IF_DSKBLK, IF_RBF, IF_TBE, IF_SOFT, IF_PORTS, IF_EXTER
 66 };
 67 static const unsigned char ami_servers[AMI_STD_IRQS] = {
 68         1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1
 69 };
 70 
 71 static short ami_ablecount[AMI_IRQS];
 72 
 73 static irqreturn_t ami_badint(int irq, void *dev_id, struct pt_regs *fp)
 74 {
 75         num_spurious += 1;
 76         return IRQ_NONE;
 77 }
 78 
 79 /*
 80  * void amiga_init_IRQ(void)
 81  *
 82  * Parameters:  None
 83  *
 84  * Returns:     Nothing
 85  *
 86  * This function should be called during kernel startup to initialize
 87  * the amiga IRQ handling routines.
 88  */
 89 
 90 void __init amiga_init_IRQ(void)
 91 {
 92         int i;
 93 
 94         /* initialize handlers */
 95         for (i = 0; i < AMI_STD_IRQS; i++) {
 96                 if (ami_servers[i]) {
 97                         ami_irq_list[i] = NULL;
 98                 } else {
 99                         ami_irq_list[i] = new_irq_node();
100                         ami_irq_list[i]->handler = ami_badint;
101                         ami_irq_list[i]->flags   = 0;
102                         ami_irq_list[i]->dev_id  = NULL;
103                         ami_irq_list[i]->devname = NULL;
104                         ami_irq_list[i]->next    = NULL;
105                 }
106         }
107         for (i = 0; i < AMI_IRQS; i++)
108                 ami_ablecount[i] = 0;
109 
110         /* turn off PCMCIA interrupts */
111         if (AMIGAHW_PRESENT(PCMCIA))
112                 gayle.inten = GAYLE_IRQ_IDE;
113 
114         /* turn off all interrupts and enable the master interrupt bit */
115         custom.intena = 0x7fff;
116         custom.intreq = 0x7fff;
117         custom.intena = IF_SETCLR | IF_INTEN;
118 
119         cia_init_IRQ(&ciaa_base);
120         cia_init_IRQ(&ciab_base);
121 }
122 
123 static inline int amiga_insert_irq(irq_node_t **list, irq_node_t *node)
124 {
125         unsigned long flags;
126         irq_node_t *cur;
127 
128         if (!node->dev_id)
129                 printk("%s: Warning: dev_id of %s is zero\n",
130                        __FUNCTION__, node->devname);
131 
132         local_irq_save(flags);
133 
134         cur = *list;
135 
136         if (node->flags & SA_INTERRUPT) {
137                 if (node->flags & SA_SHIRQ)
138                         return -EBUSY;
139                 /*
140                  * There should never be more than one
141                  */
142                 while (cur && cur->flags & SA_INTERRUPT) {
143                         list = &cur->next;
144                         cur = cur->next;
145                 }
146         } else {
147                 while (cur) {
148                         list = &cur->next;
149                         cur = cur->next;
150                 }
151         }
152 
153         node->next = cur;
154         *list = node;
155 
156         local_irq_restore(flags);
157         return 0;
158 }
159 
160 static inline void amiga_delete_irq(irq_node_t **list, void *dev_id)
161 {
162         unsigned long flags;
163         irq_node_t *node;
164 
165         local_irq_save(flags);
166 
167         for (node = *list; node; list = &node->next, node = *list) {
168                 if (node->dev_id == dev_id) {
169                         *list = node->next;
170                         /* Mark it as free. */
171                         node->handler = NULL;
172                         local_irq_restore(flags);
173                         return;
174                 }
175         }
176         local_irq_restore(flags);
177         printk ("%s: tried to remove invalid irq\n", __FUNCTION__);
178 }
179 
180 /*
181  * amiga_request_irq : add an interrupt service routine for a particular
182  *                     machine specific interrupt source.
183  *                     If the addition was successful, it returns 0.
184  */
185 
186 int amiga_request_irq(unsigned int irq,
187                       irqreturn_t (*handler)(int, void *, struct pt_regs *),
188                       unsigned long flags, const char *devname, void *dev_id)
189 {
190         irq_node_t *node;
191         int error = 0;
192 
193         if (irq >= AMI_IRQS) {
194                 printk ("%s: Unknown IRQ %d from %s\n", __FUNCTION__,
195                         irq, devname);
196                 return -ENXIO;
197         }
198 
199         if (irq >= IRQ_AMIGA_AUTO)
200                 return sys_request_irq(irq - IRQ_AMIGA_AUTO, handler,
201                                        flags, devname, dev_id);
202 
203         if (irq >= IRQ_AMIGA_CIAB)
204                 return cia_request_irq(&ciab_base, irq - IRQ_AMIGA_CIAB,
205                                        handler, flags, devname, dev_id);
206 
207         if (irq >= IRQ_AMIGA_CIAA)
208                 return cia_request_irq(&ciaa_base, irq - IRQ_AMIGA_CIAA,
209                                        handler, flags, devname, dev_id);
210 
211         /*
212          * IRQ_AMIGA_PORTS & IRQ_AMIGA_EXTER defaults to shared,
213          * we could add a check here for the SA_SHIRQ flag but all drivers
214          * should be aware of sharing anyway.
215          */
216         if (ami_servers[irq]) {
217                 if (!(node = new_irq_node()))
218                         return -ENOMEM;
219                 node->handler = handler;
220                 node->flags   = flags;
221                 node->dev_id  = dev_id;
222                 node->devname = devname;
223                 node->next    = NULL;
224                 error = amiga_insert_irq(&ami_irq_list[irq], node);
225         } else {
226                 ami_irq_list[irq]->handler = handler;
227                 ami_irq_list[irq]->flags   = flags;
228                 ami_irq_list[irq]->dev_id  = dev_id;
229                 ami_irq_list[irq]->devname = devname;
230         }
231 
232         /* enable the interrupt */
233         if (irq < IRQ_AMIGA_PORTS && !ami_ablecount[irq])
234                 custom.intena = IF_SETCLR | amiga_intena_vals[irq];
235 
236         return error;
237 }
238 
239 void amiga_free_irq(unsigned int irq, void *dev_id)
240 {
241         if (irq >= AMI_IRQS) {
242                 printk ("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
243                 return;
244         }
245 
246         if (irq >= IRQ_AMIGA_AUTO)
247                 sys_free_irq(irq - IRQ_AMIGA_AUTO, dev_id);
248 
249         if (irq >= IRQ_AMIGA_CIAB) {
250                 cia_free_irq(&ciab_base, irq - IRQ_AMIGA_CIAB, dev_id);
251                 return;
252         }
253 
254         if (irq >= IRQ_AMIGA_CIAA) {
255                 cia_free_irq(&ciaa_base, irq - IRQ_AMIGA_CIAA, dev_id);
256                 return;
257         }
258 
259         if (ami_servers[irq]) {
260                 amiga_delete_irq(&ami_irq_list[irq], dev_id);
261                 /* if server list empty, disable the interrupt */
262                 if (!ami_irq_list[irq] && irq < IRQ_AMIGA_PORTS)
263                         custom.intena = amiga_intena_vals[irq];
264         } else {
265                 if (ami_irq_list[irq]->dev_id != dev_id)
266                         printk("%s: removing probably wrong IRQ %d from %s\n",
267                                __FUNCTION__, irq, ami_irq_list[irq]->devname);
268                 ami_irq_list[irq]->handler = ami_badint;
269                 ami_irq_list[irq]->flags   = 0;
270                 ami_irq_list[irq]->dev_id  = NULL;
271                 ami_irq_list[irq]->devname = NULL;
272                 custom.intena = amiga_intena_vals[irq];
273         }
274 }
275 
276 /*
277  * Enable/disable a particular machine specific interrupt source.
278  * Note that this may affect other interrupts in case of a shared interrupt.
279  * This function should only be called for a _very_ short time to change some
280  * internal data, that may not be changed by the interrupt at the same time.
281  * ami_(enable|disable)_irq calls may also be nested.
282  */
283 
284 void amiga_enable_irq(unsigned int irq)
285 {
286         if (irq >= AMI_IRQS) {
287                 printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
288                 return;
289         }
290 
291         if (--ami_ablecount[irq])
292                 return;
293 
294         /* No action for auto-vector interrupts */
295         if (irq >= IRQ_AMIGA_AUTO){
296                 printk("%s: Trying to enable auto-vector IRQ %i\n",
297                        __FUNCTION__, irq - IRQ_AMIGA_AUTO);
298                 return;
299         }
300 
301         if (irq >= IRQ_AMIGA_CIAB) {
302                 cia_set_irq(&ciab_base, (1 << (irq - IRQ_AMIGA_CIAB)));
303                 cia_able_irq(&ciab_base, CIA_ICR_SETCLR |
304                              (1 << (irq - IRQ_AMIGA_CIAB)));
305                 return;
306         }
307 
308         if (irq >= IRQ_AMIGA_CIAA) {
309                 cia_set_irq(&ciaa_base, (1 << (irq - IRQ_AMIGA_CIAA)));
310                 cia_able_irq(&ciaa_base, CIA_ICR_SETCLR |
311                              (1 << (irq - IRQ_AMIGA_CIAA)));
312                 return;
313         }
314 
315         /* enable the interrupt */
316         custom.intena = IF_SETCLR | amiga_intena_vals[irq];
317 }
318 
319 void amiga_disable_irq(unsigned int irq)
320 {
321         if (irq >= AMI_IRQS) {
322                 printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
323                 return;
324         }
325 
326         if (ami_ablecount[irq]++)
327                 return;
328 
329         /* No action for auto-vector interrupts */
330         if (irq >= IRQ_AMIGA_AUTO) {
331                 printk("%s: Trying to disable auto-vector IRQ %i\n",
332                        __FUNCTION__, irq - IRQ_AMIGA_AUTO);
333                 return;
334         }
335 
336         if (irq >= IRQ_AMIGA_CIAB) {
337                 cia_able_irq(&ciab_base, 1 << (irq - IRQ_AMIGA_CIAB));
338                 return;
339         }
340 
341         if (irq >= IRQ_AMIGA_CIAA) {
342                 cia_able_irq(&ciaa_base, 1 << (irq - IRQ_AMIGA_CIAA));
343                 return;
344         }
345 
346         /* disable the interrupt */
347         custom.intena = amiga_intena_vals[irq];
348 }
349 
350 inline void amiga_do_irq(int irq, struct pt_regs *fp)
351 {
352         kstat_cpu(0).irqs[SYS_IRQS + irq]++;
353         ami_irq_list[irq]->handler(irq, ami_irq_list[irq]->dev_id, fp);
354 }
355 
356 void amiga_do_irq_list(int irq, struct pt_regs *fp)
357 {
358         irq_node_t *node;
359 
360         kstat_cpu(0).irqs[SYS_IRQS + irq]++;
361 
362         custom.intreq = amiga_intena_vals[irq];
363 
364         for (node = ami_irq_list[irq]; node; node = node->next)
365                 node->handler(irq, node->dev_id, fp);
366 }
367 
368 /*
369  * The builtin Amiga hardware interrupt handlers.
370  */
371 
372 static irqreturn_t ami_int1(int irq, void *dev_id, struct pt_regs *fp)
373 {
374         unsigned short ints = custom.intreqr & custom.intenar;
375 
376         /* if serial transmit buffer empty, interrupt */
377         if (ints & IF_TBE) {
378                 custom.intreq = IF_TBE;
379                 amiga_do_irq(IRQ_AMIGA_TBE, fp);
380         }
381 
382         /* if floppy disk transfer complete, interrupt */
383         if (ints & IF_DSKBLK) {
384                 custom.intreq = IF_DSKBLK;
385                 amiga_do_irq(IRQ_AMIGA_DSKBLK, fp);
386         }
387 
388         /* if software interrupt set, interrupt */
389         if (ints & IF_SOFT) {
390                 custom.intreq = IF_SOFT;
391                 amiga_do_irq(IRQ_AMIGA_SOFT, fp);
392         }
393         return IRQ_HANDLED;
394 }
395 
396 static irqreturn_t ami_int3(int irq, void *dev_id, struct pt_regs *fp)
397 {
398         unsigned short ints = custom.intreqr & custom.intenar;
399 
400         /* if a blitter interrupt */
401         if (ints & IF_BLIT) {
402                 custom.intreq = IF_BLIT;
403                 amiga_do_irq(IRQ_AMIGA_BLIT, fp);
404         }
405 
406         /* if a copper interrupt */
407         if (ints & IF_COPER) {
408                 custom.intreq = IF_COPER;
409                 amiga_do_irq(IRQ_AMIGA_COPPER, fp);
410         }
411 
412         /* if a vertical blank interrupt */
413         if (ints & IF_VERTB)
414                 amiga_do_irq_list(IRQ_AMIGA_VERTB, fp);
415         return IRQ_HANDLED;
416 }
417 
418 static irqreturn_t ami_int4(int irq, void *dev_id, struct pt_regs *fp)
419 {
420         unsigned short ints = custom.intreqr & custom.intenar;
421 
422         /* if audio 0 interrupt */
423         if (ints & IF_AUD0) {
424                 custom.intreq = IF_AUD0;
425                 amiga_do_irq(IRQ_AMIGA_AUD0, fp);
426         }
427 
428         /* if audio 1 interrupt */
429         if (ints & IF_AUD1) {
430                 custom.intreq = IF_AUD1;
431                 amiga_do_irq(IRQ_AMIGA_AUD1, fp);
432         }
433 
434         /* if audio 2 interrupt */
435         if (ints & IF_AUD2) {
436                 custom.intreq = IF_AUD2;
437                 amiga_do_irq(IRQ_AMIGA_AUD2, fp);
438         }
439 
440         /* if audio 3 interrupt */
441         if (ints & IF_AUD3) {
442                 custom.intreq = IF_AUD3;
443                 amiga_do_irq(IRQ_AMIGA_AUD3, fp);
444         }
445         return IRQ_HANDLED;
446 }
447 
448 static irqreturn_t ami_int5(int irq, void *dev_id, struct pt_regs *fp)
449 {
450         unsigned short ints = custom.intreqr & custom.intenar;
451 
452         /* if serial receive buffer full interrupt */
453         if (ints & IF_RBF) {
454                 /* acknowledge of IF_RBF must be done by the serial interrupt */
455                 amiga_do_irq(IRQ_AMIGA_RBF, fp);
456         }
457 
458         /* if a disk sync interrupt */
459         if (ints & IF_DSKSYN) {
460                 custom.intreq = IF_DSKSYN;
461                 amiga_do_irq(IRQ_AMIGA_DSKSYN, fp);
462         }
463         return IRQ_HANDLED;
464 }
465 
466 static irqreturn_t ami_int7(int irq, void *dev_id, struct pt_regs *fp)
467 {
468         panic ("level 7 interrupt received\n");
469 }
470 
471 irqreturn_t (*amiga_default_handler[SYS_IRQS])(int, void *, struct pt_regs *) = {
472         ami_badint, ami_int1, ami_badint, ami_int3,
473         ami_int4, ami_int5, ami_badint, ami_int7
474 };
475 
476 int show_amiga_interrupts(struct seq_file *p, void *v)
477 {
478         int i;
479         irq_node_t *node;
480 
481         for (i = 0; i < AMI_STD_IRQS; i++) {
482                 if (!(node = ami_irq_list[i]))
483                         continue;
484                 seq_printf(p, "ami  %2d: %10u ", i,
485                                kstat_cpu(0).irqs[SYS_IRQS + i]);
486                 do {
487                         if (node->flags & SA_INTERRUPT)
488                                 seq_puts(p, "F ");
489                         else
490                                 seq_puts(p, "  ");
491                         seq_printf(p, "%s\n", node->devname);
492                         if ((node = node->next))
493                                 seq_puts(p, "                    ");
494                 } while (node);
495         }
496 
497         cia_get_irq_list(&ciaa_base, p);
498         cia_get_irq_list(&ciab_base, p);
499         return 0;
500 }
501 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp