PCI: Explicitly put devices into D0 when initializing
authorMario Limonciello <mario.limonciello@amd.com>
Thu, 24 Apr 2025 04:31:32 +0000 (23:31 -0500)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 5 May 2025 23:04:44 +0000 (18:04 -0500)
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.

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.

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>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Tested-by: Denis Benato <benato.denis96@gmail.com>
Tested-By: Yijun Shen <Yijun_Shen@Dell.com>
Tested-By: David Perry <david.perry@amd.com>
Reviewed-by: Rafael J. Wysocki <rafael@kernel.org>
Link: https://patch.msgid.link/20250424043232.1848107-1-superm1@kernel.org
drivers/pci/pci-driver.c
drivers/pci/pci.c
drivers/pci/pci.h

index c8bd71a739f724e09b4dd773fb0cf74bddda1728..082918ce03d8a0ee84a638f86dcc6dec0a83646d 100644 (file)
@@ -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);
index 4d7c9f64ea24ec754a135a2585c99489cfa641a9..cd51c6454d1be8c2ec9a6d96ee80c3988ce6b8e7 100644 (file)
@@ -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)
index b81e99cd4b62a3022c8b07a09f212f6888674487..49165b739138bae0dae6774d515379667d2f678e 100644 (file)
@@ -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);