summaryrefslogtreecommitdiff
path: root/src/devices/device_util.c
diff options
context:
space:
mode:
authorEric Biederman <ebiederm@xmission.com>2003-09-02 03:36:25 +0000
committerEric Biederman <ebiederm@xmission.com>2003-09-02 03:36:25 +0000
commite9a271e32c53076445ef70da8aec8201c82693ec (patch)
treeaf88f51ba907922157d3b97f9713a07480223372 /src/devices/device_util.c
parentd4c14524f53d8e812cf52b57e16c53d259c44ea0 (diff)
downloadcoreboot-e9a271e32c53076445ef70da8aec8201c82693ec.tar.xz
- Major update of the dynamic device tree so it can handle
* subtractive resources * merging with the static device tree * more device types than just pci - The piece to watch out for is the new enable_resources method that was needed in all of the drivers git-svn-id: svn://svn.coreboot.org/coreboot/trunk@1096 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'src/devices/device_util.c')
-rw-r--r--src/devices/device_util.c83
1 files changed, 81 insertions, 2 deletions
diff --git a/src/devices/device_util.c b/src/devices/device_util.c
index a57ea1f5ae..384a3be8e0 100644
--- a/src/devices/device_util.c
+++ b/src/devices/device_util.c
@@ -1,5 +1,26 @@
#include <console/console.h>
#include <device/device.h>
+#include <device/path.h>
+#include <device/pci.h>
+#include <string.h>
+
+
+/**
+ * See if a device structure already exists and if not allocate it
+ * @param bus The bus to find the device on
+ * @param path The relative path from the bus to the appropriate device
+ * @return pointer a device structure for the device on bus at path
+ */
+device_t alloc_find_dev(struct bus *parent, struct device_path *path)
+{
+ device_t child;
+ for(child = parent->children; child; child = child->sibling) {
+ if (path_eq(path, &child->path)) {
+ return child;
+ }
+ }
+ return alloc_dev(parent, path);
+}
/**
* Given a bus and a devfn number, find the device structure
@@ -11,9 +32,12 @@ 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)
+ for (dev = all_devices; dev; dev = dev->next) {
+ if ((dev->bus->secondary == bus) &&
+ (dev->path.u.pci.devfn == devfn)) {
break;
+ }
+ }
return dev;
}
@@ -54,3 +78,58 @@ struct device *dev_find_class(unsigned int class, struct device *from)
return from;
}
+
+const char *dev_path(device_t dev)
+{
+ static char buffer[DEVICE_PATH_MAX];
+ buffer[0] = '\0';
+ if (!dev) {
+ memcpy(buffer, "<null>", 7);
+ }
+ else {
+ switch(dev->path.type) {
+ case DEVICE_PATH_PCI:
+ sprintf(buffer, "PCI: %02x:%02x.%01x",
+ dev->bus->secondary,
+ PCI_SLOT(dev->path.u.pci.devfn), PCI_FUNC(dev->path.u.pci.devfn));
+ break;
+ case DEVICE_PATH_PNP:
+ sprintf(buffer, "PNP: %04x.%01x",
+ dev->path.u.pnp.port, dev->path.u.pnp.device);
+ break;
+ case DEVICE_PATH_I2C:
+ sprintf(buffer, "I2C: %02x",
+ dev->path.u.i2c.device);
+ break;
+ default:
+ printk_err("Unknown device path type: %d\n", dev->path.type);
+ break;
+ }
+ }
+ return buffer;
+}
+
+int path_eq(struct device_path *path1, struct device_path *path2)
+{
+ int equal = 0;
+ if (path1->type == path2->type) {
+ switch(path1->type) {
+ case DEVICE_PATH_NONE:
+ break;
+ case DEVICE_PATH_PCI:
+ equal = path1->u.pci.devfn == path2->u.pci.devfn;
+ break;
+ case DEVICE_PATH_PNP:
+ equal = (path1->u.pnp.port == path2->u.pnp.port) &&
+ (path1->u.pnp.device == path2->u.pnp.device);
+ break;
+ case DEVICE_PATH_I2C:
+ equal = (path1->u.i2c.device == path2->u.i2c.device);
+ break;
+ default:
+ printk_err("Uknown device type: %d\n", path1->type);
+ break;
+ }
+ }
+ return equal;
+}