From patchwork Wed Jan 10 21:26:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Komlodi X-Patchwork-Id: 1885186 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=wIO9v8N3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T9LW31X86z1yPp for ; Thu, 11 Jan 2024 08:27:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNg66-0001hp-Vq; Wed, 10 Jan 2024 16:26:51 -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 <3lgufZQcKCl0FJHGJ8DBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--komlodi.bounces.google.com>) id 1rNg65-0001hR-Ki for qemu-devel@nongnu.org; Wed, 10 Jan 2024 16:26:49 -0500 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3lgufZQcKCl0FJHGJ8DBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--komlodi.bounces.google.com>) id 1rNg64-000108-5H for qemu-devel@nongnu.org; Wed, 10 Jan 2024 16:26:49 -0500 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5e74c97832aso65182367b3.2 for ; Wed, 10 Jan 2024 13:26:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704922006; x=1705526806; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=X73fxUseiD1AEJCI70SmF4TO4nJxvqf3TpYTw9z/euM=; b=wIO9v8N3LLlq1M/Al00gZlV0Fa+mErV7+ug/kWTo9CItBN1Jlcy4F1bG6piustExyc 4WF/wgqaKLHmT9c3ZjRUurricDk/Tg/4KTJfQdLxhdZVOIPfd2DM+LbFKPZYPQtDEwlX ROxpUMSeFJ13nfS3F5hVVTN8PqSHE2BVrUgaES+p/4H5Allpt0WSpzj17fbqg3dFcl8X 4AIlPcSzWc367S338HRQR8VYv3EICdd7WkyKwDk3NL1OgxGhyciOpf+acBqUcYyt5E6Y kZmF3DcWORyDoSlyyIc0fF4GarKrx/S+Y7lG6Noa0fkJgvY8N7YAVLQzNHyWIeuuiVpt jzHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704922006; x=1705526806; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=X73fxUseiD1AEJCI70SmF4TO4nJxvqf3TpYTw9z/euM=; b=jd29dZdsPb/03AeNMdbmdsTMgW2FYRygJUgV5L9Lo3Be4YdyGC5y2mVjFO64arjvvl dChCKqw0HosJYRbY4RTRBvl9TMYIc+GI5GDnpdq4UAd/aP+yUQDrpAe8lynbhNn+c7gR 3l9Pul1sSwc44lfFyS59f4D3zR4JxX5GQH1VsAQSByEshN4IB5mkOSgxW/g8NqZaUdRs 9y2Hn5IuRAjh4le4/hiBWYOOR3iXB4ZfJH3jmYbTLRYPxCaqXYqlZXjtOtKDFVOR4KlM MXuona+YSfhpOlS9mMItMOVgPX3cP0SxABS43mBOYavVbweLxVoE4S0Ju52Y0rCaQUMQ e/7g== X-Gm-Message-State: AOJu0YwR0nyVUu2x/RRZNf0/gDJhQJP94aEp7SlbXkCWQl2gm+TL7HHN o8wW4GC3ruF4zEpFIeED3lsFTyL6mcJTN1MyQOTgAgB8TZQGMid8jbIM8y5LLPQDRne3Mq2ZEdd Ck9rA75+krDyiFy59Nn1B+dlSNrQ8aPGKKJxR96GaHusVU5W4bdHXrwacfH4EIh2pWe7wiQ== X-Google-Smtp-Source: AGHT+IEVz1Ak6/6dP8VuNYxH/bM3R7u/MkEGKyaYhYmzvUiFcFSjG+tol/IZoJ1SewjohT/yQY/wrRoj2HI6 X-Received: from komlodi.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:35ee]) (user=komlodi job=sendgmr) by 2002:a0d:ce45:0:b0:5f8:e803:4b0d with SMTP id q66-20020a0dce45000000b005f8e8034b0dmr121258ywd.2.1704922006030; Wed, 10 Jan 2024 13:26:46 -0800 (PST) Date: Wed, 10 Jan 2024 21:26:38 +0000 In-Reply-To: <20240110212641.1916202-1-komlodi@google.com> Mime-Version: 1.0 References: <20240110212641.1916202-1-komlodi@google.com> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog Message-ID: <20240110212641.1916202-2-komlodi@google.com> Subject: [PATCH 1/4] hw/i2c: core: Add reset From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, cminyard@google.com Received-SPF: pass client-ip=2607:f8b0:4864:20::114a; envelope-from=3lgufZQcKCl0FJHGJ8DBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--komlodi.bounces.google.com; helo=mail-yw1-x114a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It's possible for a reset to come in the middle of a transaction, which causes the bus to be in an old state when a new transaction comes in. Signed-off-by: Joe Komlodi --- hw/i2c/core.c | 30 +++++++++++++++++++++++++----- include/hw/i2c/i2c.h | 6 +++++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 4cf30b2c86..def4f134d0 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -23,11 +23,31 @@ static Property i2c_props[] = { DEFINE_PROP_END_OF_LIST(), }; -static const TypeInfo i2c_bus_info = { - .name = TYPE_I2C_BUS, - .parent = TYPE_BUS, - .instance_size = sizeof(I2CBus), -}; +static void i2c_bus_enter_reset(Object *obj, ResetType type) +{ + I2CBus *bus = I2C_BUS(obj); + I2CNode *node, *next; + + bus->broadcast = false; + QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) { + QLIST_REMOVE(node, next); + g_free(node); + } +} + +static void i2c_bus_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc = RESETTABLE_CLASS(klass); + rc->phases.enter = i2c_bus_enter_reset; +} + + static const TypeInfo i2c_bus_info = { + .name = TYPE_I2C_BUS, + .parent = TYPE_BUS, + .instance_size = sizeof(I2CBus), + .class_size = sizeof(I2CBusClass), + .class_init = i2c_bus_class_init, + }; static int i2c_bus_pre_save(void *opaque) { diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h index 2a3abacd1b..420868a269 100644 --- a/include/hw/i2c/i2c.h +++ b/include/hw/i2c/i2c.h @@ -64,7 +64,7 @@ struct I2CSlave { }; #define TYPE_I2C_BUS "i2c-bus" -OBJECT_DECLARE_SIMPLE_TYPE(I2CBus, I2C_BUS) +OBJECT_DECLARE_TYPE(I2CBus, I2CBusClass, I2C_BUS) typedef struct I2CNode I2CNode; @@ -83,6 +83,10 @@ struct I2CPendingMaster { typedef QLIST_HEAD(I2CNodeList, I2CNode) I2CNodeList; typedef QSIMPLEQ_HEAD(I2CPendingMasters, I2CPendingMaster) I2CPendingMasters; +struct I2CBusClass { + DeviceClass parent_class; +}; + struct I2CBus { BusState qbus; I2CNodeList current_devs; From patchwork Wed Jan 10 21:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Komlodi X-Patchwork-Id: 1885185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=BVvXvWfC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T9LVj07Ylz1yPp for ; Thu, 11 Jan 2024 08:27:40 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNg6F-0001iT-3S; Wed, 10 Jan 2024 16:26:59 -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 <3lwufZQcKCl4GKIHK9ECKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--komlodi.bounces.google.com>) id 1rNg68-0001iA-45 for qemu-devel@nongnu.org; Wed, 10 Jan 2024 16:26:52 -0500 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3lwufZQcKCl4GKIHK9ECKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--komlodi.bounces.google.com>) id 1rNg66-00010d-Mg for qemu-devel@nongnu.org; Wed, 10 Jan 2024 16:26:51 -0500 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-28d29d2dd7dso2143020a91.1 for ; Wed, 10 Jan 2024 13:26:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704922008; x=1705526808; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=UujjEtCL3f3hHEN5AYDAZysO92z8l1BhG6bS0cwEohQ=; b=BVvXvWfCiOgzOL6A8FywwyWBf4d3JVZioaMiMTN5ktt1RYbmdz2rU4obIAsdvLZDdU jOu4HagX7pUeOT/kRQqz1+KOL5Gk5RcJNJvx3wjsoZS+OjLviu4IMfSh2lFgB7HdC3mG 91zaRVEQNdj98zadzUx43Y0JN9DblsxzzmxImnv4WsDPARYDNqrccFIt5BiNaZ9gGE+L ZIbrPzaqHDniMYdXzFfFStSS74pV25kT2J66wGPd5IDqKrAXCk4lh6E2H8YvbYKwe9Vj aoIn1aeQYP+nK3UFUsVr/QBrOu1RzXxJtudc5+Fe8bGWAT5uOeZOP2MFvRgnCBtjTGUC 5qRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704922008; x=1705526808; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UujjEtCL3f3hHEN5AYDAZysO92z8l1BhG6bS0cwEohQ=; b=OQsHzIjiy6TqY7Z1QGh88imk+2ICedoRIkkynZtNfvfIesZQO2U3Zq7smtlyskhpx7 k4uG0suJ287z+/uhuGOF61xQChm3DDWvLzz7xex+2KFS0PMkztKGSpt6Sr2DUJ7CVFFX c4TdWCiKNwqYYWqnoKcF7bnXWcUnQwFdsZ4bNTjLrXAkRa2W/6fP6/yaayO8IrIImjx1 qmGS2Z4P3hQgBmX9H/8QPuFm8RYSX85eJoJjatcL4oe+pGpch5TY2QORs/VOZl3Nf3+a x3PH1QsZTdeL/uZKl6y9FCwEoJ/59BHdVW0EVBNXN/Cz7Q0BnL8sTkVTJfLDe2wnYO5t zkLg== X-Gm-Message-State: AOJu0YzCDa916OKqVaEn+QW7nva29sizY54PjcUypNB80nE3YB9ZMhYd J99ZtVBPPzxnyZhnLfG/7vhJLx8zfrpEH9iP9LzfSSsqpIxC/QfLqFwlaMf5dSWAjLCbLYsVOIu duKhm8BkemrHndy5M8UbQ5YmZBAExY1kk6PVBDgTp+FDnbumNPX2uqK3mnq8JRsiP8IKQAg== X-Google-Smtp-Source: AGHT+IE5kcic6ArKbCMUC9GZQUx/LxgJzY4NPM7k6bA8jhG4XO+hHj9txx/6bLwAhndpgXxoXJ/j09qt7Vfa X-Received: from komlodi.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:35ee]) (user=komlodi job=sendgmr) by 2002:a17:90b:3d4e:b0:28d:c240:4253 with SMTP id qn14-20020a17090b3d4e00b0028dc2404253mr679pjb.1.1704922007746; Wed, 10 Jan 2024 13:26:47 -0800 (PST) Date: Wed, 10 Jan 2024 21:26:39 +0000 In-Reply-To: <20240110212641.1916202-1-komlodi@google.com> Mime-Version: 1.0 References: <20240110212641.1916202-1-komlodi@google.com> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog Message-ID: <20240110212641.1916202-3-komlodi@google.com> Subject: [PATCH 2/4] hw/i2c/smbus_slave: Add object path on error prints From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, cminyard@google.com Received-SPF: pass client-ip=2607:f8b0:4864:20::104a; envelope-from=3lwufZQcKCl4GKIHK9ECKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--komlodi.bounces.google.com; helo=mail-pj1-x104a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The current logging doesn't tell us which specific smbus device is an error state. Signed-off-by: Joe Komlodi --- hw/i2c/smbus_slave.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 1300c9ec72..e24a1ef472 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -25,11 +25,15 @@ #define DPRINTF(fmt, ...) \ do { printf("smbus(%02x): " fmt , dev->i2c.address, ## __VA_ARGS__); } while (0) #define BADF(fmt, ...) \ -do { fprintf(stderr, "smbus: error: " fmt , ## __VA_ARGS__); exit(1);} while (0) +do { fprintf(stderr, "%s: smbus: error: " fmt , \ + object_get_canonical_path(OBJECT(dev)), ## __VA_ARGS__); \ + exit(1); } while (0) #else #define DPRINTF(fmt, ...) do {} while(0) #define BADF(fmt, ...) \ -do { fprintf(stderr, "smbus: error: " fmt , ## __VA_ARGS__);} while (0) +do { fprintf(stderr, "%s: smbus: error: " fmt , \ + object_get_canonical_path(OBJECT(dev)), ## __VA_ARGS__); \ + } while (0) #endif enum { From patchwork Wed Jan 10 21:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Komlodi X-Patchwork-Id: 1885189 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=PmD9ftRL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T9LWL4k6mz1yPw for ; Thu, 11 Jan 2024 08:28:14 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNg6I-0001ko-Fo; Wed, 10 Jan 2024 16:27:03 -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 <3mQufZQcKCmAIMKJMBGEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--komlodi.bounces.google.com>) id 1rNg69-0001iI-0I for qemu-devel@nongnu.org; Wed, 10 Jan 2024 16:26:53 -0500 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3mQufZQcKCmAIMKJMBGEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--komlodi.bounces.google.com>) id 1rNg67-00010y-Im for qemu-devel@nongnu.org; Wed, 10 Jan 2024 16:26:52 -0500 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5f9e5455db1so29584897b3.1 for ; Wed, 10 Jan 2024 13:26:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704922010; x=1705526810; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=y123XMP/caBorPk6crLzl1eoEJf2Tw2ucYeM6ljh3JY=; b=PmD9ftRL4WEraqxuAV3trWvQbRa0eJjMA0nllMpe4tA3CkB9Tbie48rFIVZfhRZqSe b+ztgskOYFhZRavyFEORshv6YmT3mJub8AUz0+lvGn8inPfs00AZTFM/MEbqT0g6BkJ4 f2fDaokR1O2B1NhGa870bqkqVoFxJU895iNntvjIsyqW02nY05ky7CvTxTE7gfuiFFkh tARfkO2GoGpWh5aFdJtwCRvJVhwO2veZ1Jil8u/rjzCUL9TMvXLDbz3JUCR8GMX0m8KH FysdEg/jkRf71Hq4kzsz8qxRRl3lRWUpUnVwujBtvGo43UoLrf7/6i35YsBTuytyESWe 026A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704922010; x=1705526810; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y123XMP/caBorPk6crLzl1eoEJf2Tw2ucYeM6ljh3JY=; b=rf4BEVhQjklp9iCzqmA5kFFI1/t2sbflEKNeRWk0+sJreLYuTV9OJnOOOC/VXU1Avp ECWhpCW3ryMvYGC+qjx3c3SScs5GSkmEo4Lf5SVhkvI20iOALuuoiqElpFe2PtNwFZqd tZyH8BqosaHvLD7yvL/5Kww9hLprnBGH705mvtNNe8UcLUBkcgG2wA2Tay90p8RyhsF3 t3WhLColUi5MKzNgUbhE1sykCGnE3cIWWXGLr7L0uuLTVvmQufG8o4hhELUrQTffaM05 p76D9jAd/BpYL9KdpsyxOgfvuc8WQlYU+VpXt3wNuXpDZ4P4QZw5h+oX/SRWqng/lbGM Taig== X-Gm-Message-State: AOJu0YyEi4j3R+tqZOI+MU9GZk9592i9UMk6V6E13STc8KRrIes2hNnz OejFK/pcNq9jBm9UW5pPa5M+RQIDcQsYYIPUS3dVHpIBXibrNpj4kGiRfrL7Qt1fWIKx/CPbP2e FFy89gsgdSW2Obu5aJQU6QDi3sLYHNe66WD10FROxDT8scF5QHp5t32MZMI/HVQDue7iFow== X-Google-Smtp-Source: AGHT+IEStgegXrEJ13kAZArqrt8JrYPRLjgklROeQnl0tT/sQd2sXO0f9s9/5fdQm22vi/7vYHsAzzXmWR+J X-Received: from komlodi.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:35ee]) (user=komlodi job=sendgmr) by 2002:a81:df01:0:b0:5f9:2515:19a5 with SMTP id c1-20020a81df01000000b005f9251519a5mr103380ywn.5.1704922009581; Wed, 10 Jan 2024 13:26:49 -0800 (PST) Date: Wed, 10 Jan 2024 21:26:40 +0000 In-Reply-To: <20240110212641.1916202-1-komlodi@google.com> Mime-Version: 1.0 References: <20240110212641.1916202-1-komlodi@google.com> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog Message-ID: <20240110212641.1916202-4-komlodi@google.com> Subject: [PATCH 3/4] hw/i2c: smbus_slave: Reset state on reset From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, cminyard@google.com Received-SPF: pass client-ip=2607:f8b0:4864:20::1149; envelope-from=3mQufZQcKCmAIMKJMBGEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--komlodi.bounces.google.com; helo=mail-yw1-x1149.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 e24a1ef472..58abde29de 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_enter_reset(Object *obj, ResetType type) +{ + 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.enter = smbus_device_enter_reset; sc->event = smbus_i2c_event; sc->recv = smbus_i2c_recv; sc->send = smbus_i2c_send; From patchwork Wed Jan 10 21:26:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Komlodi X-Patchwork-Id: 1885188 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20230601 header.b=jqFAe860; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4T9LWK62Sqz1yPp for ; Thu, 11 Jan 2024 08:28:13 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rNg6K-0001lS-SA; Wed, 10 Jan 2024 16:27:05 -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 <3mwufZQcKCmIKOMLODIGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--komlodi.bounces.google.com>) id 1rNg6G-0001kQ-Aw for qemu-devel@nongnu.org; Wed, 10 Jan 2024 16:27:00 -0500 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3mwufZQcKCmIKOMLODIGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--komlodi.bounces.google.com>) id 1rNg6E-00011I-Im for qemu-devel@nongnu.org; Wed, 10 Jan 2024 16:27:00 -0500 Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-28b6d5de7f8so2192847a91.0 for ; Wed, 10 Jan 2024 13:26:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704922012; x=1705526812; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xFUcLlmYVdoFhksu7OL7gQGTf33CNrJzxpdV8oEWtTI=; b=jqFAe860RSqOxkt77lzeraqakE/YhUpaL288rlKc06bipFJR7NOAl57aEY1zWSss8a hCcFh85f1B83xCbM/6hYLqN2uZMN/azc+yzSMJDODKEEqOHPQsrFOrrpIxqh7oMRSBPx 8GZJ+6lTogjK/mDtFvFeFrF/v5ugGKAUQ/LhBSthlT9UHhpPMJq63GL7rGn7YU6mP4D4 kdE92tN8HxAse5I126z/IXfc55kowq5J8QrLcq4adFALLFYfNhv7rAgU1JBHd9YNa5Go UKQglFSEGenn+kW0EPNGHzTAGmKDKU+xJgonktGsPQifYcgvNmf4nHAczb99vlQlQ4EZ dJpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704922012; x=1705526812; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xFUcLlmYVdoFhksu7OL7gQGTf33CNrJzxpdV8oEWtTI=; b=HSnUSBkj8vDBCvNl4tqduspPJT8z35sUzJrspO/Hz3oYv5Y6M+nqwIqigYASHnN6l9 3Yz77QY3mtGecH1mTnz6nFNlGMw+AfoDqobFbZmBbkHl5jOtVG/aLq297APWCI9Ak/rs vo55eBQfMfTHmarwZHGVxnBXUt94GaZZ5yMw/HlFH7vVJBLM+nT8iYNRwS1TsKykuEpC 86K7oCe3PKYD0gyAqoF2hgWIoOceeI2xka5Yp4Y501DIzRXpAD/LzxKNpYh05bN6BQRZ ZmlXq0QiPRq/KXBwyX1GZ8kqRrUkWy2AWhmAowQcqFSZowiRTKCH+XV6+qMNK0sApPkn 3E5A== X-Gm-Message-State: AOJu0YxAR40rGwEz2A1yXBPoUa0sdEyHxfpqAxJ3dKqb3aw5i0bUEGwU k/5uZne5dkHwwZl+utTH3g/NBw6Ucpzh9qpL7JkKM/5HYCUR2ZKHqL7JuM6dr3FxLfPd3J6JeNp R4yxZzSXbxCIGG4tnbl3vhmN3HtZMtRnMa84aSPAZ7dlzBezsMWuy3MPL5k/mmjA4U01f2g== X-Google-Smtp-Source: AGHT+IHQMRX2C8NCKsrNHCUJe+7wDV9KFZfOqGRs0Cz7bwX2kgMlph4wFDvz2k5KFc8Q/FX5ypSsMzcypxh+ X-Received: from komlodi.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:35ee]) (user=komlodi job=sendgmr) by 2002:a17:90b:5183:b0:28d:c290:29a0 with SMTP id se3-20020a17090b518300b0028dc29029a0mr712pjb.3.1704922011662; Wed, 10 Jan 2024 13:26:51 -0800 (PST) Date: Wed, 10 Jan 2024 21:26:41 +0000 In-Reply-To: <20240110212641.1916202-1-komlodi@google.com> Mime-Version: 1.0 References: <20240110212641.1916202-1-komlodi@google.com> X-Mailer: git-send-email 2.43.0.275.g3460e3d667-goog Message-ID: <20240110212641.1916202-5-komlodi@google.com> Subject: [PATCH 4/4] hw/i2c: smbus: mux: Reset SMBusDevice state on reset From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, cminyard@google.com Received-SPF: pass client-ip=2607:f8b0:4864:20::104a; envelope-from=3mwufZQcKCmIKOMLODIGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--komlodi.bounces.google.com; helo=mail-pj1-x104a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@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-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When a reset happens, both the SMBusDevice and PCA954x class do their variable resetting on an enter reset. Because of this, only the PCA954x has its reset called, which can leave the SMBusDevice in a bad state if it was in the middle of a transaction. To fix this we add parent reset functions for the SMBusDevice class, and have the mux class invoke it when it resets. Signed-off-by: Joe Komlodi --- hw/i2c/i2c_mux_pca954x.c | 5 +++++ hw/i2c/smbus_slave.c | 3 +++ include/hw/i2c/smbus_slave.h | 1 + 3 files changed, 9 insertions(+) diff --git a/hw/i2c/i2c_mux_pca954x.c b/hw/i2c/i2c_mux_pca954x.c index db5db956a6..307359a518 100644 --- a/hw/i2c/i2c_mux_pca954x.c +++ b/hw/i2c/i2c_mux_pca954x.c @@ -159,8 +159,13 @@ static uint8_t pca954x_read_byte(SMBusDevice *d) static void pca954x_enter_reset(Object *obj, ResetType type) { Pca954xState *s = PCA954X(obj); + Pca954xClass *pc = PCA954X_GET_CLASS(obj); + /* Reset will disable all channels. */ pca954x_write(s, 0); + if (pc->parent.parent_phases.enter) { + pc->parent.parent_phases.enter(obj, type); + } } I2CBus *pca954x_i2c_get_bus(I2CSlave *mux, uint8_t channel) diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 58abde29de..81adab8f77 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -212,8 +212,11 @@ static void smbus_device_class_init(ObjectClass *klass, void *data) { I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass); ResettableClass *rc = RESETTABLE_CLASS(klass); + SMBusDeviceClass *sdc = SMBUS_DEVICE_CLASS(klass); rc->phases.enter = smbus_device_enter_reset; + resettable_class_set_parent_phases(rc, smbus_device_enter_reset, NULL, NULL, + &sdc->parent_phases); sc->event = smbus_i2c_event; sc->recv = smbus_i2c_recv; sc->send = smbus_i2c_send; diff --git a/include/hw/i2c/smbus_slave.h b/include/hw/i2c/smbus_slave.h index 86bfe0a79e..0dd14be178 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -35,6 +35,7 @@ OBJECT_DECLARE_TYPE(SMBusDevice, SMBusDeviceClass, struct SMBusDeviceClass { I2CSlaveClass parent_class; + ResettablePhases parent_phases; /* * An operation with no data, special in SMBus.