Shuo Liu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/81108?usp=email )
Change subject: device: Add dev_find_device_filter ......................................................................
device: Add dev_find_device_filter
The new utils allows to find devices based on a filter function.
TEST=intel/archercity CRB
Change-Id: Id657830e557389bb776a929ac049af2b9545027d Signed-off-by: Shuo Liu shuo.liu@intel.com --- M src/device/device_util.c M src/include/device/device.h 2 files changed, 24 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/08/81108/1
diff --git a/src/device/device_util.c b/src/device/device_util.c index b5d0d98..f5d7934 100644 --- a/src/device/device_util.c +++ b/src/device/device_util.c @@ -55,6 +55,28 @@ }
/** + * Find a device by a filter function + * + * @param filter Pointer to a filter function. + * @param from Pointer to the device structure, used as a starting point in + * the linked list of all_devices, which can be 0 to start at the + * head of the list (i.e. all_devices). + * @return Pointer to the device struct. + */ +struct device *dev_find_device_filter(dev_filter_t filter, struct device *from) +{ + if (!from) + from = all_devices; + else + from = from->next; + + while (from && (!filter(from))) + from = from->next; + + return from; +} + +/** * Find a device of a given class. * * @param class Class of the device. diff --git a/src/include/device/device.h b/src/include/device/device.h index 25f730b..35f648f 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -210,6 +210,8 @@ 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); +typedef int (*dev_filter_t)(struct device *dev); +struct device *dev_find_device_filter(dev_filter_t filter, struct device *from); struct device *dev_find_class(unsigned int class, struct device *from); DEVTREE_CONST struct device *dev_find_path( DEVTREE_CONST struct device *prev_match,