X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fapic.c;h=18273669dc2d3c0e5707d7b25bedc8d7d1e81a4f;hb=1df601c90b519a54b64ca101fd6aa4c0a39bf0f0;hp=6eaa35fbe10d83c7faf9c1b0de9b754d81eeb2fb;hpb=b4aaeaa7233244ad9d607a0077dbbce719833fe0;p=palacios.git diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c index 6eaa35f..1827366 100644 --- a/palacios/src/devices/apic.c +++ b/palacios/src/devices/apic.c @@ -207,6 +207,8 @@ struct apic_state { struct guest_info * core; + struct v3_timer * timer; + uint32_t eoi; v3_lock_t lock; @@ -1463,13 +1465,27 @@ static struct v3_timer_ops timer_ops = { static int apic_free(struct vm_device * dev) { + struct apic_dev_state * apic_dev = (struct apic_dev_state *)dev->private_data; + int i = 0; + + for (i = 0; i < dev->vm->num_cores; i++) { + struct apic_state * apic = &(apic_dev->apics[i]); + struct guest_info * core = &(dev->vm->cores[i]); + + + // unregister intr controller - /* TODO: This should crosscall to force an unhook on each CPU */ + if (apic->timer) { + v3_remove_timer(core, apic->timer); + } + + // unhook memory - // struct apic_state * apic = (struct apic_state *)dev->private_data; + } v3_unhook_msr(dev->vm, BASE_ADDR_MSR); + V3_Free(apic_dev); return 0; } @@ -1501,6 +1517,7 @@ static int apic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { if (v3_attach_device(vm, dev) == -1) { PrintError("apic: Could not attach device %s\n", dev_id); + V3_Free(apic_dev); return -1; } @@ -1515,7 +1532,13 @@ static int apic_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { v3_register_intr_controller(core, &intr_ops, apic_dev); - v3_add_timer(core, &timer_ops, apic_dev); + apic->timer = v3_add_timer(core, &timer_ops, apic_dev); + + if (apic->timer == NULL) { + PrintError("APIC: Failed to attach timer to core %d\n", i); + v3_detach_device(dev); + return -1; + } v3_hook_full_mem(vm, core->cpu_id, apic->base_addr, apic->base_addr + PAGE_SIZE_4KB, apic_read, apic_write, apic_dev);