Subversion Repositories shark

Rev

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