From 9b24620e16dd03da735b0a812f549b42bb649111 Mon Sep 17 00:00:00 2001 From: Tw Date: Mon, 4 Mar 2019 13:51:41 +0800 Subject: [PATCH] hv: merge SBL and UEFI related stuff under boot This patch mainly unifies init_vm_boot_info's implementation between SBL and UEFI. Tracked-On: #2708 Signed-off-by: Tw Acked-by: Eddie Dong --- hypervisor/Makefile | 5 ----- hypervisor/arch/x86/guest/vm.c | 5 +++-- hypervisor/arch/x86/init.c | 1 + hypervisor/boot/acpi.c | 1 + hypervisor/boot/sbl/multiboot.c | 2 +- hypervisor/boot/uefi/uefi_boot.c | 16 ++++++++-------- hypervisor/bsp/firmware_sbl.c | 1 + hypervisor/bsp/firmware_uefi.c | 5 +++-- hypervisor/bsp/firmware_wrapper.c | 7 +++++++ hypervisor/bsp/include/firmware.h | 2 ++ hypervisor/bsp/include/firmware_sbl.h | 1 + hypervisor/bsp/include/firmware_uefi.h | 1 + hypervisor/include/arch/x86/guest/vm.h | 1 - 13 files changed, 29 insertions(+), 19 deletions(-) diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 57727a79a..41ededdb3 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -232,15 +232,10 @@ C_SRCS += bsp/firmware_uefi.c C_SRCS += bsp/cmdline.c C_SRCS += bsp/const_dmar.c -ifeq ($(CONFIG_PLATFORM_UEFI),y) C_SRCS += boot/uefi/uefi_boot.c -else -ifeq ($(CONFIG_PLATFORM_SBL),y) C_SRCS += boot/sbl/multiboot.c C_SRCS += boot/sbl/sbl_seed_parse.c C_SRCS += boot/sbl/abl_seed_parse.c -endif -endif # retpoline support ifeq (true, $(shell [ $(GCC_MAJOR) -eq 7 ] && [ $(GCC_MINOR) -ge 3 ] && echo true)) diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index 0add82e7b..23b4e625c 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -23,6 +23,7 @@ #include #include #include +#include vm_sw_loader_t vm_sw_loader; @@ -329,7 +330,7 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_ create_sos_vm_e820(vm); prepare_sos_vm_memmap(vm); - status = init_vm_boot_info(vm); + status = firmware_init_vm_boot_info(vm); if (status == 0) { init_fallback_iommu_domain(vm->iommu, vm->vm_id, vm->arch_vm.nworld_eptp); } else { @@ -358,7 +359,7 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_ #ifdef CONFIG_PARTITION_MODE create_prelaunched_vm_e820(vm); prepare_prelaunched_vm_memmap(vm, vm_config); - (void)init_vm_boot_info(vm); + (void)firmware_init_vm_boot_info(vm); #endif } diff --git a/hypervisor/arch/x86/init.c b/hypervisor/arch/x86/init.c index 40a32dfeb..dc5e4c160 100644 --- a/hypervisor/arch/x86/init.c +++ b/hypervisor/arch/x86/init.c @@ -14,6 +14,7 @@ #include #include #include +#include /* Push sp magic to top of stack for call trace */ #define SWITCH_TO(rsp, to) \ diff --git a/hypervisor/boot/acpi.c b/hypervisor/boot/acpi.c index 374e016fc..38eeb5651 100644 --- a/hypervisor/boot/acpi.c +++ b/hypervisor/boot/acpi.c @@ -28,6 +28,7 @@ */ #include +#include #include "acpi_priv.h" #include "acpi.h" diff --git a/hypervisor/boot/sbl/multiboot.c b/hypervisor/boot/sbl/multiboot.c index 7fe11f343..1934f0b13 100644 --- a/hypervisor/boot/sbl/multiboot.c +++ b/hypervisor/boot/sbl/multiboot.c @@ -111,7 +111,7 @@ static void *get_kernel_load_addr(void *kernel_src_addr) * @pre vm != NULL * @pre is_sos_vm(vm) == true */ -int32_t init_vm_boot_info(struct acrn_vm *vm) +int32_t sbl_init_vm_boot_info(struct acrn_vm *vm) { struct multiboot_module *mods = NULL; struct multiboot_info *mbi = NULL; diff --git a/hypervisor/boot/uefi/uefi_boot.c b/hypervisor/boot/uefi/uefi_boot.c index 8a89add30..4184113eb 100644 --- a/hypervisor/boot/uefi/uefi_boot.c +++ b/hypervisor/boot/uefi/uefi_boot.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include static int32_t uefi_sw_loader(struct acrn_vm *vm) { @@ -15,23 +15,23 @@ static int32_t uefi_sw_loader(struct acrn_vm *vm) /* get primary vcpu */ struct acrn_vcpu *vcpu = vcpu_from_vid(vm, BOOT_CPU_ID); struct acrn_vcpu_regs *vcpu_regs = &boot_context; - const struct efi_context *efi_ctx = get_efi_ctx(); - const struct lapic_regs *uefi_lapic_regs = get_efi_lapic_regs(); + const struct uefi_context *uefi_ctx = get_uefi_ctx(); + const struct lapic_regs *uefi_lapic_regs = get_uefi_lapic_regs(); pr_dbg("Loading guest to run-time location"); vlapic_restore(vcpu_vlapic(vcpu), uefi_lapic_regs); /* For UEFI platform, the bsp init regs come from two places: - * 1. saved in efi_boot: gpregs, rip + * 1. saved in uefi_boot: gpregs, rip * 2. saved when HV started: other registers - * We copy the info saved in efi_boot to boot_context and + * We copy the info saved in uefi_boot to boot_context and * init bsp with boot_context. */ memcpy_s(&(vcpu_regs->gprs), sizeof(struct acrn_gp_regs), - &(efi_ctx->vcpu_regs.gprs), sizeof(struct acrn_gp_regs)); + &(uefi_ctx->vcpu_regs.gprs), sizeof(struct acrn_gp_regs)); - vcpu_regs->rip = efi_ctx->vcpu_regs.rip; + vcpu_regs->rip = uefi_ctx->vcpu_regs.rip; set_vcpu_regs(vcpu, vcpu_regs); /* defer irq enabling till vlapic is ready */ @@ -40,7 +40,7 @@ static int32_t uefi_sw_loader(struct acrn_vm *vm) return ret; } -int32_t init_vm_boot_info(__unused struct acrn_vm *vm) +int32_t uefi_init_vm_boot_info(__unused struct acrn_vm *vm) { vm_sw_loader = uefi_sw_loader; diff --git a/hypervisor/bsp/firmware_sbl.c b/hypervisor/bsp/firmware_sbl.c index 188c3deac..603a8f4d5 100644 --- a/hypervisor/bsp/firmware_sbl.c +++ b/hypervisor/bsp/firmware_sbl.c @@ -36,6 +36,7 @@ static struct firmware_operations firmware_sbl_ops = { .get_ap_trampoline = sbl_get_ap_trampoline, .get_rsdp = sbl_get_rsdp, .init_irq = sbl_init_irq, + .init_vm_boot_info = sbl_init_vm_boot_info, }; struct firmware_operations* sbl_get_firmware_operations(void) diff --git a/hypervisor/bsp/firmware_uefi.c b/hypervisor/bsp/firmware_uefi.c index 5acb4b0c4..4ed1f97a8 100644 --- a/hypervisor/bsp/firmware_uefi.c +++ b/hypervisor/bsp/firmware_uefi.c @@ -34,13 +34,13 @@ static void uefi_init(void) } } -const struct uefi_context *get_efi_ctx(void) +const struct uefi_context *get_uefi_ctx(void) { uefi_init(); return &uefi_ctx; } -const struct lapic_regs *get_efi_lapic_regs(void) +const struct lapic_regs *get_uefi_lapic_regs(void) { uefi_init(); return &uefi_lapic_regs; @@ -80,6 +80,7 @@ static struct firmware_operations firmware_uefi_ops = { .get_ap_trampoline = uefi_get_ap_trampoline, .get_rsdp = uefi_get_rsdp, .init_irq = uefi_init_irq, + .init_vm_boot_info = uefi_init_vm_boot_info, }; struct firmware_operations* uefi_get_firmware_operations(void) diff --git a/hypervisor/bsp/firmware_wrapper.c b/hypervisor/bsp/firmware_wrapper.c index b29af49de..db6ce849a 100644 --- a/hypervisor/bsp/firmware_wrapper.c +++ b/hypervisor/bsp/firmware_wrapper.c @@ -9,6 +9,7 @@ #include #include #include +#include "platform_acpi_info.h" static struct firmware_operations *firmware_ops; @@ -77,3 +78,9 @@ void firmware_init_irq(void) { return firmware_ops->init_irq(); } + +/* @pre: firmware_ops->init_vm_boot_info != NULL */ +int32_t firmware_init_vm_boot_info(struct acrn_vm *vm) +{ + return firmware_ops->init_vm_boot_info(vm); +} diff --git a/hypervisor/bsp/include/firmware.h b/hypervisor/bsp/include/firmware.h index 2b284c932..c9a4fe52d 100644 --- a/hypervisor/bsp/include/firmware.h +++ b/hypervisor/bsp/include/firmware.h @@ -13,6 +13,7 @@ struct firmware_operations { uint64_t (*get_ap_trampoline)(void); void *(*get_rsdp)(void); void (*init_irq)(void); + int32_t (*init_vm_boot_info)(struct acrn_vm *vm); }; void init_firmware_operations(void); @@ -20,6 +21,7 @@ void init_firmware(void); uint64_t firmware_get_ap_trampoline(void); void *firmware_get_rsdp(void); void firmware_init_irq(void); +int32_t firmware_init_vm_boot_info(struct acrn_vm *vm); #ifndef CONFIG_CONSTANT_ACPI void acpi_fixup(void); diff --git a/hypervisor/bsp/include/firmware_sbl.h b/hypervisor/bsp/include/firmware_sbl.h index b4de2ce69..1ab2a3294 100644 --- a/hypervisor/bsp/include/firmware_sbl.h +++ b/hypervisor/bsp/include/firmware_sbl.h @@ -11,5 +11,6 @@ #include struct firmware_operations* sbl_get_firmware_operations(void); +int32_t sbl_init_vm_boot_info(struct acrn_vm *vm); #endif /* end of include guard: FIRMWARE_SBL_H */ diff --git a/hypervisor/bsp/include/firmware_uefi.h b/hypervisor/bsp/include/firmware_uefi.h index c9ea65a69..da6b3a676 100644 --- a/hypervisor/bsp/include/firmware_uefi.h +++ b/hypervisor/bsp/include/firmware_uefi.h @@ -19,5 +19,6 @@ const struct uefi_context *get_uefi_ctx(void); const struct lapic_regs *get_uefi_lapic_regs(void); struct firmware_operations* uefi_get_firmware_operations(void); +int32_t uefi_init_vm_boot_info(__unused struct acrn_vm *vm); #endif /* end of include guard: FIRMWARE_UEFI_H */ diff --git a/hypervisor/include/arch/x86/guest/vm.h b/hypervisor/include/arch/x86/guest/vm.h index b99fc6d9a..bddc2a48a 100644 --- a/hypervisor/include/arch/x86/guest/vm.h +++ b/hypervisor/include/arch/x86/guest/vm.h @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include