linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] PCI: Explicitly put devices into D0 when initializing
@ 2025-04-24  4:31 Mario Limonciello
  2025-04-24 15:07 ` Wysocki, Rafael J
                   ` (4 more replies)
  0 siblings, 5 replies; 19+ messages in thread
From: Mario Limonciello @ 2025-04-24  4:31 UTC (permalink / raw)
  To: mario.limonciello, bhelgaas, rafael.j.wysocki, huang.ying.caritas,
	stern
  Cc: linux-pci

From: Mario Limonciello <mario.limonciello@amd.com>

AMD BIOS team has root caused an issue that NVME storage failed to come
back from suspend to a lack of a call to _REG when NVME device was probed.

commit 112a7f9c8edbf ("PCI/ACPI: Call _REG when transitioning D-states")
added support for calling _REG when transitioning D-states, but this only
works if the device actually "transitions" D-states.

commit 967577b062417 ("PCI/PM: Keep runtime PM enabled for unbound PCI
devices") added support for runtime PM on PCI devices, but never actually
'explicitly' sets the device to D0.

To make sure that devices are in D0 and that platform methods such as
_REG are called, explicitly set all devices into D0 during initialization.

Fixes: 967577b062417 ("PCI/PM: Keep runtime PM enabled for unbound PCI devices")
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v2:
 * Move runtime PM calls after setting to D0
 * Use pci_pm_power_up_and_verify_state()
---
 drivers/pci/pci-driver.c |  6 ------
 drivers/pci/pci.c        | 13 ++++++++++---
 drivers/pci/pci.h        |  1 +
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index c8bd71a739f72..082918ce03d8a 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -555,12 +555,6 @@ static void pci_pm_default_resume(struct pci_dev *pci_dev)
 	pci_enable_wake(pci_dev, PCI_D0, false);
 }
 
-static void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev)
-{
-	pci_power_up(pci_dev);
-	pci_update_current_state(pci_dev, PCI_D0);
-}
-
 static void pci_pm_default_resume_early(struct pci_dev *pci_dev)
 {
 	pci_pm_power_up_and_verify_state(pci_dev);
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e77d5b53c0cec..8d125998b30b7 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -3192,6 +3192,12 @@ void pci_d3cold_disable(struct pci_dev *dev)
 }
 EXPORT_SYMBOL_GPL(pci_d3cold_disable);
 
+void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev)
+{
+	pci_power_up(pci_dev);
+	pci_update_current_state(pci_dev, PCI_D0);
+}
+
 /**
  * pci_pm_init - Initialize PM functions of given PCI device
  * @dev: PCI device to handle.
@@ -3202,9 +3208,6 @@ void pci_pm_init(struct pci_dev *dev)
 	u16 status;
 	u16 pmc;
 
-	pm_runtime_forbid(&dev->dev);
-	pm_runtime_set_active(&dev->dev);
-	pm_runtime_enable(&dev->dev);
 	device_enable_async_suspend(&dev->dev);
 	dev->wakeup_prepared = false;
 
@@ -3266,6 +3269,10 @@ void pci_pm_init(struct pci_dev *dev)
 	pci_read_config_word(dev, PCI_STATUS, &status);
 	if (status & PCI_STATUS_IMM_READY)
 		dev->imm_ready = 1;
+	pci_pm_power_up_and_verify_state(dev);
+	pm_runtime_forbid(&dev->dev);
+	pm_runtime_set_active(&dev->dev);
+	pm_runtime_enable(&dev->dev);
 }
 
 static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index b81e99cd4b62a..49165b739138b 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -148,6 +148,7 @@ void pci_dev_adjust_pme(struct pci_dev *dev);
 void pci_dev_complete_resume(struct pci_dev *pci_dev);
 void pci_config_pm_runtime_get(struct pci_dev *dev);
 void pci_config_pm_runtime_put(struct pci_dev *dev);
+void pci_pm_power_up_and_verify_state(struct pci_dev *pci_dev);
 void pci_pm_init(struct pci_dev *dev);
 void pci_ea_init(struct pci_dev *dev);
 void pci_msi_init(struct pci_dev *dev);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread
[parent not found: <BY5PR19MB3922D2994064085132D8FEBD9A822@BY5PR19MB3922.namprd19.prod.outlook.com>]

end of thread, other threads:[~2025-06-19  9:11 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-24  4:31 [PATCH v2] PCI: Explicitly put devices into D0 when initializing Mario Limonciello
2025-04-24 15:07 ` Wysocki, Rafael J
2025-04-24 18:20   ` Mario Limonciello
2025-04-27 12:54 ` Denis Benato
2025-05-05 19:20 ` Perry, David
2025-05-05 20:01   ` Mario Limonciello
2025-05-05 23:06 ` Bjorn Helgaas
2025-06-11 14:14   ` Nicolas Dichtel
2025-06-11 14:56     ` Mario Limonciello
2025-06-11 16:05       ` Alex Williamson
2025-06-11 12:52 ` [PATCH v2] PCI: Explicitly put devices into D0 when initializing - Bug report Cabiddu, Giovanni
2025-06-11 13:50   ` Mario Limonciello
2025-06-11 14:30     ` Cabiddu, Giovanni
2025-06-11 16:00     ` Alex Williamson
2025-06-11 16:13       ` Cabiddu, Giovanni
2025-06-11 20:45         ` Mario Limonciello
2025-06-11 22:07           ` Giovanni Cabiddu
2025-06-19  9:11           ` Alexey Kardashevskiy
     [not found] <BY5PR19MB3922D2994064085132D8FEBD9A822@BY5PR19MB3922.namprd19.prod.outlook.com>
2025-05-01 14:14 ` [PATCH v2] PCI: Explicitly put devices into D0 when initializing Shen, Yijun

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).