linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] PCI: rename pci_is_bridge() to pci_has_subordinate()
@ 2014-03-14  9:38 Yijing Wang
  2014-04-04 23:31 ` Bjorn Helgaas
  0 siblings, 1 reply; 3+ messages in thread
From: Yijing Wang @ 2014-03-14  9:38 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Rafael J. Wysocki, Yijing Wang

pci_is_bridge() return true only when the device subordinate
is not equal to NULL. This confuses people. PCI device is a
bridge means header type(bit 0 through 6) is 0x1(PCI bridge) or 
0x2(CardBus bridge).

Signed-off-by: Yijing Wang <wangyijing@huawei.com>
---
 drivers/pci/pci-acpi.c   |    5 -----
 drivers/pci/pci-driver.c |    8 ++++----
 drivers/pci/pci.h        |    2 +-
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index f49abef..4bc7971 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -309,11 +309,6 @@ static struct acpi_device *acpi_pci_find_companion(struct device *dev)
 	bool check_children;
 	u64 addr;
 
-	/*
-	 * pci_is_bridge() is not suitable here, because pci_dev->subordinate
-	 * is set only after acpi_pci_find_device() has been called for the
-	 * given device.
-	 */
 	check_children = pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE
 			|| pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
 	/* Please ref to ACPI spec for the syntax of _ADR */
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 25f0bc6..019dcb2 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -580,14 +580,14 @@ static void pci_pm_default_resume(struct pci_dev *pci_dev)
 {
 	pci_fixup_device(pci_fixup_resume, pci_dev);
 
-	if (!pci_is_bridge(pci_dev))
+	if (!pci_has_subordinate(pci_dev))
 		pci_enable_wake(pci_dev, PCI_D0, false);
 }
 
 static void pci_pm_default_suspend(struct pci_dev *pci_dev)
 {
 	/* Disable non-bridge devices without PM support */
-	if (!pci_is_bridge(pci_dev))
+	if (!pci_has_subordinate(pci_dev))
 		pci_disable_enabled_device(pci_dev);
 }
 
@@ -711,7 +711,7 @@ static int pci_pm_suspend_noirq(struct device *dev)
 
 	if (!pci_dev->state_saved) {
 		pci_save_state(pci_dev);
-		if (!pci_is_bridge(pci_dev))
+		if (!pci_has_subordinate(pci_dev))
 			pci_prepare_to_sleep(pci_dev);
 	}
 
@@ -954,7 +954,7 @@ static int pci_pm_poweroff_noirq(struct device *dev)
 			return error;
 	}
 
-	if (!pci_dev->state_saved && !pci_is_bridge(pci_dev))
+	if (!pci_dev->state_saved && !pci_has_subordinate(pci_dev))
 		pci_prepare_to_sleep(pci_dev);
 
 	/*
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 4df38df..a3b9cc1 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -79,7 +79,7 @@ static inline void pci_wakeup_event(struct pci_dev *dev)
 	pm_wakeup_event(&dev->dev, 100);
 }
 
-static inline bool pci_is_bridge(struct pci_dev *pci_dev)
+static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
 {
 	return !!(pci_dev->subordinate);
 }
-- 
1.7.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] PCI: rename pci_is_bridge() to pci_has_subordinate()
  2014-03-14  9:38 [PATCH 1/2] PCI: rename pci_is_bridge() to pci_has_subordinate() Yijing Wang
@ 2014-04-04 23:31 ` Bjorn Helgaas
  2014-04-08  9:22   ` Yijing Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Helgaas @ 2014-04-04 23:31 UTC (permalink / raw)
  To: Yijing Wang; +Cc: linux-pci, Rafael J. Wysocki

On Fri, Mar 14, 2014 at 05:38:09PM +0800, Yijing Wang wrote:
> pci_is_bridge() return true only when the device subordinate
> is not equal to NULL. This confuses people. PCI device is a
> bridge means header type(bit 0 through 6) is 0x1(PCI bridge) or 
> 0x2(CardBus bridge).
> 
> Signed-off-by: Yijing Wang <wangyijing@huawei.com>
> ---
>  drivers/pci/pci-acpi.c   |    5 -----
>  drivers/pci/pci-driver.c |    8 ++++----
>  drivers/pci/pci.h        |    2 +-
>  3 files changed, 5 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
> index f49abef..4bc7971 100644
> --- a/drivers/pci/pci-acpi.c
> +++ b/drivers/pci/pci-acpi.c
> @@ -309,11 +309,6 @@ static struct acpi_device *acpi_pci_find_companion(struct device *dev)
>  	bool check_children;
>  	u64 addr;
>  
> -	/*
> -	 * pci_is_bridge() is not suitable here, because pci_dev->subordinate
> -	 * is set only after acpi_pci_find_device() has been called for the
> -	 * given device.
> -	 */

This hunk shouldn't be here.  My guess is that you intended to replace
the code below with the new pci_is_bridge() that you introduced in
patch [2/2].  That new pci_is_bridge() is never used, and it does the
same hdr_type test as the code below.  But you apparently forgot to
change this code to use it?

>  	check_children = pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE
>  			|| pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
>  	/* Please ref to ACPI spec for the syntax of _ADR */
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 25f0bc6..019dcb2 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -580,14 +580,14 @@ static void pci_pm_default_resume(struct pci_dev *pci_dev)
>  {
>  	pci_fixup_device(pci_fixup_resume, pci_dev);
>  
> -	if (!pci_is_bridge(pci_dev))
> +	if (!pci_has_subordinate(pci_dev))

The rest of this is a simple rename and looks fine to me.

>  		pci_enable_wake(pci_dev, PCI_D0, false);
>  }
>  
>  static void pci_pm_default_suspend(struct pci_dev *pci_dev)
>  {
>  	/* Disable non-bridge devices without PM support */
> -	if (!pci_is_bridge(pci_dev))
> +	if (!pci_has_subordinate(pci_dev))
>  		pci_disable_enabled_device(pci_dev);
>  }
>  
> @@ -711,7 +711,7 @@ static int pci_pm_suspend_noirq(struct device *dev)
>  
>  	if (!pci_dev->state_saved) {
>  		pci_save_state(pci_dev);
> -		if (!pci_is_bridge(pci_dev))
> +		if (!pci_has_subordinate(pci_dev))
>  			pci_prepare_to_sleep(pci_dev);
>  	}
>  
> @@ -954,7 +954,7 @@ static int pci_pm_poweroff_noirq(struct device *dev)
>  			return error;
>  	}
>  
> -	if (!pci_dev->state_saved && !pci_is_bridge(pci_dev))
> +	if (!pci_dev->state_saved && !pci_has_subordinate(pci_dev))
>  		pci_prepare_to_sleep(pci_dev);
>  
>  	/*
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 4df38df..a3b9cc1 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -79,7 +79,7 @@ static inline void pci_wakeup_event(struct pci_dev *dev)
>  	pm_wakeup_event(&dev->dev, 100);
>  }
>  
> -static inline bool pci_is_bridge(struct pci_dev *pci_dev)
> +static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
>  {
>  	return !!(pci_dev->subordinate);
>  }
> -- 
> 1.7.1
> 
> 
> --
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] PCI: rename pci_is_bridge() to pci_has_subordinate()
  2014-04-04 23:31 ` Bjorn Helgaas
@ 2014-04-08  9:22   ` Yijing Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Yijing Wang @ 2014-04-08  9:22 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, Rafael J. Wysocki

>>  
>> -	/*
>> -	 * pci_is_bridge() is not suitable here, because pci_dev->subordinate
>> -	 * is set only after acpi_pci_find_device() has been called for the
>> -	 * given device.
>> -	 */
> 
> This hunk shouldn't be here.  My guess is that you intended to replace
> the code below with the new pci_is_bridge() that you introduced in
> patch [2/2].  That new pci_is_bridge() is never used, and it does the
> same hdr_type test as the code below.  But you apparently forgot to
> change this code to use it?
> 
>>  	check_children = pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE
>>  			|| pci_dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
>>  	/* Please ref to ACPI spec for the syntax of _ADR */
>> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c


Hi Bjorn, I noticed the kernel compare (pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) directly
to identify bridge device. But the pci_is_brdge() helper function(which seems to do this) actually
only check the device whether has subordinate bus. This maybe confuses people.

So I think we should rename current pci_is_brdge(), and refactor a new pci_is_bridge() helper function.
This can make code more readable, also there are a lot of codes using (pci_dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) directly compare.
If you think this make sense, we can replace them by the new pci_is_bridge().

eg. in acpiphp:

enable_device()
    ......
    	for (pass = 0; pass < 2; pass++) {
		list_for_each_entry(dev, &bus->devices, bus_list) {
			if (PCI_SLOT(dev->devfn) != slot->device)
				continue;
			if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
			    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) {
				max = pci_scan_bridge(bus, dev, max, pass);
				if (pass && dev->subordinate)
					pci_bus_size_bridges(dev->subordinate);
			}
		}
	}
    ......

and in PCI core code

pci_rescan_bus()
    .......
    	down_read(&pci_bus_sem);
	list_for_each_entry(dev, &bus->devices, bus_list)
		if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
		    dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
			if (dev->subordinate)
				__pci_bus_size_bridges(dev->subordinate,
							 &add_list);
	up_read(&pci_bus_sem);
    ..........


Thanks!
Yijing.





>> index 25f0bc6..019dcb2 100644
>> --- a/drivers/pci/pci-driver.c
>> +++ b/drivers/pci/pci-driver.c
>> @@ -580,14 +580,14 @@ static void pci_pm_default_resume(struct pci_dev *pci_dev)
>>  {
>>  	pci_fixup_device(pci_fixup_resume, pci_dev);
>>  
>> -	if (!pci_is_bridge(pci_dev))
>> +	if (!pci_has_subordinate(pci_dev))
> 
> The rest of this is a simple rename and looks fine to me.
> 
>>  		pci_enable_wake(pci_dev, PCI_D0, false);
>>  }
>>  
>>  static void pci_pm_default_suspend(struct pci_dev *pci_dev)
>>  {
>>  	/* Disable non-bridge devices without PM support */
>> -	if (!pci_is_bridge(pci_dev))
>> +	if (!pci_has_subordinate(pci_dev))
>>  		pci_disable_enabled_device(pci_dev);
>>  }
>>  
>> @@ -711,7 +711,7 @@ static int pci_pm_suspend_noirq(struct device *dev)
>>  
>>  	if (!pci_dev->state_saved) {
>>  		pci_save_state(pci_dev);
>> -		if (!pci_is_bridge(pci_dev))
>> +		if (!pci_has_subordinate(pci_dev))
>>  			pci_prepare_to_sleep(pci_dev);
>>  	}
>>  
>> @@ -954,7 +954,7 @@ static int pci_pm_poweroff_noirq(struct device *dev)
>>  			return error;
>>  	}
>>  
>> -	if (!pci_dev->state_saved && !pci_is_bridge(pci_dev))
>> +	if (!pci_dev->state_saved && !pci_has_subordinate(pci_dev))
>>  		pci_prepare_to_sleep(pci_dev);
>>  
>>  	/*
>> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
>> index 4df38df..a3b9cc1 100644
>> --- a/drivers/pci/pci.h
>> +++ b/drivers/pci/pci.h
>> @@ -79,7 +79,7 @@ static inline void pci_wakeup_event(struct pci_dev *dev)
>>  	pm_wakeup_event(&dev->dev, 100);
>>  }
>>  
>> -static inline bool pci_is_bridge(struct pci_dev *pci_dev)
>> +static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
>>  {
>>  	return !!(pci_dev->subordinate);
>>  }
>> -- 
>> 1.7.1
>>
>>
>> --
>> 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
> 
> 


-- 
Thanks!
Yijing


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-08  9:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-14  9:38 [PATCH 1/2] PCI: rename pci_is_bridge() to pci_has_subordinate() Yijing Wang
2014-04-04 23:31 ` Bjorn Helgaas
2014-04-08  9:22   ` Yijing Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).