From patchwork Fri Oct 12 11:38:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 191101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2B59E2C0089 for ; Fri, 12 Oct 2012 22:39:56 +1100 (EST) Received: from localhost ([::1]:54514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMdas-0002OO-2x for incoming@patchwork.ozlabs.org; Fri, 12 Oct 2012 07:39:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMdZn-0000Lx-ED for qemu-devel@nongnu.org; Fri, 12 Oct 2012 07:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TMdZm-00081q-8M for qemu-devel@nongnu.org; Fri, 12 Oct 2012 07:38:47 -0400 Received: from 38.0.169.217.in-addr.arpa ([217.169.0.38]:57335 helo=mnementh.archaic.org.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMdZm-00080H-18 for qemu-devel@nongnu.org; Fri, 12 Oct 2012 07:38:46 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1TMdZY-0003Hm-Mj; Fri, 12 Oct 2012 12:38:32 +0100 From: Peter Maydell To: Anthony Liguori Date: Fri, 12 Oct 2012 12:38:29 +0100 Message-Id: <1350041912-12595-7-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1350041912-12595-1-git-send-email-peter.maydell@linaro.org> References: <1350041912-12595-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 217.169.0.38 Cc: qemu-devel@nongnu.org, Paul Brook Subject: [Qemu-devel] [PATCH 6/9] hw/ds1338: Implement state save/restore 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 Implement state save/restore for the DS1338. This requires the usual minor adjustment of types in the state struct to get fixed-width ones with vmstate macros. Signed-off-by: Peter Maydell --- hw/ds1338.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/hw/ds1338.c b/hw/ds1338.c index 16aba4b..b576d56 100644 --- a/hw/ds1338.c +++ b/hw/ds1338.c @@ -19,12 +19,27 @@ typedef struct { I2CSlave i2c; - time_t offset; + int64_t offset; uint8_t nvram[NVRAM_SIZE]; - int ptr; - int addr_byte; + int32_t ptr; + bool addr_byte; } DS1338State; +static const VMStateDescription vmstate_ds1338 = { + .name = "ds1338", + .version_id = 1, + .minimum_version_id = 1, + .minimum_version_id_old = 1, + .fields = (VMStateField[]) { + VMSTATE_I2C_SLAVE(i2c, DS1338State), + VMSTATE_INT64(offset, DS1338State), + VMSTATE_UINT8_ARRAY(nvram, DS1338State, NVRAM_SIZE), + VMSTATE_INT32(ptr, DS1338State), + VMSTATE_BOOL(addr_byte, DS1338State), + VMSTATE_END_OF_LIST() + } +}; + static void capture_current_time(DS1338State *s) { /* Capture the current time into the secondary registers @@ -74,7 +89,7 @@ static void ds1338_event(I2CSlave *i2c, enum i2c_event event) capture_current_time(s); break; case I2C_START_SEND: - s->addr_byte = 1; + s->addr_byte = true; break; default: break; @@ -96,7 +111,7 @@ static int ds1338_send(I2CSlave *i2c, uint8_t data) DS1338State *s = FROM_I2C_SLAVE(DS1338State, i2c); if (s->addr_byte) { s->ptr = data & (NVRAM_SIZE - 1); - s->addr_byte = 0; + s->addr_byte = false; return 0; } if (s->ptr < 8) { @@ -153,12 +168,14 @@ static int ds1338_init(I2CSlave *i2c) static void ds1338_class_init(ObjectClass *klass, void *data) { + DeviceClass *dc = DEVICE_CLASS(klass); I2CSlaveClass *k = I2C_SLAVE_CLASS(klass); k->init = ds1338_init; k->event = ds1338_event; k->recv = ds1338_recv; k->send = ds1338_send; + dc->vmsd = &vmstate_ds1338; } static TypeInfo ds1338_info = {