From: Lukas Wunner <lukas@wunner.de>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-kernel@vger.kernel.org,
Andreas Noever <andreas.noever@gmail.com>,
linux-pci@vger.kernel.org, linux-pm@vger.kernel.org
Subject: Re: [PATCH v5 7/8] thunderbolt: Power down controller when idle
Date: Sun, 12 Feb 2017 17:31:30 +0100 [thread overview]
Message-ID: <20170212163130.GA2769@wunner.de> (raw)
In-Reply-To: <20170128233237.GQ20550@bhelgaas-glaptop.roam.corp.google.com>
On Sat, Jan 28, 2017 at 05:32:37PM -0600, Bjorn Helgaas wrote:
> On Sun, Jan 15, 2017 at 09:03:45PM +0100, Lukas Wunner wrote:
> > A Thunderbolt controller appears to the OS as a set of virtual devices:
> > One upstream bridge, multiple downstream bridges and one NHI (Native
> > Host Interface). The upstream and downstream bridges represent a PCIe
> > switch (see definition of a switch in the PCIe spec). The NHI device is
> > used to manage the switch fabric. Hotplugged devices appear behind the
> > downstream bridges:
> >
> > (Root Port) ---- Upstream Bridge --+-- Downstream Bridge 0 ---- NHI
> > +-- Downstream Bridge 1 --
> > +-- Downstream Bridge 2 --
> > ...
> >
> > Power is cut to the entire set of devices. The Linux pm model is
> > hierarchical and assumes that a child cannot resume before its parent.
> > To conform to this model, power control must be governed by the
> > Thunderbolt controller's topmost device, which is the upstream bridge.
> > The NHI and downstream bridges go to D3hot independently and the
> > upstream bridge goes to D3cold once all its children have suspended.
> > This commit only adds runtime pm for the upstream bridge. Runtime pm
> > for the NHI is added in a separate commit to signify its independence.
> > Runtime pm for the downstream bridges is handled by the pcieport driver.
> >
> > Because Apple's ACPI methods are nonstandard, a struct dev_pm_domain is
> > used to override the PCI bus pm_ops. The thunderbolt driver binds to
>
> What are the default PCI bus pm_ops? I looked briefly for it to see
> if there was some way to use hooks there instead of using
> dev_pm_domain_set() with its weird out-of-orderness.
The default PCI bus pm_ops are defined in drivers/pci/pci-driver.c as
struct dev_pm_ops pci_dev_pm_ops.
I did hook into those callbacks in an earlier version of this series
but it required more patches and more modifications to the PCI core
and PCIe port services driver to get Thunderbolt runpm to work:
https://www.spinics.net/lists/linux-pci/msg51158.html
Using dev_pm_domain_set() is the de facto standard to solve this,
vga_switcheroo does the same, that's why I settled on this approach.
(see drivers/gpu/vga/vga_switcheroo.c:vga_switcheroo_init_domain_pm_ops())
> I guess what you do in thunderbolt_power_init() is copy the upstream
> device's bus's ops, then override a few of them? Seems like we then
> have the problem of keeping the Thunderbolt ones in sync with the
> generic ones, e.g., if something got added to the generic one,
> somebody should look at the Thunderbolt one to see if it's also need
> there?
Not a problem. upstream_runtime_suspend() essentially does this:
// call pci_dev_pm_ops ->runtime_suspend hook:
ret = dev->bus->pm->runtime_suspend(dev);
// power down:
acpi_execute_simple_method(power->set, NULL, 0)
// enable wake interrupt:
acpi_enable_gpe(NULL, power->wake_gpe)
So any changes to the pci_dev_pm_ops are inherited. Again,
vga_switcheroo does the same (see vga_switcheroo_runtime_suspend()).
> > +#define pr_fmt(fmt) KBUILD_MODNAME " %s: " fmt, dev_name(dev)
[...]
> > + /* prevent interrupts during system sleep transition */
> > + if (ACPI_FAILURE(acpi_disable_gpe(NULL, power->wake_gpe))) {
> > + pr_err("cannot disable wake GPE, resuming\n");
>
> Can you use dev_err() here and below? This is related to a specific
> device, and it'd be nice to know which one.
See above, the device name is included in pr_fmt. The reason to use
pr_err() instead of dev_err() is to get the error message prefixed
with "thunderbolt" instead of "pcieport". Recall that this function
is executed in the context of the upstream bridge, whose driver name
is pcieport. I would like to prevent people from grepping the portdrv
code for the error message. You're the second person to raise this
question (Andy Shevchenko made the same comment on an earlier version
of this patch), so I've now added a comment to explain it.
> > +void thunderbolt_power_init(struct tb *tb)
> > +{
> > + struct device *upstream_dev, *nhi_dev = &tb->nhi->pdev->dev;
> > + struct tb_power *power = NULL;
>
> Unnecessary initialization.
Good point.
Thanks,
Lukas
next prev parent reply other threads:[~2017-02-12 16:31 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-15 20:03 [PATCH v5 0/8] Runtime PM for Thunderbolt on Macs Lukas Wunner
2017-01-15 20:03 ` [PATCH v5 5/8] PM: Make requirements of dev_pm_domain_set() more precise Lukas Wunner
2017-01-28 23:14 ` Bjorn Helgaas
2017-01-15 20:03 ` [PATCH v5 4/8] Revert "PM / Runtime: Remove the exported function pm_children_suspended()" Lukas Wunner
2017-01-15 20:03 ` [PATCH v5 2/8] PCI: Allow runtime PM on Thunderbolt ports Lukas Wunner
2017-01-28 22:09 ` Bjorn Helgaas
2017-01-30 7:15 ` Rafael J. Wysocki
2017-02-10 17:57 ` Bjorn Helgaas
2017-01-15 20:03 ` [PATCH v5 1/8] PCI: Recognize Thunderbolt devices Lukas Wunner
2017-01-28 21:52 ` Bjorn Helgaas
2017-01-29 0:26 ` Lukas Wunner
2017-02-06 6:09 ` Lukas Wunner
2017-02-10 17:42 ` Bjorn Helgaas
2017-02-12 16:50 ` Lukas Wunner
2017-01-15 20:03 ` [PATCH v5 8/8] thunderbolt: Runtime suspend NHI when idle Lukas Wunner
2017-01-15 20:03 ` [PATCH v5 3/8] PCI: Don't block runtime PM for Thunderbolt host hotplug ports Lukas Wunner
2017-01-16 10:29 ` Mika Westerberg
2017-01-28 23:00 ` Bjorn Helgaas
2017-02-10 18:39 ` Bjorn Helgaas
2017-02-12 17:13 ` Lukas Wunner
2017-02-13 12:17 ` Rafael J. Wysocki
2017-01-15 20:03 ` [PATCH v5 7/8] thunderbolt: Power down controller when idle Lukas Wunner
2017-01-28 23:32 ` Bjorn Helgaas
2017-02-12 16:31 ` Lukas Wunner [this message]
2017-02-13 22:57 ` Bjorn Helgaas
2017-01-15 20:03 ` [PATCH v5 6/8] PM / sleep: Define constant for direct_complete Lukas Wunner
2017-01-19 10:38 ` [PATCH v5 0/8] Runtime PM for Thunderbolt on Macs Greg Kroah-Hartman
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=20170212163130.GA2769@wunner.de \
--to=lukas@wunner.de \
--cc=andreas.noever@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=helgaas@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@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;
as well as URLs for NNTP newsgroup(s).