From nobody Sun Nov 9 17:50:10 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551378833073791.3609575483852; Thu, 28 Feb 2019 10:33:53 -0800 (PST) Received: from localhost ([127.0.0.1]:44710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQVC-0003nG-SU for importer@patchew.org; Thu, 28 Feb 2019 13:33:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFm-0000ZE-5C for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002IH-SG for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:53 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:44273) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002Cr-Hr for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x343.google.com with SMTP id g1so18496329otj.11 for ; Thu, 28 Feb 2019 10:17:27 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id h138sm8770527oic.8.2019.02.28.10.17.17 (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 (unknown [IPv6:2001:470:b8f6:1b:b89e:c7bf:12ab:ad14]) by serve.minyard.net (Postfix) with ESMTPA id 7A1201808FE; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 61A30302AF4; Thu, 28 Feb 2019 12:17:14 -0600 (CST) 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; bh=AoLcNOQ30aKzN3oO2kA4DzR6j6MGF6e7733YDW7t8Z0=; b=UZUuizI48sCubY3hw47ea01lV5GPznGqVkZtpCwrfYNQhJ77Afw5+lbojnLpMrLYBp Cc+ZfM11yTrNvUplN49HXfsO3TLP3xhEc9PPwpuvOV9a//8DKwMakeIUmy29Sgu3U6sK SpXgooOYA+1oQLUlNtmxAx+OevxagNXPKYKeb9T9U/1stANPOMskaTx09zfoWnKUUOCN bV38NXnwsU9lnCbWfV+EsFdsFJVEC2yiNhDD+StoxJxi7rF/uJObweNzpUhEwKbzhHq6 WO00ipNe0VbRQ+LiFXUUp0GbXIDg+2ep8yu8iInIWdfpmDAHhDNa/Mj/H1pnXQTgzXqw oiew== 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; bh=AoLcNOQ30aKzN3oO2kA4DzR6j6MGF6e7733YDW7t8Z0=; b=XrSCIL0KfBKd4ZP929ZjtLWPdzgFMKCmrcPs4ae5mCbB15rIRZ6kTeuz85P1Q3hze6 xcSPtwE/QvZrKM3L+2VAmFWTW6dCoOOsy9pr31Jbj8F6mJLLxaRdWNo7rC2ThjfWyOlp sjooriM5BNqUrit47973duLMgTk8CrRvIi2Q7RGXdiABwcCt9UhkucKbyVtWZ/V+1hUd j4yEdUnqLP+pRb9d+4AQNIKwwmh/Fc6Kn72j3dQ4pb1xJtJcdvSfqQHNfaJ0GL+pCeOT cOwDW6D5siJmdDjG0eFJXbqaA1D4LltiXA2pbtuKSR8jhPdgMMkpd4bvaMwhAIrILrry fhUg== X-Gm-Message-State: APjAAAUHi5fpZmqvxBVNoMVJ8P9irFJYgYZ0aPOkSkEaPZIOfOBiB+pN lI/Uo1UH8CKpaqtWNENvCw== X-Google-Smtp-Source: APXvYqw0SgIblMZSDXZ2Jn4+4RoFvxYkEaQHNIXu2aAPjvjsXbFTU17NUSFD/ypTZCRt1WNxipWsFw== X-Received: by 2002:a9d:73d6:: with SMTP id m22mr632392otk.322.1551377846720; Thu, 28 Feb 2019 10:17:26 -0800 (PST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:05 -0600 Message-Id: <20190228181710.2477-15-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> 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 14/19] i2c:smbus_slave: Add an SMBus vmstate structure 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 , minyard@acm.org, "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , QEMU Developers , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Corey Minyard There is no vmstate handling for SMBus, so no device sitting on SMBus can have a state transfer that works reliably. So add it. Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- hw/i2c/smbus_slave.c | 18 ++++++++++++++++++ include/hw/i2c/smbus_slave.h | 24 +++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 5b3046f6a3..9a2d314d1a 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -201,6 +201,24 @@ static void smbus_device_class_init(ObjectClass *klass= , void *data) sc->send =3D smbus_i2c_send; } =20 +bool smbus_vmstate_needed(SMBusDevice *dev) +{ + return dev->mode !=3D SMBUS_IDLE; +} + +const VMStateDescription vmstate_smbus_device =3D { + .name =3D TYPE_SMBUS_DEVICE, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_I2C_SLAVE(i2c, SMBusDevice), + VMSTATE_INT32(mode, SMBusDevice), + VMSTATE_INT32(data_len, SMBusDevice), + VMSTATE_UINT8_ARRAY(data_buf, SMBusDevice, SMBUS_DATA_MAX_LEN), + VMSTATE_END_OF_LIST() + } +}; + static const TypeInfo smbus_device_type_info =3D { .name =3D TYPE_SMBUS_DEVICE, .parent =3D TYPE_I2C_SLAVE, diff --git a/include/hw/i2c/smbus_slave.h b/include/hw/i2c/smbus_slave.h index 79050fb92d..ebe068304e 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -69,14 +69,32 @@ typedef struct SMBusDeviceClass uint8_t (*receive_byte)(SMBusDevice *dev); } SMBusDeviceClass; =20 +#define SMBUS_DATA_MAX_LEN 34 /* command + len + 32 bytes of data. */ + struct SMBusDevice { /* The SMBus protocol is implemented on top of I2C. */ I2CSlave i2c; =20 /* Remaining fields for internal use only. */ - int mode; - int data_len; - uint8_t data_buf[34]; /* command + len + 32 bytes of data. */ + int32_t mode; + int32_t data_len; + uint8_t data_buf[SMBUS_DATA_MAX_LEN]; }; =20 +extern const VMStateDescription vmstate_smbus_device; + +#define VMSTATE_SMBUS_DEVICE(_field, _state) { \ + .name =3D (stringify(_field)), \ + .size =3D sizeof(SMBusDevice), \ + .vmsd =3D &vmstate_smbus_device, \ + .flags =3D VMS_STRUCT, \ + .offset =3D vmstate_offset_value(_state, _field, SMBusDevice), \ +} + +/* + * Users should call this in their .needed functions to know if the + * SMBus slave data needs to be transferred. + */ +bool smbus_vmstate_needed(SMBusDevice *dev); + #endif --=20 2.17.1