From e36b615fe1dc7307d38bdc0da381bcabb97b097b Mon Sep 17 00:00:00 2001 From: Calvin Zhang Date: Fri, 6 May 2022 15:19:15 +0800 Subject: [PATCH] misc: configurator: Config usb mediator devices in dropdown list Support detecting connected usb devices in board_inspector and list them in the usb mediator configuration menu. Tracked-On: #7424 Signed-off-by: Calvin Zhang --- .../board_inspector/extractors/95-usb.py | 33 +++++++++++++++++++ .../launch_config/launch_cfg_gen.py | 5 +-- misc/config_tools/schema/VMtypes.xsd | 12 +++++++ misc/config_tools/schema/config.xsd | 10 +----- 4 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 misc/config_tools/board_inspector/extractors/95-usb.py diff --git a/misc/config_tools/board_inspector/extractors/95-usb.py b/misc/config_tools/board_inspector/extractors/95-usb.py new file mode 100644 index 000000000..185ec8858 --- /dev/null +++ b/misc/config_tools/board_inspector/extractors/95-usb.py @@ -0,0 +1,33 @@ +# Copyright (C) 2022 Intel Corporation. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +import os, re + +from extractors.helpers import add_child, get_node + +USB_DEVICES_PATH = "/sys/bus/usb/devices" +USB_DEVICES_REGEX = r"^\d-\d$" # only devices connecting to root hub + +def extract(args, board_etree): + dev_regex = re.compile(USB_DEVICES_REGEX) + for dev in os.listdir(USB_DEVICES_PATH): + m = dev_regex.match(dev) + if m: + d = m.group(0) + devpath = os.path.join(USB_DEVICES_PATH, d) + with open(os.path.join(devpath, 'devnum'), 'r') as f: + devnum = f.read().strip() + with open(os.path.join(devpath, 'busnum'), 'r') as f: + busnum = f.read().strip() + cmd_out = os.popen('lsusb -s {b}:{d}'.format(b=busnum, d=devnum)).read() + desc = cmd_out.split(':', maxsplit=1)[1].strip('\n') + + with open(devpath + '/port/firmware_node/path') as f: + acpi_path = f.read().strip() + usb_port_node = get_node(board_etree, f"//device[acpi_object='{acpi_path}']") + if usb_port_node is not None: + add_child(usb_port_node, "usb_device", location=d, + description=d + desc) + diff --git a/misc/config_tools/launch_config/launch_cfg_gen.py b/misc/config_tools/launch_config/launch_cfg_gen.py index 302918e06..a168182e6 100755 --- a/misc/config_tools/launch_config/launch_cfg_gen.py +++ b/misc/config_tools/launch_config/launch_cfg_gen.py @@ -267,8 +267,9 @@ def generate_for_one_vm(board_etree, hv_scenario_etree, vm_scenario_etree, vm_id script.add_virtual_device("uart", options="vuart_idx:{idx}") # Mediated PCI devices, including virtio - for usb_xhci in eval_xpath_all(vm_scenario_etree, ".//usb_xhci[text() != '']/text()"): - script.add_virtual_device("xhci", options=usb_xhci) + for usb_xhci in eval_xpath_all(vm_scenario_etree, ".//usb_xhci/usb_dev[text() != '']/text()"): + bus_port = usb_xhci.split(' ')[0] + script.add_virtual_device("xhci", options=bus_port) for virtio_input_etree in eval_xpath_all(vm_scenario_etree, ".//virtio_devices/input"): backend_device_file = eval_xpath(virtio_input_etree, "./backend_device_file[text() != '']/text()") diff --git a/misc/config_tools/schema/VMtypes.xsd b/misc/config_tools/schema/VMtypes.xsd index f98c068d4..0701f00db 100644 --- a/misc/config_tools/schema/VMtypes.xsd +++ b/misc/config_tools/schema/VMtypes.xsd @@ -284,6 +284,18 @@ The size is a subset of the VM's total memory size specified on the Basic tab. + + + + + Select the USB devices you want to assign to this virtual machine. + + + + + + A string with value: ``Kernel based (Virtual Host)`` or ``User space based (VBSU)``. diff --git a/misc/config_tools/schema/config.xsd b/misc/config_tools/schema/config.xsd index 68cc575c6..2669b2a73 100644 --- a/misc/config_tools/schema/config.xsd +++ b/misc/config_tools/schema/config.xsd @@ -433,18 +433,10 @@ argument and memory. Enable the ACRN Device Model to emulate COM1 as a User VM stdio I/O. Hypervisor global emulation will take priority over this VM setting. - + Select the USB physical bus and port number that will be emulated by the ACRN Device Model for this VM. USB 3.0, 2.0, and 1.0 are supported. - - - Input format: ``bus#-port#[:bus#-port#: ...]``, for example, ``1-2:2-4``. - - - - -