diff mbox

PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

Message ID 1348588579-16970-1-git-send-email-jiang.liu@huawei.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Jiang Liu Sept. 25, 2012, 3:56 p.m. UTC
From: Yinghai Lu <yinghai@kernel.org>

use bus_find_device to loop host_bridges.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
 drivers/pci/search.c |   22 ++++++++++++++++++++++
 include/linux/pci.h  |    3 +++
 2 files changed, 25 insertions(+)

Comments

Yinghai Lu Sept. 25, 2012, 4:25 p.m. UTC | #1
On Tue, Sep 25, 2012 at 8:56 AM, Jiang Liu <liuj97@gmail.com> wrote:
> From: Yinghai Lu <yinghai@kernel.org>
>
> use bus_find_device to loop host_bridges.
>
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---
>  drivers/pci/search.c |   22 ++++++++++++++++++++++
>  include/linux/pci.h  |    3 +++
>  2 files changed, 25 insertions(+)
>
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index bf969ba..5e82905 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -178,6 +178,28 @@ struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
>  }
>  EXPORT_SYMBOL(pci_get_domain_bus_and_slot);
>
> +static int match_pci_host_bridge(struct device *dev, void *data)
> +{
> +       return 1;
> +}
> +
> +struct pci_bus *pci_get_next_root_bus(struct pci_bus *bus)
> +{
> +       struct device *dev;
> +
> +       WARN_ON(in_interrupt());
> +       dev = bus_find_device(&pci_host_bridge_bus_type,
> +                             bus ? bus->bridge : NULL,
> +                             NULL,
> +                             match_pci_host_bridge);
> +       if (bus)
> +               put_device(bus->bridge);
> +       if (dev)
> +               return to_pci_host_bridge(dev)->bus;
> +
> +       return NULL;
> +}

that interface is not good, bus could be not root bus.

Also now we still have chance to have root bridge is there, but root
bus already get removed ?

Actually some root member should be in pci host bridge instead.
So don't need to go deep to bus anymore.

hope we should get rid of pci_bus.

-Yinghai
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index bf969ba..5e82905 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -178,6 +178,28 @@  struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
 }
 EXPORT_SYMBOL(pci_get_domain_bus_and_slot);
 
+static int match_pci_host_bridge(struct device *dev, void *data)
+{
+	return 1;
+}
+
+struct pci_bus *pci_get_next_root_bus(struct pci_bus *bus)
+{
+	struct device *dev;
+
+	WARN_ON(in_interrupt());
+	dev = bus_find_device(&pci_host_bridge_bus_type,
+			      bus ? bus->bridge : NULL,
+			      NULL,
+			      match_pci_host_bridge);
+	if (bus)
+		put_device(bus->bridge);
+	if (dev)
+		return to_pci_host_bridge(dev)->bus;
+
+	return NULL;
+}
+
 static int match_pci_dev_by_id(struct device *dev, void *data)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index be1de01..54e8fa1 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -394,6 +394,8 @@  struct pci_host_bridge {
 };
 
 #define	to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev)
+#define for_each_pci_root_bus(bus) while (bus = pci_get_next_root_bus(bus))
+
 void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
 		     void (*release_fn)(struct pci_host_bridge *),
 		     void *release_data);
@@ -757,6 +759,7 @@  int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
 int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
 struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
 
+struct pci_bus *pci_get_next_root_bus(struct pci_bus *from);
 struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
 				struct pci_dev *from);
 struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,