From fe204fe902f5d08dbf07e0f9686e4315c67292ea Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Tue, 6 Dec 2016 18:06:30 +0530 Subject: src/device: Get device structure by path type Add helper function to find a device by path type in the device tree. Change-Id: I8846f63bd2488788ea3c7ab5154e7cf431a252bc Credits-to: Aaron Durbin Signed-off-by: Subrata Banik Signed-off-by: Dhaval V Sharma Reviewed-on: https://review.coreboot.org/17731 Reviewed-by: Aaron Durbin Tested-by: build bot (Jenkins) --- src/device/device_util.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/device') diff --git a/src/device/device_util.c b/src/device/device_util.c index 157f7b7443..cd33aac263 100644 --- a/src/device/device_util.c +++ b/src/device/device_util.c @@ -130,6 +130,31 @@ device_t dev_find_lapic(unsigned apic_id) return result; } +/** + * Given a Device Path Type, find the device structure. + * + * @param prev_match The previously matched device instance. + * @param path_type The Device Path Type. + * @return Pointer to the device structure (if found), 0 otherwise. + */ +device_t dev_find_path(device_t prev_match, enum device_path_type path_type) +{ + device_t dev, result = NULL; + + if (prev_match == NULL) + prev_match = all_devices; + else + prev_match = prev_match->next; + + for (dev = prev_match; dev; dev = dev->next) { + if (dev->path.type == path_type) { + result = dev; + break; + } + } + return result; +} + /** * Find a device of a given vendor and type. * -- cgit v1.2.3