Attention is currently required from: Arthur Heymans. Hello Arthur Heymans,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/62896
to review the following change.
Change subject: device/device_const.c: Write loop with topology ......................................................................
device/device_const.c: Write loop with topology
A side benefit is that more than one domain gets probed.
Change-Id: I6f35ab1efc7c293f129ec16d45b155275c2a8b52 Signed-off-by: Arthur Heymans arthur@aheymans.xyz --- M src/device/device_const.c 1 file changed, 18 insertions(+), 13 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/62896/1
diff --git a/src/device/device_const.c b/src/device/device_const.c index c629f05..dc97ab7 100644 --- a/src/device/device_const.c +++ b/src/device/device_const.c @@ -218,21 +218,26 @@ return find_dev_path(parent, &path); }
+static const struct bus *find_pci_bus(const struct device *dev, unsigned int bus) +{ + const struct device *d; + for (d = dev; d != NULL; d = d->sibling) { + if (d->path.type == DEVICE_PATH_PCI && d->bus->secondary == bus) + return d->bus; + if (d->link_list && d->link_list->children) { + const struct bus *child_bus = find_pci_bus(d->link_list->children, bus); + if (child_bus) + return child_bus; + } + } + return NULL; +} + DEVTREE_CONST struct device *pcidev_path_on_bus(unsigned int bus, pci_devfn_t devfn) { - DEVTREE_CONST struct bus *parent = pci_root_bus(); - DEVTREE_CONST struct device *dev = parent->children; - - /* FIXME: Write the loop with topology links. */ - while (dev) { - if (dev->path.type != DEVICE_PATH_PCI) { - dev = dev->next; - continue; - } - if (dev->bus->secondary == bus) - return pcidev_path_behind(dev->bus, devfn); - dev = dev->next; - } + const struct bus *pci_bus = find_pci_bus(dev_find_path(NULL, DEVICE_PATH_DOMAIN), bus); + if (pci_bus) + return pcidev_path_behind(pci_bus, devfn); return NULL; }