diff mbox

[U-Boot,6/8] dm: pci: Add a function to get the controller for a bus

Message ID 1445104205-4079-7-git-send-email-sjg@chromium.org
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Oct. 17, 2015, 5:50 p.m. UTC
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>
---

 drivers/pci/pci-uclass.c | 8 ++++++++
 include/pci.h            | 8 ++++++++
 2 files changed, 16 insertions(+)

Comments

Bin Meng Oct. 25, 2015, 3:11 a.m. UTC | #1
Hi Simon,

On Sun, Oct 18, 2015 at 1:50 AM, Simon Glass <sjg@chromium.org> wrote:
> 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>
> ---
>
>  drivers/pci/pci-uclass.c | 8 ++++++++
>  include/pci.h            | 8 ++++++++
>  2 files changed, 16 insertions(+)
>
> diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
> index 1c6df0f..527d3bb 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_get_uclass_id(dev->parent) == UCLASS_PCI)

Please use device_is_on_pci_bus() API.

> +               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 f40a83d..8b471ab 100644
> --- a/include/pci.h
> +++ b/include/pci.h
> @@ -1123,6 +1123,14 @@ 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
>   */
>  struct dm_pci_emul_ops {
> --

Regards,
Bin
diff mbox

Patch

diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index 1c6df0f..527d3bb 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_get_uclass_id(dev->parent) == UCLASS_PCI)
+		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 f40a83d..8b471ab 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -1123,6 +1123,14 @@  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
  */
 struct dm_pci_emul_ops {