diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 790cfac9a..d4b02a230 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -201,7 +201,7 @@ int create_vm(struct vm_description *vm_desc, struct vm **rtn_vm) /* Create virtual uart */ vm->vuart = vuart_init(vm); } - vm->vpic = vpic_init(vm); + vpic_init(vm); #ifdef CONFIG_PARTITION_MODE /* Create virtual uart */ @@ -240,10 +240,6 @@ err: vioapic_cleanup(vm->arch_vm.virt_ioapic); } - if (vm->vpic != NULL) { - vpic_cleanup(vm); - } - if (vm->arch_vm.m2p != NULL) { free(vm->arch_vm.m2p); } @@ -314,9 +310,6 @@ int shutdown_vm(struct vm *vm) free_vm_id(vm); #endif - if (vm->vpic != NULL) { - vpic_cleanup(vm); - } #ifdef CONFIG_PARTITION_MODE vpci_cleanup(vm); diff --git a/hypervisor/arch/x86/virq.c b/hypervisor/arch/x86/virq.c index e11bfe3ca..43702a00a 100644 --- a/hypervisor/arch/x86/virq.c +++ b/hypervisor/arch/x86/virq.c @@ -156,7 +156,7 @@ static int vcpu_do_pending_extint(struct vcpu *vcpu) /* check if there is valid interrupt from vPIC, if yes just inject it */ /* PIC only connect with primary CPU */ primary = get_primary_vcpu(vm); - if ((vm->vpic != NULL) && vcpu == primary) { + if (vcpu == primary) { vpic_pending_intr(vcpu->vm, &vector); if (vector <= NR_MAX_VECTOR) { diff --git a/hypervisor/debug/vuart.c b/hypervisor/debug/vuart.c index 73b750052..37b272e8e 100644 --- a/hypervisor/debug/vuart.c +++ b/hypervisor/debug/vuart.c @@ -125,14 +125,11 @@ static void vuart_toggle_intr(struct vuart *vu) intr_reason = vuart_intr_reason(vu); if (intr_reason != IIR_NOPEND) { - if (vu->vm->vpic != NULL) { - vpic_assert_irq(vu->vm, COM1_IRQ); - } + vpic_assert_irq(vu->vm, COM1_IRQ); vioapic_assert_irq(vu->vm, COM1_IRQ); - if (vu->vm->vpic != NULL) { - vpic_deassert_irq(vu->vm, COM1_IRQ); - } + + vpic_deassert_irq(vu->vm, COM1_IRQ); vioapic_deassert_irq(vu->vm, COM1_IRQ); } diff --git a/hypervisor/dm/vpic.c b/hypervisor/dm/vpic.c index 260f1f62c..162622d31 100644 --- a/hypervisor/dm/vpic.c +++ b/hypervisor/dm/vpic.c @@ -35,8 +35,6 @@ /* TODO: add spinlock_locked support? */ /*#define VPIC_LOCKED(vpic) spinlock_locked(&((vpic)->lock))*/ -#define vm_pic(vm) (vm->vpic) - #define ACRN_DBG_PIC 6U enum irqstate { @@ -45,34 +43,6 @@ enum irqstate { IRQSTATE_PULSE }; -struct i8259_reg_state { - bool ready; - uint8_t icw_num; - uint8_t rd_cmd_reg; - - bool aeoi; - bool poll; - bool rotate; - bool sfn; /* special fully-nested mode */ - - uint32_t irq_base; - uint8_t request; /* Interrupt Request Register (IIR) */ - uint8_t service; /* Interrupt Service (ISR) */ - uint8_t mask; /* Interrupt Mask Register (IMR) */ - uint8_t smm; /* special mask mode */ - - int acnt[8]; /* sum of pin asserts and deasserts */ - uint8_t lowprio; /* lowest priority irq */ - - bool intr_raised; - uint8_t elc; -}; - -struct acrn_vpic { - struct vm *vm; - spinlock_t lock; - struct i8259_reg_state i8259[2]; -}; #define NR_VPIC_PINS_PER_CHIP 8U #define NR_VPIC_PINS_TOTAL 16U @@ -921,27 +891,13 @@ static void vpic_register_io_handler(struct vm *vm) &vpic_elc_io_read, &vpic_elc_io_write); } -void *vpic_init(struct vm *vm) +void vpic_init(struct vm *vm) { - struct acrn_vpic *vpic; - + struct acrn_vpic *vpic = vm_pic(vm); vpic_register_io_handler(vm); - - vpic = calloc(1U, sizeof(struct acrn_vpic)); - ASSERT(vpic != NULL, ""); - vpic->vm = vm; - vpic->i8259[0].mask = 0xffU; - vpic->i8259[1].mask = 0xffU; + vm->arch_vm.vpic.vm = vm; + vm->arch_vm.vpic.i8259[0].mask = 0xffU; + vm->arch_vm.vpic.i8259[1].mask = 0xffU; VPIC_LOCK_INIT(vpic); - - return vpic; -} - -void vpic_cleanup(struct vm *vm) -{ - if (vm->vpic != NULL) { - free(vm->vpic); - vm->vpic = NULL; - } } diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index b2355eb86..7cfbdb9ab 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -99,6 +99,7 @@ struct vm_arch { void *iobitmap[2];/* IO bitmap page array base address for this VM */ void *msr_bitmap; /* MSR bitmap page base address for this VM */ void *virt_ioapic; /* Virtual IOAPIC base address */ + struct acrn_vpic vpic; /* Virtual PIC */ /** * A link to the IO handler of this VM. * We only register io handle to this link @@ -125,7 +126,6 @@ struct vcpuid_entry { uint32_t padding; }; -struct acrn_vpic; struct vm { uint16_t vm_id; /* Virtual machine identifier */ struct vm_hw_info hw; /* Reference to this VM's HW information */ @@ -134,7 +134,6 @@ struct vm { struct vm_arch arch_vm; /* Reference to this VM's arch information */ enum vm_state state; /* VM state */ void *vuart; /* Virtual UART */ - struct acrn_vpic *vpic; /* Virtual PIC */ enum vpic_wire_mode wire_mode; struct iommu_domain *iommu; /* iommu domain of this VM */ struct list_head list; /* list of VM */ @@ -244,6 +243,12 @@ static inline struct vcpu *get_primary_vcpu(struct vm *vm) return NULL; } +static inline struct acrn_vpic * +vm_pic(struct vm *vm) +{ + return (struct acrn_vpic *)&(vm->arch_vm.vpic); +} + int shutdown_vm(struct vm *vm); void pause_vm(struct vm *vm); void resume_vm(struct vm *vm); diff --git a/hypervisor/include/arch/x86/guest/vpic.h b/hypervisor/include/arch/x86/guest/vpic.h index a44bf8dd6..0b84f8f9a 100644 --- a/hypervisor/include/arch/x86/guest/vpic.h +++ b/hypervisor/include/arch/x86/guest/vpic.h @@ -90,8 +90,36 @@ enum vpic_trigger { LEVEL_TRIGGER }; -void *vpic_init(struct vm *vm); -void vpic_cleanup(struct vm *vm); +struct i8259_reg_state { + bool ready; + uint8_t icw_num; + uint8_t rd_cmd_reg; + + bool aeoi; + bool poll; + bool rotate; + bool sfn; /* special fully-nested mode */ + + uint32_t irq_base; + uint8_t request; /* Interrupt Request Register (IIR) */ + uint8_t service; /* Interrupt Service (ISR) */ + uint8_t mask; /* Interrupt Mask Register (IMR) */ + uint8_t smm; /* special mask mode */ + + int acnt[8]; /* sum of pin asserts and deasserts */ + uint8_t lowprio; /* lowest priority irq */ + + bool intr_raised; + uint8_t elc; +}; + +struct acrn_vpic { + struct vm *vm; + spinlock_t lock; + struct i8259_reg_state i8259[2]; +}; + +void vpic_init(struct vm *vm); void vpic_assert_irq(struct vm *vm, uint32_t irq); void vpic_deassert_irq(struct vm *vm, uint32_t irq); diff --git a/hypervisor/include/arch/x86/hv_arch.h b/hypervisor/include/arch/x86/hv_arch.h index 21d29734c..9ed99011d 100644 --- a/hypervisor/include/arch/x86/hv_arch.h +++ b/hypervisor/include/arch/x86/hv_arch.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +33,6 @@ #include #include -#include #include #include #include