From patchwork Wed Feb 20 13:59:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10822411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99E6C6C2 for ; Wed, 20 Feb 2019 15:49:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8262F2D2C9 for ; Wed, 20 Feb 2019 15:49:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7685F2D3E3; Wed, 20 Feb 2019 15:49:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 205A62D2C9 for ; Wed, 20 Feb 2019 15:49:21 +0000 (UTC) Received: from localhost ([127.0.0.1]:41254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU7c-0003qF-D4 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:49:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTvu-000200-6z for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTvq-0005u9-3Z for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:13 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:43372) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTvn-0005UN-8a for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:09 -0500 Received: by mail-ot1-x344.google.com with SMTP id n71so40778176ota.10 for ; Wed, 20 Feb 2019 07:36:34 -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 :mime-version:content-transfer-encoding; bh=WonWmYMnT8u7LZWW1RNFTm76th+WgxeztPZLRKTOfE4=; b=dskQAQcMSKCTpMNshfMFyHEton0vbBwqjFEisPnrrQJZ8SwGIvP7SOTE+34/t5d3jo K4Pv7hpEWvl+EvjhW2BlxLPDeNCI5Ax5eiCoT7YHBbGMgAv3KOw8Xe/dSoIkhVvJyUSP Nq9qymjd4SL3fRcvgLMCeIsFK5fMkZzDfSn5frKnBmwjTegjGKk/Bvqd3smPK4ZU92ue yenYiMhVJar/ojNa6nTDVK+sKOI+eXVyvY3J3Pr/QxQKOHjDdKsbDU+mLPi/Q3WP0uJU EExboCNdRr+GNI62XkO7Hrj44zKwONyf4gAQFAwZcgtRnmuHXBenJp3uhWo8oAYQZFJQ OpUQ== 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:mime-version:content-transfer-encoding; bh=WonWmYMnT8u7LZWW1RNFTm76th+WgxeztPZLRKTOfE4=; b=OwOWrNSxh+6aPU6uB177WKwIAkaRbllj1v9eIchlSR37npJEaJA50CSoMA7NCdy9E/ spYP7/g4L8veuDLfRcRshjqX5zOdMbRn222ndzOf4LfmjCaacRquy6wtVp5BwzeAprMd vd/lVcJWOW1cdBRyaqByyLFL7NRHMiJpnAYrDkv+VkhJKAynPgCvZUH20tcS/PYR5E6Q /gVdzosN8uvadoonEMEuTpM6MpjQ3BdQ9N+gkL2Tcj2o5qFIiBUe7B24UtKiZ5PmtwNK bEXQAMuYxt74hVx1mRgrz+2VGlC8n3DtSXbq7wXM2TQ0e81cENA/r7R7kvIpXqAokN8E ko6g== X-Gm-Message-State: AHQUAubMGZLuAfx4DBjHQ6U05ZpojCo0gk11XPcq2bpQY3TmN49ZUIlo fy7S5/9j69ZiT2hAdNECjCLOHBPeqA== X-Google-Smtp-Source: AHgI3IbUuOoyHWCGBD75RsVjU2R2hIP+eUDSnEscqRbPcL1chmJIi/ZZmHuQJnj3HaYg4rq1W2Qm4g== X-Received: by 2002:a9d:5617:: with SMTP id e23mr22212269oti.193.1550671222553; Wed, 20 Feb 2019 06:00:22 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id q24sm8037917otk.46.2019.02.20.06.00.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:20 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 4F8BE1808FE; Wed, 20 Feb 2019 14:00:11 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 23A7F302812; 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:55 -0600 Message-Id: <20190220135956.22589-19-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> MIME-Version: 1.0 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] [PATCH 18/19] i2c:smbus_eeprom: Add a reset function to 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard Reset the contents to init data and reset the offset on a machine reset. Signed-off-by: Corey Minyard Reviewed-by: Philippe Mathieu-Daudé --- hw/i2c/smbus_eeprom.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index c0a0c4d501..44887b4a27 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -106,7 +106,17 @@ static const VMStateDescription vmstate_smbus_eeprom = { } }; -static void smbus_eeprom_realize(DeviceState *dev, Error **errp) +/* + * Reset the EEPROM contents to the initial state on a reset. This + * isn't really how an EEPROM works, of course, but the general + * principle of QEMU is to restore function on reset to what it would + * be if QEMU was stopped and started. + * + * The proper thing to do would be to have a backing blockdev to hold + * the contents and restore that on startup, and not do this on reset. + * But until that time, act as if we had been stopped and restarted. + */ +static void smbus_eeprom_reset(DeviceState *dev) { SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); @@ -114,6 +124,11 @@ static void smbus_eeprom_realize(DeviceState *dev, Error **errp) eeprom->offset = 0; } +static void smbus_eeprom_realize(DeviceState *dev, Error **errp) +{ + smbus_eeprom_reset(dev); +} + static Property smbus_eeprom_properties[] = { DEFINE_PROP_PTR("data", SMBusEEPROMDevice, init_data), DEFINE_PROP_END_OF_LIST(), @@ -125,6 +140,7 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(klass); dc->realize = smbus_eeprom_realize; + dc->reset = smbus_eeprom_reset; sc->receive_byte = eeprom_receive_byte; sc->write_data = eeprom_write_data; dc->props = smbus_eeprom_properties;