pci-v6.11-fixes-3

-----BEGIN PGP SIGNATURE-----
 
 iQJIBAABCgAyFiEEgMe7l+5h9hnxdsnuWYigwDrT+vwFAmbbV3kUHGJoZWxnYWFz
 QGdvb2dsZS5jb20ACgkQWYigwDrT+vzzZg//TStL7op+bZCbMSB2SHtKJAuAWiXa
 44g9Wi5ubCqwnWbx3H81NlNp2OsqmSh/niMRlVIRooDiS/J8JBT8SwSw9nopEhhb
 U0xcpGlIQjZbue0Zp3nhOohYBl+P/SpZqCojkWCKhfVDgR4ft1HjlaORcxoX5Suk
 cpR1iGqFH8kWk0X5Mo3GJCveNSIWGBJXX+IIENVJO3sc4n4wdpSIQRCq7whYQivA
 G0tFIBYYY164rVhVslFvO4zwFM1RgbskFqOb6St3mPMYqn0NptM2FoOzefdILqo6
 3qRkQnm1om6u+9qnyn7br+RYofaOFtzhIgulLJvjSHa7jxVubgNdOZtF3hls+e02
 F6Cg89GgPrnkpt+kvLG097vsCoVxwS8wa31mYBvXy8HZ4RQ5/4LQ1j2Dlad51ZbL
 fxOzRSyui//RoaexxvwrsvoQOEYYxUL5VxhonU3bLLEfYVU2I4apT+JtQO1iBiEC
 83pnha0ELDPl/sBdV/kfNBp8OEUvMSbjzBes1sCecnvKtHAVTisS0FXXnyU25KPU
 aZU+sn7915wfilNe7wQPwW8LUMt1kcgFDI9aD3eKS8m/cxENProAJPk2vNEM9UhO
 iWEGLOABb7Bq+Y3etFg9Ds9WF+25oojYoTEwn+Vk2Xwyx83BCDIsyjyvFd0RbtS0
 2QH/YCtEpCD7qiA=
 =JNeL
 -----END PGP SIGNATURE-----

Merge tag 'pci-v6.11-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci

Pull pci fixes from Bjorn Helgaas:

 - Unregister platform devices for child nodes when stopping a PCI
   device, even if the PCI core has already cleared the OF_POPULATED bit
   and of_platform_depopulate() doesn't do anything (Bartosz
   Golaszewski)

 - Rescan the bus from a separate thread so we don't deadlock when
   triggering rescan from sysfs (Bartosz Golaszewski)

* tag 'pci-v6.11-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci:
  PCI/pwrctl: Rescan bus on a separate thread
  PCI: Don't rely on of_platform_depopulate() for reused OF-nodes
This commit is contained in:
Linus Torvalds 2024-09-06 17:38:50 -07:00
commit 487ee43bac
4 changed files with 44 additions and 5 deletions

View File

@ -48,6 +48,28 @@ static int pci_pwrctl_notify(struct notifier_block *nb, unsigned long action,
return NOTIFY_DONE;
}
static void rescan_work_func(struct work_struct *work)
{
struct pci_pwrctl *pwrctl = container_of(work, struct pci_pwrctl, work);
pci_lock_rescan_remove();
pci_rescan_bus(to_pci_dev(pwrctl->dev->parent)->bus);
pci_unlock_rescan_remove();
}
/**
* pci_pwrctl_init() - Initialize the PCI power control context struct
*
* @pwrctl: PCI power control data
* @dev: Parent device
*/
void pci_pwrctl_init(struct pci_pwrctl *pwrctl, struct device *dev)
{
pwrctl->dev = dev;
INIT_WORK(&pwrctl->work, rescan_work_func);
}
EXPORT_SYMBOL_GPL(pci_pwrctl_init);
/**
* pci_pwrctl_device_set_ready() - Notify the pwrctl subsystem that the PCI
* device is powered-up and ready to be detected.
@ -74,9 +96,7 @@ int pci_pwrctl_device_set_ready(struct pci_pwrctl *pwrctl)
if (ret)
return ret;
pci_lock_rescan_remove();
pci_rescan_bus(to_pci_dev(pwrctl->dev->parent)->bus);
pci_unlock_rescan_remove();
schedule_work(&pwrctl->work);
return 0;
}

View File

@ -50,7 +50,7 @@ static int pci_pwrctl_pwrseq_probe(struct platform_device *pdev)
if (ret)
return ret;
data->ctx.dev = dev;
pci_pwrctl_init(&data->ctx, dev);
ret = devm_pci_pwrctl_device_set_ready(dev, &data->ctx);
if (ret)

View File

@ -1,7 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
#include <linux/pci.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include "pci.h"
static void pci_free_resources(struct pci_dev *dev)
@ -14,12 +17,25 @@ static void pci_free_resources(struct pci_dev *dev)
}
}
static int pci_pwrctl_unregister(struct device *dev, void *data)
{
struct device_node *pci_node = data, *plat_node = dev_of_node(dev);
if (dev_is_platform(dev) && plat_node && plat_node == pci_node) {
of_device_unregister(to_platform_device(dev));
of_node_clear_flag(plat_node, OF_POPULATED);
}
return 0;
}
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_for_each_child(dev->dev.parent, dev_of_node(&dev->dev),
pci_pwrctl_unregister);
device_release_driver(&dev->dev);
pci_proc_detach_device(dev);
pci_remove_sysfs_dev_files(dev);

View File

@ -7,6 +7,7 @@
#define __PCI_PWRCTL_H__
#include <linux/notifier.h>
#include <linux/workqueue.h>
struct device;
struct device_link;
@ -41,8 +42,10 @@ struct pci_pwrctl {
/* Private: don't use. */
struct notifier_block nb;
struct device_link *link;
struct work_struct work;
};
void pci_pwrctl_init(struct pci_pwrctl *pwrctl, struct device *dev);
int pci_pwrctl_device_set_ready(struct pci_pwrctl *pwrctl);
void pci_pwrctl_device_unset_ready(struct pci_pwrctl *pwrctl);
int devm_pci_pwrctl_device_set_ready(struct device *dev,