Subversion Repositories shark

Rev

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