aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/virtio/virtio_pci.c
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2014-10-13 20:10:35 -0400
committerRusty Russell <rusty@rustcorp.com.au>2014-10-14 19:54:55 -0400
commitc6716bae52f97347e25166c6270aa98693d9212c (patch)
tree0a8cf01f68e1eb0c0e403c24e9fbf1d76ccb3568 /drivers/virtio/virtio_pci.c
parent016c98c6fe0c914d12e2e242b2bccde6d6dea54b (diff)
virtio-pci: move freeze/restore to virtio core
This is in preparation to extending config changed event handling in core. Wrapping these in an API also seems to make for a cleaner code. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/virtio/virtio_pci.c')
-rw-r--r--drivers/virtio/virtio_pci.c54
1 files changed, 2 insertions, 52 deletions
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index f39f4e772e6a..d34ebfa604f3 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -57,9 +57,6 @@ struct virtio_pci_device
57 /* Vectors allocated, excluding per-vq vectors if any */ 57 /* Vectors allocated, excluding per-vq vectors if any */
58 unsigned msix_used_vectors; 58 unsigned msix_used_vectors;
59 59
60 /* Status saved during hibernate/restore */
61 u8 saved_status;
62
63 /* Whether we have vector per vq */ 60 /* Whether we have vector per vq */
64 bool per_vq_vectors; 61 bool per_vq_vectors;
65}; 62};
@@ -764,16 +761,9 @@ static int virtio_pci_freeze(struct device *dev)
764{ 761{
765 struct pci_dev *pci_dev = to_pci_dev(dev); 762 struct pci_dev *pci_dev = to_pci_dev(dev);
766 struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); 763 struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
767 struct virtio_driver *drv;
768 int ret; 764 int ret;
769 765
770 drv = container_of(vp_dev->vdev.dev.driver, 766 ret = virtio_device_freeze(&vp_dev->vdev);
771 struct virtio_driver, driver);
772
773 ret = 0;
774 vp_dev->saved_status = vp_get_status(&vp_dev->vdev);
775 if (drv && drv->freeze)
776 ret = drv->freeze(&vp_dev->vdev);
777 767
778 if (!ret) 768 if (!ret)
779 pci_disable_device(pci_dev); 769 pci_disable_device(pci_dev);
@@ -784,54 +774,14 @@ static int virtio_pci_restore(struct device *dev)
784{ 774{
785 struct pci_dev *pci_dev = to_pci_dev(dev); 775 struct pci_dev *pci_dev = to_pci_dev(dev);
786 struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev); 776 struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
787 struct virtio_driver *drv;
788 unsigned status = 0;
789 int ret; 777 int ret;
790 778
791 drv = container_of(vp_dev->vdev.dev.driver,
792 struct virtio_driver, driver);
793
794 ret = pci_enable_device(pci_dev); 779 ret = pci_enable_device(pci_dev);
795 if (ret) 780 if (ret)
796 return ret; 781 return ret;
797 782
798 pci_set_master(pci_dev); 783 pci_set_master(pci_dev);
799 /* We always start by resetting the device, in case a previous 784 return virtio_device_restore(&vp_dev->vdev);
800 * driver messed it up. */
801 vp_reset(&vp_dev->vdev);
802
803 /* Acknowledge that we've seen the device. */
804 status |= VIRTIO_CONFIG_S_ACKNOWLEDGE;
805 vp_set_status(&vp_dev->vdev, status);
806
807 /* Maybe driver failed before freeze.
808 * Restore the failed status, for debugging. */
809 status |= vp_dev->saved_status & VIRTIO_CONFIG_S_FAILED;
810 vp_set_status(&vp_dev->vdev, status);
811
812 if (!drv)
813 return 0;
814
815 /* We have a driver! */
816 status |= VIRTIO_CONFIG_S_DRIVER;
817 vp_set_status(&vp_dev->vdev, status);
818
819 vp_finalize_features(&vp_dev->vdev);
820
821 if (drv->restore) {
822 ret = drv->restore(&vp_dev->vdev);
823 if (ret) {
824 status |= VIRTIO_CONFIG_S_FAILED;
825 vp_set_status(&vp_dev->vdev, status);
826 return ret;
827 }
828 }
829
830 /* Finally, tell the device we're all set */
831 status |= VIRTIO_CONFIG_S_DRIVER_OK;
832 vp_set_status(&vp_dev->vdev, status);
833
834 return ret;
835} 785}
836 786
837static const struct dev_pm_ops virtio_pci_pm_ops = { 787static const struct dev_pm_ops virtio_pci_pm_ops = {