Skip to contentSkip to conversation

PCI/PM: RTD3 fixes/changes for 3.7

RFC In review Huang Ying 5 participants 15 messages Sep 17, 2012 – Sep 21, 2012

Subsystems (4)
lore
Share & tools
lore
author
#1 lore raw

RFC 1/3 PCI/PM: Fix kexec for D3cold and bridge suspending

In reply to Huang Ying

If PCI devices are put into D3cold before kexec, because the configuration registers of PCI devices in D3cold are not accessible.

And if PCI bridges are put into low power state before kexec, configuration registers of PCI devices underneath the PCI bridges are not accessible too.

These will make some PCI devices can not be scanned after kexec, so resume the PCI devices in D3cold or PCI bridges in low power state before kexec.

---
 drivers/pci/pci-driver.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-driver.c +4 -0
@@ -421,6 +421,10 @@ static void pci_device_shutdown(struct d
 	struct pci_dev *pci_dev = to_pci_dev(dev);
 	struct pci_driver *drv = pci_dev->driver;
 
+	/* Resume bridges and devices in D3cold for kexec to work properly */
+	if (pci_dev->current_state == PCI_D3cold || pci_dev->subordinate)
+		pm_runtime_resume(dev);
+
 	if (drv && drv->shutdown)
 		drv->shutdown(pci_dev);
 	pci_msi_shutdown(pci_dev);
author
#9 lore raw

RFC 2/3 PCI/PM: Make PCI devices notified when its power resource turned on

In reply to Huang Ying

A set of power resources may be shared by multiple devices. When all devices share one set of power resources is put into D3_COLD state, the power resources will be turned off. When one of the device is waked, the power resource will be turned on and all devices share it will be powered on to D0uninitialized state. These devices should be resumed, so that they can get opportunity to go to low power state later.

---
 drivers/acpi/pci_bind.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/pci_bind.c +2 -0
@@ -45,6 +45,7 @@ static int acpi_pci_unbind(struct acpi_d
 
 	device_set_run_wake(&dev->dev, false);
 	pci_acpi_remove_pm_notifier(device);
+	acpi_power_resource_unregister_device(dev, device->handle);
 
 	if (!dev->subordinate)
 		goto out;
@@ -71,6 +72,7 @@ static int acpi_pci_bind(struct acpi_dev
 		return 0;
 
 	pci_acpi_add_pm_notifier(device, dev);
+	acpi_power_resource_register_device(dev, device->handle);
 	if (device->wakeup.flags.run_wake)
 		device_set_run_wake(&dev->dev, true);
 

Huang Ying

author
#0 lore raw

cover PCI/PM: RTD3 fixes/changes for 3.7

[RFC 1/3] PCI/PM: Fix kexec for D3cold and bridge suspending [RFC 2/3] PCI/PM: Make PCI devices notified when its power [RFC 3/3] PCI/PM: Disable PME poll for PCIe devices

Best Regards,
Huang Ying

author
#11 lore raw

RFC 3/3 PCI/PM: Disable PME poll for PCIe devices

PME poll is not necessary for PCIe devices, because PCIe devices use in-band PME message and IRQ on PCIe port to report PME.

PME poll is useful for PCI devices. Because for PCI devices, PME is reported via a side-band PME# line and some platform logic, and the platform logic is often missing on many systems.

---
 drivers/pci/pcie/pme.c |    1 +
 1 file changed, 1 insertion(+)
drivers/pci/pcie/pme.c +1 -0
@@ -313,6 +313,7 @@ static int pcie_pme_set_native(struct pc
 
 	device_set_run_wake(&dev->dev, true);
 	dev->pme_interrupt = true;
+	dev->pme_poll = false;
 	return 0;
 }
 
maintainer
#2 lore raw

Re: [RFC 1/3] PCI/PM: Fix kexec for D3cold and bridge suspending

In reply to Huang Ying

+cc Eric and kexec list

Quoted 10 lines · Huang Ying

If PCI devices are put into D3cold before kexec, because the configuration registers of PCI devices in D3cold are not accessible.

And if PCI bridges are put into low power state before kexec, configuration registers of PCI devices underneath the PCI bridges are not accessible too.

These will make some PCI devices can not be scanned after kexec, so resume the PCI devices in D3cold or PCI bridges in low power state before kexec.

Don't we need to resume the device even without the kexec issue? And even if it's in D1 or D2?

It looks to me like pci_msi_shutdown() (and probably drv->shutdown()) depend on the device being in D0.

Quoted 18 lines
---
 drivers/pci/pci-driver.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-driver.c +4 -0
@@ -421,6 +421,10 @@ static void pci_device_shutdown(struct d
        struct pci_dev *pci_dev = to_pci_dev(dev);
        struct pci_driver *drv = pci_dev->driver;
 
+       /* Resume bridges and devices in D3cold for kexec to work properly */
+       if (pci_dev->current_state == PCI_D3cold || pci_dev->subordinate)
+               pm_runtime_resume(dev);
+
        if (drv && drv->shutdown)
                drv->shutdown(pci_dev);
        pci_msi_shutdown(pci_dev);
#3 lore raw

Re: [RFC 1/3] PCI/PM: Fix kexec for D3cold and bridge suspending

Quoted 10 lines · Bjorn Helgaas

+cc Eric and kexec list

Quoted 7 lines · Huang Ying

If PCI devices are put into D3cold before kexec, because the configuration registers of PCI devices in D3cold are not accessible.

And if PCI bridges are put into low power state before kexec, configuration registers of PCI devices underneath the PCI bridges are not accessible too.

Quoted 6 lines
Quoted 3 lines

These will make some PCI devices can not be scanned after kexec, so resume the PCI devices in D3cold or PCI bridges in low power state before kexec.

Don't we need to resume the device even without the kexec issue? And even if it's in D1 or D2?

The basic requirement is that the device needs to be visible so we can auto discover it. As I recall most sleep states don't make the device invisible and we can handle the rest in the device initializatoin code.

Quoted 2 lines

It looks to me like pci_msi_shutdown() (and probably drv->shutdown()) depend on the device being in D0.

There is certainly a depenency on the config registers being visible. Although I don't know if much will go wrong if they aren't.

Ceratinly pci_msi_shutdown doesn't have anything to do if the device has had so much power removed that the device is not even exectuing.

Eric

Quoted 23 lines
Quoted 8 lines
---
 drivers/pci/pci-driver.c |    4 ++++
 1 file changed, 4 insertions(+)

drivers/pci/pci-driver.c static void pci_device_shutdown(struct d · line 430

Quoted 10 lines
drivers/pci/pci-driver.c +4 -0
@@ -421,6 +421,10 @@ static void pci_device_shutdown(struct d
        struct pci_dev *pci_dev = to_pci_dev(dev);
        struct pci_driver *drv = pci_dev->driver;
 
+       /* Resume bridges and devices in D3cold for kexec to work properly */
+       if (pci_dev->current_state == PCI_D3cold || pci_dev->subordinate)
+               pm_runtime_resume(dev);
+
        if (drv && drv->shutdown)
                drv->shutdown(pci_dev);
        pci_msi_shutdown(pci_dev);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

author
#4 lore raw

Re: [RFC 1/3] PCI/PM: Fix kexec for D3cold and bridge suspending

Quoted 16 lines · Eric W. Biederman
Quoted 14 lines · Bjorn Helgaas

+cc Eric and kexec list

Quoted 10 lines · Huang Ying

If PCI devices are put into D3cold before kexec, because the configuration registers of PCI devices in D3cold are not accessible.

And if PCI bridges are put into low power state before kexec, configuration registers of PCI devices underneath the PCI bridges are not accessible too.

These will make some PCI devices can not be scanned after kexec, so resume the PCI devices in D3cold or PCI bridges in low power state before kexec.

Quoted 6 lines
Quoted 2 lines

Don't we need to resume the device even without the kexec issue? And even if it's in D1 or D2?

The basic requirement is that the device needs to be visible so we can auto discover it. As I recall most sleep states don't make the device invisible and we can handle the rest in the device initializatoin code.

PCI devices in D3cold or under a bridge in D3hot will not be visible, so we must fix that for kexec to run properly.

Quoted 8 lines
Quoted 2 lines

It looks to me like pci_msi_shutdown() (and probably drv->shutdown()) depend on the device being in D0.

There is certainly a depenency on the config registers being visible. Although I don't know if much will go wrong if they aren't.

Ceratinly pci_msi_shutdown doesn't have anything to do if the device has had so much power removed that the device is not even exectuing.

Don't know which power state device should be in for pci_msi_shutdown etc. But it appears that normal shutdown/reboot and kexec works at most times so far. D3cold and bridge in D3hot works for normal shutdown/reboot, but not for kexec. So I write some fix.

Best Regards,
Huang Ying

Quoted 23 lines
Quoted 23 lines
Quoted 8 lines
---
 drivers/pci/pci-driver.c |    4 ++++
 1 file changed, 4 insertions(+)

drivers/pci/pci-driver.c static void pci_device_shutdown(struct d · line 430

Quoted 10 lines
drivers/pci/pci-driver.c +4 -0
@@ -421,6 +421,10 @@ static void pci_device_shutdown(struct d
        struct pci_dev *pci_dev = to_pci_dev(dev);
        struct pci_driver *drv = pci_dev->driver;
 
+       /* Resume bridges and devices in D3cold for kexec to work properly */
+       if (pci_dev->current_state == PCI_D3cold || pci_dev->subordinate)
+               pm_runtime_resume(dev);
+
        if (drv && drv->shutdown)
                drv->shutdown(pci_dev);
        pci_msi_shutdown(pci_dev);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#5 lore raw

Re: [RFC 1/3] PCI/PM: Fix kexec for D3cold and bridge suspending

Quoted 20 lines · Huang Ying
Quoted 19 lines · Eric W. Biederman
Quoted 16 lines · Bjorn Helgaas

+cc Eric and kexec list

Quoted 10 lines · Huang Ying

If PCI devices are put into D3cold before kexec, because the configuration registers of PCI devices in D3cold are not accessible.

And if PCI bridges are put into low power state before kexec, configuration registers of PCI devices underneath the PCI bridges are not accessible too.

These will make some PCI devices can not be scanned after kexec, so resume the PCI devices in D3cold or PCI bridges in low power state before kexec.

Don't we need to resume the device even without the kexec issue? And even if it's in D1 or D2?

Quoted 6 lines
Quoted 3 lines

The basic requirement is that the device needs to be visible so we can auto discover it. As I recall most sleep states don't make the device invisible and we can handle the rest in the device initializatoin code.

PCI devices in D3cold or under a bridge in D3hot will not be visible, so we must fix that for kexec to run properly.

That seems reasonable to me.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

It looks to me like pci_msi_shutdown() (and probably drv->shutdown()) depend on the device being in D0.

There is certainly a depenency on the config registers being visible. Although I don't know if much will go wrong if they aren't.

Quoted 7 lines
Quoted 2 lines

Ceratinly pci_msi_shutdown doesn't have anything to do if the device has had so much power removed that the device is not even exectuing.

Don't know which power state device should be in for pci_msi_shutdown etc. But it appears that normal shutdown/reboot and kexec works at most times so far. D3cold and bridge in D3hot works for normal shutdown/reboot, but not for kexec. So I write some fix.

To be clear. Has someone picked up this patch yet?

As for reboot it tends to always work because frequently the firmware code triggers a soft reset of the entire machine, which puts devices in their power on reset state, which is not a suspended state. Although that behavior is not required for a software reboot.

Eric

Quoted 26 lines

Best Regards,
Huang Ying

Quoted 23 lines
Quoted 23 lines
Quoted 8 lines
---
 drivers/pci/pci-driver.c |    4 ++++
 1 file changed, 4 insertions(+)

drivers/pci/pci-driver.c static void pci_device_shutdown(struct d · line 430

Quoted 10 lines
drivers/pci/pci-driver.c +4 -0
@@ -421,6 +421,10 @@ static void pci_device_shutdown(struct d
        struct pci_dev *pci_dev = to_pci_dev(dev);
        struct pci_driver *drv = pci_dev->driver;
 
+       /* Resume bridges and devices in D3cold for kexec to work properly */
+       if (pci_dev->current_state == PCI_D3cold || pci_dev->subordinate)
+               pm_runtime_resume(dev);
+
        if (drv && drv->shutdown)
                drv->shutdown(pci_dev);
        pci_msi_shutdown(pci_dev);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#6 lore raw

Re: [RFC 1/3] PCI/PM: Fix kexec for D3cold and bridge suspending

In reply to Bjorn Helgaas
Quoted 14 lines · Bjorn Helgaas

+cc Eric and kexec list

Quoted 10 lines · Huang Ying

If PCI devices are put into D3cold before kexec, because the configuration registers of PCI devices in D3cold are not accessible.

And if PCI bridges are put into low power state before kexec, configuration registers of PCI devices underneath the PCI bridges are not accessible too.

These will make some PCI devices can not be scanned after kexec, so resume the PCI devices in D3cold or PCI bridges in low power state before kexec.

Quoted 5 lines

Don't we need to resume the device even without the kexec issue? And even if it's in D1 or D2?

It looks to me like pci_msi_shutdown() (and probably drv->shutdown()) depend on the device being in D0.

We should in theory, but we didn't do any power management of PCI bridges before, so this is the first time we have a problem with it.

So I'd say, yeah, let's resume if current_state is between D1 and D3cold inclusive and the kexec comment is not very helpful (the problem is not kexec-specific in general).

Speaking of kexec, it might consider using the hibernation device freeze instead of device shutdown (which the kexec jump feature does). I've seen reports of problems that would be solved this way most likely.

Thanks,
Rafael

Quoted 11 lines
Quoted 11 lines
---
 drivers/pci/pci-driver.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-driver.c +0 -0
@@ -421,6 +421,10 @@ static void pci_device_shutdown(struct d
        struct pci_dev *pci_dev = to_pci_dev(dev);
        struct pci_driver *drv = pci_dev->driver;
 
Quoted 9 lines

drivers/pci/pci-driver.c static void pci_device_shutdown(struct d · line 430

Quoted 7 lines
drivers/pci/pci-driver.c +4 -0
+       /* Resume bridges and devices in D3cold for kexec to work properly */
+       if (pci_dev->current_state == PCI_D3cold || pci_dev->subordinate)
+               pm_runtime_resume(dev);
+
        if (drv && drv->shutdown)
                drv->shutdown(pci_dev);
        pci_msi_shutdown(pci_dev);

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#12 lore raw

Re: [RFC 3/3] PCI/PM: Disable PME poll for PCIe devices

In reply to Huang Ying
Quoted 2 lines · Huang Ying

PME poll is not necessary for PCIe devices, because PCIe devices use in-band PME message and IRQ on PCIe port to report PME.

Alas, not all of them as it turns out and even if they do, it doesn't work for some of them. That's why we've added the PCIe devices polling (quite recently, for that matter).

If you'd spent some time on some proper research regarding that (like browsing the changelogs of git commits modifying the relevant part of drivers/pci/pci.c), you'd have known that already.

And that actually is quite important, because I don't have to remember every single PM-related change we're making in the PCI layer. I _incidentally_ do remember this one, but that may not happen next time. Please do the research _before_ proposing changes of this kind.

Thanks,
Rafael

Quoted 21 lines

PME poll is useful for PCI devices. Because for PCI devices, PME is reported via a side-band PME# line and some platform logic, and the platform logic is often missing on many systems.

---
 drivers/pci/pcie/pme.c |    1 +
 1 file changed, 1 insertion(+)
drivers/pci/pcie/pme.c +1 -0
@@ -313,6 +313,7 @@ static int pcie_pme_set_native(struct pc
 
 	device_set_run_wake(&dev->dev, true);
 	dev->pme_interrupt = true;
+	dev->pme_poll = false;
 	return 0;
 }
 
Acked-by on v1 2/3
#10 lore raw

Re: [RFC 2/3] PCI/PM: Make PCI devices notified when its power resource turned on

In reply to Huang Ying
Quoted 9 lines · Huang Ying

A set of power resources may be shared by multiple devices. When all devices share one set of power resources is put into D3_COLD state, the power resources will be turned off. When one of the device is waked, the power resource will be turned on and all devices share it will be powered on to D0uninitialized state. These devices should be resumed, so that they can get opportunity to go to low power state later.

Makes sense.

Quoted 24 lines
---
 drivers/acpi/pci_bind.c |    2 ++
 1 file changed, 2 insertions(+)
drivers/acpi/pci_bind.c +2 -0
@@ -45,6 +45,7 @@ static int acpi_pci_unbind(struct acpi_d
 
 	device_set_run_wake(&dev->dev, false);
 	pci_acpi_remove_pm_notifier(device);
+	acpi_power_resource_unregister_device(dev, device->handle);
 
 	if (!dev->subordinate)
 		goto out;
@@ -71,6 +72,7 @@ static int acpi_pci_bind(struct acpi_dev
 		return 0;
 
 	pci_acpi_add_pm_notifier(device, dev);
+	acpi_power_resource_register_device(dev, device->handle);
 	if (device->wakeup.flags.run_wake)
 		device_set_run_wake(&dev->dev, true);
 
#13 lore raw

Re: [RFC 3/3] PCI/PM: Disable PME poll for PCIe devices

In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 2 lines · Huang Ying

PME poll is not necessary for PCIe devices, because PCIe devices use in-band PME message and IRQ on PCIe port to report PME.

Alas, not all of them as it turns out and even if they do, it doesn't work for some of them. That's why we've added the PCIe devices polling (quite recently, for that matter).

Right. I'd believe that there's some underlying bug that's causing the missing PMEs and maybe it does work in theory, but the reality is that right now some PCIe devices are not getting their PMEs delivered to us. We don't know if it's our bug or a hardware bug, and until we do we need to leave the polling code.

Signature · 1 line
Matthew Garrett | [email protected]
author
#7 lore raw

Re: [RFC 1/3] PCI/PM: Fix kexec for D3cold and bridge suspending

In reply to Rafael J. Wysocki
Quoted 21 lines · Rafael J. Wysocki
Quoted 14 lines · Bjorn Helgaas

+cc Eric and kexec list

Quoted 10 lines · Huang Ying

If PCI devices are put into D3cold before kexec, because the configuration registers of PCI devices in D3cold are not accessible.

And if PCI bridges are put into low power state before kexec, configuration registers of PCI devices underneath the PCI bridges are not accessible too.

These will make some PCI devices can not be scanned after kexec, so resume the PCI devices in D3cold or PCI bridges in low power state before kexec.

Quoted 5 lines

Don't we need to resume the device even without the kexec issue? And even if it's in D1 or D2?

It looks to me like pci_msi_shutdown() (and probably drv->shutdown()) depend on the device being in D0.

Quoted 6 lines

We should in theory, but we didn't do any power management of PCI bridges before, so this is the first time we have a problem with it.

So I'd say, yeah, let's resume if current_state is between D1 and D3cold inclusive and the kexec comment is not very helpful (the problem is not kexec-specific in general).

Resume from D1 to D3cold for any device or just bridges?

Best Regards,
Huang Ying

Quoted 29 lines

Speaking of kexec, it might consider using the hibernation device freeze instead of device shutdown (which the kexec jump feature does). I've seen reports of problems that would be solved this way most likely.

Thanks,
Rafael

Quoted 20 lines
Quoted 18 lines
---
 drivers/pci/pci-driver.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-driver.c +4 -0
@@ -421,6 +421,10 @@ static void pci_device_shutdown(struct d
        struct pci_dev *pci_dev = to_pci_dev(dev);
        struct pci_driver *drv = pci_dev->driver;
 
+       /* Resume bridges and devices in D3cold for kexec to work properly */
+       if (pci_dev->current_state == PCI_D3cold || pci_dev->subordinate)
+               pm_runtime_resume(dev);
+
        if (drv && drv->shutdown)
                drv->shutdown(pci_dev);
        pci_msi_shutdown(pci_dev);
author
#14 lore raw

Re: [RFC 3/3] PCI/PM: Disable PME poll for PCIe devices

In reply to Rafael J. Wysocki
Quoted 8 lines · Rafael J. Wysocki
Quoted 2 lines · Huang Ying

PME poll is not necessary for PCIe devices, because PCIe devices use in-band PME message and IRQ on PCIe port to report PME.

Alas, not all of them as it turns out and even if they do, it doesn't work for some of them. That's why we've added the PCIe devices polling (quite recently, for that matter).

Quoted 8 lines

If you'd spent some time on some proper research regarding that (like browsing the changelogs of git commits modifying the relevant part of drivers/pci/pci.c), you'd have known that already.

And that actually is quite important, because I don't have to remember every single PM-related change we're making in the PCI layer. I _incidentally_ do remember this one, but that may not happen next time. Please do the research _before_ proposing changes of this kind.

Sorry. I should have done more research before sending the patch out. Will do more research next time.

Best Regards,
Huang Ying

#8 lore raw

Re: [RFC 1/3] PCI/PM: Fix kexec for D3cold and bridge suspending

In reply to Huang Ying
Quoted 22 lines · Huang Ying
Quoted 21 lines · Rafael J. Wysocki
Quoted 19 lines · Bjorn Helgaas

+cc Eric and kexec list

Quoted 10 lines · Huang Ying

If PCI devices are put into D3cold before kexec, because the configuration registers of PCI devices in D3cold are not accessible.

And if PCI bridges are put into low power state before kexec, configuration registers of PCI devices underneath the PCI bridges are not accessible too.

These will make some PCI devices can not be scanned after kexec, so resume the PCI devices in D3cold or PCI bridges in low power state before kexec.

Don't we need to resume the device even without the kexec issue? And even if it's in D1 or D2?

It looks to me like pci_msi_shutdown() (and probably drv->shutdown()) depend on the device being in D0.

Quoted 8 lines
Quoted 6 lines

We should in theory, but we didn't do any power management of PCI bridges before, so this is the first time we have a problem with it.

So I'd say, yeah, let's resume if current_state is between D1 and D3cold inclusive and the kexec comment is not very helpful (the problem is not kexec-specific in general).

Resume from D1 to D3cold for any device or just bridges?

I'd say every device for starters.

Thanks,
Rafael

Quoted 33 lines
Quoted 29 lines

Speaking of kexec, it might consider using the hibernation device freeze instead of device shutdown (which the kexec jump feature does). I've seen reports of problems that would be solved this way most likely.

Thanks,
Rafael

Quoted 20 lines
Quoted 18 lines
---
 drivers/pci/pci-driver.c |    4 ++++
 1 file changed, 4 insertions(+)
drivers/pci/pci-driver.c +4 -0
@@ -421,6 +421,10 @@ static void pci_device_shutdown(struct d
        struct pci_dev *pci_dev = to_pci_dev(dev);
        struct pci_driver *drv = pci_dev->driver;
 
+       /* Resume bridges and devices in D3cold for kexec to work properly */
+       if (pci_dev->current_state == PCI_D3cold || pci_dev->subordinate)
+               pm_runtime_resume(dev);
+
        if (drv && drv->shutdown)
                drv->shutdown(pci_dev);
        pci_msi_shutdown(pci_dev);