From patchwork Mon Oct 19 18:43:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 36412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C506FB7B6F for ; Tue, 20 Oct 2009 06:23:39 +1100 (EST) Received: from localhost ([127.0.0.1]:36921 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MzxpQ-0006GD-Pb for incoming@patchwork.ozlabs.org; Mon, 19 Oct 2009 15:23:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MzxDK-0006I3-U4 for qemu-devel@nongnu.org; Mon, 19 Oct 2009 14:44:15 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MzxDG-0006EU-5H for qemu-devel@nongnu.org; Mon, 19 Oct 2009 14:44:13 -0400 Received: from [199.232.76.173] (port=49057 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MzxDE-0006E9-Qs for qemu-devel@nongnu.org; Mon, 19 Oct 2009 14:44:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56423) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MzxDE-0006Ml-6s for qemu-devel@nongnu.org; Mon, 19 Oct 2009 14:44:08 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9JIi75Z006324 for ; Mon, 19 Oct 2009 14:44:07 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9JIhcCF012656; Mon, 19 Oct 2009 14:44:06 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 19 Oct 2009 20:43:07 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 22/25] ne2000: port to vmstate X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Juan Quintela --- hw/ne2000-isa.c | 4 +- hw/ne2000.c | 133 ++++++++++++++++++++----------------------------------- hw/ne2000.h | 3 +- 3 files changed, 51 insertions(+), 89 deletions(-) diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c index e346731..0948b82 100644 --- a/hw/ne2000-isa.c +++ b/hw/ne2000-isa.c @@ -40,7 +40,7 @@ static void isa_ne2000_cleanup(VLANClientState *vc) NE2000State *s = vc->opaque; ISANE2000State *isa = container_of(s, ISANE2000State, ne2000); - unregister_savevm("ne2000", s); + vmstate_unregister(&vmstate_ne2000, s); isa_unassign_ioport(isa->iobase, 16); isa_unassign_ioport(isa->iobase + 0x10, 2); @@ -73,7 +73,7 @@ static int isa_ne2000_initfn(ISADevice *dev) isa_ne2000_cleanup, s); qemu_format_nic_info_str(s->vc, s->macaddr); - register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s); + vmstate_register(-1, &vmstate_ne2000, s); return 0; } diff --git a/hw/ne2000.c b/hw/ne2000.c index 87f1e59..88a81fb 100644 --- a/hw/ne2000.c +++ b/hw/ne2000.c @@ -622,94 +622,57 @@ uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr) return 0; } -void ne2000_save(QEMUFile* f, void* opaque) +static int ne2000_post_load(void* opaque, int version_id) { - NE2000State* s = opaque; - uint32_t tmp; - - qemu_put_8s(f, &s->rxcr); - - qemu_put_8s(f, &s->cmd); - qemu_put_be32s(f, &s->start); - qemu_put_be32s(f, &s->stop); - qemu_put_8s(f, &s->boundary); - qemu_put_8s(f, &s->tsr); - qemu_put_8s(f, &s->tpsr); - qemu_put_be16s(f, &s->tcnt); - qemu_put_be16s(f, &s->rcnt); - qemu_put_be32s(f, &s->rsar); - qemu_put_8s(f, &s->rsr); - qemu_put_8s(f, &s->isr); - qemu_put_8s(f, &s->dcfg); - qemu_put_8s(f, &s->imr); - qemu_put_buffer(f, s->phys, 6); - qemu_put_8s(f, &s->curpag); - qemu_put_buffer(f, s->mult, 8); - tmp = 0; - qemu_put_be32s(f, &tmp); /* ignored, was irq */ - qemu_put_buffer(f, s->mem, NE2000_MEM_SIZE); -} - -int ne2000_load(QEMUFile* f, void* opaque, int version_id) -{ - NE2000State* s = opaque; - uint32_t tmp; - - if (version_id > 3) - return -EINVAL; - - if (version_id >= 2) { - qemu_get_8s(f, &s->rxcr); - } else { - s->rxcr = 0x0c; - } - - qemu_get_8s(f, &s->cmd); - qemu_get_be32s(f, &s->start); - qemu_get_be32s(f, &s->stop); - qemu_get_8s(f, &s->boundary); - qemu_get_8s(f, &s->tsr); - qemu_get_8s(f, &s->tpsr); - qemu_get_be16s(f, &s->tcnt); - qemu_get_be16s(f, &s->rcnt); - qemu_get_be32s(f, &s->rsar); - qemu_get_8s(f, &s->rsr); - qemu_get_8s(f, &s->isr); - qemu_get_8s(f, &s->dcfg); - qemu_get_8s(f, &s->imr); - qemu_get_buffer(f, s->phys, 6); - qemu_get_8s(f, &s->curpag); - qemu_get_buffer(f, s->mult, 8); - qemu_get_be32s(f, &tmp); /* ignored */ - qemu_get_buffer(f, s->mem, NE2000_MEM_SIZE); - - return 0; -} - -static void pci_ne2000_save(QEMUFile* f, void* opaque) -{ - PCINE2000State* s = opaque; + NE2000State* s = opaque; - pci_device_save(&s->dev, f); - ne2000_save(f, &s->ne2000); + if (version_id < 2) { + s->rxcr = 0x0c; + } + return 0; } -static int pci_ne2000_load(QEMUFile* f, void* opaque, int version_id) -{ - PCINE2000State* s = opaque; - int ret; - - if (version_id > 3) - return -EINVAL; - - if (version_id >= 3) { - ret = pci_device_load(&s->dev, f); - if (ret < 0) - return ret; - } +const VMStateDescription vmstate_ne2000 = { + .name = "ne2000", + .version_id = 2, + .minimum_version_id = 0, + .minimum_version_id_old = 0, + .post_load = ne2000_post_load, + .fields = (VMStateField []) { + VMSTATE_UINT8_V(rxcr, NE2000State, 2), + VMSTATE_UINT8(cmd, NE2000State), + VMSTATE_UINT32(start, NE2000State), + VMSTATE_UINT32(stop, NE2000State), + VMSTATE_UINT8(boundary, NE2000State), + VMSTATE_UINT8(tsr, NE2000State), + VMSTATE_UINT8(tpsr, NE2000State), + VMSTATE_UINT16(tcnt, NE2000State), + VMSTATE_UINT16(rcnt, NE2000State), + VMSTATE_UINT32(rsar, NE2000State), + VMSTATE_UINT8(rsr, NE2000State), + VMSTATE_UINT8(isr, NE2000State), + VMSTATE_UINT8(dcfg, NE2000State), + VMSTATE_UINT8(imr, NE2000State), + VMSTATE_BUFFER(phys, NE2000State), + VMSTATE_UINT8(curpag, NE2000State), + VMSTATE_BUFFER(mult, NE2000State), + VMSTATE_UNUSED(4), /* was irq */ + VMSTATE_BUFFER(mem, NE2000State), + VMSTATE_END_OF_LIST() + } +}; - return ne2000_load(f, &s->ne2000, version_id); -} +const VMStateDescription vmstate_pci_ne2000 = { + .name = "ne2000", + .version_id = 3, + .minimum_version_id = 3, + .minimum_version_id_old = 3, + .fields = (VMStateField []) { + VMSTATE_PCI_DEVICE(dev, PCINE2000State), + VMSTATE_STRUCT(ne2000, PCINE2000State, 0, vmstate_ne2000, NE2000State), + VMSTATE_END_OF_LIST() + } +}; /***********************************************************/ /* PCI NE2000 definitions */ @@ -738,7 +701,7 @@ static void ne2000_cleanup(VLANClientState *vc) { NE2000State *s = vc->opaque; - unregister_savevm("ne2000", s); + vmstate_unregister(&vmstate_pci_ne2000, s); } static int pci_ne2000_init(PCIDevice *pci_dev) @@ -766,7 +729,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev) qemu_format_nic_info_str(s->vc, s->macaddr); - register_savevm("ne2000", -1, 3, pci_ne2000_save, pci_ne2000_load, d); + vmstate_register(-1, &vmstate_pci_ne2000, d); return 0; } diff --git a/hw/ne2000.h b/hw/ne2000.h index 92a2ddb..9bd5cab 100644 --- a/hw/ne2000.h +++ b/hw/ne2000.h @@ -33,8 +33,7 @@ void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val); uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr); void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val); uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr); -void ne2000_save(QEMUFile* f, void* opaque); -int ne2000_load(QEMUFile* f, void* opaque, int version_id); +extern const VMStateDescription vmstate_ne2000; void ne2000_reset(NE2000State *s); int ne2000_can_receive(VLANClientState *vc); ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_);