diff options
-rw-r--r-- | src/device/device_const.c | 26 | ||||
-rw-r--r-- | src/include/device/device.h | 5 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/device/device_const.c b/src/device/device_const.c index 90b68679e9..ec128e877d 100644 --- a/src/device/device_const.c +++ b/src/device/device_const.c @@ -22,6 +22,7 @@ #include <device/device.h> #include <device/path.h> #include <device/pci.h> +#include <device/pci_def.h> #include <device/resource.h> /** Linked list of ALL devices */ @@ -172,6 +173,31 @@ DEVTREE_CONST struct device *find_dev_path( return child; } +DEVTREE_CONST struct device *pcidev_path_behind( + const struct bus *parent, pci_devfn_t devfn) +{ + const struct device_path path = { + .type = DEVICE_PATH_PCI, + .pci.devfn = devfn, + }; + return find_dev_path(parent, &path); +} + +DEVTREE_CONST struct device *pcidev_path_on_root(pci_devfn_t devfn) +{ + DEVTREE_CONST struct device *pci_domain; + + pci_domain = dev_find_path(NULL, DEVICE_PATH_DOMAIN); + if (!pci_domain) + return NULL; + return pcidev_path_behind(pci_domain->link_list, devfn); +} + +DEVTREE_CONST struct device *pcidev_on_root(uint8_t dev, uint8_t fn) +{ + return pcidev_path_on_root(PCI_DEVFN(dev, fn)); +} + /** * Given an SMBus bus and a device number, find the device structure. * diff --git a/src/include/device/device.h b/src/include/device/device.h index 5e539ea339..540b7e3899 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -276,6 +276,11 @@ DEVTREE_CONST struct device *dev_find_slot_pnp(u16 port, u16 device); DEVTREE_CONST struct device *dev_bus_each_child(const struct bus *parent, DEVTREE_CONST struct device *prev_child); +DEVTREE_CONST struct device *pcidev_path_behind(const struct bus *parent, + pci_devfn_t devfn); +DEVTREE_CONST struct device *pcidev_path_on_root(pci_devfn_t devfn); +DEVTREE_CONST struct device *pcidev_on_root(uint8_t dev, uint8_t fn); + void scan_smbus(struct device *bus); void scan_generic_bus(struct device *bus); void scan_static_bus(struct device *bus); |