- Small step forward Linux boots and almost works...
[coreboot.git] / src / devices / device_util.c
1 #include <console/console.h>
2 #include <device/device.h>
3
4 /**
5  * Given a bus and a devfn number, find the device structure
6  * @param bus The bus number
7  * @param devfn a device/function number
8  * @return pointer to the device structure
9  */
10 struct device *dev_find_slot(unsigned int bus, unsigned int devfn)
11 {
12         struct device *dev;
13
14         for (dev = all_devices; dev; dev = dev->next)
15                 if (dev->bus->secondary == bus && dev->devfn == devfn)
16                         break;
17         return dev;
18 }
19
20 /** Find a device of a given vendor and type
21  * @param vendor Vendor ID (e.g. 0x8086 for Intel)
22  * @param device Device ID
23  * @param from Pointer to the device structure, used as a starting point
24  *        in the linked list of all_devices, which can be 0 to start at the 
25  *        head of the list (i.e. all_devices)
26  * @return Pointer to the device struct 
27  */
28 struct device *dev_find_device(unsigned int vendor, unsigned int device, struct device *from)
29 {
30         if (!from)
31                 from = all_devices;
32         else
33                 from = from->next;
34         while (from && (from->vendor != vendor || from->device != device))
35                 from = from->next;
36         return from;
37 }
38
39 /** Find a device of a given class
40  * @param class Class of the device
41  * @param from Pointer to the device structure, used as a starting point
42  *        in the linked list of all_devices, which can be 0 to start at the 
43  *        head of the list (i.e. all_devices)
44  * @return Pointer to the device struct 
45  */
46 struct device *dev_find_class(unsigned int class, struct device *from)
47 {
48         if (!from)
49                 from = all_devices;
50         else
51                 from = from->next;
52         while (from && from->class != class)
53                 from = from->next;
54         return from;
55 }
56