http://www.hht-eu.com/pls/hht/docs/F3140/bcm963xx_Speedport500V.0.09.04L.300L01.V27_c...
[bcm963xx.git] / kernel / linux / arch / m68k / hp300 / ints.c
1 /*
2  *  linux/arch/m68k/hp300/ints.c
3  *
4  *  Copyright (C) 1998 Philip Blundell <philb@gnu.org>
5  *
6  *  This file contains the HP300-specific interrupt handling.
7  *  We only use the autovector interrupts, and therefore we need to
8  *  maintain lists of devices sharing each ipl.
9  *  [ipl list code added by Peter Maydell <pmaydell@chiark.greenend.org.uk> 06/1998]
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/init.h>
15 #include <linux/sched.h>
16 #include <linux/kernel_stat.h>
17 #include <linux/interrupt.h>
18 #include <linux/spinlock.h>
19 #include <asm/machdep.h>
20 #include <asm/irq.h>
21 #include <asm/io.h>
22 #include <asm/system.h>
23 #include <asm/traps.h>
24 #include <asm/ptrace.h>
25 #include <asm/errno.h>
26 #include "ints.h"
27
28 /* Each ipl has a linked list of interrupt service routines.
29  * Service routines are added via hp300_request_irq() and removed
30  * via hp300_free_irq(). The device driver should set IRQ_FLG_FAST
31  * if it needs to be serviced early (eg FIFOless UARTs); this will
32  * cause it to be added at the front of the queue rather than
33  * the back.
34  * Currently IRQ_FLG_SLOW and flags=0 are treated identically; if
35  * we needed three levels of priority we could distinguish them
36  * but this strikes me as mildly ugly...
37  */
38
39 /* we start with no entries in any list */
40 static irq_node_t *hp300_irq_list[HP300_NUM_IRQS];
41
42 static spinlock_t irqlist_lock;
43
44 /* This handler receives all interrupts, dispatching them to the registered handlers */
45 static irqreturn_t hp300_int_handler(int irq, void *dev_id, struct pt_regs *fp)
46 {
47         irq_node_t *t;
48         /* We just give every handler on the chain an opportunity to handle
49          * the interrupt, in priority order.
50          */
51         for(t = hp300_irq_list[irq]; t; t=t->next)
52                 t->handler(irq, t->dev_id, fp);
53         /* We could put in some accounting routines, checks for stray interrupts,
54          * etc, in here. Note that currently we can't tell whether or not
55          * a handler handles the interrupt, though.
56          */
57         return IRQ_HANDLED;
58 }
59
60 irqreturn_t (*hp300_default_handler[SYS_IRQS])(int, void *, struct pt_regs *) = {
61         [0] = hp300_int_handler,
62         [1] = hp300_int_handler,
63         [2] = hp300_int_handler,
64         [3] = hp300_int_handler,
65         [4] = hp300_int_handler,
66         [5] = hp300_int_handler,
67         [6] = hp300_int_handler,
68 };
69
70 /* dev_id had better be unique to each handler because it's the only way we have
71  * to distinguish handlers when removing them...
72  *
73  * It would be pretty easy to support IRQ_FLG_LOCK (handler is not replacable)
74  * and IRQ_FLG_REPLACE (handler replaces existing one with this dev_id)
75  * if we wanted to. IRQ_FLG_FAST is needed for devices where interrupt latency
76  * matters (eg the dreaded FIFOless UART...)
77  */
78 int hp300_request_irq(unsigned int irq,
79                       irqreturn_t (*handler) (int, void *, struct pt_regs *),
80                       unsigned long flags, const char *devname, void *dev_id)
81 {
82         irq_node_t *t, *n = new_irq_node();
83
84         if (!n)                                   /* oops, no free nodes */
85                 return -ENOMEM;
86
87         spin_lock_irqsave(&irqlist_lock, flags);
88
89         if (!hp300_irq_list[irq]) {
90                 /* no list yet */
91                 hp300_irq_list[irq] = n;
92                 n->next = NULL;
93         } else if (flags & IRQ_FLG_FAST) {
94                 /* insert at head of list */
95                 n->next = hp300_irq_list[irq];
96                 hp300_irq_list[irq] = n;
97         } else {
98                 /* insert at end of list */
99                 for(t = hp300_irq_list[irq]; t->next; t = t->next)
100                         /* do nothing */;
101                 n->next = NULL;
102                 t->next = n;
103         }
104
105         /* Fill in n appropriately */
106         n->handler = handler;
107         n->flags = flags;
108         n->dev_id = dev_id;
109         n->devname = devname;
110         spin_unlock_irqrestore(&irqlist_lock, flags);
111         return 0;
112 }
113
114 void hp300_free_irq(unsigned int irq, void *dev_id)
115 {
116         irq_node_t *t;
117         unsigned long flags;
118
119         spin_lock_irqsave(&irqlist_lock, flags);
120
121         t = hp300_irq_list[irq];
122         if (!t)                                   /* no handlers at all for that IRQ */
123         {
124                 printk(KERN_ERR "hp300_free_irq: attempt to remove nonexistent handler for IRQ %d\n", irq);
125                 spin_unlock_irqrestore(&irqlist_lock, flags);
126                 return;
127         }
128
129         if (t->dev_id == dev_id)
130         {                                         /* removing first handler on chain */
131                 t->flags = IRQ_FLG_STD;           /* we probably don't really need these */
132                 t->dev_id = NULL;
133                 t->devname = NULL;
134                 t->handler = NULL;                /* frees this irq_node_t */
135                 hp300_irq_list[irq] = t->next;
136                 spin_unlock_irqrestore(&irqlist_lock, flags);
137                 return;
138         }
139
140         /* OK, must be removing from middle of the chain */
141
142         for (t = hp300_irq_list[irq]; t->next && t->next->dev_id != dev_id; t = t->next)
143                 /* do nothing */;
144         if (!t->next)
145         {
146                 printk(KERN_ERR "hp300_free_irq: attempt to remove nonexistent handler for IRQ %d\n", irq);
147                 spin_unlock_irqrestore(&irqlist_lock, flags);
148                 return;
149         }
150         /* remove the entry after t: */
151         t->next->flags = IRQ_FLG_STD;
152         t->next->dev_id = NULL;
153         t->next->devname = NULL;
154         t->next->handler = NULL;
155         t->next = t->next->next;
156
157         spin_unlock_irqrestore(&irqlist_lock, flags);
158 }
159
160 int show_hp300_interrupts(struct seq_file *p, void *v)
161 {
162         return 0;
163 }
164
165 void __init hp300_init_IRQ(void)
166 {
167         spin_lock_init(&irqlist_lock);
168 }