acrn-config/hv: create new file pt_intx_c.py to generate the pt_intx.c file

Move struct pt_intx_config vm0_pt_intx[] defintion to pt_intx.c
so that vm_configurations.h/vm_configurations.c are consistent for different boards

Tracked-On: #5229
Signed-off-by: dongshen <dongsheng.x.zhang@intel.com>
This commit is contained in:
dongshen 2020-09-09 13:05:45 -07:00 committed by wenlingz
parent 0f0d0c0d18
commit ef9a961523
8 changed files with 107 additions and 43 deletions

View File

@ -268,6 +268,7 @@ HW_C_SRCS += boot/guest/direct_boot.c
# VM Configuration
VM_CFG_C_SRCS += $(BOARD_INFO_DIR)/board.c
VM_CFG_C_SRCS += $(SCENARIO_CFG_DIR)/vm_configurations.c
VM_CFG_C_SRCS += $(BOARD_CFG_DIR)/pt_intx.c
ifneq (,$(wildcard $(BOARD_CFG_DIR)/pci_dev.c))
VM_CFG_C_SRCS += $(BOARD_CFG_DIR)/pci_dev.c
endif

View File

@ -231,6 +231,20 @@ def boot_args_per_vm_gen(config):
print("", file=config)
def pt_intx_num_vm0_gen(config):
phys_gsi, virt_gsi = common.get_pt_intx_table(common.SCENARIO_INFO_FILE)
if (board_cfg_lib.is_matched_board(("ehl-crb-b"))
and phys_gsi.get(0) is not None
and len(phys_gsi[0]) > 0):
print("#define VM0_PT_INTX_NUM\t{}U".format(len(phys_gsi[0])), file=config)
else:
print("#define VM0_PT_INTX_NUM\t0U", file=config)
print("", file=config)
def generate_file(config):
"""
Start to generate board.c
@ -400,6 +414,8 @@ def generate_file(config):
boot_args_per_vm_gen(config)
pt_intx_num_vm0_gen(config)
print("{}".format(MISC_CFG_END), file=config)
return err_dic

View File

@ -9,6 +9,7 @@ import getopt
import shutil
import subprocess
import xml.etree.ElementTree as ET
import re
ACRN_CONFIG_TARGET = ''
@ -560,3 +561,38 @@ def str2int(x):
return int(s, base)
return 0
def get_pt_intx_table(config_file):
pt_intx_map = get_leaf_tag_map(config_file, "pt_intx")
# translation table to normalize the paired phys_gsi and virt_gsi string
table = {ord('[') : ord('('), ord(']') : ord(')'), ord('{') : ord('('),
ord('}') : ord(')'), ord(';') : ord(','),
ord('\n') : None, ord('\r') : None, ord(' ') : None}
phys_gsi = {}
virt_gsi = {}
for vm_i, s in pt_intx_map.items():
#normalize the phys_gsi and virt_gsi pair string
s = s.translate(table)
#extract the phys_gsi and virt_gsi pairs between parenthesis to a list
s = re.findall(r'\(([^)]+)', s)
phys_gsi[vm_i] = [];
virt_gsi[vm_i] = [];
for part in s:
if not part: continue
assert ',' in part, "you need to use ',' to separate phys_gsi and virt_gsi!"
a, b = part.split(',')
if not a and not b: continue
assert a and b, "you need to specify both phys_gsi and virt_gsi!"
a, b = str2int(a), str2int(b)
phys_gsi[vm_i].append(a)
virt_gsi[vm_i].append(b)
return phys_gsi, virt_gsi

View File

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

View File

@ -15,6 +15,7 @@ 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
@ -24,7 +25,7 @@ import asl_gen
ACRN_PATH = common.SOURCE_ROOT_DIR
ACRN_CONFIG_DEF = ACRN_PATH + 'misc/vm_configs/scenarios/'
GEN_FILE = ["vm_configurations.h", "vm_configurations.c", "pci_dev.c", ".config", "ivshmem_cfg.h"]
GEN_FILE = ["vm_configurations.h", "vm_configurations.c", "pci_dev.c", ".config", "ivshmem_cfg.h", "pt_intx.c"]
def get_scenario_item_values(board_info, scenario_info):
@ -171,6 +172,7 @@ def main(args):
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'])
@ -203,6 +205,11 @@ def main(args):
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)

View File

@ -6,7 +6,6 @@
import common
import board_cfg_lib
import scenario_cfg_lib
import re
class HwInfo:
""" This is Abstract of class of Hardware information """
@ -309,34 +308,7 @@ class PtIntxInfo:
Get all items which belong to this class
:return: None
"""
pt_intx_map = common.get_leaf_tag_map(self.scenario_info, "pt_intx")
# translation table to normalize the paired phys_gsi and virt_gsi string
table = {ord('[') : ord('('), ord(']') : ord(')'), ord('{') : ord('('),
ord('}') : ord(')'), ord(';') : ord(','),
ord('\n') : None, ord('\r') : None, ord(' ') : None}
for vm_i, s in pt_intx_map.items():
#normalize the phys_gsi and virt_gsi pair string
s = s.translate(table)
#extract the phys_gsi and virt_gsi pairs between parenthesis to a list
s = re.findall(r'\(([^)]+)', s)
self.phys_gsi[vm_i] = [];
self.virt_gsi[vm_i] = [];
for part in s:
if not part: continue
assert ',' in part, "you need to use ',' to separate phys_gsi and virt_gsi!"
a, b = part.split(',')
if not a and not b: continue
assert a and b, "you need to specify both phys_gsi and virt_gsi!"
a, b = common.str2int(a), common.str2int(b)
self.phys_gsi[vm_i].append(a)
self.virt_gsi[vm_i].append(b)
self.phys_gsi, self.virt_gsi = common.get_pt_intx_table(self.scenario_info)
def check_item(self):
"""

View File

@ -347,10 +347,8 @@ def gen_pre_launch_vm(vm_type, vm_i, scenario_items, config):
print("\t\t},", file=config)
print("#endif", file=config)
if (vm_i == 0 and board_cfg_lib.is_matched_board(("ehl-crb-b"))
and vm_info.pt_intx_info.phys_gsi.get(vm_i) is not None
and len(vm_info.pt_intx_info.phys_gsi[vm_i]) > 0):
print("\t\t.pt_intx_num = {}U,".format(len(vm_info.pt_intx_info.phys_gsi[vm_i])), 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)
@ -415,16 +413,11 @@ def generate_file(scenario_items, 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("static 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)
print("", 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():

View File

@ -27,6 +27,7 @@ PRE_BUILD_SRCS += static_checks.c
PRE_BUILD_SRCS += vm_cfg_checks.c
PRE_BUILD_SRCS += $(HV_SRC_DIR)/arch/x86/configs/vm_config.c
PRE_BUILD_SRCS += $(SCENARIO_CFG_DIR)/vm_configurations.c
PRE_BUILD_SRCS += $(BOARD_CFG_DIR)/pt_intx.c
ifneq (,$(wildcard $(BOARD_CFG_DIR)/pci_dev.c))
PRE_BUILD_SRCS += $(BOARD_CFG_DIR)/pci_dev.c
endif