hv: modularization: change of multiboot API.

The init_multiboot_info() and sanitize_multiboot_ifno() APIs now
require parameters instead of implicitly relying on global boot
variables.

Tracked-On: #5661
Signed-off-by: Vijay Dhanraj <vijay.dhanraj@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
This commit is contained in:
Liang Yi 2021-01-18 07:41:30 +08:00 committed by wenlingz
parent 66599e0aa7
commit 681688fbe4
11 changed files with 38 additions and 37 deletions

View File

@ -127,7 +127,7 @@ void init_e820(void)
uint32_t i; uint32_t i;
uint64_t top_addr_space = CONFIG_PLATFORM_RAM_SIZE + PLATFORM_LO_MMIO_SIZE; uint64_t top_addr_space = CONFIG_PLATFORM_RAM_SIZE + PLATFORM_LO_MMIO_SIZE;
struct acrn_multiboot_info *mbi = get_multiboot_info(); struct acrn_multiboot_info *mbi = get_acrn_multiboot_info();
struct multiboot_mmap *mmap = mbi->mi_mmap_entry; struct multiboot_mmap *mmap = mbi->mi_mmap_entry;
hv_e820_entries_nr = mbi->mi_mmap_entries; hv_e820_entries_nr = mbi->mi_mmap_entries;

View File

@ -15,6 +15,7 @@
#include <seed.h> #include <seed.h>
#include <ld_sym.h> #include <ld_sym.h>
#include <boot.h> #include <boot.h>
#include <multiboot.h>
/* Push sp magic to top of stack for call trace */ /* Push sp magic to top of stack for call trace */
#define SWITCH_TO(rsp, to) \ #define SWITCH_TO(rsp, to) \
@ -86,11 +87,11 @@ void init_primary_pcpu(void)
/* Clear BSS */ /* Clear BSS */
(void)memset(&ld_bss_start, 0U, (size_t)(&ld_bss_end - &ld_bss_start)); (void)memset(&ld_bss_start, 0U, (size_t)(&ld_bss_end - &ld_bss_start));
init_acrn_multiboot_info(); init_acrn_multiboot_info(boot_regs[0], boot_regs[1], efiloader_sig);
init_debug_pre(); init_debug_pre();
if (sanitize_multiboot_info() != 0) { if (sanitize_acrn_multiboot_info(boot_regs[0], boot_regs[1]) != 0) {
panic("Multiboot info error!"); panic("Multiboot info error!");
} }

View File

@ -41,7 +41,7 @@ static uint32_t parse_seed_arg(void)
{ {
const char *cmd_src = NULL; const char *cmd_src = NULL;
char *arg, *arg_end; char *arg, *arg_end;
struct acrn_multiboot_info *mbi = get_multiboot_info(); struct acrn_multiboot_info *mbi = get_acrn_multiboot_info();
uint32_t i = SEED_ARG_NUM - 1U; uint32_t i = SEED_ARG_NUM - 1U;
uint32_t len; uint32_t len;

View File

@ -70,7 +70,7 @@ static struct acpi_table_rsdp *get_rsdp(void)
if (acpi_rsdp != NULL) { if (acpi_rsdp != NULL) {
rsdp = acpi_rsdp; rsdp = acpi_rsdp;
} else { } else {
rsdp = (struct acpi_table_rsdp *)(get_multiboot_info()->mi_acpi_rsdp_va); rsdp = (struct acpi_table_rsdp *)(get_acrn_multiboot_info()->mi_acpi_rsdp_va);
if (rsdp == NULL) { if (rsdp == NULL) {
uint16_t *addr; uint16_t *addr;

View File

@ -9,7 +9,7 @@
#include <errno.h> #include <errno.h>
#include <per_cpu.h> #include <per_cpu.h>
#include <irq.h> #include <irq.h>
#include <boot.h> #include <multiboot.h>
#include <pgtable.h> #include <pgtable.h>
#include <zeropage.h> #include <zeropage.h>
#include <seed.h> #include <seed.h>
@ -257,7 +257,7 @@ static int32_t init_vm_sw_load(struct acrn_vm *vm, const struct acrn_multiboot_i
*/ */
int32_t init_vm_boot_info(struct acrn_vm *vm) int32_t init_vm_boot_info(struct acrn_vm *vm)
{ {
struct acrn_multiboot_info *mbi = get_multiboot_info(); struct acrn_multiboot_info *mbi = get_acrn_multiboot_info();
int32_t ret = -EINVAL; int32_t ret = -EINVAL;
stac(); stac();

View File

@ -76,9 +76,9 @@ struct acrn_multiboot_info {
struct efi_info mi_efi_info; struct efi_info mi_efi_info;
}; };
void init_acrn_multiboot_info(void); void init_acrn_multiboot_info(uint32_t magic, uint32_t info, char *sig);
struct acrn_multiboot_info *get_multiboot_info(void); int32_t sanitize_acrn_multiboot_info(uint32_t magic, uint32_t info);
int32_t sanitize_multiboot_info(void); struct acrn_multiboot_info *get_acrn_multiboot_info(void);
#endif /* ASSEMBLER */ #endif /* ASSEMBLER */

View File

@ -7,7 +7,6 @@
#include <types.h> #include <types.h>
#include <errno.h> #include <errno.h>
#include <pgtable.h> #include <pgtable.h>
#include <boot.h>
#include <multiboot.h> #include <multiboot.h>
#include <rtl.h> #include <rtl.h>
#include <logmsg.h> #include <logmsg.h>
@ -68,10 +67,10 @@ static struct acrn_multiboot_info acrn_mbi = { 0U };
static int32_t mbi_status; static int32_t mbi_status;
void init_acrn_multiboot_info(void) void init_acrn_multiboot_info(uint32_t magic, uint32_t info, char *sig)
{ {
if (boot_from_multiboot1()) { if (boot_from_multiboot1(magic, info)) {
struct multiboot_info *mbi = (struct multiboot_info *)(hpa2hva_early((uint64_t)boot_regs[1])); struct multiboot_info *mbi = (struct multiboot_info *)(hpa2hva_early((uint64_t)info));
acrn_mbi.mi_flags = mbi->mi_flags; acrn_mbi.mi_flags = mbi->mi_flags;
acrn_mbi.mi_drives_addr = mbi->mi_drives_addr; acrn_mbi.mi_drives_addr = mbi->mi_drives_addr;
@ -84,22 +83,22 @@ void init_acrn_multiboot_info(void)
acrn_mbi.mi_mods_va = (struct multiboot_module *)hpa2hva_early((uint64_t)mbi->mi_mods_addr); acrn_mbi.mi_mods_va = (struct multiboot_module *)hpa2hva_early((uint64_t)mbi->mi_mods_addr);
mbi_status = 0; mbi_status = 0;
#ifdef CONFIG_MULTIBOOT2 #ifdef CONFIG_MULTIBOOT2
} else if (boot_from_multiboot2()) { } else if (boot_from_multiboot2(magic)) {
mbi_status = multiboot2_to_acrn_mbi(&acrn_mbi, hpa2hva_early((uint64_t)boot_regs[1])); mbi_status = multiboot2_to_acrn_mbi(&acrn_mbi, hpa2hva_early((uint64_t)info), sig);
#endif #endif
} else { } else {
mbi_status = -ENODEV; mbi_status = -ENODEV;
} }
} }
int32_t sanitize_multiboot_info(void) int32_t sanitize_acrn_multiboot_info(uint32_t magic, uint32_t info)
{ {
if ((acrn_mbi.mi_mmap_entries != 0U) && (acrn_mbi.mi_mmap_va != NULL)) { if ((acrn_mbi.mi_mmap_entries != 0U) && (acrn_mbi.mi_mmap_va != NULL)) {
if (acrn_mbi.mi_mmap_entries > E820_MAX_ENTRIES) { if (acrn_mbi.mi_mmap_entries > E820_MAX_ENTRIES) {
pr_err("Too many E820 entries %d\n", acrn_mbi.mi_mmap_entries); pr_err("Too many E820 entries %d\n", acrn_mbi.mi_mmap_entries);
acrn_mbi.mi_mmap_entries = E820_MAX_ENTRIES; acrn_mbi.mi_mmap_entries = E820_MAX_ENTRIES;
} }
if (boot_from_multiboot1()) { if (boot_from_multiboot1(magic, info)) {
uint32_t mmap_entry_size = sizeof(struct multiboot_mmap); uint32_t mmap_entry_size = sizeof(struct multiboot_mmap);
(void)memcpy_s((void *)(&acrn_mbi.mi_mmap_entry[0]), (void)memcpy_s((void *)(&acrn_mbi.mi_mmap_entry[0]),
@ -108,7 +107,7 @@ int32_t sanitize_multiboot_info(void)
(acrn_mbi.mi_mmap_entries * mmap_entry_size)); (acrn_mbi.mi_mmap_entries * mmap_entry_size));
} }
#ifdef CONFIG_MULTIBOOT2 #ifdef CONFIG_MULTIBOOT2
if (boot_from_multiboot2()) { if (boot_from_multiboot2(magic)) {
uint32_t i; uint32_t i;
struct multiboot2_mmap_entry *mb2_mmap = (struct multiboot2_mmap_entry *)acrn_mbi.mi_mmap_va; struct multiboot2_mmap_entry *mb2_mmap = (struct multiboot2_mmap_entry *)acrn_mbi.mi_mmap_va;
@ -129,7 +128,7 @@ int32_t sanitize_multiboot_info(void)
acrn_mbi.mi_mods_count = MAX_MODULE_NUM; acrn_mbi.mi_mods_count = MAX_MODULE_NUM;
} }
if (acrn_mbi.mi_mods_count != 0U) { if (acrn_mbi.mi_mods_count != 0U) {
if (boot_from_multiboot1() && (acrn_mbi.mi_mods_va != NULL)) { if (boot_from_multiboot1(magic, info) && (acrn_mbi.mi_mods_va != NULL)) {
(void)memcpy_s((void *)(&acrn_mbi.mi_mods[0]), (void)memcpy_s((void *)(&acrn_mbi.mi_mods[0]),
(acrn_mbi.mi_mods_count * sizeof(struct multiboot_module)), (acrn_mbi.mi_mods_count * sizeof(struct multiboot_module)),
(const void *)acrn_mbi.mi_mods_va, (const void *)acrn_mbi.mi_mods_va,
@ -145,9 +144,10 @@ int32_t sanitize_multiboot_info(void)
mbi_status = -EINVAL; mbi_status = -EINVAL;
} }
if (boot_from_multiboot2()) { #ifdef CONFIG_MULTIBOOT2
if (boot_from_multiboot2(magic)) {
if (acrn_mbi.mi_efi_info.efi_memmap_hi != 0U) { if (acrn_mbi.mi_efi_info.efi_memmap_hi != 0U) {
pr_err("the efi mmap address should be less than 4G!"); pr_err("the EFI mmap address should be less than 4G!");
acrn_mbi.mi_flags &= ~MULTIBOOT_INFO_HAS_EFI_MMAP; acrn_mbi.mi_flags &= ~MULTIBOOT_INFO_HAS_EFI_MMAP;
mbi_status = -EINVAL; mbi_status = -EINVAL;
} }
@ -156,12 +156,13 @@ int32_t sanitize_multiboot_info(void)
pr_err("no multiboot2 uefi info found!"); pr_err("no multiboot2 uefi info found!");
} }
} }
#endif
if (acrn_mbi.mi_loader_name[0] == '\0') { if (acrn_mbi.mi_loader_name[0] == '\0') {
pr_err("no bootloader name found!"); pr_err("no bootloader name found!");
mbi_status = -EINVAL; mbi_status = -EINVAL;
} else { } else {
printf("Multiboot%s Bootloader: %s\n", boot_from_multiboot1() ? "" : "2", acrn_mbi.mi_loader_name); printf("Multiboot%s Bootloader: %s\n", boot_from_multiboot1(magic, info) ? "" : "2", acrn_mbi.mi_loader_name);
} }
return mbi_status; return mbi_status;
@ -172,7 +173,7 @@ int32_t sanitize_multiboot_info(void)
* @post retval->mi_flags & MULTIBOOT_INFO_HAS_MMAP != 0U * @post retval->mi_flags & MULTIBOOT_INFO_HAS_MMAP != 0U
* @post (retval->mi_mmap_entries > 0U) && (retval->mi_mmap_entries <= E820_MAX_ENTRIES) * @post (retval->mi_mmap_entries > 0U) && (retval->mi_mmap_entries <= E820_MAX_ENTRIES)
*/ */
struct acrn_multiboot_info *get_multiboot_info(void) struct acrn_multiboot_info *get_acrn_multiboot_info(void)
{ {
return &acrn_mbi; return &acrn_mbi;
} }

View File

@ -6,7 +6,6 @@
#include <types.h> #include <types.h>
#include <errno.h> #include <errno.h>
#include <boot.h>
#include <multiboot.h> #include <multiboot.h>
#include <pgtable.h> #include <pgtable.h>
#include "multiboot_priv.h" #include "multiboot_priv.h"
@ -37,10 +36,11 @@ static void mb2_mods_to_mbi(struct acrn_multiboot_info *mbi,
/** /**
* @pre mbi != NULL && mb2_tag_efi64 != 0 * @pre mbi != NULL && mb2_tag_efi64 != 0
*/ */
static void mb2_efi64_to_mbi(struct acrn_multiboot_info *mbi, const struct multiboot2_tag_efi64 *mb2_tag_efi64) static void mb2_efi64_to_mbi(struct acrn_multiboot_info *mbi, const struct multiboot2_tag_efi64 *mb2_tag_efi64,
char *sig)
{ {
mbi->mi_efi_info.efi_systab = (uint32_t)(uint64_t)mb2_tag_efi64->pointer; mbi->mi_efi_info.efi_systab = (uint32_t)(uint64_t)mb2_tag_efi64->pointer;
mbi->mi_efi_info.efi_loader_signature = (uint32_t)(uint64_t)efiloader_sig; mbi->mi_efi_info.efi_loader_signature = (uint32_t)(uint64_t)sig;
mbi->mi_flags |= MULTIBOOT_INFO_HAS_EFI64; mbi->mi_flags |= MULTIBOOT_INFO_HAS_EFI64;
} }
@ -61,7 +61,7 @@ static void mb2_efimmap_to_mbi(struct acrn_multiboot_info *mbi,
/** /**
* @pre mbi != NULL * @pre mbi != NULL
*/ */
int32_t multiboot2_to_acrn_mbi(struct acrn_multiboot_info *mbi, void *mb2_info) int32_t multiboot2_to_acrn_mbi(struct acrn_multiboot_info *mbi, void *mb2_info, char *sig)
{ {
int32_t ret = 0; int32_t ret = 0;
struct multiboot2_tag *mb2_tag, *mb2_tag_end; struct multiboot2_tag *mb2_tag, *mb2_tag_end;
@ -92,7 +92,7 @@ int32_t multiboot2_to_acrn_mbi(struct acrn_multiboot_info *mbi, void *mb2_info)
mbi->mi_acpi_rsdp_va = ((struct multiboot2_tag_new_acpi *)mb2_tag)->rsdp; mbi->mi_acpi_rsdp_va = ((struct multiboot2_tag_new_acpi *)mb2_tag)->rsdp;
break; break;
case MULTIBOOT2_TAG_TYPE_EFI64: case MULTIBOOT2_TAG_TYPE_EFI64:
mb2_efi64_to_mbi(mbi, (const struct multiboot2_tag_efi64 *)mb2_tag); mb2_efi64_to_mbi(mbi, (const struct multiboot2_tag_efi64 *)mb2_tag, sig);
break; break;
case MULTIBOOT2_TAG_TYPE_EFI_MMAP: case MULTIBOOT2_TAG_TYPE_EFI_MMAP:
mb2_efimmap_to_mbi(mbi, (const struct multiboot2_tag_efi_mmap *)mb2_tag); mb2_efimmap_to_mbi(mbi, (const struct multiboot2_tag_efi_mmap *)mb2_tag);

View File

@ -75,7 +75,7 @@ struct multiboot2_tag_efi_mmap
/* /*
* @post boot_regs[1] stores the address pointer that point to a valid multiboot2 info * @post boot_regs[1] stores the address pointer that point to a valid multiboot2 info
*/ */
static inline bool boot_from_multiboot2(void) static inline bool boot_from_multiboot2(uint32_t magic)
{ {
/* /*
* Multiboot spec states that the Multiboot information structure may be placed * Multiboot spec states that the Multiboot information structure may be placed
@ -86,16 +86,15 @@ static inline bool boot_from_multiboot2(void)
* 0f3f5b7c13fa9b67 ("multiboot2: Set min address for mbi allocation to 0x1000") * 0f3f5b7c13fa9b67 ("multiboot2: Set min address for mbi allocation to 0x1000")
* which dates on Dec 26 2019. * which dates on Dec 26 2019.
*/ */
return (boot_regs[0] == MULTIBOOT2_INFO_MAGIC); return (magic == MULTIBOOT2_INFO_MAGIC);
} }
int32_t multiboot2_to_acrn_mbi(struct acrn_multiboot_info *mbi, void *mb2_info); int32_t multiboot2_to_acrn_mbi(struct acrn_multiboot_info *mbi, void *mb2_info, char *sig);
#endif #endif
static inline bool boot_from_multiboot1(uint32_t magic, uint32_t info)
static inline bool boot_from_multiboot1(void)
{ {
return ((boot_regs[0] == MULTIBOOT_INFO_MAGIC) && (boot_regs[1] != 0U)); return ((magic == MULTIBOOT_INFO_MAGIC) && (info != 0U));
} }
#endif /* MULTIBOOT_PRIV_H */ #endif /* MULTIBOOT_PRIV_H */

View File

@ -76,7 +76,7 @@ static uint64_t create_zero_page(struct acrn_vm *vm)
#ifdef CONFIG_MULTIBOOT2 #ifdef CONFIG_MULTIBOOT2
if (is_sos_vm(vm)) { if (is_sos_vm(vm)) {
struct acrn_multiboot_info *mbi = get_multiboot_info(); struct acrn_multiboot_info *mbi = get_acrn_multiboot_info();
(void)memcpy_s(&(zeropage->boot_efi_info), sizeof(zeropage->boot_efi_info), (void)memcpy_s(&(zeropage->boot_efi_info), sizeof(zeropage->boot_efi_info),
&(mbi->mi_efi_info), sizeof(mbi->mi_efi_info)); &(mbi->mi_efi_info), sizeof(mbi->mi_efi_info));

View File

@ -28,7 +28,7 @@ static void parse_hvdbg_cmdline(void)
{ {
const char *start = NULL; const char *start = NULL;
const char *end = NULL; const char *end = NULL;
struct acrn_multiboot_info *mbi = get_multiboot_info(); struct acrn_multiboot_info *mbi = get_acrn_multiboot_info();
if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) { if ((mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) != 0U) {
start = mbi->mi_cmdline; start = mbi->mi_cmdline;