From mboxrd@z Thu Jan 1 00:00:00 1970 From: Amit Shah Subject: [RFC PATCH 2/8] virtio-pci: add PM notification handlers for restore, freeze, thaw, poweroff Date: Thu, 28 Jul 2011 20:05:07 +0530 Message-ID: <0d7a31302c2467936f70c3aaecd47b8720891f4d.1311863438.git.amit.shah@redhat.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: In-Reply-To: References: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org To: Virtualization List Cc: Amit Shah , "Michael S. Tsirkin" List-Id: virtualization@lists.linuxfoundation.org Handle restore and freeze notification from the PM core. Expose these to individual virtio drivers that can quiesce and resume vq operations. Signed-off-by: Amit Shah --- drivers/virtio/virtio_pci.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/virtio.h | 4 ++++ 2 files changed, 38 insertions(+), 0 deletions(-) diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c index 3879c3e..579681f 100644 --- a/drivers/virtio/virtio_pci.c +++ b/drivers/virtio/virtio_pci.c @@ -704,9 +704,43 @@ static int virtio_pci_resume(struct device *dev) return 0; } +static int virtio_pci_freeze(struct device *dev) +{ + struct pci_dev *pci_dev = to_pci_dev(dev); + struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); + struct virtio_driver *drv; + + drv = container_of(vp_dev->vdev.dev.driver, + struct virtio_driver, driver); + + if (drv && drv->freeze) + return drv->freeze(&vp_dev->vdev); + + return 0; +} + +static int virtio_pci_restore(struct device *dev) +{ + struct pci_dev *pci_dev = to_pci_dev(dev); + struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); + struct virtio_driver *drv; + + drv = container_of(vp_dev->vdev.dev.driver, + struct virtio_driver, driver); + + if (drv && drv->restore) + return drv->restore(&vp_dev->vdev); + + return 0; +} + static const struct dev_pm_ops virtio_pci_pm_ops = { .suspend = virtio_pci_suspend, .resume = virtio_pci_resume, + .freeze = virtio_pci_freeze, + .thaw = virtio_pci_restore, + .restore = virtio_pci_restore, + .poweroff = virtio_pci_suspend, }; #endif diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 7108857..9afb662 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -141,6 +141,10 @@ struct virtio_driver { int (*probe)(struct virtio_device *dev); void (*remove)(struct virtio_device *dev); void (*config_changed)(struct virtio_device *dev); +#ifdef CONFIG_PM + int (*freeze)(struct virtio_device *dev); + int (*restore)(struct virtio_device *dev); +#endif }; int register_virtio_driver(struct virtio_driver *drv); -- 1.7.6