From: Lucas Stach <l.stach@pengutronix.de>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Thierry Reding <thierry.reding@gmail.com>,
Stephen Warren <swarren@wwwdotorg.org>,
Alexandre Courbot <gnurou@gmail.com>,
linux-tegra@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v4 1/2] PCI: add helper function to find root port for device
Date: Mon, 30 Mar 2015 18:06:41 +0200 [thread overview]
Message-ID: <1427731601.3370.14.camel@pengutronix.de> (raw)
In-Reply-To: <1427726038.3643.913.camel@redhat.com>
Am Montag, den 30.03.2015, 08:33 -0600 schrieb Alex Williamson:
> On Mon, 2015-03-30 at 12:55 +0200, Lucas Stach wrote:
> > This adds a simple way to get the root port a given device
> > is connected to.
> >
> > Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
> > ---
> > v2: new patch in v2
> > v3: rename to pci_find_rootport to fit better with other API
> > v4: - rename to make it obvious that this function is PCIe specific
> > - fixes wrong assumption about what is a root bus in the presence
> > virtual buses
> > ---
> > drivers/pci/search.c | 20 ++++++++++++++++++++
> > include/linux/pci.h | 1 +
> > 2 files changed, 21 insertions(+)
> >
> > diff --git a/drivers/pci/search.c b/drivers/pci/search.c
> > index a20ce7d5e2a7..d7c599103ae1 100644
> > --- a/drivers/pci/search.c
> > +++ b/drivers/pci/search.c
> > @@ -384,3 +384,23 @@ int pci_dev_present(const struct pci_device_id *ids)
> > return 0;
> > }
> > EXPORT_SYMBOL(pci_dev_present);
> > +
> > +/**
> > + * pcie_find_root_port - Returns the root port the given device is connected to.
> > + * @dev: PCI device for which the root port should be found.
> > + */
> > +struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
> > +{
> > + struct pci_bus *bus = dev->bus;
> > +
> > + /* if this device is located on the root bus, it is a root port */
> > + if (pci_is_root_bus(bus))
> > + return dev;
>
> It could also be a root complex endpoint or a conventional PCI
> device/bridge sitting on the host bridge bus.
> > +
> > + /* walk up the PCI hierarchy to the first level below the root */
> > + while (bus->parent && bus->parent->parent)
> > + bus = bus->parent;
> > +
> > + return bus->self;
> > +}
> > +EXPORT_SYMBOL(pcie_find_root_port);
>
> IMHO, this makes too many assumptions about the topology that it's
> working with for a generic interface. Your usage may be fairly fixed,
> but there are too many cases where it could return something that's not
> a root port as a general interface. Thanks,
>
I'm open to suggestions on how to improve the detection. I really need
something which works reliable in the majority of cases, as the Tegra
quirk should not be executed on other platforms.
Do you think filtering out EP devices and conventional PCI bridges on
the root bus is enough?
Regards,
Lucas
--
Pengutronix e.K. | Lucas Stach |
Industrial Linux Solutions | http://www.pengutronix.de/ |
next prev parent reply other threads:[~2015-03-30 16:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-30 10:55 [PATCH v4 1/2] PCI: add helper function to find root port for device Lucas Stach
2015-03-30 10:55 ` [PATCH v4 2/2] PCI: tegra: apply relaxed ordering fixup only on Tegra Lucas Stach
2015-03-30 14:33 ` [PATCH v4 1/2] PCI: add helper function to find root port for device Alex Williamson
2015-03-30 16:06 ` Lucas Stach [this message]
2015-03-30 16:52 ` Alex Williamson
2015-03-31 12:23 ` Lucas Stach
2015-03-31 14:09 ` Alex Williamson
2015-04-08 18:13 ` Bjorn Helgaas
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=1427731601.3370.14.camel@pengutronix.de \
--to=l.stach@pengutronix.de \
--cc=alex.williamson@redhat.com \
--cc=bhelgaas@google.com \
--cc=gnurou@gmail.com \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=swarren@wwwdotorg.org \
--cc=thierry.reding@gmail.com \
/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;
as well as URLs for NNTP newsgroup(s).