From 723ff1f4ee651decd9d63498f0f247f966b22377 Mon Sep 17 00:00:00 2001 From: Minggui Cao Date: Thu, 24 Jan 2019 14:03:23 +0800 Subject: [PATCH] HV: modularization improve UEFI macro control code 1. in UEFI bsp code, not need UEFI macro; it is controlled in makefile. 2. in vm/acpi/interrupt code, unify the API name for SBL & UEFI. 3. remove unnecessary header including and unused code. Tracked-On: #1842 Signed-off-by: Minggui Cao Reviewed-by: Jason Chen CJ --- efi-stub/Makefile | 2 +- efi-stub/boot.c | 2 +- hypervisor/Makefile | 1 + hypervisor/arch/x86/guest/guest.c | 1 - hypervisor/arch/x86/guest/vcpu.c | 1 - hypervisor/arch/x86/guest/vm.c | 5 ----- hypervisor/arch/x86/irq.c | 5 ++--- hypervisor/arch/x86/trampoline.c | 7 +------ hypervisor/arch/x86/vmx.c | 1 - hypervisor/boot/acpi.c | 5 +---- hypervisor/boot/uefi/uefi_boot.c | 7 ++----- hypervisor/bsp/include/bsp_extern.h | 21 +++---------------- .../vm0_boot.h => bsp/include/uefi/uefi.h} | 11 +++++----- hypervisor/bsp/sbl/sbl.c | 16 ++++++++++++++ hypervisor/bsp/uefi/uefi.c | 21 +++++++++---------- hypervisor/include/arch/x86/ioapic.h | 2 -- hypervisor/include/arch/x86/per_cpu.h | 1 - 17 files changed, 43 insertions(+), 66 deletions(-) rename hypervisor/{include/arch/x86/guest/vm0_boot.h => bsp/include/uefi/uefi.h} (63%) diff --git a/efi-stub/Makefile b/efi-stub/Makefile index da42a7d12..5b87d49b3 100644 --- a/efi-stub/Makefile +++ b/efi-stub/Makefile @@ -60,7 +60,7 @@ LDSCRIPT := $(GNUEFI_DIR)/elf_$(ARCH)_efi.lds INCDIR := $(SYSROOT)/usr/include CFLAGS=-I. -I.. -I../hypervisor/include/arch/x86/guest -I$(INCDIR)/efi -I$(INCDIR)/efi/$(ARCH) \ - -I../hypervisor/include/public -I../hypervisor/include/lib \ + -I../hypervisor/include/public -I../hypervisor/include/lib -I../hypervisor/bsp/include/uefi \ -DEFI_FUNCTION_WRAPPER -fPIC -fshort-wchar -ffreestanding \ -Wall -I../fs/ -D$(ARCH) -O2 \ -include config.h diff --git a/efi-stub/boot.c b/efi-stub/boot.c index 2360715df..7f91699de 100644 --- a/efi-stub/boot.c +++ b/efi-stub/boot.c @@ -37,7 +37,7 @@ #include "stdlib.h" #include "boot.h" #include "acrn_common.h" -#include "vm0_boot.h" +#include "uefi.h" EFI_SYSTEM_TABLE *sys_table; EFI_BOOT_SERVICES *boot; diff --git a/hypervisor/Makefile b/hypervisor/Makefile index 061beb098..8ab786b74 100644 --- a/hypervisor/Makefile +++ b/hypervisor/Makefile @@ -234,6 +234,7 @@ C_SRCS += dm/vpci/msix.c endif ifeq ($(CONFIG_PLATFORM_UEFI),y) +INCLUDE_PATH += bsp/include/uefi C_SRCS += bsp/uefi/uefi.c C_SRCS += bsp/uefi/cmdline.c C_SRCS += boot/uefi/uefi_boot.c diff --git a/hypervisor/arch/x86/guest/guest.c b/hypervisor/arch/x86/guest/guest.c index 5e08ee013..d8820fdc1 100644 --- a/hypervisor/arch/x86/guest/guest.c +++ b/hypervisor/arch/x86/guest/guest.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include diff --git a/hypervisor/arch/x86/guest/vcpu.c b/hypervisor/arch/x86/guest/vcpu.c index d67eb722b..72fc38d82 100644 --- a/hypervisor/arch/x86/guest/vcpu.c +++ b/hypervisor/arch/x86/guest/vcpu.c @@ -6,7 +6,6 @@ #include #include -#include #include #include diff --git a/hypervisor/arch/x86/guest/vm.c b/hypervisor/arch/x86/guest/vm.c index ee4f658de..0f45aedaf 100644 --- a/hypervisor/arch/x86/guest/vm.c +++ b/hypervisor/arch/x86/guest/vm.c @@ -9,7 +9,6 @@ #include #include #include -#include vm_sw_loader_t vm_sw_loader; @@ -142,11 +141,7 @@ int32_t create_vm(uint16_t vm_id, struct acrn_vm_config *vm_config, struct acrn_ rebuild_sos_vm_e820(); prepare_sos_vm_memmap(vm); -#ifndef CONFIG_EFI_STUB status = init_vm_boot_info(vm); -#else - status = efi_boot_init(); -#endif if (status == 0) { init_iommu_sos_vm_domain(vm); } else { diff --git a/hypervisor/arch/x86/irq.c b/hypervisor/arch/x86/irq.c index 56cdcdd8e..4dde399a5 100644 --- a/hypervisor/arch/x86/irq.c +++ b/hypervisor/arch/x86/irq.c @@ -468,7 +468,6 @@ void interrupt_init(uint16_t pcpu_id) set_idt(idtd); init_lapic(pcpu_id); init_default_irqs(pcpu_id); -#ifndef CONFIG_EFI_STUB - CPU_IRQ_ENABLE(); -#endif + + bsp_init_irq(); } diff --git a/hypervisor/arch/x86/trampoline.c b/hypervisor/arch/x86/trampoline.c index e652bf168..c94d6a285 100644 --- a/hypervisor/arch/x86/trampoline.c +++ b/hypervisor/arch/x86/trampoline.c @@ -6,7 +6,6 @@ #include #include #include -#include #include #include @@ -108,11 +107,7 @@ uint64_t prepare_trampoline(void) uint64_t size, dest_pa, i; size = (uint64_t)(&ld_trampoline_end - &ld_trampoline_start); -#ifndef CONFIG_EFI_STUB - dest_pa = e820_alloc_low_memory(CONFIG_LOW_RAM_SIZE); -#else - dest_pa = (uint64_t)get_ap_trampoline_buf(); -#endif + dest_pa = bsp_get_ap_trampoline(); pr_dbg("trampoline code: %llx size %x", dest_pa, size); diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c index 8cd1bd6a9..56506a52a 100644 --- a/hypervisor/arch/x86/vmx.c +++ b/hypervisor/arch/x86/vmx.c @@ -7,7 +7,6 @@ */ #include -#include #include /** diff --git a/hypervisor/boot/acpi.c b/hypervisor/boot/acpi.c index 8dc22ed78..5f8673c5b 100644 --- a/hypervisor/boot/acpi.c +++ b/hypervisor/boot/acpi.c @@ -30,7 +30,6 @@ #include #include "acpi_priv.h" #include "acpi.h" -#include #define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Ptr */ #define ACPI_OEM_ID_SIZE 6 @@ -138,9 +137,7 @@ static struct acpi_table_rsdp *get_rsdp(void) struct acpi_table_rsdp *rsdp = NULL; uint16_t *addr; -#ifdef CONFIG_EFI_STUB - rsdp = (struct acpi_table_rsdp *) get_rsdp_from_uefi(); -#endif + rsdp = (struct acpi_table_rsdp *)bsp_get_rsdp(); if (rsdp == NULL) { /* EBDA is addressed by the 16 bit pointer at 0x40E */ addr = (uint16_t *)hpa2hva(0x40eUL); diff --git a/hypervisor/boot/uefi/uefi_boot.c b/hypervisor/boot/uefi/uefi_boot.c index b854d179d..fb861349a 100644 --- a/hypervisor/boot/uefi/uefi_boot.c +++ b/hypervisor/boot/uefi/uefi_boot.c @@ -7,9 +7,7 @@ #include #include #include -#include - -#ifdef CONFIG_EFI_STUB +#include static void efi_spurious_handler(int32_t vector) { @@ -54,11 +52,10 @@ static int32_t uefi_sw_loader(struct acrn_vm *vm) return ret; } -int32_t efi_boot_init(void) +int32_t init_vm_boot_info(__unused struct acrn_vm *vm) { vm_sw_loader = uefi_sw_loader; spurious_handler = (spurious_handler_t)efi_spurious_handler; return 0; } -#endif diff --git a/hypervisor/bsp/include/bsp_extern.h b/hypervisor/bsp/include/bsp_extern.h index 2c0f08469..f63097465 100644 --- a/hypervisor/bsp/include/bsp_extern.h +++ b/hypervisor/bsp/include/bsp_extern.h @@ -23,29 +23,14 @@ #define UOS_DEFAULT_START_ADDR (0x100000000UL) -struct acpi_info { - uint8_t x86_family; - uint8_t x86_model; - struct pm_s_state_data pm_s_state; - /* TODO: we can add more acpi info field here if needed. */ -}; - -/**********************************/ -/* EXTERNAL VARIABLES */ -/**********************************/ /* BSP Interfaces */ void init_bsp(void); +uint64_t bsp_get_ap_trampoline(void); +void *bsp_get_rsdp(void); +void bsp_init_irq(void); #ifndef CONFIG_CONSTANT_ACPI void acpi_fixup(void); #endif -#ifdef CONFIG_EFI_STUB - -void *get_rsdp_from_uefi(void); -void *get_ap_trampoline_buf(void); -const struct efi_context *get_efi_ctx(void); -const struct lapic_regs *get_efi_lapic_regs(void); -#endif - #endif /* BSP_EXTERN_H */ diff --git a/hypervisor/include/arch/x86/guest/vm0_boot.h b/hypervisor/bsp/include/uefi/uefi.h similarity index 63% rename from hypervisor/include/arch/x86/guest/vm0_boot.h rename to hypervisor/bsp/include/uefi/uefi.h index e41ec0ba4..b6651681e 100644 --- a/hypervisor/include/arch/x86/guest/vm0_boot.h +++ b/hypervisor/bsp/include/uefi/uefi.h @@ -4,17 +4,16 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef VM0_BOOT_H -#define VM0_BOOT_H +#ifndef _UEFI_H_ +#define _UEFI_H_ -#ifdef CONFIG_EFI_STUB struct efi_context { struct acrn_vcpu_regs vcpu_regs; void *rsdp; void *ap_trampoline_buf; } __packed; -int32_t efi_boot_init(void); -#endif +const struct efi_context *get_efi_ctx(void); +const struct lapic_regs *get_efi_lapic_regs(void); -#endif /* VM0_BOOT_H */ +#endif diff --git a/hypervisor/bsp/sbl/sbl.c b/hypervisor/bsp/sbl/sbl.c index f8ab7d751..6f8eacc24 100644 --- a/hypervisor/bsp/sbl/sbl.c +++ b/hypervisor/bsp/sbl/sbl.c @@ -5,6 +5,7 @@ */ #include +#include void init_bsp(void) { @@ -12,3 +13,18 @@ void init_bsp(void) acpi_fixup(); #endif } + +uint64_t bsp_get_ap_trampoline(void) +{ + return e820_alloc_low_memory(CONFIG_LOW_RAM_SIZE); +} + +void *bsp_get_rsdp(void) +{ + return NULL; +} + +void bsp_init_irq(void) +{ + CPU_IRQ_ENABLE(); +} diff --git a/hypervisor/bsp/uefi/uefi.c b/hypervisor/bsp/uefi/uefi.c index 5096cbc9f..258da4f50 100644 --- a/hypervisor/bsp/uefi/uefi.c +++ b/hypervisor/bsp/uefi/uefi.c @@ -7,9 +7,7 @@ #include #include #include -#include - -#ifdef CONFIG_EFI_STUB +#include static struct efi_context efi_ctx; static struct lapic_regs uefi_lapic_regs; @@ -28,14 +26,15 @@ static void efi_init(void) pr_err("no multiboot drivers for uefi found"); } else { - memcpy_s(&efi_ctx, sizeof(struct efi_context), hpa2hva((uint64_t)mbi->mi_drives_addr), sizeof(struct efi_context)); + memcpy_s(&efi_ctx, sizeof(struct efi_context), hpa2hva((uint64_t)mbi->mi_drives_addr), + sizeof(struct efi_context)); save_lapic(&uefi_lapic_regs); efi_initialized = 1; } } } -void *get_rsdp_from_uefi(void) +void *bsp_get_rsdp(void) { if (!efi_initialized) { efi_init(); @@ -44,14 +43,14 @@ void *get_rsdp_from_uefi(void) return hpa2hva((uint64_t)efi_ctx.rsdp); } -void *get_ap_trampoline_buf(void) +uint64_t bsp_get_ap_trampoline(void) { - return efi_ctx.ap_trampoline_buf; + return (uint64_t)efi_ctx.ap_trampoline_buf; } const struct efi_context *get_efi_ctx(void) { - return (const struct efi_context *)&efi_ctx; + return &efi_ctx; } const struct lapic_regs *get_efi_lapic_regs(void) @@ -59,7 +58,9 @@ const struct lapic_regs *get_efi_lapic_regs(void) return &uefi_lapic_regs; } -#endif +void bsp_init_irq(void) +{ +} void init_bsp(void) { @@ -68,8 +69,6 @@ void init_bsp(void) #endif parse_hv_cmdline(); -#ifdef CONFIG_EFI_STUB if (!efi_initialized) efi_init(); -#endif } diff --git a/hypervisor/include/arch/x86/ioapic.h b/hypervisor/include/arch/x86/ioapic.h index c3a3eecc5..cb71925cf 100644 --- a/hypervisor/include/arch/x86/ioapic.h +++ b/hypervisor/include/arch/x86/ioapic.h @@ -7,8 +7,6 @@ #ifndef IOAPIC_H #define IOAPIC_H -#include - #define NR_LEGACY_IRQ 16U #define NR_LEGACY_PIN NR_LEGACY_IRQ void ioapic_setup_irqs(void); diff --git a/hypervisor/include/arch/x86/per_cpu.h b/hypervisor/include/arch/x86/per_cpu.h index a082a0cc7..4065908f7 100644 --- a/hypervisor/include/arch/x86/per_cpu.h +++ b/hypervisor/include/arch/x86/per_cpu.h @@ -8,7 +8,6 @@ #define PER_CPU_H #include -#include #include #include #include