OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [arch/] [m68knommu/] [platform/] [68EN302/] [ints.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * linux/arch/$(ARCH)/platform/$(PLATFORM)/ints.c
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
 * Copyright 1996 Roman Zippel
9
 * Copyright 1999 D. Jeff Dionne <jeff@rt-control.com>
10
 */
11
 
12
#include <linux/types.h>
13
#include <linux/kernel.h>
14
#include <linux/sched.h>
15
#include <linux/kernel_stat.h>
16
 
17
#include <asm/system.h>
18
#include <asm/irq.h>
19
#include <asm/traps.h>
20
#include <asm/io.h>
21
#include <asm/machdep.h>
22
#include <asm/setup.h>
23
 
24
#include <asm/MC68EZ328.h>
25
 
26
#define INTERNAL_IRQS (32)
27
 
28
/* assembler routines */
29
asmlinkage void system_call(void);
30
asmlinkage void buserr(void);
31
asmlinkage void trap(void);
32
asmlinkage void trap3(void);
33
asmlinkage void trap4(void);
34
asmlinkage void trap5(void);
35
asmlinkage void trap6(void);
36
asmlinkage void trap7(void);
37
asmlinkage void trap8(void);
38
asmlinkage void trap9(void);
39
asmlinkage void trap10(void);
40
asmlinkage void trap11(void);
41
asmlinkage void trap12(void);
42
asmlinkage void trap13(void);
43
asmlinkage void trap14(void);
44
asmlinkage void trap15(void);
45
asmlinkage void trap33(void);
46
asmlinkage void trap34(void);
47
asmlinkage void trap35(void);
48
asmlinkage void trap36(void);
49
asmlinkage void trap37(void);
50
asmlinkage void trap38(void);
51
asmlinkage void trap39(void);
52
asmlinkage void trap40(void);
53
asmlinkage void trap41(void);
54
asmlinkage void trap42(void);
55
asmlinkage void trap43(void);
56
asmlinkage void trap44(void);
57
asmlinkage void trap45(void);
58
asmlinkage void trap46(void);
59
asmlinkage void trap47(void);
60
asmlinkage void bad_interrupt(void);
61
asmlinkage void inthandler(void);
62
asmlinkage void inthandler1(void);
63
asmlinkage void inthandler2(void);
64
asmlinkage void inthandler3(void);
65
asmlinkage void inthandler4(void);
66
asmlinkage void inthandler5(void);
67
asmlinkage void inthandler6(void);
68
asmlinkage void inthandler7(void);
69
 
70
extern void *_ramvec[];
71
 
72
/* irq node variables for the 32 (potential) on chip sources */
73
static irq_node_t *int_irq_list[INTERNAL_IRQS];
74
 
75
static int int_irq_count[INTERNAL_IRQS];
76
static short int_irq_ablecount[INTERNAL_IRQS];
77
 
78
static void int_badint(int irq, void *dev_id, struct pt_regs *fp)
79
{
80
        num_spurious += 1;
81
}
82
 
83
/*
84
 * This function should be called during kernel startup to initialize
85
 * the amiga IRQ handling routines.
86
 */
87
 
88
void M68EZ328_init_IRQ(void)
89
{
90
        int i;
91
 
92
        /* set up the vectors */
93
#if 0
94
        _ramvec[2] = buserr;
95
        _ramvec[3] = trap3;
96
        _ramvec[4] = trap4;
97
        _ramvec[5] = trap5;
98
        _ramvec[6] = trap6;
99
        _ramvec[7] = trap7;
100
        _ramvec[8] = trap8;
101
        _ramvec[9] = trap9;
102
        _ramvec[10] = trap10;
103
        _ramvec[11] = trap11;
104
        _ramvec[12] = trap12;
105
        _ramvec[13] = trap13;
106
        _ramvec[14] = trap14;
107
        _ramvec[15] = trap15;
108
#endif
109
        _ramvec[32] = system_call;
110
 
111
        _ramvec[64] = bad_interrupt;
112
        _ramvec[65] = inthandler1;
113
        _ramvec[66] = inthandler2;
114
        _ramvec[67] = inthandler3;
115
        _ramvec[68] = inthandler4;
116
        _ramvec[69] = inthandler5;
117
        _ramvec[70] = inthandler6;
118
        _ramvec[71] = inthandler7;
119
 
120
        IVR = 0x40; /* Set DragonBall IVR (interrupt base) to 64 */
121
 
122
        /* initialize handlers */
123
        for (i = 0; i < INTERNAL_IRQS; i++) {
124
                int_irq_list[i] = NULL;
125
 
126
                int_irq_ablecount[i] = 0;
127
                int_irq_count[i] = 0;
128
        }
129
        /* turn off all interrupts */
130
        IMR = ~0;
131
}
132
 
133
void M68EZ328_insert_irq(irq_node_t **list, irq_node_t *node)
134
{
135
        unsigned long flags;
136
        irq_node_t *cur;
137
 
138
        if (!node->dev_id)
139
                printk("%s: Warning: dev_id of %s is zero\n",
140
                       __FUNCTION__, node->devname);
141
 
142
        save_flags(flags);
143
        cli();
144
 
145
        cur = *list;
146
 
147
        while (cur) {
148
                list = &cur->next;
149
                cur = cur->next;
150
        }
151
 
152
        node->next = cur;
153
        *list = node;
154
 
155
        restore_flags(flags);
156
}
157
 
158
void M68EZ328_delete_irq(irq_node_t **list, void *dev_id)
159
{
160
        unsigned long flags;
161
        irq_node_t *node;
162
 
163
        save_flags(flags);
164
        cli();
165
 
166
        for (node = *list; node; list = &node->next, node = *list) {
167
                if (node->dev_id == dev_id) {
168
                        *list = node->next;
169
                        /* Mark it as free. */
170
                        node->handler = NULL;
171
                        restore_flags(flags);
172
                        return;
173
                }
174
        }
175
        restore_flags(flags);
176
        printk ("%s: tried to remove invalid irq\n", __FUNCTION__);
177
}
178
 
179
int M68EZ328_request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
180
                         unsigned long flags, const char *devname, void *dev_id)
181
{
182
        if (irq >= INTERNAL_IRQS) {
183
                printk ("%s: Unknown IRQ %d from %s\n", __FUNCTION__, irq, devname);
184
                return -ENXIO;
185
        }
186
 
187
        if (!int_irq_list[irq]) {
188
                int_irq_list[irq] = new_irq_node();
189
                int_irq_list[irq]->flags   = IRQ_FLG_STD;
190
        }
191
 
192
        if (!(int_irq_list[irq]->flags & IRQ_FLG_STD)) {
193
                if (int_irq_list[irq]->flags & IRQ_FLG_LOCK) {
194
                        printk("%s: IRQ %d from %s is not replaceable\n",
195
                               __FUNCTION__, irq, int_irq_list[irq]->devname);
196
                        return -EBUSY;
197
                }
198
                if (flags & IRQ_FLG_REPLACE) {
199
                        printk("%s: %s can't replace IRQ %d from %s\n",
200
                               __FUNCTION__, devname, irq, int_irq_list[irq]->devname);
201
                        return -EBUSY;
202
                }
203
        }
204
        int_irq_list[irq]->handler = handler;
205
        int_irq_list[irq]->flags   = flags;
206
        int_irq_list[irq]->dev_id  = dev_id;
207
        int_irq_list[irq]->devname = devname;
208
 
209
        /* enable in the IMR */
210
        if (!int_irq_ablecount[irq])
211
                *(volatile unsigned long *)0xfffff304 &= ~(1<<irq);
212
 
213
        return 0;
214
}
215
 
216
void M68EZ328_free_irq(unsigned int irq, void *dev_id)
217
{
218
        if (irq >= INTERNAL_IRQS) {
219
                printk ("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
220
                return;
221
        }
222
 
223
        if (int_irq_list[irq]->dev_id != dev_id)
224
                printk("%s: removing probably wrong IRQ %d from %s\n",
225
                       __FUNCTION__, irq, int_irq_list[irq]->devname);
226
        int_irq_list[irq]->handler = int_badint;
227
        int_irq_list[irq]->flags   = IRQ_FLG_STD;
228
        int_irq_list[irq]->dev_id  = NULL;
229
        int_irq_list[irq]->devname = NULL;
230
 
231
        *(volatile unsigned long *)0xfffff304 |= 1<<irq;
232
}
233
 
234
/*
235
 * Enable/disable a particular machine specific interrupt source.
236
 * Note that this may affect other interrupts in case of a shared interrupt.
237
 * This function should only be called for a _very_ short time to change some
238
 * internal data, that may not be changed by the interrupt at the same time.
239
 * int_(enable|disable)_irq calls may also be nested.
240
 */
241
 
242
void M68EZ328_enable_irq(unsigned int irq)
243
{
244
        if (irq >= INTERNAL_IRQS) {
245
                printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
246
                return;
247
        }
248
 
249
        if (--int_irq_ablecount[irq])
250
                return;
251
 
252
        /* enable the interrupt */
253
        *(volatile unsigned long *)0xfffff304 &= ~(1<<irq);
254
}
255
 
256
void M68EZ328_disable_irq(unsigned int irq)
257
{
258
        if (irq >= INTERNAL_IRQS) {
259
                printk("%s: Unknown IRQ %d\n", __FUNCTION__, irq);
260
                return;
261
        }
262
 
263
        if (int_irq_ablecount[irq]++)
264
                return;
265
 
266
        /* disable the interrupt */
267
        *(volatile unsigned long *)0xfffff304 |= 1<<irq;
268
}
269
 
270
/* The 68k family did not have a good way to determine the source
271
 * of interrupts until later in the family.  The EC000 core does
272
 * not provide the vector number on the stack, we vector everything
273
 * into one vector and look in the blasted mask register...
274
 * This code is designed to be fast, almost constant time, not clean!
275
 */
276
inline int M68EZ328_do_irq(int vec, struct pt_regs *fp)
277
{
278
        int irq;
279
        int mask;
280
 
281
        unsigned long pend = *(volatile unsigned long *)0xfffff30c;
282
 
283
        while (pend) {
284
                if (pend & 0x0000ffff) {
285
                        if (pend & 0x000000ff) {
286
                                if (pend & 0x0000000f) {
287
                                        mask = 0x00000001;
288
                                        irq = 0;
289
                                } else {
290
                                        mask = 0x00000010;
291
                                        irq = 4;
292
                                }
293
                        } else {
294
                                if (pend & 0x00000f00) {
295
                                        mask = 0x00000100;
296
                                        irq = 8;
297
                                } else {
298
                                        mask = 0x00001000;
299
                                        irq = 12;
300
                                }
301
                        }
302
                } else {
303
                        if (pend & 0x00ff0000) {
304
                                if (pend & 0x000f0000) {
305
                                        mask = 0x00010000;
306
                                        irq = 16;
307
                                } else {
308
                                        mask = 0x00100000;
309
                                        irq = 20;
310
                                }
311
                        } else {
312
                                if (pend & 0x0f000000) {
313
                                        mask = 0x01000000;
314
                                        irq = 24;
315
                                } else {
316
                                        mask = 0x10000000;
317
                                        irq = 28;
318
                                }
319
                        }
320
                }
321
 
322
                while (! (mask & pend)) {
323
                        mask <<=1;
324
                        irq++;
325
                }
326
 
327
                if (int_irq_list[irq] && int_irq_list[irq]->handler) {
328
                        int_irq_list[irq]->handler(irq | IRQ_MACHSPEC, int_irq_list[irq]->dev_id, fp);
329
                        int_irq_count[irq]++;
330
                } else {
331
                        printk("unregistered interrupt %d!\nTurning it off in the IMR...\n", irq);
332
                        *(volatile unsigned long *)0xfffff304 |= mask;
333
                }
334
                pend &= ~mask;
335
        }
336
        return 0;
337
}
338
 
339
int M68EZ328_get_irq_list(char *buf)
340
{
341
        int i, len = 0;
342
        irq_node_t *node;
343
 
344
        len += sprintf(buf+len, "Internal 68EZ328 interrupts\n");
345
 
346
        for (i = 0; i < INTERNAL_IRQS; i++) {
347
                if (!(node = int_irq_list[i]))
348
                        continue;
349
                if (!(node->handler))
350
                        continue;
351
 
352
                len += sprintf(buf+len, " %2d: %10u    %s\n", i,
353
                               int_irq_count[i], int_irq_list[i]->devname);
354
        }
355
        return len;
356
}
357
 
358
void config_M68EZ328_irq(void)
359
{
360
        mach_default_handler = NULL;
361
        mach_init_IRQ        = M68EZ328_init_IRQ;
362
        mach_request_irq     = M68EZ328_request_irq;
363
        mach_free_irq        = M68EZ328_free_irq;
364
        mach_enable_irq      = M68EZ328_enable_irq;
365
        mach_disable_irq     = M68EZ328_disable_irq;
366
        mach_get_irq_list    = M68EZ328_get_irq_list;
367
        mach_process_int     = M68EZ328_do_irq;
368
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.