diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 511d45568..aebb8a06a 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -168,9 +168,8 @@ C_SRCS += boot/dmar_info.c C_SRCS += boot/cmdline.c C_SRCS += boot/guest/vboot_wrapper.c C_SRCS += boot/guest/deprivilege_boot.c -C_SRCS += boot/guest/deprivilege_boot_info.c C_SRCS += boot/guest/direct_boot.c -C_SRCS += boot/guest/direct_boot_info.c +C_SRCS += boot/guest/vboot_info.c S_SRCS += arch/x86/idt.S C_SRCS += arch/x86/ioapic.c diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index e70778bdc..a568a069c 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -23,6 +23,7 @@ #include #include #include +#include #include vm_sw_loader_t vm_sw_loader; @@ -666,10 +667,6 @@ void prepare_vm(uint16_t vm_id, struct acrn_vm_config *vm_config) } if (err == 0) { - if (vm_sw_loader == NULL) { - vm_sw_loader = general_sw_loader; - } - (void )vm_sw_loader(vm); /* start vm BSP automatically */ diff --git a/hypervisor/boot/guest/deprivilege_boot.c b/hypervisor/boot/guest/deprivilege_boot.c index 88a3ffbac..20e844ba6 100644 --- a/hypervisor/boot/guest/deprivilege_boot.c +++ b/hypervisor/boot/guest/deprivilege_boot.c @@ -63,23 +63,9 @@ static void* get_depri_boot_rsdp(void) return hpa2hva((uint64_t)(depri_boot_ctx.rsdp)); } -static void depri_boot_spurious_handler(uint32_t vector) -{ - if (get_pcpu_id() == BOOT_CPU_ID) { - struct acrn_vcpu *vcpu = per_cpu(vcpu, BOOT_CPU_ID); - - if (vcpu != NULL) { - vlapic_set_intr(vcpu, vector, LAPIC_TRIG_EDGE); - } else { - pr_err("%s vcpu or vlapic is not ready, interrupt lost\n", __func__); - } - } -} - static void init_depri_boot_irq(void) { - spurious_handler = (spurious_handler_t)depri_boot_spurious_handler; - /* we defer irq enabling till vlapic is ready */ + /* nothing to do for now */ } static struct vboot_operations depri_boot_ops = { @@ -87,7 +73,6 @@ static struct vboot_operations depri_boot_ops = { .get_ap_trampoline = get_depri_boot_ap_trampoline, .get_rsdp = get_depri_boot_rsdp, .init_irq = init_depri_boot_irq, - .init_vboot_info = init_depri_vboot_info, }; struct vboot_operations* get_deprivilege_boot_ops(void) diff --git a/hypervisor/boot/guest/deprivilege_boot_info.c b/hypervisor/boot/guest/deprivilege_boot_info.c deleted file mode 100644 index 6350edc68..000000000 --- a/hypervisor/boot/guest/deprivilege_boot_info.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2018 Intel Corporation. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include -#include -#include -#include -#include - -static int32_t depri_boot_sw_loader(struct acrn_vm *vm) -{ - int32_t ret = 0; - /* get primary vcpu */ - struct acrn_vcpu *vcpu = vcpu_from_vid(vm, BOOT_CPU_ID); - struct acrn_vcpu_regs *vcpu_regs = &boot_context; - const struct depri_boot_context *depri_boot_ctx = get_depri_boot_ctx(); - const struct lapic_regs *depri_boot_lapic_regs = get_depri_boot_lapic_regs(); - - pr_dbg("Loading guest to run-time location"); - - vlapic_restore(vcpu_vlapic(vcpu), depri_boot_lapic_regs); - - /* For UEFI platform, the bsp init regs come from two places: - * 1. saved in depri_boot: gpregs, rip - * 2. saved when HV started: other registers - * We copy the info saved in depri_boot to boot_context and - * init bsp with boot_context. - */ - memcpy_s(&(vcpu_regs->gprs), sizeof(struct acrn_gp_regs), - &(depri_boot_ctx->vcpu_regs.gprs), sizeof(struct acrn_gp_regs)); - - vcpu_regs->rip = depri_boot_ctx->vcpu_regs.rip; - set_vcpu_regs(vcpu, vcpu_regs); - - /* defer irq enabling till vlapic is ready */ - CPU_IRQ_ENABLE(); - - return ret; -} - -int32_t init_depri_vboot_info(__unused struct acrn_vm *vm) -{ - vm_sw_loader = depri_boot_sw_loader; - - return 0; -} diff --git a/hypervisor/boot/guest/direct_boot.c b/hypervisor/boot/guest/direct_boot.c index f327df1a0..210b0bdcc 100644 --- a/hypervisor/boot/guest/direct_boot.c +++ b/hypervisor/boot/guest/direct_boot.c @@ -37,7 +37,6 @@ static struct vboot_operations direct_boot_ops = { .get_ap_trampoline = get_direct_boot_ap_trampoline, .get_rsdp = get_direct_boot_rsdp, .init_irq = init_direct_boot_irq, - .init_vboot_info = init_direct_vboot_info, }; struct vboot_operations* get_direct_boot_ops(void) diff --git a/hypervisor/boot/guest/direct_boot_info.c b/hypervisor/boot/guest/vboot_info.c similarity index 80% rename from hypervisor/boot/guest/direct_boot_info.c rename to hypervisor/boot/guest/vboot_info.c index 34725a439..63ebb22fd 100644 --- a/hypervisor/boot/guest/direct_boot_info.c +++ b/hypervisor/boot/guest/vboot_info.c @@ -1,11 +1,15 @@ /* - * Copyright (C) 2018 Intel Corporation. All rights reserved. + * Copyright (C) 2019 Intel Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ + #include #include #include +#include +#include +#include #include #include #include @@ -14,6 +18,7 @@ #include #include #include +#include #define ACRN_DBG_BOOT 6U @@ -150,16 +155,7 @@ static void *get_kernel_load_addr(void *kernel_src_addr) return (void *)zeropage; } -/** - * @param[inout] vm pointer to a vm descriptor - * - * @retval 0 on success - * @retval -EINVAL on invalid parameters - * - * @pre vm != NULL - * @pre is_sos_vm(vm) == true - */ -int32_t init_direct_vboot_info(struct acrn_vm *vm) +static int32_t init_general_vm_boot_info(struct acrn_vm *vm) { struct multiboot_module *mods = NULL; struct multiboot_info *mbi = NULL; @@ -238,3 +234,70 @@ int32_t init_direct_vboot_info(struct acrn_vm *vm) } return ret; } + +static void depri_boot_spurious_handler(uint32_t vector) +{ + if (get_pcpu_id() == BOOT_CPU_ID) { + struct acrn_vcpu *vcpu = per_cpu(vcpu, BOOT_CPU_ID); + + if (vcpu != NULL) { + vlapic_set_intr(vcpu, vector, LAPIC_TRIG_EDGE); + } else { + pr_err("%s vcpu or vlapic is not ready, interrupt lost\n", __func__); + } + } +} + +static int32_t depri_boot_sw_loader(struct acrn_vm *vm) +{ + int32_t ret = 0; + /* get primary vcpu */ + struct acrn_vcpu *vcpu = vcpu_from_vid(vm, BOOT_CPU_ID); + struct acrn_vcpu_regs *vcpu_regs = &boot_context; + const struct depri_boot_context *depri_boot_ctx = get_depri_boot_ctx(); + const struct lapic_regs *depri_boot_lapic_regs = get_depri_boot_lapic_regs(); + + pr_dbg("Loading guest to run-time location"); + + vlapic_restore(vcpu_vlapic(vcpu), depri_boot_lapic_regs); + + /* For UEFI platform, the bsp init regs come from two places: + * 1. saved in depri_boot: gpregs, rip + * 2. saved when HV started: other registers + * We copy the info saved in depri_boot to boot_context and + * init bsp with boot_context. + */ + memcpy_s(&(vcpu_regs->gprs), sizeof(struct acrn_gp_regs), + &(depri_boot_ctx->vcpu_regs.gprs), sizeof(struct acrn_gp_regs)); + + vcpu_regs->rip = depri_boot_ctx->vcpu_regs.rip; + set_vcpu_regs(vcpu, vcpu_regs); + + /* defer irq enabling till vlapic is ready */ + spurious_handler = depri_boot_spurious_handler; + CPU_IRQ_ENABLE(); + + return ret; +} + +/** + * @param[inout] vm pointer to a vm descriptor + * + * @retval 0 on success + * @retval -EINVAL on invalid parameters + * + * @pre vm != NULL + */ +int32_t init_vm_boot_info(struct acrn_vm *vm) +{ + int32_t ret = 0; + + if (is_sos_vm(vm) && (get_sos_boot_mode() == DEPRI_BOOT_MODE)) { + vm_sw_loader = depri_boot_sw_loader; + } else { + vm_sw_loader = direct_boot_sw_loader; + ret = init_general_vm_boot_info(vm); + } + + return ret; +} diff --git a/hypervisor/boot/guest/vboot_wrapper.c b/hypervisor/boot/guest/vboot_wrapper.c index 049240b0b..bffa16954 100644 --- a/hypervisor/boot/guest/vboot_wrapper.c +++ b/hypervisor/boot/guest/vboot_wrapper.c @@ -95,9 +95,3 @@ void init_vboot_irq(void) { return vboot_ops->init_irq(); } - -/* @pre: vboot_ops->init_vboot_info != NULL */ -int32_t init_vm_boot_info(struct acrn_vm *vm) -{ - return vboot_ops->init_vboot_info(vm); -} diff --git a/hypervisor/boot/include/guest/deprivilege_boot.h b/hypervisor/boot/include/guest/deprivilege_boot.h index 1a03a3090..4be920eb5 100644 --- a/hypervisor/boot/include/guest/deprivilege_boot.h +++ b/hypervisor/boot/include/guest/deprivilege_boot.h @@ -19,6 +19,5 @@ const struct depri_boot_context *get_depri_boot_ctx(void); const struct lapic_regs *get_depri_boot_lapic_regs(void); struct vboot_operations* get_deprivilege_boot_ops(void); -int32_t init_depri_vboot_info(__unused struct acrn_vm *vm); #endif /* end of include guard: DEPRIVILEGE_BOOT_H */ diff --git a/hypervisor/boot/include/guest/direct_boot.h b/hypervisor/boot/include/guest/direct_boot.h index f956f29f0..5f27b327e 100644 --- a/hypervisor/boot/include/guest/direct_boot.h +++ b/hypervisor/boot/include/guest/direct_boot.h @@ -11,6 +11,5 @@ #include struct vboot_operations* get_direct_boot_ops(void); -int32_t init_direct_vboot_info(struct acrn_vm *vm); #endif /* end of include guard: DIRECT_BOOT_H */ diff --git a/hypervisor/boot/include/guest/vboot.h b/hypervisor/boot/include/guest/vboot.h index 51b8a96c9..8802ca67d 100644 --- a/hypervisor/boot/include/guest/vboot.h +++ b/hypervisor/boot/include/guest/vboot.h @@ -13,19 +13,16 @@ enum vboot_mode { DEPRI_BOOT_MODE }; -struct acrn_vm; struct vboot_operations { void (*init)(void); uint64_t (*get_ap_trampoline)(void); void *(*get_rsdp)(void); void (*init_irq)(void); - int32_t (*init_vboot_info)(struct acrn_vm *vm); }; void init_vboot_operations(void); void init_vboot(void); void init_vboot_irq(void); -int32_t init_vm_boot_info(struct acrn_vm *vm); uint64_t get_ap_trampoline_buf(void); void *get_rsdp_ptr(void); diff --git a/hypervisor/boot/include/guest/vboot_info.h b/hypervisor/boot/include/guest/vboot_info.h new file mode 100644 index 000000000..7178c53f6 --- /dev/null +++ b/hypervisor/boot/include/guest/vboot_info.h @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2019 Intel Corporation. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef VBOOT_INFO_H + +#define VBOOT_INFO_H + +int32_t init_vm_boot_info(struct acrn_vm *vm); + +#endif /* end of include guard: VBOOT_INFO_H */ diff --git a/hypervisor/common/vm_load.c b/hypervisor/common/vm_load.c index 945505741..986331e90 100644 --- a/hypervisor/common/vm_load.c +++ b/hypervisor/common/vm_load.c @@ -97,7 +97,7 @@ static uint64_t create_zero_page(struct acrn_vm *vm) return gpa; } -int32_t general_sw_loader(struct acrn_vm *vm) +int32_t direct_boot_sw_loader(struct acrn_vm *vm) { int32_t ret = 0; char dyn_bootargs[100] = {0}; diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index 23421cec1..95b11e20f 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -210,7 +210,7 @@ uint16_t get_vmid_by_uuid(const uint8_t *uuid); struct acrn_vm *get_vm_from_vmid(uint16_t vm_id); struct acrn_vm *get_sos_vm(void); -int32_t general_sw_loader(struct acrn_vm *vm); +int32_t direct_boot_sw_loader(struct acrn_vm *vm); typedef int32_t (*vm_sw_loader_t)(struct acrn_vm *vm); extern vm_sw_loader_t vm_sw_loader;