Skip to content

Commit ed7ac37

Browse files
stephan-ghmstsirkin
authored andcommitted
virtio_mmio: Add missing PM calls to freeze/restore
Most virtio drivers provide freeze/restore callbacks to finish up device usage before suspend and to reinitialize the virtio device after resume. However, these callbacks are currently only called when using virtio_pci. virtio_mmio does not have any PM ops defined. This causes problems for example after suspend to disk (hibernation), since the virtio devices might lose their state after the VMM is restarted. Calling virtio_device_freeze()/restore() ensures that the virtio devices are re-initialized correctly. Fix this by implementing the dev_pm_ops for virtio_mmio, similar to virtio_pci_common. Signed-off-by: Stephan Gerhold <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 11a37eb commit ed7ac37

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

drivers/virtio/virtio_mmio.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include <linux/list.h>
6363
#include <linux/module.h>
6464
#include <linux/platform_device.h>
65+
#include <linux/pm.h>
6566
#include <linux/slab.h>
6667
#include <linux/spinlock.h>
6768
#include <linux/virtio.h>
@@ -556,6 +557,25 @@ static const struct virtio_config_ops virtio_mmio_config_ops = {
556557
.synchronize_cbs = vm_synchronize_cbs,
557558
};
558559

560+
#ifdef CONFIG_PM_SLEEP
561+
static int virtio_mmio_freeze(struct device *dev)
562+
{
563+
struct virtio_mmio_device *vm_dev = dev_get_drvdata(dev);
564+
565+
return virtio_device_freeze(&vm_dev->vdev);
566+
}
567+
568+
static int virtio_mmio_restore(struct device *dev)
569+
{
570+
struct virtio_mmio_device *vm_dev = dev_get_drvdata(dev);
571+
572+
return virtio_device_restore(&vm_dev->vdev);
573+
}
574+
575+
static const struct dev_pm_ops virtio_mmio_pm_ops = {
576+
SET_SYSTEM_SLEEP_PM_OPS(virtio_mmio_freeze, virtio_mmio_restore)
577+
};
578+
#endif
559579

560580
static void virtio_mmio_release_dev(struct device *_d)
561581
{
@@ -799,6 +819,9 @@ static struct platform_driver virtio_mmio_driver = {
799819
.name = "virtio-mmio",
800820
.of_match_table = virtio_mmio_match,
801821
.acpi_match_table = ACPI_PTR(virtio_mmio_acpi_match),
822+
#ifdef CONFIG_PM_SLEEP
823+
.pm = &virtio_mmio_pm_ops,
824+
#endif
802825
},
803826
};
804827

0 commit comments

Comments
 (0)