diff mbox

[04/15] virtio-pci: reset device before PCI layer

Message ID 1355761490-10073-5-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Dec. 17, 2012, 4:24 p.m. UTC
At the end of this series, qdev will reset devices in post-order: first
the children, then the parents.  The ->vdev link is logically a child
of the virtio-pci device and, even though it is not explicitly modeled
like that, we want to use the same reset semantics as qdev.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/virtio-pci.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 71f4fb5..a7c75fe 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -245,8 +245,8 @@  static void virtio_pci_stop_ioeventfd(VirtIOPCIProxy *proxy)
 void virtio_pci_reset(DeviceState *d)
 {
     VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
-    virtio_pci_stop_ioeventfd(proxy);
     virtio_reset(proxy->vdev);
+    virtio_pci_stop_ioeventfd(proxy);
     msix_unuse_all_vectors(&proxy->pci_dev);
     proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
 }
@@ -268,8 +268,8 @@  static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     case VIRTIO_PCI_QUEUE_PFN:
         pa = (hwaddr)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
         if (pa == 0) {
-            virtio_pci_stop_ioeventfd(proxy);
             virtio_reset(proxy->vdev);
+            virtio_pci_stop_ioeventfd(proxy);
             msix_unuse_all_vectors(&proxy->pci_dev);
         }
         else
@@ -285,6 +285,10 @@  static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         }
         break;
     case VIRTIO_PCI_STATUS:
+        if (vdev->status == 0) {
+            virtio_reset(proxy->vdev);
+        }
+
         if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) {
             virtio_pci_stop_ioeventfd(proxy);
         }
@@ -296,7 +300,6 @@  static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
         }
 
         if (vdev->status == 0) {
-            virtio_reset(proxy->vdev);
             msix_unuse_all_vectors(&proxy->pci_dev);
         }