summaryrefslogtreecommitdiff
path: root/src/devices/device_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/device_util.c')
-rw-r--r--src/devices/device_util.c56
1 files changed, 56 insertions, 0 deletions
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 <console/console.h>
+#include <device.h>
+
+/**
+ * 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;
+}
+