[PATCH v3] config_tools: board_inspector: parse bdf for ioport serial controler


Zhao, Yuanyuan
 

Add bdf infomation to ioport serial controler.

v2->v3:
Use 'get_bdf_from_realpath'.

v1->v2:
Parse tty*/device link instead of parse pci device infomation.

Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@...>
---
.../board_inspector/legacy/misc.py | 21 +++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/misc/config_tools/board_inspector/legacy/misc.py b/misc/config_tools/board_inspector/legacy/misc.py
index e6abb4ab8..7be4e4585 100644
--- a/misc/config_tools/board_inspector/legacy/misc.py
+++ b/misc/config_tools/board_inspector/legacy/misc.py
@@ -3,7 +3,8 @@
# SPDX-License-Identifier: BSD-3-Clause
#

-import parser_lib
+import parser_lib, os
+from extractors.helpers import get_bdf_from_realpath

MEM_PATH = ['/proc/iomem', '/proc/meminfo']
TTY_PATH = '/sys/class/tty/'
@@ -78,6 +79,14 @@ def iomem2bdf(base):

return bdf

+def ioport2bdf(ttys_n):
+ path = os.path.join(TTY_PATH, ttys_n, 'device')
+ link = os.readlink(path).split('/')[-1]
+ bdf = link.lstrip("0000").lstrip(":")
+ if not is_bdf_format(bdf):
+ bdf = ''
+ return bdf
+
def dump_ttys_info(ttys_list, config):
for ttys in ttys_list:
ttys_n = ttys.split('/')[-1]
@@ -91,7 +100,15 @@ def dump_ttys_info(ttys_list, config):
if ttys_type[serial_type] == 'PORT':
base_path = '{}{}/port'.format(TTY_PATH, ttys_n)
base = read_ttys_node(base_path)
- print("\tseri:{} type:portio base:{} irq:{}".format(ttys, base, irq), file=config)
+ try:
+ b = get_bdf_from_realpath(os.path.join(TTY_PATH, ttys_n, 'device'))
+ bdf = f'{b[0]}:{b[1]}.{b[2]}
+ except AssertionError:
+ bdf = ''
+ if bdf:
+ print("\tseri:{} type:portio base:{} irq:{} bdf:{}".format(ttys, base, irq, bdf), file=config)
+ else:
+ print("\tseri:{} type:portio base:{} irq:{}".format(ttys, base, irq), file=config)
elif ttys_type[serial_type] == 'MMIO':
base_path = '{}{}/iomem_base'.format(TTY_PATH, ttys_n)
base = read_ttys_node(base_path)
--
2.25.1


Junjie Mao
 

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of Zhao,
Yuanyuan
Sent: Monday, October 17, 2022 9:59 AM
To: Mao, Junjie <junjie.mao@...>; acrn-dev@...
Cc: yuanyuan.zhao@...
Subject: [acrn-dev] [PATCH v3] config_tools: board_inspector: parse bdf for ioport serial
controler

Add bdf infomation to ioport serial controler.

v2->v3:
Use 'get_bdf_from_realpath'.

v1->v2:
Parse tty*/device link instead of parse pci device infomation.

Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@...>
Reviewed-by: Junjie Mao <junjie.mao@...>

Some minor comments are embedded below.

---
.../board_inspector/legacy/misc.py | 21 +++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/misc/config_tools/board_inspector/legacy/misc.py
b/misc/config_tools/board_inspector/legacy/misc.py
index e6abb4ab8..7be4e4585 100644
--- a/misc/config_tools/board_inspector/legacy/misc.py
+++ b/misc/config_tools/board_inspector/legacy/misc.py
@@ -3,7 +3,8 @@
# SPDX-License-Identifier: BSD-3-Clause
#

-import parser_lib
+import parser_lib, os
+from extractors.helpers import get_bdf_from_realpath

MEM_PATH = ['/proc/iomem', '/proc/meminfo']
TTY_PATH = '/sys/class/tty/'
@@ -78,6 +79,14 @@ def iomem2bdf(base):

return bdf

+def ioport2bdf(ttys_n):
+ path = os.path.join(TTY_PATH, ttys_n, 'device')
+ link = os.readlink(path).split('/')[-1]
+ bdf = link.lstrip("0000").lstrip(":")
+ if not is_bdf_format(bdf):
+ bdf = ''
+ return bdf
+
You can remove this function now.

def dump_ttys_info(ttys_list, config):
for ttys in ttys_list:
ttys_n = ttys.split('/')[-1]
@@ -91,7 +100,15 @@ def dump_ttys_info(ttys_list, config):
if ttys_type[serial_type] == 'PORT':
base_path = '{}{}/port'.format(TTY_PATH, ttys_n)
base = read_ttys_node(base_path)
- print("\tseri:{} type:portio base:{} irq:{}".format(ttys, base, irq),
file=config)
+ try:
+ b = get_bdf_from_realpath(os.path.join(TTY_PATH, ttys_n, 'device'))
+ bdf = f'{b[0]}:{b[1]}.{b[2]}
+ except AssertionError:
Capturing AssertionError (which is typically used to capture internal errors). You can contact Yu-chu (CC'ed) to use a separate exception class to raise such error.

---
Best Regards
Junjie Mao

+ bdf = ''
+ if bdf:
+ print("\tseri:{} type:portio base:{} irq:{} bdf:{}".format(ttys, base,
irq, bdf), file=config)
+ else:
+ print("\tseri:{} type:portio base:{} irq:{}".format(ttys, base, irq),
file=config)
elif ttys_type[serial_type] == 'MMIO':
base_path = '{}{}/iomem_base'.format(TTY_PATH, ttys_n)
base = read_ttys_node(base_path)
--
2.25.1