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


Zhao, Yuanyuan
 

Add bdf infomation to ioport serial controler.

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

Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@...>
---
misc/config_tools/board_inspector/legacy/misc.py | 16 ++++++++++++++--
1 file changed, 14 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..127f31a40 100644
--- a/misc/config_tools/board_inspector/legacy/misc.py
+++ b/misc/config_tools/board_inspector/legacy/misc.py
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#

-import parser_lib
+import parser_lib, os

MEM_PATH = ['/proc/iomem', '/proc/meminfo']
TTY_PATH = '/sys/class/tty/'
@@ -78,6 +78,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 +99,11 @@ 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)
+ bdf = ioport2bdf(ttys_n)
+ 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: Yuanyuan Zhao <yuanyuan.zhao@...>
Sent: Tuesday, October 11, 2022 11:40 AM
To: Mao, Junjie <junjie.mao@...>; acrn-dev@...
Cc: yuanyuan.zhao@...
Subject: [PATCH v2] config_tools: board_inspector: parse bdf for ioport serial controler

Add bdf infomation to ioport serial controler.

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

Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@...>
---
misc/config_tools/board_inspector/legacy/misc.py | 16 ++++++++++++++--
1 file changed, 14 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..127f31a40 100644
--- a/misc/config_tools/board_inspector/legacy/misc.py
+++ b/misc/config_tools/board_inspector/legacy/misc.py
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#

-import parser_lib
+import parser_lib, os

MEM_PATH = ['/proc/iomem', '/proc/meminfo']
TTY_PATH = '/sys/class/tty/'
@@ -78,6 +78,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 may use the `get_bdf_from_realpath` in Yu-chu's series for converting a path to sysfs device node to BDF.

Also, since this method has nothing to do with whether the serial port is using I/O ports or MMIO, also replace iomem2bdf with that method and rewrite its name to be more general, e.g., `ttys_to_bdf`.

+
def dump_ttys_info(ttys_list, config):
for ttys in ttys_list:
ttys_n = ttys.split('/')[-1]
@@ -91,7 +99,11 @@ 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)
+ bdf = ioport2bdf(ttys_n)
+ 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


Zhao, Yuanyuan
 

On 2022/10/11 15:07, Mao, Junjie wrote:
-----Original Message-----
From: Yuanyuan Zhao <yuanyuan.zhao@...>
Sent: Tuesday, October 11, 2022 11:40 AM
To: Mao, Junjie <junjie.mao@...>; acrn-dev@...
Cc: yuanyuan.zhao@...
Subject: [PATCH v2] config_tools: board_inspector: parse bdf for ioport serial controler

Add bdf infomation to ioport serial controler.

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

Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@...>
---
misc/config_tools/board_inspector/legacy/misc.py | 16 ++++++++++++++--
1 file changed, 14 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..127f31a40 100644
--- a/misc/config_tools/board_inspector/legacy/misc.py
+++ b/misc/config_tools/board_inspector/legacy/misc.py
@@ -3,7 +3,7 @@
# SPDX-License-Identifier: BSD-3-Clause
#

-import parser_lib
+import parser_lib, os

MEM_PATH = ['/proc/iomem', '/proc/meminfo']
TTY_PATH = '/sys/class/tty/'
@@ -78,6 +78,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 may use the `get_bdf_from_realpath` in Yu-chu's series for converting a path to sysfs device node to BDF.
OK.
Also, since this method has nothing to do with whether the serial port is using I/O ports or MMIO, also replace iomem2bdf with that method and rewrite its name to be more general, e.g., `ttys_to_bdf`.
If the serial port is MMIO, the 'device' link do not have dbf infomation. So board inspector should get it separately.

+
def dump_ttys_info(ttys_list, config):
for ttys in ttys_list:
ttys_n = ttys.split('/')[-1]
@@ -91,7 +99,11 @@ 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)
+ bdf = ioport2bdf(ttys_n)
+ 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