acrn-config: Reorg config tool folder

Remove vm_configs folder and move all the XML files and generic code example into config_tools/data

Tracked-On: #5644
Signed-off-by: Xie, nanlin <nanlin.xie@intel.com>
This commit is contained in:
Xie, nanlin
2021-01-23 07:24:06 +08:00
committed by wenlingz
parent 0ab5db9cf9
commit 97c9b24030
452 changed files with 1533 additions and 12205 deletions

View File

@@ -0,0 +1,6 @@
Please run scenario_cfg_gen.py to generate board related configuration files.
usage: python3 scenario_cfg_gen.py [h] --board <board_info_file> --scenario <scenario_info_file>
positional arguments:
board_info_file : file name of the board info XML
scenario_info_file : file name of the scenario info XML

View File

@@ -0,0 +1,101 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import common
import scenario_cfg_lib
import board_cfg_lib
IVSHMEM_HEADER_DEFINE = scenario_cfg_lib.HEADER_LICENSE + r"""
#ifndef IVSHMEM_CFG_H
#define IVSHMEM_CFG_H
"""
IVSHMEM_END_DEFINE = r"""#endif /* IVSHMEM_CFG_H */"""
def gen_common_header(config):
"""
This is common header for ivshmem_cfg.h
:param config: it is the pointer which file write to
:return: None
"""
print("{0}".format(IVSHMEM_HEADER_DEFINE), file=config)
def write_shmem_regions(config):
raw_shmem_regions = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "IVSHMEM", "IVSHMEM_REGION")
shmem_regions = []
shmem_dev_num = 0
for raw_shm in raw_shmem_regions:
if raw_shm is None or raw_shm.strip() == '':
continue
raw_shm_splited = raw_shm.split(',')
if len(raw_shm_splited) == 3 and raw_shm_splited[0].strip() != '' \
and raw_shm_splited[1].strip() != '' and len(raw_shm_splited[2].strip().split(':')) >= 1:
shmem_regions.append((raw_shm_splited[0].strip(), raw_shm_splited[1].strip(), raw_shm_splited[2].strip().split(':')))
shmem_dev_num += len(raw_shm_splited[2].strip().split(':'))
if len(shmem_regions) > 0:
shmem_cnt = 0
print("", file=config)
for shmem_region in shmem_regions:
print("#define IVSHMEM_SHM_REGION_%d\t"%shmem_cnt, end="", file=config)
print('"{}"'.format(shmem_region[0]), file=config)
shmem_cnt += 1
print("", file=config)
print("/*", file=config)
print(" * The IVSHMEM_SHM_SIZE is the sum of all memory regions.", file=config)
print(" * The size range of each memory region is [2MB, 512MB] and is a power of 2.", file=config)
print(" */", file=config)
total_shm_size = 0
if len(shmem_regions) > 0:
for shmem_region in shmem_regions:
int_size = 0
size = shmem_region[1]
try:
int_size = int(size) * 0x100000
except Exception as e:
print('the format of shm size error: ', str(e))
total_shm_size += int_size
print("#define IVSHMEM_SHM_SIZE\t{}UL".format(hex(total_shm_size)), file=config)
print("#define IVSHMEM_DEV_NUM\t\t{}UL".format(shmem_dev_num), file=config)
print("", file=config)
print("/* All user defined memory regions */", file=config)
if len(shmem_regions) == 0:
print("#define IVSHMEM_SHM_REGIONS", file=config)
else:
print("#define IVSHMEM_SHM_REGIONS \\", file=config)
shmem_cnt = 0
for shmem in shmem_regions:
print("\t{ \\", file=config)
print('\t\t.name = IVSHMEM_SHM_REGION_{}, \\'.format(shmem_cnt), file=config)
try:
int_size = int(shmem[1]) * 0x100000
except:
int_size = 0
print('\t\t.size = {}UL,\t\t/* {}M */ \\'.format(hex(int_size), shmem[1]), file=config)
if shmem_cnt < len(shmem_regions) - 1:
print("\t}, \\", file=config)
else:
print("\t},", file=config)
shmem_cnt += 1
print("", file=config)
def generate_file(scenario_items, config):
"""
Start to generate ivshmem_cfg.h
:param scenario_items: it is the class which contain all user setting information
:param config: it is a file pointer of scenario information for writing to
"""
vm_info = scenario_items['vm']
gen_common_header(config)
if vm_info.shmem.shmem_enabled == 'y':
print("#include <ivshmem.h>", file=config)
print("#include <pgtable.h>", file=config)
write_shmem_regions(config)
print("{0}".format(IVSHMEM_END_DEFINE), file=config)

View File

@@ -0,0 +1,309 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import re
from collections import namedtuple
import common
import scenario_cfg_lib
import board_cfg_lib
PCI_DEV_TYPE = ['PCI_DEV_TYPE_HVEMUL', 'PCI_DEV_TYPE_PTDEV']
class BusDevFunc(namedtuple(
"BusDevFunc", [
"bus",
"dev",
"func"])):
PATTERN = re.compile(r"(?P<bus>[0-9a-f]{2}):(?P<dev>[0-9a-f]{2})\.(?P<func>[0-7]{1})")
@classmethod
def from_str(cls, value):
if not(isinstance(value, str)):
raise ValueError("value must be a str: {}".format(type(value)))
match = cls.PATTERN.fullmatch(value)
if match:
return BusDevFunc(
bus=int(match.group("bus"), 16),
dev=int(match.group("dev"), 16),
func=int(match.group("func"), 16))
else:
raise ValueError("not a bdf: {!r}".format(value))
def __init__(self, *args, **kwargs):
if not (0x00 <= self.bus <= 0xff):
raise ValueError("Invalid bus number (0x00 ~ 0xff): {:#04x}".format(self.bus))
if not (0x00 <= self.dev <= 0x1f):
raise ValueError("Invalid device number (0x00 ~ 0x1f): {:#04x}".format(self.dev))
if not (0x0 <= self.func <= 0x7):
raise ValueError("Invalid function number (0 ~ 7): {:#x}".format(self.func))
def __str__(self):
return "{:02x}:{:02x}.{:x}".format(self.bus, self.dev, self.func)
def __repr__(self):
return "BusDevFunc.from_str({!r})".format(str(self))
def find_unused_bdf(used_bdf, case):
if case == "vuart":
# vuart device cannot detect function difference, find vbdf based on dev increment
for dev in range(0x20):
bdf = BusDevFunc(bus=0x00, dev=dev, func=0x0)
#if bdf not in used_bdf:
if all((bdf.dev != in_use_bdf.dev for in_use_bdf in used_bdf)):
return bdf
else:
for dev in range(0x20):
for func in range(0x8):
bdf = BusDevFunc(bus=0x00, dev=dev, func=func)
if bdf not in used_bdf:
return bdf
raise ValueError("Cannot find free bdf")
def add_instance_to_name(i_cnt, bdf, bar_attr):
if i_cnt == 0 and bar_attr.name.upper() == "HOST BRIDGE":
tmp_sub_name = "_".join(bar_attr.name.split()).upper()
else:
if '-' in bar_attr.name:
tmp_sub_name = common.undline_name(bar_attr.name) + "_" + str(i_cnt)
else:
tmp_sub_name = "_".join(bar_attr.name.split()).upper() + "_" + str(i_cnt)
board_cfg_lib.PCI_DEV_BAR_DESC.pci_dev_dic[bdf].name_w_i_cnt = tmp_sub_name
def generate_file(vm_info, config):
"""
Generate pci_dev.c for Pre-Launched VMs in a scenario.
:param config: it is pointer for for file write to
:return: None
"""
board_cfg_lib.parser_pci()
board_cfg_lib.parse_mem()
compared_bdf = []
sos_used_bdf = []
for cnt_sub_name in board_cfg_lib.SUB_NAME_COUNT.keys():
i_cnt = 0
for bdf, bar_attr in board_cfg_lib.PCI_DEV_BAR_DESC.pci_dev_dic.items():
if cnt_sub_name == bar_attr.name and bdf not in compared_bdf:
compared_bdf.append(bdf)
else:
continue
add_instance_to_name(i_cnt, bdf, bar_attr)
i_cnt += 1
for bdf in compared_bdf:
bdf_tuple = BusDevFunc.from_str(bdf)
sos_used_bdf.append(bdf_tuple)
# BDF 00:01.0 cannot be used in tgl
bdf_tuple = BusDevFunc(bus=0,dev=1,func=0)
sos_used_bdf.append(bdf_tuple)
vuarts = common.get_vuart_info(common.SCENARIO_INFO_FILE)
pci_vuarts_num = scenario_cfg_lib.get_pci_vuart_num(vuarts)
pci_vuart_enabled = False
for vm_i in common.VM_TYPES:
if pci_vuarts_num[vm_i] > 0:
pci_vuart_enabled = True
break
print("{}".format(scenario_cfg_lib.HEADER_LICENSE), file=config)
print("", file=config)
print("#include <vm_config.h>", file=config)
print("#include <pci_devices.h>", file=config)
print("#include <vpci.h>", file=config)
print("#include <vbar_base.h>", file=config)
print("#include <mmu.h>", file=config)
print("#include <page.h>", file=config)
if pci_vuart_enabled:
print("#include <vmcs9900.h>", file=config)
# Insert header for share memory
if vm_info.shmem.shmem_enabled == 'y':
print("#include <ivshmem_cfg.h>", file=config)
# Insert comments and macros for passthrough devices
if any((p for _,p in vm_info.cfg_pci.pci_devs.items())):
print("", file=config)
print("/*", file=config)
print(" * TODO: remove PTDEV macro and add DEV_PRIVINFO macro to initialize pbdf for", file=config)
print(" * passthrough device configuration and shm_name for ivshmem device configuration.", file=config)
print(" */", file=config)
print("#define PTDEV(PCI_DEV)\t\tPCI_DEV, PCI_DEV##_VBAR",file=config)
print("", file=config)
print("/*", file=config)
print(" * TODO: add DEV_PCICOMMON macro to initialize emu_type, vbdf and vdev_ops", file=config)
print(" * to simplify the code.", file=config)
print(" */", file=config)
if pci_vuart_enabled:
print("#define INVALID_PCI_BASE\t0U",file=config)
for vm_i, vm_type in common.VM_TYPES.items():
vm_used_bdf = []
# bdf 00:00.0 is reserved for pci host bridge of any type of VM
bdf_tuple = BusDevFunc.from_str("00:00.0")
vm_used_bdf.append(bdf_tuple)
# Skip this vm if there is no any pci device and virtual device
if not scenario_cfg_lib.get_pci_dev_num_per_vm()[vm_i] and \
scenario_cfg_lib.VM_DB[vm_type]['load_type'] != "SOS_VM":
continue
if not scenario_cfg_lib.get_pci_dev_num_per_vm()[vm_i] and \
scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
print("", file=config)
print("struct acrn_vm_pci_dev_config " +
"sos_pci_devs[CONFIG_MAX_PCI_DEV_NUM];", file=config)
continue
pci_cnt = 1
# Insert device structure and bracket
print("", file=config)
if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
print("struct acrn_vm_pci_dev_config " +
"sos_pci_devs[CONFIG_MAX_PCI_DEV_NUM] = {", file=config)
else:
print("struct acrn_vm_pci_dev_config " +
"vm{}_pci_devs[VM{}_CONFIG_PCI_DEV_NUM] = {{".format(vm_i, vm_i), file=config)
# If a pre-launched vm has either passthrough pci devices or ivshmem devices, hostbridge is needed
if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
pciHostbridge = False
# Check if there is a passtrhough pci devices
pci_bdf_devs_list = vm_info.cfg_pci.pci_devs[vm_i]
if pci_bdf_devs_list:
pciHostbridge = True
# Check if the ivshmem is enabled
if vm_info.shmem.shmem_enabled == 'y' and vm_i in vm_info.shmem.shmem_regions \
and len(vm_info.shmem.shmem_regions[vm_i]) > 0:
pciHostbridge = True
# Check if there is pci vuart is enabled
if pci_vuarts_num[vm_i] > 0:
pciHostbridge = True
if pciHostbridge:
print("\t{", file=config)
print("\t\t.emu_type = {},".format(PCI_DEV_TYPE[0]), file=config)
print("\t\t.vbdf.bits = {.b = 0x00U, .d = 0x00U, .f = 0x00U},", file=config)
print("\t\t.vdev_ops = &vhostbridge_ops,", file=config)
print("\t},", file=config)
# Insert passtrough devices data
if vm_i in vm_info.cfg_pci.pci_devs.keys():
pci_bdf_devs_list = vm_info.cfg_pci.pci_devs[vm_i]
if pci_bdf_devs_list:
for pci_bdf_dev in pci_bdf_devs_list:
if not pci_bdf_dev:
continue
bus = int(pci_bdf_dev.split(':')[0], 16)
dev = int(pci_bdf_dev.split(':')[1].split('.')[0], 16)
fun = int(pci_bdf_dev.split('.')[1], 16)
print("\t{", file=config)
print("\t\t.emu_type = {},".format(PCI_DEV_TYPE[1]), file=config)
print("\t\t.vbdf.bits = {{.b = 0x00U, .d = 0x{0:02x}U, .f = 0x00U}},".format(pci_cnt), file=config)
for bdf, bar_attr in board_cfg_lib.PCI_DEV_BAR_DESC.pci_dev_dic.items():
if bdf == pci_bdf_dev:
print("\t\tPTDEV({}),".format(board_cfg_lib.PCI_DEV_BAR_DESC.pci_dev_dic[bdf].name_w_i_cnt), file=config)
else:
continue
print("\t},", file=config)
bdf_tuple = BusDevFunc(0,pci_cnt,0)
vm_used_bdf.append(bdf_tuple)
pci_cnt += 1
# Insert ivshmem information
if vm_info.shmem.shmem_enabled == 'y' and vm_i in vm_info.shmem.shmem_regions \
and len(vm_info.shmem.shmem_regions[vm_i]) > 0:
raw_shm_list = vm_info.shmem.shmem_regions[vm_i]
index = 0
for shm in raw_shm_list:
shm_splited = shm.split(',')
print("\t{", file=config)
print("\t\t.emu_type = {},".format(PCI_DEV_TYPE[0]), file=config)
if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
free_bdf = find_unused_bdf(sos_used_bdf, "ivshmem")
print("\t\t.vbdf.bits = {{.b = 0x00U, .d = 0x{:02x}U, .f = 0x{:02x}U}}," \
.format(free_bdf.dev,free_bdf.func), file=config)
sos_used_bdf.append(free_bdf)
elif scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
print("\t\t.vbdf.bits = {{.b = 0x00U, .d = 0x{0:02x}U, .f = 0x00U}},".format(pci_cnt), file=config)
bdf_tuple = BusDevFunc(0,pci_cnt,0)
vm_used_bdf.append(bdf_tuple)
elif scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "POST_LAUNCHED_VM":
print("\t\t.vbdf.value = UNASSIGNED_VBDF,", file=config)
print("\t\t.vdev_ops = &vpci_ivshmem_ops,", file=config)
for shm_name,_ in board_cfg_lib.PCI_DEV_BAR_DESC.shm_bar_dic.items():
region = shm_name[:shm_name.find('_')]
shm_name = shm_name[shm_name.find('_') + 1:]
if shm_name == shm_splited[0].strip():
if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
print("\t\t.shm_region_name = IVSHMEM_SHM_REGION_{},".format(region), file=config)
print("\t\tIVSHMEM_DEVICE_{}_VBAR".format(index), file=config)
elif scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
print("\t\t.shm_region_name = IVSHMEM_SHM_REGION_{},".format(region), file=config)
print("\t\tSOS_IVSHMEM_DEVICE_{}_VBAR".format(index), file=config)
else:
print("\t\t.shm_region_name = IVSHMEM_SHM_REGION_{}".format(region), file=config)
pci_cnt += 1
index += 1
print("\t},", file=config)
if vm_i in vuarts.keys():
# get legacy vuart information
vuart0_setting = common.get_vuart_info_id(common.SCENARIO_INFO_FILE, 0)
vuart1_setting = common.get_vuart_info_id(common.SCENARIO_INFO_FILE, 1)
for vuart_id in vuarts[vm_i].keys():
if vuarts[vm_i][vuart_id]['base'] == "INVALID_PCI_BASE":
continue
# skip pci vuart 0 for post-launched vm
if vuart_id == 0 and scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "POST_LAUNCHED_VM":
continue
# Skip pci vuart 0 if the legacy vuart 0 is enabled
if vuart_id == 0 and vm_i in vuart0_setting and vuart0_setting[vm_i]['base'] != "INVALID_COM_BASE":
continue
# Skip pci vuart 1 if the legacy vuart 1 is enabled
if vuart_id == 1 and vm_i in vuart1_setting and vuart1_setting[vm_i]['base'] != "INVALID_COM_BASE":
continue
print("\t{", file=config)
print("\t\t.vuart_idx = {:1d},".format(vuart_id), file=config)
print("\t\t.emu_type = {},".format(PCI_DEV_TYPE[0]), file=config)
print("\t\t.vdev_ops = &vmcs9900_ops,", file=config)
if vuart_id != 0 and scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "POST_LAUNCHED_VM":
print("\t\t.vbar_base[0] = INVALID_PCI_BASE,", file=config)
print("\t\t.vbdf.value = UNASSIGNED_VBDF,", file=config)
if scenario_cfg_lib.VM_DB[vm_type]['load_type'] != "POST_LAUNCHED_VM":
print("\t\tVM{:1d}_VUART_{:1d}_VBAR,".format(vm_i, vuart_id), file=config)
if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
free_bdf = find_unused_bdf(vm_used_bdf, "vuart")
vm_used_bdf.append(free_bdf)
elif scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
free_bdf = find_unused_bdf(sos_used_bdf, "vuart")
sos_used_bdf.append(free_bdf)
print("\t\t.vbdf.bits = {{.b = 0x00U, .d = 0x{:02x}U, .f = 0x00U}},".format(free_bdf.dev,free_bdf.func), file=config)
if vuart_id != 0:
print("\t\t.t_vuart.vm_id = {},".format(vuarts[vm_i][vuart_id]['target_vm_id']), file=config)
print("\t\t.t_vuart.vuart_id = {},".format(vuarts[vm_i][vuart_id]['target_uart_id']), file=config)
pci_cnt += 1
print("\t},", file=config)
# Insert the end bracket of the pci_dev.c file
print("};", file=config)

View File

@@ -0,0 +1,38 @@
# Copyright (C) 2020 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import common
import scenario_cfg_lib
import board_cfg_lib
def generate_file(vm_info, config):
"""
Generate pt_intx.c for Pre-Launched VMs in a scenario.
:param config: it is pointer for for file write to
:return: None
"""
print("{}".format(scenario_cfg_lib.HEADER_LICENSE), file=config)
print("", file=config)
print("#include <vm_config.h>", file=config)
print("", file=config)
if (board_cfg_lib.is_matched_board(("ehl-crb-b"))
and vm_info.pt_intx_info.phys_gsi.get(0) is not None
and len(vm_info.pt_intx_info.phys_gsi[0]) > 0):
print("struct pt_intx_config vm0_pt_intx[{}U] = {{".format(len(vm_info.pt_intx_info.phys_gsi[0])), file=config)
for i, (p_pin, v_pin) in enumerate(zip(vm_info.pt_intx_info.phys_gsi[0], vm_info.pt_intx_info.virt_gsi[0])):
print("\t[{}U] = {{".format(i), file=config)
print("\t\t.phys_gsi = {}U,".format(p_pin), file=config)
print("\t\t.virt_gsi = {}U,".format(v_pin), file=config)
print("\t},", file=config)
print("};", file=config)
else:
print("struct pt_intx_config vm0_pt_intx[1U];", file=config)
print("", file=config)

View File

@@ -0,0 +1,248 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import os
import sys
import copy
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'library'))
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'hv_config'))
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'acpi_gen'))
from scenario_item import HwInfo, VmInfo
import board_cfg_lib
import scenario_cfg_lib
import vm_configurations_c
import vm_configurations_h
import pci_dev_c
import pt_intx_c
import ivshmem_cfg_h
import common
import hv_cfg_lib
import board_defconfig
from hv_item import HvInfo
import asl_gen
ACRN_PATH = common.SOURCE_ROOT_DIR
ACRN_CONFIG_DEF = ACRN_PATH + 'misc/config_tools/data/'
GEN_FILE = ["vm_configurations.h", "vm_configurations.c", "pci_dev.c", ".config", "ivshmem_cfg.h", "pt_intx.c"]
def get_scenario_item_values(board_info, scenario_info):
"""
Glue code to provide user selectable options to config UI tool.
Return a dictionary of key-value pairs containing features and corresponding lists of
user selectable values to the config UI tool.
:param board_info: file that contains board information
"""
hv_cfg_lib.ERR_LIST = {}
scenario_item_values = {}
hw_info = HwInfo(board_info)
hv_info = HvInfo(scenario_info)
# get vm count
common.BOARD_INFO_FILE = board_info
common.SCENARIO_INFO_FILE = scenario_info
common.get_vm_num(scenario_info)
common.get_vm_types()
# per scenario
guest_flags = copy.deepcopy(common.GUEST_FLAG)
guest_flags.remove('0UL')
scenario_item_values['vm,vm_type'] = scenario_cfg_lib.LOAD_VM_TYPE
scenario_item_values["vm,cpu_affinity"] = hw_info.get_processor_val()
scenario_item_values["vm,guest_flags"] = guest_flags
scenario_item_values["vm,clos,vcpu_clos"] = hw_info.get_clos_val()
scenario_item_values["vm,pci_devs"] = scenario_cfg_lib.avl_pci_devs()
scenario_item_values["vm,os_config,kern_type"] = scenario_cfg_lib.KERN_TYPE_LIST
scenario_item_values["vm,mmio_resources,p2sb"] = hv_cfg_lib.N_Y
scenario_item_values["vm,mmio_resources,TPM2"] = hv_cfg_lib.N_Y
scenario_item_values.update(scenario_cfg_lib.avl_vuart_ui_select(scenario_info))
scenario_item_values["vm,console_vuart,base"] = ['INVALID_PCI_BASE', 'PCI_VUART']
scenario_item_values["vm,communication_vuart,base"] = ['INVALID_PCI_BASE', 'PCI_VUART']
# board
(scenario_item_values["vm,board_private,rootfs"], num) = board_cfg_lib.get_rootfs(board_info)
scenario_item_values["hv,DEBUG_OPTIONS,RELEASE"] = hv_cfg_lib.N_Y
scenario_item_values["hv,DEBUG_OPTIONS,NPK_LOGLEVEL"] = hv_cfg_lib.get_select_range("DEBUG_OPTIONS", "LOG_LEVEL")
scenario_item_values["hv,DEBUG_OPTIONS,MEM_LOGLEVEL"] = hv_cfg_lib.get_select_range("DEBUG_OPTIONS", "LOG_LEVEL")
scenario_item_values["hv,DEBUG_OPTIONS,CONSOLE_LOGLEVEL"] = hv_cfg_lib.get_select_range("DEBUG_OPTIONS", "LOG_LEVEL")
scenario_item_values["hv,DEBUG_OPTIONS,SERIAL_CONSOLE"] = board_cfg_lib.get_native_ttys_info(board_info)
scenario_item_values["hv,DEBUG_OPTIONS,LOG_DESTINATION"] = hv_cfg_lib.get_select_range("DEBUG_OPTIONS", "LOG_DESTINATION_BITMAP")
scenario_item_values["hv,CAPACITIES,MAX_IOAPIC_NUM"] = hv_cfg_lib.get_select_range("CAPACITIES", "IOAPIC_NUM")
scenario_item_values["hv,FEATURES,MULTIBOOT2"] = hv_cfg_lib.N_Y
scenario_item_values["hv,FEATURES,RDT,RDT_ENABLED"] = board_cfg_lib.get_rdt_select_opt()
scenario_item_values["hv,FEATURES,RDT,CDP_ENABLED"] = board_cfg_lib.get_rdt_select_opt()
scenario_item_values["hv,FEATURES,SCHEDULER"] = hv_cfg_lib.SCHEDULER_TYPE
scenario_item_values["hv,FEATURES,RELOC"] = hv_cfg_lib.N_Y
scenario_item_values["hv,FEATURES,HYPERV_ENABLED"] = hv_cfg_lib.N_Y
scenario_item_values["hv,FEATURES,ACPI_PARSE_ENABLED"] = hv_cfg_lib.N_Y
scenario_item_values["hv,FEATURES,L1D_VMENTRY_ENABLED"] = hv_cfg_lib.N_Y
scenario_item_values["hv,FEATURES,MCE_ON_PSC_DISABLED"] = hv_cfg_lib.N_Y
scenario_item_values["hv,FEATURES,IOMMU_ENFORCE_SNP"] = hv_cfg_lib.N_Y
scenario_item_values["hv,FEATURES,IVSHMEM,IVSHMEM_ENABLED"] = hv_cfg_lib.N_Y
scenario_item_values["hv,FEATURES,PSRAM,PSRAM_ENABLED"] = hv_cfg_lib.N_Y
scenario_cfg_lib.ERR_LIST.update(hv_cfg_lib.ERR_LIST)
return scenario_item_values
def validate_scenario_setting(board_info, scenario_info):
"""
Validate settings in scenario xml
:param board_info: board file
:param scenario_info: scenario file
:return: return a dictionary that contains errors
"""
hv_cfg_lib.ERR_LIST = {}
scenario_cfg_lib.ERR_LIST = {}
common.BOARD_INFO_FILE = board_info
common.SCENARIO_INFO_FILE = scenario_info
hv_info = HvInfo(scenario_info)
hv_info.get_info()
hv_info.check_item()
scenario_info_items = {}
vm_info = VmInfo(board_info, scenario_info)
vm_info.get_info()
vm_info.set_ivshmem(hv_info.mem.ivshmem_region)
vm_info.check_item()
scenario_info_items['vm'] = vm_info
scenario_info_items['hv'] = hv_info
scenario_cfg_lib.ERR_LIST.update(hv_cfg_lib.ERR_LIST)
return (scenario_cfg_lib.ERR_LIST, scenario_info_items)
def main(args):
"""
Generate board related source code
:param args: command line args
"""
err_dic = {}
(err_dic, params) = common.get_param(args)
if err_dic:
return err_dic
# check env
err_dic = common.prepare()
if err_dic:
return err_dic
common.BOARD_INFO_FILE = params['--board']
common.SCENARIO_INFO_FILE = params['--scenario']
common.get_vm_num(params['--scenario'])
common.get_vm_types()
# get board name
(err_dic, board_name) = common.get_board_name()
# get scenario name
(err_dic, scenario) = common.get_scenario_name()
if err_dic:
return err_dic
if common.VM_COUNT > common.MAX_VM_NUM:
err_dic['vm count'] = "Number of VMs in scenario xml file should be no greater than {}!".format(common.MAX_VM_NUM)
return err_dic
# check if this is the scenario config which matches board info
(err_dic, status) = common.is_config_file_match()
if not status:
err_dic['scenario config'] = "The board xml file does not match scenario xml file!"
return err_dic
if params['--out']:
if os.path.isabs(params['--out']):
scen_output = params['--out'] + "/scenarios/" + scenario + "/"
else:
scen_output = ACRN_PATH + params['--out'] + "/scenarios/" + scenario + "/"
else:
scen_output = ACRN_CONFIG_DEF + "/" + scenario + "/"
scen_board = scen_output + board_name + "/"
common.mkdir(scen_board)
common.mkdir(scen_output)
vm_config_h = scen_output + GEN_FILE[0]
vm_config_c = scen_output + GEN_FILE[1]
pci_config_c = scen_board + GEN_FILE[2]
config_hv = scen_board + board_name + GEN_FILE[3]
ivshmem_config_h = scen_board + GEN_FILE[4]
pt_intx_config_c = scen_board + GEN_FILE[5]
# parse the scenario.xml
get_scenario_item_values(params['--board'], params['--scenario'])
(err_dic, scenario_items) = validate_scenario_setting(params['--board'], params['--scenario'])
if err_dic:
common.print_red("Scenario xml file validation failed:", err=True)
return err_dic
# generate board defconfig
with open(config_hv, 'w+') as config:
err_dic = board_defconfig.generate_file(scenario_items['hv'], config)
if err_dic:
return err_dic
# generate vm_configuration.h
with open(vm_config_h, 'w') as config:
vm_configurations_h.generate_file(scenario_items, config)
# generate vm_configuration.c
with open(vm_config_c, 'w') as config:
err_dic = vm_configurations_c.generate_file(scenario_items, config)
if err_dic:
return err_dic
# generate ivshmem_cfg.h
with open(ivshmem_config_h, 'w') as config:
ivshmem_cfg_h.generate_file(scenario_items, config)
# generate pci_dev.c
with open(pci_config_c, 'w') as config:
pci_dev_c.generate_file(scenario_items['vm'], config)
# generate pt_intx.c
with open(pt_intx_config_c, 'w') as config:
pt_intx_c.generate_file(scenario_items['vm'], config)
# generate ASL code of ACPI tables for Pre-launched VMs
if not err_dic:
err_dic = asl_gen.main(args)
if not err_dic:
print("Scenario configuration files were created successfully.")
else:
print("Failed to create scenario configuration files.")
return err_dic
def ui_entry_api(board_info, scenario_info, out=''):
arg_list = ['scenario_cfg_gen.py', '--board', board_info, '--scenario', scenario_info, '--out', out]
err_dic = common.prepare()
if err_dic:
return err_dic
err_dic = main(arg_list)
return err_dic
if __name__ == '__main__':
ARGS = sys.argv
err_dic = main(ARGS)
if err_dic:
for err_k, err_v in err_dic.items():
common.print_red("{}: {}".format(err_k, err_v), err=True)
sys.exit(1 if err_dic else 0)

View File

@@ -0,0 +1,412 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import common
import board_cfg_lib
import scenario_cfg_lib
class HwInfo:
""" This is Abstract of class of Hardware information """
processor_val = []
clos_val = []
root_dev_val = []
ttys_val = []
def __init__(self, board_file):
self.board_info = board_file
def get_processor_val(self):
"""
Get cpu core list
:return: cpu processor which one cpu has
"""
self.processor_val = board_cfg_lib.get_processor_info()
return self.processor_val
def get_rootdev_val(self):
"""
Get root devices from board info
:return: root devices list
"""
(self.root_dev_val, num) = common.get_rootfs(self.board_info)
return self.root_dev_val
def get_ttys_val(self):
"""
Get ttySn from board info
:return: serial console list
"""
self.ttys_val = board_cfg_lib.get_native_ttys_info(self.board_info)
return self.ttys_val
def get_clos_val(self):
"""
Get clos max number from board info
:return: clos support list
"""
self.clos_val = []
(rdt_resources, rdt_res_clos_max, _) = board_cfg_lib.clos_info_parser(self.board_info)
if len(rdt_resources) != 0 and len(rdt_res_clos_max) != 0:
common_clos_max = min(rdt_res_clos_max)
for i_cnt in range(common_clos_max):
self.clos_val.append(str(i_cnt))
return self.clos_val
def get_info(self):
"""
Get all items which belong to this class
:return: None
"""
self.processor_val = self.get_processor_val()
self.get_rootdev_val()
self.get_ttys_val()
self.get_clos_val()
class CfgOsKern:
""" This is Abstract of class of configuration of vm os kernel setting """
kern_name = {}
kern_type = {}
kern_mod = {}
kern_args = {}
kern_load_addr = {}
kern_entry_addr = {}
ramdisk_mod = {}
def __init__(self, scenario_file):
self.scenario_info = scenario_file
def get_info(self):
"""
Get all items which belong to this class
:return: None
"""
self.kern_name = common.get_leaf_tag_map(self.scenario_info, "os_config", "name")
self.kern_type = common.get_leaf_tag_map(
self.scenario_info, "os_config", "kern_type")
self.kern_mod = common.get_leaf_tag_map(
self.scenario_info, "os_config", "kern_mod")
self.kern_args = common.get_leaf_tag_map(
self.scenario_info, "os_config", "bootargs")
self.kern_load_addr = common.get_leaf_tag_map(
self.scenario_info, "os_config", "kern_load_addr")
self.kern_entry_addr = common.get_leaf_tag_map(
self.scenario_info, "os_config", "kern_entry_addr")
self.ramdisk_mod = common.get_leaf_tag_map(
self.scenario_info, "os_config", "ramdisk_mod")
def check_item(self):
"""
Check all items in this class
:return: None
"""
scenario_cfg_lib.os_kern_name_check(self.kern_name, "os_config", "name")
scenario_cfg_lib.os_kern_type_check(self.kern_type, "os_config", "kern_type")
scenario_cfg_lib.os_kern_mod_check(self.kern_mod, "os_config", "kern_mod")
scenario_cfg_lib.os_kern_args_check(self.kern_args, "os_config", "kern_args")
scenario_cfg_lib.os_kern_load_addr_check(self.kern_type, self.kern_load_addr, "os_config", "kern_load_addr")
scenario_cfg_lib.os_kern_entry_addr_check(self.kern_type, self.kern_entry_addr, "os_config", "kern_entry_addr")
class VuartInfo:
""" This is Abstract of class of vm vuart setting """
v0_vuart = {}
v1_vuart = {}
pci_vuarts = {}
def __init__(self, scenario_file):
self.scenario_info = scenario_file
def style_check_1(self):
""" This is public method for style check"""
self.v1_vuart = []
def get_info(self):
"""
Get all items which belong to this class
:return: None
"""
self.v0_vuart = common.get_vuart_info_id(self.scenario_info, 0)
self.v1_vuart = common.get_vuart_info_id(self.scenario_info, 1)
self.pci_vuarts = common.get_vuart_info(self.scenario_info)
def check_item(self):
"""
Check all items in this class
:return: None
"""
scenario_cfg_lib.check_board_private_info()
scenario_cfg_lib.check_vuart(self.v0_vuart, self.v1_vuart)
scenario_cfg_lib.check_pci_vuart(self.pci_vuarts, self.v0_vuart, self.v1_vuart)
class MemInfo:
""" This is Abstract of class of memory setting information """
mem_start_hpa = {}
mem_size = {}
mem_start_hpa2 = {}
mem_size_hpa2 = {}
def __init__(self, scenario_file):
self.scenario_info = scenario_file
def get_info(self):
"""
Get all items which belong to this class
:return: None
"""
self.mem_start_hpa = common.get_leaf_tag_map(
self.scenario_info, "memory", "start_hpa")
self.mem_size = common.get_leaf_tag_map(
self.scenario_info, "memory", "size")
self.mem_start_hpa2 = common.get_leaf_tag_map(
self.scenario_info, "memory", "start_hpa2")
self.mem_size_hpa2 = common.get_leaf_tag_map(
self.scenario_info, "memory", "size_hpa2")
def check_item(self):
"""
Check all items in this class
:return: None
"""
scenario_cfg_lib.mem_start_hpa_check(self.mem_start_hpa, "memory", "start_hpa")
scenario_cfg_lib.mem_size_check(self.mem_size, "memory", "size")
scenario_cfg_lib.mem_start_hpa_check(self.mem_start_hpa2, "memory", "start_hpa2")
scenario_cfg_lib.mem_size_check(self.mem_size_hpa2, "memory", "size_hpa2")
class CfgPci:
""" This is Abstract of class of PCi devices setting information """
pt_pci_num = {}
pci_devs = {}
def __init__(self, scenario_file):
self.scenario_info = scenario_file
def get_pt_pci_dev_num(self):
"""
Get pci device number items
:return: None
"""
self.pt_pci_num = scenario_cfg_lib.get_pt_pci_num(self.pci_devs)
def get_pt_pci_devs(self):
"""
Get pci devices items
:return: None
"""
pci_items = common.get_leaf_tag_map(self.scenario_info, "pci_devs", "pci_dev")
self.pci_devs = scenario_cfg_lib.get_pt_pci_devs(pci_items)
def get_info(self):
"""
Get all items which belong to this class
:return: None
"""
self.get_pt_pci_devs()
self.get_pt_pci_dev_num()
def check_item(self):
""" Check all items in this class
:return: None
"""
scenario_cfg_lib.pci_devs_check(self.pci_devs, "pci_devs", "pci_dev")
class EpcSection:
base = {}
size = {}
def __init__(self, scenario_info):
self.scenario_info = scenario_info
def get_info(self):
self.base = common.get_leaf_tag_map(self.scenario_info, "epc_section", "base")
self.size = common.get_leaf_tag_map(self.scenario_info, "epc_section", "size")
class ShareMem:
""" This is the class to get Share Memory regions for VMs """
shmem_enabled = 'n'
raw_shmem_regions = []
shmem_regions = {}
shmem_num = {}
def __init__(self, scenario_info):
self.scenario_info = scenario_info
def set_ivshmem(self, ivshmem_regions):
"""
set ivshmem regions for VMs.
:param ivshmem_regions:
:return:
"""
self.raw_shmem_regions = ivshmem_regions
self.shmem_enabled = common.get_hv_item_tag(self.scenario_info, "FEATURES", "IVSHMEM", "IVSHMEM_ENABLED")
self.shmem_regions = scenario_cfg_lib.get_shmem_regions(ivshmem_regions)
self.shmem_num = scenario_cfg_lib.get_shmem_num(self.shmem_regions)
def check_items(self):
'''
check the configurations for share memories.
:return:
'''
if self.shmem_enabled == 'y':
vm_type_info = common.get_leaf_tag_map(self.scenario_info, "vm_type")
scenario_cfg_lib.share_mem_check(self.shmem_regions, self.raw_shmem_regions, vm_type_info,
"FEATURES", "IVSHMEM", "IVSHMEM_REGION")
class LoadOrderNum:
""" This is Abstract of VM number for different load order """
def __init__(self):
self.pre_vm = 0
self.sos_vm = 0
self.post_vm = 0
def get_info(self, load_vm):
self.pre_vm = scenario_cfg_lib.get_load_vm_cnt(load_vm, "PRE_LAUNCHED_VM")
self.sos_vm = scenario_cfg_lib.get_load_vm_cnt(load_vm, "SOS_VM")
self.post_vm = scenario_cfg_lib.get_load_vm_cnt(load_vm, "POST_LAUNCHED_VM")
class MmioResourcesInfo:
""" This is Abstract of class of mmio resource setting information """
p2sb = False
def __init__(self, scenario_file):
self.scenario_info = scenario_file
def get_info(self):
"""
Get all items which belong to this class
:return: None
"""
self.p2sb = common.get_leaf_tag_map_bool(self.scenario_info, "mmio_resources", "p2sb")
self.tpm2 = common.get_leaf_tag_map_bool(self.scenario_info, "mmio_resources", "TPM2")
def check_item(self):
"""
Check all items in this class
:return: None
"""
scenario_cfg_lib.check_p2sb(self.p2sb)
class PtIntxInfo:
""" This is Abstract of class of pt intx setting information """
phys_gsi = {}
virt_gsi = {}
def __init__(self, scenario_file):
self.scenario_info = scenario_file
def get_info(self):
"""
Get all items which belong to this class
:return: None
"""
self.phys_gsi, self.virt_gsi = common.get_pt_intx_table(self.scenario_info)
def check_item(self):
"""
Check all items in this class
:return: None
"""
scenario_cfg_lib.check_pt_intx(self.phys_gsi, self.virt_gsi)
class VmInfo:
""" This is Abstract of class of VM setting """
name = {}
load_vm = {}
clos_per_vm = {}
guest_flags = {}
cpus_per_vm = {}
def __init__(self, board_file, scenario_file):
self.board_info = board_file
self.scenario_info = scenario_file
common.get_vm_num(self.scenario_info)
self.epc_section = EpcSection(self.scenario_info)
self.mem_info = MemInfo(self.scenario_info)
self.os_cfg = CfgOsKern(self.scenario_info)
self.vuart = VuartInfo(self.scenario_info)
self.cfg_pci = CfgPci(self.scenario_info)
self.load_order_cnt = LoadOrderNum()
self.shmem = ShareMem(self.scenario_info)
self.mmio_resource_info = MmioResourcesInfo(self.scenario_info)
self.pt_intx_info = PtIntxInfo(self.scenario_info)
def get_info(self):
"""
Get all items which belong to this class
:return: None
"""
self.name = common.get_leaf_tag_map(self.scenario_info, "name")
self.load_vm= common.get_leaf_tag_map(self.scenario_info, "vm_type")
self.guest_flags = common.get_leaf_tag_map(
self.scenario_info, "guest_flags", "guest_flag")
self.cpus_per_vm = common.get_leaf_tag_map(
self.scenario_info, "cpu_affinity", "pcpu_id")
self.clos_per_vm = common.get_leaf_tag_map(
self.scenario_info, "clos", "vcpu_clos")
self.epc_section.get_info()
self.mem_info.get_info()
self.os_cfg.get_info()
self.vuart.get_info()
self.cfg_pci.get_info()
self.load_order_cnt.get_info(self.load_vm)
self.mmio_resource_info.get_info()
self.pt_intx_info.get_info()
def set_ivshmem(self, ivshmem_regions):
"""
set ivshmem regions for VMs
:param ivshmem_regions:
:return:
"""
self.shmem.set_ivshmem(ivshmem_regions)
def get_cpu_bitmap(self, index):
"""
:param index: index list in GUESF_FLAGS
:return: cpus per vm and their vm id
"""
return scenario_cfg_lib.cpus_assignment(self.cpus_per_vm, index)
def get_clos_bitmap(self, index):
"""
:param index: index list in GUESF_FLAGS
:return: clos per vm and their vm id
"""
return scenario_cfg_lib.clos_assignment(self.clos_per_vm, index)
def check_item(self):
"""
Check all items in this class
:return: None
"""
scenario_cfg_lib.vm_name_check(self.name, "name")
scenario_cfg_lib.load_vm_check(self.load_vm, "load_vm")
scenario_cfg_lib.guest_flag_check(self.guest_flags, "guest_flags", "guest_flag")
err_dic = scenario_cfg_lib.vm_cpu_affinity_check(self.scenario_info, self.cpus_per_vm, "pcpu_id")
scenario_cfg_lib.vcpu_clos_check(self.cpus_per_vm, self.clos_per_vm, "clos", "vcpu_clos")
self.mem_info.check_item()
self.os_cfg.check_item()
self.cfg_pci.check_item()
self.vuart.check_item()
self.shmem.check_items()
self.mmio_resource_info.check_item()
self.pt_intx_info.check_item()
scenario_cfg_lib.ERR_LIST.update(err_dic)

View File

@@ -0,0 +1,430 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import sys
import common
import board_cfg_lib
import scenario_cfg_lib
C_HEADER = scenario_cfg_lib.HEADER_LICENSE + r"""
#include <vm_config.h>
#include <vuart.h>
#include <pci_dev.h>
"""
def get_pre_vm_type(vm_type, vm_i):
if vm_type == "SAFETY_VM":
return "CONFIG_SAFETY_VM(1)"
if vm_type == "PRE_RT_VM":
return "CONFIG_PRE_RT_VM(1)"
i_cnt = 0
for i,v_type in common.VM_TYPES.items():
if v_type == "PRE_STD_VM" and i <= vm_i:
i_cnt += 1
return "CONFIG_PRE_STD_VM({})".format(i_cnt)
def get_post_vm_type(vm_type, vm_i):
if vm_type == "KATA_VM":
return "CONFIG_KATA_VM(1)"
if vm_type == "POST_RT_VM":
return "CONFIG_POST_RT_VM(1)"
i_cnt = 0
for i,v_type in common.VM_TYPES.items():
if v_type == "POST_STD_VM" and i <= vm_i:
i_cnt += 1
return "CONFIG_POST_STD_VM({})".format(i_cnt)
def vuart0_output(i, vm_type, vm_info, config):
"""
This is generate vuart 0 setting
:param i: vm id number
:param vm_type: vm load order type
:param vm_info: it is the class which contain all user setting information
:param config: it is the pointer which file write to
:return: None
"""
# SOS_VM vuart[0]
print("\t\t.vuart[0] = {", file=config)
print("\t\t\t.type = {0},".format(vm_info.vuart.v0_vuart[i]['type']), file=config)
if vm_info.vuart.v0_vuart[i]['base'] == "INVALID_COM_BASE":
print("\t\t\t.addr.port_base = INVALID_COM_BASE,", file=config)
if "SOS_" in vm_type:
print("\t\t\t.irq = SOS_COM1_IRQ,", file=config)
elif "PRE_LAUNCHED_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
print("\t\t\t.irq = COM1_IRQ,", file=config)
elif "POST_LAUNCHED_VM" in scenario_cfg_lib.VM_DB[vm_type]['load_type']:
print("\t\t\t.irq = {0},".format(
vm_info.vuart.v0_vuart[i]['irq']), file=config)
else:
if "SOS_" in vm_type:
print("\t\t\t.addr.port_base = SOS_COM1_BASE,", file=config)
print("\t\t\t.irq = SOS_COM1_IRQ,", file=config)
elif "PRE_LAUNCHED_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
print("\t\t\t.addr.port_base = COM1_BASE,", file=config)
print("\t\t\t.irq = COM1_IRQ,", file=config)
elif "POST_LAUNCHED_VM" in scenario_cfg_lib.VM_DB[vm_type]['load_type']:
print("\t\t\t.addr.port_base = {0},".format(
vm_info.vuart.v0_vuart[i]['base']), file=config)
print("\t\t\t.irq = {0},".format(
vm_info.vuart.v0_vuart[i]['irq']), file=config)
print("\t\t},", file=config)
def vuart_map_enable(vm_info):
map_dic = {}
for i,vm_type in common.VM_TYPES.items():
base_i = vm_info.vuart.v1_vuart[i]['base']
src_t_vm_i = vm_info.vuart.v1_vuart[i]['target_vm_id']
src_t_vuart_i = vm_info.vuart.v1_vuart[i]['target_uart_id']
des_base = vm_info.vuart.v1_vuart[int(src_t_vm_i)]['base']
des_t_vm_i = vm_info.vuart.v1_vuart[int(src_t_vm_i)]['target_vm_id']
des_t_vuart_i = vm_info.vuart.v1_vuart[int(src_t_vm_i)]['target_uart_id']
if int(des_t_vm_i) == i and int(des_t_vuart_i) == 1 and des_t_vuart_i == src_t_vuart_i:
map_dic[i] = True
else:
map_dic[i] = False
return map_dic
def vuart1_output(i, vm_type, vuart1_vmid_dic, vm_info, config):
"""
This is generate vuart 1 setting
:param i: vm id number
:param vm_type: vm load order type
:param vuart1_vmid_dic: vuart1 and vm id mapping
:param vm_info: it is the class which contain all user setting information
:param config: it is the pointer which file write to
:return: None
"""
vuart_enable = vuart_map_enable(vm_info)
# vuart1: {vmid:target_vmid}
print("\t\t.vuart[1] = {", file=config)
print("\t\t\t.type = {0},".format(vm_info.vuart.v1_vuart[i]['type']), file=config)
if vm_info.vuart.v1_vuart[i]['base'] != "INVALID_COM_BASE" and vuart_enable[i]:
print("\t\t\t.addr.port_base = {0},".format(
vm_info.vuart.v1_vuart[i]['base']), file=config)
else:
print("\t\t\t.addr.port_base = INVALID_COM_BASE,", file=config)
if vuart1_vmid_dic and i in vuart1_vmid_dic.keys():
if "SOS_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
if vm_info.vuart.v1_vuart[i]['base'] != "INVALID_COM_BASE" and vuart_enable[i]:
print("\t\t\t.irq = SOS_COM2_IRQ,", file=config)
else:
if vm_info.vuart.v1_vuart[i]['base'] != "INVALID_COM_BASE" and vuart_enable[i]:
print("\t\t\t.irq = COM2_IRQ,", file=config)
if vm_info.vuart.v1_vuart[i]['base'] != "INVALID_COM_BASE" and vuart_enable[i]:
print("\t\t\t.t_vuart.vm_id = {0}U,".format(
vm_info.vuart.v1_vuart[i]['target_vm_id']), file=config)
print("\t\t\t.t_vuart.vuart_id = {0}U,".format(
vm_info.vuart.v1_vuart[i]['target_uart_id']), file=config)
def vuart_output(vm_type, i, vm_info, config):
"""
This is generate vuart setting
:param i: vm id number
:param vm_info: it is the class which contain all user setting information
:param config: it is the pointer which file write to
:return: None
"""
vuart1_vmid_dic = {}
vuart1_vmid_dic = scenario_cfg_lib.get_vuart1_vmid(vm_info.vuart.v1_vuart)
vuart0_output(i, vm_type, vm_info, config)
vuart1_output(i, vm_type, vuart1_vmid_dic, vm_info, config)
print("\t\t},", file=config)
def is_need_epc(epc_section, i, config):
"""
Check if it is need epc section
:param epc_section: struct epc_scectoin conatins base/size
:param i: the index of vm id
:param config: it is file pointer to store the information
:return: None
"""
# SOS_VM have not set epc section
if i not in common.VM_TYPES.keys():
return
vm_type = list(common.VM_TYPES.values())[i]
if "SOS_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
return
if epc_section.base[i] == '0' and epc_section.size[i] == '0':
return
else:
print("\t\t.epc= {", file=config)
print('\t\t\t.base = {0},'.format(epc_section.base[i]), file=config)
print('\t\t\t.size = {0},'.format(epc_section.size[i]), file=config)
print("\t\t},", file=config)
def cpu_affinity_output(vm_info, i, config):
"""
Output the pcpu affinity bitmap
:param vminfo: the data structure have all the xml items values
:param i: the index of vm id
:param config: file pointor to store the information
"""
if "SOS_VM" == common.VM_TYPES[i]:
print("\t\t.cpu_affinity = SOS_VM_CONFIG_CPU_AFFINITY,", file=config)
else:
print("\t\t.cpu_affinity = VM{}_CONFIG_CPU_AFFINITY,".format(i), file=config)
def clos_output(scenario_items, i, config):
"""
This is generate clos setting
:param scenario_items: it is the class which contain all user setting information
:param i: vm id number
:param config: it is the pointer which file write to
:return: None
"""
hv_info = scenario_items['hv']
print("#ifdef CONFIG_RDT_ENABLED", file=config)
print("\t\t.clos = VM{}_VCPU_CLOS,".format(i), file=config)
print("#endif", file=config)
def get_guest_flag(flags):
"""
This is get flag index list
:param flags:
:return: flag index list in GUEST_FLAGS
"""
err_dic = {}
flag_str = ''
for flag in flags:
if flags.count(flag) >= 2:
return (err_dic, flag)
for i in range(len(flags)):
if i == 0:
if len(flags) == 1:
# get the guest flag 0UL
if flags[0] == '0UL':
return (err_dic, flags[0])
flag_str = "{0}".format(flags[0])
else:
flag_str = "({0}".format(flags[0])
else:
# flags lenght already minus 1
if i == len(flags) - 1:
flag_str = flag_str + " | {0})".format(flags[i])
else:
flag_str = flag_str + " | {0}".format(flags[i])
return (err_dic, flag_str)
def gen_source_header(config):
"""
This is the common header for vm_configuration.c
:param config: it is the pointer which file write to
:return: None
"""
print("{0}".format(C_HEADER), file=config)
def gen_sos_vm(vm_type, vm_i, scenario_items, config):
vm_info = scenario_items['vm']
(err_dic, sos_guest_flags) = get_guest_flag(vm_info.guest_flags[vm_i])
if err_dic:
return err_dic
print("\t{{\t/* VM{} */".format(vm_i), file=config)
print("\t\tCONFIG_SOS_VM,", file=config)
print('\t\t.name = "{0}",'.format(vm_info.name[vm_i]), file=config)
print("", file=config)
print("\t\t/* Allow SOS to reboot the host since " +
"there is supposed to be the highest severity guest */", file=config)
if sos_guest_flags:
print("\t\t.guest_flags = {0},".format(sos_guest_flags), file=config)
clos_output(scenario_items, vm_i, config)
cpu_affinity_output(vm_info, vm_i, config)
print("\t\t.memory = {", file=config)
print("\t\t\t.start_hpa = {}UL,".format(vm_info.mem_info.mem_start_hpa[vm_i]), file=config)
print("\t\t\t.size = {0},".format("CONFIG_SOS_RAM_SIZE"), file=config)
print("\t\t},", file=config)
print("\t\t.os_config = {", file=config)
print('\t\t\t.name = "{0}",'.format(vm_info.os_cfg.kern_name[vm_i]), file=config)
print('\t\t\t.kernel_type = {0},'.format(vm_info.os_cfg.kern_type[vm_i]), file=config)
print('\t\t\t.kernel_mod_tag = "{0}",'.format(
vm_info.os_cfg.kern_mod[vm_i]), file=config)
print('\t\t\t.bootargs = {0},'.format(vm_info.os_cfg.kern_args[vm_i]), file=config)
if (vm_info.os_cfg.ramdisk_mod[vm_i].strip()):
print('\t\t\t.ramdisk_mod_tag = "{0}",'.format(
vm_info.os_cfg.ramdisk_mod[vm_i]), file=config)
print("\t\t},", file=config)
# VUART
err_dic = vuart_output(vm_type, vm_i, vm_info, config)
if err_dic:
return err_dic
sos_dev_num = scenario_cfg_lib.get_pci_dev_num_per_vm()[vm_i]
print("\t\t.pci_dev_num = {}U,".format(sos_dev_num), file=config)
print("\t\t.pci_devs = sos_pci_devs,", file=config)
print("\t},", file=config)
def gen_pre_launch_vm(vm_type, vm_i, scenario_items, config):
vm_info = scenario_items['vm']
# guest flags
(err_dic, guest_flags) = get_guest_flag(vm_info.guest_flags[vm_i])
if err_dic:
return err_dic
pre_vm_type = get_pre_vm_type(vm_type, vm_i)
print("\t{{\t/* VM{} */".format(vm_i), file=config)
print("\t\t{},".format(pre_vm_type), file=config)
print('\t\t.name = "{0}",'.format(vm_info.name[vm_i]), file=config)
cpu_affinity_output(vm_info, vm_i, config)
if guest_flags:
print("\t\t.guest_flags = {0},".format(guest_flags), file=config)
clos_output(scenario_items, vm_i, config)
print("\t\t.memory = {", file=config)
print("\t\t\t.start_hpa = VM{0}_CONFIG_MEM_START_HPA,".format(vm_i), file=config)
print("\t\t\t.size = VM{0}_CONFIG_MEM_SIZE,".format(vm_i), file=config)
print("\t\t\t.start_hpa2 = VM{0}_CONFIG_MEM_START_HPA2,".format(vm_i), file=config)
print("\t\t\t.size_hpa2 = VM{0}_CONFIG_MEM_SIZE_HPA2,".format(vm_i), file=config)
print("\t\t},", file=config)
is_need_epc(vm_info.epc_section, vm_i, config)
print("\t\t.os_config = {", file=config)
print('\t\t\t.name = "{0}",'.format(vm_info.os_cfg.kern_name[vm_i]), file=config)
print("\t\t\t.kernel_type = {0},".format(
vm_info.os_cfg.kern_type[vm_i]), file=config)
print('\t\t\t.kernel_mod_tag = "{0}",'.format(
vm_info.os_cfg.kern_mod[vm_i]), file=config)
if (vm_info.os_cfg.ramdisk_mod[vm_i].strip()):
print('\t\t\t.ramdisk_mod_tag = "{0}",'.format(
vm_info.os_cfg.ramdisk_mod[vm_i]), file=config)
if vm_i in vm_info.os_cfg.kern_load_addr.keys() and vm_info.os_cfg.kern_entry_addr[vm_i]:
print("\t\t\t.kernel_load_addr = {0},".format(vm_info.os_cfg.kern_load_addr[vm_i]), file=config)
if vm_i in vm_info.os_cfg.kern_entry_addr.keys() and vm_info.os_cfg.kern_entry_addr[vm_i]:
print("\t\t\t.kernel_entry_addr = {0},".format(vm_info.os_cfg.kern_entry_addr[vm_i]), file=config)
if vm_i in vm_info.os_cfg.kern_args.keys() and vm_info.os_cfg.kern_args[vm_i]:
print("\t\t\t.bootargs = VM{0}_BOOT_ARGS,".format(vm_i), file=config)
print("\t\t},", file=config)
print("\t\t.acpi_config = {", file=config)
print('\t\t\t.acpi_mod_tag = "ACPI_VM{}",'.format(vm_i), file=config)
print("\t\t},", file=config)
# VUART
err_dic = vuart_output(vm_type, vm_i, vm_info, config)
if err_dic:
return err_dic
if scenario_cfg_lib.get_pci_dev_num_per_vm()[vm_i]:
print("\t\t.pci_dev_num = VM{}_CONFIG_PCI_DEV_NUM,".format(vm_i), file=config)
print("\t\t.pci_devs = vm{}_pci_devs,".format(vm_i), file=config)
if vm_i == 0:
print("#ifdef VM0_PASSTHROUGH_TPM", file=config)
print("\t\t.pt_tpm2 = true,", file=config)
print("\t\t.mmiodevs[0] = {", file=config)
print("\t\t\t.base_gpa = VM0_TPM_BUFFER_BASE_ADDR_GPA,", file=config)
print("\t\t\t.base_hpa = VM0_TPM_BUFFER_BASE_ADDR,", file=config)
print("\t\t\t.size = VM0_TPM_BUFFER_SIZE,", file=config)
print("\t\t},", file=config)
print("#endif", file=config)
if vm_i == 0:
print("#ifdef P2SB_BAR_ADDR", file=config)
print("\t\t.pt_p2sb_bar = true,", file=config)
print("\t\t.mmiodevs[0] = {", file=config)
print("\t\t\t.base_gpa = P2SB_BAR_ADDR_GPA,", file=config)
print("\t\t\t.base_hpa = P2SB_BAR_ADDR,", file=config)
print("\t\t\t.size = P2SB_BAR_SIZE,", file=config)
print("\t\t},", file=config)
print("#endif", file=config)
if vm_i == 0:
print("\t\t.pt_intx_num = VM0_PT_INTX_NUM,", file=config)
print("\t\t.pt_intx = &vm0_pt_intx[0U],", file=config)
print("\t},", file=config)
def gen_post_launch_vm(vm_type, vm_i, scenario_items, config):
vm_info = scenario_items['vm']
post_vm_type = get_post_vm_type(vm_type, vm_i)
print("\t{{\t/* VM{} */".format(vm_i), file=config)
print("\t\t{},".format(post_vm_type), file=config)
clos_output(scenario_items, vm_i, config)
if scenario_cfg_lib.get_pci_dev_num_per_vm()[vm_i]:
print("\t\t/* The PCI device configuration is only for in-hypervisor vPCI devices. */", file=config)
print("\t\t.pci_dev_num = VM{}_CONFIG_PCI_DEV_NUM,".format(vm_i), file=config)
print("\t\t.pci_devs = vm{}_pci_devs,".format(vm_i), file=config)
cpu_affinity_output(vm_info, vm_i, config)
is_need_epc(vm_info.epc_section, vm_i, config)
# VUART
err_dic = vuart_output(vm_type, vm_i, vm_info, config)
if err_dic:
return err_dic
print("\t},", file=config)
def declare_pci_devs(vm_info, config):
for vm_i,vm_type in common.VM_TYPES.items():
if vm_type == "SOS_VM":
print("extern struct acrn_vm_pci_dev_config " +
"sos_pci_devs[CONFIG_MAX_PCI_DEV_NUM];", file=config)
continue
if scenario_cfg_lib.get_pci_dev_num_per_vm()[vm_i]:
print("extern struct acrn_vm_pci_dev_config " +
"vm{}_pci_devs[VM{}_CONFIG_PCI_DEV_NUM];".format(vm_i, vm_i), file=config)
print("", file=config)
def generate_file(scenario_items, config):
"""
Start to generate vm_configurations.c
:param config: it is a file pointer of board information for writing to
"""
err_dic = {}
vm_info = scenario_items['vm']
gen_source_header(config)
declare_pci_devs(vm_info, config)
if (board_cfg_lib.is_matched_board(("ehl-crb-b"))
and vm_info.pt_intx_info.phys_gsi.get(0) is not None
and len(vm_info.pt_intx_info.phys_gsi[0]) > 0):
print("extern struct pt_intx_config vm0_pt_intx[{}U];".format(len(vm_info.pt_intx_info.phys_gsi[0])), file=config)
else:
print("extern struct pt_intx_config vm0_pt_intx[1U];", file=config)
print("", file=config)
print("struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM] = {", file=config)
for vm_i, vm_type in common.VM_TYPES.items():
if "SOS_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
gen_sos_vm(vm_type, vm_i, scenario_items, config)
elif "PRE_LAUNCHED_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
gen_pre_launch_vm(vm_type, vm_i, scenario_items, config)
elif "POST_LAUNCHED_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
gen_post_launch_vm(vm_type, vm_i, scenario_items, config)
print("};", file=config)
return err_dic

View File

@@ -0,0 +1,116 @@
# Copyright (C) 2019 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import common
import scenario_cfg_lib
import board_cfg_lib
VM_HEADER_DEFINE = scenario_cfg_lib.HEADER_LICENSE + r"""
#ifndef VM_CONFIGURATIONS_H
#define VM_CONFIGURATIONS_H
"""
VM_END_DEFINE = r"""#endif /* VM_CONFIGURATIONS_H */"""
def gen_common_header(config):
"""
This is common header for vm_configuration.h
:param config: it is the pointer which file write to
:return: None
"""
print("{0}".format(VM_HEADER_DEFINE), file=config)
def scenario_vm_num(scenario_items, config):
print("", file=config)
print("/* SOS_VM_NUM can only be 0U or 1U;", file=config)
print(" * When SOS_VM_NUM is 0U, MAX_POST_VM_NUM must be 0U too;", file=config)
print(" * MAX_POST_VM_NUM must be bigger than CONFIG_MAX_KATA_VM_NUM;", file=config)
print(" */", file=config)
load_type_cnt = scenario_items['vm'].load_order_cnt
print("#define PRE_VM_NUM\t\t\t{}U".format(load_type_cnt.pre_vm), file=config)
print("#define SOS_VM_NUM\t\t\t{}U".format(load_type_cnt.sos_vm), file=config)
print("#define MAX_POST_VM_NUM\t\t\t{}U".format(load_type_cnt.post_vm), file=config)
print("#define CONFIG_MAX_KATA_VM_NUM\t\t{}U".format(scenario_cfg_lib.KATA_VM_COUNT), file=config)
def gen_pre_launch_vm(scenario_items, config):
vm_info = scenario_items['vm']
vm_i = 0
for vm_type in common.VM_TYPES.values():
if "PRE_LAUNCHED_VM" != scenario_cfg_lib.VM_DB[vm_type]['load_type']:
vm_i += 1
continue
print("#define VM{0}_CONFIG_MEM_START_HPA {1}UL".format(
vm_i, vm_info.mem_info.mem_start_hpa[vm_i]), file=config)
print("#define VM{0}_CONFIG_MEM_SIZE {1}UL".format(
vm_i, vm_info.mem_info.mem_size[vm_i]), file=config)
if vm_info.mem_info.mem_start_hpa2[vm_i] not in (None, ''):
print("#define VM{0}_CONFIG_MEM_START_HPA2 {1}UL".format(
vm_i, vm_info.mem_info.mem_start_hpa2[vm_i]), file=config)
print("#define VM{0}_CONFIG_MEM_SIZE_HPA2 {1}UL".format(
vm_i, vm_info.mem_info.mem_size_hpa2[vm_i]), file=config)
print("", file=config)
vm_i += 1
def gen_sos_header(scenario_items, config):
if 'SOS_VM' not in common.VM_TYPES.values():
return
for vm_i,vm_type in common.VM_TYPES.items():
if vm_type == 'SOS_VM':
print("/* SOS_VM == VM{0} */".format(vm_i), file=config)
print("#define SOS_VM_BOOTARGS\t\t\tSOS_ROOTFS\t\\", file=config)
print("\t\t\t\t\tSOS_CONSOLE\t\\", file=config)
print("\t\t\t\t\tSOS_IDLE\t\\", file=config)
print("\t\t\t\t\tSOS_BOOTARGS_DIFF", file=config)
print("", file=config)
def gen_header_file(scenario_items, config):
gen_pre_launch_vm(scenario_items, config)
gen_sos_header(scenario_items, config)
def get_dm_owned_guest_flag_mask(vm_info, config):
print("", file=config)
if "SOS_VM" not in common.VM_TYPES.values():
print("#define DM_OWNED_GUEST_FLAG_MASK 0UL", file=config)
else:
print("/* Bits mask of guest flags that can be programmed by device model." +
" Other bits are set by hypervisor only */", file=config)
print("#define DM_OWNED_GUEST_FLAG_MASK " +
"(GUEST_FLAG_SECURE_WORLD_ENABLED | GUEST_FLAG_LAPIC_PASSTHROUGH | \\\n" +
"\t\t\t\t\t\tGUEST_FLAG_RT | GUEST_FLAG_IO_COMPLETION_POLLING)", file=config)
print("", file=config)
def generate_file(scenario_items, config):
"""
Start to generate vm_configurations.h
:param scenario_items: it is the class which contain all user setting information
:param config: it is a file pointer of board information for writing to
"""
vm_info = scenario_items['vm']
gen_common_header(config)
print("#include <misc_cfg.h>", file=config)
print("#include <pci_devices.h>", file=config)
scenario_vm_num(scenario_items, config)
get_dm_owned_guest_flag_mask(vm_info, config)
gen_header_file(scenario_items, config)
print("{0}".format(VM_END_DEFINE), file=config)