]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
dm: pci: Add a function to get the BDF for a device
authorSimon Glass <sjg@chromium.org>
Mon, 6 Jul 2015 22:47:46 +0000 (16:47 -0600)
committerLothar Waßmann <LW@KARO-electronics.de>
Wed, 9 Sep 2015 11:48:58 +0000 (13:48 +0200)
It is useful to be able to find the full PCI address (bus, device and
function) for a PCI device. Add a function to provide this.

Adjust the existing code to use this.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/pci/pci-uclass.c
drivers/pci/pci_compat.c
include/pci.h

index 41daa0d6eba4fa1f0a5a72cb359f57bb862b10f9..3be76c99ee471646dc5307164c6817d69563f793 100644 (file)
@@ -30,6 +30,14 @@ struct pci_controller *pci_bus_to_hose(int busnum)
        return dev_get_uclass_priv(bus);
 }
 
+pci_dev_t pci_get_bdf(struct udevice *dev)
+{
+       struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
+       struct udevice *bus = dev->parent;
+
+       return PCI_ADD_BUS(bus->seq, pplat->devfn);
+}
+
 /**
  * pci_get_bus_max() - returns the bus number of the last active bus
  *
@@ -295,19 +303,14 @@ int pci_auto_config_devices(struct udevice *bus)
        for (ret = device_find_first_child(bus, &dev);
             !ret && dev;
             ret = device_find_next_child(&dev)) {
-               struct pci_child_platdata *pplat;
                struct pci_controller *ctlr_hose;
-
-               pplat = dev_get_parent_platdata(dev);
                unsigned int max_bus;
-               pci_dev_t bdf;
 
-               bdf = PCI_ADD_BUS(bus->seq, pplat->devfn);
                debug("%s: device %s\n", __func__, dev->name);
 
                /* The root controller has the region information */
                ctlr_hose = hose->ctlr->uclass_priv;
-               max_bus = pciauto_config_device(ctlr_hose, bdf);
+               max_bus = pciauto_config_device(ctlr_hose, pci_get_bdf(dev));
                sub_bus = max(sub_bus, max_bus);
        }
        debug("%s: done\n", __func__);
index d6938c198f70a79b1d8662209df128c4eaa108af..05c35105ab421568e4441c2f8f5d5edccefc5d80 100644 (file)
@@ -31,13 +31,9 @@ PCI_HOSE_OP(write, dword, 32, u32)
 
 pci_dev_t pci_find_devices(struct pci_device_id *ids, int index)
 {
-       struct pci_child_platdata *pplat;
-       struct udevice *bus, *dev;
+       struct udevice *dev;
 
        if (pci_find_device_id(ids, index, &dev))
                return -1;
-       bus = dev->parent;
-       pplat = dev_get_parent_platdata(dev);
-
-       return PCI_ADD_BUS(bus->seq, pplat->devfn);
+       return pci_get_bdf(dev);
 }
index 021928f534d42de333ee3800543312fc0ec43817..94bca9751248d13fae0df6a9060751c0483ae9e2 100644 (file)
@@ -807,6 +807,14 @@ struct dm_pci_ops {
 /* Get access to a PCI bus' operations */
 #define pci_get_ops(dev)       ((struct dm_pci_ops *)(dev)->driver->ops)
 
+/**
+ * pci_get_bdf() - Get the BDF value for a device
+ *
+ * @dev:       Device to check
+ * @return bus/device/function value (see PCI_BDF())
+ */
+pci_dev_t pci_get_bdf(struct udevice *dev);
+
 /**
  * pci_bind_bus_devices() - scan a PCI bus and bind devices
  *