Skip to content

Commit dff4fa0

Browse files
David Stevensmstsirkin
authored andcommitted
virtio: Add support for no-reset virtio PCI PM
If a virtio_pci_device supports native PCI power management and has the No_Soft_Reset bit set, then skip resetting and reinitializing the device when suspending and restoring the device. This allows system-wide low power states like s2idle to be used in systems with stateful virtio devices that can't simply be re-initialized (e.g. virtio-fs). Signed-off-by: David Stevens <stevensd@chromium.org> Message-Id: <20231208070754.3132339-1-stevensd@chromium.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent d2c4f19 commit dff4fa0

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

drivers/virtio/virtio_pci_common.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,40 @@ static int virtio_pci_restore(struct device *dev)
492492
return virtio_device_restore(&vp_dev->vdev);
493493
}
494494

495+
static bool vp_supports_pm_no_reset(struct device *dev)
496+
{
497+
struct pci_dev *pci_dev = to_pci_dev(dev);
498+
u16 pmcsr;
499+
500+
if (!pci_dev->pm_cap)
501+
return false;
502+
503+
pci_read_config_word(pci_dev, pci_dev->pm_cap + PCI_PM_CTRL, &pmcsr);
504+
if (PCI_POSSIBLE_ERROR(pmcsr)) {
505+
dev_err(dev, "Unable to query pmcsr");
506+
return false;
507+
}
508+
509+
return pmcsr & PCI_PM_CTRL_NO_SOFT_RESET;
510+
}
511+
512+
static int virtio_pci_suspend(struct device *dev)
513+
{
514+
return vp_supports_pm_no_reset(dev) ? 0 : virtio_pci_freeze(dev);
515+
}
516+
517+
static int virtio_pci_resume(struct device *dev)
518+
{
519+
return vp_supports_pm_no_reset(dev) ? 0 : virtio_pci_restore(dev);
520+
}
521+
495522
static const struct dev_pm_ops virtio_pci_pm_ops = {
496-
SET_SYSTEM_SLEEP_PM_OPS(virtio_pci_freeze, virtio_pci_restore)
523+
.suspend = virtio_pci_suspend,
524+
.resume = virtio_pci_resume,
525+
.freeze = virtio_pci_freeze,
526+
.thaw = virtio_pci_restore,
527+
.poweroff = virtio_pci_freeze,
528+
.restore = virtio_pci_restore,
497529
};
498530
#endif
499531

0 commit comments

Comments
 (0)