Re: [PATCH] virtio_mmio: pm: Add notification handlers for restore and freeze

From: Mikhail Golubev
Date: Tue Dec 14 2021 - 11:21:58 EST


The 12/13/2021 18:55, Michael S. Tsirkin wrote:
> On Mon, Dec 13, 2021 at 05:00:08PM +0100, Mikhail Golubev wrote:
> > From: Yurii Danilovskyi <glyd@xxxxxxxxxxxxxxx>
> >
> > Handle restore and freeze notifications from the PM core. Expose
> > these to individual virtio drivers that can quiesce and resume vq
> > operations.
> >
> > Signed-off-by: Yurii Danilovskyi <glyd@xxxxxxxxxxxxxxx>
> > Signed-off-by: Mikhail Golubev <Mikhail.Golubev@xxxxxxxxxxxxxxx>
> > ---
> > drivers/virtio/virtio_mmio.c | 19 +++++++++++++++++++
> > 1 file changed, 19 insertions(+)
> >
> > diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
> > index 56128b9c46eb..af79f8c2a2f2 100644
> > --- a/drivers/virtio/virtio_mmio.c
> > +++ b/drivers/virtio/virtio_mmio.c
> > @@ -762,6 +762,24 @@ static void vm_unregister_cmdline_devices(void)
> >
> > #endif
> >
> > +static int __maybe_unused virtio_mmio_freeze(struct device *dev)
> > +{
> > + struct platform_device *pdev = to_platform_device(dev);
> > + struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
> > +
> > + return virtio_device_freeze(&vm_dev->vdev);
> > +}
> > +
> > +static int __maybe_unused virtio_mmio_restore(struct device *dev)
> > +{
> > + struct platform_device *pdev = to_platform_device(dev);
> > + struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
> > +
> > + return virtio_device_restore(&vm_dev->vdev);
> > +}
> > +
> > +static SIMPLE_DEV_PM_OPS(virtio_mmio_pm_ops, virtio_mmio_freeze, virtio_mmio_restore);
> > +
> > /* Platform driver */
> >
> > static const struct of_device_id virtio_mmio_match[] = {
> > @@ -785,6 +803,7 @@ static struct platform_driver virtio_mmio_driver = {
> > .name = "virtio-mmio",
> > .of_match_table = virtio_mmio_match,
> > .acpi_match_table = ACPI_PTR(virtio_mmio_acpi_match),
> > + .pm = &virtio_mmio_pm_ops,
> > },
> > };
>
> All this code needs to be within ifdef CONFIG_PM_SLEEP. Alternatively,
> tweak virtio.h to expose virtio_device_freeze/virtio_device_restore
> unconditionally.

Added ifdef CONFIG_PM_SLEEP in the patch v2 for simplicity and to be more
aligned with other PM code in drivers/virtio.

>
>
> >
> > --
> > 2.34.1
> >
> >
> > --
>

--