From 5403fd720dbcd2286397a5053109141e32bfd501 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Wed, 27 May 2020 11:28:47 +0800 Subject: [PATCH] acrn-config: re-generate TTYS_INFO in native board Currently, MMIO PCI BDF of ttyS was indexed by IRQ, but it may found the wrong BDF when the IRQ was shared and it is not expected. So, the patch uses the MMIO base to query /proc/iomem to find BDF, the waring will get if BDF is not present in iomem. Tracked-On: #4862 Signed-off-by: Wei Liu Acked-by: Victor Sun --- misc/acrn-config/board_config/misc_cfg_h.py | 2 +- misc/acrn-config/hv_config/board_defconfig.py | 10 ++-- misc/acrn-config/target/misc.py | 47 +++++++++++-------- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/misc/acrn-config/board_config/misc_cfg_h.py b/misc/acrn-config/board_config/misc_cfg_h.py index 3049f7050..81fda9f3a 100644 --- a/misc/acrn-config/board_config/misc_cfg_h.py +++ b/misc/acrn-config/board_config/misc_cfg_h.py @@ -36,7 +36,7 @@ def get_valid_ttys_for_vuart(ttys_n): vuart0_valid.clear() for tty_line in ttys_lines: tmp_dic = {} - #seri:/dev/ttySx type:mmio base:0x91526000 irq:4 bdf:"00:18.0" + #seri:/dev/ttySx type:mmio base:0x91526000 irq:4 [bdf:"00:18.0"] #seri:/dev/ttySy type:portio base:0x2f8 irq:5 tty = tty_line.split('/')[2].split()[0] ttys_irq = tty_line.split()[3].split(':')[1].strip() diff --git a/misc/acrn-config/hv_config/board_defconfig.py b/misc/acrn-config/hv_config/board_defconfig.py index 0bb8ceecf..f09085dbb 100644 --- a/misc/acrn-config/hv_config/board_defconfig.py +++ b/misc/acrn-config/hv_config/board_defconfig.py @@ -97,12 +97,15 @@ def get_serial_type(): if ttyn in line: # line format: # seri:/dev/ttyS0 type:portio base:0x3F8 irq:4 - # seri:/dev/ttyS0 type:mmio base:0xB3640000 irq:4 bdf:"0:x.y" + # seri:/dev/ttyS0 type:mmio base:0xB3640000 irq:4 [bdf:"0:x.y"] ttys_type = line.split()[1].split(':')[1] if ttys_type == "portio": ttys_value = line.split()[2].split(':')[1] elif ttys_type == "mmio": - ttys_value = line.split()[-1].split('"')[1:-1][0] + if 'bdf' in line: + ttys_value = line.split()[-1].split('"')[1:-1][0] + else: + common.print_yel("You have chosen a MMIO PCI serial that BDF does not existed for HV console.", warn=True) break return (ttys_type, ttys_value) @@ -156,7 +159,8 @@ def get_serial_console(config): print("CONFIG_SERIAL_PIO_BASE={}".format(serial_value), file=config) if serial_type == "mmio": print("CONFIG_SERIAL_PCI=y", file=config) - print('CONFIG_SERIAL_PCI_BDF="{}"'.format(serial_value), file=config) + if serial_value: + print('CONFIG_SERIAL_PCI_BDF="{}"'.format(serial_value), file=config) def get_miscfg(hv_info, config): diff --git a/misc/acrn-config/target/misc.py b/misc/acrn-config/target/misc.py index 8977f2ee7..4b2194882 100644 --- a/misc/acrn-config/target/misc.py +++ b/misc/acrn-config/target/misc.py @@ -51,29 +51,33 @@ def detected_ttys(): return tty_used_list -def irq2bdf(irq_n): - cmd = 'lspci -vv' - res = parser_lib.cmd_execute(cmd) +def is_bdf_format(bdf): + is_bdf = False + + if len(bdf) == 7 and len(bdf.split(':')[0]) == 2 and len(bdf.split(':')[1].split('.')[0]) == 2 and len(bdf.split(".")[1]) == 1: + is_bdf = True + + return is_bdf + + +def iomem2bdf(base): bdf = '' - irq = 0 - while True: - line = res.stdout.readline().decode('ascii') - if not line: - break + base_iomem = base.strip('0x').lower() + with open(MEM_PATH[0], 'rt') as mem_info: - if ':' not in line: - continue - - if '.' in line.split()[0]: - bdf = line.split()[0] - - if "Interrupt:" in line.strip(): - irq = line.split()[-1] - if irq == irq_n and bdf: + while True: + line = mem_info.readline().strip('\n') + if not line: break - return bdf + if base_iomem in line and '0000:' in line: + bdf = line.split(" ")[-1].lstrip("0000").lstrip(":") + if not is_bdf_format(bdf): + continue + else: + break + return bdf def dump_ttys_info(ttys_list, config): for ttys in ttys_list: @@ -92,8 +96,11 @@ def dump_ttys_info(ttys_list, config): elif ttys_type[serial_type] == 'MMIO': base_path = '{}{}/iomem_base'.format(TTY_PATH, ttys_n) base = read_ttys_node(base_path) - bdf = irq2bdf(irq) - print('\tseri:{} type:mmio base:{} irq:{} bdf:"{}"'.format(ttys, base, irq, bdf), file=config) + bdf = iomem2bdf(base) + if bdf: + print('\tseri:{} type:mmio base:{} irq:{} bdf:"{}"'.format(ttys, base, irq, bdf), file=config) + else: + print('\tseri:{} type:mmio base:{} irq:{}'.format(ttys, base, irq), file=config) def dump_ttys(config):