From 8ca8d7665d671e10d72b8fcb4d69121d75f7906e Mon Sep 17 00:00:00 2001 From: Eric Biederman Date: Tue, 22 Apr 2003 19:02:15 +0000 Subject: - Initial checkin of the freebios2 tree git-svn-id: svn://svn.coreboot.org/coreboot/trunk@784 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- src/devices/device_util.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/devices/device_util.c (limited to 'src/devices/device_util.c') diff --git a/src/devices/device_util.c b/src/devices/device_util.c new file mode 100644 index 0000000000..fdaa20d966 --- /dev/null +++ b/src/devices/device_util.c @@ -0,0 +1,56 @@ +#include +#include + +/** + * Given a bus and a devfn number, find the device structure + * @param bus The bus number + * @param devfn a device/function number + * @return pointer to the device structure + */ +struct device *dev_find_slot(unsigned int bus, unsigned int devfn) +{ + struct device *dev; + + for (dev = all_devices; dev; dev = dev->next) + if (dev->bus->secondary == bus && dev->devfn == devfn) + break; + return dev; +} + +/** Find a device of a given vendor and type + * @param vendor Vendor ID (e.g. 0x8086 for Intel) + * @param device Device ID + * @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(unsigned int vendor, unsigned int device, struct device *from) +{ + if (!from) + from = all_devices; + else + from = from->next; + while (from && (from->vendor != vendor || from->device != device)) + from = from->next; + return from; +} + +/** Find a device of a given class + * @param class Class of the device + * @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_class(unsigned int class, struct device *from) +{ + if (!from) + from = all_devices; + else + from = from->next; + while (from && from->class != class) + from = from->next; + return from; +} + -- cgit v1.2.3