From patchwork Mon Jan 28 17:54:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10784241 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 177BE6C2 for ; Mon, 28 Jan 2019 18:07:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 065F22B777 for ; Mon, 28 Jan 2019 18:07:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE1852B9BF; Mon, 28 Jan 2019 18:07:16 +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 6BAE62B777 for ; Mon, 28 Jan 2019 18:07:10 +0000 (UTC) Received: from localhost ([127.0.0.1]:36280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBJN-0006h2-K5 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 28 Jan 2019 13:07:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEC-0003Zq-K0 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8U-0005tU-Vr for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:04 -0500 Received: from mail-it1-x142.google.com ([2607:f8b0:4864:20::142]:38418) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8U-0005eu-Pj for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:54 -0500 Received: by mail-it1-x142.google.com with SMTP id z20so20674869itc.3 for ; Mon, 28 Jan 2019 09:55:25 -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=JmH/T84G/XlZ/0h8GK5SIo7bqvVFU/nja/i8J0RAExoWyxSKvnjH91MJXETDx5d4Wd qRQ1CqW2puQD360YTjlsYPxpD6/WOZBGefOPsIKtDT7O417yTmH4c+69O5vwApCUc0Ft 22+ekcQWnb+VDJM7JzrspvovYXu8My4ucBi1PtPZXUl34M7FL6/jj+UXYj0apxVAxJh7 CrfK68lzlbYSRHYhXQyEwYgo+fK79j70Qha68CsiDVRIVR+4Rk97mcr/iw+ldp70Nn+B i1rPzmM6CETRVqRuZiZkCkTtuPBQusYadBznC68hQRSuYRijaIsUji6Cj16wmSBHG6BI PR4Q== 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=fbtj/D0oYlLHNbUelFwfW47Zn33R9odbVxnb9WT1SDa6bXObyju9AK3KDjFXtEq4kT zLAS6PxSDc6aaZeG4Wkg+BgkZtqDQUOHvHoczaZdYb7BxtRw0eXhjoNYODJJomBCHVxm VzdbDlo2v0XdZCHm8hOEXRIKUgz3Vt1fPUF2AvRAUJiobYlk+dc3lfvl7qEoym6PltUv WBlKfGzccHMN7WClhSLi95opWAWF5qAzZwU27I0MhtaPGZetIxGadMapLd2+Y9srG2fj J5muNfZrRbp+zsG2n4SLGU1J15RNm4rXqgP9oSsh1eG4mOH3k812Ecxrxy+2z3NCEwZX aQng== X-Gm-Message-State: AJcUukduEG9bZL/+KcthfIElCZ4ua+y2PjLHUzJplVvMvhw4UNZOlgvX LDQ/K75Ttkl6Zbzn411WwA== X-Google-Smtp-Source: ALg8bN45U5uZOtD9KKsqDSgDQ23x8EqZZCxV5VURmMVIFqxUG3b/SEJvj+bBjW+D84j+jogojfEcSw== X-Received: by 2002:a24:ba0b:: with SMTP id p11mr10809557itf.113.1548698124649; Mon, 28 Jan 2019 09:55:24 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id 193sm42060itl.19.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 EFDFCBD2; Mon, 28 Jan 2019 11:55:17 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 95CEE301156; Mon, 28 Jan 2019 11:55:11 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:57 -0600 Message-Id: <20190128175458.27255-19-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> 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::142 Subject: [Qemu-devel] [PATCH v4 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 , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" 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;