From patchwork Thu Oct 27 18:17:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 122202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E80AD1007D8 for ; Fri, 28 Oct 2011 05:18:48 +1100 (EST) Received: from localhost ([::1]:33058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJUXE-0003bd-Lp for incoming@patchwork.ozlabs.org; Thu, 27 Oct 2011 14:18:36 -0400 Received: from eggs.gnu.org ([140.186.70.92]:53071) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJUX6-0003bD-AS for qemu-devel@nongnu.org; Thu, 27 Oct 2011 14:18:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RJUX1-0000AC-TA for qemu-devel@nongnu.org; Thu, 27 Oct 2011 14:18:28 -0400 Received: from mout.perfora.net ([74.208.4.194]:63354) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RJUX1-0000A3-NR for qemu-devel@nongnu.org; Thu, 27 Oct 2011 14:18:23 -0400 Received: from illuin.austin.ibm.com ([32.97.110.59]) by mrelay.perfora.net (node=mrus3) with ESMTP (Nemesis) id 0MK0K5-1RKK0j1WR3-001EqV; Thu, 27 Oct 2011 14:18:21 -0400 From: Michael Roth To: qemu-devel@nongnu.org Date: Thu, 27 Oct 2011 13:17:16 -0500 Message-Id: <1319739445-17629-5-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1319739445-17629-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1319739445-17629-1-git-send-email-mdroth@linux.vnet.ibm.com> X-Provags-ID: V02:K0:rVVEi/VWo0+MsXtXrxm+vlTxmFWDBL3IsbCGR/InaPd OqCCrZkBqH/Ywdvhm5P5W2TBNRSBiO3+1Wn+YkKTd7NOkXNl4o Js74+MGcjzEMBe/d9BwgYKPGrKji0MP+GTsr5PGGFP48LXbskm J+wpabk0MagaI9rVKqoUlx/FX5rHC5KKfl4NPYExk5lapDjGkL I4l/6bR9CrlX/cZzCn8CzPQpqPmlvkt/RuJUbIRfTN85lJl/O4 u7FzMImGezWrS29FdrrXPDnf2h6EcBz3HTfOfFex7ffpxSSZrJ aLY5/9pshIPLhDJAs0vkK99yWqGL0xJ1vVadUTlUYudNC+nPgW ighH9vO0M1XderIHjzQ21P6m6QfsYwCHjCVDzsi6V98lBs2Z9X byqqb0OUTH0lQ6phP1sEVDfwX1vGNnunFc= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.208.4.194 Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 04/13] msix: convert save/load to visitors (including interfaces) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use visitors for serialization. Also, with the only 2 direct users, virtio-pci and ivshmem, converted to visitors, we can change msix save/load function to take a Visitor directly, along with an Error object. Signed-off-by: Michael Roth --- hw/ivshmem.c | 4 ++-- hw/msix.c | 37 ++++++++++++++++++++++++++++--------- hw/msix.h | 4 ++-- hw/virtio-pci.c | 4 ++-- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/hw/ivshmem.c b/hw/ivshmem.c index 48e27f5..8d0607d 100644 --- a/hw/ivshmem.c +++ b/hw/ivshmem.c @@ -573,7 +573,7 @@ static void ivshmem_save(QEMUFile* f, void *opaque) pci_device_save(&proxy->dev, f); if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) { - msix_save(&proxy->dev, f); + msix_save(&proxy->dev, v, &err); } else { visit_type_uint32(v, &proxy->intrstatus, "proxy.intrstatus", &err); visit_type_uint32(v, &proxy->intrmask, "proxy.intrmask", &err); @@ -615,7 +615,7 @@ static int ivshmem_load(QEMUFile* f, void *opaque, int version_id) } if (ivshmem_has_feature(proxy, IVSHMEM_MSI)) { - msix_load(&proxy->dev, f); + msix_load(&proxy->dev, v, &err); for (i = 0; i < proxy->vectors; i++) { msix_vector_use(&proxy->dev, i); } diff --git a/hw/msix.c b/hw/msix.c index b15bafc..c62eeaa 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -276,30 +276,49 @@ int msix_uninit(PCIDevice *dev, MemoryRegion *bar) return 0; } -void msix_save(PCIDevice *dev, QEMUFile *f) +static void msix_visit(Visitor *v, PCIDevice *dev, Error **errp) { unsigned n = dev->msix_entries_nr; + int i; + Error *err = NULL; + visit_start_struct(v, NULL, NULL, "msix", 0, &err); + + visit_start_array(v, NULL, "msix_table_page", n * PCI_MSIX_ENTRY_SIZE, 1, + &err); + for (i = 0; i < n * PCI_MSIX_ENTRY_SIZE; i++) { + visit_type_uint8(v, &dev->msix_table_page[i], NULL, &err); + } + visit_end_array(v, &err); + + visit_start_array(v, NULL, "msix_table_page_pending", (n + 7) / 8, 1, &err); + for (i = 0; i < (n + 7) / 8; i++) { + visit_type_uint8(v, &dev->msix_table_page[i + MSIX_PAGE_PENDING], + NULL, &err); + } + visit_end_array(v, &err); + + visit_end_struct(v, &err); + error_propagate(errp, err); +} + +void msix_save(PCIDevice *dev, Visitor *v, Error **errp) +{ if (!(dev->cap_present & QEMU_PCI_CAP_MSIX)) { return; } - - qemu_put_buffer(f, dev->msix_table_page, n * PCI_MSIX_ENTRY_SIZE); - qemu_put_buffer(f, dev->msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8); + msix_visit(v, dev, errp); } /* Should be called after restoring the config space. */ -void msix_load(PCIDevice *dev, QEMUFile *f) +void msix_load(PCIDevice *dev, Visitor *v, Error **errp) { - unsigned n = dev->msix_entries_nr; - if (!(dev->cap_present & QEMU_PCI_CAP_MSIX)) { return; } msix_free_irq_entries(dev); - qemu_get_buffer(f, dev->msix_table_page, n * PCI_MSIX_ENTRY_SIZE); - qemu_get_buffer(f, dev->msix_table_page + MSIX_PAGE_PENDING, (n + 7) / 8); + msix_visit(v, dev, errp); } /* Does device support MSI-X? */ diff --git a/hw/msix.h b/hw/msix.h index 7e04336..e60ab10 100644 --- a/hw/msix.h +++ b/hw/msix.h @@ -13,8 +13,8 @@ void msix_write_config(PCIDevice *pci_dev, uint32_t address, int msix_uninit(PCIDevice *d, MemoryRegion *bar); -void msix_save(PCIDevice *dev, QEMUFile *f); -void msix_load(PCIDevice *dev, QEMUFile *f); +void msix_save(PCIDevice *dev, Visitor *v, Error **errp); +void msix_load(PCIDevice *dev, Visitor *v, Error **errp); int msix_enabled(PCIDevice *dev); int msix_present(PCIDevice *dev); diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 9092c02..ca9cabc 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -107,7 +107,7 @@ static void virtio_pci_save_config(void * opaque, QEMUFile *f) Error *err = NULL; pci_device_save(&proxy->pci_dev, f); - msix_save(&proxy->pci_dev, f); + msix_save(&proxy->pci_dev, v, &err); if (msix_present(&proxy->pci_dev)) { visit_type_uint16(v, &proxy->vdev->config_vector, "proxy.vdev.config_vector", &err); @@ -148,7 +148,7 @@ static int virtio_pci_load_config(void * opaque, QEMUFile *f) if (ret) { goto out; } - msix_load(&proxy->pci_dev, f); + msix_load(&proxy->pci_dev, v, &err); if (msix_present(&proxy->pci_dev)) { visit_type_uint16(v, &proxy->vdev->config_vector, "proxy.vdev.config_vector", &err);