mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-14 14:25:14 +00:00
This patch is to support the Inter-VM communication by IVSHMEM in config tool. Users can configure IVSHMEM_ENABLE to enable or disable Inter-VM communication by IVSHMEM; users can configure the name, size, communication VM IDs of the IVSHMEM devices in the VM settings of scenario xmls, then config tool will generate the related IVSHMEM configurations for Inter-VM communication. The config tool will do sanity check including when saving the xmls: the format of shared memory region configuration is [name],[size],[VM ID]:[VM ID](:[VM ID]...); the max size of the name is 32 bytes; the names should not be duplicated; the mininum value of shared memory region size is 2M; the value of shared memory region is a power of 2; the size of share memory region should not extended the size of available ram. Tracked-On: #4853 Signed-off-by: Shuang Zheng <shuang.zheng@intel.com> Acked-by: Victor Sun <victor.sun@intel.com>
104 lines
4.1 KiB
Python
104 lines
4.1 KiB
Python
# Copyright (C) 2020 Intel Corporation. All rights reserved.
|
|
#
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
#
|
|
|
|
import common
|
|
import board_cfg_lib
|
|
import scenario_cfg_lib
|
|
|
|
VBAR_INFO_DEFINE="""#ifndef VBAR_BASE_H_
|
|
#define VBAR_BASE_H_
|
|
"""
|
|
|
|
VBAR_INFO_ENDIF="""#endif /* VBAR_BASE_H_ */"""
|
|
|
|
def write_vbar(i_cnt, bdf, pci_bar_dic, bar_attr, config):
|
|
"""
|
|
Parser and generate vbar
|
|
:param i_cnt: the number of pci devices have the same PCI sub class name
|
|
:param bdf: it is a string what contains BDF
|
|
:param pci_bar_dic: it is a dictionary of pci vbar for those BDF
|
|
:param bar_attr: it is a class, contains PIC bar attribute
|
|
:param config: it is a file pointer of pci information for writing to
|
|
"""
|
|
align = ' ' * 54
|
|
ptdev_mmio_str = ''
|
|
|
|
tmp_sub_name = board_cfg_lib.get_sub_pci_name(i_cnt, bar_attr)
|
|
if bdf in pci_bar_dic.keys():
|
|
bar_list = list(pci_bar_dic[bdf].keys())
|
|
bar_len = len(bar_list)
|
|
bar_num = 0
|
|
for bar_i in bar_list:
|
|
if not bar_attr.remappable:
|
|
print("/* TODO: add {} 64bit BAR support */".format(tmp_sub_name), file=config)
|
|
|
|
bar_num += 1
|
|
bar_val = pci_bar_dic[bdf][bar_i].addr
|
|
if pci_bar_dic[bdf][bar_i].remapped:
|
|
ptdev_mmio_str = 'PTDEV_HI_MMIO_START + '
|
|
|
|
if bar_num == bar_len:
|
|
if bar_len == 1:
|
|
print("#define %-38s" % (tmp_sub_name+"_VBAR"), " .vbar_base[{}] = {}{}UL".format(bar_i, ptdev_mmio_str, bar_val), file=config)
|
|
else:
|
|
print("{}.vbar_base[{}] = {}{}UL".format(align, bar_i, ptdev_mmio_str, bar_val), file=config)
|
|
elif bar_num == 1:
|
|
print("#define %-38s" % (tmp_sub_name+"_VBAR"), " .vbar_base[{}] = {}{}UL, \\".format(bar_i, ptdev_mmio_str, bar_val), file=config)
|
|
else:
|
|
print("{}.vbar_base[{}] = {}{}UL, \\".format(align, bar_i, ptdev_mmio_str, bar_val), file=config)
|
|
print("", file=config)
|
|
|
|
|
|
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)
|