mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Alex Chiang <achiang@hp.com>
Cc: jbarnes@virtuousgeek.org, lenb@kernel.org,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-acpi@vger.kernel.org
Subject: Re: [PATCH v2 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly
Date: Mon, 20 Jul 2009 14:55:43 -0600	[thread overview]
Message-ID: <200907201455.44959.bjorn.helgaas@hp.com> (raw)
In-Reply-To: <20090714205333.18933.73027.stgit@bob.kio>

On Tuesday 14 July 2009 02:53:33 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>
> ---
> 
>  drivers/pci/hotplug/acpiphp_glue.c |   27 ++++++++++++++++-----------
>  1 files changed, 16 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
> index 0cb0f83..fa4658b 100644
> --- a/drivers/pci/hotplug/acpiphp_glue.c
> +++ b/drivers/pci/hotplug/acpiphp_glue.c
> @@ -62,6 +62,21 @@ 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;
> +
> +	if (acpi_is_root_bridge(handle)) {
> +		struct acpi_pci_root *root = acpi_pci_find_root(handle);
> +		pbus = root->bus;
> +	} else {
> +		struct pci_dev *pdev = acpi_get_pci_dev(handle);
> +		pbus = pdev->subordinate;
> +		pci_dev_put(pdev);
> +	}
> +	return pbus;

I worry that acpi_is_root_bridge() merely checks the device IDs of
"handle", which isn't quite the same as checking whether the pci_root
driver has claimed "handle".

Are you confident that it's safe to move the pci_dev_put(), so it is
released before configuring the bridge?

What do you think about something like this (even though the get/put
is still a little clunky):

	struct pci_dev *dev = NULL;

	root = acpi_pci_find_root(handle);
	if (root)
		bus = root->bus;
	else {
		dev = acpi_get_pci_dev(handle);
		if (dev)
			bus = pdev->subordinate;
		else {
			err("cannot get PCI domain and bus number for bridge\n");
			return -EINVAL;
		}
	}

	pci_bus_size_bridges(bus);
	...
	if (dev)
		pci_dev_put(dev);
	return 0;

> +}
> +
>  /* 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 +1402,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 +1410,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;
>  }

  reply	other threads:[~2009-07-20 20:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-14 20:53 [PATCH v2 0/2] ACPI/PCI: export acpi_pci_root to find pci_bus correctly Alex Chiang
2009-07-14 20:53 ` [PATCH v2 1/2] ACPI: export acpi_pci_root and friends Alex Chiang
2009-07-14 20:53 ` [PATCH v2 2/2] PCI Hotplug: acpiphp: get pci_bus from acpi handle correctly Alex Chiang
2009-07-20 20:55   ` Bjorn Helgaas [this message]
2009-07-21 19:57     ` Alex Chiang
2009-07-21 20:15       ` Bjorn Helgaas
2009-07-21 20:19         ` Alex Chiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200907201455.44959.bjorn.helgaas@hp.com \
    --to=bjorn.helgaas@hp.com \
    --cc=achiang@hp.com \
    --cc=jbarnes@virtuousgeek.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome