device: Move dev_find_path() to device_const.c

Make it available early and use it in dev_find_next_pci_device().

Change-Id: I1d0ad07f37ea79dae2b9a592fcccba5e03fd86d5
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/26294
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
This commit is contained in:
Nico Huber 2018-05-15 14:13:32 +02:00 committed by Kyösti Mälkki
parent 81ec9c0500
commit f6a4344c5b
3 changed files with 31 additions and 42 deletions

View File

@ -50,6 +50,33 @@ DEVTREE_CONST struct device *dev_find_slot(unsigned int bus,
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.
*/
DEVTREE_CONST struct device *dev_find_path(
DEVTREE_CONST struct device *prev_match,
enum device_path_type path_type)
{
DEVTREE_CONST struct device *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;
}
/**
* Given a device pointer, find the next PCI device.
*
@ -59,19 +86,7 @@ DEVTREE_CONST struct device *dev_find_slot(unsigned int bus,
DEVTREE_CONST struct device *dev_find_next_pci_device(
DEVTREE_CONST struct device *previous_dev)
{
DEVTREE_CONST struct device *dev, *result;
if (previous_dev == NULL)
previous_dev = all_devices;
result = 0;
for (dev = previous_dev->next; dev; dev = dev->next) {
if (dev->path.type == DEVICE_PATH_PCI) {
result = dev;
break;
}
}
return result;
return dev_find_path(previous_dev, DEVICE_PATH_PCI);
}
/**

View File

@ -64,33 +64,6 @@ struct device *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.
*/
struct device *dev_find_path(struct device *prev_match,
enum device_path_type path_type)
{
struct device *dev;
struct device *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.
*

View File

@ -200,7 +200,8 @@ struct device *find_dev_path(struct bus *parent, struct device_path *path);
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);
struct device *dev_find_path(struct device *prev_match,
DEVTREE_CONST struct device *dev_find_path(
DEVTREE_CONST struct device *prev_match,
enum device_path_type path_type);
struct device *dev_find_lapic(unsigned int apic_id);
int dev_count_cpu(void);