Ejemplo n.º 1
0
def validate_launch_setting(board_info, scenario_info, launch_info):
    """
    This is validate the data setting from scenario xml
    :param board_info: it is a file what contains board information for script to read from
    :param scenario_info: it is a file what user have already setting to
    :return: return a dictionary contain errors
    """
    common.SCENARIO_INFO_FILE = scenario_info
    common.get_vm_types()

    launch_cfg_lib.ERR_LIST = {}
    common.BOARD_INFO_FILE = board_info
    common.SCENARIO_INFO_FILE = scenario_info
    common.LAUNCH_INFO_FILE = launch_info

    # init available pt devices and get selected pt devices
    pt_avl = AvailablePthru(board_info)
    pt_sel = PthruSelected(launch_info, pt_avl.bdf_desc_map,
                           pt_avl.bdf_vpid_map)
    pt_sel.get_bdf()
    pt_sel.get_vpid()
    pt_sel.get_slot()
    pt_sel.check_item()

    # virt-io devices
    virtio = VirtioDeviceSelect(launch_info)
    virtio.get_virtio()
    virtio.check_virtio()

    # acrn dm arguments
    dm = AcrnDmArgs(board_info, scenario_info, launch_info)
    dm.get_args()
    dm.check_item()

    return (launch_cfg_lib.ERR_LIST, pt_sel, virtio, dm)
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,SSRAM,SSRAM_ENABLED"] = hv_cfg_lib.N_Y

    scenario_cfg_lib.ERR_LIST.update(hv_cfg_lib.ERR_LIST)
    return scenario_item_values
Ejemplo n.º 3
0
def generate_file(config):
    # start to generate board_info.h
    print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
    print(VBAR_INFO_DEFINE, file=config)
    common.get_vm_types()
    pre_vm = False
    for vm_type in common.VM_TYPES.values():
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
            pre_vm = True

    if not pre_vm:
        print(VBAR_INFO_ENDIF, file=config)
        return

    compared_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

            write_vbar(i_cnt, bdf, board_cfg_lib.PCI_DEV_BAR_DESC.pci_bar_dic, bar_attr, config)

            i_cnt += 1

    print(VBAR_INFO_ENDIF, file=config)
Ejemplo n.º 4
0
def get_scenario_item_values(board_info, scenario_info):
    """
    Get items which capable multi select for user
    :param board_info: it is a file what contains board information for script to read from
    """
    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()

    # pre 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"] = 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.update(scenario_cfg_lib.avl_vuart_ui_select(scenario_info))

    # pre board_private
    (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,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_cfg_lib.ERR_LIST.update(hv_cfg_lib.ERR_LIST)
    return scenario_item_values
Ejemplo n.º 5
0
def main(args):
    # Initialize configuration libraries for backward compatibility
    common.BOARD_INFO_FILE = args.board
    common.SCENARIO_INFO_FILE = args.scenario
    common.get_vm_num(args.scenario)
    common.get_vm_types()

    scripts_path = os.path.dirname(os.path.realpath(__file__))
    current = os.path.basename(__file__)

    board_etree = lxml.etree.parse(args.board)
    scenario_etree = lxml.etree.parse(args.scenario)
    allocation_etree = lxml.etree.ElementTree(
        element=lxml.etree.fromstring("<acrn-config></acrn-config>"))
    for script in [
            f for f in os.listdir(scripts_path)
            if f.endswith(".py") and f != current
    ]:
        module_name = os.path.splitext(script)[0]
        module = import_module(f"{module_name}")
        module.fn(board_etree, scenario_etree, allocation_etree)
    allocation_etree.write(args.output, pretty_print=True)
Ejemplo n.º 6
0
def generate_file(config):
    """
    Start to generate board.c
    :param config: it is a file pointer of board information for writing to
    """
    board_cfg_lib.get_valid_irq(common.BOARD_INFO_FILE)

    # get the vuart0/vuart1 which user chosed from scenario.xml of board_private section
    (err_dic, ttys_n) = board_cfg_lib.parser_hv_console()
    if err_dic:
        return err_dic

    # parse sos_bootargs/rootfs/console
    (err_dic, sos_cmdlines, sos_rootfs, vuart0_dic, vuart1_dic) = parse_boot_info()
    if err_dic:
        return err_dic

    if vuart0_dic:
        # parse to get poart/base of vuart0/vuart1
        vuart0_port_base = board_cfg_lib.LEGACY_TTYS[list(vuart0_dic.keys())[0]]
        vuart0_irq = vuart0_dic[list(vuart0_dic.keys())[0]]

    vuart1_port_base = board_cfg_lib.LEGACY_TTYS[list(vuart1_dic.keys())[0]]
    vuart1_irq = vuart1_dic[list(vuart1_dic.keys())[0]]

    # parse the setting ttys vuatx dic: {vmid:base/irq}
    vuart0_setting = Vuart()
    vuart1_setting = Vuart()
    vuart0_setting = common.get_vuart_info_id(common.SCENARIO_INFO_FILE, 0)
    vuart1_setting = common.get_vuart_info_id(common.SCENARIO_INFO_FILE, 1)

    # sos command lines information
    sos_cmdlines = [i for i in sos_cmdlines[0].split() if i != '']

    # get native rootfs list from board_info.xml
    (root_devs, root_dev_num) = board_cfg_lib.get_rootfs(common.BOARD_INFO_FILE)

    # start to generate misc_cfg.h
    print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
    print("{}".format(MISC_CFG_HEADER), file=config)
    print("", file=config)

    # define rootfs with macro
    #for i in range(root_dev_num):
    #    print('#define ROOTFS_{}\t\t"root={} "'.format(i, root_devs[i]), file=config)

    # sos rootfs and console
    if "SOS_VM" in common.VM_TYPES.values():
        print('#define SOS_ROOTFS\t\t"root={} "'.format(sos_rootfs[0]), file=config)
        if ttys_n:
            print('#define SOS_CONSOLE\t\t"console={} "'.format(ttys_n), file=config)
        else:
            print('#define SOS_CONSOLE\t\t" "', file=config)

    # sos com base/irq
    i_type = 0
    for vm_i,vm_type in common.VM_TYPES.items():
        if vm_type == "SOS_VM":
            i_type = vm_i
            break

    if "SOS_VM" in common.VM_TYPES.values():
        if vuart0_dic:
            print("#define SOS_COM1_BASE\t\t{}U".format(vuart0_port_base), file=config)
            print("#define SOS_COM1_IRQ\t\t{}U".format(vuart0_irq), file=config)
        else:
            print("#define SOS_COM1_BASE\t\t0U", file=config)
            print("#define SOS_COM1_IRQ\t\t0U", file=config)

        if vuart1_setting[i_type]['base'] != "INVALID_COM_BASE":
            print("#define SOS_COM2_BASE\t\t{}U".format(vuart1_port_base), file=config)
            print("#define SOS_COM2_IRQ\t\t{}U".format(vuart1_irq), file=config)

        # sos boot command line
        print("", file=config)

    if "SOS_VM" in common.VM_TYPES.values():
        sos_bootarg_diff(sos_cmdlines, config)
        print("", file=config)

    if board_cfg_lib.is_rdt_supported():
        print("", file=config)
        common_clos_max = board_cfg_lib.get_common_clos_max()
        max_cache_clos_entries = common_clos_max
        if board_cfg_lib.is_cdp_enabled():
            max_cache_clos_entries = 2 * common_clos_max
        print("#define MAX_CACHE_CLOS_NUM_ENTRIES\t{}U".format(max_cache_clos_entries), file=config)

        (rdt_resources, rdt_res_clos_max, _) = board_cfg_lib.clos_info_parser(common.BOARD_INFO_FILE)
        cat_mask_list = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "RDT", "CLOS_MASK")
        mba_delay_list = common.get_hv_item_tag(common.SCENARIO_INFO_FILE, "FEATURES", "RDT", "MBA_DELAY")
        idx = 0
        for mba_delay_mask in mba_delay_list:
            print("#define MBA_MASK_{}\t\t\t{}U".format(idx, mba_delay_mask), file=config)
            idx += 1

        idx = 0
        for cat_mask in cat_mask_list:
            print("#define CLOS_MASK_{}\t\t\t{}U".format(idx, cat_mask), file=config)
            idx += 1
        print("", file=config)

    vm0_pre_launch = False
    common.get_vm_types()
    for vm_idx,vm_type in common.VM_TYPES.items():
        if vm_idx == 0 and scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
            vm0_pre_launch = True

    if vm0_pre_launch and board_cfg_lib.is_tpm_passthru():
        print("#define VM0_PASSTHROUGH_TPM", file=config)
        print("#define VM0_TPM_BUFFER_BASE_ADDR   0xFED40000UL", file=config)
        print("#define VM0_TPM_BUFFER_SIZE        0x5000UL", file=config)

        print("", file=config)

    print("{}".format(MISC_CFG_END), file=config)

    return err_dic
Ejemplo n.º 7
0
def main(args):
    """
    This is main function to start generate source code related with board
    :param args: it is a command line args for the script
    """
    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'] = "The vm count in config xml should be less or equal {}!".format(
                common.MAX_VM_NUM)
        return err_dic

    # check if this is the scenario config which matched board info
    (err_dic, status) = common.is_config_file_match()
    if not status:
        err_dic[
            'scenario config'] = "The board xml and scenario xml should be matched!"
        return err_dic

    if params['--out']:
        if os.path.isabs(params['--out']):
            scenario_dir = os.path.join(params['--out'], scenario + '/')
            config_hv = os.path.join(params['--out'], board_name + GEN_FILE[3])
        else:
            scenario_dir = os.path.join(ACRN_PATH + params['--out'],
                                        scenario + '/')
            config_hv = os.path.join(ACRN_PATH + params['--out'],
                                     board_name + GEN_FILE[3])
    else:
        scenario_dir = os.path.join(ACRN_CONFIG_DEF, scenario + '/')
        config_hv = os.path.join(ACRN_CONFIGS, board_name + GEN_FILE[3])
        common.print_yel("{}".format("Override board defconfig...", warn=True))
    common.mkdir(scenario_dir)

    vm_config_h = scenario_dir + GEN_FILE[0]
    vm_config_c = scenario_dir + GEN_FILE[1]
    pci_config_c = scenario_dir + GEN_FILE[2]

    # 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("Validate the scenario item failure", 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['vm'],
                                                    config)
        if err_dic:
            return err_dic

    # generate pci_dev.c
    for vm_i, pci_dev_num in scenario_items['vm'].cfg_pci.pci_dev_num.items():
        if pci_dev_num >= 2:
            with open(pci_config_c, 'w') as config:
                pci_dev_c.generate_file(scenario_items['vm'], config)
            break

    if not err_dic:
        print(
            "Scenario configurations for {} is generated successfully.".format(
                scenario))
    else:
        print("Scenario configurations for {} is generated failed.".format(
            scenario))

    return err_dic
Ejemplo n.º 8
0
def main(args):
    """
    This is main function to start generate source code related with board
    :param args: it is a command line args for the script
    """
    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()

    if common.VM_COUNT > common.MAX_VM_NUM:
        err_dic[
            'vm count'] = "The vm count in config xml should be less or equal {}!".format(
                common.MAX_VM_NUM)
        return err_dic

    # check if this is the scenario config which matched board info
    # get board name
    (err_dic, board) = common.get_board_name()
    if err_dic:
        return err_dic

    (err_dic, scenario) = common.get_scenario_name()
    if err_dic:
        return err_dic
    board_cfg_lib.BOARD_NAME = board

    # check if this is the scenario config which matched board info
    (err_dic, status) = common.is_config_file_match()
    if not status:
        err_dic[
            'board config'] = "The board xml file does not match scenario xml file!"
        return err_dic

    output = ''
    if params['--out']:
        if os.path.isabs(params['--out']):
            output = params['--out']
        else:
            output = ACRN_PATH + params['--out']
    else:
        output = ACRN_CONFIG_DEF

    board_fix_dir = os.path.join(output, "boards/")
    scen_board_dir = os.path.join(output, "scenarios/" + scenario + "/")
    common.mkdir(board_fix_dir)
    common.mkdir(scen_board_dir)

    config_pci = board_fix_dir + GEN_FILE[0]
    config_board = board_fix_dir + GEN_FILE[1]
    config_acpi = board_fix_dir + GEN_FILE[2]
    config_board_h = board_fix_dir + GEN_FILE[4]
    config_misc_cfg = scen_board_dir + GEN_FILE[3]
    config_vbar_base = scen_board_dir + GEN_FILE[5]

    # generate pci_devices.h
    with open(config_pci, 'w+') as config:
        pci_devices_h.generate_file(config)

    # generate board_info.h
    with open(config_board_h, 'w+') as config:
        err_dic = board_info_h.generate_file(config)
        if err_dic:
            return err_dic

    # generate board.c
    with open(config_board, 'w+') as config:
        err_dic = board_c.generate_file(config)
        if err_dic:
            return err_dic

    # generate vbar_base.h
    with open(config_vbar_base, 'w+') as config:
        vbar_base_h.generate_file(config)

    # generate platform_acpi_info.h
    with open(config_acpi, 'w+') as config:
        acpi_platform_h.generate_file(config, ACRN_DEFAULT_ACPI)

    # generate misc_cfg.h
    with open(config_misc_cfg, 'w+') as config:
        err_dic = misc_cfg_h.generate_file(config)
        if err_dic:
            return err_dic

    if not err_dic:
        print("Board configurations for {} is generated successfully.".format(
            board))
    else:
        print("Board configurations for {} is generated failed.".format(board))

    return err_dic
Ejemplo n.º 9
0
def generate_file(config):
    """
    Start to generate board.c
    :param config: it is a file pointer of board information for writing to
    """
    board_cfg_lib.get_valid_irq(common.BOARD_INFO_FILE)

    # get the vuart0/vuart1 which user chosed from scenario.xml of board_private section
    (err_dic, ttys_n) = board_cfg_lib.parser_hv_console()
    if err_dic:
        return err_dic

    # parse sos_bootargs/rootfs/console
    (err_dic, sos_cmdlines, sos_rootfs, vuart0_dic,
     vuart1_dic) = parse_boot_info()
    if err_dic:
        return err_dic

    if vuart0_dic:
        # parse to get poart/base of vuart0/vuart1
        vuart0_port_base = board_cfg_lib.LEGACY_TTYS[list(
            vuart0_dic.keys())[0]]
        vuart0_irq = vuart0_dic[list(vuart0_dic.keys())[0]]

    vuart1_port_base = board_cfg_lib.LEGACY_TTYS[list(vuart1_dic.keys())[0]]
    vuart1_irq = vuart1_dic[list(vuart1_dic.keys())[0]]

    # parse the setting ttys vuatx dic: {vmid:base/irq}
    vuart0_setting = Vuart()
    vuart1_setting = Vuart()
    vuart0_setting = common.get_vuart_info_id(common.SCENARIO_INFO_FILE, 0)
    vuart1_setting = common.get_vuart_info_id(common.SCENARIO_INFO_FILE, 1)

    # sos command lines information
    sos_cmdlines = [i for i in sos_cmdlines[0].split() if i != '']

    # add maxcpus parameter into sos cmdlines if there are pre-launched VMs
    pcpu_list = board_cfg_lib.get_processor_info()
    cpu_affinity = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE,
                                           "cpu_affinity", "pcpu_id")
    pre_cpu_list = []
    sos_cpu_num = 0
    for vmid, cpu_list in cpu_affinity.items():
        if vmid in common.VM_TYPES and cpu_list != [None]:
            vm_type = common.VM_TYPES[vmid]
            load_type = ''
            if vm_type in scenario_cfg_lib.VM_DB:
                load_type = scenario_cfg_lib.VM_DB[vm_type]['load_type']
            if load_type == "PRE_LAUNCHED_VM":
                pre_cpu_list += cpu_list
            elif load_type == "SOS_VM":
                sos_cpu_num += len(cpu_list)
    if sos_cpu_num == 0:
        sos_cpu_num_max = len(list(set(pcpu_list) - set(pre_cpu_list)))
    else:
        sos_cpu_num_max = sos_cpu_num
    if sos_cpu_num_max > 0:
        sos_cmdlines.append('maxcpus=' + str(sos_cpu_num_max))

    # get native rootfs list from board_info.xml
    (root_devs,
     root_dev_num) = board_cfg_lib.get_rootfs(common.BOARD_INFO_FILE)

    # start to generate misc_cfg.h
    print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
    print("{}".format(MISC_CFG_HEADER), file=config)
    print("", file=config)

    # define rootfs with macro
    #for i in range(root_dev_num):
    #    print('#define ROOTFS_{}\t\t"root={} "'.format(i, root_devs[i]), file=config)

    # sos rootfs and console
    if "SOS_VM" in common.VM_TYPES.values():
        print('#define SOS_ROOTFS\t\t"root={} "'.format(sos_rootfs[0]),
              file=config)
        if ttys_n:
            print('#define SOS_CONSOLE\t\t"console={} "'.format(ttys_n),
                  file=config)
        else:
            print('#define SOS_CONSOLE\t\t" "', file=config)

    # sos com base/irq
    i_type = 0
    for vm_i, vm_type in common.VM_TYPES.items():
        if vm_type == "SOS_VM":
            i_type = vm_i
            break

    if "SOS_VM" in common.VM_TYPES.values():
        if vuart0_dic:
            print("#define SOS_COM1_BASE\t\t{}U".format(vuart0_port_base),
                  file=config)
            print("#define SOS_COM1_IRQ\t\t{}U".format(vuart0_irq),
                  file=config)
        else:
            print("#define SOS_COM1_BASE\t\t0U", file=config)
            print("#define SOS_COM1_IRQ\t\t0U", file=config)

        if vuart1_setting[i_type]['base'] != "INVALID_COM_BASE":
            print("#define SOS_COM2_BASE\t\t{}U".format(vuart1_port_base),
                  file=config)
            print("#define SOS_COM2_IRQ\t\t{}U".format(vuart1_irq),
                  file=config)

        # sos boot command line
        print("", file=config)

    if "SOS_VM" in common.VM_TYPES.values():
        sos_bootarg_diff(sos_cmdlines, config)
        print("", file=config)

    cpu_affinity_per_vm_gen(config)

    common_clos_max = board_cfg_lib.get_common_clos_max()
    max_mba_clos_entries = common_clos_max
    max_cache_clos_entries = common_clos_max

    comments_max_clos = '''
/*
 * The maximum CLOS that is allowed by ACRN hypervisor,
 * its value is set to be least common Max CLOS (CPUID.(EAX=0x10,ECX=ResID):EDX[15:0])
 * among all supported RDT resources in the platform. In other words, it is
 * min(maximum CLOS of L2, L3 and MBA). This is done in order to have consistent
 * CLOS allocations between all the RDT resources.
 */'''

    comments_max_mba_clos = '''
/*
 * Max number of Cache Mask entries corresponding to each CLOS.
 * This can vary if CDP is enabled vs disabled, as each CLOS entry
 * will have corresponding cache mask values for Data and Code when
 * CDP is enabled.
 */'''

    comments_max_cache_clos = '''
/* Max number of MBA delay entries corresponding to each CLOS. */'''

    if board_cfg_lib.is_cdp_enabled():
        max_cache_clos_entries_cdp_enable = 2 * common_clos_max
        (res_info, rdt_res_clos_max,
         clos_max_mask_list) = board_cfg_lib.clos_info_parser(
             common.BOARD_INFO_FILE)
        common_clos_max_cdp_disable = min(rdt_res_clos_max)

        print("#ifdef CONFIG_RDT_ENABLED", file=config)
        print("#ifdef CONFIG_CDP_ENABLED", file=config)
        print(comments_max_clos, file=config)
        print("#define HV_SUPPORTED_MAX_CLOS\t{}U".format(common_clos_max),
              file=config)

        print(comments_max_cache_clos, file=config)
        print("#define MAX_CACHE_CLOS_NUM_ENTRIES\t{}U".format(
            max_cache_clos_entries_cdp_enable),
              file=config)

        print("#else", file=config)
        print(comments_max_clos, file=config)
        print("#define HV_SUPPORTED_MAX_CLOS\t{}U".format(
            common_clos_max_cdp_disable),
              file=config)

        print(comments_max_cache_clos, file=config)
        print("#define MAX_CACHE_CLOS_NUM_ENTRIES\t{}U".format(
            max_cache_clos_entries),
              file=config)
        print("#endif", file=config)

        print(comments_max_mba_clos, file=config)
        print("#define MAX_MBA_CLOS_NUM_ENTRIES\t{}U".format(
            max_mba_clos_entries),
              file=config)
    else:
        print("#ifdef CONFIG_RDT_ENABLED", file=config)
        print(comments_max_clos, file=config)
        print("#define HV_SUPPORTED_MAX_CLOS\t{}U".format(common_clos_max),
              file=config)

        print(comments_max_mba_clos, file=config)
        print("#define MAX_MBA_CLOS_NUM_ENTRIES\t{}U".format(
            max_mba_clos_entries),
              file=config)

        print(comments_max_cache_clos, file=config)
        print("#define MAX_CACHE_CLOS_NUM_ENTRIES\t{}U".format(
            max_cache_clos_entries),
              file=config)
        if not board_cfg_lib.is_rdt_supported():
            print("#endif", file=config)

    print("", file=config)

    if board_cfg_lib.is_rdt_supported():
        (rdt_resources, rdt_res_clos_max,
         _) = board_cfg_lib.clos_info_parser(common.BOARD_INFO_FILE)
        cat_mask_list = common.get_hv_item_tag(common.SCENARIO_INFO_FILE,
                                               "FEATURES", "RDT", "CLOS_MASK")
        mba_delay_list = common.get_hv_item_tag(common.SCENARIO_INFO_FILE,
                                                "FEATURES", "RDT", "MBA_DELAY")
        idx = 0
        for mba_delay_mask in mba_delay_list:
            print("#define MBA_MASK_{}\t\t\t{}U".format(idx, mba_delay_mask),
                  file=config)
            idx += 1

        idx = 0
        for cat_mask in cat_mask_list:
            print("#define CLOS_MASK_{}\t\t\t{}U".format(idx, cat_mask),
                  file=config)
            idx += 1
        print("", file=config)

        clos_per_vm_gen(config)
        print("#endif", file=config)
        print("", file=config)

    vm0_pre_launch = False
    common.get_vm_types()
    for vm_idx, vm_type in common.VM_TYPES.items():
        if vm_idx == 0 and scenario_cfg_lib.VM_DB[vm_type][
                'load_type'] == "PRE_LAUNCHED_VM":
            vm0_pre_launch = True

    if vm0_pre_launch and board_cfg_lib.is_tpm_passthru():
        tpm2_passthru_enabled = common.get_leaf_tag_map_bool(
            common.SCENARIO_INFO_FILE, "mmio_resources", "TPM2")
        if 0 in tpm2_passthru_enabled and tpm2_passthru_enabled[0]:
            print("#define VM0_PASSTHROUGH_TPM", file=config)
            print("#define VM0_TPM_BUFFER_BASE_ADDR   0xFED40000UL",
                  file=config)
            gpa = common.hpa2gpa(0, 0xFED40000, 0x5000)
            print(
                "#define VM0_TPM_BUFFER_BASE_ADDR_GPA   0x{:X}UL".format(gpa),
                file=config)
            print("#define VM0_TPM_BUFFER_SIZE        0x5000UL", file=config)
            print("", file=config)

    pci_dev_num_per_vm_gen(config)

    boot_args_per_vm_gen(config)

    pt_intx_num_vm0_gen(config)

    swsram_base_gpa_gen(config)

    print("{}".format(MISC_CFG_END), file=config)

    return err_dic
Ejemplo n.º 10
0
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
    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
Ejemplo n.º 11
0
def main(args):
    """
    This is main function to start generate launch script
    :param args: it is a command line args for the script
    """
    # get parameters
    (err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th,
     output_folder) = launch_cfg_lib.get_param(args)
    if err_dic:
        return err_dic

    # check env
    err_dic = common.prepare()
    if err_dic:
        return err_dic

    # vm_th =[0..post_vm_max]
    # 0: generate all launch script for all post vm launch script
    # 1: generate launch script for 1st post vm launch script
    # 2: generate launch script for 2nd post vm launch script

    common.BOARD_INFO_FILE = board_info_file
    common.SCENARIO_INFO_FILE = scenario_info_file
    common.LAUNCH_INFO_FILE = launch_info_file
    common.get_vm_types()

    # get post vm dic
    post_num_list = launch_cfg_lib.get_post_num_list()

    # get toatl post vm number and total vm in launch config file
    (launch_vm_count, post_vm_count) = launch_cfg_lib.get_post_vm_cnt()
    if vm_th < 0 or vm_th > post_vm_count:
        err_dic[
            'uosid err:'] = "--uosid shoudl be positive and less than total post vm count in scenario"
    if vm_th and vm_th not in post_num_list:
        err_dic[
            'uosid err:'] = "--uosid generate the {} post vm, but this vm's config not in launch xml".format(
                vm_th)
    if launch_vm_count > post_vm_count:
        err_dic['xm config err:'] = "too many vms config than scenario"

    for post_num in post_num_list:
        if post_num > post_vm_count:
            err_dic[
                'xm config err:'] = "launch xml uos id config is bigger than scenario post vm count"

    if err_dic:
        return err_dic

    # validate launch config file
    (err_dic, pt_sel, virt_io,
     dm) = validate_launch_setting(board_info_file, scenario_info_file,
                                   launch_info_file)
    if err_dic:
        return err_dic

    # check if this is the scenario config which matched board info
    (err_dic, status) = launch_cfg_lib.is_config_file_match()
    if not status:
        return err_dic

    (err_dic, names) = get_names()
    if err_dic:
        return err_dic

    # create output directory
    board_name = names['board_name']
    if output_folder:
        if os.path.isabs(output_folder):
            output = os.path.join(output_folder + '/' + board_name, 'output/')
        else:
            output = os.path.join(ACRN_PATH + output_folder + '/' + board_name,
                                  'output/')
    else:
        output = os.path.join(ACRN_CONFIG_DEF + board_name, 'output/')
    common.mkdir(output)

    # generate launch script
    if vm_th:
        script_name = "launch_uos_id{}.sh".format(vm_th)
        launch_script_file = output + script_name
        with open(launch_script_file, mode='w', newline=None,
                  encoding='utf-8') as config:
            err_dic = generate_script_file(names, pt_sel, virt_io.dev, dm.args,
                                           vm_th, config)
            if err_dic:
                return err_dic
    else:
        for post_vm_i in post_num_list:
            script_name = "launch_uos_id{}.sh".format(post_vm_i)
            launch_script_file = output + script_name
            with open(launch_script_file,
                      mode='w',
                      newline='\n',
                      encoding='utf-8') as config:
                err_dic = generate_script_file(names, pt_sel, virt_io.dev,
                                               dm.args, post_vm_i, config)
                if err_dic:
                    return err_dic

    if not err_dic:
        print("Launch files in {} is generated successfully!".format(output))
    else:
        print("Launch files generate failed".format(output))

    return err_dic
Ejemplo n.º 12
0
def main(args):
    """
    This is main function to start generate launch script
    :param args: it is a command line args for the script
    """
    # get parameters
    (err_dic, board_info_file, scenario_info_file, launch_info_file, vm_th,
     output_folder) = launch_cfg_lib.get_param(args)
    if err_dic:
        return err_dic

    # check env
    err_dic = common.prepare()
    if err_dic:
        return err_dic

    # vm_th =[0..post_vm_max]
    # 0: generate all launch script for all post vm launch script
    # 1: generate launch script for 1st post vm launch script
    # 2: generate launch script for 2nd post vm launch script

    common.BOARD_INFO_FILE = board_info_file
    common.SCENARIO_INFO_FILE = scenario_info_file
    common.LAUNCH_INFO_FILE = launch_info_file
    common.get_vm_types()

    # get post vm dic
    post_num_list = launch_cfg_lib.get_post_num_list()

    # get toatl post vm number and total vm in launch config file
    (launch_vm_count, post_vm_count) = launch_cfg_lib.get_post_vm_cnt()
    if vm_th < 0 or vm_th > post_vm_count:
        err_dic[
            'user_vmid err:'] = "--user_vmid shoudl be positive and less than total post vm count in scenario"
    if vm_th and vm_th not in post_num_list:
        err_dic[
            'user_vmid err:'] = "--user_vmid generate the {} post vm, but this vm's config not in launch xml".format(
                vm_th)
    if launch_vm_count > post_vm_count:
        err_dic['xm config err:'] = "too many vms config than scenario"

    for post_num in post_num_list:
        if post_num > post_vm_count:
            err_dic[
                'xm config err:'] = "launch xml user vmid config is bigger than scenario post vm count"

    # validate vm_names
    scenario_names = common.get_leaf_tag_map(scenario_info_file,
                                             "name").values()
    for user_vm_id, vm_name in launch_cfg_lib.get_user_vm_names().items():
        if not re.match(r"^\S{1,15}$", vm_name):
            err_name = 'user_vm id="{}" name error:'.format(user_vm_id)
            err_dic[err_name] = 'vm_name only allowed 1-15 characters with letters, numbers & symbols ' \
                                '(not include space)'
        if vm_name not in scenario_names:
            err_name = 'user_vm id="{}" name not found error:'.format(
                user_vm_id)
            err_dic[
                err_name] = 'user_vm id="{}" vm_name not found in it scenario file:'.format(
                    user_vm_id)

    if err_dic:
        return err_dic

    # validate launch config file
    (err_dic, pt_sel, virt_io, dm,
     sriov) = validate_launch_setting(board_info_file, scenario_info_file,
                                      launch_info_file)
    if err_dic:
        return err_dic

    # check if this is the scenario config which matched board info
    (err_dic, status) = launch_cfg_lib.is_config_file_match()
    if not status:
        return err_dic

    (err_dic, names) = get_names()
    if err_dic:
        return err_dic

    # create output directory
    board_name = names['board_name']
    if output_folder:
        if os.path.isabs(output_folder):
            output = os.path.join(output_folder, board_name, 'output')
        else:
            output = os.path.join(ACRN_PATH, output_folder, board_name,
                                  'output')
    else:
        output = os.path.join(ACRN_CONFIG_DEF, board_name, 'output')
    output = os.path.abspath(output)
    common.mkdir(output)

    # generate launch script
    if vm_th:
        script_name = "launch_user_vm_id{}.sh".format(vm_th)
        launch_script_file = os.path.join(output, script_name)
        with open(launch_script_file, mode='w', newline=None,
                  encoding='utf-8') as config:
            err_dic = generate_script_file(names, pt_sel, virt_io.dev, dm.args,
                                           sriov.dev, vm_th, config)
            if err_dic:
                return err_dic
    else:
        for post_vm_i in post_num_list:
            script_name = "launch_user_vm_id{}.sh".format(post_vm_i)
            launch_script_file = os.path.join(output, script_name)
            with open(launch_script_file,
                      mode='w',
                      newline='\n',
                      encoding='utf-8') as config:
                err_dic = generate_script_file(names, pt_sel, virt_io.dev,
                                               dm.args, sriov.dev, post_vm_i,
                                               config)
                if err_dic:
                    return err_dic

    if not err_dic:
        print("Launch files in {} is generated successfully!".format(output))
    else:
        print("Launch files generate failed".format(output))

    return err_dic
Ejemplo n.º 13
0
def generate_file(config):
    matching_mmios, non_matching_mmios = get_mmio_windows_with_key(
        ['PCI Bus 0000:00'])
    matching_mmios = removed_nested(matching_mmios, non_matching_mmios)
    non_matching_mmios = [
        w for w in non_matching_mmios
        if any((w.overlaps(w2) for w2 in matching_mmios))
    ]
    non_matching_mmios = merged_windows(non_matching_mmios)

    # list of all vmsix supported device list in bdf format
    bdf_list = board_cfg_lib.get_known_caps_pci_devs().get('VMSIX', [])
    # list of all PRE_LAUNCHED_VMs' vmsix supported passthrough devices in bdf format
    pci_items = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, "pci_devs",
                                        "pci_dev")
    pci_devs = scenario_cfg_lib.get_pt_pci_devs(pci_items)
    pci_devs_per_vm = get_devs_per_vm_with_key(pci_devs, bdf_list)
    # list Service VM vmsix supported devices without other PRE_LAUNCHED_VMs' in bdf format
    sos_bdf_list = [
        d for d in bdf_list
        if all((d not in pci_devs_per_vm[i] for i in pci_devs_per_vm))
    ]

    for vm_i in pci_devs_per_vm:
        vm_type = common.VM_TYPES[vm_i]
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SERVICE_VM":
            pci_devs_per_vm[vm_i] = sos_bdf_list

    mmiolist_per_vm = {}
    for vm_i, vm_type in common.VM_TYPES.items():
        if vm_i not in mmiolist_per_vm.keys():
            mmiolist_per_vm[vm_i] = []
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SERVICE_VM":
            mmiolist_per_vm[vm_i] = non_matching_mmios
        else:
            if vm_i in pci_devs.keys():
                match, _ = get_mmio_windows_with_key(pci_devs[vm_i])
                mmiolist_per_vm[vm_i] = match
            if scenario_cfg_lib.VM_DB[vm_type][
                    'load_type'] == "PRE_LAUNCHED_VM":
                if vm_i not in mmiolist_per_vm.keys():
                    mmiolist_per_vm[vm_i] = []
                # TSN reserved region
                mmiolist_per_vm[vm_i].append(
                    MmioWindow(start=0xffff0000, end=0xffffffff))
                # For the pre-launched vm, if the TPM is passtrough, this address is used
                if vm_i == 0 and board_cfg_lib.is_tpm_passthru():
                    mmiolist_per_vm[vm_i].append(
                        MmioWindow(start=0xfed40000,
                                   end=0xfed40000 + 0x5000 - 1))
                # For the pre-launched vm o ehl-crb-b, if the p2sb is passtrough, this address is used
                if board_cfg_lib.is_matched_board(('ehl-crb-b')):
                    p2sb_start = board_cfg_lib.find_p2sb_bar_addr()
                    mmiolist_per_vm[vm_i].append(
                        MmioWindow(start=p2sb_start,
                                   end=p2sb_start + 0x1000000 - 1))
                mmiolist_per_vm[vm_i].sort()

    # start to generate board_info.h
    print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
    print(VBAR_INFO_DEFINE, file=config)
    common.get_vm_types()
    pre_vm = False
    sos_vm = False
    for vm_type in common.VM_TYPES.values():
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
            pre_vm = True
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SERVICE_VM":
            sos_vm = True

    if not pre_vm and not sos_vm:
        print(VBAR_INFO_ENDIF, file=config)
        return

    ivshmem_enabled = common.get_hv_item_tag(common.SCENARIO_INFO_FILE,
                                             "FEATURES", "IVSHMEM",
                                             "IVSHMEM_ENABLED")
    if ivshmem_enabled == 'y':
        write_ivshmem_vbar(mmiolist_per_vm, matching_mmios, config)

    # Get passthrough devices vbar bases
    compared_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

            write_vbar(i_cnt, bdf, board_cfg_lib.PCI_DEV_BAR_DESC.pci_bar_dic, bar_attr, \
                pci_devs_per_vm, mmiolist_per_vm, matching_mmios, config)

            i_cnt += 1

    write_vuart_vbar(mmiolist_per_vm, matching_mmios, config)
    print(VBAR_INFO_ENDIF, file=config)
Ejemplo n.º 14
0
def generate_file(config):
    # start to generate board_info.h
    print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
    print(VBAR_INFO_DEFINE, file=config)
    common.get_vm_types()
    pre_vm = False
    for vm_type in common.VM_TYPES.values():
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
            pre_vm = True

    if not pre_vm:
        print(VBAR_INFO_ENDIF, file=config)
        return

    compared_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

            write_vbar(i_cnt, bdf, board_cfg_lib.PCI_DEV_BAR_DESC.pci_bar_dic,
                       bar_attr, config)

            i_cnt += 1

    ivshmem_enabled = common.get_hv_item_tag(common.SCENARIO_INFO_FILE,
                                             "FEATURES", "IVSHMEM",
                                             "IVSHMEM_ENABLED")
    if ivshmem_enabled == 'y':
        board_cfg_lib.parse_mem()
        for shm_name, bar_attr_dic in board_cfg_lib.PCI_DEV_BAR_DESC.shm_bar_dic.items(
        ):
            index = shm_name[:shm_name.find('_')]
            i_cnt = 0
            for bar_i, bar_attr in bar_attr_dic.items():
                i_cnt += 1
                if bar_i == 0:
                    if len(bar_attr_dic.keys()) == 1:
                        print("#define IVSHMEM_DEVICE_%-23s" %
                              (str(index) + "_VBAR"),
                              "       .vbar_base[{}] = {}UL".format(
                                  bar_i, bar_attr.addr),
                              file=config)
                    else:
                        print("#define IVSHMEM_DEVICE_%-23s" %
                              (str(index) + "_VBAR"),
                              "       .vbar_base[{}] = {}UL, \\".format(
                                  bar_i, bar_attr.addr),
                              file=config)
                elif i_cnt == len(bar_attr_dic.keys()):
                    print("{}.vbar_base[{}] = {}UL".format(
                        ' ' * 54, bar_i, bar_attr.addr),
                          file=config)
                else:
                    print("{}.vbar_base[{}] = {}UL, \\".format(
                        ' ' * 54, bar_i, bar_attr.addr),
                          file=config)

            print("", file=config)

    print(VBAR_INFO_ENDIF, file=config)
Ejemplo n.º 15
0
def generate_file(config):
    matching_mmios, non_matching_mmios = get_mmio_windows_with_key(
        ['PCI Bus 0000:00'])
    matching_mmios = removed_nested(matching_mmios, non_matching_mmios)
    non_matching_mmios = [
        w for w in non_matching_mmios
        if any((w.overlaps(w2) for w2 in matching_mmios))
    ]
    non_matching_mmios = merged_windows(non_matching_mmios)

    # list of all vmsix supported device list in bdf format
    bdf_list = board_cfg_lib.get_known_caps_pci_devs().get('VMSIX', [])
    # list of all PRE_LAUNCHED_VMs' vmsix supported passthrough devices in bdf format
    pci_items = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, "pci_devs",
                                        "pci_dev")
    pci_devs = scenario_cfg_lib.get_pci_devs(pci_items)
    pci_devs_per_vm = get_devs_per_vm_with_key(pci_devs, bdf_list)
    # list SOS vmsix supported devices without other PRE_LAUNCHED_VMs' in bdf format
    sos_bdf_list = [
        d for d in bdf_list
        if all((d not in pci_devs_per_vm[i] for i in pci_devs_per_vm))
    ]

    for vm_i in pci_devs_per_vm:
        vm_type = common.VM_TYPES[vm_i]
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
            pci_devs_per_vm[vm_i] = sos_bdf_list

    mmiolist_per_vm = {}
    for vm_i, vm_type in common.VM_TYPES.items():
        if vm_i not in mmiolist_per_vm.keys():
            mmiolist_per_vm[vm_i] = []
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
            mmiolist_per_vm[vm_i] = non_matching_mmios
        else:
            if vm_i in pci_devs.keys():
                match, _ = get_mmio_windows_with_key(pci_devs[vm_i])
                mmiolist_per_vm[vm_i] = match
            if scenario_cfg_lib.VM_DB[vm_type][
                    'load_type'] == "PRE_LAUNCHED_VM":
                if vm_i not in mmiolist_per_vm.keys():
                    mmiolist_per_vm[vm_i] = []
                # TSN reserved region
                mmiolist_per_vm[vm_i].append(
                    MmioWindow(start=0xffff0000, end=0xffffffff))
                # For the pre-launched vm, if the TPM is passtrough, this address is used
                if vm_i == 0 and board_cfg_lib.is_tpm_passthru():
                    mmiolist_per_vm[vm_i].append(
                        MmioWindow(start=0xfed40000,
                                   end=0xfed40000 + 0x5000 - 1))
                # For the pre-launched vm o ehl-crb-b, if the p2sb is passtrough, this address is used
                if board_cfg_lib.is_matched_board(('ehl-crb-b')):
                    p2sb_start = board_cfg_lib.find_p2sb_bar_addr()
                    mmiolist_per_vm[vm_i].append(
                        MmioWindow(start=p2sb_start,
                                   end=p2sb_start + 0x1000000 - 1))
                mmiolist_per_vm[vm_i].sort()

    # start to generate board_info.h
    print("{0}".format(board_cfg_lib.HEADER_LICENSE), file=config)
    print(VBAR_INFO_DEFINE, file=config)
    common.get_vm_types()
    pre_vm = False
    sos_vm = False
    for vm_type in common.VM_TYPES.values():
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "PRE_LAUNCHED_VM":
            pre_vm = True
        if scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
            sos_vm = True

    if not pre_vm and not sos_vm:
        print(VBAR_INFO_ENDIF, file=config)
        return

    ivshmem_enabled = common.get_hv_item_tag(common.SCENARIO_INFO_FILE,
                                             "FEATURES", "IVSHMEM",
                                             "IVSHMEM_ENABLED")
    if ivshmem_enabled == 'y':
        for vm_id, vm_type in common.VM_TYPES.items():
            free_bar = []
            if scenario_cfg_lib.VM_DB[vm_type][
                    'load_type'] == "PRE_LAUNCHED_VM":
                board_cfg_lib.parse_mem()
                for shm_name, bar_attr_dic in board_cfg_lib.PCI_DEV_BAR_DESC.shm_bar_dic.items(
                ):
                    index = shm_name[:shm_name.find('_')]
                    i_cnt = 0
                    for bar_i, bar_attr in bar_attr_dic.items():
                        i_cnt += 1
                        if bar_i == 2:
                            raw_shmem_regions = common.get_hv_item_tag(
                                common.SCENARIO_INFO_FILE, "FEATURES",
                                "IVSHMEM", "IVSHMEM_REGION")
                            for shm in raw_shmem_regions:
                                if shm is None or shm.strip() == '':
                                    continue
                                shm_splited = shm.split(',')
                                name = shm_splited[0].strip()
                                size = shm_splited[1].strip()

                                try:
                                    int_size = int(size) * 0x100000
                                except:
                                    int_size = 0
                            bar_2 = int(bar_attr.addr, 16)
                            mmiolist_per_vm[vm_id].append(
                                MmioWindow(start=bar_2,
                                           end=bar_2 + int_size - 1))
                            mmiolist_per_vm[vm_id].sort()
                        if bar_i == 0:
                            bar_0 = MmioWindow(start=int(bar_attr.addr, 16),
                                               end=int(bar_attr.addr, 16) +
                                               0x100 - 1)
                            mmiolist_per_vm[vm_id].append(bar_0)
                            mmiolist_per_vm[vm_id].sort()
                            if len(bar_attr_dic.keys()) == 1:
                                print("#define IVSHMEM_DEVICE_%-23s" %
                                      (str(index) + "_VBAR"),
                                      "       .vbar_base[{}] = {}UL".format(
                                          bar_i, bar_attr.addr),
                                      file=config)
                            else:
                                print(
                                    "#define IVSHMEM_DEVICE_%-23s" %
                                    (str(index) + "_VBAR"),
                                    "       .vbar_base[{}] = {}UL, \\".format(
                                        bar_i, bar_attr.addr),
                                    file=config)
                                # vbar[1] for share memory is fix to 4K
                                free_bar = get_free_mmio([MmioWindow(start=common.SIZE_2G, end=common.SIZE_4G-1)], \
                                                mmiolist_per_vm[vm_id], BAR1_SHEMEM_ALIGNMENT + BAR1_SHEMEM_SIZE)
                                free_bar_start_addr = common.round_up(
                                    free_bar.start, BAR1_SHEMEM_ALIGNMENT)
                                free_bar_end_addr = free_bar_start_addr + BAR1_SHEMEM_SIZE - 1
                                free_bar = MmioWindow(free_bar_start_addr,
                                                      free_bar_end_addr)
                                mmiolist_per_vm[vm_id].append(free_bar)
                                mmiolist_per_vm[vm_id].sort()
                                print("{}.vbar_base[1] = {:#x}UL, \\".format(
                                    ' ' * 54, free_bar.start),
                                      file=config)
                        elif i_cnt == len(bar_attr_dic.keys()):
                            print("{}.vbar_base[{}] = {}UL".format(
                                ' ' * 54, bar_i, bar_attr.addr),
                                  file=config)
                        else:
                            print("{}.vbar_base[{}] = {}UL, \\".format(
                                ' ' * 54, bar_i, bar_attr.addr),
                                  file=config)
                    print("", file=config)
            elif scenario_cfg_lib.VM_DB[vm_type]['load_type'] == "SOS_VM":
                ivshmem_region = common.get_hv_item_tag(
                    common.SCENARIO_INFO_FILE, "FEATURES", "IVSHMEM",
                    "IVSHMEM_REGION")
                shmem_regions = scenario_cfg_lib.get_shmem_regions(
                    ivshmem_region)
                if vm_id not in shmem_regions.keys():
                    continue
                idx = 0
                for shm in ivshmem_region:
                    if shm is None or shm.strip() == '':
                        continue
                    shm_splited = shm.split(',')
                    name = shm_splited[0].strip()
                    size = shm_splited[1].strip()
                    try:
                        int_size = int(size) * 0x100000
                    except:
                        int_size = 0
                    # vbar[0] for shared memory is 0x100
                    free_bar0 = get_free_mmio(
                        matching_mmios, mmiolist_per_vm[vm_id],
                        BAR0_SHEMEM_ALIGNMENT + BAR0_SHEMEM_SIZE)
                    free_bar0_start_addr = common.round_up(
                        free_bar0.start, BAR0_SHEMEM_ALIGNMENT)
                    free_bar0_end_addr = free_bar0_start_addr + BAR0_SHEMEM_SIZE - 1
                    free_bar0 = MmioWindow(free_bar0_start_addr,
                                           free_bar0_end_addr)
                    mmiolist_per_vm[vm_id].append(free_bar0)
                    mmiolist_per_vm[vm_id].sort()
                    # vbar[1] for shared memory is 4K
                    free_bar1 = get_free_mmio(
                        matching_mmios, mmiolist_per_vm[vm_id],
                        BAR1_SHEMEM_ALIGNMENT + BAR1_SHEMEM_SIZE)
                    free_bar1_start_addr = common.round_up(
                        free_bar1.start, BAR1_SHEMEM_ALIGNMENT)
                    free_bar1_end_addr = free_bar1_start_addr + BAR1_SHEMEM_SIZE - 1
                    free_bar1 = MmioWindow(free_bar1_start_addr,
                                           free_bar1_end_addr)
                    mmiolist_per_vm[vm_id].append(free_bar1)
                    mmiolist_per_vm[vm_id].sort()
                    # vbar[2] for shared memory is specified size in MB
                    free_bar2 = get_free_mmio(matching_mmios,
                                              mmiolist_per_vm[vm_id],
                                              BAR2_SHEMEM_ALIGNMENT + int_size)
                    free_bar2_start_addr = common.round_up(
                        free_bar2.start, BAR2_SHEMEM_ALIGNMENT) + 0xC
                    free_bar2_end_addr = free_bar2_start_addr + int_size - 1
                    free_bar2 = MmioWindow(free_bar2_start_addr,
                                           free_bar2_end_addr)
                    mmiolist_per_vm[vm_id].append(free_bar2)
                    mmiolist_per_vm[vm_id].sort()
                    print("#define SOS_IVSHMEM_DEVICE_%-19s" %
                          (str(idx) + "_VBAR"),
                          "       .vbar_base[0] = {:#x}UL, \\".format(
                              free_bar0.start),
                          file=config)
                    print("{}.vbar_base[1] = {:#x}UL, \\".format(
                        ' ' * 54, free_bar1.start),
                          file=config)
                    print("{}.vbar_base[2] = {:#x}UL".format(
                        ' ' * 54, free_bar2.start),
                          file=config)
                    print("", file=config)
                    idx += 1

    # Get passthrough devices vbar bases
    compared_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

            write_vbar(i_cnt, bdf, board_cfg_lib.PCI_DEV_BAR_DESC.pci_bar_dic, bar_attr, \
                pci_devs_per_vm, mmiolist_per_vm, matching_mmios, config)

            i_cnt += 1

    write_vuart_vbar(mmiolist_per_vm, matching_mmios, config)
    print(VBAR_INFO_ENDIF, file=config)