From patchwork Wed Jun 10 12:29:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 29287 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5ACX0td027482 for ; Wed, 10 Jun 2009 12:33:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757136AbZFJMc4 (ORCPT ); Wed, 10 Jun 2009 08:32:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758445AbZFJMc4 (ORCPT ); Wed, 10 Jun 2009 08:32:56 -0400 Received: from mx2.redhat.com ([66.187.237.31]:40278 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756331AbZFJMcz (ORCPT ); Wed, 10 Jun 2009 08:32:55 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n5ACUMgv004649; Wed, 10 Jun 2009 08:30:22 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n5ACULud005150; Wed, 10 Jun 2009 08:30:21 -0400 Received: from redhat.com (dhcp-0-223.tlv.redhat.com [10.35.0.223]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n5ACUHuv015674; Wed, 10 Jun 2009 08:30:18 -0400 Date: Wed, 10 Jun 2009 15:29:26 +0300 From: "Michael S. Tsirkin" To: Paul Brook , Avi Kivity , qemu-devel@nongnu.org, Carsten Otte , kvm@vger.kernel.org, Rusty Russell , virtualization@lists.linux-foundation.org, Christian Borntraeger , Blue Swirl , Anthony Liguori , Glauber Costa Subject: [PATCHv4 12/13] qemu: virtio save/load bindings Message-ID: <20090610122926.GM27174@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Implement bindings for virtio save/load. Use them in virtio pci. Signed-off-by: Michael S. Tsirkin --- hw/virtio-pci.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- hw/virtio.c | 33 ++++++++++++++++----------------- hw/virtio.h | 4 ++++ 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 294f4c7..5a7bdcc 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -105,6 +105,50 @@ static void virtio_pci_notify(void *opaque, uint16_t vector) qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1); } +static void virtio_pci_save_config(void * opaque, QEMUFile *f) +{ + VirtIOPCIProxy *proxy = opaque; + pci_device_save(&proxy->pci_dev, f); + msix_save(&proxy->pci_dev, f); + if (msix_present(&proxy->pci_dev)) + qemu_put_be16(f, proxy->vdev->config_vector); +} + +static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f) +{ + VirtIOPCIProxy *proxy = opaque; + if (msix_present(&proxy->pci_dev)) + qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n)); +} + +static int virtio_pci_load_config(void * opaque, QEMUFile *f) +{ + VirtIOPCIProxy *proxy = opaque; + int ret; + ret = pci_device_load(&proxy->pci_dev, f); + if (ret) + return ret; + ret = msix_load(&proxy->pci_dev, f); + if (ret) + return ret; + if (msix_present(&proxy->pci_dev)) + qemu_get_be16s(f, &proxy->vdev->config_vector); + + pci_resize_io_region(&proxy->pci_dev, 1, msix_bar_size(&proxy->pci_dev)); + return 0; +} + +static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f) +{ + VirtIOPCIProxy *proxy = opaque; + uint16_t vector; + if (!msix_present(&proxy->pci_dev)) + return 0; + qemu_get_be16s(f, &vector); + virtio_queue_set_vector(proxy->vdev, n, vector); + return 0; +} + static void virtio_pci_reset(void *opaque) { VirtIOPCIProxy *proxy = opaque; @@ -317,7 +361,11 @@ static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, } static const VirtIOBindings virtio_pci_bindings = { - .notify = virtio_pci_notify + .notify = virtio_pci_notify, + .save_config = virtio_pci_save_config, + .load_config = virtio_pci_load_config, + .save_queue = virtio_pci_save_queue, + .load_queue = virtio_pci_load_queue, }; static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, diff --git a/hw/virtio.c b/hw/virtio.c index fe9f793..b773dff 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -568,9 +568,8 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) { int i; - /* FIXME: load/save binding. */ - //pci_device_save(&vdev->pci_dev, f); - //msix_save(&vdev->pci_dev, f); + if (vdev->binding->save_config) + vdev->binding->save_config(vdev->binding_opaque, f); qemu_put_8s(f, &vdev->status); qemu_put_8s(f, &vdev->isr); @@ -596,18 +595,20 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f) qemu_put_be32(f, vdev->vq[i].vring.num); qemu_put_be64(f, vdev->vq[i].pa); qemu_put_be16s(f, &vdev->vq[i].last_avail_idx); - if (vdev->nvectors) - qemu_put_be16s(f, &vdev->vq[i].vector); + if (vdev->binding->save_queue) + vdev->binding->save_queue(vdev->binding_opaque, i, f); } } -void virtio_load(VirtIODevice *vdev, QEMUFile *f) +int virtio_load(VirtIODevice *vdev, QEMUFile *f) { - int num, i; + int num, i, ret; - /* FIXME: load/save binding. */ - //pci_device_load(&vdev->pci_dev, f); - //r = msix_load(&vdev->pci_dev, f); + if (vdev->binding->load_config) { + ret = vdev->binding->load_config(vdev->binding_opaque, f); + if (ret) + return ret; + } qemu_get_8s(f, &vdev->status); qemu_get_8s(f, &vdev->isr); @@ -616,10 +617,6 @@ void virtio_load(VirtIODevice *vdev, QEMUFile *f) vdev->config_len = qemu_get_be32(f); qemu_get_buffer(f, vdev->config, vdev->config_len); - if (vdev->nvectors) { - qemu_get_be16s(f, &vdev->config_vector); - //msix_vector_use(&vdev->pci_dev, vdev->config_vector); - } num = qemu_get_be32(f); for (i = 0; i < num; i++) { @@ -630,13 +627,15 @@ void virtio_load(VirtIODevice *vdev, QEMUFile *f) if (vdev->vq[i].pa) { virtqueue_init(&vdev->vq[i]); } - if (vdev->nvectors) { - qemu_get_be16s(f, &vdev->vq[i].vector); - //msix_vector_use(&vdev->pci_dev, vdev->config_vector); + if (vdev->binding->load_queue) { + ret = vdev->binding->load_queue(vdev->binding_opaque, i, f); + if (ret) + return ret; } } virtio_notify_vector(vdev, VIRTIO_NO_VECTOR); + return 0; } void virtio_cleanup(VirtIODevice *vdev) diff --git a/hw/virtio.h b/hw/virtio.h index 04a3c3d..ce05517 100644 --- a/hw/virtio.h +++ b/hw/virtio.h @@ -72,6 +72,10 @@ typedef struct VirtQueueElement typedef struct { void (*notify)(void * opaque, uint16_t vector); + void (*save_config)(void * opaque, QEMUFile *f); + void (*save_queue)(void * opaque, int n, QEMUFile *f); + int (*load_config)(void * opaque, QEMUFile *f); + int (*load_queue)(void * opaque, int n, QEMUFile *f); } VirtIOBindings; #define VIRTIO_PCI_QUEUE_MAX 16