]> git.sur5r.net Git - u-boot/commitdiff
dm: pci: Add a function to get the controller for a bus
authorSimon Glass <sjg@chromium.org>
Fri, 20 Nov 2015 03:27:00 +0000 (20:27 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 1 Dec 2015 13:26:36 +0000 (06:26 -0700)
A PCI bus may be a bridge device where the controller is the bridge's
parent. Add a function to return the controller device, given a PCI device.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Stephen Warren <swarren@nvidia.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
drivers/pci/pci-uclass.c
include/pci.h

index e38e0b25947a63e27512b6fde28fca1f4bbad48e..f3f5f007c8e5a0eb3b1b53baa2ebd6d6d7eb95a7 100644 (file)
@@ -53,6 +53,14 @@ struct pci_controller *pci_bus_to_hose(int busnum)
        return dev_get_uclass_priv(bus);
 }
 
+struct udevice *pci_get_controller(struct udevice *dev)
+{
+       while (device_is_on_pci_bus(dev))
+               dev = dev->parent;
+
+       return dev;
+}
+
 pci_dev_t pci_get_bdf(struct udevice *dev)
 {
        struct pci_child_platdata *pplat = dev_get_parent_platdata(dev);
index ec2d104dffef7442eb5841a7781763a85500883d..f3dda702f52f4328ca63ba0cd40ee1b0efeaa6a1 100644 (file)
@@ -1122,6 +1122,14 @@ ulong pci_conv_32_to_size(ulong value, uint offset, enum pci_size_t size);
 ulong pci_conv_size_to_32(ulong old, ulong value, uint offset,
                          enum pci_size_t size);
 
+/**
+ * pci_get_controller() - obtain the controller to use for a bus
+ *
+ * @dev:       Device to check
+ * @return pointer to the controller device for this bus
+ */
+struct udevice *pci_get_controller(struct udevice *dev);
+
 /**
  * struct dm_pci_emul_ops - PCI device emulator operations
  */