Skip to contentSkip to conversation

PCI: Explicitly put devices into D0 when initializing

PATCH Superseded Mario Limonciello 3 participants 3 messages Apr 22, 2025 – Apr 23, 2025 PCI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Explicitly put devices into D0 when initializing

From: Mario Limonciello <[email protected]>

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

---
Note: an earlier internal version of this attempted to do this in local_pci_probe() but this doesn't affect PCI root ports and we need _REG called on the root ports too.

 drivers/pci/pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/pci.c +1 -0
index 53a070394739a..cd87c8370dede 100644
@@ -3266,6 +3266,7 @@ 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_set_power_state(dev, PCI_D0);
 }
 
 static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 30 lines · Mario Limonciello

From: Mario Limonciello <[email protected]>

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

---
Note: an earlier internal version of this attempted to do this in local_pci_probe() but this doesn't affect PCI root ports and we need _REG called on the root ports too.

  drivers/pci/pci.c | 1 +
  1 file changed, 1 insertion(+)
drivers/pci/pci.c +0 -0
index 53a070394739a..cd87c8370dede 100644

drivers/pci/pci.c void pci_pm_init(struct pci_dev *dev) · line 3269

Quoted 4 lines
drivers/pci/pci.c +1 -0
@@ -3266,6 +3266,7 @@ 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_set_power_state(dev, PCI_D0);

I'd rather not do this after enabling runtime PM, but at the same time doing it before setting up PM would be rather unsafe.

I'd move the pm_runtime_forbid(), pm_runtime_set_active(), and pm_runtime_enable() sequence of calls after the pci_set_power_state() call above.

Quoted 3 lines
drivers/pci/pci.c +0 -0
  }
 
  static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)
#2 lore raw
Quoted 41 lines · Rafael J
Quoted 30 lines · Mario Limonciello

From: Mario Limonciello <[email protected]>

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

---
Note: an earlier internal version of this attempted to do this in local_pci_probe() but this doesn't affect PCI root ports and we need _REG called on the root ports too.

  drivers/pci/pci.c | 1 +
  1 file changed, 1 insertion(+)
drivers/pci/pci.c +0 -0
index 53a070394739a..cd87c8370dede 100644

drivers/pci/pci.c void pci_pm_init(struct pci_dev *dev) · line 3269

Quoted 4 lines
drivers/pci/pci.c +1 -0
@@ -3266,6 +3266,7 @@ 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_set_power_state(dev, PCI_D0);

I'd rather not do this after enabling runtime PM, but at the same time doing it before setting up PM would be rather unsafe.

Quoted 3 lines

I'd move the pm_runtime_forbid(), pm_runtime_set_active(), and pm_runtime_enable() sequence of calls after the pci_set_power_state() call above.

Also, I think that pci_pm_power_up_and_verify_state() would be more suitable for this initial power up because power_state is already 0 at this point and this case is analogous to post-resume.