acrn-hypervisor/hypervisor/arch/x86/init.c
Zhao Yakui cee2f8b288 ACRN/HV: Refine the function of init_vboot to initialize the depriv_boot env correctly
Currently when get_rsdp is called, the EFI depriv_boot env is not initialized.
In such case it will fallback to the legacy mechanism of ACPI table.
If the ACPI table based on legacy mechanism is not found, it will fail to get
the ACPI table and then the system will hang.
On the old platform it still can parse the ACPI table from legacy mechanism.
In fact when EFI RSDP exists, the EFI RSDP is preferred instead of legacy ACPI
RSDP.

In order to avoid multiple calling of depriv_init_boot, the init_boot_operations
is renamed and called after X2apic is enabled(early_init_lapic).

Tracked-On: #3184
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
2019-05-30 14:07:57 +08:00

107 lines
2.1 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <types.h>
#include <init.h>
#include <console.h>
#include <per_cpu.h>
#include <profiling.h>
#include <vtd.h>
#include <shell.h>
#include <vmx.h>
#include <vm.h>
#include <logmsg.h>
#include <vboot.h>
#include <seed.h>
/* Push sp magic to top of stack for call trace */
#define SWITCH_TO(rsp, to) \
{ \
asm volatile ("movq %0, %%rsp\n" \
"pushq %1\n" \
"jmpq *%2\n" \
: \
: "r"(rsp), "rm"(SP_BOTTOM_MAGIC), "a"(to)); \
}
/*TODO: move into debug module */
static void init_debug_pre(void)
{
/* Initialize console */
console_init();
/* Enable logging */
init_logmsg(CONFIG_LOG_DESTINATION);
}
/*TODO: move into debug module */
static void init_debug_post(uint16_t pcpu_id)
{
if (pcpu_id == BOOT_CPU_ID) {
/* Initialize the shell */
shell_init();
console_setup_timer();
}
profiling_setup();
}
/*TODO: move into guest-vcpu module */
static void enter_guest_mode(uint16_t pcpu_id)
{
vmx_on();
(void)launch_vms(pcpu_id);
switch_to_idle(default_idle);
/* Control should not come here */
cpu_dead();
}
static void init_primary_pcpu_post(void)
{
init_debug_pre();
init_pcpu_post(BOOT_CPU_ID);
init_seed();
init_debug_post(BOOT_CPU_ID);
enter_guest_mode(BOOT_CPU_ID);
}
/* NOTE: this function is using temp stack, and after SWITCH_TO(runtime_sp, to)
* it will switch to runtime stack.
*/
void init_primary_pcpu(void)
{
uint64_t rsp;
init_pcpu_pre(BOOT_CPU_ID);
/* Switch to run-time stack */
rsp = (uint64_t)(&get_cpu_var(stack)[CONFIG_STACK_SIZE - 1]);
rsp &= ~(CPU_STACK_ALIGN - 1UL);
SWITCH_TO(rsp, init_primary_pcpu_post);
}
void init_secondary_pcpu(void)
{
uint16_t pcpu_id;
init_pcpu_pre(INVALID_CPU_ID);
pcpu_id = get_pcpu_id();
init_pcpu_post(pcpu_id);
init_debug_post(pcpu_id);
enter_guest_mode(pcpu_id);
}