From patchwork Wed Feb 20 13:59:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158823 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5066920jaa; Wed, 20 Feb 2019 07:40:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IbG4+tGo+XcpjYyO33ly+5k3C9Fk9GrEtWm0QOrKqvOhQZfliciGPjS4mk2i4Ikkqsarmoc X-Received: by 2002:a81:3cc3:: with SMTP id j186mr27556788ywa.315.1550677213437; Wed, 20 Feb 2019 07:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677213; cv=none; d=google.com; s=arc-20160816; b=Cztc1SdPlZYmeLmqBNjQ/Tz0HmtJ8ygLcTgZ/g/OyU+0SyjMb2uBfI2g49/siFYRvs 7/Pte3ybO0thx0YwdkZb1LCeYL374ruTzjbBm6jmCiY02bXmhCkRnhY2pQ8kWzhyxwI+ L17VOg3r/vd21URbujA5/VCxZSrLxqCvgHSqHGQlyDDnooKoSWR7jU+zhBUtxxyoK0kW nAaOeUVbvc4lflPPSfD0kKGL3vuz7RVZO6VWkTHsAhTwQ4gaqmBF+CadtRVWAORKFobl 4QFsh5yCD7WNd/2sm39lyRIr+Wsq6jkmmMIMZtMJPlehQsjBTJzODllcLhYTX9VpLWEa z5lw== 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=57kh67Tu41hZVnC/NJgxfWgmjYyLR+EzK4WyD222hhs=; b=R2QQ9FuAXTWBBv9l90TEYTVwewiuhTm/T6eQeFCrJcQcXWMOj8w/shf5VAR5OqqXXQ +VFLzi7x+nmht1ZxfehyRKVsPi/dGbr6na0xKX2eYoG+7mlmnnZ0hWRfLx0qQzJ5GBAj s5I+P4TuMmMLBicNA6eCcM6xKBrYM7uat3EdcqKGlbmm92uDg2OE7qJWxQprkIp1GNUR xM3L7bW6GnVMl4w9/tWEqtAYBYM41XGbRKNMUf3OPUFP4TL68IaAiFooSDbjP/MzK8Kl da/1NTHq24WrL+5Fveqv4puMWWp9SOq4KvNlsR+lNb5OiW523aEWmKKm+zvG4FTtGOo2 VQmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XqljcMPq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b65si3106916ywc.333.2019.02.20.07.40.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:40:13 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XqljcMPq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([127.0.0.1]:41038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTym-0002x4-HX for patch@linaro.org; Wed, 20 Feb 2019 10:40:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTma-0002E5-Jf for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTmX-0000G7-Ng for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:35 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:36110) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTmV-0000CX-Hi for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:33 -0500 Received: by mail-ot1-x343.google.com with SMTP id v62so31914474otb.3 for ; Wed, 20 Feb 2019 07:27:27 -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=57kh67Tu41hZVnC/NJgxfWgmjYyLR+EzK4WyD222hhs=; b=XqljcMPqCYEZhtfx4jpFu60TdYCbwupCqoTeLBWKUNRD2vyNWGcER/hFRu44vTGUCm sB74cRDKcRbq1KLLmgwNgyuhPeJCatU+3eLSSfWnIIcLI3WWQT3B8yK9XjHwH4l5QMoE 4bmJ2TkpELDSjBRw/iddyy9LTREdkNd31BrbLCtAseQ+XbMjZlZE2J4W0kd9xsqQRAGD oclesWLQSBzeHQd+njBj0+JIHCRXJmbYyZ8wIJCHu7QXwRTZE+ujwnVsSHcVG4yzRKgn 3J92Lbn7xckwMgCPP1WROptAp1AXdKPkOWswcHDsXnar10Ox3U3BLmnn1q1+63z9huDa L2YA== 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=57kh67Tu41hZVnC/NJgxfWgmjYyLR+EzK4WyD222hhs=; b=uO+iYaeBWhh4R+ntDcZr1HMF4h+6pj9+G6+IHi0ABi6/zW7GtVgSyaUN8o+3R+iNgI Fj7kZhWromwDl1s5PwjMlsudpiGlQlP4pifHS2bGKwuAybamrYIc8pstv7M89Yt4acYK NNxJ3ovOy4L6ectdLdVh6IuNIaViIUsjBs57eG/SIUjllt42H2rq2aP7V7aRFQLcdTWS 0LiSxyLdPowBxNvVPhbOV8WeBEBGdIdqITVvWDxZ2E5vHuzRMbewWQ8NGyLTXldcdGmT l7fSmOmdD55DrsJURBggBJmaG6mYzsoFBjuYlfOtZtG6vUHXcBm2S9YVOXRnjwLqB3Yo m9Dw== X-Gm-Message-State: AHQUAubNTZ52jBe4E4wzxNW+k8B1HD/UAn+cji0Ba4M2QqR88H0UqAML IqImEKqjMn0Wpn5+lBrJfoSLx160Yw== X-Received: by 2002:aca:d6cc:: with SMTP id n195mr6124979oig.27.1550671219993; Wed, 20 Feb 2019 06:00:19 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id d6sm8107661oia.30.2019.02.20.06.00.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:d1f6:7172:48bb:512b]) by serve.minyard.net (Postfix) with ESMTPA id C48141808FB; Wed, 20 Feb 2019 14:00:10 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 98793302A62; Wed, 20 Feb 2019 08:00:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:54 -0600 Message-Id: <20190220135956.22589-18-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-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 17/19] i2c:smbus_eeprom: 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 , Corey Minyard , 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 Reviewed-by: Dr. David Alan Gilbert --- 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 b3cc9c7083..c0a0c4d501 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, buf[0], buf[1]); @@ -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; }