2 #include <palacios/vmm_irq.h>
3 #include <palacios/vmm.h>
5 void init_irq_map(struct vmm_irq_map * map) {
11 int add_irq_hook(struct vmm_irq_map * map, struct vmm_irq_hook * hook) {
16 } else if (map->head->irq > hook->irq) {
17 hook->next = map->head;
19 map->head->prev = hook;
25 struct vmm_irq_hook * tmp_hook = map->head;
26 while ((tmp_hook->next) &&
27 (tmp_hook->next->irq <= hook->irq)) {
28 tmp_hook = tmp_hook->next;
31 if (tmp_hook->irq == hook->irq) {
34 hook->prev = tmp_hook;
35 hook->next = tmp_hook->next;
38 tmp_hook->next->prev = hook;
41 tmp_hook->next = hook;
51 int remove_irq_hook(struct vmm_irq_map * map, struct vmm_irq_hook * hook) {
52 if (map->head == hook) {
53 map->head = hook->next;
54 } else if (hook->prev) {
55 hook->prev->next = hook->next;
61 hook->next->prev = hook->prev;
70 int hook_irq(struct vmm_irq_map * map, uint_t irq,
71 int(*handler)(uint_t irq, void * private_data),
72 void * private_data) {
74 struct vmm_irq_hook * hook = NULL;
75 VMMMalloc(struct vmm_irq_hook *, hook, sizeof(struct vmm_irq_hook));
83 hook->handler = handler;
84 hook->private_data = private_data;
88 if (add_irq_hook(map, hook) != 0) {
97 int unhook_irq(struct vmm_irq_map * map, uint_t irq) {
98 struct vmm_irq_hook * hook = get_irq_hook(map, irq);
104 remove_irq_hook(map, hook);
109 struct vmm_irq_hook * get_irq_hook(struct vmm_irq_map * map, uint_t irq) {
110 struct vmm_irq_hook * tmp_hook = map->head;
113 if (tmp_hook->irq == irq) {
116 tmp_hook = tmp_hook->next;