X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fapic.c;h=ccb89e3e82113225f8f774604982713d72cd3b3d;hp=098b87de05e4470a5107aeac9f17236439a0f41c;hb=123a1ba27ea09c8fa77a1b36ce625b43d7c48b14;hpb=19b2e4b4ce85ae4e683a3ede33360bdf7547b069 diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c index 098b87d..ccb89e3 100644 --- a/palacios/src/devices/apic.c +++ b/palacios/src/devices/apic.c @@ -22,7 +22,7 @@ #include #include #include - +#include #ifndef CONFIG_DEBUG_APIC #undef PrintDebug @@ -183,6 +183,8 @@ struct apic_state { }; +static int apic_read(addr_t guest_addr, void * dst, uint_t length, void * priv_data); +static int apic_write(addr_t guest_addr, void * src, uint_t length, void * priv_data); static void init_apic_state(struct apic_state * apic) { apic->base_addr = DEFAULT_BASE_ADDR; @@ -242,12 +244,26 @@ static int read_apic_msr(uint_t msr, v3_msr_t * dst, void * priv_data) { static int write_apic_msr(uint_t msr, v3_msr_t src, void * priv_data) { - // struct vm_device * dev = (struct vm_device *)priv_data; - // struct apic_state * apic = (struct apic_state *)dev->private_data; + struct vm_device * dev = (struct vm_device *)priv_data; + struct apic_state * apic = (struct apic_state *)dev->private_data; + struct v3_shadow_region * old_reg = v3_get_shadow_region(dev->vm, apic->base_addr); + + if (old_reg == NULL) { + // uh oh... + PrintError("APIC Base address region does not exit...\n"); + return -1; + } + + v3_delete_shadow_region(dev->vm, old_reg); - PrintError("WRITING APIC BASE ADDR: HI=%x LO=%x\n", src.hi, src.lo); + apic->base_addr = src.value; - return -1; + if (v3_hook_full_mem(dev->vm, apic->base_addr, apic->base_addr + PAGE_SIZE_4KB, apic_read, apic_write, dev) == -1) { + PrintError("Could not hook new APIC Base address\n"); + return -1; + } + + return 0; } @@ -266,6 +282,10 @@ static int activate_apic_irq(struct apic_state * apic, uint32_t irq_num) { PrintDebug("Raising APIC IRQ %d\n", irq_num); + if (*req_location & flag) { + V3_Print("Interrupts coallescing\n"); + } + if (*en_location & flag) { *req_location |= flag; } else { @@ -923,6 +943,8 @@ int v3_apic_raise_intr(struct guest_info * info, struct vm_device * apic_dev, in return -1; } + v3_interrupt_cpu(info, 0); + return 0; } @@ -998,7 +1020,7 @@ static void apic_update_time(ullong_t cpu_cycles, ullong_t cpu_freq, void * priv apic->tmr_vec_tbl.tmr_mode, apic->tmr_init_cnt, shift_num); if (apic_intr_pending(dev->vm, priv_data)) { - PrintDebug("Overriding pending IRQ %d\n", apic_get_intr_number(priv_data)); + PrintDebug("Overriding pending IRQ %d\n", apic_get_intr_number(dev->vm, priv_data)); } if (activate_internal_irq(apic, APIC_TMR_INT) == -1) { @@ -1050,15 +1072,16 @@ static struct v3_device_ops dev_ops = { -static int apic_init(struct guest_info * vm, void * cfg_data) { +static int apic_init(struct guest_info * vm, v3_cfg_tree_t * cfg) { PrintDebug("Creating APIC\n"); + char * name = v3_cfg_val(cfg, "name"); struct apic_state * apic = (struct apic_state *)V3_Malloc(sizeof(struct apic_state)); - struct vm_device * dev = v3_allocate_device("LAPIC", &dev_ops, apic); + struct vm_device * dev = v3_allocate_device(name, &dev_ops, apic); if (v3_attach_device(vm, dev) == -1) { - PrintError("Could not attach device %s\n", "LAPIC"); + PrintError("Could not attach device %s\n", name); return -1; }