2019-03-04 13:34:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <multiboot.h>
|
2019-03-22 03:02:30 +08:00
|
|
|
#include <vm.h>
|
|
|
|
#include <types.h>
|
|
|
|
#include <pgtable.h>
|
2019-04-29 13:52:37 +08:00
|
|
|
#include <acpi.h>
|
2019-04-30 13:56:32 +08:00
|
|
|
#include <vboot.h>
|
|
|
|
#include <direct_boot.h>
|
|
|
|
#include <deprivilege_boot.h>
|
2019-05-08 20:20:54 +08:00
|
|
|
#include <logmsg.h>
|
2019-03-04 13:34:09 +08:00
|
|
|
|
2019-05-06 21:46:42 +08:00
|
|
|
#define BOOTLOADER_NUM 4U
|
|
|
|
#define BOOTLOADER_NAME_SIZE 20U
|
|
|
|
|
|
|
|
struct vboot_bootloader_map {
|
|
|
|
const char bootloader_name[BOOTLOADER_NAME_SIZE];
|
|
|
|
enum vboot_mode mode;
|
|
|
|
};
|
|
|
|
|
2019-04-30 15:56:58 +08:00
|
|
|
static struct vboot_operations *vboot_ops;
|
2019-05-06 21:46:42 +08:00
|
|
|
static enum vboot_mode sos_boot_mode;
|
2019-03-04 13:34:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @pre: this function is called during detect mode which is very early stage,
|
|
|
|
* other exported interfaces should not be called beforehand.
|
|
|
|
*/
|
2019-04-30 15:56:58 +08:00
|
|
|
void init_vboot_operations(void)
|
2019-03-04 13:34:09 +08:00
|
|
|
{
|
HV:BSP:Update firmware detection and operations selecting logic
In the current design, hypervisor only detects two kinds of
multiboot compiliant firwares (UEFI loader and non-UEFI loader),
It can't detect other multiboot compliant firware (such GRUB
loader) and can't detect UEFI loader explicitly since loader
name is not supported by UEFI loader (efi stub). In the
logical partition scenario on KBL NUC i7, one multiboot
compliant firware is used to boot hypervisor and load guest
OS image, and firware runtime service shall be disable to
avoid interference. So GRUB can be selected as a candidate
to enable logical partition scenario on KBL NUC i7.
Update firware detection and operations selecting logic to detect
more multiboot compiliant firware (such as GRUB and UEFI loader)
explicitly, different operations is selected according to the
boot load name through a static mapping table between boot load name
and firmware operations. GRUB loader can use the SBL operations
to handle multiboot information parsing and vm booting since
these multiboot compiliant firmware (SBL/ABL/GRUB) which boots
hypervisor (binary format), provides multiboot information and
the start address of guest OS image(binary format) in the same way,
and only runs on boot time.
From MISRA C view, viarble array is not allowed, so define the
static array for above mapping table;
From security view, it is better use strncmp insteads of strcmp.
TODO: In future, need to redesign boot moudle to suport different
boot loader, different VM boot, and different guest OS.
V2-->V3:
Update firmware detection logic to handle GRUB loader
which is need to provided multiboot information to the
hypervisor (such as the address of guest OS image);
V3-->V4:
Update firmware detection and operations selecting logic
to enable GRUB loader support in hypervisor;
V4-->V5:
Separte UEFI loader name supporting in a separate patch,
and update commit comment to make patch clearer.
V5-->V6:
Update "Tracked-On"
Tracked-On: #2944
Signed-off-by: Xiangyang Wu <xiangyang.wu@linux.intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2019-04-15 23:02:08 +08:00
|
|
|
|
|
|
|
struct multiboot_info *mbi;
|
|
|
|
uint32_t i;
|
|
|
|
|
2019-05-06 21:46:42 +08:00
|
|
|
const struct vboot_bootloader_map vboot_bootloader_maps[BOOTLOADER_NUM] = {
|
|
|
|
{"Slim BootLoader", DIRECT_BOOT_MODE},
|
|
|
|
{"Intel IOTG/TSD ABL", DIRECT_BOOT_MODE},
|
|
|
|
{"ACRN UEFI loader", DEPRI_BOOT_MODE},
|
|
|
|
{"GRUB", DIRECT_BOOT_MODE},
|
HV:BSP:Update firmware detection and operations selecting logic
In the current design, hypervisor only detects two kinds of
multiboot compiliant firwares (UEFI loader and non-UEFI loader),
It can't detect other multiboot compliant firware (such GRUB
loader) and can't detect UEFI loader explicitly since loader
name is not supported by UEFI loader (efi stub). In the
logical partition scenario on KBL NUC i7, one multiboot
compliant firware is used to boot hypervisor and load guest
OS image, and firware runtime service shall be disable to
avoid interference. So GRUB can be selected as a candidate
to enable logical partition scenario on KBL NUC i7.
Update firware detection and operations selecting logic to detect
more multiboot compiliant firware (such as GRUB and UEFI loader)
explicitly, different operations is selected according to the
boot load name through a static mapping table between boot load name
and firmware operations. GRUB loader can use the SBL operations
to handle multiboot information parsing and vm booting since
these multiboot compiliant firmware (SBL/ABL/GRUB) which boots
hypervisor (binary format), provides multiboot information and
the start address of guest OS image(binary format) in the same way,
and only runs on boot time.
From MISRA C view, viarble array is not allowed, so define the
static array for above mapping table;
From security view, it is better use strncmp insteads of strcmp.
TODO: In future, need to redesign boot moudle to suport different
boot loader, different VM boot, and different guest OS.
V2-->V3:
Update firmware detection logic to handle GRUB loader
which is need to provided multiboot information to the
hypervisor (such as the address of guest OS image);
V3-->V4:
Update firmware detection and operations selecting logic
to enable GRUB loader support in hypervisor;
V4-->V5:
Separte UEFI loader name supporting in a separate patch,
and update commit comment to make patch clearer.
V5-->V6:
Update "Tracked-On"
Tracked-On: #2944
Signed-off-by: Xiangyang Wu <xiangyang.wu@linux.intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2019-04-15 23:02:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
mbi = (struct multiboot_info *)hpa2hva((uint64_t)boot_regs[1]);
|
2019-05-08 20:20:54 +08:00
|
|
|
if (mbi == NULL) {
|
|
|
|
panic("No multiboot info");
|
|
|
|
} else {
|
|
|
|
for (i = 0U; i < BOOTLOADER_NUM; i++) {
|
|
|
|
if (strncmp(hpa2hva(mbi->mi_loader_name), vboot_bootloader_maps[i].bootloader_name,
|
|
|
|
strnlen_s(vboot_bootloader_maps[i].bootloader_name, BOOTLOADER_NAME_SIZE)) == 0) {
|
|
|
|
/* Only support two vboot mode */
|
|
|
|
if (vboot_bootloader_maps[i].mode == DEPRI_BOOT_MODE) {
|
|
|
|
vboot_ops = get_deprivilege_boot_ops();
|
|
|
|
sos_boot_mode = DEPRI_BOOT_MODE;
|
|
|
|
} else {
|
|
|
|
vboot_ops = get_direct_boot_ops();
|
|
|
|
sos_boot_mode = DIRECT_BOOT_MODE;
|
|
|
|
}
|
|
|
|
break;
|
2019-05-06 21:46:42 +08:00
|
|
|
}
|
HV:BSP:Update firmware detection and operations selecting logic
In the current design, hypervisor only detects two kinds of
multiboot compiliant firwares (UEFI loader and non-UEFI loader),
It can't detect other multiboot compliant firware (such GRUB
loader) and can't detect UEFI loader explicitly since loader
name is not supported by UEFI loader (efi stub). In the
logical partition scenario on KBL NUC i7, one multiboot
compliant firware is used to boot hypervisor and load guest
OS image, and firware runtime service shall be disable to
avoid interference. So GRUB can be selected as a candidate
to enable logical partition scenario on KBL NUC i7.
Update firware detection and operations selecting logic to detect
more multiboot compiliant firware (such as GRUB and UEFI loader)
explicitly, different operations is selected according to the
boot load name through a static mapping table between boot load name
and firmware operations. GRUB loader can use the SBL operations
to handle multiboot information parsing and vm booting since
these multiboot compiliant firmware (SBL/ABL/GRUB) which boots
hypervisor (binary format), provides multiboot information and
the start address of guest OS image(binary format) in the same way,
and only runs on boot time.
From MISRA C view, viarble array is not allowed, so define the
static array for above mapping table;
From security view, it is better use strncmp insteads of strcmp.
TODO: In future, need to redesign boot moudle to suport different
boot loader, different VM boot, and different guest OS.
V2-->V3:
Update firmware detection logic to handle GRUB loader
which is need to provided multiboot information to the
hypervisor (such as the address of guest OS image);
V3-->V4:
Update firmware detection and operations selecting logic
to enable GRUB loader support in hypervisor;
V4-->V5:
Separte UEFI loader name supporting in a separate patch,
and update commit comment to make patch clearer.
V5-->V6:
Update "Tracked-On"
Tracked-On: #2944
Signed-off-by: Xiangyang Wu <xiangyang.wu@linux.intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2019-04-15 23:02:08 +08:00
|
|
|
}
|
2019-03-04 13:34:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-30 15:56:58 +08:00
|
|
|
/* @pre: vboot_ops->init != NULL */
|
|
|
|
void init_vboot(void)
|
2019-03-04 13:34:09 +08:00
|
|
|
{
|
2019-05-14 14:48:23 +08:00
|
|
|
#ifdef CONFIG_ACPI_PARSE_ENABLED
|
2019-03-04 13:34:09 +08:00
|
|
|
acpi_fixup();
|
|
|
|
#endif
|
2019-04-30 15:56:58 +08:00
|
|
|
vboot_ops->init();
|
2019-03-04 13:34:09 +08:00
|
|
|
}
|
|
|
|
|
2019-05-06 21:46:42 +08:00
|
|
|
/* @pre: vboot_ops != NULL */
|
|
|
|
enum vboot_mode get_sos_boot_mode(void)
|
|
|
|
{
|
|
|
|
return sos_boot_mode;
|
|
|
|
}
|
|
|
|
|
2019-04-30 15:56:58 +08:00
|
|
|
/* @pre: vboot_ops->get_ap_trampoline != NULL */
|
|
|
|
uint64_t get_ap_trampoline_buf(void)
|
2019-03-04 13:34:09 +08:00
|
|
|
{
|
2019-04-30 15:56:58 +08:00
|
|
|
return vboot_ops->get_ap_trampoline();
|
2019-03-04 13:34:09 +08:00
|
|
|
}
|
|
|
|
|
2019-04-30 15:56:58 +08:00
|
|
|
/* @pre: vboot_ops->get_rsdp != NULL */
|
|
|
|
void *get_rsdp_ptr(void)
|
2019-03-04 13:34:09 +08:00
|
|
|
{
|
2019-04-30 15:56:58 +08:00
|
|
|
return vboot_ops->get_rsdp();
|
2019-03-04 13:34:09 +08:00
|
|
|
}
|
|
|
|
|
2019-04-30 15:56:58 +08:00
|
|
|
/* @pre: vboot_ops->init_irq != NULL */
|
|
|
|
void init_vboot_irq(void)
|
2019-03-04 13:34:09 +08:00
|
|
|
{
|
2019-04-30 15:56:58 +08:00
|
|
|
return vboot_ops->init_irq();
|
2019-03-04 13:34:09 +08:00
|
|
|
}
|