mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-09-22 17:27:53 +00:00
initial import
internal commit: 14ac2bc2299032fa6714d1fefa7cf0987b3e3085 Signed-off-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
57
hypervisor/bsp/include/bsp_extern.h
Normal file
57
hypervisor/bsp/include/bsp_extern.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/************************************************************************
|
||||
*
|
||||
* FILE NAME
|
||||
*
|
||||
* bsp_extern.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
* This file defines the generic BSP interface
|
||||
*
|
||||
************************************************************************/
|
||||
#ifndef BSP_EXTERN_H
|
||||
#define BSP_EXTERN_H
|
||||
|
||||
#define UOS_DEFAULT_START_ADDR (0x100000000)
|
||||
/**********************************/
|
||||
/* EXTERNAL VARIABLES */
|
||||
/**********************************/
|
||||
|
||||
/* BSP Interfaces */
|
||||
void init_bsp(void);
|
||||
|
||||
/* External Interfaces */
|
||||
struct _vm_description_array;
|
||||
const struct _vm_description_array *get_vm_desc_base(void);
|
||||
|
||||
#endif /* BSP_EXTERN_H */
|
94
hypervisor/bsp/ld/link_ram.ld.in
Normal file
94
hypervisor/bsp/ld/link_ram.ld.in
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "bsp_cfg.h"
|
||||
|
||||
ENTRY(cpu_primary_start_32)
|
||||
|
||||
MEMORY
|
||||
{
|
||||
/* Low 1MB of memory for secondary processor start-up */
|
||||
lowram : ORIGIN = CONFIG_LOW_RAM_START, LENGTH = CONFIG_LOW_RAM_SIZE
|
||||
|
||||
/* 32 MBytes of RAM for HV */
|
||||
ram : ORIGIN = CONFIG_RAM_START, LENGTH = CONFIG_RAM_SIZE
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.boot :
|
||||
{
|
||||
_ld_ram_start = . ;
|
||||
KEEP(*(multiboot_header)) ;
|
||||
} > ram
|
||||
|
||||
.entry :
|
||||
{
|
||||
KEEP(*(entry)) ;
|
||||
|
||||
} > ram
|
||||
|
||||
.text :
|
||||
{
|
||||
*(.text .text*) ;
|
||||
*(.gnu.linkonce.t*)
|
||||
*(.note.gnu.build-id)
|
||||
} > ram
|
||||
|
||||
.rodata :
|
||||
{
|
||||
*(.rodata*) ;
|
||||
|
||||
} > ram
|
||||
|
||||
_ld_cpu_secondary_reset_load = .;
|
||||
|
||||
.cpu_secondary : AT (_ld_cpu_secondary_reset_load)
|
||||
{
|
||||
_ld_cpu_secondary_reset_start = .;
|
||||
*(.cpu_secondary_reset);
|
||||
. = ALIGN(4);
|
||||
_ld_cpu_secondary_reset_end = .;
|
||||
|
||||
} > lowram
|
||||
|
||||
_ld_cpu_secondary_reset_size = _ld_cpu_secondary_reset_end - _ld_cpu_secondary_reset_start;
|
||||
|
||||
.data (_ld_cpu_secondary_reset_load + _ld_cpu_secondary_reset_size):
|
||||
{
|
||||
*(.data) ;
|
||||
*(.data*) ;
|
||||
*(.sdata)
|
||||
*(.gnu.linkonce.d*)
|
||||
|
||||
} > ram
|
||||
|
||||
.bss_noinit (NOLOAD):
|
||||
{
|
||||
. = ALIGN(4) ;
|
||||
*(.bss_noinit) ;
|
||||
*(.bss_noinit*) ;
|
||||
. = ALIGN(4) ;
|
||||
} > ram
|
||||
|
||||
.bss (NOLOAD):
|
||||
{
|
||||
. = ALIGN(4) ;
|
||||
_ld_bss_start = . ;
|
||||
*(.bss) ;
|
||||
*(.bss*) ;
|
||||
*(COMMON) ;
|
||||
. = ALIGN(4) ;
|
||||
_ld_bss_end = . ;
|
||||
} > ram
|
||||
|
||||
.discard (NOLOAD):
|
||||
{
|
||||
. = ALIGN(4096) ;
|
||||
_ld_cpu_data_start = .;
|
||||
*(.cpu_data) ;
|
||||
. = ALIGN(4096) ;
|
||||
_ld_cpu_data_end = .;
|
||||
} > ram
|
||||
|
||||
_ld_ram_size = LENGTH(ram) ;
|
||||
_ld_ram_end = _ld_ram_size + _ld_ram_start ;
|
||||
}
|
||||
|
49
hypervisor/bsp/sbl/include/bsp/bsp_cfg.h
Normal file
49
hypervisor/bsp/sbl/include/bsp/bsp_cfg.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef BSP_CFG_H
|
||||
#define BSP_CFG_H
|
||||
#define NR_IOAPICS 1
|
||||
#define STACK_SIZE 8192
|
||||
#define LOG_BUF_SIZE 0x100000
|
||||
#define LOG_DESTINATION 3
|
||||
#define CPU_UP_TIMEOUT 100
|
||||
#define CONFIG_SERIAL_MMIO_BASE 0xfc000000
|
||||
#define MALLOC_ALIGN 16
|
||||
#define NUM_ALLOC_PAGES 4096
|
||||
#define HEAP_SIZE 0x100000
|
||||
#define CONSOLE_LOGLEVEL_DEFAULT 2
|
||||
#define MEM_LOGLEVEL_DEFAULT 4
|
||||
#define CONFIG_LOW_RAM_START 0x00001000
|
||||
#define CONFIG_LOW_RAM_SIZE 0x000CF000
|
||||
#define CONFIG_RAM_START 0x6E000000
|
||||
#define CONFIG_RAM_SIZE 0x02000000 /* 32M */
|
||||
#define CONFIG_RETPOLINE
|
||||
#endif /* BSP_CFG_H */
|
94
hypervisor/bsp/sbl/sbl.c
Normal file
94
hypervisor/bsp/sbl/sbl.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <hv_lib.h>
|
||||
#include <acrn_common.h>
|
||||
#include <hv_arch.h>
|
||||
#include <bsp_extern.h>
|
||||
#include <vtd.h>
|
||||
|
||||
/* IOAPIC id */
|
||||
#define SBL_IOAPIC_ID 8
|
||||
/* IOAPIC base address */
|
||||
#define SBL_IOAPIC_ADDR 0xfec00000
|
||||
/* IOAPIC range size */
|
||||
#define SBL_IOAPIC_SIZE 0x100000
|
||||
/* Local APIC base address */
|
||||
#define SBL_LAPIC_ADDR 0xfee00000
|
||||
/* Local APIC range size */
|
||||
#define SBL_LAPIC_SIZE 0x100000
|
||||
/* Number of PCI IRQ assignments */
|
||||
#define SBL_PCI_IRQ_ASSIGNMENT_NUM 28
|
||||
|
||||
#ifndef CONFIG_DMAR_PARSE_ENABLED
|
||||
static struct dmar_dev_scope default_drhd_unit_dev_scope0[] = {
|
||||
{ .bus = 0, .devfun = DEVFUN(0x2, 0), },
|
||||
};
|
||||
|
||||
static struct dmar_drhd drhd_info_array[] = {
|
||||
{
|
||||
.dev_cnt = 1,
|
||||
.segment = 0,
|
||||
.flags = 0,
|
||||
.reg_base_addr = 0xFED64000,
|
||||
/* Ignore the iommu for intel graphic device since GVT-g needs
|
||||
* vtd disabled for gpu
|
||||
*/
|
||||
.ignore = true,
|
||||
.devices = default_drhd_unit_dev_scope0,
|
||||
},
|
||||
{
|
||||
/* No need to specify devices since
|
||||
* DRHD_FLAG_INCLUDE_PCI_ALL_MASK set
|
||||
*/
|
||||
.dev_cnt = 0,
|
||||
.segment = 0,
|
||||
.flags = DRHD_FLAG_INCLUDE_PCI_ALL_MASK,
|
||||
.reg_base_addr = 0xFED65000,
|
||||
.ignore = false,
|
||||
.devices = NULL,
|
||||
},
|
||||
};
|
||||
|
||||
static struct dmar_info sbl_dmar_info = {
|
||||
.drhd_count = 2,
|
||||
.drhd_units = drhd_info_array,
|
||||
};
|
||||
|
||||
struct dmar_info *get_dmar_info(void)
|
||||
{
|
||||
return &sbl_dmar_info;
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_bsp(void)
|
||||
{
|
||||
}
|
70
hypervisor/bsp/sbl/vm_description.c
Normal file
70
hypervisor/bsp/sbl/vm_description.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <hv_lib.h>
|
||||
#include <acrn_common.h>
|
||||
#include <hv_arch.h>
|
||||
|
||||
#define NUM_USER_VMS 2
|
||||
|
||||
/* Number of CPUs in VM0 */
|
||||
#define VM0_NUM_CPUS 1
|
||||
|
||||
/* Logical CPU IDs assigned to VM0 */
|
||||
int VM0_CPUS[VM0_NUM_CPUS] = {0};
|
||||
|
||||
/* Number of CPUs in VM1 */
|
||||
#define VM1_NUM_CPUS 2
|
||||
|
||||
/* Logical CPU IDs assigned with VM1 */
|
||||
int VM1_CPUS[VM1_NUM_CPUS] = {3, 1};
|
||||
|
||||
const struct vm_description_array vm_desc = {
|
||||
/* Number of user virtual machines */
|
||||
.num_vm_desc = NUM_USER_VMS,
|
||||
|
||||
/* Virtual Machine descriptions */
|
||||
.vm_desc_array = {
|
||||
{
|
||||
/* Internal variable, MUSTBE init to -1 */
|
||||
.vm_attr_name = "vm_0",
|
||||
.vm_hw_num_cores = VM0_NUM_CPUS,
|
||||
.vm_hw_logical_core_ids = &VM0_CPUS[0],
|
||||
.vm_state_info_privilege = VM_PRIVILEGE_LEVEL_HIGH,
|
||||
.vm_created = false,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
const struct vm_description_array *get_vm_desc_base(void)
|
||||
{
|
||||
return &vm_desc;
|
||||
}
|
3
hypervisor/bsp/uefi/clearlinux/acrn.conf
Executable file
3
hypervisor/bsp/uefi/clearlinux/acrn.conf
Executable file
@@ -0,0 +1,3 @@
|
||||
title ACRN OS
|
||||
linux /EFI/org.clearlinux/acrn.efi
|
||||
options sos=bzImage pci_devices_ignore=(0:18:2) noxsave maxcpus=1 console=tty0 console=ttyS0 i915.nuclear_pageflip=1 root=/dev/sda3 rw rootwait clocksource=hpet ignore_loglevel no_timer_check consoleblank=0 i915.tsd_init=7 i915.tsd_delay=2000 i915.avail_planes_per_pipe=0x00000F i915.domain_plane_owners=0x011111110000 i915.enable_guc_loading=0 i915.enable_guc_submission=0 i915.enable_preemption=1 i915.context_priority_mode=2 i915.enable_gvt=1 hvlog=2M@0x1FE00000 cma=2560M@0x100000000-0
|
131
hypervisor/bsp/uefi/cmdline.c
Normal file
131
hypervisor/bsp/uefi/cmdline.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <hv_lib.h>
|
||||
#include <acrn_common.h>
|
||||
#include <hv_arch.h>
|
||||
#include <bsp_extern.h>
|
||||
#include <acrn_hv_defs.h>
|
||||
#include <hv_debug.h>
|
||||
#include <multiboot.h>
|
||||
|
||||
#define MAX_PORT 0x10000 /* port 0 - 64K */
|
||||
#define DEFAULT_UART_PORT 0x3F8
|
||||
|
||||
#define ACRN_DBG_PARSE 6
|
||||
|
||||
#define MAX_CMD_LEN 64
|
||||
|
||||
static const char * const cmd_list[] = {
|
||||
"uart=disabled", /* to disable uart */
|
||||
"uart=port@", /* like uart=port@0x3F8 */
|
||||
"uart=mmio@", /*like: uart=mmio@0xFC000000 */
|
||||
};
|
||||
|
||||
enum IDX_CMD {
|
||||
IDX_DISABLE_UART,
|
||||
IDX_PORT_UART,
|
||||
IDX_MMIO_UART,
|
||||
|
||||
IDX_MAX_CMD,
|
||||
};
|
||||
|
||||
static void handle_cmd(const char *cmd, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < IDX_MAX_CMD; i++) {
|
||||
int tmp = strnlen_s(cmd_list[i], MAX_CMD_LEN);
|
||||
|
||||
/*cmd prefix should be same with one in cmd_list */
|
||||
if (len < tmp)
|
||||
continue;
|
||||
|
||||
if (strncmp(cmd_list[i], cmd, tmp) != 0)
|
||||
continue;
|
||||
|
||||
if (i == IDX_DISABLE_UART) {
|
||||
/* set uart disabled*/
|
||||
uart16550_set_property(0, 0, 0);
|
||||
} else if ((i == IDX_PORT_UART) || (i == IDX_MMIO_UART)) {
|
||||
uint64_t addr = strtoul(cmd + tmp, NULL, 16);
|
||||
|
||||
dev_dbg(ACRN_DBG_PARSE, "uart addr=0x%llx", addr);
|
||||
|
||||
if (i == IDX_PORT_UART) {
|
||||
if (addr > MAX_PORT)
|
||||
addr = DEFAULT_UART_PORT;
|
||||
|
||||
uart16550_set_property(1, 1, addr);
|
||||
} else {
|
||||
uart16550_set_property(1, 0, addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int parse_hv_cmdline(void)
|
||||
{
|
||||
const char *start;
|
||||
const char *end;
|
||||
struct multiboot_info *mbi = NULL;
|
||||
|
||||
if (boot_regs[0] != MULTIBOOT_INFO_MAGIC) {
|
||||
ASSERT(0, "no multiboot info found");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
mbi = (struct multiboot_info *)((uint64_t)boot_regs[1]);
|
||||
dev_dbg(ACRN_DBG_PARSE, "Multiboot detected, flag=0x%x", mbi->mi_flags);
|
||||
|
||||
if (!(mbi->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE)) {
|
||||
dev_dbg(ACRN_DBG_PARSE, "no hv cmdline!");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
start = (char *)(uint64_t)mbi->mi_cmdline;
|
||||
dev_dbg(ACRN_DBG_PARSE, "hv cmdline: %s", start);
|
||||
|
||||
do {
|
||||
while (*start == ' ')
|
||||
start++;
|
||||
|
||||
end = start + 1;
|
||||
while (*end != ' ' && *end)
|
||||
end++;
|
||||
|
||||
handle_cmd(start, end - start);
|
||||
start = end + 1;
|
||||
|
||||
} while (*end && *start);
|
||||
|
||||
return 0;
|
||||
}
|
105
hypervisor/bsp/uefi/efi/Makefile
Normal file
105
hypervisor/bsp/uefi/efi/Makefile
Normal file
@@ -0,0 +1,105 @@
|
||||
#
|
||||
# Copyright (c) 2011, Intel Corporation
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following
|
||||
# disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
# * Neither the name of Intel Corporation nor the names of its
|
||||
# contributors may be used to endorse or promote products derived
|
||||
# from this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
|
||||
RELEASE:=0
|
||||
HV_OBJDIR:=build
|
||||
HV_FILE:=acrn
|
||||
EFI_OBJDIR:=$(HV_OBJDIR)/bsp/uefi/efi
|
||||
C_SRCS = boot.c pe.c malloc.c
|
||||
ACRN_OBJS := $(patsubst %.c,$(EFI_OBJDIR)/%.o,$(C_SRCS))
|
||||
|
||||
OBJCOPY=objcopy
|
||||
|
||||
HOST = $(shell $(CC) -dumpmachine | sed "s/\(-\).*$$//")
|
||||
ARCH := $(shell $(CC) -dumpmachine | sed "s/\(-\).*$$//")
|
||||
|
||||
ifeq ($(ARCH),x86_64)
|
||||
LIBDIR := $(shell if [ -d /usr/lib64 ]; then echo /usr/lib64; \
|
||||
else if [ -d /usr/lib ]; then echo /usr/lib; fi ; fi;)
|
||||
FORMAT=efi-app-x86-64
|
||||
else
|
||||
ARCH=ia32
|
||||
LIBDIR=/usr/lib32
|
||||
FORMAT=efi-app-ia32
|
||||
endif
|
||||
|
||||
INCDIR := /usr/include
|
||||
|
||||
# gnuefi sometimes installs these under a gnuefi/ directory, and sometimes not
|
||||
CRT0 := $(LIBDIR)/crt0-efi-$(ARCH).o
|
||||
LDSCRIPT := $(LIBDIR)/elf_$(ARCH)_efi.lds
|
||||
|
||||
CFLAGS=-I. -I.. -I$(INCDIR)/efi -I$(INCDIR)/efi/$(ARCH) \
|
||||
-DEFI_FUNCTION_WRAPPER -fPIC -fshort-wchar -ffreestanding \
|
||||
-Wall -I../fs/ -D$(ARCH)
|
||||
|
||||
ifeq ($(ARCH),ia32)
|
||||
ifeq ($(HOST),x86_64)
|
||||
CFLAGS += -m32
|
||||
endif
|
||||
endif
|
||||
ifeq ($(ARCH),x86_64)
|
||||
CFLAGS += -mno-red-zone
|
||||
endif
|
||||
|
||||
LDFLAGS=-T $(LDSCRIPT) -Bsymbolic -shared -nostdlib -znocombreloc \
|
||||
-L$(LIBDIR) $(CRT0)
|
||||
EFIBIN=$(HV_OBJDIR)/$(HV_FILE).efi
|
||||
BOOT=$(EFI_OBJDIR)/boot.efi
|
||||
|
||||
all: $(EFIBIN)
|
||||
$(OBJCOPY) --add-section .hv="$(HV_OBJDIR)/$(HV_FILE).bin" --change-section-vma .hv=0x6e000 --set-section-flags .hv=alloc,data,contents,load --section-alignment 0x1000 $(EFI_OBJDIR)/boot.efi $(EFIBIN)
|
||||
|
||||
install: $(EFIBIN)
|
||||
install -D $(EFIBIN) $(DESTDIR)/usr/share/$(HV_FILE).efi
|
||||
|
||||
$(EFIBIN): $(BOOT)
|
||||
|
||||
$(EFI_OBJDIR)/boot.efi: $(EFI_OBJDIR)/boot.so
|
||||
|
||||
$(EFI_OBJDIR)/boot.so: $(ACRN_OBJS) $(FS)
|
||||
$(LD) $(LDFLAGS) -o $@ $^ -lgnuefi -lefi $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
||||
|
||||
clean:
|
||||
rm -f $(BOOT) $(HV_OBJDIR)/$(HV_FILE).efi $(EFI_OBJDIR)/boot.so $(ACRN_OBJS) $(FS)
|
||||
|
||||
$(EFI_OBJDIR)/%.o:%.S
|
||||
[ ! -e $@ ] && mkdir -p $(dir $@); \
|
||||
$(CC) $(CFLAGS) -c -o $@ $<
|
||||
|
||||
$(EFI_OBJDIR)/%.o: %.c
|
||||
[ ! -e $@ ] && mkdir -p $(dir $@); \
|
||||
$(CC) $(patsubst %, -I%, $(INCLUDE_PATH)) -I. -c $(CFLAGS) $(ARCH_CFLAGS) $< -o $@
|
||||
|
||||
%.efi: %.so
|
||||
$(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel \
|
||||
-j .rela -j .reloc --target=$(FORMAT) $*.so $@
|
615
hypervisor/bsp/uefi/efi/boot.c
Normal file
615
hypervisor/bsp/uefi/efi/boot.c
Normal file
@@ -0,0 +1,615 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
#include "efilinux.h"
|
||||
#include "stdlib.h"
|
||||
#include "boot.h"
|
||||
#include "multiboot.h"
|
||||
|
||||
#define ERROR_STRING_LENGTH 32
|
||||
#define EFI_LOADER_SIGNATURE "EL64"
|
||||
|
||||
#define LEAGCY_BIOS
|
||||
|
||||
#define ACPI_XSDT_ENTRY_SIZE (sizeof (UINT64))
|
||||
#define ACPI_NAME_SIZE 4
|
||||
#define ACPI_OEM_ID_SIZE 6
|
||||
#define ACPI_OEM_TABLE_ID_SIZE 8
|
||||
|
||||
EFI_SYSTEM_TABLE *sys_table;
|
||||
EFI_BOOT_SERVICES *boot;
|
||||
EFI_RUNTIME_SERVICES *runtime;
|
||||
|
||||
/**
|
||||
* memory_map - Allocate and fill out an array of memory descriptors
|
||||
* @map_buf: buffer containing the memory map
|
||||
* @map_size: size of the buffer containing the memory map
|
||||
* @map_key: key for the current memory map
|
||||
* @desc_size: size of the desc
|
||||
* @desc_version: memory descriptor version
|
||||
*
|
||||
* On success, @map_size contains the size of the memory map pointed
|
||||
* to by @map_buf and @map_key, @desc_size and @desc_version are
|
||||
* updated.
|
||||
*/
|
||||
EFI_STATUS
|
||||
memory_map(EFI_MEMORY_DESCRIPTOR **map_buf, UINTN *map_size,
|
||||
UINTN *map_key, UINTN *desc_size, UINT32 *desc_version)
|
||||
{
|
||||
EFI_STATUS err;
|
||||
|
||||
*map_size = sizeof(**map_buf) * 31;
|
||||
get_map:
|
||||
|
||||
/*
|
||||
* Because we're about to allocate memory, we may
|
||||
* potentially create a new memory descriptor, thereby
|
||||
* increasing the size of the memory map. So increase
|
||||
* the buffer size by the size of one memory
|
||||
* descriptor, just in case.
|
||||
*/
|
||||
*map_size += sizeof(**map_buf);
|
||||
|
||||
err = allocate_pool(EfiLoaderData, *map_size,
|
||||
(void **)map_buf);
|
||||
if (err != EFI_SUCCESS) {
|
||||
Print(L"Failed to allocate pool for memory map");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
err = get_memory_map(map_size, *map_buf, map_key,
|
||||
desc_size, desc_version);
|
||||
if (err != EFI_SUCCESS) {
|
||||
if (err == EFI_BUFFER_TOO_SMALL) {
|
||||
/*
|
||||
* 'map_size' has been updated to reflect the
|
||||
* required size of a map buffer.
|
||||
*/
|
||||
free_pool((void *)*map_buf);
|
||||
goto get_map;
|
||||
}
|
||||
|
||||
Print(L"Failed to get memory map");
|
||||
goto failed;
|
||||
}
|
||||
|
||||
failed:
|
||||
return err;
|
||||
}
|
||||
|
||||
static inline BOOLEAN isspace(CHAR8 ch)
|
||||
{
|
||||
return ((unsigned char)ch <= ' ');
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void print_ch(char *str)
|
||||
{
|
||||
int j;
|
||||
CHAR16 *buf;
|
||||
int len = strlen(str);
|
||||
|
||||
buf = malloc((strlen(str) + 1)* 2);
|
||||
for (j=0; j<len; j++)
|
||||
buf[j] = str[j];
|
||||
buf[j] = 0;
|
||||
Print(L"CHAR16::: %s\n", buf);
|
||||
free(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
struct acpi_table_rsdp {
|
||||
char signature[8]; /* ACPI signature, contains "RSD PTR " */
|
||||
UINT8 checksum; /* ACPI 1.0 checksum */
|
||||
char oem_id[ACPI_OEM_ID_SIZE]; /* OEM identification */
|
||||
UINT8 revision; /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */
|
||||
UINT32 rsdt_physical_address; /* 32-bit physical address of the RSDT */
|
||||
UINT32 length; /* Table length in bytes, including header (ACPI 2.0+) */
|
||||
UINT64 xsdt_physical_address; /* 64-bit physical address of the XSDT (ACPI 2.0+) */
|
||||
UINT8 extended_checksum; /* Checksum of entire table (ACPI 2.0+) */
|
||||
UINT8 reserved[3]; /* Reserved, must be zero */
|
||||
};
|
||||
|
||||
struct acpi_table_header {
|
||||
char signature[ACPI_NAME_SIZE]; /* ASCII table signature */
|
||||
UINT32 length; /* Length of table in bytes, including this header */
|
||||
UINT8 revision; /* ACPI Specification minor version number */
|
||||
UINT8 checksum; /* To make sum of entire table == 0 */
|
||||
char oem_id[ACPI_OEM_ID_SIZE]; /* ASCII OEM identification */
|
||||
char oem_table_id[ACPI_OEM_TABLE_ID_SIZE]; /* ASCII OEM table identification */
|
||||
UINT32 oem_revision; /* OEM revision number */
|
||||
char asl_compiler_id[ACPI_NAME_SIZE]; /* ASCII ASL compiler vendor ID */
|
||||
UINT32 asl_compiler_revision; /* ASL compiler version */
|
||||
};
|
||||
|
||||
typedef void(*hv_func)(int, struct multiboot_info*, struct efi_ctx*);
|
||||
EFI_IMAGE_ENTRY_POINT get_pe_entry(CHAR8 *base);
|
||||
|
||||
static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start,
|
||||
struct multiboot_info* mbi, struct efi_ctx* pe)
|
||||
{
|
||||
hv_func hf;
|
||||
|
||||
asm volatile ("cli");
|
||||
|
||||
/* The 64-bit kernel entry is 512 bytes after the start. */
|
||||
hf = (hv_func)(hv_start + 0x200);
|
||||
|
||||
/*
|
||||
* The first parameter is a dummy because the kernel expects
|
||||
* boot_params in %[re]si.
|
||||
*/
|
||||
hf(MULTIBOOT_INFO_MAGIC, mbi, pe);
|
||||
}
|
||||
|
||||
|
||||
|
||||
EFI_STATUS get_path(CHAR16* name, EFI_LOADED_IMAGE *info, EFI_DEVICE_PATH **path)
|
||||
{
|
||||
unsigned int pathlen;
|
||||
EFI_STATUS efi_status = EFI_SUCCESS;
|
||||
CHAR16 *pathstr, *pathname;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < StrLen(name); i++) {
|
||||
if (name[i] == '/')
|
||||
name[i] = '\\';
|
||||
}
|
||||
|
||||
pathstr = DevicePathToStr(info->FilePath);
|
||||
for (i = 0; i < StrLen(pathstr); i++) {
|
||||
if (pathstr[i] == '/')
|
||||
pathstr[i] = '\\';
|
||||
}
|
||||
|
||||
pathlen = StrLen(pathstr);
|
||||
|
||||
if (name[0] == '\\') {
|
||||
*path = FileDevicePath(info->DeviceHandle, name);
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i=pathlen - 1; i > 0; i--) {
|
||||
if (pathstr[i] == '\\') break;
|
||||
}
|
||||
pathstr[i] = '\0';
|
||||
|
||||
pathlen = StrLen(pathstr);
|
||||
|
||||
pathlen++;
|
||||
pathname = AllocatePool((pathlen + 1 + StrLen(name))*sizeof(CHAR16));
|
||||
if (!pathname) {
|
||||
Print(L"Failed to allocate memory for pathname\n");
|
||||
efi_status = EFI_OUT_OF_RESOURCES;
|
||||
goto out;
|
||||
}
|
||||
StrCpy(pathname, pathstr);
|
||||
StrCat(pathname, L"\\");
|
||||
StrCat(pathname, name);
|
||||
|
||||
*path = FileDevicePath(info->DeviceHandle, pathname);
|
||||
|
||||
out:
|
||||
FreePool(pathstr);
|
||||
return efi_status;
|
||||
}
|
||||
/**
|
||||
* load_kernel - Load a kernel image into memory from the boot device
|
||||
*/
|
||||
EFI_STATUS
|
||||
load_sos_image(EFI_HANDLE image, CHAR16 *name, CHAR16 *cmdline)
|
||||
{
|
||||
UINTN map_size, _map_size, map_key;
|
||||
UINT32 desc_version;
|
||||
UINTN desc_size;
|
||||
EFI_MEMORY_DESCRIPTOR *map_buf;
|
||||
EFI_PHYSICAL_ADDRESS addr;
|
||||
EFI_LOADED_IMAGE *info = NULL;
|
||||
EFI_STATUS err;
|
||||
struct multiboot_mmap *mmap;
|
||||
struct multiboot_info *mbi;
|
||||
|
||||
struct acpi_table_rsdp *rsdp;
|
||||
int i, j;
|
||||
|
||||
|
||||
err = handle_protocol(image, &LoadedImageProtocol, (void **)&info);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto out;
|
||||
|
||||
|
||||
EFI_HANDLE bz_hd;
|
||||
EFI_DEVICE_PATH *path;
|
||||
EFI_LOADED_IMAGE *bz_info = NULL;
|
||||
EFI_IMAGE_ENTRY_POINT pe_entry;
|
||||
struct efi_ctx* pe;
|
||||
|
||||
err = get_path(name, info, &path);
|
||||
if (err != EFI_SUCCESS) {
|
||||
Print(L"fail to get bzImage.efi path");
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = uefi_call_wrapper(BS->LoadImage, 6, FALSE, image, path, NULL, 0, &bz_hd);
|
||||
|
||||
if (err != EFI_SUCCESS) {
|
||||
Print(L"failed to load bzImage %lx\n", err);
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = handle_protocol(bz_hd, &LoadedImageProtocol, (void **)&bz_info);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto out;
|
||||
|
||||
if (cmdline) {
|
||||
bz_info->LoadOptions = cmdline;
|
||||
bz_info->LoadOptionsSize = (StrLen(cmdline) + 1) * sizeof(CHAR16);
|
||||
}
|
||||
|
||||
pe_entry = get_pe_entry(bz_info->ImageBase);
|
||||
|
||||
if (pe_entry == NULL) {
|
||||
Print(L"fail to get pe entry of bzImage\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
err = emalloc(sizeof(struct efi_ctx), 8, &addr);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto out;
|
||||
pe = (struct efi_ctx*)(UINTN)addr;
|
||||
pe->entry = pe_entry;
|
||||
pe->handle = bz_hd;
|
||||
pe->table = sys_table;
|
||||
|
||||
|
||||
/* multiboot info */
|
||||
err = emalloc(16384, 8, &addr);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto out;
|
||||
|
||||
mbi = (struct multiboot_info *)(UINTN)addr;
|
||||
memset((void *)mbi, 0x0, sizeof(*mbi));
|
||||
|
||||
/* allocate mmap[] */
|
||||
err = emalloc(sizeof(struct multiboot_mmap)*128, 8, &addr);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto out;
|
||||
mmap = (struct multiboot_mmap *)(UINTN)addr;
|
||||
memset((void *)mmap, 0x0, sizeof(*mmap)*128);
|
||||
|
||||
|
||||
EFI_CONFIGURATION_TABLE *config_table = sys_table->ConfigurationTable;
|
||||
for (i = 0; i < sys_table->NumberOfTableEntries;i++) {
|
||||
EFI_GUID acpi_20_table_guid = ACPI_20_TABLE_GUID;
|
||||
EFI_GUID acpi_table_guid = ACPI_TABLE_GUID;
|
||||
if (CompareGuid(&acpi_20_table_guid, &config_table->VendorGuid) == 0) {
|
||||
rsdp = config_table->VendorTable;
|
||||
break;
|
||||
}
|
||||
|
||||
if (CompareGuid(&acpi_table_guid, &config_table->VendorGuid) == 0)
|
||||
rsdp = config_table->VendorTable;
|
||||
|
||||
config_table++;
|
||||
}
|
||||
|
||||
if (!rsdp) {
|
||||
Print(L"unable to find RSDP\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
||||
/* We're just interested in the map's size for now */
|
||||
map_size = 0;
|
||||
err = get_memory_map(&map_size, NULL, NULL, NULL, NULL);
|
||||
if (err != EFI_SUCCESS && err != EFI_BUFFER_TOO_SMALL)
|
||||
goto out;
|
||||
|
||||
again:
|
||||
_map_size = map_size;
|
||||
err = emalloc(map_size, 1, &addr);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto out;
|
||||
map_buf = (EFI_MEMORY_DESCRIPTOR *)(UINTN)addr;
|
||||
|
||||
/*
|
||||
* Remember! We've already allocated map_buf with emalloc (and
|
||||
* 'map_size' contains its size) which means that it should be
|
||||
* positioned below our allocation for the kernel. Use that
|
||||
* space for the memory map.
|
||||
*/
|
||||
err = get_memory_map(&map_size, map_buf, &map_key,
|
||||
&desc_size, &desc_version);
|
||||
if (err != EFI_SUCCESS) {
|
||||
if (err == EFI_BUFFER_TOO_SMALL) {
|
||||
/*
|
||||
* Argh! The buffer that we allocated further
|
||||
* up wasn't large enough which means we need
|
||||
* to allocate them again, but this time
|
||||
* larger. 'map_size' has been updated by the
|
||||
* call to memory_map().
|
||||
*/
|
||||
efree((UINTN)map_buf, _map_size);
|
||||
goto again;
|
||||
}
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert the EFI memory map to E820.
|
||||
*/
|
||||
for (i = 0, j = 0; i < map_size / desc_size; i++) {
|
||||
EFI_MEMORY_DESCRIPTOR *d;
|
||||
unsigned int e820_type = 0;
|
||||
|
||||
d = (EFI_MEMORY_DESCRIPTOR *)((unsigned long)map_buf + (i * desc_size));
|
||||
switch(d->Type) {
|
||||
case EfiReservedMemoryType:
|
||||
case EfiRuntimeServicesCode:
|
||||
case EfiRuntimeServicesData:
|
||||
case EfiMemoryMappedIO:
|
||||
case EfiMemoryMappedIOPortSpace:
|
||||
case EfiPalCode:
|
||||
e820_type = E820_RESERVED;
|
||||
break;
|
||||
|
||||
case EfiUnusableMemory:
|
||||
e820_type = E820_UNUSABLE;
|
||||
break;
|
||||
|
||||
case EfiACPIReclaimMemory:
|
||||
e820_type = E820_ACPI;
|
||||
break;
|
||||
|
||||
case EfiLoaderCode:
|
||||
case EfiLoaderData:
|
||||
case EfiBootServicesCode:
|
||||
case EfiBootServicesData:
|
||||
case EfiConventionalMemory:
|
||||
e820_type = E820_RAM;
|
||||
break;
|
||||
|
||||
case EfiACPIMemoryNVS:
|
||||
e820_type = E820_NVS;
|
||||
break;
|
||||
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
if (e820_type == E820_RAM) {
|
||||
UINT64 start = d->PhysicalStart;
|
||||
UINT64 end = d->PhysicalStart + (d->NumberOfPages<<EFI_PAGE_SHIFT);
|
||||
if (start <= ACRN_HV_ADDR && end > (ACRN_HV_ADDR + ACRN_HV_SIZE))
|
||||
Print(L"e820[%d] start=%lx len=%lx\n", i, d->PhysicalStart, d->NumberOfPages << EFI_PAGE_SHIFT);
|
||||
}
|
||||
|
||||
if (j && mmap[j-1].mm_type == e820_type &&
|
||||
(mmap[j-1].mm_base_addr + mmap[j-1].mm_length) == d->PhysicalStart) {
|
||||
mmap[j-1].mm_length += d->NumberOfPages << EFI_PAGE_SHIFT;
|
||||
} else {
|
||||
mmap[j].mm_base_addr = d->PhysicalStart;
|
||||
mmap[j].mm_length = d->NumberOfPages << EFI_PAGE_SHIFT;
|
||||
mmap[j].mm_type = e820_type;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
/* switch hv memory region(0x20000000 ~ 0x22000000) to availiable RAM in e820 table */
|
||||
mmap[j].mm_base_addr = ACRN_HV_ADDR;
|
||||
mmap[j].mm_length = ACRN_HV_SIZE;
|
||||
mmap[j].mm_type = E820_RAM;
|
||||
j++;
|
||||
|
||||
/* reserve secondary memory region(0x1000 ~ 0x10000) for hv */
|
||||
err = __emalloc(ACRN_SECONDARY_SIZE, ACRN_SECONDARY_ADDR, &addr, EfiReservedMemoryType);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto out;
|
||||
|
||||
mbi->mi_flags |= MULTIBOOT_INFO_HAS_MMAP | MULTIBOOT_INFO_HAS_CMDLINE;
|
||||
mbi->mi_mmap_length = j*sizeof(struct multiboot_mmap);
|
||||
|
||||
//mbi->mi_cmdline = (UINTN)"uart=mmio@0x92230000";
|
||||
//mbi->mi_cmdline = (UINTN)"uart=port@0x3F8";
|
||||
mbi->mi_cmdline = (UINTN)"uart=disabled";
|
||||
mbi->mi_mmap_addr = (UINTN)mmap;
|
||||
|
||||
#ifdef LEAGCY_BIOS
|
||||
/* copy rsdt in low memory space(0~0x1000) for hypervisor parsing */
|
||||
memcpy((void *)0x500, (void*)rsdp, sizeof(struct acpi_table_rsdp));
|
||||
*(UINT16*)(0x40E) = 0x50;
|
||||
#endif
|
||||
//Print(L"start 9!\n");
|
||||
|
||||
asm volatile ("mov %%cr0, %0":"=r"(pe->cr0));
|
||||
asm volatile ("mov %%cr3, %0":"=r"(pe->cr3));
|
||||
asm volatile ("mov %%cr4, %0":"=r"(pe->cr4));
|
||||
asm volatile ("sidt %0" :: "m" (pe->idt));
|
||||
asm volatile ("sgdt %0" :: "m" (pe->gdt));
|
||||
asm volatile ("str %0" :: "m" (pe->tr_sel));
|
||||
asm volatile ("sldt %0" :: "m" (pe->ldt_sel));
|
||||
|
||||
asm volatile ("mov %%cs, %%ax": "=a"(pe->cs_sel));
|
||||
asm volatile ("lar %%eax, %%eax"
|
||||
:"=a"(pe->cs_ar)
|
||||
:"a"(pe->cs_sel)
|
||||
);
|
||||
pe->cs_ar = (pe->cs_ar >> 8) & 0xf0ff; /* clear bits 11:8 */
|
||||
|
||||
asm volatile ("mov %%es, %%ax": "=a"(pe->es_sel));
|
||||
asm volatile ("mov %%ss, %%ax": "=a"(pe->ss_sel));
|
||||
asm volatile ("mov %%ds, %%ax": "=a"(pe->ds_sel));
|
||||
asm volatile ("mov %%fs, %%ax": "=a"(pe->fs_sel));
|
||||
asm volatile ("mov %%gs, %%ax": "=a"(pe->gs_sel));
|
||||
|
||||
|
||||
uint32_t idx = 0xC0000080; /* MSR_IA32_EFER */
|
||||
uint32_t msrl, msrh;
|
||||
asm volatile ("rdmsr":"=a"(msrl), "=d"(msrh): "c"(idx));
|
||||
pe->efer = ((uint64_t)msrh<<32) | msrl;
|
||||
|
||||
asm volatile ("pushf\n\t"
|
||||
"pop %0\n\t"
|
||||
:"=r"(pe->rflags):);
|
||||
|
||||
asm volatile ("movq %%rsp, %0":"=r"(pe->rsp));
|
||||
|
||||
hv_jump(ACRN_HV_ADDR, mbi, pe);
|
||||
out:
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static EFI_STATUS
|
||||
parse_args(CHAR16 *options, UINT32 size, CHAR16 **name,
|
||||
CHAR16 **hcmdline, CHAR16 **scmdline)
|
||||
{
|
||||
CHAR16 *n, *p, *cmdline, *search;
|
||||
UINTN i = 0;
|
||||
|
||||
*hcmdline = NULL;
|
||||
*scmdline = NULL;
|
||||
*name = NULL;
|
||||
|
||||
cmdline = StrDuplicate(options);
|
||||
|
||||
search = PoolPrint(L"sos=");
|
||||
n = strstr_16(cmdline, search);
|
||||
if (!n) {
|
||||
Print(L"Failed to get sos\n");
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
FreePool(search);
|
||||
|
||||
|
||||
n += 4;
|
||||
p = n;
|
||||
i = 0;
|
||||
while (*n && !isspace((CHAR8)*n)) {
|
||||
n++; i++;
|
||||
}
|
||||
*n++ = '\0';
|
||||
*name = p;
|
||||
|
||||
*scmdline = n;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* efi_main - The entry point for the OS loader image.
|
||||
* @image: firmware-allocated handle that identifies the image
|
||||
* @sys_table: EFI system table
|
||||
*/
|
||||
EFI_STATUS
|
||||
efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *_table)
|
||||
{
|
||||
WCHAR *error_buf;
|
||||
EFI_STATUS err;
|
||||
EFI_LOADED_IMAGE *info;
|
||||
EFI_PHYSICAL_ADDRESS addr;
|
||||
CHAR16 *options = NULL, *name;
|
||||
UINT32 options_size = 0;
|
||||
CHAR16 *hcmdline, *scmdline;
|
||||
UINTN sec_addr;
|
||||
UINTN sec_size;
|
||||
char *section;
|
||||
|
||||
|
||||
InitializeLib(image, _table);
|
||||
|
||||
sys_table = _table;
|
||||
boot = sys_table->BootServices;
|
||||
runtime = sys_table->RuntimeServices;
|
||||
|
||||
if (CheckCrc(sys_table->Hdr.HeaderSize, &sys_table->Hdr) != TRUE)
|
||||
return EFI_LOAD_ERROR;
|
||||
|
||||
|
||||
err = handle_protocol(image, &LoadedImageProtocol, (void **)&info);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto failed;
|
||||
|
||||
options = info->LoadOptions;
|
||||
options_size = info->LoadOptionsSize;
|
||||
|
||||
err = parse_args(options, options_size, &name, &hcmdline, &scmdline);
|
||||
if (err != EFI_SUCCESS)
|
||||
return err;
|
||||
|
||||
section = ".hv";
|
||||
err = get_pe_section(info->ImageBase, section, &sec_addr, &sec_size);
|
||||
if (EFI_ERROR(err)) {
|
||||
Print(L"Unable to locate section of ACRNHV %r ", err);
|
||||
goto failed;
|
||||
}
|
||||
|
||||
err = __emalloc(ACRN_HV_SIZE, ACRN_HV_ADDR, &addr, EfiReservedMemoryType);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto failed;
|
||||
|
||||
/* Copy ACRNHV binary to fixed phys addr. LoadImage and StartImage ?? */
|
||||
memcpy((char*)addr, info->ImageBase + sec_addr, sec_size);
|
||||
|
||||
/* load sos and run hypervisor */
|
||||
err = load_sos_image(image, name, scmdline);
|
||||
|
||||
if (err != EFI_SUCCESS)
|
||||
goto free_args;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
|
||||
free_args:
|
||||
free(name);
|
||||
failed:
|
||||
/*
|
||||
* We need to be careful not to trash 'err' here. If we fail
|
||||
* to allocate enough memory to hold the error string fallback
|
||||
* to returning 'err'.
|
||||
*/
|
||||
if (allocate_pool(EfiLoaderData, ERROR_STRING_LENGTH,
|
||||
(void **)&error_buf) != EFI_SUCCESS) {
|
||||
Print(L"Couldn't allocate pages for error string\n");
|
||||
return err;
|
||||
}
|
||||
|
||||
StatusToString(error_buf, err);
|
||||
Print(L": %s\n", error_buf);
|
||||
return exit(image, err, ERROR_STRING_LENGTH, error_buf);
|
||||
}
|
||||
|
100
hypervisor/bsp/uefi/efi/boot.h
Normal file
100
hypervisor/bsp/uefi/efi/boot.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __ACRNBOOT_H__
|
||||
#define __ACRNBOOT_H__
|
||||
|
||||
#define E820_RAM 1
|
||||
#define E820_RESERVED 2
|
||||
#define E820_ACPI 3
|
||||
#define E820_NVS 4
|
||||
#define E820_UNUSABLE 5
|
||||
|
||||
#define ACRN_HV_SIZE 0x2000000
|
||||
#define ACRN_HV_ADDR 0x20000000
|
||||
|
||||
#define ACRN_SECONDARY_SIZE 0xf000
|
||||
#define ACRN_SECONDARY_ADDR 0x8000
|
||||
|
||||
|
||||
EFI_STATUS get_pe_section(CHAR8 *base, char *section, UINTN *vaddr, UINTN *size);
|
||||
EFI_STATUS load_sos_image(EFI_HANDLE image, CHAR16 *name, CHAR16 *cmdline);
|
||||
|
||||
struct efi_info {
|
||||
UINT32 efi_loader_signature;
|
||||
UINT32 efi_systab;
|
||||
UINT32 efi_memdesc_size;
|
||||
UINT32 efi_memdesc_version;
|
||||
UINT32 efi_memmap;
|
||||
UINT32 efi_memmap_size;
|
||||
UINT32 efi_systab_hi;
|
||||
UINT32 efi_memmap_hi;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
UINT16 limit;
|
||||
UINT64 *base;
|
||||
} __attribute__((packed)) dt_addr_t;
|
||||
|
||||
struct e820_entry {
|
||||
UINT64 addr; /* start of memory segment */
|
||||
UINT64 size; /* size of memory segment */
|
||||
UINT32 type; /* type of memory segment */
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct efi_ctx {
|
||||
EFI_IMAGE_ENTRY_POINT entry;
|
||||
EFI_HANDLE handle;
|
||||
EFI_SYSTEM_TABLE* table;
|
||||
dt_addr_t gdt;
|
||||
dt_addr_t idt;
|
||||
uint16_t tr_sel;
|
||||
uint16_t ldt_sel;
|
||||
uint64_t cr0;
|
||||
uint64_t cr3;
|
||||
uint64_t cr4;
|
||||
uint64_t rflags;
|
||||
uint16_t cs_sel;
|
||||
uint32_t cs_ar;
|
||||
uint16_t es_sel;
|
||||
uint16_t ss_sel;
|
||||
uint16_t ds_sel;
|
||||
uint16_t fs_sel;
|
||||
uint16_t gs_sel;
|
||||
uint64_t rsp;
|
||||
uint64_t efer;
|
||||
}__attribute__((packed));
|
||||
|
||||
#endif
|
||||
|
238
hypervisor/bsp/uefi/efi/efilinux.h
Normal file
238
hypervisor/bsp/uefi/efi/efilinux.h
Normal file
@@ -0,0 +1,238 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file contains some wrappers around the gnu-efi functions. As
|
||||
* we're not going through uefi_call_wrapper() directly, this allows
|
||||
* us to get some type-safety for function call arguments and for the
|
||||
* compiler to check that the number of function call arguments is
|
||||
* correct.
|
||||
*
|
||||
* It's also a good place to document the EFI interface.
|
||||
*/
|
||||
|
||||
#ifndef __EFILINUX_H__
|
||||
#define __EFILINUX_H__
|
||||
|
||||
#define EFILINUX_VERSION_MAJOR 1
|
||||
#define EFILINUX_VERSION_MINOR 0
|
||||
|
||||
|
||||
extern EFI_SYSTEM_TABLE *sys_table;
|
||||
extern EFI_BOOT_SERVICES *boot;
|
||||
extern EFI_RUNTIME_SERVICES *runtime;
|
||||
|
||||
/**
|
||||
* allocate_pages - Allocate memory pages from the system
|
||||
* @atype: type of allocation to perform
|
||||
* @mtype: type of memory to allocate
|
||||
* @num_pages: number of contiguous 4KB pages to allocate
|
||||
* @memory: used to return the address of allocated pages
|
||||
*
|
||||
* Allocate @num_pages physically contiguous pages from the system
|
||||
* memory and return a pointer to the base of the allocation in
|
||||
* @memory if the allocation succeeds. On success, the firmware memory
|
||||
* map is updated accordingly.
|
||||
*
|
||||
* If @atype is AllocateAddress then, on input, @memory specifies the
|
||||
* address at which to attempt to allocate the memory pages.
|
||||
*/
|
||||
static inline EFI_STATUS
|
||||
allocate_pages(EFI_ALLOCATE_TYPE atype, EFI_MEMORY_TYPE mtype,
|
||||
UINTN num_pages, EFI_PHYSICAL_ADDRESS *memory)
|
||||
{
|
||||
return uefi_call_wrapper(boot->AllocatePages, 4, atype,
|
||||
mtype, num_pages, memory);
|
||||
}
|
||||
|
||||
/**
|
||||
* free_pages - Return memory allocated by allocate_pages() to the firmware
|
||||
* @memory: physical base address of the page range to be freed
|
||||
* @num_pages: number of contiguous 4KB pages to free
|
||||
*
|
||||
* On success, the firmware memory map is updated accordingly.
|
||||
*/
|
||||
static inline EFI_STATUS
|
||||
free_pages(EFI_PHYSICAL_ADDRESS memory, UINTN num_pages)
|
||||
{
|
||||
return uefi_call_wrapper(boot->FreePages, 2, memory, num_pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* allocate_pool - Allocate pool memory
|
||||
* @type: the type of pool to allocate
|
||||
* @size: number of bytes to allocate from pool of @type
|
||||
* @buffer: used to return the address of allocated memory
|
||||
*
|
||||
* Allocate memory from pool of @type. If the pool needs more memory
|
||||
* pages are allocated from EfiConventionalMemory in order to grow the
|
||||
* pool.
|
||||
*
|
||||
* All allocations are eight-byte aligned.
|
||||
*/
|
||||
static inline EFI_STATUS
|
||||
allocate_pool(EFI_MEMORY_TYPE type, UINTN size, void **buffer)
|
||||
{
|
||||
return uefi_call_wrapper(boot->AllocatePool, 3, type, size, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* free_pool - Return pool memory to the system
|
||||
* @buffer: the buffer to free
|
||||
*
|
||||
* Return @buffer to the system. The returned memory is marked as
|
||||
* EfiConventionalMemory.
|
||||
*/
|
||||
static inline EFI_STATUS free_pool(void *buffer)
|
||||
{
|
||||
return uefi_call_wrapper(boot->FreePool, 1, buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* get_memory_map - Return the current memory map
|
||||
* @size: the size in bytes of @map
|
||||
* @map: buffer to hold the current memory map
|
||||
* @key: used to return the key for the current memory map
|
||||
* @descr_size: used to return the size in bytes of EFI_MEMORY_DESCRIPTOR
|
||||
* @descr_version: used to return the version of EFI_MEMORY_DESCRIPTOR
|
||||
*
|
||||
* Get a copy of the current memory map. The memory map is an array of
|
||||
* EFI_MEMORY_DESCRIPTORs. An EFI_MEMORY_DESCRIPTOR describes a
|
||||
* contiguous block of memory.
|
||||
*
|
||||
* On success, @key is updated to contain an identifer for the current
|
||||
* memory map. The firmware's key is changed every time something in
|
||||
* the memory map changes. @size is updated to indicate the size of
|
||||
* the memory map pointed to by @map.
|
||||
*
|
||||
* @descr_size and @descr_version are used to ensure backwards
|
||||
* compatibility with future changes made to the EFI_MEMORY_DESCRIPTOR
|
||||
* structure. @descr_size MUST be used when the size of an
|
||||
* EFI_MEMORY_DESCRIPTOR is used in a calculation, e.g when iterating
|
||||
* over an array of EFI_MEMORY_DESCRIPTORs.
|
||||
*
|
||||
* On failure, and if the buffer pointed to by @map is too small to
|
||||
* hold the memory map, EFI_BUFFER_TOO_SMALL is returned and @size is
|
||||
* updated to reflect the size of a buffer required to hold the memory
|
||||
* map.
|
||||
*/
|
||||
static inline EFI_STATUS
|
||||
get_memory_map(UINTN *size, EFI_MEMORY_DESCRIPTOR *map, UINTN *key,
|
||||
UINTN *descr_size, UINT32 *descr_version)
|
||||
{
|
||||
return uefi_call_wrapper(boot->GetMemoryMap, 5, size, map,
|
||||
key, descr_size, descr_version);
|
||||
}
|
||||
|
||||
/**
|
||||
* exit_boot_serivces - Terminate all boot services
|
||||
* @image: firmware-allocated handle that identifies the image
|
||||
* @key: key to the latest memory map
|
||||
*
|
||||
* This function is called when efilinux wants to take complete
|
||||
* control of the system. efilinux should not make calls to boot time
|
||||
* services after this function is called.
|
||||
*/
|
||||
static inline EFI_STATUS
|
||||
exit_boot_services(EFI_HANDLE image, UINTN key)
|
||||
{
|
||||
return uefi_call_wrapper(boot->ExitBootServices, 2, image, key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* handle_protocol - Query @handle to see if it supports @protocol
|
||||
* @handle: the handle being queried
|
||||
* @protocol: the GUID of the protocol
|
||||
* @interface: used to return the protocol interface
|
||||
*
|
||||
* Query @handle to see if @protocol is supported. If it is supported,
|
||||
* @interface contains the protocol interface.
|
||||
*/
|
||||
static inline EFI_STATUS
|
||||
handle_protocol(EFI_HANDLE handle, EFI_GUID *protocol, void **interface)
|
||||
{
|
||||
return uefi_call_wrapper(boot->HandleProtocol, 3,
|
||||
handle, protocol, interface);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* exit - Terminate a loaded EFI image
|
||||
* @image: firmware-allocated handle that identifies the image
|
||||
* @status: the image's exit code
|
||||
* @size: size in bytes of @reason. Ignored if @status is EFI_SUCCESS
|
||||
* @reason: a NUL-terminated status string, optionally followed by binary data
|
||||
*
|
||||
* This function terminates @image and returns control to the boot
|
||||
* services. This function MUST NOT be called until all loaded child
|
||||
* images have exited. All memory allocated by the image must be freed
|
||||
* before calling this function, apart from the buffer @reason, which
|
||||
* will be freed by the firmware.
|
||||
*/
|
||||
static inline EFI_STATUS
|
||||
exit(EFI_HANDLE image, EFI_STATUS status, UINTN size, CHAR16 *reason)
|
||||
{
|
||||
return uefi_call_wrapper(boot->Exit, 4, image, status, size, reason);
|
||||
}
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
static const CHAR16 *memory_types[] = {
|
||||
L"EfiReservedMemoryType",
|
||||
L"EfiLoaderCode",
|
||||
L"EfiLoaderData",
|
||||
L"EfiBootServicesCode",
|
||||
L"EfiBootServicesData",
|
||||
L"EfiRuntimeServicesCode",
|
||||
L"EfiRuntimeServicesData",
|
||||
L"EfiConventionalMemory",
|
||||
L"EfiUnusableMemory",
|
||||
L"EfiACPIReclaimMemory",
|
||||
L"EfiACPIMemoryNVS",
|
||||
L"EfiMemoryMappedIO",
|
||||
L"EfiMemoryMappedIOPortSpace",
|
||||
L"EfiPalCode",
|
||||
};
|
||||
|
||||
static inline const CHAR16 *memory_type_to_str(UINT32 type)
|
||||
{
|
||||
if (type > sizeof(memory_types)/sizeof(CHAR16 *))
|
||||
return L"Unknown";
|
||||
|
||||
return memory_types[type];
|
||||
}
|
||||
|
||||
extern EFI_STATUS memory_map(EFI_MEMORY_DESCRIPTOR **map_buf,
|
||||
UINTN *map_size, UINTN *map_key,
|
||||
UINTN *desc_size, UINT32 *desc_version);
|
||||
|
||||
#endif /* __EFILINUX_H__ */
|
271
hypervisor/bsp/uefi/efi/malloc.c
Normal file
271
hypervisor/bsp/uefi/efi/malloc.c
Normal file
@@ -0,0 +1,271 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
#include "efilinux.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
/**
|
||||
* emalloc - Allocate memory with a strict alignment requirement
|
||||
* @size: size in bytes of the requested allocation
|
||||
* @align: the required alignment of the allocation
|
||||
* @addr: a pointer to the allocated address on success
|
||||
*
|
||||
* If we cannot satisfy @align we return 0.
|
||||
*/
|
||||
EFI_STATUS emalloc(UINTN size, UINTN align, EFI_PHYSICAL_ADDRESS *addr)
|
||||
{
|
||||
UINTN map_size, map_key, desc_size;
|
||||
EFI_MEMORY_DESCRIPTOR *map_buf;
|
||||
UINTN d, map_end;
|
||||
UINT32 desc_version;
|
||||
EFI_STATUS err;
|
||||
UINTN nr_pages = EFI_SIZE_TO_PAGES(size);
|
||||
|
||||
err = memory_map(&map_buf, &map_size, &map_key,
|
||||
&desc_size, &desc_version);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
d = (UINTN)map_buf;
|
||||
map_end = (UINTN)map_buf + map_size;
|
||||
|
||||
for (; d < map_end; d += desc_size) {
|
||||
EFI_MEMORY_DESCRIPTOR *desc;
|
||||
EFI_PHYSICAL_ADDRESS start, end, aligned;
|
||||
|
||||
desc = (EFI_MEMORY_DESCRIPTOR *)d;
|
||||
if (desc->Type != EfiConventionalMemory)
|
||||
continue;
|
||||
|
||||
if (desc->NumberOfPages < nr_pages)
|
||||
continue;
|
||||
|
||||
start = desc->PhysicalStart;
|
||||
end = start + (desc->NumberOfPages << EFI_PAGE_SHIFT);
|
||||
|
||||
/* Low-memory is super-precious! */
|
||||
if (end <= 1 << 20)
|
||||
continue;
|
||||
if (start < 1 << 20) {
|
||||
size -= (1 << 20) - start;
|
||||
start = (1 << 20);
|
||||
}
|
||||
|
||||
aligned = (start + align -1) & ~(align -1);
|
||||
|
||||
if ((aligned + size) <= end) {
|
||||
err = allocate_pages(AllocateAddress, EfiLoaderData,
|
||||
nr_pages, &aligned);
|
||||
if (err == EFI_SUCCESS) {
|
||||
*addr = aligned;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d == map_end)
|
||||
err = EFI_OUT_OF_RESOURCES;
|
||||
|
||||
free_pool(map_buf);
|
||||
fail:
|
||||
return err;
|
||||
}
|
||||
|
||||
EFI_STATUS __emalloc(UINTN size, UINTN align, EFI_PHYSICAL_ADDRESS *addr, EFI_MEMORY_TYPE mem_type)
|
||||
{
|
||||
UINTN map_size, map_key, desc_size;
|
||||
EFI_MEMORY_DESCRIPTOR *map_buf;
|
||||
UINTN d, map_end;
|
||||
UINT32 desc_version;
|
||||
EFI_STATUS err;
|
||||
UINTN nr_pages = EFI_SIZE_TO_PAGES(size);
|
||||
|
||||
err = memory_map(&map_buf, &map_size, &map_key,
|
||||
&desc_size, &desc_version);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
d = (UINTN)map_buf;
|
||||
map_end = (UINTN)map_buf + map_size;
|
||||
|
||||
for (; d < map_end; d += desc_size) {
|
||||
EFI_MEMORY_DESCRIPTOR *desc;
|
||||
EFI_PHYSICAL_ADDRESS start, end, aligned;
|
||||
|
||||
desc = (EFI_MEMORY_DESCRIPTOR *)d;
|
||||
if (desc->Type != EfiConventionalMemory)
|
||||
continue;
|
||||
|
||||
if (desc->NumberOfPages < nr_pages)
|
||||
continue;
|
||||
|
||||
start = desc->PhysicalStart;
|
||||
end = start + (desc->NumberOfPages << EFI_PAGE_SHIFT);
|
||||
|
||||
/* Low-memory is super-precious! */
|
||||
if (end <= 1 << 20)
|
||||
continue;
|
||||
if (start < 1 << 20) {
|
||||
size -= (1 << 20) - start;
|
||||
start = (1 << 20);
|
||||
}
|
||||
|
||||
aligned = align;//(start + align -1) & ~(align -1);
|
||||
|
||||
|
||||
if ((aligned + size) <= end) {
|
||||
//Print(L"trying to allocate memory at %0x!\n", aligned);
|
||||
err = allocate_pages(AllocateAddress, mem_type,
|
||||
nr_pages, &aligned);
|
||||
if (err == EFI_SUCCESS) {
|
||||
//Print(L"trying to allocate memory at %0x, success!\n", aligned);
|
||||
*addr = aligned;
|
||||
break;
|
||||
} {
|
||||
//Print(L"trying to allocate memory at %0x, failure!\n", aligned);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d == map_end)
|
||||
err = EFI_OUT_OF_RESOURCES;
|
||||
|
||||
free_pool(map_buf);
|
||||
fail:
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* efree - Return memory allocated with emalloc
|
||||
* @memory: the address of the emalloc() allocation
|
||||
* @size: the size of the allocation
|
||||
*/
|
||||
void efree(EFI_PHYSICAL_ADDRESS memory, UINTN size)
|
||||
{
|
||||
UINTN nr_pages = EFI_SIZE_TO_PAGES(size);
|
||||
|
||||
free_pages(memory, nr_pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* malloc - Allocate memory from the EfiLoaderData pool
|
||||
* @size: size in bytes of the requested allocation
|
||||
*
|
||||
* Return a pointer to an allocation of @size bytes of type
|
||||
* EfiLoaderData.
|
||||
*/
|
||||
void *malloc(UINTN size)
|
||||
{
|
||||
EFI_STATUS err;
|
||||
void *buffer;
|
||||
|
||||
err = allocate_pool(EfiLoaderData, size, &buffer);
|
||||
if (err != EFI_SUCCESS)
|
||||
buffer = NULL;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* free - Release memory to the EfiLoaderData pool
|
||||
* @buffer: pointer to the malloc() allocation to free
|
||||
*/
|
||||
void free(void *buffer)
|
||||
{
|
||||
if (buffer)
|
||||
free_pool(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* calloc - Allocate zeroed memory for an array of elements
|
||||
* @nmemb: number of elements
|
||||
* @size: size of each element
|
||||
*/
|
||||
void *calloc(UINTN nmemb, UINTN size)
|
||||
{
|
||||
void *buffer;
|
||||
|
||||
/*
|
||||
* There's no equivalent of UINTN_MAX, so for safety we refuse to
|
||||
* allocate anything larger than 32 bits.
|
||||
*/
|
||||
UINTN bytes = nmemb * size;
|
||||
if ((nmemb | size) > 0xffffU) {
|
||||
if (size && bytes / size != nmemb)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buffer = malloc(bytes);
|
||||
if (buffer)
|
||||
memset(buffer, 0, bytes);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
EFI_STATUS dump_e820(void)
|
||||
{
|
||||
UINTN map_size, map_key, desc_size;
|
||||
EFI_MEMORY_DESCRIPTOR *map_buf;
|
||||
UINTN d, map_end;
|
||||
UINTN i;
|
||||
UINT32 desc_version;
|
||||
EFI_STATUS err;
|
||||
|
||||
err = memory_map(&map_buf, &map_size, &map_key,
|
||||
&desc_size, &desc_version);
|
||||
if (err != EFI_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
d = (UINTN)map_buf;
|
||||
map_end = (UINTN)map_buf + map_size;
|
||||
|
||||
for (i = 0; d < map_end; d += desc_size, i++) {
|
||||
EFI_MEMORY_DESCRIPTOR *desc;
|
||||
EFI_PHYSICAL_ADDRESS start, end;
|
||||
|
||||
desc = (EFI_MEMORY_DESCRIPTOR *)d;
|
||||
if (desc->Type != EfiConventionalMemory)
|
||||
continue;
|
||||
|
||||
start = desc->PhysicalStart;
|
||||
end = start + (desc->NumberOfPages << EFI_PAGE_SHIFT);
|
||||
|
||||
Print(L"[%d]start:%lx, end:%lx, type:%d\n", i, start, end, desc->Type);
|
||||
}
|
||||
|
||||
free_pool(map_buf);
|
||||
fail:
|
||||
return err;
|
||||
}
|
||||
|
186
hypervisor/bsp/uefi/efi/multiboot.h
Normal file
186
hypervisor/bsp/uefi/efi/multiboot.h
Normal file
@@ -0,0 +1,186 @@
|
||||
/* [ORIGIN: src/sys/arch/i386/include/... */
|
||||
/* $NetBSD: multiboot.h,v 1.8 2009/02/22 18:05:42 ahoka Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Julio M. Merino Vidal.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* multiboot.h
|
||||
*/
|
||||
|
||||
#ifndef _MULTIBOOT_H
|
||||
#define _MULTIBOOT_H
|
||||
|
||||
#include <stdint.h>
|
||||
//typedef uintptr_t uint32_t;
|
||||
typedef uintptr_t vaddr_t;
|
||||
|
||||
struct multiboot_info;
|
||||
extern struct multiboot_info mbi;
|
||||
|
||||
// ========================================================================
|
||||
|
||||
/*
|
||||
* Multiboot header structure.
|
||||
*/
|
||||
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
|
||||
#define MULTIBOOT_HEADER_MODS_ALIGNED 0x00000001
|
||||
#define MULTIBOOT_HEADER_WANT_MEMORY 0x00000002
|
||||
#define MULTIBOOT_HEADER_HAS_VBE 0x00000004
|
||||
#define MULTIBOOT_HEADER_HAS_ADDR 0x00010000
|
||||
|
||||
#if !defined(_LOCORE)
|
||||
struct multiboot_header {
|
||||
uint32_t mh_magic;
|
||||
uint32_t mh_flags;
|
||||
uint32_t mh_checksum;
|
||||
|
||||
/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_ADDR. */
|
||||
uint32_t mh_header_addr;
|
||||
uint32_t mh_load_addr;
|
||||
uint32_t mh_load_end_addr;
|
||||
uint32_t mh_bss_end_addr;
|
||||
uint32_t mh_entry_addr;
|
||||
|
||||
/* Valid if mh_flags sets MULTIBOOT_HEADER_HAS_VBE. */
|
||||
uint32_t mh_mode_type;
|
||||
uint32_t mh_width;
|
||||
uint32_t mh_height;
|
||||
uint32_t mh_depth;
|
||||
};
|
||||
#endif /* !defined(_LOCORE) */
|
||||
|
||||
/*
|
||||
* Symbols defined in locore.S.
|
||||
*/
|
||||
extern struct multiboot_header *Multiboot_Header;
|
||||
|
||||
// ========================================================================
|
||||
/*
|
||||
* Multiboot information structure.
|
||||
*/
|
||||
#define MULTIBOOT_INFO_MAGIC 0x2BADB002
|
||||
#define MULTIBOOT_INFO_HAS_MEMORY 0x00000001
|
||||
#define MULTIBOOT_INFO_HAS_BOOT_DEVICE 0x00000002
|
||||
#define MULTIBOOT_INFO_HAS_CMDLINE 0x00000004
|
||||
#define MULTIBOOT_INFO_HAS_MODS 0x00000008
|
||||
#define MULTIBOOT_INFO_HAS_AOUT_SYMS 0x00000010
|
||||
#define MULTIBOOT_INFO_HAS_ELF_SYMS 0x00000020
|
||||
#define MULTIBOOT_INFO_HAS_MMAP 0x00000040
|
||||
#define MULTIBOOT_INFO_HAS_DRIVES 0x00000080
|
||||
#define MULTIBOOT_INFO_HAS_CONFIG_TABLE 0x00000100
|
||||
#define MULTIBOOT_INFO_HAS_LOADER_NAME 0x00000200
|
||||
#define MULTIBOOT_INFO_HAS_APM_TABLE 0x00000400
|
||||
#define MULTIBOOT_INFO_HAS_VBE 0x00000800
|
||||
|
||||
#if !defined(_LOCORE)
|
||||
struct multiboot_info {
|
||||
uint32_t mi_flags;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MEMORY. */
|
||||
uint32_t mi_mem_lower;
|
||||
uint32_t mi_mem_upper;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_BOOT_DEVICE. */
|
||||
uint8_t mi_boot_device_part3;
|
||||
uint8_t mi_boot_device_part2;
|
||||
uint8_t mi_boot_device_part1;
|
||||
uint8_t mi_boot_device_drive;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CMDLINE. */
|
||||
uint32_t mi_cmdline;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MODS. */
|
||||
uint32_t mi_mods_count;
|
||||
uint32_t mi_mods_addr;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_{AOUT,ELF}_SYMS. */
|
||||
uint32_t mi_elfshdr_num;
|
||||
uint32_t mi_elfshdr_size;
|
||||
uint32_t mi_elfshdr_addr;
|
||||
uint32_t mi_elfshdr_shndx;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_MMAP. */
|
||||
uint32_t mi_mmap_length;
|
||||
uint32_t mi_mmap_addr;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_DRIVES. */
|
||||
uint32_t mi_drives_length;
|
||||
uint32_t mi_drives_addr;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_CONFIG_TABLE. */
|
||||
uint32_t unused_mi_config_table;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_LOADER_NAME. */
|
||||
uint32_t mi_loader_name;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_APM. */
|
||||
uint32_t unused_mi_apm_table;
|
||||
|
||||
/* Valid if mi_flags sets MULTIBOOT_INFO_HAS_VBE. */
|
||||
uint32_t unused_mi_vbe_control_info;
|
||||
uint32_t unused_mi_vbe_mode_info;
|
||||
uint32_t unused_mi_vbe_interface_seg;
|
||||
uint32_t unused_mi_vbe_interface_off;
|
||||
uint32_t unused_mi_vbe_interface_len;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Memory mapping. This describes an entry in the memory mappings table
|
||||
* as pointed to by mi_mmap_addr.
|
||||
*
|
||||
* Be aware that mm_size specifies the size of all other fields *except*
|
||||
* for mm_size. In order to jump between two different entries, you
|
||||
* have to count mm_size + 4 bytes.
|
||||
*/
|
||||
struct __attribute__((packed)) multiboot_mmap {
|
||||
uint32_t mm_size;
|
||||
uint64_t mm_base_addr;
|
||||
uint64_t mm_length;
|
||||
uint32_t mm_type;
|
||||
};
|
||||
|
||||
/*
|
||||
* Modules. This describes an entry in the modules table as pointed
|
||||
* to by mi_mods_addr.
|
||||
*/
|
||||
|
||||
struct multiboot_module {
|
||||
uint32_t mmo_start;
|
||||
uint32_t mmo_end;
|
||||
char * mmo_string;
|
||||
uint32_t mmo_reserved;
|
||||
};
|
||||
|
||||
#endif /* !defined(_LOCORE) */
|
||||
|
||||
// ========================================================================
|
||||
|
||||
#endif /* _MULTIBOOT_H */
|
172
hypervisor/bsp/uefi/efi/pe.c
Normal file
172
hypervisor/bsp/uefi/efi/pe.c
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file contains some wrappers around the gnu-efi functions. As
|
||||
* we're not going through uefi_call_wrapper() directly, this allows
|
||||
* us to get some type-safety for function call arguments and for the
|
||||
* compiler to check that the number of function call arguments is
|
||||
* correct.
|
||||
*
|
||||
* It's also a good place to document the EFI interface.
|
||||
*/
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
#include "stdlib.h"
|
||||
|
||||
#define DOS_FILE_MAGIC_NUMBER 0x5A4D //"MZ"
|
||||
struct DosFileHeader {
|
||||
uint16_t mMagic;
|
||||
uint16_t LastSize;
|
||||
uint16_t nBlocks;
|
||||
uint16_t nReloc;
|
||||
uint16_t HdrSize;
|
||||
uint16_t MinAlloc;
|
||||
uint16_t MaxAlloc;
|
||||
uint16_t ss;
|
||||
uint16_t sp;
|
||||
uint16_t Checksum;
|
||||
uint16_t ip;
|
||||
uint16_t cs;
|
||||
uint16_t RelocPos;
|
||||
uint16_t nOverlay;
|
||||
uint16_t reserved[4];
|
||||
uint16_t OEMId;
|
||||
uint16_t OEMInfo;
|
||||
uint16_t reserved2[10];
|
||||
uint32_t ExeHeader;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define IMAGE_FILE_MACHINE_I386 0x14c
|
||||
#define IMAGE_FILE_MACHINE_AMD64 0x8664
|
||||
#define PE_FILE_MAGIC_NUMBER 0x00004550 //"PE\0\0"
|
||||
struct PeHeader {
|
||||
uint32_t mMagic;
|
||||
uint16_t mMachine;
|
||||
uint16_t mNumberOfSections;
|
||||
uint32_t mTimeDateStamp;
|
||||
uint32_t mPointerToSymbolTable;
|
||||
uint32_t mNumberOfSymbols;
|
||||
uint16_t mSizeOfOptionalHeader;
|
||||
uint16_t mCharacteristics;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct OptionHeader {
|
||||
uint16_t Format;
|
||||
uint8_t MajorLinkVer;
|
||||
uint8_t MinorLinkVer;
|
||||
uint32_t CodeSize;
|
||||
uint32_t InitializedDataSize;
|
||||
uint32_t UninitializedDataSize;
|
||||
uint32_t EntryPoint;
|
||||
uint32_t BaseOfCode;
|
||||
uint32_t BaseOfDate;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
struct PeSectionHeader {
|
||||
char mName[8];
|
||||
uint32_t mVirtualSize;
|
||||
uint32_t mVirtualAddress;
|
||||
uint32_t mSizeOfRawData;
|
||||
uint32_t mPointerToRawData;
|
||||
uint32_t mPointerToRealocations;
|
||||
uint32_t mPointerToLinenumbers;
|
||||
uint16_t mNumberOfRealocations;
|
||||
uint16_t mNumberOfLinenumbers;
|
||||
uint32_t mCharacteristics;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
EFI_STATUS get_pe_section(CHAR8 *base, char *section, UINTN *vaddr, UINTN *size)
|
||||
{
|
||||
struct PeSectionHeader *ph;
|
||||
struct DosFileHeader *dh;
|
||||
struct PeHeader *pe;
|
||||
UINTN i;
|
||||
UINTN offset;
|
||||
|
||||
dh = (struct DosFileHeader *)base;
|
||||
|
||||
if (dh->mMagic != DOS_FILE_MAGIC_NUMBER)
|
||||
return EFI_LOAD_ERROR;
|
||||
|
||||
pe = (struct PeHeader *)&base[dh->ExeHeader];
|
||||
if (pe->mMagic != PE_FILE_MAGIC_NUMBER)
|
||||
return EFI_LOAD_ERROR;
|
||||
|
||||
if ((pe->mMachine != IMAGE_FILE_MACHINE_AMD64)
|
||||
&& (pe->mMachine != IMAGE_FILE_MACHINE_I386))
|
||||
return EFI_LOAD_ERROR;
|
||||
|
||||
offset = dh->ExeHeader + sizeof(*pe) + pe->mSizeOfOptionalHeader;
|
||||
|
||||
for (i = 0; i < pe->mNumberOfSections; i++) {
|
||||
ph = (struct PeSectionHeader *)&base[offset];
|
||||
if (CompareMem(ph->mName, section, strlen(section)) == 0) {
|
||||
*vaddr = (UINTN)ph->mVirtualAddress;
|
||||
*size = (UINTN)ph->mVirtualSize;
|
||||
break;
|
||||
}
|
||||
|
||||
offset += sizeof(*ph);
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
EFI_IMAGE_ENTRY_POINT get_pe_entry(CHAR8 *base)
|
||||
{
|
||||
struct DosFileHeader* dh;
|
||||
struct PeHeader* pe;
|
||||
struct OptionHeader* oh;
|
||||
UINTN offset;
|
||||
|
||||
dh = (struct DosFileHeader *)base;
|
||||
|
||||
if (dh->mMagic != DOS_FILE_MAGIC_NUMBER)
|
||||
return NULL;
|
||||
|
||||
pe = (struct PeHeader *)&base[dh->ExeHeader];
|
||||
if (pe->mMagic != PE_FILE_MAGIC_NUMBER)
|
||||
return NULL;
|
||||
|
||||
if ((pe->mMachine != IMAGE_FILE_MACHINE_AMD64)
|
||||
&& (pe->mMachine != IMAGE_FILE_MACHINE_I386))
|
||||
return NULL;
|
||||
|
||||
offset = dh->ExeHeader + sizeof(*pe);
|
||||
oh = (struct OptionHeader*)&base[offset];
|
||||
|
||||
return (EFI_IMAGE_ENTRY_POINT)((UINT64)base + oh->EntryPoint);
|
||||
}
|
137
hypervisor/bsp/uefi/efi/stdlib.h
Normal file
137
hypervisor/bsp/uefi/efi/stdlib.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Intel Corporation
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer
|
||||
* in the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file contains some wrappers around the gnu-efi functions. As
|
||||
* we're not going through uefi_call_wrapper() directly, this allows
|
||||
* us to get some type-safety for function call arguments and for the
|
||||
* compiler to check that the number of function call arguments is
|
||||
* correct.
|
||||
*
|
||||
* It's also a good place to document the EFI interface.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef __STDLIB_H__
|
||||
#define __STDLIB_H__
|
||||
|
||||
extern void *malloc(UINTN size);
|
||||
extern void free(void *buf);
|
||||
extern void *calloc(UINTN nmemb, UINTN size);
|
||||
|
||||
extern EFI_STATUS emalloc(UINTN, UINTN, EFI_PHYSICAL_ADDRESS *);
|
||||
extern EFI_STATUS __emalloc(UINTN, UINTN, EFI_PHYSICAL_ADDRESS *, EFI_MEMORY_TYPE);
|
||||
extern void efree(EFI_PHYSICAL_ADDRESS, UINTN);
|
||||
|
||||
static inline void memset(void *dstv, char ch, UINTN size)
|
||||
{
|
||||
char *dst = dstv;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
dst[i] = ch;
|
||||
}
|
||||
|
||||
static inline void memcpy(char *dst, const char *src, UINTN size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
*dst++ = *src++;
|
||||
}
|
||||
|
||||
static inline int strlen(const char *str)
|
||||
{
|
||||
int len;
|
||||
|
||||
len = 0;
|
||||
while (*str++)
|
||||
len++;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
static inline char *strstr(const char *haystack, const char *needle)
|
||||
{
|
||||
const char *p;
|
||||
const char *word = NULL;
|
||||
int len = strlen(needle);
|
||||
|
||||
if (!len)
|
||||
return NULL;
|
||||
|
||||
p = haystack;
|
||||
while (*p) {
|
||||
word = p;
|
||||
if (!strncmpa((CHAR8 *)p, (CHAR8 *)needle, len))
|
||||
break;
|
||||
p++;
|
||||
word = NULL;
|
||||
}
|
||||
|
||||
return (char *)word;
|
||||
}
|
||||
|
||||
static inline char *strdup(const char *src)
|
||||
{
|
||||
int len;
|
||||
char *dst;
|
||||
|
||||
len = strlen(src);
|
||||
dst = malloc(len + 1);
|
||||
if (dst)
|
||||
memcpy(dst, src, len + 1);
|
||||
return dst;
|
||||
}
|
||||
|
||||
static inline CHAR16 *strstr_16(CHAR16 *haystack, CHAR16 *needle)
|
||||
{
|
||||
CHAR16 *p;
|
||||
CHAR16 *word = NULL;
|
||||
UINTN len = StrLen(needle);
|
||||
|
||||
if (!len)
|
||||
return NULL;
|
||||
|
||||
p = haystack;
|
||||
while (*p) {
|
||||
if (!StrnCmp(p, needle, len)) {
|
||||
word = p;
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
return (CHAR16*)word;
|
||||
}
|
||||
|
||||
#endif /* __STDLIB_H__ */
|
52
hypervisor/bsp/uefi/include/bsp/bsp_cfg.h
Normal file
52
hypervisor/bsp/uefi/include/bsp/bsp_cfg.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef BSP_CFG_H
|
||||
#define BSP_CFG_H
|
||||
#define NR_IOAPICS 1
|
||||
#define STACK_SIZE 8192
|
||||
#define LOG_BUF_SIZE 0x100000
|
||||
#define LOG_DESTINATION 3
|
||||
#define CPU_UP_TIMEOUT 100
|
||||
#define CONFIG_SERIAL_PIO_BASE 0x3f8
|
||||
#define MALLOC_ALIGN 16
|
||||
#define NUM_ALLOC_PAGES 4096
|
||||
#define HEAP_SIZE 0x100000
|
||||
#define CONSOLE_LOGLEVEL_DEFAULT 2
|
||||
#define MEM_LOGLEVEL_DEFAULT 4
|
||||
#define CONFIG_LOW_RAM_START 0x00008000
|
||||
#define CONFIG_LOW_RAM_SIZE 0x000CF000
|
||||
#define CONFIG_RAM_START 0x20000000
|
||||
#define CONFIG_RAM_SIZE 0x02000000 /* 32M */
|
||||
#define CONFIG_DMAR_PARSE_ENABLED 1
|
||||
#define CONFIG_GPU_SBDF 0x00000010 /* 0000:00:02.0 */
|
||||
#define CONFIG_EFI_STUB 1
|
||||
#define CONFIG_RETPOLINE
|
||||
#endif /* BSP_CFG_H */
|
160
hypervisor/bsp/uefi/uefi.c
Normal file
160
hypervisor/bsp/uefi/uefi.c
Normal file
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <hv_lib.h>
|
||||
#include <acrn_common.h>
|
||||
#include <hv_arch.h>
|
||||
#include <bsp_extern.h>
|
||||
#include <multiboot.h>
|
||||
#ifdef CONFIG_EFI_STUB
|
||||
#include <acrn_efi.h>
|
||||
#endif
|
||||
#include <hv_debug.h>
|
||||
|
||||
/* IOAPIC id */
|
||||
#define UEFI_IOAPIC_ID 8
|
||||
/* IOAPIC base address */
|
||||
#define UEFI_IOAPIC_ADDR 0xfec00000
|
||||
/* IOAPIC range size */
|
||||
#define UEFI_IOAPIC_SIZE 0x100000
|
||||
/* Local APIC base address */
|
||||
#define UEFI_LAPIC_ADDR 0xfee00000
|
||||
/* Local APIC range size */
|
||||
#define UEFI_LAPIC_SIZE 0x100000
|
||||
/* Number of PCI IRQ assignments */
|
||||
#define UEFI_PCI_IRQ_ASSIGNMENT_NUM 28
|
||||
|
||||
#ifdef CONFIG_EFI_STUB
|
||||
uint32_t efi_physical_available_ap_bitmap = 0;
|
||||
uint32_t efi_wake_up_ap_bitmap = 0;
|
||||
struct efi_ctx* efi_ctx = NULL;
|
||||
int efi_launch_vector;
|
||||
extern uint32_t up_count;
|
||||
extern unsigned long pcpu_sync;
|
||||
|
||||
bool in_efi_boot_svc(void)
|
||||
{
|
||||
return (efi_wake_up_ap_bitmap != efi_physical_available_ap_bitmap);
|
||||
}
|
||||
|
||||
int efi_spurious_handler(int vector)
|
||||
{
|
||||
struct vcpu* vcpu;
|
||||
|
||||
if (get_cpu_id() != 0)
|
||||
return 0;
|
||||
|
||||
vcpu = per_cpu(vcpu, 0);
|
||||
if (vcpu && vcpu->launched) {
|
||||
int ret = vlapic_set_intr(vcpu, vector, 0);
|
||||
if (ret && in_efi_boot_svc())
|
||||
exec_vmwrite(VMX_ENTRY_INT_INFO_FIELD,
|
||||
VMX_INT_INFO_VALID | vector);
|
||||
} else
|
||||
efi_launch_vector = vector;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int sipi_from_efi_boot_service_exit(uint32_t dest, uint32_t mode, uint32_t vec)
|
||||
{
|
||||
if (efi_wake_up_ap_bitmap != efi_physical_available_ap_bitmap) {
|
||||
if (mode == APIC_DELMODE_STARTUP) {
|
||||
uint32_t cpu_id = cpu_find_logical_id(dest);
|
||||
send_startup_ipi(INTR_CPU_STARTUP_USE_DEST,
|
||||
cpu_id, (paddr_t)(vec<<12));
|
||||
efi_wake_up_ap_bitmap |= 1 << dest;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void efi_deferred_wakeup_pcpu(int cpu_id)
|
||||
{
|
||||
uint32_t timeout;
|
||||
uint32_t expected_up;
|
||||
|
||||
expected_up = up_count + 1;
|
||||
|
||||
send_startup_ipi(INTR_CPU_STARTUP_USE_DEST,
|
||||
cpu_id, (paddr_t)cpu_secondary_reset);
|
||||
|
||||
timeout = CPU_UP_TIMEOUT * 1000;
|
||||
|
||||
while ((up_count != expected_up)) {
|
||||
/* Delay 10us */
|
||||
udelay(10);
|
||||
|
||||
/* Decrement timeout value */
|
||||
timeout -= 10;
|
||||
}
|
||||
|
||||
bitmap_set(0, &pcpu_sync);
|
||||
}
|
||||
|
||||
int uefi_sw_loader(struct vm *vm, struct vcpu *vcpu)
|
||||
{
|
||||
int ret = 0;
|
||||
struct run_context *cur_context =
|
||||
&vcpu->arch_vcpu.contexts[vcpu->arch_vcpu.cur_context];
|
||||
|
||||
ASSERT(vm != NULL, "Incorrect argument");
|
||||
|
||||
pr_dbg("Loading guest to run-time location");
|
||||
|
||||
if (!is_vm0(vm))
|
||||
return load_guest(vm, vcpu);
|
||||
|
||||
vcpu->entry_addr = efi_ctx->entry;
|
||||
cur_context->guest_cpu_regs.regs.rcx = efi_ctx->handle;
|
||||
cur_context->guest_cpu_regs.regs.rdx = efi_ctx->table;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_bsp(void)
|
||||
{
|
||||
parse_hv_cmdline();
|
||||
|
||||
#ifdef CONFIG_EFI_STUB
|
||||
efi_ctx = (struct efi_ctx*)(uint64_t)boot_regs[2];
|
||||
ASSERT(efi_ctx != NULL, "");
|
||||
|
||||
vm_sw_loader = uefi_sw_loader;
|
||||
|
||||
spurious_handler = efi_spurious_handler;
|
||||
efi_launch_vector = -1;
|
||||
#endif
|
||||
}
|
69
hypervisor/bsp/uefi/vm_description.c
Normal file
69
hypervisor/bsp/uefi/vm_description.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* * Neither the name of Intel Corporation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <hypervisor.h>
|
||||
#include <hv_lib.h>
|
||||
#include <acrn_common.h>
|
||||
#include <hv_arch.h>
|
||||
|
||||
#define NUM_USER_VMS 2
|
||||
|
||||
/* Number of CPUs in VM0 */
|
||||
#define VM0_NUM_CPUS 1
|
||||
|
||||
/* Logical CPU IDs assigned to VM0 */
|
||||
int VM0_CPUS[VM0_NUM_CPUS] = {0};
|
||||
|
||||
/* Number of CPUs in VM1 */
|
||||
#define VM1_NUM_CPUS 2
|
||||
|
||||
/* Logical CPU IDs assigned with VM1 */
|
||||
int VM1_CPUS[VM1_NUM_CPUS] = {3, 1};
|
||||
|
||||
const struct vm_description_array vm_desc = {
|
||||
/* Number of user virtual machines */
|
||||
.num_vm_desc = NUM_USER_VMS,
|
||||
|
||||
/* Virtual Machine descriptions */
|
||||
.vm_desc_array = {
|
||||
{
|
||||
.vm_attr_name = "vm_0",
|
||||
.vm_hw_num_cores = VM0_NUM_CPUS,
|
||||
.vm_hw_logical_core_ids = &VM0_CPUS[0],
|
||||
.vm_state_info_privilege = VM_PRIVILEGE_LEVEL_HIGH,
|
||||
.vm_created = false,
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
const struct vm_description_array *get_vm_desc_base(void)
|
||||
{
|
||||
return &vm_desc;
|
||||
}
|
Reference in New Issue
Block a user