From patchwork Mon Nov 26 20:04:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 152074 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp335463ljp; Mon, 26 Nov 2018 12:31:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wzb+XInKRq2b6FH5QUHbJRv/gTir2Yw5RWhb9bdvbCtVL+fsa65sKRGNsPOqwCMmN5R5rf X-Received: by 2002:a0c:c927:: with SMTP id r36mr28625300qvj.51.1543264269178; Mon, 26 Nov 2018 12:31:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543264269; cv=none; d=google.com; s=arc-20160816; b=nJiz9T6ipxjQb8mnD5E6P/vyY8ej1v4umsfhvWFM9Pf8tXx4sFqrelpXEMmF6/oUIO c78pI0VenwQz3CyA7ZP7dbj3/HUsFamntsYhbAAN5R69wHMRkYqVahT9eq+RRHvH3nop 3O0qyrjakNJiCLnZZw36bGLVXhL5MOYvOFANCRT6VPNgo/F+NDQ09/Sx9Z5A+ozivv/0 JMhGm/JA0D4QWzlJeAoJplb91rihYVXvSvTzEJ19MYhQNBEraJ+5PJQqqFFGjwwfxMx+ ZxfweI19oLjgJbVdtf1FI+L3uxN5koC52VEtbQ8BosUNZO9WFoVcaqK+elV6M49gIXDt ka4w== 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=lSuM852stPEpYnpnMdFOlTomPlqpFcyEkuwe5W4k325A8zvB9b+vkXWctFNXBInOIA krE6dbX4K6DLboCpEUcrQfazaN/bIDBREI8tL7GzJCW164S72DCU/rYDgrYIVLv1brN2 B3AID11UazpHfWM2pen6On7Iw1DJU25wFpLkCBNWEfdZay9qWD/xxg5w2TfhdItFxkCj zOpl2PG5/NCtccMUge7P4RFudowDdBzQ0MfPXNQmhbThO1gGVIGXWr88A6T0k6Vts9vM gEwJVVIKB4embzmrQLrxlXffus/e4B5eiBYuC1MSIqC3Qm6oQiO98BkqxNZlAFAC/ZoY +QNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=soaMz2vc; 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 c73si1012136qke.177.2018.11.26.12.31.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 26 Nov 2018 12:31:09 -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=soaMz2vc; 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]:38713 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNXA-0008AE-IH for patch@linaro.org; Mon, 26 Nov 2018 15:31:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55386) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNE4-0007Vu-LW for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:11:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRNE1-0002kH-0Q for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:11:24 -0500 Received: from mail-oi1-x244.google.com ([2607:f8b0:4864:20::244]:33550) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gRNE0-0002k4-PZ for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:11:20 -0500 Received: by mail-oi1-x244.google.com with SMTP id c206so17136839oib.0 for ; Mon, 26 Nov 2018 12:11:20 -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=soaMz2vcwkv0q/QF9vzsIDjk3dBSuNo/LaQOqob3UGHLnTdb9Oci4J2JC69SxKMYLf zEYQ/IRGikMITDk4zKguey+zkuuvGMtq36lcrvmMBBkDT3Ht1QjIO4cWXem1qdJ+ee9f YTKfLyjAJiRpU97zmhafHAxdsBOAAg2f4Um2mP7jsHkqc2e+E5yfbEBbLE7GKoZAEDDS v+S8smmkb16biO3t+yLvkNTptiSFX9Mi2kdORb9ipcdwxqJiY0ZZUcVe9sp4du6Ks01Q vNzCcRM8+gSmOAbwIhajZDA3T+qBbRaS1qTYTqOK4b3TSwmMHwHw6nPZp9aIlNrXZ78K UZCA== 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=cp3LTyrI0Hp2dV6735MlwMLiUPI1Ab9Zmeo0SEOHqseTce03BaH5/x/xE37Gpb/6Yo Lw9eF4Xu28/BTN9awsocacCzKgQgTkl1Mraclls8FJYTsKX29CxkQ/uuXzfAaIUa7DVK PnIFEGG/RLyHm02wgNOLqLSOWguMrf/n0D9/hAvV5riDpbBbXMKQDz/C4K66prIuX6D8 7ppGA2fJ2HHfmxDxjMEDIt826l2NPSdBVafDXj6FhHCRjQ4kVQteacOeLyycMvrj7k5a 7FXj1PxM/7qFw/MhXEau9LjTf/qqZMrgQqKijTU+swkqExnfY4exNu+GJfUmfinleQ4P m/0g== X-Gm-Message-State: AA+aEWYGLFvNNUj3KhTC2rsVCuYl/dh3jXyCM0qZwmGY9p7Ul/7XG8Nc 5PJEEp9Le6o3YfrfH5gHyg== X-Received: by 2002:aca:6046:: with SMTP id u67mr3360512oib.295.1543263079288; Mon, 26 Nov 2018 12:11:19 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id s66sm390644otb.74.2018.11.26.12.11.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 12:11:17 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 021061F8D; Mon, 26 Nov 2018 14:04:50 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id D834E30146F; Mon, 26 Nov 2018 14:04:46 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell Date: Mon, 26 Nov 2018 14:04:33 -0600 Message-Id: <20181126200435.23408-15-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181126200435.23408-1-minyard@acm.org> References: <20181126200435.23408-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::244 Subject: [Qemu-devel] [PATCH v3 14/16] 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: 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 --- hw/i2c/smbus_eeprom.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) -- 2.17.1 Reviewed-by: Dr. David Alan Gilbert 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; }