mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-02 00:08:43 +00:00
config_tools: extract virtio device input basic information
Add a new extractor 70-device-classes.py which extracts virtio device input basic information such as: name and phys. An example: <device_classes> <inputs> <input> <name>Power Button</name> <phys>LNXPWRBN/button/input0</phys> </input> <inputs> </device_classes> Tracked-On: #6690 Signed-off-by: Kunhui-Li <kunhuix.li@intel.com>
This commit is contained in:
parent
8c46c2306f
commit
e47765d8e5
@ -102,6 +102,7 @@ def main(board_name, board_xml, args):
|
||||
root_node.append(lxml.etree.Element("memory"))
|
||||
root_node.append(lxml.etree.Element("ioapics"))
|
||||
root_node.append(lxml.etree.Element("devices"))
|
||||
root_node.append(lxml.etree.Element("device-classes"))
|
||||
|
||||
extractors_path = os.path.join(script_dir, "extractors")
|
||||
extractors = [f for f in os.listdir(extractors_path) if f[:2].isdigit()]
|
||||
|
@ -0,0 +1,42 @@
|
||||
# Copyright (C) 2022 Intel Corporation.
|
||||
#
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
|
||||
import re, os
|
||||
import logging
|
||||
from extractors.helpers import add_child, get_node
|
||||
|
||||
SYS_DEVICES_CLASS_PATH = "/sys/class/input/"
|
||||
|
||||
def get_input_ids():
|
||||
input_ids = list()
|
||||
root_regex = re.compile("input([0-9]+)")
|
||||
for root in filter(lambda x: x.startswith("input"), os.listdir(SYS_DEVICES_CLASS_PATH)):
|
||||
m = root_regex.match(root)
|
||||
if m:
|
||||
input_ids.append(int(m.group(1)))
|
||||
return sorted(input_ids)
|
||||
|
||||
def extract_topology(device_classes_node):
|
||||
inputs_node = add_child(device_classes_node, "inputs", None)
|
||||
input_ids = get_input_ids()
|
||||
for id in input_ids:
|
||||
input_node = add_child(inputs_node, "input", None)
|
||||
try:
|
||||
with open("/sys/class/input/input{}/name".format(id), "r") as f:
|
||||
res = f.read().strip()
|
||||
add_child(input_node, "name", res)
|
||||
except Exception as e:
|
||||
logging.warning(f"Failed to read the data of /sys/class/input/input{id}/name: {e}")
|
||||
|
||||
try:
|
||||
with open("/sys/class/input/input{}/phys".format(id), "r") as f:
|
||||
res = f.read().strip()
|
||||
add_child(input_node, "phys", res)
|
||||
except Exception as e:
|
||||
logging.warning(f"Failed to read the data of /sys/class/input/input{id}/phys: {e}")
|
||||
|
||||
def extract(args, board_etree):
|
||||
device_classes_node = get_node(board_etree, "//device-classes")
|
||||
extract_topology(device_classes_node)
|
Loading…
Reference in New Issue
Block a user