From patchwork Thu Feb 28 18:17:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10833599 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 B03191575 for ; Thu, 28 Feb 2019 18:33:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CBBA2DEBA for ; Thu, 28 Feb 2019 18:33:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 918322F6E0; Thu, 28 Feb 2019 18:33:20 +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 2F6512F6E2 for ; Thu, 28 Feb 2019 18:33:20 +0000 (UTC) Received: from localhost ([127.0.0.1]:44710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQUh-0003nG-CO for patchwork-qemu-devel@patchwork.kernel.org; Thu, 28 Feb 2019 13:33:19 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = smbus_i2c_send; } +bool smbus_vmstate_needed(SMBusDevice *dev) +{ + return dev->mode != SMBUS_IDLE; +} + +const VMStateDescription vmstate_smbus_device = { + .name = TYPE_SMBUS_DEVICE, + .version_id = 1, + .minimum_version_id = 1, + .fields = (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 = { .name = TYPE_SMBUS_DEVICE, .parent = 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; +#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; /* 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]; }; +extern const VMStateDescription vmstate_smbus_device; + +#define VMSTATE_SMBUS_DEVICE(_field, _state) { \ + .name = (stringify(_field)), \ + .size = sizeof(SMBusDevice), \ + .vmsd = &vmstate_smbus_device, \ + .flags = VMS_STRUCT, \ + .offset = 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