diff mbox series

[2/2] kselftest: devices: Add of-fullname-regex property

Message ID 20240613-kselftest-discoverable-probe-mt8195-kci-v1-2-7b396a9b032d@collabora.com
State New
Headers show
Series kselftest: devices: Allow running test on more platforms | expand

Commit Message

NĂ­colas F. R. A. Prado June 13, 2024, 3:14 p.m. UTC
Introduce a new 'of-fullname-regex' property that takes a regular
expression and matches against the OF_FULLNAME property. It allows
matching controllers that don't have a unique DT address across sibling
controllers, and thus dt-mmio can't be used.

One particular example of where this is needed is on MT8195 which has
multiple USB controllers described by two level deep nodes and using the
ranges property:

    ssusb2: usb@112a1000 {
        reg = <0 0x112a1000 0 0x2dff>, <0 0x112a3e00 0 0x0100>;
        ranges = <0 0 0 0x112a0000 0 0x3f00>;
        xhci2: usb@0 {

Signed-off-by: NĂ­colas F. R. A. Prado <nfraprado@collabora.com>
---
 .../selftests/devices/boards/google,spherion.yaml  |  4 ++++
 .../selftests/devices/test_discoverable_devices.py | 24 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/devices/boards/google,spherion.yaml b/tools/testing/selftests/devices/boards/google,spherion.yaml
index 17157ecd8c14..3ea843324797 100644
--- a/tools/testing/selftests/devices/boards/google,spherion.yaml
+++ b/tools/testing/selftests/devices/boards/google,spherion.yaml
@@ -11,6 +11,10 @@ 
 # this, several optional keys can be used:
 # - dt-mmio: identify the MMIO address of the controller as defined in the
 #   Devicetree.
+# - of-fullname-regex: regular expression to match against the OF_FULLNAME
+#   property. Useful when the controller's address is not unique across other
+#   sibling controllers. In this case, dt-mmio can't be used, and this property
+#   allows the matching to include parent nodes as well to make it unique.
 # - usb-version: for USB controllers to differentiate between USB3 and USB2
 #   buses sharing the same controller.
 # - acpi-uid: _UID property of the controller as supplied by the ACPI. Useful to
diff --git a/tools/testing/selftests/devices/test_discoverable_devices.py b/tools/testing/selftests/devices/test_discoverable_devices.py
index 19f28ea774f4..8f2200540a1f 100755
--- a/tools/testing/selftests/devices/test_discoverable_devices.py
+++ b/tools/testing/selftests/devices/test_discoverable_devices.py
@@ -64,6 +64,22 @@  def get_dt_mmio(sysfs_dev_dir):
         sysfs_dev_dir = os.path.dirname(sysfs_dev_dir)
 
 
+def get_of_fullname(sysfs_dev_dir):
+    re_of_fullname = re.compile("OF_FULLNAME=(.*)")
+    of_full_name = None
+
+    # PCI controllers' sysfs don't have an of_node, so have to read it from the
+    # parent
+    while not of_full_name:
+        try:
+            with open(os.path.join(sysfs_dev_dir, "uevent")) as f:
+                of_fullname = re_of_fullname.search(f.read()).group(1)
+                return of_fullname
+        except:
+            pass
+        sysfs_dev_dir = os.path.dirname(sysfs_dev_dir)
+
+
 def get_acpi_uid(sysfs_dev_dir):
     with open(os.path.join(sysfs_dev_dir, "firmware_node", "uid")) as f:
         return f.read()
@@ -97,6 +113,11 @@  def find_controller_in_sysfs(controller, parent_sysfs=None):
             if str(controller["dt-mmio"]) != get_dt_mmio(c):
                 continue
 
+        if controller.get("of-fullname-regex"):
+            re_of_fullname = re.compile(str(controller["of-fullname-regex"]))
+            if not re_of_fullname.match(get_of_fullname(c)):
+                continue
+
         if controller.get("usb-version"):
             if controller["usb-version"] != get_usb_version(c):
                 continue
@@ -195,6 +216,9 @@  def generate_pathname(device):
     if device.get("dt-mmio"):
         pathname += "@" + str(device["dt-mmio"])
 
+    if device.get("of-fullname-regex"):
+        pathname += "-" + str(device["of-fullname-regex"])
+
     if device.get("name"):
         pathname = pathname + "/" + device["name"]