Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


reworked some of the interrupt handling
[palacios.git] / palacios / src / palacios / vmm_intr.c
1 #include <palacios/vmm_intr.h>
2 #include <palacios/vmm.h>
3
4 #include <palacios/vm_guest.h>
5
6
7 void init_interrupt_state(struct guest_info * info) {
8   info->intr_state.excp_pending = 0;
9   info->intr_state.excp_num = 0;
10   info->intr_state.excp_error_code = 0;
11
12   info->vm_ops.raise_irq = &raise_irq;
13 }
14
15 void set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state) {
16   info->intr_state.controller = ops;
17   info->intr_state.controller_state = state;
18 }
19
20
21
22
23
24
25
26
27
28 int hook_irq(struct guest_info * info, int irq) {
29   extern struct vmm_os_hooks * os_hooks;
30
31   return os_hooks->hook_interrupt(info, irq);
32 }
33
34 int raise_exception_with_error(struct guest_info * info, uint_t excp, uint_t error_code) {
35   struct vm_intr * intr_state = &(info->intr_state);
36
37   if (intr_state->excp_pending) {
38     intr_state->excp_pending = 1;
39     intr_state->excp_num = excp;
40     intr_state->excp_error_code = error_code;
41     intr_state->excp_error_code_valid = 1;
42   } else {
43     return -1;
44   }
45
46   return 0;
47 }
48
49 int raise_exception(struct guest_info * info, uint_t excp) {
50   struct vm_intr * intr_state = &(info->intr_state);
51
52   if (intr_state->excp_pending == 0) {
53     intr_state->excp_pending = 1;
54     intr_state->excp_num = excp;
55     intr_state->excp_error_code = 0;
56     intr_state->excp_error_code_valid = 0;
57   } else {
58     return -1;
59   }
60
61   return 0;
62 }
63
64
65 int raise_irq(struct guest_info * info, int irq, int error_code) {
66   // Look up PIC and resend
67   V3_ASSERT(info);
68   V3_ASSERT(info->intr_state.controller);
69   V3_ASSERT(info->intr_state.controller->raise_intr);
70
71   //  if ((info->intr_state.controller) && 
72   //  (info->intr_state.controller->raise_intr)) {
73     info->intr_state.controller->raise_intr(info->intr_state.controller_state, irq, error_code);
74     //} else {
75     // PrintDebug("There is no registered Interrupt Controller... (NULL POINTER)\n");
76     // return -1;
77     //}
78   return 0;
79 }
80
81
82
83
84
85
86
87
88
89
90
91 int intr_pending(struct guest_info * info) {
92   struct vm_intr * intr_state = &(info->intr_state);
93
94   if (intr_state->excp_pending) {
95     return 1;
96   } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
97     return 1;
98   }
99
100   /* Check [A]PIC */
101
102   return 0;
103 }
104
105
106 uint_t get_intr_number(struct guest_info * info) {
107   struct vm_intr * intr_state = &(info->intr_state);
108
109   if (intr_state->excp_pending) {
110     return intr_state->excp_num;
111   } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
112     return intr_state->controller->get_intr_number(intr_state->controller_state);
113   }
114
115   /* someway to get the [A]PIC intr */
116
117   return 0;
118 }
119
120
121 intr_type_t get_intr_type(struct guest_info * info) {
122  struct vm_intr * intr_state = &(info->intr_state);
123
124   if (intr_state->excp_pending) {
125     return EXCEPTION;
126   } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
127     return EXTERNAL_IRQ;
128   }
129
130   return INVALID_INTR;
131 }
132
133
134
135
136
137
138 int injecting_intr(struct guest_info * info, uint_t intr_num, intr_type_t type) {
139   struct vm_intr * intr_state = &(info->intr_state);
140
141   if (type == EXCEPTION) {
142
143     intr_state->excp_pending = 0;
144     intr_state->excp_num = 0;
145     intr_state->excp_error_code = 0;
146     intr_state->excp_error_code_valid = 0;
147     
148   } else if (type == EXTERNAL_IRQ) {
149     return intr_state->controller->begin_irq(intr_state->controller_state, intr_num);
150   }
151
152   return 0;
153 }