UPSTREAM: PCI: Restore config space on runtime resume despite being unbound

We leave PCI devices not bound to a driver in D0 during runtime suspend.
But they may have a parent which is bound and can be transitioned to
D3cold at runtime.  Once the parent goes to D3cold, the unbound child
may go to D3cold as well.  When the child goes to D3cold, its internal
state, including configuration of BARs, MSI, ASPM, MPS, etc., is lost.

One example are recent hybrid graphics laptops which cut power to the
discrete GPU when the root port above it goes to ACPI power state D3.
Users may provoke this by unbinding the GPU driver and allowing runtime
PM on the GPU via sysfs:  The PM core will then treat the GPU as
"suspended", which in turn allows the root port to runtime suspend,
causing the power resources listed in its _PR3 object to be powered off.
The GPU's BARs will be uninitialized when a driver later probes it.

Another example are hybrid graphics laptops where the GPU itself (rather
than the root port) is capable of runtime suspending to D3cold.  If the
GPU's integrated HDA controller is not bound and the GPU's driver
decides to runtime suspend to D3cold, the HDA controller's BARs will be
uninitialized when a driver later probes it.

Fix by saving and restoring config space over a runtime suspend cycle
even if the device is not bound.

Acked-by: Bjorn Helgaas <>
Tested-by: Peter Wu <>              # Nvidia Optimus
Tested-by: Lukas Wunner <>              # MacBook Pro
Signed-off-by: Rafael J. Wysocki <>
[lukas: add commit message, bikeshed code comments for clarity]
Signed-off-by: Lukas Wunner <>
(cherry picked from commit 5775b843a619b3c93f946e2b55a208d9f0f48b59)

TEST=tested that the BAR0 is restored properly on Coral devices.
Change-Id: Iaca03abce6d3ca40df9df2ed5681b9d393e0d5d4
Commit-Ready: Rajat Jain <>
Tested-by: Rajat Jain <>
Reviewed-by: Guenter Roeck <>
Reviewed-by: Furquan Shaikh <>
Reviewed-by: Kirtika Ruchandani <>
(cherry picked from commit cbd2bf1872ed7132a3bd30687b31563992e575e8)
Commit-Queue: Kirtika Ruchandani <>
Tested-by: Kirtika Ruchandani <>
Trybot-Ready: Kirtika Ruchandani <>
1 file changed