From patchwork Wed Oct 14 11:37:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 35949 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 D094FB7B76 for ; Wed, 14 Oct 2009 22:49:22 +1100 (EST) Received: from localhost ([127.0.0.1]:45350 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My2M3-0008Bu-GX for incoming@patchwork.ozlabs.org; Wed, 14 Oct 2009 07:49:19 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1My2Bf-0002LR-NN for qemu-devel@nongnu.org; Wed, 14 Oct 2009 07:38:35 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1My2BZ-0002FL-Kl for qemu-devel@nongnu.org; Wed, 14 Oct 2009 07:38:33 -0400 Received: from [199.232.76.173] (port=41240 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My2BY-0002Ew-V4 for qemu-devel@nongnu.org; Wed, 14 Oct 2009 07:38:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62978) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1My2BY-0006Cm-AK for qemu-devel@nongnu.org; Wed, 14 Oct 2009 07:38:28 -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 n9EBcOha022423 for ; Wed, 14 Oct 2009 07:38:24 -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 n9EBcIEt006321; Wed, 14 Oct 2009 07:38:23 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 14 Oct 2009 13:37:44 +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 04/13] ide: port ide_drive 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/ide/core.c | 113 ++++++++++++++++++++++++++++----------------------------- 1 files changed, 56 insertions(+), 57 deletions(-) diff --git a/hw/ide/core.c b/hw/ide/core.c index aeff034..c08d5aa 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2591,70 +2591,69 @@ void ide_init_ioport(IDEBus *bus, int iobase, int iobase2) register_ioport_read(iobase, 4, 4, ide_data_readl, bus); } -/* save per IDE drive data */ -void ide_save(QEMUFile* f, IDEState *s) +static bool is_identify_set(void *opaque, int version_id) { - qemu_put_be32(f, s->mult_sectors); - qemu_put_be32(f, s->identify_set); - if (s->identify_set) { - qemu_put_buffer(f, (const uint8_t *)s->identify_data, 512); - } - qemu_put_8s(f, &s->feature); - qemu_put_8s(f, &s->error); - qemu_put_be32s(f, &s->nsector); - qemu_put_8s(f, &s->sector); - qemu_put_8s(f, &s->lcyl); - qemu_put_8s(f, &s->hcyl); - qemu_put_8s(f, &s->hob_feature); - qemu_put_8s(f, &s->hob_nsector); - qemu_put_8s(f, &s->hob_sector); - qemu_put_8s(f, &s->hob_lcyl); - qemu_put_8s(f, &s->hob_hcyl); - qemu_put_8s(f, &s->select); - qemu_put_8s(f, &s->status); - qemu_put_8s(f, &s->lba48); - - qemu_put_8s(f, &s->sense_key); - qemu_put_8s(f, &s->asc); - qemu_put_8s(f, &s->cdrom_changed); - /* XXX: if a transfer is pending, we do not save it yet */ -} - -/* load per IDE drive data */ -void ide_load(QEMUFile* f, IDEState *s, int version_id) + IDEState *s = opaque; + + return s->identify_set != 0; +} + +static int ide_drive_post_load(void *opaque, int version_id) { - s->mult_sectors=qemu_get_be32(f); - s->identify_set=qemu_get_be32(f); - if (s->identify_set) { - qemu_get_buffer(f, (uint8_t *)s->identify_data, 512); - } - qemu_get_8s(f, &s->feature); - qemu_get_8s(f, &s->error); - qemu_get_be32s(f, &s->nsector); - qemu_get_8s(f, &s->sector); - qemu_get_8s(f, &s->lcyl); - qemu_get_8s(f, &s->hcyl); - qemu_get_8s(f, &s->hob_feature); - qemu_get_8s(f, &s->hob_nsector); - qemu_get_8s(f, &s->hob_sector); - qemu_get_8s(f, &s->hob_lcyl); - qemu_get_8s(f, &s->hob_hcyl); - qemu_get_8s(f, &s->select); - qemu_get_8s(f, &s->status); - qemu_get_8s(f, &s->lba48); - - qemu_get_8s(f, &s->sense_key); - qemu_get_8s(f, &s->asc); - if (version_id == 3) { - qemu_get_8s(f, &s->cdrom_changed); - } else { + IDEState *s = opaque; + + if (version_id < 3) { if (s->sense_key == SENSE_UNIT_ATTENTION && - s->asc == ASC_MEDIUM_MAY_HAVE_CHANGED) + s->asc == ASC_MEDIUM_MAY_HAVE_CHANGED) { s->cdrom_changed = 1; + } } - /* XXX: if a transfer is pending, we do not save it yet */ + return 0; } +const VMStateDescription vmstate_ide_drive = { + .name = "ide_drive", + .version_id = 3, + .minimum_version_id = 0, + .minimum_version_id_old = 0, + .post_load = ide_drive_post_load, + .fields = (VMStateField []) { + VMSTATE_INT32(mult_sectors, IDEState), + VMSTATE_INT32(identify_set, IDEState), + VMSTATE_BUFFER_TEST(identify_data, IDEState, is_identify_set), + VMSTATE_UINT8(feature, IDEState), + VMSTATE_UINT8(error, IDEState), + VMSTATE_UINT32(nsector, IDEState), + VMSTATE_UINT8(sector, IDEState), + VMSTATE_UINT8(lcyl, IDEState), + VMSTATE_UINT8(hcyl, IDEState), + VMSTATE_UINT8(hob_feature, IDEState), + VMSTATE_UINT8(hob_sector, IDEState), + VMSTATE_UINT8(hob_nsector, IDEState), + VMSTATE_UINT8(hob_lcyl, IDEState), + VMSTATE_UINT8(hob_hcyl, IDEState), + VMSTATE_UINT8(select, IDEState), + VMSTATE_UINT8(status, IDEState), + VMSTATE_UINT8(lba48, IDEState), + VMSTATE_UINT8(sense_key, IDEState), + VMSTATE_UINT8(asc, IDEState), + VMSTATE_UINT8_V(cdrom_changed, IDEState, 3), + /* XXX: if a transfer is pending, we do not save it yet */ + VMSTATE_END_OF_LIST() + } +}; + +void ide_save(QEMUFile* f, IDEState *s) +{ + vmstate_save_state(f, &vmstate_ide_drive, s); +} + +void ide_load(QEMUFile* f, IDEState *s, int version_id) +{ + vmstate_load_state(f, &vmstate_ide_drive, s, vmstate_ide_drive.version_id); +} + + const VMStateDescription vmstate_ide_bus = { .name = "ide_bus", .version_id = 1,