acrn-hypervisor/hypervisor/arch/x86/init.c
Mingqiang Chi 511d4c158b hv:cleanup console.h
--move several uart API declarations from console.h to uart16550.h
 --move several shell API declarations from console.h to shell.h
 --add dbg_cmd.h, move 'handle_dbg_cmd' declaration from console.h
   to dbg_cmd.h
 --move debug/uart16550.h to include/debug/uart16550.h since some
   uart APIs will be called by external files

Tracked-On: #1842
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>

	modified:   arch/x86/guest/vm.c
	modified:   arch/x86/init.c
	modified:   bsp/uefi/cmdline.c
	modified:   debug/console.c
	modified:   debug/dbg_cmd.c
	modified:   debug/uart16550.c
	modified:   debug/vuart.c
	modified:   hw/pci.c
	modified:   include/arch/x86/multiboot.h
	modified:   include/debug/console.h
	new file:   include/debug/dbg_cmd.h
	new file:   include/debug/shell.h
	renamed:    debug/uart16550.h -> include/debug/uart16550.h
2019-02-27 11:12:48 +08:00

118 lines
2.3 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>
/* 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 pass-thru module */
static void init_passthru(void)
{
if (init_iommu() != 0) {
panic("failed to initialize iommu!");
}
ptdev_init();
}
/*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_cpu_post(void)
{
/* Perform any necessary BSP initialization */
init_bsp();
init_debug_pre();
init_cpu_post(BOOT_CPU_ID);
init_debug_post(BOOT_CPU_ID);
init_passthru();
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_cpu(void)
{
uint64_t rsp;
init_cpu_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_cpu_post);
}
void init_secondary_cpu(void)
{
uint16_t pcpu_id;
init_cpu_pre(INVALID_CPU_ID);
pcpu_id = get_cpu_id();
init_cpu_post(pcpu_id);
init_debug_post(pcpu_id);
enter_guest_mode(pcpu_id);
}