Subversion Repositories shark

Rev

Rev 1007 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
495 giacomo 1
#include <linuxcomp.h>
2
 
3
#include <asm/ptrace.h>
4
#include <asm-generic/errno-base.h>
5
#include <linux/kernel.h>
6
 
1007 mauro 7
#define MAX_IRQS (NR_IRQS +1)
495 giacomo 8
 
847 giacomo 9
#ifndef NIL
10
#define NIL     -1                      /*+ integer unvalid value   +*/
11
#endif
12
 
1019 mauro 13
//#define DEBUG_LINUX_INT
14
 
847 giacomo 15
struct int_handler {
16
        void (*func)(int, void *dev_id, struct pt_regs *);
17
        void *data;
18
        int flags;
19
        struct int_handler *next;
20
};
21
 
22
static struct irq_handler_list {
23
        struct int_handler *handlers;
24
} irq_list[MAX_IRQS];
25
 
26
void init_linux_irq();
27
extern void fast_call_intr(int no);
28
extern void* malloc(int size);
29
extern void free(void *ptr);
30
extern int handler_set(int no, void (*fast)(int), int pi, BYTE lock);
31
extern int handler_remove(int no);
32
 
33
unsigned long intr_count = 0;
34
static int init = 0;
35
 
495 giacomo 36
/*
847 giacomo 37
* Generic Linux interrupt handler.
38
*/
513 giacomo 39
void linux_intr(int irq)
495 giacomo 40
{
847 giacomo 41
        struct pt_regs regs;
42
        struct int_handler *ihp;
43
 
44
        intr_count++;
45
 
1019 mauro 46
#ifdef DEBUG_LINUX_INT
47
        printk("(linux_intr %d)", irq);
48
#endif
956 mauro 49
 
847 giacomo 50
        ihp=irq_list[irq].handlers;
51
        while (ihp) {
52
                (*ihp->func)(irq, ihp->data, &regs);
53
                ihp=ihp->next;
54
        }
55
 
56
        intr_count--;
57
 
495 giacomo 58
}
59
 
847 giacomo 60
void add_list(struct int_handler** headp, struct int_handler *ihp)
61
{
62
        if (*headp == NULL) {
63
                *headp=ihp;
64
                return;
65
        }
66
        ihp->next=*headp;
67
        *headp=ihp;
68
}
69
 
495 giacomo 70
/*
847 giacomo 71
* Attach a handler to an IRQ.
72
*/
495 giacomo 73
int request_irq(unsigned int irq, void (*handler)(int, void *dev_id, struct pt_regs *), unsigned long flags, const char *device, void *dev_id)
74
{
847 giacomo 75
        struct int_handler *ihp;
76
 
77
        if (init == 0)
78
                init_linux_irq();
79
 
80
        ihp=malloc(sizeof(struct int_handler));
81
        if (ihp == NULL)
82
                return -ENOMEM;
83
 
84
        if (irq_list[irq].handlers == NULL)
85
        {
1007 mauro 86
                //* Warning: check if irq is used from somebody that doesn't share! (Claudio ?!?)
87
                shark_handler_set(irq, linux_intr);
88
                //shark_handler_set(irq, NULL, NULL);
89
 
1019 mauro 90
#ifdef DEBUG_LINUX_INT
91
                printk("(request_irq %d)", irq);
92
#endif
847 giacomo 93
        }
94
        ihp->func = handler;
95
        ihp->flags = flags;
96
        ihp->data = dev_id;
97
        ihp->next = NULL;
98
        add_list(&irq_list[irq].handlers, ihp);
99
 
495 giacomo 100
        return 0;
101
}
102
 
103
/*
847 giacomo 104
* Deallocate an irq
105
*/
106
void free_irq(unsigned int irq, void *dev_id)
495 giacomo 107
{
847 giacomo 108
        struct int_handler **headp, *ihp;
513 giacomo 109
 
847 giacomo 110
        headp=&irq_list[irq].handlers;
111
        while (*headp)
112
        {
113
                ihp=*headp;
114
                if (ihp->data == dev_id)
115
                {
116
                        *headp=ihp->next;
117
                        free(ihp);
118
                        break;
119
                }
120
                headp=&ihp->next;
121
        }
513 giacomo 122
 
847 giacomo 123
        if (irq_list[irq].handlers == NULL)
124
        {
1007 mauro 125
                shark_handler_remove(irq);
126
 
1019 mauro 127
#ifdef DEBUG_LINUX_INT
128
                printk("(free_irq %d)", irq);
129
#endif
847 giacomo 130
        }
495 giacomo 131
}
847 giacomo 132
 
133
void init_linux_irq()
134
{
135
        int i;
136
 
137
        for (i=0; i<MAX_IRQS; i++)
138
        {
139
                irq_list[i].handlers = NULL;
140
        }
141
        init=1;
142
}