diff mbox

[12/29] PCI: Add for_each_pci_host_bridge() and pci_get_next_host_bridge

Message ID 1348561590-28067-13-git-send-email-yinghai@kernel.org
State Changes Requested
Headers show

Commit Message

Yinghai Lu Sept. 25, 2012, 8:26 a.m. UTC
use bus_find_device to loop host_bridges.

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

Comments

Jiang Liu Sept. 25, 2012, 2:51 p.m. UTC | #1
On 09/25/2012 04:26 PM, Yinghai Lu wrote:
> use bus_find_device to loop host_bridges.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---
>  drivers/pci/search.c |   23 +++++++++++++++++++++++
>  include/linux/pci.h  |    3 +++
>  2 files changed, 26 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index bf969ba..f072b54 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -178,6 +178,29 @@ 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_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *from)
> +{
> +	struct device *dev;
> +	struct device *dev_start = NULL;
> +	struct pci_host_bridge *bridge = NULL;
> +
> +	WARN_ON(in_interrupt());
> +	if (from)
> +		dev_start = &from->dev;
> +	dev = bus_find_device(&pci_host_bridge_bus_type, dev_start, NULL,
> +			      match_pci_host_bridge);
> +	if (dev)
> +		bridge = to_pci_host_bridge(dev);
> +	if (from)
> +		put_device(&from->dev);
> +	return bridge;
> +}
> +
>  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 cc8b558..1e45d6f 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_host_bridge(d) while (d = pci_get_next_host_bridge(d))
> +
>  void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
>  		     void (*release_fn)(struct pci_host_bridge *),
>  		     void *release_data);
> @@ -758,6 +760,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_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *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,
> 
Hi Yinghai,
	I'm working on a patchset to get rid of pci_find_next_bus() by using
class_for_each_device(&pcibus_class, xxx). I think your solution is better,
which removes both pci_find_next_bus() and pci_root_buses list. So I will give
up my version.
	Thanks!
	Gerry
--
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
Yinghai Lu Sept. 25, 2012, 2:59 p.m. UTC | #2
On Tue, Sep 25, 2012 at 7:51 AM, Jiang Liu <liuj97@gmail.com> wrote:
> Hi Yinghai,
>         I'm working on a patchset to get rid of pci_find_next_bus() by using
> class_for_each_device(&pcibus_class, xxx). I think your solution is better,
> which removes both pci_find_next_bus() and pci_root_buses list. So I will give
> up my version.

Good.

updated version that fixes compiling problem that Fengguang found.

-Yinghai
Jiang Liu Sept. 25, 2012, 3:04 p.m. UTC | #3
Hi Yinghai,
	Seems it would be better to change pci_get_next_host_bridge()
to pci_get_next_root_bus(struct pci_bus *bus). Almost all caller of
pci_get_next_host_bridge() has a pattern:

host_bridge = pci_get_next_host_bridge();
xxx_func(host_brige->bus);

And you add:
Reviewed-By: Jiang Liu <jiang.liu@huawei.com> to patch 12-29.

Thanks
Gerry

On 09/25/2012 04:26 PM, Yinghai Lu wrote:
> use bus_find_device to loop host_bridges.
> 
> Signed-off-by: Yinghai Lu <yinghai@kernel.org>
> ---
>  drivers/pci/search.c |   23 +++++++++++++++++++++++
>  include/linux/pci.h  |    3 +++
>  2 files changed, 26 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> index bf969ba..f072b54 100644
> --- a/drivers/pci/search.c
> +++ b/drivers/pci/search.c
> @@ -178,6 +178,29 @@ 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_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *from)
> +{
> +	struct device *dev;
> +	struct device *dev_start = NULL;
> +	struct pci_host_bridge *bridge = NULL;
> +
> +	WARN_ON(in_interrupt());
> +	if (from)
> +		dev_start = &from->dev;
> +	dev = bus_find_device(&pci_host_bridge_bus_type, dev_start, NULL,
> +			      match_pci_host_bridge);
> +	if (dev)
> +		bridge = to_pci_host_bridge(dev);
> +	if (from)
> +		put_device(&from->dev);
> +	return bridge;
> +}
> +
>  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 cc8b558..1e45d6f 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_host_bridge(d) while (d = pci_get_next_host_bridge(d))
> +
>  void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
>  		     void (*release_fn)(struct pci_host_bridge *),
>  		     void *release_data);
> @@ -758,6 +760,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_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *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,
> 

--
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..f072b54 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -178,6 +178,29 @@  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_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *from)
+{
+	struct device *dev;
+	struct device *dev_start = NULL;
+	struct pci_host_bridge *bridge = NULL;
+
+	WARN_ON(in_interrupt());
+	if (from)
+		dev_start = &from->dev;
+	dev = bus_find_device(&pci_host_bridge_bus_type, dev_start, NULL,
+			      match_pci_host_bridge);
+	if (dev)
+		bridge = to_pci_host_bridge(dev);
+	if (from)
+		put_device(&from->dev);
+	return bridge;
+}
+
 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 cc8b558..1e45d6f 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_host_bridge(d) while (d = pci_get_next_host_bridge(d))
+
 void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
 		     void (*release_fn)(struct pci_host_bridge *),
 		     void *release_data);
@@ -758,6 +760,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_host_bridge *pci_get_next_host_bridge(struct pci_host_bridge *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,