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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [arch/] [armnommu/] [kernel/] [irq.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *  linux/arch/arm/kernel/irq.c
3
 *
4
 *  Copyright (C) 1992 Linus Torvalds
5
 *  Modifications for ARM processor Copyright (C) 1995, 1996 Russell King.
6
 *
7
 * This file contains the code used by various IRQ handling routines:
8
 * asking for different IRQ's should be done through these routines
9
 * instead of just grabbing them. Thus setups with different IRQ numbers
10
 * shouldn't result in any weird surprises, and installing new handlers
11
 * should be easier.
12
 */
13
 
14
/*
15
 * IRQ's are in fact implemented a bit like signal handlers for the kernel.
16
 * Naturally it's not a 1:1 relation, but there are similarities.
17
 */
18
#include <linux/ptrace.h>
19
#include <linux/errno.h>
20
#include <linux/kernel_stat.h>
21
#include <linux/signal.h>
22
#include <linux/sched.h>
23
#include <linux/interrupt.h>
24
#include <linux/timex.h>
25
#include <linux/malloc.h>
26
#include <linux/random.h>
27
 
28
#include <asm/io.h>
29
#include <asm/system.h>
30
#include <asm/hardware.h>
31
#include <asm/irq.h>
32
 
33
#include <asm/arch/irq.h>
34
 
35
void disable_irq(unsigned int irq_nr)
36
{
37
        unsigned long flags;
38
 
39
#ifdef cliIF
40
        save_flags(flags);
41
        cliIF();
42
#else
43
        save_flags_cli (flags);
44
#endif
45
        mask_irq(irq_nr);
46
        restore_flags(flags);
47
}
48
 
49
void enable_irq(unsigned int irq_nr)
50
{
51
        unsigned long flags;
52
 
53
#ifdef cliIF
54
        save_flags (flags);
55
        cliIF();
56
#else
57
        save_flags_cli (flags);
58
#endif
59
        unmask_irq(irq_nr);
60
        restore_flags(flags);
61
}
62
 
63
BUILD_IRQ(FIRST,0,0x01)
64
BUILD_IRQ(FIRST,1,0x02)
65
BUILD_IRQ(FIRST,2,0x04)
66
BUILD_IRQ(FIRST,3,0x08)
67
BUILD_IRQ(FIRST,4,0x10)
68
BUILD_IRQ(FIRST,5,0x20)
69
BUILD_IRQ(FIRST,6,0x40)
70
BUILD_IRQ(FIRST,7,0x80)
71
BUILD_IRQ(SECOND,8,0x01)
72
BUILD_IRQ(SECOND,9,0x02)
73
BUILD_IRQ(SECOND,10,0x04)
74
BUILD_IRQ(SECOND,11,0x08)
75
BUILD_IRQ(SECOND,12,0x10)
76
BUILD_IRQ(SECOND,13,0x20)
77
BUILD_IRQ(SECOND,14,0x40)
78
BUILD_IRQ(SECOND,15,0x80)
79
BUILD_IRQ(SECOND,16,0x01)
80
BUILD_IRQ(SECOND,17,0x02)
81
BUILD_IRQ(SECOND,18,0x04)
82
BUILD_IRQ(SECOND,19,0x08)
83
BUILD_IRQ(SECOND,20,0x10)
84
BUILD_IRQ(SECOND,21,0x20)
85
BUILD_IRQ(SECOND,22,0x40)
86
BUILD_IRQ(SECOND,23,0x80)
87
 
88
/*
89
 * Pointers to the low-level handlers: first the general ones, then the
90
 * fast ones, then the bad ones.
91
 */
92
static void (* const interrupt[24])(void) = {
93
    IRQ_INTERRUPT( 0), IRQ_INTERRUPT( 1), IRQ_INTERRUPT( 2), IRQ_INTERRUPT( 3),
94
    IRQ_INTERRUPT( 4), IRQ_INTERRUPT( 5), IRQ_INTERRUPT( 6), IRQ_INTERRUPT( 7),
95
    IRQ_INTERRUPT( 8), IRQ_INTERRUPT( 9), IRQ_INTERRUPT(10), IRQ_INTERRUPT(11),
96
    IRQ_INTERRUPT(12), IRQ_INTERRUPT(13), IRQ_INTERRUPT(14), IRQ_INTERRUPT(15),
97
    IRQ_INTERRUPT(16), IRQ_INTERRUPT(17), IRQ_INTERRUPT(18), IRQ_INTERRUPT(19),
98
    IRQ_INTERRUPT(20), IRQ_INTERRUPT(21), IRQ_INTERRUPT(22), IRQ_INTERRUPT(23)
99
};
100
 
101
static void (* const fast_interrupt[24])(void) = {
102
    FAST_INTERRUPT( 0), FAST_INTERRUPT( 1), FAST_INTERRUPT( 2), FAST_INTERRUPT( 3),
103
    FAST_INTERRUPT( 4), FAST_INTERRUPT( 5), FAST_INTERRUPT( 6), FAST_INTERRUPT( 7),
104
    FAST_INTERRUPT( 8), FAST_INTERRUPT( 9), FAST_INTERRUPT(10), FAST_INTERRUPT(11),
105
    FAST_INTERRUPT(12), FAST_INTERRUPT(13), FAST_INTERRUPT(14), FAST_INTERRUPT(15),
106
    FAST_INTERRUPT(16), FAST_INTERRUPT(17), FAST_INTERRUPT(18), FAST_INTERRUPT(19),
107
    FAST_INTERRUPT(20), FAST_INTERRUPT(21), FAST_INTERRUPT(22), FAST_INTERRUPT(23)
108
};
109
 
110
static void (* const bad_interrupt[24])(void) = {
111
    BAD_INTERRUPT( 0), BAD_INTERRUPT( 1), BAD_INTERRUPT( 2), BAD_INTERRUPT( 3),
112
    BAD_INTERRUPT( 4), BAD_INTERRUPT( 5), BAD_INTERRUPT( 6), BAD_INTERRUPT( 7),
113
    BAD_INTERRUPT( 8), BAD_INTERRUPT( 9), BAD_INTERRUPT(10), BAD_INTERRUPT(11),
114
    BAD_INTERRUPT(12), BAD_INTERRUPT(13), BAD_INTERRUPT(14), BAD_INTERRUPT(15),
115
    BAD_INTERRUPT(16), BAD_INTERRUPT(17), BAD_INTERRUPT(18), BAD_INTERRUPT(19),
116
    BAD_INTERRUPT(20), BAD_INTERRUPT(21), BAD_INTERRUPT(22), BAD_INTERRUPT(23)
117
};
118
 
119
static void (* const probe_interrupt[16])(void) = {
120
    PROBE_INTERRUPT( 0), PROBE_INTERRUPT( 1), PROBE_INTERRUPT( 2), PROBE_INTERRUPT( 3),
121
    PROBE_INTERRUPT( 4), PROBE_INTERRUPT( 5), PROBE_INTERRUPT( 6), PROBE_INTERRUPT( 7),
122
    PROBE_INTERRUPT( 8), PROBE_INTERRUPT( 9), PROBE_INTERRUPT(10), PROBE_INTERRUPT(11),
123
    PROBE_INTERRUPT(12), PROBE_INTERRUPT(13), PROBE_INTERRUPT(14), PROBE_INTERRUPT(15)
124
};
125
 
126
/*
127
 * Initial irq handlers.
128
 */
129
 
130
static void no_action (int irq, void *dev_id, struct pt_regs *regs)
131
{
132
}
133
 
134
struct irqaction *irq_action[NR_IRQS];
135
 
136
unsigned long validirqs[4] = {
137
        0x003fffff,
138
        0x000001ff,
139
        0x000000ff,
140
        0x00000000
141
};
142
 
143
void (*irqjump[NR_IRQS])(void) = {
144
    PROBE_INTERRUPT( 0), PROBE_INTERRUPT( 1), PROBE_INTERRUPT( 2), PROBE_INTERRUPT( 3),
145
    PROBE_INTERRUPT( 4), PROBE_INTERRUPT( 5), PROBE_INTERRUPT( 6), PROBE_INTERRUPT( 7),
146
    PROBE_INTERRUPT( 8), PROBE_INTERRUPT( 9), PROBE_INTERRUPT(10), PROBE_INTERRUPT(11),
147
    PROBE_INTERRUPT(12), PROBE_INTERRUPT(13), PROBE_INTERRUPT(14), PROBE_INTERRUPT(15),
148
    PROBE_INTERRUPT(16), PROBE_INTERRUPT(17), PROBE_INTERRUPT(18), PROBE_INTERRUPT(19),
149
    PROBE_INTERRUPT(20), PROBE_INTERRUPT(21), PROBE_INTERRUPT(22), PROBE_INTERRUPT(23)
150
};
151
 
152
int get_irq_list(char *buf)
153
{
154
        int i, len = 0;
155
        struct irqaction * action;
156
 
157
        for (i = 0 ; i < NR_IRQS ; i++) {
158
                action = irq_action[i];
159
                if (!action)
160
                        continue;
161
                len += sprintf(buf+len, "%2d: %10u %c %s",
162
                                i, kstat.interrupts[i],
163
                                (action->flags & SA_INTERRUPT) ? '+' : ' ',
164
                                action->name);
165
                for (action = action->next; action; action = action->next) {
166
                        len += sprintf(buf+len, ",%s %s",
167
                            (action->flags & SA_INTERRUPT) ? " +" : "",
168
                            action->name);
169
                }
170
                len += sprintf(buf+len, "\n");
171
        }
172
        return len;
173
}
174
 
175
/*
176
 * do_IRQ handles IRQ's that have been installed without the
177
 * SA_INTERRUPT flag: it uses the full signal-handling return
178
 * and runs with other interrupts enabled. All relatively slow
179
 * IRQ's should use this format: notably the keyboard/timer
180
 * routines.
181
 */
182
asmlinkage void do_IRQ(int irq, struct pt_regs * regs)
183
{
184
        struct irqaction * action = *(irq + irq_action);
185
        int do_random = 0;
186
 
187
        kstat.interrupts[irq]++;
188
 
189
        while (action) {
190
                do_random |= action->flags;
191
                action->handler(irq, action->dev_id, regs);
192
                action = action->next;
193
        }
194
        if (do_random & SA_SAMPLE_RANDOM)
195
                add_interrupt_randomness(irq);
196
}
197
 
198
/*
199
 * do_fast_IRQ handles IRQ's that don't need the fancy interrupt return
200
 * stuff - the handler is also running with interrupts disabled unless
201
 * it explicitly enables them later.
202
 */
203
asmlinkage void do_fast_IRQ(int irq)
204
{
205
        struct irqaction * action = *(irq + irq_action);
206
        int do_random = 0;
207
 
208
        kstat.interrupts[irq]++;
209
 
210
        while (action) {
211
                do_random |= action->flags;
212
                action->handler(irq, action->dev_id, NULL);
213
                action = action->next;
214
        }
215
        if (do_random & SA_SAMPLE_RANDOM)
216
                add_interrupt_randomness(irq);
217
}
218
 
219
#define SA_PROBE SA_ONESHOT
220
 
221
int setup_arm_irq(int irq, struct irqaction * new)
222
{
223
        int shared = 0;
224
        struct irqaction *old, **p;
225
        unsigned long flags;
226
 
227
        p = irq_action + irq;
228
 
229
        if ((old = *p) != NULL) {
230
                /* Can't share interrupts unless both agree to */
231
                if (!(old->flags & new->flags & SA_SHIRQ))
232
                        return -EBUSY;
233
 
234
                /* Can't share interrupts unless both are same type */
235
                if ((old->flags ^ new->flags) & SA_INTERRUPT)
236
                        return -EBUSY;
237
 
238
                /* add new interrupt at end of irq queue */
239
                do {
240
                        p = &old->next;
241
                        old = *p;
242
                } while (old);
243
                shared = 1;
244
        }
245
 
246
        if (new->flags & SA_SAMPLE_RANDOM)
247
                rand_initialize_irq(irq);
248
 
249
        save_flags_cli(flags);
250
 
251
        *p = new;
252
 
253
        if (!shared) {
254
                if (irq < 24) {
255
                        if (!(new->flags & SA_PROBE)) { /* SA_ONESHOT is used by probing */
256
                                if (new->flags & SA_INTERRUPT)
257
                                        irqjump[irq] = fast_interrupt[irq];
258
                                else
259
                                        irqjump[irq] = interrupt[irq];
260
                        } else
261
                                irqjump[irq] = probe_interrupt[irq];
262
                }
263
                unmask_irq(irq);
264
        }
265
        restore_flags(flags);
266
        return 0;
267
}
268
 
269
/*
270
 * Using "struct sigaction" is slightly silly, but there
271
 * are historical reasons and it works well, so..
272
 */
273
int request_irq(unsigned int irq, void (*handler)(int, void *, struct pt_regs *),
274
                 unsigned long irq_flags, const char * devname, void *dev_id)
275
{
276
        unsigned long retval;
277
        struct irqaction *action;
278
 
279
        if (irq >= NR_IRQS || !(validirqs[irq >> 5] & (1 << (irq & 31))))
280
                return -EINVAL;
281
        if (!handler)
282
                return -EINVAL;
283
 
284
        action = (struct irqaction *)kmalloc(sizeof(struct irqaction), GFP_KERNEL);
285
        if (!action)
286
                return -ENOMEM;
287
 
288
        action->handler = handler;
289
        action->flags = irq_flags;
290
        action->mask = 0;
291
        action->name = devname;
292
        action->next = NULL;
293
        action->dev_id = dev_id;
294
 
295
        retval = setup_arm_irq(irq, action);
296
 
297
        if (retval)
298
                kfree(action);
299
        return retval;
300
}
301
 
302
void free_irq(unsigned int irq, void *dev_id)
303
{
304
        struct irqaction * action, **p;
305
        unsigned long flags;
306
 
307
        if (irq >= NR_IRQS || !(validirqs[irq >> 5] & (1 << (irq & 31)))) {
308
                printk (KERN_ERR "Trying to free IRQ%d\n",irq);
309
#ifdef CONFIG_DEBUG_ERRORS
310
                __backtrace();
311
#endif
312
                return;
313
        }
314
 
315
        for (p = irq + irq_action; (action = *p) != NULL; p = &action->next) {
316
                if (action->dev_id != dev_id)
317
                        continue;
318
 
319
                /* Found it - now free it */
320
                save_flags_cli (flags);
321
                *p = action->next;
322
                if (!irq_action[irq]) {
323
                        mask_irq(irq);
324
                        if (irq < 24)
325
                                irqjump[irq] = bad_interrupt[irq];
326
                }
327
                restore_flags (flags);
328
                kfree(action);
329
                return;
330
        }
331
        printk(KERN_ERR "Trying to free free IRQ%d\n",irq);
332
#ifdef CONFIG_DEBUG_ERRORS
333
        __backtrace();
334
#endif
335
}
336
 
337
unsigned long probe_irq_on (void)
338
{
339
        unsigned int i, irqs = 0, irqmask;
340
        unsigned long delay;
341
 
342
        /* first snaffle up any unassigned irqs */
343
        for (i = 15; i > 0; i--) {
344
                if (!request_irq (i, no_action, SA_PROBE, "probe", NULL))
345
                        irqs |= 1 << i;
346
        }
347
 
348
        /* wait for spurious interrupts to mask themselves out again */
349
        for (delay = jiffies + 2; delay > jiffies; ); /* min 10ms delay */
350
 
351
        /* now filter out any obviously spurious interrupts */
352
        irqmask = ~get_enabled_irqs();
353
        for (i = 15; i > 0; i--) {
354
                if (irqs & (1 << i) & irqmask) {
355
                        irqs ^= 1 << i;
356
                        free_irq (i, NULL);
357
                }
358
        }
359
        return irqs;
360
}
361
 
362
int probe_irq_off (unsigned long irqs)
363
{
364
        unsigned int i, irqmask;
365
 
366
        irqmask = ~get_enabled_irqs();
367
 
368
        for (i = 15; i > 0; i--) {
369
                if (irqs & (1 << i))
370
                        free_irq (i, NULL);
371
        }
372
 
373
        irqs &= irqmask;
374
        if (!irqs)
375
                return 0;
376
        i = ffz (~irqs);
377
        if (irqs != (irqs & (1 << i)))
378
                i = -i;
379
        return i;
380
}
381
 
382
void init_IRQ(void)
383
{
384
        extern void init_dma(void);
385
        irq_init_irq();
386
        init_dma();
387
}

powered by: WebSVN 2.1.0

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