[PATCH v2 4/8] PCI: Change the parent to correctly represent pcie hierarchy

Krishna chaitanya chundru
2024-08-03T03:32:29Z

Currently the pwrctl driver is child of pci-pci bridge driver,
this will cause issue when suspend resume is introduced in the pwr
control driver. If the supply is removed to the endpoint in the
power control driver then the config space access by the
pci-pci bridge driver can cause issues like Timeouts.

For this reason change the parent to controller from pci-pci bridge.

Fixes: 4565d2652a37 ("PCI/pwrctl: Add PCI power control core code")
Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com>
---
drivers/pci/bus.c | 3 ++-
drivers/pci/pwrctl/core.c | 9 ++++++++-
2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 55c853686051..15b42f0f588f 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -328,6 +328,7 @@ void __weak pcibios_bus_add_device(struct pci_dev *pdev) { }
*/
void pci_bus_add_device(struct pci_dev *dev)
{
+ struct pci_host_bridge *host = pci_find_host_bridge(dev->bus);
struct device_node *dn = dev->dev.of_node;
int retval;

@@ -352,7 +353,7 @@ void pci_bus_add_device(struct pci_dev *dev)

if (dev_of_node(&dev->dev) && pci_is_bridge(dev)) {
retval = of_platform_populate(dev_of_node(&dev->dev), NULL, NULL,
- &dev->dev);
+ host->dev.parent);
if (retval)
pci_err(dev, "failed to populate child OF nodes (%d)\n",
retval);
diff --git a/drivers/pci/pwrctl/core.c b/drivers/pci/pwrctl/core.c
index feca26ad2f6a..4f2ffa0b0a5f 100644
--- a/drivers/pci/pwrctl/core.c
+++ b/drivers/pci/pwrctl/core.c
@@ -11,6 +11,8 @@
#include <linux/property.h>
#include <linux/slab.h>

+#include "../pci.h"
+
static int pci_pwrctl_notify(struct notifier_block *nb, unsigned long action,
void *data)
{
@@ -64,18 +66,23 @@ static int pci_pwrctl_notify(struct notifier_block *nb, unsigned long action,
*/
int pci_pwrctl_device_set_ready(struct pci_pwrctl *pwrctl)
{
+ struct pci_bus *bus;
int ret;

if (!pwrctl->dev)
return -ENODEV;

+ bus = pci_find_bus(of_get_pci_domain_nr(pwrctl->dev->parent->of_node), 0);
+ if (!bus)
+ return -ENODEV;
+
pwrctl->nb.notifier_call = pci_pwrctl_notify;
ret = bus_register_notifier(&pci_bus_type, &pwrctl->nb);
if (ret)
return ret;

pci_lock_rescan_remove();
- pci_rescan_bus(to_pci_dev(pwrctl->dev->parent)->bus);
+ pci_rescan_bus(bus);
pci_unlock_rescan_remove();

return 0;

--
2.34.1