From patchwork Thu Nov 15 19:24:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10684923 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AB594109C for ; Thu, 15 Nov 2018 19:29:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 948CA2D007 for ; Thu, 15 Nov 2018 19:29:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 890C72D00C; Thu, 15 Nov 2018 19:29:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 04E9A2D004 for ; Thu, 15 Nov 2018 19:29:28 +0000 (UTC) Received: from localhost ([::1]:40452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNKS-0007Gy-3g for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Nov 2018 14:29:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56295) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNGP-0003Zq-Nf for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNNGF-00084G-Fi for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:15 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:35206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gNNGD-00082W-Gl for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:05 -0500 Received: by mail-ot1-x343.google.com with SMTP id 81so19101039otj.2 for ; Thu, 15 Nov 2018 11:25:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=gPp0Jj9QcW7Ga60MVfBaCOOAOQyOvMf44N8geulCpZ8=; b=hFWsNlH9ttn7qrWMFwKiZhn2uQo5Jrg6F6tCHt+awI5bQHlYckk5pPHfvmA8m2YJWu aJEiqkMB1jvgsjxbOj6ZQTSEuNCSpaDg5ivg/HqGXkosPQVe6lwNq6yf0j3reZaYIvXH yBZtRReyNzau9Iia27AhZI/j6A3hrCTtxuMPowNwk/FUkr+dY1ddNG6nOEGdOclcwB8/ 4DryCPtYMxjNQ2ddQOdZ3EJSZ/mRJW9AfrqR97lLpzzPq/evrpgxzML17hzYzGhRNJFX Omt6HM4a9EOF/yD5oTOfWYvY0bAboHIwpqrETY6FTRLpWC9sKvN+bh7Ja3H351Nes5LK NoCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=gPp0Jj9QcW7Ga60MVfBaCOOAOQyOvMf44N8geulCpZ8=; b=UUO8gfeiwUNr4DAZh8Vz5XsohuvDV5S1zlAaZ8wLjYhAAQ2QtHdinFuVbBiQlo0zX0 C432uJNNlak7ercUzywW83jKMEK9Sp5CKZ/i1TQl4u9a+h99tioNbmVSxz+6iWlB/827 L9aEUuXtWe73HNw59RopmDsQ2haDJ+E0l6g0sXooE0KlWctGxROYu6QwPapR/hVWywet 3oBIc3rzLo4YjEn5MAy79lnOpYLjwExWG4JaLAMWFEt6g4hsJ9Wg9SM5LifHL5N4fZDp JTRrEH7zMF6IjbT+XQpVTJI6p0usmVUkie4LdMl4OaSksES8fGgmUJNqUqdwhmw3ofmi NErA== X-Gm-Message-State: AGRZ1gIWWUIYz6EZ/caW4378IAtXhmgjqmSFmgG2WqyAjf7R0mD0vuPF FRrPV6AAlPZdWj2ReVBTgQ== X-Google-Smtp-Source: AJdET5dQlS8V+jq+rViZp4vhjUlXYOBJNqQgLMO+IfeRkHe+jMpGrsCSUFP0vSZbQm3r033/oYOBsQ== X-Received: by 2002:a9d:b8e:: with SMTP id 14mr4199442oth.279.1542309901868; Thu, 15 Nov 2018 11:25:01 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id c58sm21404439otd.34.2018.11.15.11.24.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 11:24:57 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 8223B1E53; Thu, 15 Nov 2018 13:24:51 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 1834030146A; Thu, 15 Nov 2018 13:24:49 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 13:24:45 -0600 Message-Id: <20181115192446.17187-12-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181115192446.17187-1-minyard@acm.org> References: <20181115192446.17187-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::343 Subject: [Qemu-devel] [PATCH v2 11/12] i2c: Add vmstate handling to the smbus eeprom X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , minyard@acm.org, Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard Transfer the state of the EEPROM on a migration. This way the data remains consistent on migration. This required moving the actual data to a separate array and using the data provided in the init function as a separate initialization array, since a pointer property has to be a void * and the array needs to be uint8_t[]. Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert Cc: Peter Maydell --- hw/i2c/smbus_eeprom.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 8e9b734c09..942057dc10 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -24,6 +24,7 @@ #include "qemu/osdep.h" #include "hw/hw.h" +#include "hw/boards.h" #include "hw/i2c/i2c.h" #include "hw/i2c/smbus_slave.h" #include "hw/i2c/smbus_eeprom.h" @@ -39,8 +40,10 @@ typedef struct SMBusEEPROMDevice { SMBusDevice smbusdev; - void *data; + uint8_t data[SMBUS_EEPROM_SIZE]; + void *init_data; uint8_t offset; + bool accessed; } SMBusEEPROMDevice; static uint8_t eeprom_receive_byte(SMBusDevice *dev) @@ -49,6 +52,7 @@ static uint8_t eeprom_receive_byte(SMBusDevice *dev) uint8_t *data = eeprom->data; uint8_t val = data[eeprom->offset++]; + eeprom->accessed = true; #ifdef DEBUG printf("eeprom_receive_byte: addr=0x%02x val=0x%02x\n", dev->i2c.address, val); @@ -61,6 +65,7 @@ static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); uint8_t *data = eeprom->data; + eeprom->accessed = true; #ifdef DEBUG printf("eeprom_write_byte: addr=0x%02x cmd=0x%02x val=0x%02x\n", dev->i2c.address, cmd, buf[0]); @@ -78,15 +83,39 @@ static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) return 0; } +static bool smbus_eeprom_vmstate_needed(void *opaque) +{ + MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + SMBusEEPROMDevice *eeprom = opaque; + + return (eeprom->accessed || smbus_vmstate_needed(&eeprom->smbusdev)) && + !mc->smbus_no_migration_support; +} + +static const VMStateDescription vmstate_smbus_eeprom = { + .name = "smbus-eeprom", + .version_id = 1, + .minimum_version_id = 1, + .needed = smbus_eeprom_vmstate_needed, + .fields = (VMStateField[]) { + VMSTATE_SMBUS_DEVICE(smbusdev, SMBusEEPROMDevice), + VMSTATE_UINT8_ARRAY(data, SMBusEEPROMDevice, SMBUS_EEPROM_SIZE), + VMSTATE_UINT8(offset, SMBusEEPROMDevice), + VMSTATE_BOOL(accessed, SMBusEEPROMDevice), + VMSTATE_END_OF_LIST() + } +}; + static void smbus_eeprom_realize(DeviceState *dev, Error **errp) { SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); + memcpy(eeprom->data, eeprom->init_data, SMBUS_EEPROM_SIZE); eeprom->offset = 0; } static Property smbus_eeprom_properties[] = { - DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data), + DEFINE_PROP_PTR("data", SMBusEEPROMDevice, init_data), DEFINE_PROP_END_OF_LIST(), }; @@ -99,6 +128,7 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) sc->receive_byte = eeprom_receive_byte; sc->write_data = eeprom_write_data; dc->props = smbus_eeprom_properties; + dc->vmsd = &vmstate_smbus_eeprom; /* Reason: pointer property "data" */ dc->user_creatable = false; }