X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fio_apic.c;h=95392d00f832ba4333950e4053d0432f820b60fc;hp=70aae6f05b253807eb6175486c3d867cf479664e;hb=123a1ba27ea09c8fa77a1b36ce625b43d7c48b14;hpb=debb8d55e42ecf02a0967cbbed9247e707e99c7b diff --git a/palacios/src/devices/io_apic.c b/palacios/src/devices/io_apic.c index 70aae6f..95392d0 100644 --- a/palacios/src/devices/io_apic.c +++ b/palacios/src/devices/io_apic.c @@ -17,13 +17,13 @@ * redistribute, and modify it as specified in the file "V3VEE_LICENSE". */ -#include -#include +#include +#include #include +#include - -#ifndef DEBUG_IO_APIC +#ifndef CONFIG_DEBUG_IO_APIC #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -182,7 +182,7 @@ static int ioapic_read(addr_t guest_addr, void * dst, uint_t length, void * priv break; default: { - uint_t redir_index = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) & 0xfffffffe; + uint_t redir_index = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) >> 1; uint_t hi_val = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) % 1; if (redir_index > 0x3f) { @@ -227,7 +227,7 @@ static int ioapic_write(addr_t guest_addr, void * src, uint_t length, void * pri break; default: { - uint_t redir_index = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) & 0xfffffffe; + uint_t redir_index = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) >> 1; uint_t hi_val = (ioapic->index_reg - IOAPIC_REDIR_BASE_REG) % 1; @@ -254,20 +254,20 @@ static int ioapic_write(addr_t guest_addr, void * src, uint_t length, void * pri } /* Interrupt controller functions */ -static int ioapic_intr_pending(void * private_data) { +static int ioapic_intr_pending(struct guest_info * info, void * private_data) { return 0; } -static int ioapic_get_intr_number(void * private_data) { +static int ioapic_get_intr_number(struct guest_info * info, void * private_data) { return 0; } -static int ioapic_begin_irq(void * private_data, int irq) { +static int ioapic_begin_irq(struct guest_info * info, void * private_data, int irq) { return 0; } -static int ioapic_raise_irq(void * private_data, int irq) { +static int ioapic_raise_irq(struct guest_info * info, void * private_data, int irq) { struct vm_device * dev = (struct vm_device *)private_data; struct io_apic_state * ioapic = (struct io_apic_state *)(dev->private_data); struct redir_tbl_entry * irq_entry = NULL; @@ -281,14 +281,14 @@ static int ioapic_raise_irq(void * private_data, int irq) { if (irq_entry->mask == 0) { PrintDebug("IOAPIC Signalling APIC to raise INTR %d\n", irq_entry->vec); - v3_apic_raise_intr(ioapic->apic, irq_entry->vec); + v3_apic_raise_intr(info, ioapic->apic, irq_entry->vec); } return 0; } /* I don't know if we can do anything here.... */ -static int ioapic_lower_irq(void * private_data, int irq) { +static int ioapic_lower_irq(struct guest_info * info, void * private_data, int irq) { return 0; } @@ -301,30 +301,17 @@ static struct intr_ctrl_ops intr_ops = { }; -static int io_apic_init(struct vm_device * dev) { - struct guest_info * info = dev->vm; - struct io_apic_state * ioapic = (struct io_apic_state *)(dev->private_data); - - v3_register_intr_controller(dev->vm, &intr_ops, dev); - init_ioapic_state(ioapic); - - v3_hook_full_mem(info, ioapic->base_addr, ioapic->base_addr + PAGE_SIZE_4KB, - ioapic_read, ioapic_write, dev); - - return 0; -} -static int io_apic_deinit(struct vm_device * dev) { +static int io_apic_free(struct vm_device * dev) { // struct guest_info * info = dev->vm; return 0; } -static struct vm_device_ops dev_ops = { - .init = io_apic_init, - .deinit = io_apic_deinit, +static struct v3_device_ops dev_ops = { + .free = io_apic_free, .reset = NULL, .start = NULL, .stop = NULL, @@ -332,13 +319,38 @@ static struct vm_device_ops dev_ops = { -struct vm_device * v3_create_io_apic(struct vm_device * apic) { +static int ioapic_init(struct guest_info * vm, v3_cfg_tree_t * cfg) { + struct vm_device * apic = v3_find_dev(vm, v3_cfg_val(cfg, "irq_bus")); + char * name = v3_cfg_val(cfg, "name"); + + if (!apic) { + PrintError("Could not locate APIC device (%s)\n", v3_cfg_val(cfg, "irq_bus")); + return -1; + } + PrintDebug("Creating IO APIC\n"); struct io_apic_state * ioapic = (struct io_apic_state *)V3_Malloc(sizeof(struct io_apic_state)); + ioapic->apic = apic; - struct vm_device * device = v3_create_device("IOAPIC", &dev_ops, ioapic); + struct vm_device * dev = v3_allocate_device(name, &dev_ops, ioapic); + + + if (v3_attach_device(vm, dev) == -1) { + PrintError("Could not attach device %s\n", name); + return -1; + } + - return device; + v3_register_intr_controller(vm, &intr_ops, dev); + init_ioapic_state(ioapic); + + v3_hook_full_mem(vm, ioapic->base_addr, ioapic->base_addr + PAGE_SIZE_4KB, + ioapic_read, ioapic_write, dev); + + return 0; } + + +device_register("IOAPIC", ioapic_init)