From: Simon Glass Date: Fri, 20 Nov 2015 03:27:00 +0000 (-0700) Subject: dm: pci: Add a function to get the controller for a bus X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=9f60fb0db4b70c65760cb1799b76de1c9b71644d;p=project%2Fbcm63xx%2Fu-boot.git dm: pci: Add a function to get the controller for a bus 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 Acked-by: Stephen Warren Tested-by: Stephen Warren --- diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c index e38e0b2594..f3f5f007c8 100644 --- a/drivers/pci/pci-uclass.c +++ b/drivers/pci/pci-uclass.c @@ -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); diff --git a/include/pci.h b/include/pci.h index ec2d104dff..f3dda702f5 100644 --- a/include/pci.h +++ b/include/pci.h @@ -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 */