diff --git a/misc/config_tools/scenario_config/ivshmem_cfg_h.py b/misc/config_tools/scenario_config/ivshmem_cfg_h.py deleted file mode 100644 index 0dccd1c41..000000000 --- a/misc/config_tools/scenario_config/ivshmem_cfg_h.py +++ /dev/null @@ -1,101 +0,0 @@ -# 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 ", file=config) - print("#include ", file=config) - write_shmem_regions(config) - - print("{0}".format(IVSHMEM_END_DEFINE), file=config) diff --git a/misc/config_tools/scenario_config/pci_dev_c.py b/misc/config_tools/scenario_config/pci_dev_c.py deleted file mode 100644 index 57d23d222..000000000 --- a/misc/config_tools/scenario_config/pci_dev_c.py +++ /dev/null @@ -1,320 +0,0 @@ -# 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[0-9a-f]{2}):(?P[0-9a-f]{2})\.(?P[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, last_bdf): - 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: - if last_bdf == BusDevFunc(bus=0x00, dev=0x00, func=0x0) or last_bdf.func == 0x7: - 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: - bdf = last_bdf - for func in range(0x8): - bdf = BusDevFunc(bdf.bus, bdf.dev, func) - #if bdf not in used_bdf: - 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 ", file=config) - print("#include ", file=config) - print("#include ", file=config) - print("#include ", file=config) - print("#include ", file=config) - print("#include ", file=config) - if pci_vuart_enabled: - print("#include ", file=config) - # Insert header for share memory - if vm_info.shmem.shmem_enabled == 'y': - print("#include ", 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'] != "SERVICE_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'] == "SERVICE_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'] == "SERVICE_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 - - last_bdf = BusDevFunc(bus=0x00, dev=0x00, func=0x0) - 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'] == "SERVICE_VM": - free_bdf = find_unused_bdf(sos_used_bdf, "ivshmem", last_bdf) - last_bdf = free_bdf - 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'] == "SERVICE_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) - - last_bdf = BusDevFunc(bus=0x00, dev=0x00, func=0x0) - 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", last_bdf) - vm_used_bdf.append(free_bdf) - elif scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SERVICE_VM": - free_bdf = find_unused_bdf(sos_used_bdf, "vuart", last_bdf) - 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) diff --git a/misc/config_tools/scenario_config/pt_intx_c.py b/misc/config_tools/scenario_config/pt_intx_c.py deleted file mode 100644 index c864d6262..000000000 --- a/misc/config_tools/scenario_config/pt_intx_c.py +++ /dev/null @@ -1,38 +0,0 @@ -# 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 ", 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) diff --git a/misc/config_tools/scenario_config/scenario_cfg_gen.py b/misc/config_tools/scenario_config/scenario_cfg_gen.py index 820290f2a..59119830c 100755 --- a/misc/config_tools/scenario_config/scenario_cfg_gen.py +++ b/misc/config_tools/scenario_config/scenario_cfg_gen.py @@ -13,11 +13,6 @@ sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', ' 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 @@ -258,29 +253,6 @@ def main(args): 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) diff --git a/misc/config_tools/scenario_config/vm_configurations_c.py b/misc/config_tools/scenario_config/vm_configurations_c.py deleted file mode 100644 index 499e06d76..000000000 --- a/misc/config_tools/scenario_config/vm_configurations_c.py +++ /dev/null @@ -1,426 +0,0 @@ -# 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 -#include -#include -""" - -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 == "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 - """ - # Servce 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 "SERVICE_" in vm_type: - print("\t\t\t.irq = SERVICE_VM_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 "SERVICE_" in vm_type: - print("\t\t\t.addr.port_base = SERVICE_VM_COM1_BASE,", file=config) - print("\t\t\t.irq = SERVICE_VM_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 "SERVICE_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 = SERVICE_VM_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 - """ - # Service_VM have not set epc section - if i not in common.VM_TYPES.keys(): - return - vm_type = list(common.VM_TYPES.values())[i] - if "SERVICE_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 "SERVICE_VM" == common.VM_TYPES[i]: - print("\t\t.cpu_affinity = SERVICE_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_SERVICE_VM,", file=config) - print('\t\t.name = "{0}",'.format(vm_info.name[vm_i]), file=config) - print("", file=config) - print("\t\t/* Allow Service VM 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},", 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.user_vm_pa = VM0_TPM_BUFFER_BASE_ADDR_GPA,", file=config) - print("\t\t\t.host_pa = 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.user_vm_pa = P2SB_BAR_ADDR_GPA,", file=config) - print("\t\t\t.host_pa = 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 == "SERVICE_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 "SERVICE_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 diff --git a/misc/config_tools/scenario_config/vm_configurations_h.py b/misc/config_tools/scenario_config/vm_configurations_h.py deleted file mode 100644 index 5c92e9d39..000000000 --- a/misc/config_tools/scenario_config/vm_configurations_h.py +++ /dev/null @@ -1,99 +0,0 @@ -# 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("/* SERVICE_VM_NUM can only be 0U or 1U;", file=config) - print(" * When SERVICE_VM_NUM is 0U, MAX_POST_VM_NUM must be 0U too;", 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 SERVICE_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) - - -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 'SERVICE_VM' not in common.VM_TYPES.values(): - return - - for vm_i,vm_type in common.VM_TYPES.items(): - if vm_type == 'SERVICE_VM': - print("/* SERVICE_VM == VM{0} */".format(vm_i), file=config) - - print("#define SERVICE_VM_OS_BOOTARGS\t\t\tSERVICE_VM_ROOTFS\t\\", file=config) - print("\t\t\t\t\tSERVICE_VM_OS_CONSOLE\t\\", file=config) - print("\t\t\t\t\tSERVICE_VM_IDLE\t\\", file=config) - print("\t\t\t\t\tSERVICE_VM_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 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 ", file=config) - print("#include ", file=config) - scenario_vm_num(scenario_items, config) - - gen_header_file(scenario_items, config) - print("{0}".format(VM_END_DEFINE), file=config)