summaryrefslogtreecommitdiff
path: root/drivers/pci
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2019-12-29 21:19:14 -0700
committerSimon Glass <sjg@chromium.org>2020-01-07 16:02:38 -0700
commit4886287ee4f942aeee2ae0d50281ce21e8c43cf5 (patch)
tree744bacc35e9f321448190a3e50a0b592699e6c59 /drivers/pci
parent3d9acea3d9ae45037ff2fd1e4c2f877f0466ce6a (diff)
pci: Print a warning if the bus is accessed before probing
It is not possible to access a device on a PCI bus that has not yet been probed, since the bus number is not known. Add a warning to catch this error. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/pci-uclass.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 7308f612b6..5be2dfd0bf 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -48,6 +48,19 @@ pci_dev_t dm_pci_get_bdf(struct udevice *dev)
struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
struct udevice *bus = dev->parent;
+ /*
+ * This error indicates that @dev is a device on an unprobed PCI bus.
+ * The bus likely has bus=seq == -1, so the PCI_ADD_BUS() macro below
+ * will produce a bad BDF>
+ *
+ * A common cause of this problem is that this function is called in the
+ * ofdata_to_platdata() method of @dev. Accessing the PCI bus in that
+ * method is not allowed, since it has not yet been probed. To fix this,
+ * move that access to the probe() method of @dev instead.
+ */
+ if (!device_active(bus))
+ log_err("PCI: Device '%s' on unprobed bus '%s'\n", dev->name,
+ bus->name);
return PCI_ADD_BUS(bus->seq, pplat->devfn);
}