Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/cpufreq
[sfrench/cifs-2.6.git] / arch / ppc / amiga / ints.c
1 /*
2  *  Linux/m68k general interrupt handling code from arch/m68k/kernel/ints.c
3  *  Needed to drive the m68k emulating IRQ hardware on the PowerUp boards.
4  */
5
6 #include <linux/types.h>
7 #include <linux/sched.h>
8 #include <linux/kernel_stat.h>
9 #include <linux/errno.h>
10 #include <linux/init.h>
11 #include <linux/seq_file.h>
12
13 #include <asm/setup.h>
14 #include <asm/system.h>
15 #include <asm/irq.h>
16 #include <asm/traps.h>
17 #include <asm/page.h>
18 #include <asm/machdep.h>
19
20 /* table for system interrupt handlers */
21 static irq_handler_t irq_list[SYS_IRQS];
22
23 static const char *default_names[SYS_IRQS] = {
24         "spurious int", "int1 handler", "int2 handler", "int3 handler",
25         "int4 handler", "int5 handler", "int6 handler", "int7 handler"
26 };
27
28 /* The number of spurious interrupts */
29 volatile unsigned int num_spurious;
30
31 #define NUM_IRQ_NODES 100
32 static irq_node_t nodes[NUM_IRQ_NODES];
33
34
35 /*
36  * void init_IRQ(void)
37  *
38  * Parameters:  None
39  *
40  * Returns:     Nothing
41  *
42  * This function should be called during kernel startup to initialize
43  * the IRQ handling routines.
44  */
45
46 __init
47 void m68k_init_IRQ(void)
48 {
49         int i;
50
51         for (i = 0; i < SYS_IRQS; i++) {
52                 if (mach_default_handler)
53                         irq_list[i].handler = (*mach_default_handler)[i];
54                 irq_list[i].flags   = 0;
55                 irq_list[i].dev_id  = NULL;
56                 irq_list[i].devname = default_names[i];
57         }
58
59         for (i = 0; i < NUM_IRQ_NODES; i++)
60                 nodes[i].handler = NULL;
61
62         mach_init_IRQ ();
63 }
64
65 irq_node_t *new_irq_node(void)
66 {
67         irq_node_t *node;
68         short i;
69
70         for (node = nodes, i = NUM_IRQ_NODES-1; i >= 0; node++, i--)
71                 if (!node->handler)
72                         return node;
73
74         printk ("new_irq_node: out of nodes\n");
75         return NULL;
76 }
77
78 int sys_request_irq(unsigned int irq,
79                     void (*handler)(int, void *, struct pt_regs *),
80                     unsigned long flags, const char *devname, void *dev_id)
81 {
82         if (irq < IRQ1 || irq > IRQ7) {
83                 printk("%s: Incorrect IRQ %d from %s\n",
84                        __FUNCTION__, irq, devname);
85                 return -ENXIO;
86         }
87
88 #if 0
89         if (!(irq_list[irq].flags & IRQ_FLG_STD)) {
90                 if (irq_list[irq].flags & IRQ_FLG_LOCK) {
91                         printk("%s: IRQ %d from %s is not replaceable\n",
92                                __FUNCTION__, irq, irq_list[irq].devname);
93                         return -EBUSY;
94                 }
95                 if (!(flags & IRQ_FLG_REPLACE)) {
96                         printk("%s: %s can't replace IRQ %d from %s\n",
97                                __FUNCTION__, devname, irq, irq_list[irq].devname);
98                         return -EBUSY;
99                 }
100         }
101 #endif
102
103         irq_list[irq].handler = handler;
104         irq_list[irq].flags   = flags;
105         irq_list[irq].dev_id  = dev_id;
106         irq_list[irq].devname = devname;
107         return 0;
108 }
109
110 void sys_free_irq(unsigned int irq, void *dev_id)
111 {
112         if (irq < IRQ1 || irq > IRQ7) {
113                 printk("%s: Incorrect IRQ %d\n", __FUNCTION__, irq);
114                 return;
115         }
116
117         if (irq_list[irq].dev_id != dev_id)
118                 printk("%s: Removing probably wrong IRQ %d from %s\n",
119                        __FUNCTION__, irq, irq_list[irq].devname);
120
121         irq_list[irq].handler = (*mach_default_handler)[irq];
122         irq_list[irq].flags   = 0;
123         irq_list[irq].dev_id  = NULL;
124         irq_list[irq].devname = default_names[irq];
125 }
126
127 asmlinkage void process_int(unsigned long vec, struct pt_regs *fp)
128 {
129         if (vec >= VEC_INT1 && vec <= VEC_INT7 && !MACH_IS_BVME6000) {
130                 vec -= VEC_SPUR;
131                 kstat_cpu(0).irqs[vec]++;
132                 irq_list[vec].handler(vec, irq_list[vec].dev_id, fp);
133         } else {
134                 if (mach_process_int)
135                         mach_process_int(vec, fp);
136                 else
137                         panic("Can't process interrupt vector %ld\n", vec);
138                 return;
139         }
140 }
141
142 int m68k_get_irq_list(struct seq_file *p, void *v)
143 {
144         int i;
145
146         /* autovector interrupts */
147         if (mach_default_handler) {
148                 for (i = 0; i < SYS_IRQS; i++) {
149                         seq_printf(p, "auto %2d: %10u ", i,
150                                        i ? kstat_cpu(0).irqs[i] : num_spurious);
151                         seq_puts(p, "  ");
152                         seq_printf(p, "%s\n", irq_list[i].devname);
153                 }
154         }
155
156         mach_get_irq_list(p, v);
157         return 0;
158 }