A reference implementation of PCI suspend/resume?
Hi,
There are still many PCI drivers don't implement their .suspend/.resume methods correctly. I felt it would be quite helpful there is a reference implementation. Here is my thought:
.suspend()
{
driver specific operations;
pci_save_state();
pci_enable_wake();
/* as a result, PIC/IOAPIC pin is disabled */
free_irq();
/* as a result, bus master/irq router are disabled */
pci_disable_device();
pci_set_power_state();
}.resume()
{
pci_set_power_state(PCI_D0);
pci_restore_state();
/* device's irq possibly is changed, driver should take care */
pci_enable_device();
pci_set_master();
request_irq();
driver specific operations;
}Currently many drivers don't call free_irq/request_irq/pci_disable_device, which makes unexpected interrupt occur and even break suspend/resume in some systems. The reason is we disable PIC/IOAPIC/irq router very later (they are treated as a sysdev), so there is a window between when a device is suspend and when its PIC/IOAPIC/irq router pin are disabled. The ideal way is PIC/IOAPIC/irq router's pins are disabled soon after no device is referencing them. I'm now working on disabling irq router if no reference on it, but first I'd like to know your opinions about the proposal (the reference .suspend/.resume implementation).
Thanks,
Shaohua
Quoted 5 lines · Shaohua Li
Hi,
There are still many PCI drivers don't implement their .suspend/.resume methods correctly. I felt it would be quite helpful there is a reference implementation. Here is my thought:
Quoted 7 lines
.suspend()
{ driver specific operations; pci_save_state(); pci_enable_wake(); /* as a result, PIC/IOAPIC pin is disabled */ free_irq();
We can do this earlier, under driver specific operations, right?
Quoted 10 lines
/* as a result, bus master/irq router are disabled */ pci_disable_device(); pci_set_power_state(); }.resume()
{ pci_set_power_state(PCI_D0); pci_restore_state(); /* device's irq possibly is changed, driver should take care */
So what do you have in mind here? Could/should the device's resource configuration also possibly change.
Quoted 5 lines
pci_enable_device(); pci_set_master(); request_irq(); driver specific operations; }
MSI support may require something here too, I need to look into it.
Also, we should disable the irq bit in the PCI configuration header, I'm not sure if pci_disable_device() does this now.
Finally, I'm not sure if pci_save_state() and pci_restore_state() should be part of the default procedure. I'd rather see drivers restoring the specific configuration areas they need.
Quoted 12 lines
Currently many drivers don't call free_irq/request_irq/pci_disable_device, which makes unexpected interrupt occur and even break suspend/resume in some systems. The reason is we disable PIC/IOAPIC/irq router very later (they are treated as a sysdev), so there is a window between when a device is suspend and when its PIC/IOAPIC/irq router pin are disabled. The ideal way is PIC/IOAPIC/irq router's pins are disabled soon after no device is referencing them. I'm now working on disabling irq router if no reference on it, but first I'd like to know your opinions about the proposal (the reference .suspend/.resume implementation).
Quoted 2 lines
Thanks,
Shaohua
So if we find that over 99% of PCI device drivers need to do exactly this sequence, then why not just have the ->suspend and ->resume wrappers do it automatically?
And let's say there's a good argument or it's better coding style to allow drivers do it on thier own. We still have two problems:
a.) many drivers will get it wrong
b.) if we want to change this sequence, every driver must be changed
But say we added the following functions:pci_suspend_power(PCI-[D1-D3]);pci_restore_power();
These could do exactly what we have above, and the majority of PCI drivers could utilize them. I think this would simplify things.
Just some thoughts.
Thanks,
Adam
Quoted 16 lines · Adam Belay
Quoted 2 lines · Shaohua Li
Hi,
There are still many PCI drivers don't implementtheir .suspend/.resume
Quoted 1 line
methods correctly. I felt it would be quite helpful there is a
reference
Quoted 9 lines
implementation. Here is my thought:
.suspend()
{ driver specific operations; pci_save_state(); pci_enable_wake(); /* as a result, PIC/IOAPIC pin is disabled */ free_irq();
Quoted 1 line
We can do this earlier, under driver specific operations, right?
Right, I just list some operations. Some operations are optional and some order can be slightly adjusted.
Quoted 11 lines
Quoted 11 lines
/* as a result, bus master/irq router are disabled */ pci_disable_device(); pci_set_power_state(); }.resume()
{ pci_set_power_state(PCI_D0); pci_restore_state(); /* device's irq possibly is changed, driver should take care
Quoted 4 lines
*/
So what do you have in mind here? Could/should the device's resource configuration also possibly change.
Resources balance need it. For suspend/resume, it's unnecessary (pci_restore_state will restore the resource configuration). But we must clean irq to avoid unexpected interrupt issue. Currently, I'd like we temporarily ignore resources balance.
Quoted 11 lines
Quoted 5 lines
pci_enable_device(); pci_set_master(); request_irq(); driver specific operations; }MSI support may require something here too, I need to look into it.
Also, we should disable the irq bit in the PCI configuration header, I'm not
sure ifpci_disable_device()does this now.
Disabling the INTX for MSI? pci_enable_msi isn't called at pci_enable_device, so pci_disable_msi should be the same. Yes, pci_enable_msi/pci_disable_msi should be added in the suspend/resume methods.
Quoted 6 lines
Finally, I'm not sure if
pci_save_state()andpci_restore_state()should be
part of the default procedure. I'd rather see drivers restoring the specific
configuration areas they need.
I think pci_save_state and pci_store_state are mandatory and drivers can do extra config save/restore.
Quoted 25 lines
Quoted 5 lines
Currently many drivers don't call free_irq/request_irq/pci_disable_device, which makes unexpected interrupt occur and even break suspend/resume in some systems. The reason is we disable PIC/IOAPIC/irq router very later (they are
treated
Quoted 1 line
as a sysdev), so there is a window between when a device is suspend
and
Quoted 5 lines
when its PIC/IOAPIC/irq router pin are disabled. The ideal way is PIC/IOAPIC/irq router's pins are disabled soon after no device is referencing them. I'm now working on disabling irq router if no reference on it, but first I'd like to know your opinions about the proposal (the reference .suspend/.resume implementation).
So if we find that over 99% of PCI device drivers need to do exactly this
sequence, then why not just have the ->suspend and ->resume wrappers do it
automatically?And let's say there's a good argument or it's better coding style to allow
drivers do it on thier own. We still have two problems:
a.) many drivers will get it wrong
b.) if we want to change this sequence, every driver must be changed
Quoted 7 lines
But say we added the following functions:
pci_suspend_power(PCI-[D1-D3]);pci_restore_power();These could do exactly what we have above, and the majority of PCI drivers
could utilize them. I think this would simplify things.
It's ok. The question is how many drivers can use it.
Thanks,
Shaohua
Quoted 13 lines
Currently many drivers don't call free_irq/request_irq/pci_disable_device, which makes unexpected interrupt occur and even break suspend/resume in some systems. The reason is we disable PIC/IOAPIC/irq router very later (they are treated
as a sysdev), so there is a window between when a device is suspend and
when its PIC/IOAPIC/irq router pin are disabled. The ideal way is PIC/IOAPIC/irq router's pins are disabled soon after no device is referencing them. I'm now working on disabling irq router if no reference on it, but first I'd like to know your opinions about the proposal (the reference .suspend/.resume implementation).
Hi Pavel,
Could this be put into your tree? We should fix many PCI drivers, this possibly will help us.
Thanks,
Shaohua
---
linux-2.6.11-rc5-mm1-root/Documentation/power/pci.txt | 38 ++++++++++++++++++ 1 files changed, 38 insertions(+)
Documentation/power/pci.txt renamed from Documentation/power/pci.txt~int-doc +38 -0
@@ -291,6 +291,44 @@ a request to enable wake events from D3, pci_enable_wake (one for both D3hot and D3cold). +A reference implementation +------------------------- +.suspend() +{ + /* driver specific operations */ + + /* Disable IRQ */ + free_irq(); + /* If using MSI */ + pci_disable_msi(); + + pci_save_state(); + pci_enable_wake(); + /* Disable IO/bus master/irq router */ + pci_disable_device(); + pci_set_power_state(pci_choose_state()); +} + +.resume() +{ + pci_set_power_state(PCI_D0); + pci_restore_state(); + /* device's irq possibly is changed, driver should take care */ + pci_enable_device(); + pci_set_master(); + + /* if using MSI, device's vector possibly is changed */ + pci_enable_msi(); + + request_irq(); + /* driver specific operations; */ +} + +This is a typical implementation. Drivers can slightly change the order +of the operations in the implementation, ignore some operations or add +more deriver specific operations in it, but drivers should do something like +this on the whole. + 5. Resources ~~~~~~~~~~~~
_
Pavel Machek
AppliedHi!
Quoted 12 lines
Quoted 4 lines
Currently many drivers don't call free_irq/request_irq/pci_disable_device, which makes unexpected interrupt occur and even break suspend/resume in some systems. The reason is we disable PIC/IOAPIC/irq router very later (they are
Quoted 8 lines
treated
as a sysdev), so there is a window between when a device is suspend and
when its PIC/IOAPIC/irq router pin are disabled. The ideal way is PIC/IOAPIC/irq router's pins are disabled soon after no device is referencing them. I'm now working on disabling irq router if no reference on it, but first I'd like to know your opinions about the proposal (the reference .suspend/.resume implementation).
Quoted 3 lines
Hi Pavel,
Could this be put into your tree? We should fix many PCI drivers, this possibly will help us.
Thanks, applied.
Pavel