Skip to contentSkip to conversation

PCI/pwrctl: initial implementation and first user

PATCH Applied Bartosz Golaszewski 8 participants 33 messages Jun 12, 2024 – Jun 18, 2025 PCI

lore
Share & tools
lore
#0 lore raw

v9 cover PCI/pwrctl: initial implementation and first user

From: Bartosz Golaszewski <[email protected]>

I'm sending the PCI part separately to keep the history on the list. Bjorn acked all of them so I'll pick them up later today into the pwrseq tree.

Changelog:

Since v8:
- split out the PCI patches into their own series
- improved commit messages (added rationale for the PCI pwrctl and the powrseq driver for QCOM QCAxyz, start with a capital letter)
- pick up Acks from Bjorn
- Link to v8: https://lore.kernel.org/r/[email protected]

Since v7:
- added DTS changes for sm8650-hdk
- added circular dependency detection for pwrseq units
- fixed a KASAN reported use-after-free error in remove path
- improve Kconfig descriptions
- fix typos in bindings and Kconfig
- fixed issues reported by smatch
- fix the unbind path in PCI pwrctl
- lots of minor improvements to the pwrseq core

Since v6:
- kernel doc fixes
- drop myself from the DT bindings maintainers list for ath12k
- wait until the PCI bridge device is fully added before creating the PCI pwrctl platform devices for its sub-nodes, otherwise we may see sysfs and procfs attribute failures (due to duplication, we're basically trying to probe the same device twice at the same time)
- I kept the regulators for QCA6390's ath11k as required as they only apply to this specific Qualcomm package

Since v5:
- unify the approach to modelling the WCN WLAN/BT chips by always exposing the PMU node on the device tree and making the WLAN and BT nodes become consumers of its power outputs; this includes a major rework of the DT sources, bindings and driver code; there's no more a separate PCI pwrctl driver for WCN7850, instead its power-up sequence was moved into the pwrseq driver common for all WCN chips
- don't set load_uA from new regulator consumers
- fix reported kerneldoc issues
- drop voltage ranges for PMU outputs from DT
- many minor tweaks and reworks

v1: Original RFC:

https://lore.kernel.org/lkml/[email protected]/T/

v2: First real patch series (should have been PATCH v2) adding what I
referred to back then as PCI power sequencing:

https://lore.kernel.org/linux-arm-kernel/2024021413-grumbling-unlivable-c145@gregkh/T/

v3: RFC for the DT representation of the PMU supplying the WLAN and BT
modules inside the QCA6391 package (was largely separate from the series but probably should have been called PATCH or RFC v3):

https://lore.kernel.org/all/CAMRc=Mc+GNoi57eTQg71DXkQKjdaoAmCpB=h2ndEpGnmdhVV-Q@mail.gmail.com/T/

v4: Second attempt at the full series with changed scope (introduction of
the pwrseq subsystem, should have been RFC v4)

https://lore.kernel.org/lkml/[email protected]/T/

v5: Two different ways of handling QCA6390 and WCN7850:

https://lore.kernel.org/lkml/[email protected]/

Bartosz Golaszewski (5):
PCI: Hold the rescan mutex when scanning for the first time PCI/pwrctl: Reuse the OF node for power controlled devices PCI/pwrctl: Create platform devices for child OF nodes of the port
node
PCI/pwrctl: Add PCI power control core code
PCI/pwrctl: Add a PCI power control driver for power sequenced devices

 MAINTAINERS                            |   8 ++
 drivers/pci/Kconfig                    |   1 +
 drivers/pci/Makefile                   |   1 +
 drivers/pci/bus.c                      |   9 ++
 drivers/pci/of.c                       |  14 ++-
 drivers/pci/probe.c                    |   2 +
 drivers/pci/pwrctl/Kconfig             |  17 +++
 drivers/pci/pwrctl/Makefile            |   6 ++
 drivers/pci/pwrctl/core.c              | 137 +++++++++++++++++++++++++
 drivers/pci/pwrctl/pci-pwrctl-pwrseq.c |  89 ++++++++++++++++
 drivers/pci/remove.c                   |   3 +-
 include/linux/pci-pwrctl.h             |  51 +++++++++
 12 files changed, 333 insertions(+), 5 deletions(-)
 create mode 100644 drivers/pci/pwrctl/Kconfig
 create mode 100644 drivers/pci/pwrctl/Makefile
 create mode 100644 drivers/pci/pwrctl/core.c
 create mode 100644 drivers/pci/pwrctl/pci-pwrctl-pwrseq.c
 create mode 100644 include/linux/pci-pwrctl.h
Signature · 1 line
2.40.1
#1 lore raw

PATCH v9 1/5 PCI: Hold the rescan mutex when scanning for the first time

From: Bartosz Golaszewski <[email protected]>

With the introduction of PCI device power control drivers that will be able to trigger the port rescan when probing, we need to hold the rescan mutex during the initial pci_host_probe() too or the two could get in each other's way.

---
 drivers/pci/probe.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/probe.c +2 -0
index bfeeaf2d1fa9..b14b9876c030 100644
@@ -3083,7 +3083,9 @@ int pci_host_probe(struct pci_host_bridge *bridge)
 	struct pci_bus *bus, *child;
 	int ret;
 
+	pci_lock_rescan_remove();
 	ret = pci_scan_root_bus_bridge(bridge);
+	pci_unlock_rescan_remove();
 	if (ret < 0) {
 		dev_err(bridge->dev.parent, "Scanning root bridge failed");
 		return ret;
Signature · 1 line
2.40.1
#2 lore raw

PATCH v9 2/5 PCI/pwrctl: Reuse the OF node for power controlled devices

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

With PCI power control we deal with two struct device objects bound to two different drivers but consuming the same OF node. We must not bind the pinctrl twice. To that end: before setting the OF node of the newly instantiated PCI device, check if a platform device consuming the same OF node doesn't already exist on the platform bus and - if so - mark the PCI device as reusing the OF node.

---
 drivers/pci/of.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/pci/of.c +10 -4
index 48ba95e4ab05..dacea3fc5128 100644
@@ -6,6 +6,7 @@
  */
 #define pr_fmt(fmt)	"PCI: OF: " fmt
 
+#include <linux/cleanup.h>
 #include <linux/irqdomain.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
@@ -13,6 +14,7 @@
 #include <linux/of_irq.h>
 #include <linux/of_address.h>
 #include <linux/of_pci.h>
+#include <linux/platform_device.h>
 #include "pci.h"
 
 #ifdef CONFIG_PCI
@@ -25,16 +27,20 @@
  */
 int pci_set_of_node(struct pci_dev *dev)
 {
-	struct device_node *node;
-
 	if (!dev->bus->dev.of_node)
 		return 0;
 
-	node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
+	struct device_node *node __free(device_node) =
+		of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
 	if (!node)
 		return 0;
 
-	device_set_node(&dev->dev, of_fwnode_handle(node));
+	struct device *pdev __free(put_device) =
+		bus_find_device_by_of_node(&platform_bus_type, node);
+	if (pdev)
+		dev->bus->dev.of_node_reused = true;
+
+	device_set_node(&dev->dev, of_fwnode_handle(no_free_ptr(node)));
 	return 0;
 }
 
Signature · 1 line
2.40.1
#3 lore raw

PATCH v9 3/5 PCI/pwrctl: Create platform devices for child OF nodes of the port node

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

In preparation for introducing PCI device power control - a set of library functions that will allow powering-up of PCI devices before they're detected on the PCI bus - we need to populate the devices defined on the device-tree.

We are reusing the platform bus as it provides us with all the infrastructure we need to match the pwrctl drivers against the compatibles from OF nodes.

These platform devices will be probed by the driver core and bound to the PCI pwrctl drivers we'll introduce later.

---
 drivers/pci/bus.c    | 9 +++++++++
 drivers/pci/remove.c | 3 ++-
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/pci/bus.c +9 -0
index dfc99b3cb958..e4735428814d 100644
@@ -12,6 +12,7 @@
 #include <linux/errno.h>
 #include <linux/ioport.h>
 #include <linux/of.h>
+#include <linux/of_platform.h>
 #include <linux/proc_fs.h>
 #include <linux/slab.h>
 
@@ -348,6 +349,14 @@ void pci_bus_add_device(struct pci_dev *dev)
 		pci_warn(dev, "device attach failed (%d)\n", retval);
 
 	pci_dev_assign_added(dev, true);
+
+	if (pci_is_bridge(dev)) {
+		retval = of_platform_populate(dev->dev.of_node, NULL, NULL,
+					      &dev->dev);
+		if (retval)
+			pci_err(dev, "failed to populate child OF nodes (%d)\n",
+				retval);
+	}
 }
 EXPORT_SYMBOL_GPL(pci_bus_add_device);
 
drivers/pci/remove.c +2 -1
index d749ea8250d6..910387e5bdbf 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/pci.h>
 #include <linux/module.h>
+#include <linux/of_platform.h>
 #include "pci.h"
 
 static void pci_free_resources(struct pci_dev *dev)
@@ -18,7 +19,7 @@ static void pci_stop_dev(struct pci_dev *dev)
 	pci_pme_active(dev, false);
 
 	if (pci_dev_is_added(dev)) {
-
+		of_platform_depopulate(&dev->dev);
 		device_release_driver(&dev->dev);
 		pci_proc_detach_device(dev);
 		pci_remove_sysfs_dev_files(dev);
Signature · 1 line
2.40.1
#28 lore raw

PATCH v9 4/5 PCI/pwrctl: Add PCI power control core code

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Some PCI devices must be powered-on before they can be detected on the bus. Introduce a simple framework reusing the existing PCI OF infrastructure.

The way this works is: a DT node representing a PCI device connected to the port can be matched against its power control platform driver. If the match succeeds, the driver is responsible for powering-up the device and calling pci_pwrctl_device_set_ready() which will trigger a PCI bus rescan as well as subscribe to PCI bus notifications.

When the device is detected and created, we'll make it consume the same DT node that the platform device did. When the device is bound, we'll create a device link between it and the parent power control device.

---
 MAINTAINERS                 |   8 +++
 drivers/pci/Kconfig         |   1 +
 drivers/pci/Makefile        |   1 +
 drivers/pci/pwrctl/Kconfig  |   8 +++
 drivers/pci/pwrctl/Makefile |   4 ++
 drivers/pci/pwrctl/core.c   | 137 ++++++++++++++++++++++++++++++++++++
 include/linux/pci-pwrctl.h  |  51 ++++++++++++++
 7 files changed, 210 insertions(+)
 create mode 100644 drivers/pci/pwrctl/Kconfig
 create mode 100644 drivers/pci/pwrctl/Makefile
 create mode 100644 drivers/pci/pwrctl/core.c
 create mode 100644 include/linux/pci-pwrctl.h
MAINTAINERS +8 -0
index 3ee6e0cbc630..d8350d11a18d 100644
@@ -17411,6 +17411,14 @@ F:	Documentation/driver-api/pci/p2pdma.rst
 F:	drivers/pci/p2pdma.c
 F:	include/linux/pci-p2pdma.h
 
+PCI POWER CONTROL
+M:	Bartosz Golaszewski <[email protected]>
+L:	[email protected]
+S:	Maintained
+T:	git git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git
+F:	drivers/pci/pwrctl/*
+F:	include/linux/pci-pwrctl.h
+
 PCI SUBSYSTEM
 M:	Bjorn Helgaas <[email protected]>
 L:	[email protected]
drivers/pci/Kconfig +1 -0
index d35001589d88..aa4d1833f442 100644
@@ -296,5 +296,6 @@ source "drivers/pci/hotplug/Kconfig"
 source "drivers/pci/controller/Kconfig"
 source "drivers/pci/endpoint/Kconfig"
 source "drivers/pci/switch/Kconfig"
+source "drivers/pci/pwrctl/Kconfig"
 
 endif
drivers/pci/Makefile +1 -0
index 175302036890..8ddad57934a6 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_PCI)		+= access.o bus.o probe.o host-bridge.o \
 
 obj-$(CONFIG_PCI)		+= msi/
 obj-$(CONFIG_PCI)		+= pcie/
+obj-$(CONFIG_PCI)		+= pwrctl/
 
 ifdef CONFIG_PCI
 obj-$(CONFIG_PROC_FS)		+= proc.o
drivers/pci/pwrctl/Kconfig new file +8 -0
new file mode 100644
index 000000000000..96195395af69
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+menu "PCI Power control drivers"
+
+config PCI_PWRCTL
+	tristate
+
+endmenu
drivers/pci/pwrctl/Makefile new file +4 -0
new file mode 100644
index 000000000000..52ae0640ef7b
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_PCI_PWRCTL)		+= pci-pwrctl-core.o
+pci-pwrctl-core-y			:= core.o
drivers/pci/pwrctl/core.c new file +137 -0

137 lines not on this page · raw message

include/linux/pci-pwrctl.h new file +51 -0

51 lines not on this page · raw message

Signature · 1 line
2.40.1
#31 lore raw

PATCH v9 5/5 PCI/pwrctl: Add a PCI power control driver for power sequenced devices

In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add a PCI power control driver that's capable of correctly powering up devices using the power sequencing subsystem. The first users of this driver are the ath11k module on QCA6390 and ath12k on WCN7850. These packages require a certain delay between enabling the Bluetooth and WLAN modules and the power sequencing subsystem takes care of it behind the scenes.

---
 drivers/pci/pwrctl/Kconfig             |  9 +++
 drivers/pci/pwrctl/Makefile            |  2 +
 drivers/pci/pwrctl/pci-pwrctl-pwrseq.c | 89 ++++++++++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 drivers/pci/pwrctl/pci-pwrctl-pwrseq.c
drivers/pci/pwrctl/Kconfig +9 -0
index 96195395af69..f1b824955d4b 100644
@@ -5,4 +5,13 @@ menu "PCI Power control drivers"
 config PCI_PWRCTL
 	tristate
 
+config PCI_PWRCTL_PWRSEQ
+	tristate "PCI Power Control driver using the Power Sequencing subsystem"
+	select POWER_SEQUENCING
+	select PCI_PWRCTL
+	default m if ((ATH11K_PCI || ATH12K) && ARCH_QCOM)
+	help
+	  Enable support for the PCI power control driver for device
+	  drivers using the Power Sequencing subsystem.
+
 endmenu
drivers/pci/pwrctl/Makefile +2 -0
index 52ae0640ef7b..d308aae4800c 100644
@@ -2,3 +2,5 @@
 
 obj-$(CONFIG_PCI_PWRCTL)		+= pci-pwrctl-core.o
 pci-pwrctl-core-y			:= core.o
+
+obj-$(CONFIG_PCI_PWRCTL_PWRSEQ)		+= pci-pwrctl-pwrseq.o
drivers/pci/pwrctl/pci-pwrctl-pwrseq.c new file +89 -0

89 lines not on this page · raw message

Signature · 1 line
2.40.1
author Applied
#32 lore raw
In reply to Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 9 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

I'm sending the PCI part separately to keep the history on the list. Bjorn acked all of them so I'll pick them up later today into the pwrseq tree.

Changelog:

[...]

Applied, thanks!

[1/5] PCI: Hold the rescan mutex when scanning for the first time

      commit: 5799eba8eeabe79a476016f22a7aea57467b7638
[2/5] PCI/pwrctl: Reuse the OF node for power controlled devices
      commit: 62c953f0f4fb0b5f67b0ad3096ab38f5c5712d75
[3/5] PCI/pwrctl: Create platform devices for child OF nodes of the port node
      commit: 8fb18619d9102e8f4f6184cdac482422d9293b48
[4/5] PCI/pwrctl: Add PCI power control core code
      commit: 4565d2652a37e438e4cd729e2a8dfeffe34c958c
[5/5] PCI/pwrctl: Add a PCI power control driver for power sequenced devices
      commit: 6140d185a43daa298d43453929560388d6d49b6e

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
#4 lore raw

PATCH 1/1 pci: bus: only call of_platform_populate() if CONFIG_OF is defined

In reply to Bartosz Golaszewski

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
---
 drivers/pci/bus.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/bus.c +2 -0
index e4735428814d..b363010664cd 100644
@@ -350,6 +350,7 @@ void pci_bus_add_device(struct pci_dev *dev)
 
 	pci_dev_assign_added(dev, true);
 
+#ifdef CONFIG_OF
 	if (pci_is_bridge(dev)) {
 		retval = of_platform_populate(dev->dev.of_node, NULL, NULL,
 					      &dev->dev);
@@ -357,6 +358,7 @@ void pci_bus_add_device(struct pci_dev *dev)
 			pci_err(dev, "failed to populate child OF nodes (%d)\n",
 				retval);
 	}
+#endif
 }
 EXPORT_SYMBOL_GPL(pci_bus_add_device);
 

--
2.45.2

The mentioned error message occur on systems without CONFIG_OF, i.e. x86_64. The call to of_platform_depopulate() in drivers/pci/remove.c does not need #ifdef CONFIG_OF as the return value is not checked (it will most likely be optimized away on platforms witout OF where the of_platform_{de,}populate() functions just return -ENODEV)

Please CC me when replying, I'm not subscribed to the lists.

Bert Karwatzki

#5 lore raw

Re: [PATCH] pci: bus: only call of_platform_populate() if CONFIG_OF is defined

Quoted 41 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
---
 drivers/pci/bus.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/bus.c +2 -1
index e4735428814d..b363010664cd 100644
@@ -350,6 +350,7 @@ void pci_bus_add_device(struct pci_dev *dev)
 
        pci_dev_assign_added(dev, true);
 
+#ifdef CONFIG_OF
        if (pci_is_bridge(dev)) {
                retval = of_platform_populate(dev->dev.of_node, NULL, NULL,
                                              &dev->dev);
@@ -357,6 +358,7 @@ void pci_bus_add_device(struct pci_dev *dev)
                        pci_err(dev, "failed to populate child OF nodes (%d)\n",
                                retval);
        }
+#endif
 }
 EXPORT_SYMBOL_GPL(pci_bus_add_device);
 
--

2.45.2

The mentioned error message occur on systems without CONFIG_OF, i.e. x86_64. The call to of_platform_depopulate() in drivers/pci/remove.c does not need #ifdef CONFIG_OF as the return value is not checked (it will most likely be optimized away on platforms witout OF where the of_platform_{de,}populate() functions just return -ENODEV)

Quoted 3 lines

Please CC me when replying, I'm not subscribed to the lists.

Bert Karwatzki

There's a better (less ifdeffery) fix on the list that I'll pick up later today[1].

Bart

[1] https://lore.kernel.org/lkml/[email protected]/T/

#6 lore raw

Re: [PATCH] pci: bus: only call of_platform_populate() if CONFIG_OF is defined

Quoted 18 lines · Bartosz Golaszewski
Quoted 17 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
---
 drivers/pci/bus.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/bus.c +0 -0
index e4735428814d..b363010664cd 100644
@@ -350,6 +350,7 @@ void pci_bus_add_device(struct pci_dev *dev)
 
Quoted 4 lines

drivers/pci/bus.c void pci_bus_add_device(struct pci_dev *dev) · line 354

Quoted 4 lines
drivers/pci/bus.c +1 -0
        pci_dev_assign_added(dev, true);
 
+#ifdef CONFIG_OF
        if (pci_is_bridge(dev)) {

Per section 21 of Documentation/process/coding-style.rst, IS_ENABLED() is strongly preferred to #ifdef.

Quoted 4 lines

There's a better (less ifdeffery) fix on the list that I'll pick up later today[1].

[1] https://lore.kernel.org/lkml/[email protected]/T/

That other fix doesn't feel very robust as it depends on of_platform_populate() never returning -ENODEV in the CONFIG_OF=y case.

Thanks,

Lukas

#7 lore raw

Re: [PATCH] pci: bus: only call of_platform_populate() if CONFIG_OF is defined

Quoted 29 lines · Lukas Wunner
Quoted 18 lines · Bartosz Golaszewski
Quoted 17 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
---
 drivers/pci/bus.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/pci/bus.c +0 -0
index e4735428814d..b363010664cd 100644
@@ -350,6 +350,7 @@ void pci_bus_add_device(struct pci_dev *dev)
 
Quoted 4 lines

drivers/pci/bus.c void pci_bus_add_device(struct pci_dev *dev) · line 354

Quoted 4 lines
drivers/pci/bus.c +1 -0
        pci_dev_assign_added(dev, true);
 
+#ifdef CONFIG_OF
        if (pci_is_bridge(dev)) {

Per section 21 of Documentation/process/coding-style.rst, IS_ENABLED() is strongly preferred to #ifdef.

Quoted 9 lines
Quoted 4 lines

There's a better (less ifdeffery) fix on the list that I'll pick up later today[1].

[1] https://lore.kernel.org/lkml/[email protected]/T/

That other fix doesn't feel very robust as it depends on of_platform_populate() never returning -ENODEV in the CONFIG_OF=y case.

If we even have to play these ifdef games then the stubs for of_platform_populate() are broken and should probably return 0 with !OF as otherwise the stubs themselves are useless.

Bart

#8 lore raw

Re: [PATCH] pci: bus: only call of_platform_populate() if CONFIG_OF is defined

Quoted 7 lines · Bartosz Golaszewski
Quoted 6 lines · On Sat, Jul 6, 2024 at 10:43???AM Lukas Wunner <[email protected]> wrote:
Quoted 5 lines · Bartosz Golaszewski
Quoted 4 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

[...]

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

drivers/pci/bus.c void pci_bus_add_device(struct pci_dev *dev) · line 354

Quoted 8 lines
drivers/pci/bus.c +1 -0
@@ -350,6 +350,7 @@ void pci_bus_add_device(struct pci_dev *dev)
 
        pci_dev_assign_added(dev, true);
 
+#ifdef CONFIG_OF
        if (pci_is_bridge(dev)) {

There's a better (less ifdeffery) fix on the list that I'll pick up later today[1].

[1] https://lore.kernel.org/lkml/[email protected]/T/

Quoted 7 lines
Quoted 3 lines

That other fix doesn't feel very robust as it depends on of_platform_populate() never returning -ENODEV in the CONFIG_OF=y case.

If we even have to play these ifdef games then the stubs for of_platform_populate() are broken and should probably return 0 with !OF as otherwise the stubs themselves are useless.

The stub was introduced by commit 964dba283439 ("devicetree: Add empty of_platform_populate() for !CONFIG_OF_ADDRESS (sparc)") some twelve years ago.

From a brief look I'm under the impression that the commit used -ENODEV on purpose (instead of 0).

There are 100 files in the kernel source tree referencing of_platform_populate(). The majority is probably not compiled in the CONFIG_OF=n case, nevertheless changing the stub risks regressing some of those 100 callers unless great care is observed.

Just making this conditional on IS_ENABLED(CONFIG_OF) is the least risky option.

Thanks,

Lukas

#9 lore raw

PATCH v2 1/1 pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
---
 drivers/pci/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/bus.c +1 -1
index e4735428814d..3bab78cc68f7 100644
@@ -350,7 +350,7 @@ void pci_bus_add_device(struct pci_dev *dev)
 
 	pci_dev_assign_added(dev, true);
 
-	if (pci_is_bridge(dev)) {
+	if (IS_ENABLED(CONFIG_OF) && pci_is_bridge(dev)) {
 		retval = of_platform_populate(dev->dev.of_node, NULL, NULL,
 					      &dev->dev);
 		if (retval)

--
2.45.2

Just in case this is needed.

Bert Karwatzki

Reviewed-by on v2 1/1
#10 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 8 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
#11 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Hello,

Quoted 5 lines
Quoted 5 lines

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Quoted 8 lines
Quoted 3 lines
Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")

If there aren't any objections, I will take this via the PCI tree, and add the missing tags. So, no need to send a new version of this patch.

Thank you for the work here! Appreciated.

Krzysztof

#12 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 17 lines · Krzysztof Wilczyński

Hello,

Quoted 5 lines
Quoted 5 lines

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Quoted 8 lines
Quoted 3 lines
Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")
Quoted 6 lines

If there aren't any objections, I will take this via the PCI tree, and add the missing tags. So, no need to send a new version of this patch.

Thank you for the work here! Appreciated.

Krzysztof

I don't think you can take it via the PCI tree as it depends on the changes that went via the new pwrseq tree (with Bjorn's blessing). Please leave your Ack here and I will take it with the other PCI pwrctl changes.

After the upcoming merge window we should go back to normal.

Bart

Acked-by on v2 1/1
#23 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

In reply to Bert Karwatzki
Quoted 8 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")

- Mani

Quoted 24 lines
---
 drivers/pci/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/bus.c +1 -2
index e4735428814d..3bab78cc68f7 100644
@@ -350,7 +350,7 @@ void pci_bus_add_device(struct pci_dev *dev)
 
 	pci_dev_assign_added(dev, true);
 
-	if (pci_is_bridge(dev)) {
+	if (IS_ENABLED(CONFIG_OF) && pci_is_bridge(dev)) {
 		retval = of_platform_populate(dev->dev.of_node, NULL, NULL,
 					      &dev->dev);
 		if (retval)
--

2.45.2

Just in case this is needed.

Bert Karwatzki

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#13 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

In reply to Bartosz Golaszewski

[...]

Quoted 9 lines
Quoted 6 lines

If there aren't any objections, I will take this via the PCI tree, and add the missing tags. So, no need to send a new version of this patch.

Thank you for the work here! Appreciated.

Krzysztof

I don't think you can take it via the PCI tree as it depends on the changes that went via the new pwrseq tree (with Bjorn's blessing).

Aye.

Quoted 2 lines

Please leave your Ack here and I will take it with the other PCI pwrctl changes.

Sounds good! With that...

Quoted 1 line

After the upcoming merge window we should go back to normal.

Thank you!

Krzysztof

author Applied
#24 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

In reply to Bert Karwatzki

From: Bartosz Golaszewski <[email protected]>

Quoted 8 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")

[...]

Applied, thanks!

[1/1] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled
(no commit info)

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
#25 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 10 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Quoted 5 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Quoted 9 lines
Quoted 3 lines
Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")

[...]

Applied, thanks!

[1/1] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled
(no commit info)

The commit is here[1], not sure why b4 didn't pick it up.

Bart

[1] https://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux.git/commit/?h=pwrseq/for-next&id=10a0e6c2a8fc0d4b7e8e684654e920ea55527f3b

Quoted 3 lines

Best regards,
--
Bartosz Golaszewski <[email protected]>

#14 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

In reply to Krzysztof Wilczyński
Quoted 18 lines · Krzysztof Wilczyński

[...]

Quoted 9 lines
Quoted 6 lines

If there aren't any objections, I will take this via the PCI tree, and add the missing tags. So, no need to send a new version of this patch.

Thank you for the work here! Appreciated.

Krzysztof

I don't think you can take it via the PCI tree as it depends on the changes that went via the new pwrseq tree (with Bjorn's blessing).

Aye.

Quoted 2 lines

Please leave your Ack here and I will take it with the other PCI pwrctl changes.

Sounds good! With that...

Quoted 7 lines
Quoted 1 line

After the upcoming merge window we should go back to normal.

Thank you!

Krzysztof

FWIW this other patch makes it quieter too.

https://lore.kernel.org/linux-pci/[email protected]/

#15 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 24 lines · Mario Limonciello
Quoted 22 lines · Krzysztof Wilczyński

[...]

Quoted 9 lines
Quoted 6 lines

If there aren't any objections, I will take this via the PCI tree, and add the missing tags. So, no need to send a new version of this patch.

Thank you for the work here! Appreciated.

Krzysztof

I don't think you can take it via the PCI tree as it depends on the changes that went via the new pwrseq tree (with Bjorn's blessing).

Aye.

Quoted 2 lines

Please leave your Ack here and I will take it with the other PCI pwrctl changes.

Sounds good! With that...

Quoted 1 line

After the upcoming merge window we should go back to normal.

Quoted 7 lines
Quoted 3 lines

Thank you!

Krzysztof

FWIW this other patch makes it quieter too.

https://lore.kernel.org/linux-pci/[email protected]/

I had applied it previously but backed it out in favor of the new one.

Bart

#16 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 27 lines · Bartosz Golaszewski
Quoted 26 lines · Mario Limonciello
Quoted 24 lines · Krzysztof Wilczyński

[...]

Quoted 9 lines
Quoted 6 lines

If there aren't any objections, I will take this via the PCI tree, and add the missing tags. So, no need to send a new version of this patch.

Thank you for the work here! Appreciated.

Krzysztof

I don't think you can take it via the PCI tree as it depends on the changes that went via the new pwrseq tree (with Bjorn's blessing).

Aye.

Quoted 2 lines

Please leave your Ack here and I will take it with the other PCI pwrctl changes.

Sounds good! With that...

Quoted 1 line

After the upcoming merge window we should go back to normal.

Thank you!

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Krzysztof

FWIW this other patch makes it quieter too.

https://lore.kernel.org/linux-pci/[email protected]/

I had applied it previously but backed it out in favor of the new one.

That sounds sensible. The patch referenced above still causes of_platform_populate() to be called on non-OF platforms, which is not optimal.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#17 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 32 lines · Manivannan Sadhasivam
Quoted 31 lines · Bartosz Golaszewski
Quoted 30 lines · Mario Limonciello
Quoted 18 lines · Krzysztof Wilczyński

[...]

Quoted 9 lines
Quoted 6 lines

If there aren't any objections, I will take this via the PCI tree, and add the missing tags. So, no need to send a new version of this patch.

Thank you for the work here! Appreciated.

Krzysztof

I don't think you can take it via the PCI tree as it depends on the changes that went via the new pwrseq tree (with Bjorn's blessing).

Aye.

Quoted 2 lines

Please leave your Ack here and I will take it with the other PCI pwrctl changes.

Sounds good! With that...

Quoted 7 lines
Quoted 1 line

After the upcoming merge window we should go back to normal.

Thank you!

Krzysztof

FWIW this other patch makes it quieter too.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

https://lore.kernel.org/linux-pci/[email protected]/

I had applied it previously but backed it out in favor of the new one.

That sounds sensible. The patch referenced above still causes of_platform_populate() to be called on non-OF platforms, which is not optimal.

But couldn't I just as well have CONFIG_OF enabled in my kconfig and get the same new noise?

Quoted 3 lines

- Mani

#18 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 36 lines · Mario Limonciello
Quoted 34 lines · Manivannan Sadhasivam
Quoted 33 lines · Bartosz Golaszewski
Quoted 31 lines · Mario Limonciello
Quoted 18 lines · Krzysztof Wilczyński

[...]

Quoted 9 lines
Quoted 6 lines

If there aren't any objections, I will take this via the PCI tree, and add the missing tags. So, no need to send a new version of this patch.

Thank you for the work here! Appreciated.

Krzysztof

I don't think you can take it via the PCI tree as it depends on the changes that went via the new pwrseq tree (with Bjorn's blessing).

Aye.

Quoted 2 lines

Please leave your Ack here and I will take it with the other PCI pwrctl changes.

Sounds good! With that...

Quoted 7 lines
Quoted 1 line

After the upcoming merge window we should go back to normal.

Thank you!

Krzysztof

FWIW this other patch makes it quieter too.

https://lore.kernel.org/linux-pci/[email protected]/

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

I had applied it previously but backed it out in favor of the new one.

That sounds sensible. The patch referenced above still causes of_platform_populate() to be called on non-OF platforms, which is not optimal.

But couldn't I just as well have CONFIG_OF enabled in my kconfig and get the same new noise?

If you have CONFIG_OF enabled then of_platform_populate() will go the normal path and actually try to populate sub-nodes of the host bridge node. If there are no OF nodes (not a device-tree system) then it will fail.

Bart

#19 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 7 lines · Bartosz Golaszewski

If you have CONFIG_OF enabled then of_platform_populate() will go the normal path and actually try to populate sub-nodes of the host bridge node. If there are no OF nodes (not a device-tree system) then it will fail.

Bart

So how about keep both patches then?

#20 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 4 lines · Mario Limonciello
Quoted 1 line · Bartosz Golaszewski
Quoted 8 lines
Quoted 6 lines

If you have CONFIG_OF enabled then of_platform_populate() will go the normal path and actually try to populate sub-nodes of the host bridge node. If there are no OF nodes (not a device-tree system) then it will fail.

Bart

So how about keep both patches then?

No, it doesn't make sense. If CONFIG_OF is enabled then -ENODEV is a valid error. I was wrong to apply the previous patch as it would lead to hiding actual errors on OF-enabled systems.

Bart

#22 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

In reply to Mario Limonciello
Quoted 11 lines · Mario Limonciello
Quoted 7 lines · Bartosz Golaszewski

If you have CONFIG_OF enabled then of_platform_populate() will go the normal path and actually try to populate sub-nodes of the host bridge node. If there are no OF nodes (not a device-tree system) then it will fail.

Bart

So how about keep both patches then?

Why would anyone running non OF system have CONFIG_OF enabled? If that's the case, they have to see the error because there would be no DT nodes.

- Mani

Signature · 1 line
மணிவண்ணன் சதாசிவம்
#21 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

In reply to Bartosz Golaszewski
Quoted 12 lines · Bartosz Golaszewski
Quoted 11 lines · Mario Limonciello
Quoted 7 lines · Bartosz Golaszewski

If you have CONFIG_OF enabled then of_platform_populate() will go the normal path and actually try to populate sub-nodes of the host bridge node. If there are no OF nodes (not a device-tree system) then it will fail.

Bart

Quoted 7 lines
Quoted 1 line

So how about keep both patches then?

No, it doesn't make sense. If CONFIG_OF is enabled then -ENODEV is a valid error. I was wrong to apply the previous patch as it would lead to hiding actual errors on OF-enabled systems.

Bart

Got it; thanks.

#26 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

In reply to Bert Karwatzki
Quoted 8 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")

I didn't trace all the history of this patch so I don't know whether it's in or out. If it hasn't been applied yet or will be revised, run "git log --oneline drivers/pci/bus.c" and match the style, e.g.,

PCI/pwrctl: Call of_platform_populate() only when CONFIG_OF enabled

This would also match the 8fb18619d910 subject so it's more obvious they are connected.

Bjorn

#27 lore raw

Re: [PATCH v2] pci: bus: only call of_platform_populate() if CONFIG_OF is enabled

Quoted 15 lines · Bjorn Helgaas
Quoted 8 lines · Bert Karwatzki

If of_platform_populate() is called when CONFIG_OF is not defined this leads to spurious error messages of the following type:
pci 0000:00:01.1: failed to populate child OF nodes (-19) pci 0000:00:02.1: failed to populate child OF nodes (-19)

Fixes 8fb18619d910 ("PCI/pwrctl: Create platform devices for child OF nodes of the port node")

I didn't trace all the history of this patch so I don't know whether it's in or out. If it hasn't been applied yet or will be revised, run "git log --oneline drivers/pci/bus.c" and match the style, e.g.,

Quoted 7 lines

PCI/pwrctl: Call of_platform_populate() only when CONFIG_OF enabled

This would also match the 8fb18619d910 subject so it's more obvious they are connected.

Bjorn

Good point. I updated the commit title in my pwrseq branch.

Bart

#29 lore raw

Re: [PATCH v9 4/5] PCI/pwrctl: Add PCI power control core code

In reply to Bartosz Golaszewski
Quoted 11 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Some PCI devices must be powered-on before they can be detected on the bus. Introduce a simple framework reusing the existing PCI OF infrastructure.

include/linux/pci-pwrctl.h new file +5 -0
+/**
+ * struct pci_pwrctl - PCI device power control context.
+ * @dev: Address of the power controlling device.
+ *
+ * An object of this type must be allocated by the PCI power control device and

include/linux/pci-pwrctl.h line 44

Quoted 10 lines
include/linux/pci-pwrctl.h new file +10 -0
+ * passed to the pwrctl subsystem to trigger a bus rescan and setup a device
+ * link with the device once it's up.
+ */
+struct pci_pwrctl {
+	struct device *dev;
+
+	/* Private: don't use. */
+	struct notifier_block nb;
+	struct device_link *link;
+};

This is old and I should have noticed before, but we have partial kernel-doc for this struct:

  $ find include -name \*pci\* | xargs scripts/kernel-doc -none
  Warning: include/linux/pci-pwrctrl.h:45 struct member 'nb' not described in 'pci_pwrctrl'
  Warning: include/linux/pci-pwrctrl.h:45 struct member 'link' not described in 'pci_pwrctrl'
  Warning: include/linux/pci-pwrctrl.h:45 struct member 'work' not described in 'pci_pwrctrl'
#30 lore raw

Re: [PATCH v9 4/5] PCI/pwrctl: Add PCI power control core code

Quoted 27 lines · Bjorn Helgaas
Quoted 11 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Some PCI devices must be powered-on before they can be detected on the bus. Introduce a simple framework reusing the existing PCI OF infrastructure.

include/linux/pci-pwrctl.h new file +5 -0
+/**
+ * struct pci_pwrctl - PCI device power control context.
+ * @dev: Address of the power controlling device.
+ *
+ * An object of this type must be allocated by the PCI power control device and

include/linux/pci-pwrctl.h line 44

Quoted 10 lines
include/linux/pci-pwrctl.h new file +10 -0
+ * passed to the pwrctl subsystem to trigger a bus rescan and setup a device
+ * link with the device once it's up.
+ */
+struct pci_pwrctl {
+     struct device *dev;
+
+     /* Private: don't use. */
+     struct notifier_block nb;
+     struct device_link *link;
+};

This is old and I should have noticed before, but we have partial kernel-doc for this struct:

Quoted 5 lines
  $ find include -name \*pci\* | xargs scripts/kernel-doc -none
  Warning: include/linux/pci-pwrctrl.h:45 struct member 'nb' not described in 'pci_pwrctrl'
  Warning: include/linux/pci-pwrctrl.h:45 struct member 'link' not described in 'pci_pwrctrl'
  Warning: include/linux/pci-pwrctrl.h:45 struct member 'work' not described in 'pci_pwrctrl'

I didn't want to document these as they're not part of the API. Probably should have been "/* private: internal use only */". I will check and send a patch.

Bart