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 <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2022-03-25 23:26:09 +08:00 committed by acrnsi-robot
parent 95c2849cee
commit 8c46c2306f
2 changed files with 26 additions and 12 deletions

View File

@ -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)))
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)
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")
devices = board_etree.xpath("//device[vendor and class]")
for device in devices:
lookup_pci_device(device, ids)
buses = board_etree.xpath("//bus")
buses = board_etree.xpath("//bus[@type = 'pci']")
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.")
def extract(args, board_etree):
lookup_pci_devices(board_etree)

View File

@ -222,7 +222,8 @@ CLOSID 0 and the second is mapped to virtual CLOSID 1, etc.</xs:documentation>
<xs:complexType name="PCIDevsConfiguration">
<xs:sequence>
<xs:element name="pci_dev" type="xs:string" minOccurs="0" maxOccurs="unbounded">
<xs:annotation acrn:title="PCI device assignment">
<xs:annotation acrn:title="PCI device assignment"
acrn:options="//device[class]/@description" acrn:options-sorted-by="lambda s: (s.split(' ', maxsplit=1)[-1].split(':')[0], s.split(' ')[0])">
<xs:documentation>Select the PCI devices you want to assign to this virtual machine.</xs:documentation>
</xs:annotation>
</xs:element>