diff mbox

[v3,2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly

Message ID 20090723230305.4247.81288.stgit@bob.kio (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Alexander Chiang July 23, 2009, 11:03 p.m. UTC
We cannot simply call acpi_get_pci_dev() on any random ACPI handle
and hope that it works, because a PCI root bridge may not have
an associated struct pci_dev.

This is allowed per the PCI specification, and is referred to as a
non-materialized bridge.

So, depending on the type of PCI bridge that the handle points to,
use the appropriate interface to return the struct pci_bus correctly.

Signed-off-by: Alex Chiang <achiang@hp.com>
---

 drivers/pci/hotplug/acpiphp_glue.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)


--
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

Comments

Bjorn Helgaas July 24, 2009, 4:35 p.m. UTC | #1
On Thursday 23 July 2009 05:03:05 pm Alex Chiang wrote:
> We cannot simply call acpi_get_pci_dev() on any random ACPI handle
> and hope that it works, because a PCI root bridge may not have
> an associated struct pci_dev.
> 
> This is allowed per the PCI specification, and is referred to as a
> non-materialized bridge.
> 
> So, depending on the type of PCI bridge that the handle points to,
> use the appropriate interface to return the struct pci_bus correctly.
> 
> Signed-off-by: Alex Chiang <achiang@hp.com>

Reviewed-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

> ---
> 
>  drivers/pci/hotplug/acpiphp_glue.c |   28 +++++++++++++++++-----------
>  1 files changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
> index 0cb0f83..2e5f259 100644
> --- a/drivers/pci/hotplug/acpiphp_glue.c
> +++ b/drivers/pci/hotplug/acpiphp_glue.c
> @@ -62,6 +62,22 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus);
>  static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus);
>  static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context);
>  
> +static struct pci_bus *pci_bus_from_handle(acpi_handle handle)
> +{
> +	struct pci_bus *pbus;
> +	struct acpi_pci_root *root;
> +
> +	root = acpi_pci_find_root(handle);
> +	if (root)
> +		pbus = root->bus;
> +	else {
> +		struct pci_dev *pdev = acpi_get_pci_dev(handle);
> +		pbus = pdev->subordinate;
> +		pci_dev_put(pdev);
> +	}
> +	return pbus;
> +}
> +
>  /* callback routine to check for the existence of a pci dock device */
>  static acpi_status
>  is_pci_dock_device(acpi_handle handle, u32 lvl, void *context, void **rv)
> @@ -1387,16 +1403,7 @@ static void acpiphp_sanitize_bus(struct pci_bus *bus)
>  /* Program resources in newly inserted bridge */
>  static int acpiphp_configure_bridge (acpi_handle handle)
>  {
> -	struct pci_dev *dev;
> -	struct pci_bus *bus;
> -
> -	dev = acpi_get_pci_dev(handle);
> -	if (!dev) {
> -		err("cannot get PCI domain and bus number for bridge\n");
> -		return -EINVAL;
> -	}
> -
> -	bus = dev->bus;
> +	struct pci_bus *bus = pci_bus_from_handle(handle);
>  
>  	pci_bus_size_bridges(bus);
>  	pci_bus_assign_resources(bus);
> @@ -1404,7 +1411,6 @@ static int acpiphp_configure_bridge (acpi_handle handle)
>  	acpiphp_set_hpp_values(handle, bus);
>  	pci_enable_bridges(bus);
>  	acpiphp_configure_ioapics(handle);
> -	pci_dev_put(dev);
>  	return 0;
>  }
>  
> 
> --
> 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
> 


--
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
Jesse Barnes July 24, 2009, 9:38 p.m. UTC | #2
On Thu, 23 Jul 2009 17:03:05 -0600
Alex Chiang <achiang@hp.com> wrote:

> We cannot simply call acpi_get_pci_dev() on any random ACPI handle
> and hope that it works, because a PCI root bridge may not have
> an associated struct pci_dev.
> 
> This is allowed per the PCI specification, and is referred to as a
> non-materialized bridge.
> 
> So, depending on the type of PCI bridge that the handle points to,
> use the appropriate interface to return the struct pci_bus correctly.
> 
> Signed-off-by: Alex Chiang <achiang@hp.com>
> ---

I put these in my linux-next branch, just because I'm really
conservative about the current release.

If we hear of boxes in the wild getting bitten by the non-materialized
bit, we can push this set back to stable.
Alexander Chiang July 24, 2009, 11:58 p.m. UTC | #3
* Jesse Barnes <jesse.barnes@intel.com>:
> On Thu, 23 Jul 2009 17:03:05 -0600
> Alex Chiang <achiang@hp.com> wrote:
> 
> > We cannot simply call acpi_get_pci_dev() on any random ACPI handle
> > and hope that it works, because a PCI root bridge may not have
> > an associated struct pci_dev.
> > 
> > This is allowed per the PCI specification, and is referred to as a
> > non-materialized bridge.
> > 
> > So, depending on the type of PCI bridge that the handle points to,
> > use the appropriate interface to return the struct pci_bus correctly.
> > 
> > Signed-off-by: Alex Chiang <achiang@hp.com>
> > ---
> 
> I put these in my linux-next branch, just because I'm really
> conservative about the current release.
> 
> If we hear of boxes in the wild getting bitten by the non-materialized
> bit, we can push this set back to stable.

Sounds good, thanks Jesse.

/ac

--
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/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 0cb0f83..2e5f259 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -62,6 +62,22 @@  static void acpiphp_sanitize_bus(struct pci_bus *bus);
 static void acpiphp_set_hpp_values(acpi_handle handle, struct pci_bus *bus);
 static void handle_hotplug_event_func(acpi_handle handle, u32 type, void *context);
 
+static struct pci_bus *pci_bus_from_handle(acpi_handle handle)
+{
+	struct pci_bus *pbus;
+	struct acpi_pci_root *root;
+
+	root = acpi_pci_find_root(handle);
+	if (root)
+		pbus = root->bus;
+	else {
+		struct pci_dev *pdev = acpi_get_pci_dev(handle);
+		pbus = pdev->subordinate;
+		pci_dev_put(pdev);
+	}
+	return pbus;
+}
+
 /* callback routine to check for the existence of a pci dock device */
 static acpi_status
 is_pci_dock_device(acpi_handle handle, u32 lvl, void *context, void **rv)
@@ -1387,16 +1403,7 @@  static void acpiphp_sanitize_bus(struct pci_bus *bus)
 /* Program resources in newly inserted bridge */
 static int acpiphp_configure_bridge (acpi_handle handle)
 {
-	struct pci_dev *dev;
-	struct pci_bus *bus;
-
-	dev = acpi_get_pci_dev(handle);
-	if (!dev) {
-		err("cannot get PCI domain and bus number for bridge\n");
-		return -EINVAL;
-	}
-
-	bus = dev->bus;
+	struct pci_bus *bus = pci_bus_from_handle(handle);
 
 	pci_bus_size_bridges(bus);
 	pci_bus_assign_resources(bus);
@@ -1404,7 +1411,6 @@  static int acpiphp_configure_bridge (acpi_handle handle)
 	acpiphp_set_hpp_values(handle, bus);
 	pci_enable_bridges(bus);
 	acpiphp_configure_ioapics(handle);
-	pci_dev_put(dev);
 	return 0;
 }