From patchwork Thu Feb 28 18:17:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159406 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp974589oce; Thu, 28 Feb 2019 10:18:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzEKJVjZJ9D6sK/o++UHtw0H8QcujpuchSlO9HAuSR2az4tc5NKHZT+N9Yx3VwmnAYdHL5N X-Received: by 2002:a25:5454:: with SMTP id i81mr741794ybb.142.1551377914725; Thu, 28 Feb 2019 10:18:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551377914; cv=none; d=google.com; s=arc-20160816; b=Gs0W0xaOwPVzNu2bBqQz0IYQz1GH3UwucXFRDzXOfiqU8Daat/Vdn6SMNDLfanz2Kn 4GktN383hLTIDdHvf11fzOnqPPrxytPYfQ2ADb9zUMVBrwuShxN1yb8v1CXywM8JFpWL /d5jb5KUqWY3recddPk1hWPdNdLCgcjwj91Aib3WWc28S3nGtHcKdDzKn1+Gl5j1KF65 JWVbF37VL7i1+XWum5kVwW9cQcVGyMPU/Hq+SC4N1eoKmM9f40mUyYB7/Wi2ZXiKAK1g JVaLANwAgV5Wxx49CYx9zam/Rs/o/cxiQmbVvVNgUevhKAIXgia1/tBSXSkTOtqzoyFs LFLg== 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=JYjjFU7iSnj9ynLadPIf8UYzDHe2jrZNf2Z7T2XbxME=; b=kzd8udXokOgK/BwLT+XVmIFRrufMGg2307afSeP0vTl+LJNLmD9BlDVIjTNf7smK/j L9Ut23O42Vuoo6SbndnHO7Od0tZCoF/r4oS/a7v3ggEtkrsPWCTW5kdpVx/zHsGh/Mou RXxVtDCpzFdXbDZnmyxCqd7PMZOsLKjGhNo4UleeeGNsjQHIkBwWmPHnVrDUfxg/7F4H I7kjcPhdsZ6po155V32zmrbuxQSsuH4sV7e0flW9qmXddiaWm+RQ9ix2w1d//ZJ/3srt 7JBMzGpe7zNYWkPiXbM1/jKMyrRrI6XyTUnCTAhYrIissOQFeIVdrw+0hqHfJzNmmJl7 yx/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=S8W+ciCX; 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 129si10714462ybm.204.2019.02.28.10.18.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:18:34 -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=S8W+ciCX; 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]:44493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQGQ-0000dI-6H for patch@linaro.org; Thu, 28 Feb 2019 13:18:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFh-0000Wp-2x for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002IO-Rw for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:49 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:33922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002Di-IR for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x344.google.com with SMTP id 98so18591592oty.1 for ; Thu, 28 Feb 2019 10:17:30 -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=JYjjFU7iSnj9ynLadPIf8UYzDHe2jrZNf2Z7T2XbxME=; b=S8W+ciCXcxfYgHZqhfY8v1m9/pGJPAehp2pUuajbVN+Kw6MAHd7ioHdP+BZBjMB3vK ZDWGk9+C4H0d6lvKDkXTTNwheX7MFD2iXZLSB0qGQwXk6jmqMEj6RucP0uyf5pSprIB2 Sb6xhwcYLz7ecj/klyxrjyXfEwFu+rPvYCInjqSD1XA3Ds7rnT1Da9UJ6IcRyMPa0Li1 UvhA28XWagoEyccIT89l8Cq483COM6Wx/VQQMIs9gd0WJ7D4jxUC4p5PPgJYDYZsCdGB HOcWgD1LNnHIYrrxpjRoVKYc0GZVlrxYLxAOeA+jnMYlYPDtKXPPv3F+j8JrNy6H5hye ry2w== 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=JYjjFU7iSnj9ynLadPIf8UYzDHe2jrZNf2Z7T2XbxME=; b=F0KgkVvYsdSWfwiKYg8gjl37zYwrYVkJG6aseddtl37DvsXfaKuaasZ1SpD9KilNAz UcSX8QvEXuBjBT5ESkv29urt9Wl+PRsrOWULm4I04Nm2jE19Il3p2hdqSYgb9KuGIdhC dyfmkGHWEqn2UVPfzjwFGv7n/zEQ0qJrB+iad6yYvKAxw35oeyF8vKOYXM9Xv92FSbes pLU/bw7LcRZ62KtwfNTRDKYQSlrXPD8EMBRVATyKqi8RZs1n892mls102alJ1vVvqZpn If6ANRYPZXR7OPuF/PPX7AzZdANN/GEa+KkWzM4H7j+e+mKUlVTI3QMGO+Dk+9H6+kXy YXng== X-Gm-Message-State: APjAAAUCh4dmx88gm3HalHC9MMfYm/MKKxW2LeeqyLVLjmF0bvEMUHWs ffQujQMAHSVHXq6kWpfWzQ== X-Received: by 2002:a9d:718d:: with SMTP id o13mr606528otj.119.1551377849520; Thu, 28 Feb 2019 10:17:29 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id a14sm8101441otl.46.2019.02.28.10.17.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:25 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:b89e:c7bf:12ab:ad14]) by serve.minyard.net (Postfix) with ESMTPA id CDE47180901; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id AF866302AF4; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:08 -0600 Message-Id: <20190228181710.2477-18-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190228181710.2477-1-minyard@acm.org> References: <20190228181710.2477-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::344 Subject: [Qemu-devel] [PULL 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: Corey Minyard , minyard@acm.org, "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , QEMU Developers , 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 3fbbffb4de..5b10c31ae7 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -26,6 +26,7 @@ #include "qemu/units.h" #include "qapi/error.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" @@ -41,8 +42,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) @@ -51,6 +54,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); @@ -63,6 +67,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]); @@ -80,15 +85,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(), }; @@ -101,6 +130,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; }