qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Joe Komlodi <komlodi@google.com>
To: qemu-devel@nongnu.org
Cc: komlodi@google.com, venture@google.com, minyard@acm.org,
	 peter.maydell@linaro.org
Subject: [PATCH v4 3/3] hw/i2c: smbus_slave: Reset state on reset
Date: Tue, 20 Feb 2024 21:11:23 +0000	[thread overview]
Message-ID: <20240220211123.2664977-4-komlodi@google.com> (raw)
In-Reply-To: <20240220211123.2664977-1-komlodi@google.com>

If a reset comes while the SMBus device is not in its idle state, it's
possible for it to get confused on valid transactions post-reset.

Signed-off-by: Joe Komlodi <komlodi@google.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/i2c/smbus_slave.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c
index 9f9afc25a4..4615e8b097 100644
--- a/hw/i2c/smbus_slave.c
+++ b/hw/i2c/smbus_slave.c
@@ -201,10 +201,19 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data)
     return 0;
 }
 
+static void smbus_device_hold_reset(Object *obj)
+{
+    SMBusDevice *dev = SMBUS_DEVICE(obj);
+    dev->mode = SMBUS_IDLE;
+    dev->data_len = 0;
+}
+
 static void smbus_device_class_init(ObjectClass *klass, void *data)
 {
     I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
+    ResettableClass *rc = RESETTABLE_CLASS(klass);
 
+    rc->phases.hold = smbus_device_hold_reset;
     sc->event = smbus_i2c_event;
     sc->recv = smbus_i2c_recv;
     sc->send = smbus_i2c_send;
-- 
2.44.0.rc0.258.g7320e95886-goog



  parent reply	other threads:[~2024-02-20 21:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20 21:11 [PATCH v4 0/3] hw/i2c: smbus: Reset fixes Joe Komlodi
2024-02-20 21:11 ` [PATCH v4 1/3] hw/i2c: core: Add reset Joe Komlodi
2024-02-20 21:11 ` [PATCH v4 2/3] hw/i2c/smbus_slave: Add object path on error prints Joe Komlodi
2024-02-21 18:28   ` Philippe Mathieu-Daudé
2024-02-20 21:11 ` Joe Komlodi [this message]
2024-02-22 14:47 ` [PATCH v4 0/3] hw/i2c: smbus: Reset fixes Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240220211123.2664977-4-komlodi@google.com \
    --to=komlodi@google.com \
    --cc=minyard@acm.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=venture@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).