#ifdef __V3VEE__
#include <palacios/vmm_types.h>
-
+#include <palacios/vmm_list.h>
#define DE_EXCEPTION 0x00
#define DB_EXCEPTION 0x01
struct guest_info;
struct v3_interrupt;
-/* We need a way to allow the APIC/PIC to decide when they are supposed to receive interrupts...
- * Maybe a notification call when they have been turned on, to deliver irqs to them...
- * We can rehook the guest raise_irq op, to the appropriate controller
- */
struct v3_irq_hook {
};
+
+
+
struct v3_intr_state {
/* We need to rework the exception state, to handle stacking */
uint_t excp_error_code_valid : 1;
uint_t excp_error_code;
- struct intr_ctrl_ops * controller;
- void * controller_state;
+ struct list_head controller_list;
- /* some way to get the [A]PIC intr */
+ /* some way to get the [A]PIC intr */
struct v3_irq_hook * hooks[256];
};
-void v3_set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state);
+void v3_register_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state);
int v3_raise_exception(struct guest_info * info, uint_t excp);
int v3_raise_exception_with_error(struct guest_info * info, uint_t excp, uint_t error_code);
}
static int apic_raise_intr(void * private_data, int irq) {
- struct vm_device * dev = (struct vm_device *)private_data;
- struct apic_state * apic = (struct apic_state *)dev->private_data;
-
- return activate_apic_irq(apic, irq);
+ return 0;
}
static int apic_lower_intr(void * private_data, int irq) {
- struct vm_device * dev = (struct vm_device *)private_data;
- struct apic_state * apic = (struct apic_state *)dev->private_data;
- int major_offset = irq & ~0x00000007;
- int minor_offset = irq & 0x00000007;
- uchar_t * req_location = apic->int_req_reg + major_offset;
- uchar_t flag = 0x01 << minor_offset;
-
- *req_location &= ~flag;
-
return 0;
}
struct guest_info * info = dev->vm;
struct apic_state * apic = (struct apic_state *)(dev->private_data);
- v3_set_intr_controller(dev->vm, &intr_ops, dev);
+ v3_register_intr_controller(dev->vm, &intr_ops, dev);
v3_add_timer(dev->vm, &timer_ops, dev);
init_apic_state(apic);
+struct intr_controller {
+ struct intr_ctrl_ops * ctrl_ops;
+
+ void * priv_data;
+ struct list_head ctrl_node;
+};
+
+
void v3_init_interrupt_state(struct guest_info * info) {
info->intr_state.excp_pending = 0;
info->intr_state.excp_num = 0;
memset((uchar_t *)(info->intr_state.hooks), 0, sizeof(struct v3_irq_hook *) * 256);
}
-void v3_set_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state) {
- info->intr_state.controller = ops;
- info->intr_state.controller_state = state;
+void v3_register_intr_controller(struct guest_info * info, struct intr_ctrl_ops * ops, void * state) {
+ struct intr_controller * ctrlr = (struct intr_controller *)V3_Malloc(sizeof(struct intr_controller));
+
+ ctrlr->priv_data = state;
+ ctrlr->ctrl_ops = ops;
+
+ list_add(&(ctrlr->ctrl_node), &(info->intr_state.controller_list));
+
}
int v3_hook_passthrough_irq(struct guest_info * info, uint_t irq)
{
- int rc = v3_hook_irq(info,
- irq,
- passthrough_irq_handler,
- NULL);
+ int rc = v3_hook_irq(info, irq, passthrough_irq_handler, NULL);
if (rc) {
PrintError("guest_irq_injection: failed to hook irq 0x%x (guest=0x%p)\n", irq, (void *)info);
int v3_lower_irq(struct guest_info * info, int irq) {
- // Look up PIC and resend
- V3_ASSERT(info);
- V3_ASSERT(info->intr_state.controller);
- V3_ASSERT(info->intr_state.controller->lower_intr);
+ struct intr_controller * ctrl = NULL;
+ struct v3_intr_state * intr_state = &(info->intr_state);
PrintDebug("[v3_lower_irq]\n");
- if ((info->intr_state.controller) &&
- (info->intr_state.controller->lower_intr)) {
- info->intr_state.controller->lower_intr(info->intr_state.controller_state, irq);
- } else {
- PrintError("There is no registered Interrupt Controller... (NULL POINTER)\n");
- return -1;
+ list_for_each_entry(ctrl, &(intr_state->controller_list), ctrl_node) {
+ ctrl->ctrl_ops->lower_intr(ctrl->priv_data, irq);
}
-
+
return 0;
}
int v3_raise_irq(struct guest_info * info, int irq) {
- // Look up PIC and resend
- V3_ASSERT(info);
- V3_ASSERT(info->intr_state.controller);
- V3_ASSERT(info->intr_state.controller->raise_intr);
+ struct intr_controller * ctrl = NULL;
+ struct v3_intr_state * intr_state = &(info->intr_state);
PrintDebug("[v3_raise_irq]\n");
- if ((info->intr_state.controller) &&
- (info->intr_state.controller->raise_intr)) {
- info->intr_state.controller->raise_intr(info->intr_state.controller_state, irq);
- } else {
- PrintError("There is no registered Interrupt Controller... (NULL POINTER)\n");
- return -1;
+ list_for_each_entry(ctrl, &(intr_state->controller_list), ctrl_node) {
+ ctrl->ctrl_ops->raise_intr(ctrl->priv_data, irq);
}
return 0;
// PrintDebug("[intr_pending]\n");
if (intr_state->excp_pending == 1) {
return 1;
- } else if (intr_state->controller->intr_pending(intr_state->controller_state) == 1) {
- return 1;
- }
+ } else {
+ struct intr_controller * ctrl = NULL;
- /* Check [A]PIC */
+ list_for_each_entry(ctrl, &(intr_state->controller_list), ctrl_node) {
+ if (ctrl->ctrl_ops->intr_pending(ctrl->priv_data) == 1) {
+ return 1;
+ }
+ }
+ }
return 0;
}
if (intr_state->excp_pending == 1) {
return intr_state->excp_num;
- } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
- PrintDebug("[get_intr_number] intr_number = %d\n", intr_state->controller->get_intr_number(intr_state->controller_state));
- return intr_state->controller->get_intr_number(intr_state->controller_state);
- }
+ } else {
+ struct intr_controller * ctrl = NULL;
- /* someway to get the [A]PIC intr */
+ list_for_each_entry(ctrl, &(intr_state->controller_list), ctrl_node) {
+ if (ctrl->ctrl_ops->intr_pending(ctrl->priv_data)) {
+ uint_t intr_num = ctrl->ctrl_ops->get_intr_number(ctrl->priv_data);
+
+ PrintDebug("[get_intr_number] intr_number = %d\n", intr_num);
+
+ return intr_num;
+ }
+ }
+ }
return 0;
}
if (intr_state->excp_pending) {
PrintDebug("[get_intr_type] Exception\n");
return EXCEPTION;
- } else if (intr_state->controller->intr_pending(intr_state->controller_state)) {
- PrintDebug("[get_intr_type] External_irq\n");
- return EXTERNAL_IRQ;
+ } else {
+ struct intr_controller * ctrl = NULL;
+
+ list_for_each_entry(ctrl, &(intr_state->controller_list), ctrl_node) {
+ if (ctrl->ctrl_ops->intr_pending(ctrl->priv_data) == 1) {
+ PrintDebug("[get_intr_type] External_irq\n");
+ return EXTERNAL_IRQ;
+ }
+ }
}
- PrintDebug("[get_intr_type] Invalid_Intr\n");
+
+ PrintDebug("[get_intr_type] Invalid_Intr\n");
return INVALID_INTR;
}
intr_state->excp_error_code_valid = 0;
} else if (type == EXTERNAL_IRQ) {
- PrintDebug("[injecting_intr] External_Irq with intr_num = %x\n", intr_num);
- return intr_state->controller->begin_irq(intr_state->controller_state, intr_num);
+ struct intr_controller * ctrl = NULL;
+
+ list_for_each_entry(ctrl, &(intr_state->controller_list), ctrl_node) {
+ PrintDebug("[injecting_intr] External_Irq with intr_num = %x\n", intr_num);
+ ctrl->ctrl_ops->begin_irq(ctrl->priv_data, intr_num);
+ }
}
return 0;