HV: modularization to refine boot/bsp related code.

1. add static for local functions and variables.
2. move vm_sw_loader from vcpu to vm
3. refine uefi.c to follow the code rules.
4. separate uefi.c for vm0 boot and bsp two parts. bsp layer just
access native HW related, can't access vm/vcpu, vm0 boot part can
access vm / vcpu data structure.

Tracked-On: #1842
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
This commit is contained in:
Minggui Cao
2019-01-02 16:01:10 +08:00
committed by wenlingz
parent 4c541ba18c
commit c5e072432a
8 changed files with 110 additions and 71 deletions

View File

@@ -291,7 +291,7 @@ handle_one_drhd(struct acpi_dmar_hardware_unit *acpi_drhd,
return 0;
}
int32_t parse_dmar_table(void)
static int32_t parse_dmar_table(void)
{
int32_t i;
struct acpi_dmar_hardware_unit *acpi_drhd;

View File

@@ -0,0 +1,64 @@
/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <hypervisor.h>
#include <multiboot.h>
#include <boot_context.h>
#include <vm0_boot.h>
#ifdef CONFIG_EFI_STUB
static void efi_spurious_handler(int32_t vector)
{
if (get_cpu_id() == BOOT_CPU_ID) {
struct acrn_vcpu *vcpu = per_cpu(vcpu, BOOT_CPU_ID);
if (vcpu != NULL) {
vlapic_set_intr(vcpu, vector, 0);
} else {
pr_err("%s vcpu or vlapic is not ready, interrupt lost\n", __func__);
}
}
}
static int32_t uefi_sw_loader(struct acrn_vm *vm)
{
int32_t ret = 0;
struct acrn_vcpu *vcpu = get_primary_vcpu(vm);
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();
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
* 2. saved when HV started: other registers
* We copy the info saved in efi_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));
vcpu_regs->rip = efi_ctx->vcpu_regs.rip;
set_vcpu_regs(vcpu, vcpu_regs);
/* defer irq enabling till vlapic is ready */
CPU_IRQ_ENABLE();
return ret;
}
int32_t efi_boot_init(void)
{
vm_sw_loader = uefi_sw_loader;
spurious_handler = (spurious_handler_t)efi_spurious_handler;
return 0;
}
#endif