X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fapic.c;h=6fdce71bc0395216576ec846ddef3ab8e7541596;hb=2201970a66ded078c9228c9e4053189a00f0a882;hp=92e66833fe70e71ebaed4ee681b116605fc5e9fc;hpb=ee177da9b30ebf340c63fb5b9d535c729f90134d;p=palacios.git diff --git a/palacios/src/devices/apic.c b/palacios/src/devices/apic.c index 92e6683..6fdce71 100644 --- a/palacios/src/devices/apic.c +++ b/palacios/src/devices/apic.c @@ -24,7 +24,7 @@ #include -#ifndef DEBUG_APIC +#ifndef CONFIG_DEBUG_APIC #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -333,11 +333,11 @@ static int apic_do_eoi(struct apic_state * apic) { uchar_t flag = 0x1 << minor_offset; uchar_t * svc_location = apic->int_svc_reg + major_offset; - PrintDebug("Received APIC EOI\n"); + PrintDebug("Received APIC EOI for IRQ %d\n", isr_irq); *svc_location &= ~flag; -#ifdef CRAY_XT +#ifdef CONFIG_CRAY_XT if ((isr_irq == 238) || (isr_irq == 239)) { @@ -875,7 +875,7 @@ static int apic_get_intr_number(void * private_data) { } static int apic_raise_intr(void * private_data, int irq) { -#ifdef CRAY_XT +#ifdef CONFIG_CRAY_XT // The Seastar is connected directly to the LAPIC via LINT0 on the ICC bus if (irq == 238) { @@ -904,7 +904,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); } @@ -979,7 +979,7 @@ static void apic_update_time(ullong_t cpu_cycles, ullong_t cpu_freq, void * priv } tmr_ticks = cpu_cycles >> shift_num; - PrintDebug("Timer Ticks: %p\n", (void *)tmr_ticks); + // PrintDebug("Timer Ticks: %p\n", (void *)tmr_ticks); if (tmr_ticks < apic->tmr_cur_cnt) { apic->tmr_cur_cnt -= tmr_ticks; @@ -991,6 +991,10 @@ 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 (activate_internal_irq(apic, APIC_TMR_INT) == -1) { PrintError("Could not raise Timer interrupt\n"); } @@ -1020,23 +1024,9 @@ static struct vm_timer_ops timer_ops = { }; -static int apic_init(struct vm_device * dev) { - struct guest_info * info = dev->vm; - struct apic_state * apic = (struct apic_state *)(dev->private_data); - - v3_register_intr_controller(dev->vm, &intr_ops, dev); - v3_add_timer(dev->vm, &timer_ops, dev); - - init_apic_state(apic); - - v3_hook_msr(info, BASE_ADDR_MSR, read_apic_msr, write_apic_msr, dev); - v3_hook_full_mem(info, apic->base_addr, apic->base_addr + PAGE_SIZE_4KB, apic_read, apic_write, dev); - return 0; -} - -static int apic_deinit(struct vm_device * dev) { +static int apic_free(struct vm_device * dev) { struct guest_info * info = dev->vm; v3_unhook_msr(info, BASE_ADDR_MSR); @@ -1045,21 +1035,39 @@ static int apic_deinit(struct vm_device * dev) { } -static struct vm_device_ops dev_ops = { - .init = apic_init, - .deinit = apic_deinit, +static struct v3_device_ops dev_ops = { + .free = apic_free, .reset = NULL, .start = NULL, .stop = NULL, }; -struct vm_device * v3_create_apic() { + +static int apic_init(struct guest_info * vm, void * cfg_data) { PrintDebug("Creating APIC\n"); struct apic_state * apic = (struct apic_state *)V3_Malloc(sizeof(struct apic_state)); - struct vm_device * device = v3_create_device("APIC", &dev_ops, apic); - - return device; + struct vm_device * dev = v3_allocate_device("LAPIC", &dev_ops, apic); + + if (v3_attach_device(vm, dev) == -1) { + PrintError("Could not attach device %s\n", "LAPIC"); + return -1; + } + + v3_register_intr_controller(vm, &intr_ops, dev); + v3_add_timer(vm, &timer_ops, dev); + + init_apic_state(apic); + + v3_hook_msr(vm, BASE_ADDR_MSR, read_apic_msr, write_apic_msr, dev); + + v3_hook_full_mem(vm, apic->base_addr, apic->base_addr + PAGE_SIZE_4KB, apic_read, apic_write, dev); + + return 0; } + + + +device_register("LAPIC", apic_init)