From patchwork Mon Jan 28 17:54:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156838 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3726294jaa; Mon, 28 Jan 2019 10:11:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN55Mq2vq6gNJFvrFWEwnz0NbydWkpnavPrlNCUX99bwdKLEGV8DVXLInzSqrhvAgKtuz8L9 X-Received: by 2002:a1c:7511:: with SMTP id o17mr17748126wmc.42.1548699084308; Mon, 28 Jan 2019 10:11:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699084; cv=none; d=google.com; s=arc-20160816; b=h6BMaCFFzf+i+BayEwDNTSGvx9PElZhhUBIqLOuOHlYMwspXeOsfnxys/OXqp/nIyz gJcuUEGT4rGm5CmC8SKb5DDNY+RC1eRvYO+hpeTfuduyp02BKKevmLMCG95X51t8vzOd 5llq2O/PQcp3zMF52pjFIZWH6AHmSdxreXOfPXZcxibZuMFCYxLNkgcZNWPlKRI22rCC rFSLiQpSsJZxxS31PRCip1W1nPEMnuGrVvOYNSzU5RsgBSxO04PZ0JfoUwqPXyosdSW2 saFFEdj4uD3zhIQnW8N7rSvW5WfddmG9Bi/VeSHZeDIWmkiWMWEHl5TOc163su1galuF b2YA== 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=JcRBycFgrWl5K2A1ECqVlfICzmyn8KVSxh5spmBV+pyuR5POXnzhAY1vFiMwPAfoJy 1FyTZZAvt2lgt5ki+jRliu9IUq8O70HIaN32qVGgGyqwp3dBqkMRQJYZEvL1wtI04jB7 Bh6jshp7lSr8LgtD6XJuyQPilVVqu6Cg8Rhbe8jjVH5ECWBUzjeFoi9DofFvt1ky/UB3 /ieg0b7VS02KOkYh2l8Szz9+OK4SrCaN7ien1iGTrx3dnTBs6YELyHZ8EDLxxmI01QFp K3f30cSlF2B4x68XoCVjzT3w9LEDiMrI2WCxgJzWh0JfB6ahIm7gxZs6L/7Y2JnTyQAN HSLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=VL3xUvuf; 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 f17si85368041wru.378.2019.01.28.10.11.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:11:24 -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=VL3xUvuf; 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]:36322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBNS-0001kI-Pi for patch@linaro.org; Mon, 28 Jan 2019 13:11:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBED-0003Zq-Vc for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8U-0005sK-Di for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:02 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:37865) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8S-0005fH-DT for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:53 -0500 Received: by mail-pg1-x543.google.com with SMTP id c25so7528635pgb.4 for ; Mon, 28 Jan 2019 09:55:26 -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=VL3xUvufk3QjmbnIAvpO0iSEQbC2c4YLIKhq62LRQknO3Vvv+Jvfyj0Si6PZocihFQ +YL8R1c2Icpq98GO0UlOQO3bxKGvOgHYsa8O9Wop/EX3OG5JNcSOM0J35XZHuh5LEm6V 3Ha66K4IDHOXP+cvN7g7xxByS6pyF0rjGQZUP/s3ih+pxLta/VwX9AKfiKup2ChUlT2t ypIvRVqo7BNRaOGXsEhuQNHafLKdXXYXZCc1z1quOlaWt753k8r25UCyKluUk+ndnJhn ErPgAjPhdAowszz9GVnjQaKIaG6ZFchsR8bM4zhwL6/C7aCkO1DlkElF9ekVEMoy28c5 cXow== 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=cC7gLMfuQTWP5ANZ3HDYcBkosbRLjVhcY8au8iy8MwllxFrpmteGIkMb7VeR56isqY Wj7J/Zizri7wJxk5q+gnn94/b2qZezBfzYa69LuSyjWDv9Ls1SLi027+w2mU5YiRBaff 4ciei9tBwslPl1R4Hg9jMT3XjxdTufIBIjN486PY/vkTnTSh9+xsqPS7B83+gOX371By B/tg0gwsaZcEH2oiWRnzLucj41XsemRlENRyo6mniFk+HqDXOrgn/fWQl8cUMEqSZbT/ L6ngcaCVhqfd0TZl2q9Nez2VJgvx1PYFA10EES160Dg5CgMCy0V1rzr5ZWW2so+q1KVl h7uQ== X-Gm-Message-State: AJcUukew2DJL1HbCMfEFgSubXl5s9ed7GbWrJi480qph1FweMONtvDGS n9GDB3EKSbqWtt6R1n4zHg== X-Received: by 2002:a62:e704:: with SMTP id s4mr23074902pfh.124.1548698125167; Mon, 28 Jan 2019 09:55:25 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id b7sm53376950pga.39.2019.01.28.09.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:22 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 823803A3; Mon, 28 Jan 2019 11:55:17 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id D04CF30052D; Mon, 28 Jan 2019 11:55:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:56 -0600 Message-Id: <20190128175458.27255-18-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::543 Subject: [Qemu-devel] [PATCH v4 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 , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" 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; }