From patchwork Thu Feb 28 18:17:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10833573 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 83CFC1515 for ; Thu, 28 Feb 2019 18:26:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 701732F5C5 for ; Thu, 28 Feb 2019 18:26:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63FD02F5F1; Thu, 28 Feb 2019 18:26:00 +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 0FF422F5C5 for ; Thu, 28 Feb 2019 18:25:59 +0000 (UTC) Received: from localhost ([127.0.0.1]:44614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQNb-0006ld-5m for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Feb 2019 13:25:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46638) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFe-0000VO-BN for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002Ha-G9 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:44 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:35201) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002DZ-5v for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x343.google.com with SMTP id z19so18560642otm.2 for ; Thu, 28 Feb 2019 10:17:29 -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=578+1MXr+/10iSBsluW/Nwhfp8x/6PPyLTwDlnrEJC8=; b=qky0b50aJcOrdSjirc6oTNag3iYNWLtRWIH0Dpaef1WPuPiLLxDaKQpTU1QQj6YvwN RF9X4tWnq+IzygXmAMsybw2B/tGJZBEs8q9xohMgzOwDZJbF3pJds0LNMlwu839Blass 7Bo2+mkLT2ISemtjIn0FaM65JG3mYnwMtV6GgQiEbvapGsZIUP8wP20e60QOzQh42ZqD G7H7aRAEePjrsnoDNLHIS0vu0pSrWrGgWm/aHyzADK0GQGR7ZW2AS7oScrsD2kdJvBmB v1DuEx+f33ccGCoCeS+mpOQx3b+eV3SefJ6foAkcGsYZBP9gkGVlaRbZAuQej00fe/jI PFDg== 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=578+1MXr+/10iSBsluW/Nwhfp8x/6PPyLTwDlnrEJC8=; b=L7d2j6oZ8TzOZGAEugaXCdf3wsyVQLMoXUK5cUNbFDvWWO7wQ7RYf2PVyESkLuTSLx shQeDnzZA8XrpGBDUh2u9QzPeB0EA/y1KT1zjPPrl4LsCvMO5+/6nKz9QPirvL6oQPr0 2q3RRptVGdhBJt0zcRxxiCGDxKz1ZTvyyxI0h+E3xuXNhrcRkCTiD5fBadsTDNnRJNog k3b+zmCOMnuMLvsfeY0OMZfR14dPqLyZbTX/F6NDHdwxLAxE0JKDpXjzqMtTjNFb77RY QC16HJIVv8cvrMdR9sHOxkipVxzniYlXgkguyD9Bk7hCygd4TBofWrEMFSsHPzEd/+bw zKdg== X-Gm-Message-State: APjAAAX/iVTmY9RZ3hh9LV8lMJNquya9Mjhh04tMwVEMrpfKkQzVkY/J qKeSjVbluJ1tHf+p8+sZ6Q== X-Google-Smtp-Source: APXvYqxIP7G+wDCNfCIkDmJ3jtg+WJi1cJ1R8DwwJBndKi00PMA5y7kbo5Bj9f+Jlc8w+dIcGb6F7Q== X-Received: by 2002:a9d:7cc2:: with SMTP id r2mr702193otn.282.1551377848969; Thu, 28 Feb 2019 10:17:28 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id b131sm5471757oia.28.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 (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id D7F79180902; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id C61783028D0; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:09 -0600 Message-Id: <20190228181710.2477-19-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> 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::343 Subject: [Qemu-devel] [PULL 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: Corey Minyard , QEMU Developers , minyard@acm.org 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 5b10c31ae7..0ba5763fc2 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -108,7 +108,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); @@ -116,6 +126,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(), @@ -127,6 +142,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;