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: 151241 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7401302ljp; Thu, 15 Nov 2018 11:28:25 -0800 (PST) X-Google-Smtp-Source: AJdET5fjU7HBxJ+HEXPuziFX9FG/WjOTHtZwZ6BSPKHXdiZB4pycyh8Yk2U7xhWB938fsGnrGei+ X-Received: by 2002:a0c:d602:: with SMTP id c2mr7342364qvj.151.1542310105076; Thu, 15 Nov 2018 11:28:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542310105; cv=none; d=google.com; s=arc-20160816; b=Xc4mqNAq+phHfJoI6aY2uHH4PmqZzMhfLV7o9W8J3+BzYb/3nHfGXbQgPw2PzS8eCU 4EMLWS8yGuce+eoJQ/FGN0k0mnDwiX/SrlowkyrWqx65SQfVEf4bu9qmt4TdWRPG7PYg msbYDNv182RdsCBc8o6Ko5sC0G4ITjsRwfaZpCNnZn4qy182O76cVcgLXXZL6QF+DET6 6RdwOhH+GQb4NLLXU4Ys9mHS0z331gXxSv3zCoJfOv9AoYM0FBkdsKGRggOyT4tczYvK Yjet1+cuYvqdnzRK5EbA3Pson3v0AzHQ1ywqMHgMnNGj7ifiZuNt3E9U2b3p80WoxGQ3 on/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=gPp0Jj9QcW7Ga60MVfBaCOOAOQyOvMf44N8geulCpZ8=; b=TjN1LoB6TlJmUaJIueSeoeuyaa6bc2o+O3tKUU40nQkW7ihD60Mu85Y2a53EdSHgHQ elfxlybiHkjD85gay2PplAOimJJJhl4S26JITAs2V+TxMINnf33uGuyXVIeFDvrWHoT5 FW3a7CTbt9N86hsMoqBOOv2e9gqtr2nsgBh97p5ZsTaOgBBiovmLkr1OgKfLa57Dy7r4 2Dn/MuPAZh2YLaDjvLfZ8Gq85wq15gEAnkVl6YwSAki/yqED6+b1JfbdCwESCxIWAsCR AizMTCtZdzGIIKfAcsYVx32JbZeAzo1pX5yQfxC7ifywaEgdyfy+15/MbM41w1jNYUvC RTYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hFWsNlH9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b2si807273qti.171.2018.11.15.11.28.24 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 15 Nov 2018 11:28:25 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=hFWsNlH9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:40444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNJQ-000609-Cz for patch@linaro.org; Thu, 15 Nov 2018 14:28:24 -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-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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.17.1 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; }