mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-07-29 14:37:36 +00:00
hv: merge SBL and UEFI related stuff under bsp
This patch unifies the bsp interface between UEFI and SBL. Tracked-On: #2708 Signed-off-by: Tw <wei.tan@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
23e85ff12a
commit
56d8b08b78
@ -226,15 +226,16 @@ C_SRCS += dm/vpci/msi.c
|
||||
C_SRCS += dm/vpci/msix.c
|
||||
endif
|
||||
|
||||
C_SRCS += bsp/firmware_wrapper.c
|
||||
C_SRCS += bsp/firmware_sbl.c
|
||||
C_SRCS += bsp/firmware_uefi.c
|
||||
C_SRCS += bsp/cmdline.c
|
||||
C_SRCS += bsp/const_dmar.c
|
||||
|
||||
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
|
||||
else
|
||||
ifeq ($(CONFIG_PLATFORM_SBL),y)
|
||||
C_SRCS += bsp/sbl/sbl.c
|
||||
C_SRCS += bsp/sbl/const_dmar.c
|
||||
C_SRCS += boot/sbl/multiboot.c
|
||||
C_SRCS += boot/sbl/sbl_seed_parse.c
|
||||
C_SRCS += boot/sbl/abl_seed_parse.c
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <ld_sym.h>
|
||||
#include <logmsg.h>
|
||||
#include <cat.h>
|
||||
#include <firmware.h>
|
||||
|
||||
struct per_cpu_region per_cpu_data[CONFIG_MAX_PCPU_NUM] __aligned(PAGE_SIZE);
|
||||
static uint16_t phys_cpu_num = 0U;
|
||||
@ -112,6 +113,8 @@ void init_cpu_pre(uint16_t pcpu_id_args)
|
||||
*/
|
||||
init_cpu_capabilities();
|
||||
|
||||
init_firmware_operations();
|
||||
|
||||
init_cpu_model_name();
|
||||
|
||||
load_cpu_state_data();
|
||||
|
@ -62,8 +62,8 @@ static void enter_guest_mode(uint16_t pcpu_id)
|
||||
|
||||
static void init_primary_cpu_post(void)
|
||||
{
|
||||
/* Perform any necessary BSP initialization */
|
||||
init_bsp();
|
||||
/* Perform any necessary firmware initialization */
|
||||
init_firmware();
|
||||
|
||||
init_debug_pre();
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <ioapic.h>
|
||||
#include <lapic.h>
|
||||
#include <softirq.h>
|
||||
#include <bsp_extern.h>
|
||||
#include <firmware.h>
|
||||
#include <dump.h>
|
||||
#include <logmsg.h>
|
||||
|
||||
@ -480,5 +480,5 @@ void interrupt_init(uint16_t pcpu_id)
|
||||
init_lapic(pcpu_id);
|
||||
init_default_irqs(pcpu_id);
|
||||
|
||||
bsp_init_irq();
|
||||
firmware_init_irq();
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <per_cpu.h>
|
||||
#include <trampoline.h>
|
||||
#include <reloc.h>
|
||||
#include <bsp_extern.h>
|
||||
#include <firmware.h>
|
||||
#include <ld_sym.h>
|
||||
|
||||
static uint64_t trampoline_start16_paddr;
|
||||
@ -110,7 +110,7 @@ uint64_t prepare_trampoline(void)
|
||||
uint64_t size, dest_pa, i;
|
||||
|
||||
size = (uint64_t)(&ld_trampoline_end - &ld_trampoline_start);
|
||||
dest_pa = bsp_get_ap_trampoline();
|
||||
dest_pa = firmware_get_ap_trampoline();
|
||||
|
||||
pr_dbg("trampoline code: %llx size %x", dest_pa, size);
|
||||
|
||||
|
@ -146,7 +146,7 @@ static struct acpi_table_rsdp *get_rsdp(void)
|
||||
struct acpi_table_rsdp *rsdp = NULL;
|
||||
uint16_t *addr;
|
||||
|
||||
rsdp = (struct acpi_table_rsdp *)bsp_get_rsdp();
|
||||
rsdp = (struct acpi_table_rsdp *)firmware_get_rsdp();
|
||||
if (rsdp == NULL) {
|
||||
/* EBDA is addressed by the 16 bit pointer at 0x40E */
|
||||
addr = (uint16_t *)hpa2hva(0x40eUL);
|
||||
|
@ -9,19 +9,6 @@
|
||||
#include <boot_context.h>
|
||||
#include <uefi.h>
|
||||
|
||||
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, LAPIC_TRIG_EDGE);
|
||||
} 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;
|
||||
@ -56,7 +43,6 @@ static int32_t uefi_sw_loader(struct acrn_vm *vm)
|
||||
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;
|
||||
}
|
||||
|
44
hypervisor/bsp/firmware_sbl.c
Normal file
44
hypervisor/bsp/firmware_sbl.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/* this is for both SBL and ABL platform */
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <firmware_sbl.h>
|
||||
|
||||
static void sbl_init(void)
|
||||
{
|
||||
/* nothing to do for now */
|
||||
}
|
||||
|
||||
|
||||
/* @post: return != 0UL */
|
||||
static uint64_t sbl_get_ap_trampoline(void)
|
||||
{
|
||||
return e820_alloc_low_memory(CONFIG_LOW_RAM_SIZE);
|
||||
}
|
||||
|
||||
static void* sbl_get_rsdp(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void sbl_init_irq(void)
|
||||
{
|
||||
CPU_IRQ_ENABLE();
|
||||
}
|
||||
|
||||
static struct firmware_operations firmware_sbl_ops = {
|
||||
.init = sbl_init,
|
||||
.get_ap_trampoline = sbl_get_ap_trampoline,
|
||||
.get_rsdp = sbl_get_rsdp,
|
||||
.init_irq = sbl_init_irq,
|
||||
};
|
||||
|
||||
struct firmware_operations* sbl_get_firmware_operations(void)
|
||||
{
|
||||
return &firmware_sbl_ops;
|
||||
}
|
88
hypervisor/bsp/firmware_uefi.c
Normal file
88
hypervisor/bsp/firmware_uefi.c
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/* this is for UEFI platform */
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <multiboot.h>
|
||||
#include <boot_context.h>
|
||||
#include <firmware_uefi.h>
|
||||
|
||||
static struct uefi_context uefi_ctx;
|
||||
static struct lapic_regs uefi_lapic_regs;
|
||||
|
||||
static void uefi_init(void)
|
||||
{
|
||||
static bool uefi_initialized = false;
|
||||
struct multiboot_info *mbi = NULL;
|
||||
|
||||
if (!uefi_initialized) {
|
||||
parse_hv_cmdline();
|
||||
|
||||
mbi = (struct multiboot_info *) hpa2hva(((uint64_t)(uint32_t)boot_regs[1]));
|
||||
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_DRIVES) == 0U) {
|
||||
pr_err("no multiboot drivers for uefi found");
|
||||
} else {
|
||||
memcpy_s(&uefi_ctx, sizeof(struct uefi_context), hpa2hva((uint64_t)mbi->mi_drives_addr),
|
||||
sizeof(struct uefi_context));
|
||||
save_lapic(&uefi_lapic_regs);
|
||||
}
|
||||
uefi_initialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
const struct uefi_context *get_efi_ctx(void)
|
||||
{
|
||||
uefi_init();
|
||||
return &uefi_ctx;
|
||||
}
|
||||
|
||||
const struct lapic_regs *get_efi_lapic_regs(void)
|
||||
{
|
||||
uefi_init();
|
||||
return &uefi_lapic_regs;
|
||||
}
|
||||
|
||||
static uint64_t uefi_get_ap_trampoline(void)
|
||||
{
|
||||
return (uint64_t)(uefi_ctx.ap_trampoline_buf);
|
||||
}
|
||||
|
||||
static void* uefi_get_rsdp(void)
|
||||
{
|
||||
return hpa2hva((uint64_t)(uefi_ctx.rsdp));
|
||||
}
|
||||
|
||||
static void uefi_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, LAPIC_TRIG_EDGE);
|
||||
} else {
|
||||
pr_err("%s vcpu or vlapic is not ready, interrupt lost\n", __func__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void uefi_init_irq(void)
|
||||
{
|
||||
spurious_handler = (spurious_handler_t)uefi_spurious_handler;
|
||||
/* we defer irq enabling till vlapic is ready */
|
||||
}
|
||||
|
||||
static struct firmware_operations firmware_uefi_ops = {
|
||||
.init = uefi_init,
|
||||
.get_ap_trampoline = uefi_get_ap_trampoline,
|
||||
.get_rsdp = uefi_get_rsdp,
|
||||
.init_irq = uefi_init_irq,
|
||||
};
|
||||
|
||||
struct firmware_operations* uefi_get_firmware_operations(void)
|
||||
{
|
||||
return &firmware_uefi_ops;
|
||||
}
|
79
hypervisor/bsp/firmware_wrapper.c
Normal file
79
hypervisor/bsp/firmware_wrapper.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <multiboot.h>
|
||||
#include <firmware.h>
|
||||
#include <firmware_sbl.h>
|
||||
#include <firmware_uefi.h>
|
||||
|
||||
static struct firmware_operations *firmware_ops;
|
||||
|
||||
static bool is_firmware_sbl(void)
|
||||
{
|
||||
bool ret = false;
|
||||
struct multiboot_info *mbi = NULL;
|
||||
size_t i;
|
||||
const char *sbl_candidates[] = {
|
||||
"Slim BootLoader",
|
||||
"Intel IOTG/TSD ABL",
|
||||
};
|
||||
|
||||
mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1]);
|
||||
if (mbi != NULL) {
|
||||
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_LOADER_NAME) != 0U) {
|
||||
for (i = 0; i < sizeof(sbl_candidates); i++) {
|
||||
if (strcmp(hpa2hva(mbi->mi_loader_name), sbl_candidates[i]) == 0) {
|
||||
ret = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @pre: this function is called during detect mode which is very early stage,
|
||||
* other exported interfaces should not be called beforehand.
|
||||
*/
|
||||
void init_firmware_operations(void)
|
||||
{
|
||||
if (is_firmware_sbl()) {
|
||||
firmware_ops = sbl_get_firmware_operations();
|
||||
} else {
|
||||
firmware_ops = uefi_get_firmware_operations();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* @pre: firmware_ops->init != NULL */
|
||||
void init_firmware(void)
|
||||
{
|
||||
#ifndef CONFIG_CONSTANT_ACPI
|
||||
acpi_fixup();
|
||||
#endif
|
||||
firmware_ops->init();
|
||||
}
|
||||
|
||||
/* @pre: firmware_ops->get_ap_trampoline != NULL */
|
||||
uint64_t firmware_get_ap_trampoline(void)
|
||||
{
|
||||
return firmware_ops->get_ap_trampoline();
|
||||
}
|
||||
|
||||
/* @pre: firmware_ops->get_rsdp != NULL */
|
||||
void *firmware_get_rsdp(void)
|
||||
{
|
||||
return firmware_ops->get_rsdp();
|
||||
}
|
||||
|
||||
/* @pre: firmware_ops->init_irq != NULL */
|
||||
void firmware_init_irq(void)
|
||||
{
|
||||
return firmware_ops->init_irq();
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* FILE NAME
|
||||
*
|
||||
* bsp_extern.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* This file defines the generic BSP interface
|
||||
*
|
||||
************************************************************************/
|
||||
#ifndef BSP_EXTERN_H
|
||||
#define BSP_EXTERN_H
|
||||
|
||||
/* 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
|
||||
|
||||
#endif /* BSP_EXTERN_H */
|
28
hypervisor/bsp/include/firmware.h
Normal file
28
hypervisor/bsp/include/firmware.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FIRMWARE_H
|
||||
|
||||
#define FIRMWARE_H
|
||||
|
||||
struct firmware_operations {
|
||||
void (*init)(void);
|
||||
uint64_t (*get_ap_trampoline)(void);
|
||||
void *(*get_rsdp)(void);
|
||||
void (*init_irq)(void);
|
||||
};
|
||||
|
||||
void init_firmware_operations(void);
|
||||
void init_firmware(void);
|
||||
uint64_t firmware_get_ap_trampoline(void);
|
||||
void *firmware_get_rsdp(void);
|
||||
void firmware_init_irq(void);
|
||||
|
||||
#ifndef CONFIG_CONSTANT_ACPI
|
||||
void acpi_fixup(void);
|
||||
#endif
|
||||
|
||||
#endif /* end of include guard: FIRMWARE_H */
|
15
hypervisor/bsp/include/firmware_sbl.h
Normal file
15
hypervisor/bsp/include/firmware_sbl.h
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef FIRMWARE_SBL_H
|
||||
|
||||
#define FIRMWARE_SBL_H
|
||||
|
||||
#include <firmware.h>
|
||||
|
||||
struct firmware_operations* sbl_get_firmware_operations(void);
|
||||
|
||||
#endif /* end of include guard: FIRMWARE_SBL_H */
|
23
hypervisor/bsp/include/firmware_uefi.h
Normal file
23
hypervisor/bsp/include/firmware_uefi.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#ifndef FIRMWARE_UEFI_H
|
||||
|
||||
#define FIRMWARE_UEFI_H
|
||||
|
||||
#include <firmware.h>
|
||||
|
||||
struct uefi_context {
|
||||
struct acrn_vcpu_regs vcpu_regs;
|
||||
void *rsdp;
|
||||
void *ap_trampoline_buf;
|
||||
} __packed;
|
||||
|
||||
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);
|
||||
|
||||
#endif /* end of include guard: FIRMWARE_UEFI_H */
|
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef _UEFI_H_
|
||||
#define _UEFI_H_
|
||||
|
||||
struct efi_context {
|
||||
struct acrn_vcpu_regs vcpu_regs;
|
||||
void *rsdp;
|
||||
void *ap_trampoline_buf;
|
||||
} __packed;
|
||||
|
||||
const struct efi_context *get_efi_ctx(void);
|
||||
const struct lapic_regs *get_efi_lapic_regs(void);
|
||||
|
||||
#endif
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <e820.h>
|
||||
|
||||
void init_bsp(void)
|
||||
{
|
||||
#ifndef CONFIG_CONSTANT_ACPI
|
||||
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();
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* 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 <uefi.h>
|
||||
|
||||
static struct efi_context efi_ctx;
|
||||
static struct lapic_regs uefi_lapic_regs;
|
||||
static int32_t efi_initialized;
|
||||
|
||||
static void efi_init(void)
|
||||
{
|
||||
struct multiboot_info *mbi = NULL;
|
||||
|
||||
if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) {
|
||||
pr_err("no multiboot info found");
|
||||
} else {
|
||||
|
||||
mbi = (struct multiboot_info *) hpa2hva(((uint64_t)(uint32_t)boot_regs[1]));
|
||||
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_DRIVES) == 0U) {
|
||||
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));
|
||||
save_lapic(&uefi_lapic_regs);
|
||||
efi_initialized = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *bsp_get_rsdp(void)
|
||||
{
|
||||
if (!efi_initialized) {
|
||||
efi_init();
|
||||
}
|
||||
|
||||
return hpa2hva((uint64_t)efi_ctx.rsdp);
|
||||
}
|
||||
|
||||
uint64_t bsp_get_ap_trampoline(void)
|
||||
{
|
||||
return (uint64_t)efi_ctx.ap_trampoline_buf;
|
||||
}
|
||||
|
||||
const struct efi_context *get_efi_ctx(void)
|
||||
{
|
||||
return &efi_ctx;
|
||||
}
|
||||
|
||||
const struct lapic_regs *get_efi_lapic_regs(void)
|
||||
{
|
||||
return &uefi_lapic_regs;
|
||||
}
|
||||
|
||||
void bsp_init_irq(void)
|
||||
{
|
||||
}
|
||||
|
||||
void init_bsp(void)
|
||||
{
|
||||
#ifndef CONFIG_CONSTANT_ACPI
|
||||
acpi_fixup();
|
||||
#endif
|
||||
parse_hv_cmdline();
|
||||
|
||||
if (!efi_initialized)
|
||||
efi_init();
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
#include <bits.h>
|
||||
#include <spinlock.h>
|
||||
#include <acrn_common.h>
|
||||
#include <bsp_extern.h>
|
||||
#include <firmware.h>
|
||||
#include <vcpu.h>
|
||||
#include <vioapic.h>
|
||||
#include <vpic.h>
|
||||
|
@ -12,6 +12,7 @@
|
||||
#define MULTIBOOT_INFO_HAS_MODS 0x00000008U
|
||||
#define MULTIBOOT_INFO_HAS_MMAP 0x00000040U
|
||||
#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080U
|
||||
#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200U
|
||||
|
||||
struct acrn_vm;
|
||||
struct multiboot_info {
|
||||
|
Loading…
Reference in New Issue
Block a user