diff options
author | Rob Barnes <robbarnes@google.com> | 2020-07-23 08:25:42 -0600 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2020-07-28 19:28:22 +0000 |
commit | a223e65db2e9d4c82bb8aac29281500b8e645a97 (patch) | |
tree | 8222b0e26679d67f73085fdd247771ac1c4aeba5 /src/device/device_const.c | |
parent | e7e6c4e1d78c78e4bf5869d2329949bdaf80ad56 (diff) | |
download | coreboot-a223e65db2e9d4c82bb8aac29281500b8e645a97.tar.xz |
device: Add find_dev_nested_path helper function
Add find_dev_nested_path helper function to simplify finding deeply
nested devices.
BUG=b:157580724
TEST=Find bluetooth device on dalboz
Change-Id: I48fa5fcad0030fb6dcea97b9fc76e1d3d3f9b28f
Signed-off-by: Rob Barnes <robbarnes@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/43776
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Raul Rangel <rrangel@chromium.org>
Diffstat (limited to 'src/device/device_const.c')
-rw-r--r-- | src/device/device_const.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/device/device_const.c b/src/device/device_const.c index 12d5386d22..79f025da97 100644 --- a/src/device/device_const.c +++ b/src/device/device_const.c @@ -196,6 +196,33 @@ DEVTREE_CONST struct device *find_dev_path( return child; } +/** + * Find the device structure given an array of nested device paths, + * + * @param parent The parent bus to start the search on. + * @param nested_path An array of relative paths from the parent bus to the target device. + * @param nested_path_length Number of path elements in nested_path array. + * @return Pointer to a device structure for the device at nested path + * or 0/NULL if no device is found. + */ +DEVTREE_CONST struct device *find_dev_nested_path( + const struct bus *parent, const struct device_path nested_path[], + size_t nested_path_length) +{ + DEVTREE_CONST struct device *child; + + if (!parent || !nested_path || !nested_path_length) + return NULL; + + child = find_dev_path(parent, nested_path); + + /* Terminate recursion at end of nested path or child not found */ + if (nested_path_length == 1 || !child) + return child; + + return find_dev_nested_path(child->link_list, nested_path + 1, nested_path_length - 1); +} + DEVTREE_CONST struct device *pcidev_path_behind( const struct bus *parent, pci_devfn_t devfn) { |