acrn-config: reserve hostbirdge bdf of pre-launched vm
bdf 00:00.0 is reserved for pci hostbridge. Reserve the this bdf of pre-launced vm even there is neither passtrhough pci devices nor emulated pci devices. Refine the logic of get_pt_pci_num. It only counts the passthrough devices, and does not pre-assume any vhostbridge device exists. Refine the logic of pci hostbridge device insertion. If any one of passthrough pci dvices, ivshmem or vuarts of pre-launched vm are preset, insert the pci hostbridge declaration to pci_dev.c. Tracked-On: #5609 Signed-off-by: Yang,Yu-chu <yu-chu.yang@intel.com> Acked-by: Victor Sun <victor.sun@intel.com>
This commit is contained in:
parent
2f7e0cde46
commit
54a5832dbe
|
@ -97,8 +97,8 @@ def cpu_affinity_per_vm_gen(config):
|
|||
def pci_dev_num_per_vm_gen(config):
|
||||
|
||||
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_dev_num = scenario_cfg_lib.get_pci_num(pci_devs)
|
||||
pci_devs = scenario_cfg_lib.get_pt_pci_devs(pci_items)
|
||||
pt_pci_num = scenario_cfg_lib.get_pt_pci_num(pci_devs)
|
||||
|
||||
ivshmem_region = common.get_hv_item_tag(common.SCENARIO_INFO_FILE,
|
||||
"FEATURES", "IVSHMEM", "IVSHMEM_REGION")
|
||||
|
@ -110,25 +110,24 @@ def pci_dev_num_per_vm_gen(config):
|
|||
shmem_num = scenario_cfg_lib.get_shmem_num(shmem_regions)
|
||||
|
||||
vuarts = common.get_vuart_info(common.SCENARIO_INFO_FILE)
|
||||
vuarts_num = scenario_cfg_lib.get_vuart_num(vuarts)
|
||||
pci_vuarts_num = scenario_cfg_lib.get_pci_vuart_num(vuarts)
|
||||
|
||||
for vm_i,vm_type in common.VM_TYPES.items():
|
||||
num = 0
|
||||
if "POST_LAUNCHED_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
|
||||
shmem_num_i = 0
|
||||
vuart_num = vuarts_num[vm_i]
|
||||
pci_vuart_num = pci_vuarts_num[vm_i]
|
||||
if shmem_enabled == 'y' and vm_i in shmem_num.keys():
|
||||
shmem_num_i = shmem_num[vm_i]
|
||||
num = shmem_num_i + vuart_num
|
||||
num = shmem_num_i + pci_vuart_num
|
||||
elif "PRE_LAUNCHED_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
|
||||
shmem_num_i = 0
|
||||
if shmem_enabled == 'y' and vm_i in shmem_num.keys():
|
||||
shmem_num_i = shmem_num[vm_i]
|
||||
if pci_dev_num[vm_i] == 1:
|
||||
# there is only vhostbridge but no passthrough device
|
||||
# remove the count of vhostbridge, check get_pci_num definition
|
||||
pci_dev_num[vm_i] -= 1
|
||||
num = pci_dev_num[vm_i] + shmem_num_i + vuarts_num[vm_i]
|
||||
num = pt_pci_num[vm_i] + shmem_num_i + pci_vuarts_num[vm_i]
|
||||
if pt_pci_num[vm_i] > 0 or shmem_num_i > 0 or pci_vuarts_num[vm_i] > 0:
|
||||
# if there is passthrough device or ivshmem, vhostbridge is needed
|
||||
num += 1
|
||||
elif "SOS_VM" == scenario_cfg_lib.VM_DB[vm_type]['load_type']:
|
||||
continue
|
||||
if num > 0:
|
||||
|
|
|
@ -373,7 +373,7 @@ def generate_file(config):
|
|||
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 = scenario_cfg_lib.get_pt_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 = [
|
||||
|
|
|
@ -73,7 +73,7 @@ F_TARGET_VM_ID = 'target_vm_id'
|
|||
F_TARGET_UART_ID = 'target_uart_id'
|
||||
|
||||
|
||||
def get_pci_devs(pci_items):
|
||||
def get_pt_pci_devs(pci_items):
|
||||
|
||||
pci_devs = {}
|
||||
for vm_i,pci_descs in pci_items.items():
|
||||
|
@ -89,12 +89,11 @@ def get_pci_devs(pci_items):
|
|||
return pci_devs
|
||||
|
||||
|
||||
def get_pci_num(pci_devs):
|
||||
def get_pt_pci_num(pci_devs):
|
||||
|
||||
pci_devs_num = {}
|
||||
for vm_i,pci_devs_list in pci_devs.items():
|
||||
# vhostbridge
|
||||
cnt_dev = 1
|
||||
cnt_dev = 0
|
||||
for pci_dev in pci_devs_list:
|
||||
if not pci_dev:
|
||||
continue
|
||||
|
@ -139,7 +138,7 @@ def get_shmem_num(shmem_regions):
|
|||
return shmem_num
|
||||
|
||||
|
||||
def get_vuart_num(vuarts):
|
||||
def get_pci_vuart_num(vuarts):
|
||||
|
||||
vuarts_num = {}
|
||||
# get legacy vuart information
|
||||
|
@ -174,8 +173,8 @@ def get_pci_dev_num_per_vm():
|
|||
pci_dev_num_per_vm = {}
|
||||
|
||||
pci_items = common.get_leaf_tag_map(common.SCENARIO_INFO_FILE, "pci_devs", "pci_dev")
|
||||
pci_devs = get_pci_devs(pci_items)
|
||||
pci_dev_num = get_pci_num(pci_devs)
|
||||
pci_devs = get_pt_pci_devs(pci_items)
|
||||
pt_pci_num = get_pt_pci_num(pci_devs)
|
||||
|
||||
ivshmem_region = common.get_hv_item_tag(common.SCENARIO_INFO_FILE,
|
||||
"FEATURES", "IVSHMEM", "IVSHMEM_REGION")
|
||||
|
@ -187,7 +186,7 @@ def get_pci_dev_num_per_vm():
|
|||
shmem_num = get_shmem_num(shmem_regions)
|
||||
|
||||
vuarts = common.get_vuart_info(common.SCENARIO_INFO_FILE)
|
||||
vuarts_num = get_vuart_num(vuarts)
|
||||
vuarts_num = get_pci_vuart_num(vuarts)
|
||||
|
||||
for vm_i,vm_type in common.VM_TYPES.items():
|
||||
if "POST_LAUNCHED_VM" == VM_DB[vm_type]['load_type']:
|
||||
|
@ -200,11 +199,7 @@ def get_pci_dev_num_per_vm():
|
|||
shmem_num_i = 0
|
||||
if shmem_enabled == 'y' and vm_i in shmem_num.keys():
|
||||
shmem_num_i = shmem_num[vm_i]
|
||||
if pci_dev_num[vm_i] == 1:
|
||||
# there is only vhostbridge but no passthrough device
|
||||
# remove the count of vhostbridge, check get_pci_num definition
|
||||
pci_dev_num[vm_i] -= 1
|
||||
pci_dev_num_per_vm[vm_i] = pci_dev_num[vm_i] + shmem_num_i + vuarts_num[vm_i]
|
||||
pci_dev_num_per_vm[vm_i] = pt_pci_num[vm_i] + shmem_num_i + vuarts_num[vm_i]
|
||||
elif "SOS_VM" == VM_DB[vm_type]['load_type']:
|
||||
shmem_num_i = 0
|
||||
if shmem_enabled == 'y' and vm_i in shmem_num.keys():
|
||||
|
|
|
@ -106,14 +106,16 @@ def generate_file(vm_info, config):
|
|||
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)
|
||||
vuarts_num = scenario_cfg_lib.get_vuart_num(vuarts)
|
||||
pci_vuarts_num = scenario_cfg_lib.get_pci_vuart_num(vuarts)
|
||||
pci_vuart_enabled = False
|
||||
for vm_i in common.VM_TYPES:
|
||||
if vuarts_num[vm_i] > 0:
|
||||
if pci_vuarts_num[vm_i] > 0:
|
||||
pci_vuart_enabled = True
|
||||
break
|
||||
|
||||
|
@ -151,6 +153,10 @@ def generate_file(vm_info, config):
|
|||
|
||||
for vm_i, vm_type in common.VM_TYPES.items():
|
||||
vm_used_bdf = []
|
||||
# bdf 00:00.0 is reserved for pci host bridge of any type of VM
|
||||
bdf_tuple = BusDevFunc.from_str("00:00.0")
|
||||
vm_used_bdf.append(bdf_tuple)
|
||||
|
||||
# Skip this vm if there is no any pci device and virtual device
|
||||
if not scenario_cfg_lib.get_pci_dev_num_per_vm()[vm_i] and \
|
||||
scenario_cfg_lib.VM_DB[vm_type]['load_type'] != "SOS_VM":
|
||||
|
@ -172,20 +178,31 @@ def generate_file(vm_info, config):
|
|||
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:
|
||||
# Insert pci hostbridge for passtrough devices:
|
||||
if pci_cnt == 1:
|
||||
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)
|
||||
bdf_tuple = BusDevFunc.from_str("00:00.0")
|
||||
vm_used_bdf.append(bdf_tuple)
|
||||
|
||||
for pci_bdf_dev in pci_bdf_devs_list:
|
||||
if not pci_bdf_dev:
|
||||
continue
|
||||
|
@ -210,6 +227,7 @@ def generate_file(vm_info, config):
|
|||
and len(vm_info.shmem.shmem_regions[vm_i]) > 0:
|
||||
raw_shm_list = vm_info.shmem.shmem_regions[vm_i]
|
||||
index = 0
|
||||
|
||||
for shm in raw_shm_list:
|
||||
shm_splited = shm.split(',')
|
||||
print("\t{", file=config)
|
||||
|
|
|
@ -181,26 +181,26 @@ class MemInfo:
|
|||
|
||||
class CfgPci:
|
||||
""" This is Abstract of class of PCi devices setting information """
|
||||
pci_dev_num = {}
|
||||
pt_pci_num = {}
|
||||
pci_devs = {}
|
||||
|
||||
def __init__(self, scenario_file):
|
||||
self.scenario_info = scenario_file
|
||||
|
||||
def get_pci_dev_num(self):
|
||||
def get_pt_pci_dev_num(self):
|
||||
"""
|
||||
Get pci device number items
|
||||
:return: None
|
||||
"""
|
||||
self.pci_dev_num = scenario_cfg_lib.get_pci_num(self.pci_devs)
|
||||
self.pt_pci_num = scenario_cfg_lib.get_pt_pci_num(self.pci_devs)
|
||||
|
||||
def get_pci_devs(self):
|
||||
def get_pt_pci_devs(self):
|
||||
"""
|
||||
Get pci devices items
|
||||
:return: None
|
||||
"""
|
||||
pci_items = common.get_leaf_tag_map(self.scenario_info, "pci_devs", "pci_dev")
|
||||
self.pci_devs = scenario_cfg_lib.get_pci_devs(pci_items)
|
||||
self.pci_devs = scenario_cfg_lib.get_pt_pci_devs(pci_items)
|
||||
|
||||
|
||||
def get_info(self):
|
||||
|
@ -208,8 +208,8 @@ class CfgPci:
|
|||
Get all items which belong to this class
|
||||
:return: None
|
||||
"""
|
||||
self.get_pci_devs()
|
||||
self.get_pci_dev_num()
|
||||
self.get_pt_pci_devs()
|
||||
self.get_pt_pci_dev_num()
|
||||
|
||||
def check_item(self):
|
||||
""" Check all items in this class
|
||||
|
|
Loading…
Reference in New Issue