From patchwork Wed Oct 14 11:18:14 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 35941 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 08BBDB7B74 for ; Wed, 14 Oct 2009 22:22:40 +1100 (EST) Received: from localhost ([127.0.0.1]:46093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My1wC-0007MS-HR for incoming@patchwork.ozlabs.org; Wed, 14 Oct 2009 07:22:37 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1My1sZ-0006Oo-5g for qemu-devel@nongnu.org; Wed, 14 Oct 2009 07:18:51 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1My1sU-0006Ne-U3 for qemu-devel@nongnu.org; Wed, 14 Oct 2009 07:18:50 -0400 Received: from [199.232.76.173] (port=60194 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My1sU-0006Nb-KB for qemu-devel@nongnu.org; Wed, 14 Oct 2009 07:18:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54381) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1My1sU-0003EE-6q for qemu-devel@nongnu.org; Wed, 14 Oct 2009 07:18:46 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9EBIjlM010475 for ; Wed, 14 Oct 2009 07:18:45 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9EBIfsh019196; Wed, 14 Oct 2009 07:18:44 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Wed, 14 Oct 2009 13:18:14 +0200 Message-Id: <3a07ef65ff39900981ff2955d041da2a513a5556.1255518915.git.quintela@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 2/4] mc146818rtc: port rtc 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/mc146818rtc.c | 85 ++++++++++++++++++++--------------------------------- 1 files changed, 32 insertions(+), 53 deletions(-) diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c index f076667..b1946c3 100644 --- a/hw/mc146818rtc.c +++ b/hw/mc146818rtc.c @@ -501,68 +501,47 @@ static void rtc_set_date_from_host(RTCState *s) rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val); } -static void rtc_save(QEMUFile *f, void *opaque) -{ - RTCState *s = opaque; - - qemu_put_buffer(f, s->cmos_data, 128); - qemu_put_8s(f, &s->cmos_index); - - qemu_put_be32(f, s->current_tm.tm_sec); - qemu_put_be32(f, s->current_tm.tm_min); - qemu_put_be32(f, s->current_tm.tm_hour); - qemu_put_be32(f, s->current_tm.tm_wday); - qemu_put_be32(f, s->current_tm.tm_mday); - qemu_put_be32(f, s->current_tm.tm_mon); - qemu_put_be32(f, s->current_tm.tm_year); - - qemu_put_timer(f, s->periodic_timer); - qemu_put_be64(f, s->next_periodic_time); - - qemu_put_be64(f, s->next_second_time); - qemu_put_timer(f, s->second_timer); - qemu_put_timer(f, s->second_timer2); - qemu_put_be32(f, s->irq_coalesced); - qemu_put_be32(f, s->period); -} - -static int rtc_load(QEMUFile *f, void *opaque, int version_id) +static int rtc_post_load(void *opaque, int version_id) { +#ifdef TARGET_I386 RTCState *s = opaque; - if (version_id < 1 || version_id > 2) - return -EINVAL; - - qemu_get_buffer(f, s->cmos_data, 128); - qemu_get_8s(f, &s->cmos_index); - - s->current_tm.tm_sec=qemu_get_be32(f); - s->current_tm.tm_min=qemu_get_be32(f); - s->current_tm.tm_hour=qemu_get_be32(f); - s->current_tm.tm_wday=qemu_get_be32(f); - s->current_tm.tm_mday=qemu_get_be32(f); - s->current_tm.tm_mon=qemu_get_be32(f); - s->current_tm.tm_year=qemu_get_be32(f); - - qemu_get_timer(f, s->periodic_timer); - s->next_periodic_time=qemu_get_be64(f); - - s->next_second_time=qemu_get_be64(f); - qemu_get_timer(f, s->second_timer); - qemu_get_timer(f, s->second_timer2); - if (version_id >= 2) { - s->irq_coalesced = qemu_get_be32(f); - s->period = qemu_get_be32(f); -#ifdef TARGET_I386 if (rtc_td_hack) { rtc_coalesced_timer_update(s); } -#endif } +#endif return 0; } +static const VMStateDescription vmstate_rtc = { + .name = "mc146818rtc", + .version_id = 2, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .post_load = rtc_post_load, + .fields = (VMStateField []) { + VMSTATE_BUFFER(cmos_data, RTCState), + VMSTATE_UINT8(cmos_index, RTCState), + VMSTATE_INT32(current_tm.tm_sec, RTCState), + VMSTATE_INT32(current_tm.tm_min, RTCState), + VMSTATE_INT32(current_tm.tm_hour, RTCState), + VMSTATE_INT32(current_tm.tm_wday, RTCState), + VMSTATE_INT32(current_tm.tm_mday, RTCState), + VMSTATE_INT32(current_tm.tm_mon, RTCState), + VMSTATE_INT32(current_tm.tm_year, RTCState), + VMSTATE_TIMER(periodic_timer, RTCState), + VMSTATE_INT64(next_periodic_time, RTCState), + VMSTATE_INT64(next_second_time, RTCState), + VMSTATE_TIMER(second_timer, RTCState), + VMSTATE_TIMER(second_timer2, RTCState), + VMSTATE_UINT32_V(irq_coalesced, RTCState, 2), + VMSTATE_UINT32_V(period, RTCState, 2), + VMSTATE_END_OF_LIST() + } +}; + static void rtc_reset(void *opaque) { RTCState *s = opaque; @@ -609,7 +588,7 @@ static int rtc_initfn(ISADevice *dev) register_ioport_write(base, 2, 1, cmos_ioport_write, s); register_ioport_read(base, 2, 1, cmos_ioport_read, s); - register_savevm("mc146818rtc", base, 2, rtc_save, rtc_load, s); + vmstate_register(base, &vmstate_rtc, s); qemu_register_reset(rtc_reset, s); return 0; } @@ -741,7 +720,7 @@ RTCState *rtc_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq, io_memory = cpu_register_io_memory(rtc_mm_read, rtc_mm_write, s); cpu_register_physical_memory(base, 2 << it_shift, io_memory); - register_savevm("mc146818rtc", base, 2, rtc_save, rtc_load, s); + vmstate_register(base, &vmstate_rtc, s); qemu_register_reset(rtc_reset, s); return s; }