diff options
-rw-r--r-- | src/device/device_const.c | 27 | ||||
-rw-r--r-- | src/include/device/device.h | 4 |
2 files changed, 31 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) { diff --git a/src/include/device/device.h b/src/include/device/device.h index 317785429d..b53b64a329 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -207,6 +207,10 @@ void run_bios(struct device *dev, unsigned long addr); DEVTREE_CONST struct device *find_dev_path( const struct bus *parent, const struct device_path *path); +DEVTREE_CONST struct device *find_dev_nested_path( + const struct bus *parent, + const struct device_path nested_path[], + size_t nested_path_length); struct device *alloc_find_dev(struct bus *parent, struct device_path *path); struct device *dev_find_device(u16 vendor, u16 device, struct device *from); struct device *dev_find_class(unsigned int class, struct device *from); |