From 8c46c2306f3c120857f13dfe6782bad707abf3a7 Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Fri, 25 Mar 2022 23:26:09 +0800 Subject: [PATCH] config_tools: format BDF in descriptions of PCI devices This patch adds the BDF (in the format BBBB:DD.F) of each PCI device into its description, which helps the configurator to fetch all available PCI devices via XPATH rather than text manipulating functions. Tracked-On: #6690 Signed-off-by: Junjie Mao --- .../board_inspector/extractors/80-lookup.py | 35 +++++++++++++------ misc/config_tools/schema/VMtypes.xsd | 3 +- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/misc/config_tools/board_inspector/extractors/80-lookup.py b/misc/config_tools/board_inspector/extractors/80-lookup.py index ec4c3bf0e..f4dd04e46 100644 --- a/misc/config_tools/board_inspector/extractors/80-lookup.py +++ b/misc/config_tools/board_inspector/extractors/80-lookup.py @@ -98,10 +98,22 @@ def lookup_pci_device(element, ids): class_code = get_node(element, "class/text()") args = [vendor_id, device_id, subsystem_vendor_id, subsystem_device_id, class_code] - desc = ids.lookup(*list(map(lambda x: int(x, base=16) if x else None, args))) - if desc: - element.set("description", desc) + desc = ids.lookup(*list(map(lambda x: int(x, base=16) if x else None, args))) if ids else "" + + bus_id = int(get_node(element, "ancestor-or-self::bus[1]/@address"), base=16) + dev_func_id = int(get_node(element, "./@address"), base=16) + dev_id = dev_func_id >> 16 + func_id = dev_func_id & 0xf + + if element.tag == "bus": + if desc: + element.set("description", desc) + else: + if desc: + element.set("description", f"{bus_id:02x}:{dev_id:02x}.{func_id} {desc}") + else: + element.set("description", f"{bus_id:02x}:{dev_id:02x}.{func_id}") def lookup_pci_devices(board_etree): # Lookup names of PCI devices from pci.ids if possible @@ -114,16 +126,17 @@ def lookup_pci_devices(board_etree): opener = gzip.open if pci_id_path.endswith(".gz") else open with opener(pci_id_path, "r") as f: ids = PCI_IDs(f) - - devices = board_etree.xpath("//device") - for device in devices: - lookup_pci_device(device, ids) - - buses = board_etree.xpath("//bus") - for bus in buses: - lookup_pci_device(bus, ids) else: logging.info(f"Cannot find pci.ids under /usr/share. PCI device names will not be available.") + ids = None + + devices = board_etree.xpath("//device[vendor and class]") + for device in devices: + lookup_pci_device(device, ids) + + buses = board_etree.xpath("//bus[@type = 'pci']") + for bus in buses: + lookup_pci_device(bus, ids) def extract(args, board_etree): lookup_pci_devices(board_etree) diff --git a/misc/config_tools/schema/VMtypes.xsd b/misc/config_tools/schema/VMtypes.xsd index 380e966de..16d83d74d 100644 --- a/misc/config_tools/schema/VMtypes.xsd +++ b/misc/config_tools/schema/VMtypes.xsd @@ -222,7 +222,8 @@ CLOSID 0 and the second is mapped to virtual CLOSID 1, etc. - + Select the PCI devices you want to assign to this virtual machine.