X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fapic.c;h=3ea76cb227f9c86f390533e9aefeff6fe1a177e9;hb=36c1666cf64c49302d906a79d8cafbf760452d86;hp=2d95008cc6b265ee647bf3301f47f468d6f6fcbc;hpb=82b8b87c344fcd1eab22e3f3be5ad54cbb3f8f68;p=palacios.git diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c index 2d95008..3ea76cb 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 @@ -181,8 +181,11 @@ struct apic_state { uint32_t eoi; + struct guest_info * core; }; +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; @@ -236,19 +239,32 @@ static void init_apic_state(struct apic_state * apic) { static int read_apic_msr(uint_t msr, v3_msr_t * dst, void * priv_data) { struct vm_device * dev = (struct vm_device *)priv_data; struct apic_state * apic = (struct apic_state *)dev->private_data; - PrintError("READING APIC BASE ADDR: HI=%x LO=%x\n", apic->base_addr_msr.hi, apic->base_addr_msr.lo); - - return -1; + dst->value = apic->base_addr; + return 0; } 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); - PrintError("WRITING APIC BASE ADDR: HI=%x LO=%x\n", src.hi, src.lo); + 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); - return -1; + apic->base_addr = src.value; + + 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; } @@ -267,6 +283,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 { @@ -337,7 +357,7 @@ static int apic_do_eoi(struct apic_state * apic) { *svc_location &= ~flag; -#ifdef CRAY_XT +#ifdef CONFIG_CRAY_XT if ((isr_irq == 238) || (isr_irq == 239)) { @@ -845,7 +865,7 @@ static int apic_write(addr_t guest_addr, void * src, uint_t length, void * priv_ /* Interrupt Controller Functions */ // returns 1 if an interrupt is pending, 0 otherwise -static int apic_intr_pending(void * private_data) { +static int apic_intr_pending(struct guest_info * info, void * private_data) { struct vm_device * dev = (struct vm_device *)private_data; struct apic_state * apic = (struct apic_state *)dev->private_data; int req_irq = get_highest_irr(apic); @@ -859,7 +879,7 @@ static int apic_intr_pending(void * private_data) { return 0; } -static int apic_get_intr_number(void * private_data) { +static int apic_get_intr_number(struct guest_info * info, void * private_data) { struct vm_device * dev = (struct vm_device *)private_data; struct apic_state * apic = (struct apic_state *)dev->private_data; int req_irq = get_highest_irr(apic); @@ -874,8 +894,8 @@ static int apic_get_intr_number(void * private_data) { return -1; } -static int apic_raise_intr(void * private_data, int irq) { -#ifdef CRAY_XT +static int apic_raise_intr(struct guest_info * info, void * private_data, int irq) { +#ifdef CONFIG_CRAY_XT // The Seastar is connected directly to the LAPIC via LINT0 on the ICC bus if (irq == 238) { @@ -885,14 +905,15 @@ static int apic_raise_intr(void * private_data, int irq) { return activate_apic_irq(apic, irq); } #endif + return 0; } -static int apic_lower_intr(void * private_data, int irq) { +static int apic_lower_intr(struct guest_info * info, void * private_data, int irq) { return 0; } -static int apic_begin_irq(void * private_data, int irq) { +static int apic_begin_irq(struct guest_info * info, 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) >> 3; @@ -904,7 +925,7 @@ static int apic_begin_irq(void * private_data, int irq) { *svc_location |= flag; *req_location &= ~flag; -#ifdef CRAY_XT +#ifdef CONFIG_CRAY_XT if ((irq == 238) || (irq == 239)) { PrintError("APIC: Begin IRQ %d (ISR=%x), (IRR=%x)\n", irq, *svc_location, *req_location); } @@ -915,15 +936,23 @@ static int apic_begin_irq(void * private_data, int irq) { -int v3_apic_raise_intr(struct vm_device * apic_dev, int intr_num) { +int v3_apic_raise_intr(struct guest_info * info, struct vm_device * apic_dev, int intr_num) { struct apic_state * apic = (struct apic_state *)apic_dev->private_data; - return activate_apic_irq(apic, intr_num); + + if (activate_apic_irq(apic, intr_num) == -1) { + PrintError("Error: Could not activate apic_irq\n"); + return -1; + } + + v3_interrupt_cpu(info, 0); + + return 0; } /* Timer Functions */ -static void apic_update_time(ullong_t cpu_cycles, ullong_t cpu_freq, void * priv_data) { +static void apic_update_time(struct guest_info * info, ullong_t cpu_cycles, ullong_t cpu_freq, void * priv_data) { struct vm_device * dev = (struct vm_device *)priv_data; struct apic_state * apic = (struct apic_state *)dev->private_data; // The 32 bit GCC runtime is a pile of shit @@ -991,8 +1020,8 @@ static void apic_update_time(ullong_t cpu_cycles, ullong_t cpu_freq, void * priv PrintDebug("Raising APIC Timer interrupt (periodic=%d) (icnt=%d) (div=%d)\n", apic->tmr_vec_tbl.tmr_mode, apic->tmr_init_cnt, shift_num); - if (apic_intr_pending(priv_data)) { - PrintDebug("Overriding pending IRQ %d\n", apic_get_intr_number(priv_data)); + if (apic_intr_pending(info, 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) { @@ -1027,9 +1056,9 @@ static struct vm_timer_ops timer_ops = { static int apic_free(struct vm_device * dev) { - struct guest_info * info = dev->vm; + // struct apic_state * apic = (struct apic_state *)dev->private_data; - v3_unhook_msr(info, BASE_ADDR_MSR); + v3_unhook_msr(dev->vm, BASE_ADDR_MSR); return 0; } @@ -1044,15 +1073,16 @@ static struct v3_device_ops dev_ops = { -static int apic_init(struct guest_info * vm, void * cfg_data) { +static int apic_init(struct v3_vm_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; }