1
2 #include <stdint.h>
3
4 #include <sys/kassert.h>
5 #include <sys/irq.h>
6
7 #include <machine/trap.h>
8 #include <machine/ioapic.h>
9
10 LIST_HEAD(IRQHandlerList, IRQHandler);
11 struct IRQHandlerList handlers[T_IRQ_LEN];
12
13 void
IRQ_Init()14 IRQ_Init()
15 {
16 int i;
17
18 for (i = 0; i < T_IRQ_LEN; i++)
19 {
20 LIST_INIT(&handlers[i]);
21 }
22 }
23
24 void
IRQ_Handler(int irq)25 IRQ_Handler(int irq)
26 {
27 struct IRQHandler *h;
28 LIST_FOREACH(h, &handlers[irq], link)
29 {
30 h->cb(h->arg);
31 }
32 }
33
34 void
IRQ_Register(int irq,struct IRQHandler * h)35 IRQ_Register(int irq, struct IRQHandler *h)
36 {
37 ASSERT(irq < T_IRQ_LEN);
38
39 LIST_INSERT_HEAD(&handlers[irq], h, link);
40
41 IOAPIC_Enable(irq);
42 }
43
44 void
IRQ_Unregister(int irq,struct IRQHandler * h)45 IRQ_Unregister(int irq, struct IRQHandler *h)
46 {
47 LIST_REMOVE(h, link);
48
49 if (LIST_EMPTY(&handlers[irq]))
50 IOAPIC_Disable(irq);
51 }
52
53