Merge with Linux 2.5.74.
[linux-2.6/linux-mips.git] / arch / m68knommu / platform / 68360 / ints.c
blob667833629fce1ec9b64a36b6c9ac5f79c16ed29f
1 /*
2 * linux/arch/$(ARCH)/platform/$(PLATFORM)/ints.c
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.
8 * Copyright (c) 2000 Michael Leslie <mleslie@lineo.com>
9 * Copyright (c) 1996 Roman Zippel
10 * Copyright (c) 1999 D. Jeff Dionne <jeff@uclinux.org>
13 #include <linux/config.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/errno.h>
20 #include <asm/system.h>
21 #include <asm/irq.h>
22 #include <asm/traps.h>
23 #include <asm/io.h>
24 #include <asm/machdep.h>
25 #include <asm/setup.h>
26 #include <asm/m68360.h>
28 /* from quicc/commproc.c: */
29 extern QUICC *pquicc;
30 extern void cpm_interrupt_init(void);
32 #define INTERNAL_IRQS (96)
34 /* assembler routines */
35 asmlinkage void system_call(void);
36 asmlinkage void buserr(void);
37 asmlinkage void trap(void);
38 asmlinkage void bad_interrupt(void);
39 asmlinkage void inthandler(void);
41 extern void *_ramvec[];
43 /* The number of spurious interrupts */
44 volatile unsigned int num_spurious;
45 unsigned int local_irq_count[NR_CPUS];
47 /* irq node variables for the 32 (potential) on chip sources */
48 static irq_node_t int_irq_list[INTERNAL_IRQS];
50 static short int_irq_ablecount[INTERNAL_IRQS];
53 * This function should be called during kernel startup to initialize
54 * IRQ handling routines.
57 void init_IRQ(void)
59 int i;
60 int vba = (CPM_VECTOR_BASE<<4);
62 /* set up the vectors */
63 _ramvec[2] = buserr;
64 _ramvec[3] = trap;
65 _ramvec[4] = trap;
66 _ramvec[5] = trap;
67 _ramvec[6] = trap;
68 _ramvec[7] = trap;
69 _ramvec[8] = trap;
70 _ramvec[9] = trap;
71 _ramvec[10] = trap;
72 _ramvec[11] = trap;
73 _ramvec[12] = trap;
74 _ramvec[13] = trap;
75 _ramvec[14] = trap;
76 _ramvec[15] = trap;
78 _ramvec[32] = system_call;
79 _ramvec[33] = trap;
82 cpm_interrupt_init();
84 /* set up CICR for vector base address and irq level */
85 /* irl = 4, hp = 1f - see MC68360UM p 7-377 */
86 pquicc->intr_cicr = 0x00e49f00 | vba;
88 /* CPM interrupt vectors: (p 7-376) */
89 _ramvec[vba+CPMVEC_ERROR] = bad_interrupt; /* Error */
90 _ramvec[vba+CPMVEC_PIO_PC11] = inthandler; /* pio - pc11 */
91 _ramvec[vba+CPMVEC_PIO_PC10] = inthandler; /* pio - pc10 */
92 _ramvec[vba+CPMVEC_SMC2] = inthandler; /* smc2/pip */
93 _ramvec[vba+CPMVEC_SMC1] = inthandler; /* smc1 */
94 _ramvec[vba+CPMVEC_SPI] = inthandler; /* spi */
95 _ramvec[vba+CPMVEC_PIO_PC9] = inthandler; /* pio - pc9 */
96 _ramvec[vba+CPMVEC_TIMER4] = inthandler; /* timer 4 */
97 _ramvec[vba+CPMVEC_RESERVED1] = inthandler; /* reserved */
98 _ramvec[vba+CPMVEC_PIO_PC8] = inthandler; /* pio - pc8 */
99 _ramvec[vba+CPMVEC_PIO_PC7] = inthandler; /* pio - pc7 */
100 _ramvec[vba+CPMVEC_PIO_PC6] = inthandler; /* pio - pc6 */
101 _ramvec[vba+CPMVEC_TIMER3] = inthandler; /* timer 3 */
102 _ramvec[vba+CPMVEC_RISCTIMER] = inthandler; /* reserved */
103 _ramvec[vba+CPMVEC_PIO_PC5] = inthandler; /* pio - pc5 */
104 _ramvec[vba+CPMVEC_PIO_PC4] = inthandler; /* pio - pc4 */
105 _ramvec[vba+CPMVEC_RESERVED2] = inthandler; /* reserved */
106 _ramvec[vba+CPMVEC_RISCTIMER] = inthandler; /* timer table */
107 _ramvec[vba+CPMVEC_TIMER2] = inthandler; /* timer 2 */
108 _ramvec[vba+CPMVEC_RESERVED3] = inthandler; /* reserved */
109 _ramvec[vba+CPMVEC_IDMA2] = inthandler; /* idma 2 */
110 _ramvec[vba+CPMVEC_IDMA1] = inthandler; /* idma 1 */
111 _ramvec[vba+CPMVEC_SDMA_CB_ERR] = inthandler; /* sdma channel bus error */
112 _ramvec[vba+CPMVEC_PIO_PC3] = inthandler; /* pio - pc3 */
113 _ramvec[vba+CPMVEC_PIO_PC2] = inthandler; /* pio - pc2 */
114 /* _ramvec[vba+CPMVEC_TIMER1] = cpm_isr_timer1; */ /* timer 1 */
115 _ramvec[vba+CPMVEC_TIMER1] = inthandler; /* timer 1 */
116 _ramvec[vba+CPMVEC_PIO_PC1] = inthandler; /* pio - pc1 */
117 _ramvec[vba+CPMVEC_SCC4] = inthandler; /* scc 4 */
118 _ramvec[vba+CPMVEC_SCC3] = inthandler; /* scc 3 */
119 _ramvec[vba+CPMVEC_SCC2] = inthandler; /* scc 2 */
120 _ramvec[vba+CPMVEC_SCC1] = inthandler; /* scc 1 */
121 _ramvec[vba+CPMVEC_PIO_PC0] = inthandler; /* pio - pc0 */
124 /* turn off all CPM interrupts */
125 pquicc->intr_cimr = 0x00000000;
127 /* initialize handlers */
128 for (i = 0; i < INTERNAL_IRQS; i++) {
129 int_irq_list[i].handler = NULL;
130 int_irq_list[i].flags = IRQ_FLG_STD;
131 int_irq_list[i].dev_id = NULL;
132 int_irq_list[i].devname = NULL;
136 #if 0
137 void M68360_insert_irq(irq_node_t **list, irq_node_t *node)
139 unsigned long flags;
140 irq_node_t *cur;
142 if (!node->dev_id)
143 printk("%s: Warning: dev_id of %s is zero\n",
144 __FUNCTION__, node->devname);
146 local_irq_save(flags);
148 cur = *list;
150 while (cur) {
151 list = &cur->next;
152 cur = cur->next;
155 node->next = cur;
156 *list = node;
158 local_irq_restore(flags);
161 void M68360_delete_irq(irq_node_t **list, void *dev_id)
163 unsigned long flags;
164 irq_node_t *node;
166 local_irq_save(flags);
168 for (node = *list; node; list = &node->next, node = *list) {
169 if (node->dev_id == dev_id) {
170 *list = node->next;
171 /* Mark it as free. */
172 node->handler = NULL;
173 local_irq_restore(flags);
174 return;
177 local_irq_restore(flags);
178 printk ("%s: tried to remove invalid irq\n", __FUNCTION__);
180 #endif
182 int request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
183 unsigned long flags, const char *devname, void *dev_id)
185 int mask = (1<<irq);
187 irq += (CPM_VECTOR_BASE<<4);
189 if (irq >= INTERNAL_IRQS) {
190 printk ("%s: Unknown IRQ %d from %s\n", __FUNCTION__, irq, devname);
191 return -ENXIO;
194 if (!(int_irq_list[irq].flags & IRQ_FLG_STD)) {
195 if (int_irq_list[irq].flags & IRQ_FLG_LOCK) {
196 printk("%s: IRQ %d from %s is not replaceable\n",
197 __FUNCTION__, irq, int_irq_list[irq].devname);
198 return -EBUSY;
200 if (flags & IRQ_FLG_REPLACE) {
201 printk("%s: %s can't replace IRQ %d from %s\n",
202 __FUNCTION__, devname, irq, int_irq_list[irq].devname);
203 return -EBUSY;
206 int_irq_list[irq].handler = handler;
207 int_irq_list[irq].flags = flags;
208 int_irq_list[irq].dev_id = dev_id;
209 int_irq_list[irq].devname = devname;
211 /* enable in the CIMR */
212 if (!int_irq_ablecount[irq])
213 pquicc->intr_cimr |= mask;
214 /* *(volatile unsigned long *)0xfffff304 &= ~(1<<irq); */
216 return 0;
219 void free_irq(unsigned int irq, void *dev_id)
221 if (irq >= INTERNAL_IRQS) {
222 printk ("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
223 return;
226 if (int_irq_list[irq].dev_id != dev_id)
227 printk("%s: removing probably wrong IRQ %d from %s\n",
228 __FUNCTION__, irq, int_irq_list[irq].devname);
229 int_irq_list[irq].handler = NULL;
230 int_irq_list[irq].flags = IRQ_FLG_STD;
231 int_irq_list[irq].dev_id = NULL;
232 int_irq_list[irq].devname = NULL;
234 *(volatile unsigned long *)0xfffff304 |= 1<<irq;
237 #if 0
239 * Enable/disable a particular machine specific interrupt source.
240 * Note that this may affect other interrupts in case of a shared interrupt.
241 * This function should only be called for a _very_ short time to change some
242 * internal data, that may not be changed by the interrupt at the same time.
243 * int_(enable|disable)_irq calls may also be nested.
245 void M68360_enable_irq(unsigned int irq)
247 if (irq >= INTERNAL_IRQS) {
248 printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
249 return;
252 if (--int_irq_ablecount[irq])
253 return;
255 /* enable the interrupt */
256 *(volatile unsigned long *)0xfffff304 &= ~(1<<irq);
259 void M68360_disable_irq(unsigned int irq)
261 if (irq >= INTERNAL_IRQS) {
262 printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
263 return;
266 if (int_irq_ablecount[irq]++)
267 return;
269 /* disable the interrupt */
270 *(volatile unsigned long *)0xfffff304 |= 1<<irq;
272 #endif
274 int show_interrupts(struct seq_file *p, void *v)
276 int i;
278 for (i = 0; i < NR_IRQS; i++) {
279 if (int_irq_list[i].flags & IRQ_FLG_STD)
280 continue;
282 seq_printf(p, "%3d: %10u ", i, kstat_cpu(0).irqs[i]);
283 if (int_irq_list[i].flags & IRQ_FLG_LOCK)
284 seq_printf(p, "L ");
285 else
286 seq_printf(p, " ");
287 seq_printf(p, "%s\n", int_irq_list[i].devname);
289 seq_printf(p, " : %10u spurious\n", num_spurious);
291 return 0;
294 /* The 68k family did not have a good way to determine the source
295 * of interrupts until later in the family. The EC000 core does
296 * not provide the vector number on the stack, we vector everything
297 * into one vector and look in the blasted mask register...
298 * This code is designed to be fast, almost constant time, not clean!
300 void process_int(int vec, struct pt_regs *fp)
302 int irq;
303 int mask;
305 /* unsigned long pend = *(volatile unsigned long *)0xfffff30c; */
307 /* irq = vec + (CPM_VECTOR_BASE<<4); */
308 irq = vec;
310 /* unsigned long pend = *(volatile unsigned long *)pquicc->intr_cipr; */
312 /* Bugger all that weirdness. For the moment, I seem to know where I came from;
313 * vec is passed from a specific ISR, so I'll use it. */
315 if (int_irq_list[irq].handler) {
316 int_irq_list[irq].handler(irq , int_irq_list[irq].dev_id, fp);
317 kstat_cpu(0).irqs[irq]++;
318 pquicc->intr_cisr = (1 << vec); /* indicate that irq has been serviced */
319 } else {
320 printk("unregistered interrupt %d!\nTurning it off in the CIMR...\n", irq);
321 /* *(volatile unsigned long *)0xfffff304 |= mask; */
322 pquicc->intr_cimr &= ~(1 << vec);
323 num_spurious += 1;