Received: by 2002:a17:907:c68a:b0:84d:2074:29bb with SMTP id ue10csp298799ejc; Thu, 19 Jan 2023 04:40:23 -0800 (PST) X-Google-Smtp-Source: AMrXdXtXPCk6QS4L35Y26r3lKyQuLiH2UnZxlWJolmJEMzX3GAQaNkhwHezD/tYfsu+GxWFLZlTl X-Received: by 2002:ac8:4c90:0:b0:3ad:202f:8797 with SMTP id j16-20020ac84c90000000b003ad202f8797mr14441504qtv.9.1674132023689; Thu, 19 Jan 2023 04:40:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674132023; cv=none; d=google.com; s=arc-20160816; b=RDviAUPAwYO7nYziHXbYzE4v4ndCGdbyEQCm6szhKg6/JetPI2R7Dd6hpUKYfhMS4V QjkYLDWDPii8gEthdqxUhogfL+nsSCKbOrIVGjpvDEhuqfdvGrOG0whgj+D9k56/WmSR 6f1G7y1tPEtTJot9iT9/Y/oUpJiq39cXFY77G3Ii2e+CIex1S9eZXpMACt+0JmWm7VaT MsYyKBxheiQ1kDzmaLaOhKKQT1uIng3JJDKgEWXqjATUPmM8rmLqVFjify5YvQC8v6SL 0p9CrgnMsEmJbDHzTQ5VbOGksGwnQM08aMxTWe+LGeBdkmCSfxkSauW+zBHlf8gG3kh8 +Kmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=vwCgsbIM968WIH0LL7/s2UntYQDj4IZL6q4jhmUwAEI=; b=os3svgPYDIkzEoEVzLpzhVka2KJCjUgnuJdtkJFLL462dSVYkKAbPi2Jo7/ZhLNju5 pqPXs8MgTCWGlJG0q3SDXdNkB3/92E5khsuR9bzUMYTSKs7KoulS53DRWJ8ewLBMj8Rk Q+WfzRMq/LW83L4ird9sg2PWQ2bPycjRkL7GaK3eNCg5uqNGIB/RFzzwlZETOQmUw7eX goDIS+S3DE/0/18dyjrrFB+ixTnM76QINF48EAE1GIhTIpenZF01UWh2jch81ao4rbkv ltRI/q8ucHcGHV7nz20MM9Ve73uLlvKoGmTVvM0YgS2BrvNG183zjPPoHdgVg1LvoaEt vfhQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=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 j7-20020ac806c7000000b003a69225c2bcsi21669536qth.342.2023.01.19.04.40.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 19 Jan 2023 04:40:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pIU8x-0006x0-Mi; Thu, 19 Jan 2023 07:35:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIU8v-0006oY-JU; Thu, 19 Jan 2023 07:35:45 -0500 Received: from gandalf.ozlabs.org ([150.107.74.76]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pIU8t-0007dU-VZ; Thu, 19 Jan 2023 07:35:45 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4NyMYB6lm5z4xyK; Thu, 19 Jan 2023 23:35:42 +1100 (AEDT) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4NyMY84gxGz4xHV; Thu, 19 Jan 2023 23:35:40 +1100 (AEDT) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Delevoryas , Joel Stanley , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PATCH 14/25] hw/nvram/eeprom_at24c: Make reset behavior more like hardware Date: Thu, 19 Jan 2023 13:34:38 +0100 Message-Id: <20230119123449.531826-15-clg@kaod.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230119123449.531826-1-clg@kaod.org> References: <20230119123449.531826-1-clg@kaod.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=150.107.74.76; envelope-from=SRS0=w1SB=5Q=kaod.org=clg@ozlabs.org; helo=gandalf.ozlabs.org X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: L6GpWxZVqo0d From: Peter Delevoryas EEPROM's are a form of non-volatile memory. After power-cycling an EEPROM, I would expect the I2C state machine to be reset to default values, but I wouldn't really expect the memory to change at all. The current implementation of the at24c EEPROM resets its internal memory on reset. This matches the specification in docs/devel/reset.rst: Cold reset is supported by every resettable object. In QEMU, it means we reset to the initial state corresponding to the start of QEMU; this might differ from what is a real hardware cold reset. It differs from other resets (like warm or bus resets) which may keep certain parts untouched. But differs from my intuition. For example, if someone writes some information to an EEPROM, then AC power cycles their board, they would expect the EEPROM to retain that information. It's very useful to be able to test things like this in QEMU as well, to verify software instrumentation like determining the cause of a reboot. Fixes: 5d8424dbd3e8 ("nvram: add AT24Cx i2c eeprom") Signed-off-by: Peter Delevoryas Reviewed-by: Joel Stanley Reviewed-by: Cédric Le Goater Signed-off-by: Cédric Le Goater --- hw/nvram/eeprom_at24c.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c index f8d751fa27..5074776bff 100644 --- a/hw/nvram/eeprom_at24c.c +++ b/hw/nvram/eeprom_at24c.c @@ -185,18 +185,6 @@ static void at24c_eeprom_realize(DeviceState *dev, Error **errp) } ee->mem = g_malloc0(ee->rsize); - -} - -static -void at24c_eeprom_reset(DeviceState *state) -{ - EEPROMState *ee = AT24C_EE(state); - - ee->changed = false; - ee->cur = 0; - ee->haveaddr = 0; - memset(ee->mem, 0, ee->rsize); if (ee->init_rom) { @@ -214,6 +202,16 @@ void at24c_eeprom_reset(DeviceState *state) } } +static +void at24c_eeprom_reset(DeviceState *state) +{ + EEPROMState *ee = AT24C_EE(state); + + ee->changed = false; + ee->cur = 0; + ee->haveaddr = 0; +} + static Property at24c_eeprom_props[] = { DEFINE_PROP_UINT32("rom-size", EEPROMState, rsize, 0), DEFINE_PROP_BOOL("writable", EEPROMState, writable, true), -- 2.39.0