1 #include <palacios/vmm_intr.h>
2 #include <palacios/vmm.h>
4 #include <palacios/vm_guest.h>
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;
12 info->vm_ops.raise_irq = &raise_irq;
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;
28 int hook_irq(struct guest_info * info, int irq) {
29 extern struct vmm_os_hooks * os_hooks;
31 return os_hooks->hook_interrupt(info, irq);
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);
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;
49 int raise_exception(struct guest_info * info, uint_t excp) {
50 struct vm_intr * intr_state = &(info->intr_state);
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;
65 int raise_irq(struct guest_info * info, int irq) {
66 // Look up PIC and resend
68 V3_ASSERT(info->intr_state.controller);
69 V3_ASSERT(info->intr_state.controller->raise_intr);
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);
75 // PrintDebug("There is no registered Interrupt Controller... (NULL POINTER)\n");
91 int intr_pending(struct guest_info * info) {
92 struct vm_intr * intr_state = &(info->intr_state);
94 if (intr_state->excp_pending) {
96 } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
106 uint_t get_intr_number(struct guest_info * info) {
107 struct vm_intr * intr_state = &(info->intr_state);
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);
115 /* someway to get the [A]PIC intr */
121 intr_type_t get_intr_type(struct guest_info * info) {
122 struct vm_intr * intr_state = &(info->intr_state);
124 if (intr_state->excp_pending) {
126 } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
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);
141 if (type == EXCEPTION) {
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;
148 } else if (type == EXTERNAL_IRQ) {
149 return intr_state->controller->begin_irq(intr_state->controller_state, intr_num);