From: Bjorn Helgaas <helgaas@kernel.org>
To: Lukas Wunner <lukas@wunner.de>
Cc: linux-pci@vger.kernel.org,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
Cyril Brulebois <kibi@debian.org>,
Nicolas Saenz Julienne <nsaenz@kernel.org>,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Krzysztof Wilczy??ski <kwilczynski@kernel.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Jim Quinlan <james.quinlan@broadcom.com>,
bcm-kernel-feedback-list@broadcom.com,
linux-kernel@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com>
Subject: Re: [PATCH] PCI/pwrctrl: Skip creating platform device unless CONFIG_PCI_PWRCTL enabled
Date: Fri, 23 May 2025 21:42:07 -0500 [thread overview]
Message-ID: <20250524024207.GA1598583@bhelgaas> (raw)
In-Reply-To: <aDDn94q9gS8SfK9_@wunner.de>
On Fri, May 23, 2025 at 11:26:15PM +0200, Lukas Wunner wrote:
> On Fri, May 23, 2025 at 03:17:59PM -0500, Bjorn Helgaas wrote:
> > --- a/drivers/pci/probe.c
> > +++ b/drivers/pci/probe.c
> > @@ -2510,6 +2510,7 @@ EXPORT_SYMBOL(pci_bus_read_dev_vendor_id);
> >
> > static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, int devfn)
> > {
> > +#if defined(CONFIG_PCI_PWRCTL) || defined(CONFIG_PCI_PWRCTL_MODULE)
> > struct pci_host_bridge *host = pci_find_host_bridge(bus);
> > struct platform_device *pdev;
> > struct device_node *np;
> > @@ -2536,6 +2537,9 @@ static struct platform_device *pci_pwrctrl_create_device(struct pci_bus *bus, in
> > }
> >
> > return pdev;
> > +#else
> > + return NULL;
> > +#endif
> > }
> [...]
> > This an alternate to
> > https://lore.kernel.org/r/20250522140326.93869-1-manivannan.sadhasivam@linaro.org
> >
> > It should accomplish the same thing but I think using #ifdef makes it a
> > little more visible and easier to see that pci_pwrctrl_create_device() is
> > only relevant when CONFIG_PCI_PWRCTL is enabled.
>
> Just noting though that section 21 of Documentation/process/coding-style.rst
> discourages use of #ifdef and recommends IS_ENABLED() and inline stubs
> instead.
True, although I kind of object to IS_ENABLED() in cases like this
where what we really want is a no-op function, because IS_ENABLED()
forces me to mentally execute the function to see what's going on.
What I would prefer is something like the first paragraph in that
section: the #ifdef in a header file that declares the function and
defines a no-op stub, with the implementation in some pwrctrl file.
But now since we're considering this for v6.15 in a couple days, we
need a minimal fix. Mani's original patch is probably the best for
that, and I'm fine with that, although I don't think we should throw
brcmstb under the bus. The pci_pwrctrl_create_device() assumption
that pwrctrl is enabled is just broken, and I don't think the fix is
to improve pwrctrl and convert drivers.
Maybe we could use Mani's patch with something like my commit log
(it's quite possible I don't understand the situation completely):
If devicetree describes power supplies related to a PCI device, we
previously created a pwrctrl device even if CONFIG_PCI_PWRCTL was
not enabled.
When pci_pwrctrl_create_device() creates and returns a pwrctrl
device, pci_scan_device() doesn't enumerate the PCI device; it
assumes the pwrctrl core will rescan the bus after turning on the
power. If CONFIG_PCI_PWRCTL is not enabled, the rescan never
happens.
This may break PCI enumeration on any system that describes power
supplies in devicetree but does not use pwrctrl. Jim reported that
some brcmstb platforms break this way.
If CONFIG_PCI_PWRCTL is not enabled, skip creating the pwrctrl
platform device and scan the device normally.
Looking at pci_pwrctrl_create_device() raised more questions for me:
- If pwrctrl is enabled, devicetree describes a regulator, and the
power is already on, do we really want to defer enumeration?
- If pwrctrl *not* enabled, devicetree describes a regulator, and
the power is off, is there anything in dmesg that gives us a clue
about why we don't enumerate the device? Could/should we emit a
message as a hint?
- Creating a pwrctrl device, returning a pointer to it, and then
throwing that pointer away seems ... weird? Makes me wonder about
the lifetime management of that device.
Bjorn
next prev parent reply other threads:[~2025-05-24 2:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-23 20:17 [PATCH] PCI/pwrctrl: Skip creating platform device unless CONFIG_PCI_PWRCTL enabled Bjorn Helgaas
2025-05-23 21:26 ` Lukas Wunner
2025-05-24 2:42 ` Bjorn Helgaas [this message]
2025-05-24 6:29 ` Lukas Wunner
2025-05-24 8:51 ` Manivannan Sadhasivam
2025-05-27 22:25 ` Bjorn Helgaas
2025-05-29 19:23 ` Jim Quinlan
2025-05-30 3:16 ` Manivannan Sadhasivam
2025-05-30 3:13 ` Manivannan Sadhasivam
2025-06-20 0:06 ` Florian Fainelli
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=20250524024207.GA1598583@bhelgaas \
--to=helgaas@kernel.org \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bhelgaas@google.com \
--cc=brgl@bgdev.pl \
--cc=james.quinlan@broadcom.com \
--cc=kibi@debian.org \
--cc=kwilczynski@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=lukas@wunner.de \
--cc=manivannan.sadhasivam@linaro.org \
--cc=nsaenz@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