struct guest_info * core;
+ struct v3_timer * timer;
+
uint32_t eoi;
v3_lock_t lock;
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;
}
if (v3_attach_device(vm, dev) == -1) {
PrintError("apic: Could not attach device %s\n", dev_id);
+ V3_Free(apic_dev);
return -1;
}
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);