From patchwork Mon Sep 24 18:33:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 11680 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id C012924140 for ; Mon, 24 Sep 2012 18:33:20 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 6BEC7A18F35 for ; Mon, 24 Sep 2012 18:33:20 +0000 (UTC) Received: by ieje10 with SMTP id e10so10800276iej.11 for ; Mon, 24 Sep 2012 11:33:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=g+AjbWa+UEJF7e8PEWoSEJm+zDebMY0tN8B5U6HEnIQ=; b=XfBD517Ar9wYuDY5ATmDI3ImIWDrC5HnPGCcqhJf1stmbKnmUsloFSWjSFCzjQNro4 fEsUOHlCy/EysaWgSdyEUE7RMXFRnc0XP6SbmnUs8TirYKzo6oa2YFpp5d1QZoUK4+Sd rX8qTRjGbhDceqXC7HPfoRRAD6YJHds77AZ/4VRl20XqI6zhvApyJztoVuL7npoGQStA tlkYwYEEHi4lAKodW3KaRPQIycz89GtLhfezPnuI56u2VuNiIfmifN25JK4xLgZm3Tc7 je92aGl8ddLn9AMHdplMOtko5ToNLVPm0uAKlVxqAB0jB+3/rg7EtqjOCGWMzt2jXRl1 2DMw== Received: by 10.50.0.193 with SMTP id 1mr6118794igg.0.1348511599803; Mon, 24 Sep 2012 11:33:19 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp257080igc; Mon, 24 Sep 2012 11:33:18 -0700 (PDT) Received: by 10.204.157.10 with SMTP id z10mr5145134bkw.63.1348511597413; Mon, 24 Sep 2012 11:33:17 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id gk18si16358658bkc.83.2012.09.24.11.33.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 24 Sep 2012 11:33:17 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1TGDT1-0003TW-PI; Mon, 24 Sep 2012 19:33:15 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org Subject: [PATCH 4/4] hw/ds1338: Implement state save/restore Date: Mon, 24 Sep 2012 19:33:15 +0100 Message-Id: <1348511595-13327-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1348511595-13327-1-git-send-email-peter.maydell@linaro.org> References: <1348511595-13327-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQnFLBXM4BuvFQZK6ZeDtnNC4iOTOX1fxrgBLl//eGIcGikQAjetru1vym+7vCNwYEkfRZ8E 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 = {