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: 159422 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp987464oce; Thu, 28 Feb 2019 10:32:23 -0800 (PST) X-Google-Smtp-Source: APXvYqwJmu7f2W2H5a57b7PY1i+uXpHZQsyLaI6RQYnQCixYw6Aww2YpUIF6JJpRqHvZyUBtqXYL X-Received: by 2002:a81:28c3:: with SMTP id o186mr262870ywo.309.1551378743423; Thu, 28 Feb 2019 10:32:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378743; cv=none; d=google.com; s=arc-20160816; b=ORGW78HMKrStSAi0OFd29QvSUe70GuQoVX8K7gUvlhVu6OB3XO78YfRCQaiY/KcnsU CsPXi1zQwq3S8b3Duh3i2DwGK8SS40FwWha68r+H+ofCwaWsUbKePCHgkTE3742HD2uO AppLcaGJD/DbaHfeIanh7bZAJ3Iu6r3DQ2juLE1L3kssStxSIuYlkdGGg3Zho04XQEvK 56wD1OMQmrwJxw1/WSfQmP+pKEC5nIPAJkDub3lr2FiJTuO7TjqN3S8wGOo8hSVgvXfK tpFh9/ImimdL5IjZKthpkfUxSJz+IcO6W6aaVd1ntivxLw3e29PMQhDoxra7Szyz6o8y ihLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=AoLcNOQ30aKzN3oO2kA4DzR6j6MGF6e7733YDW7t8Z0=; b=CC2jQpYCSQdcoG/+kZxmjz+88b6jLNPye3UZvq7O5zZOHoQB33WKc2oKPye9nVn/xI PwfKSgoVhQs9vZ1mqLFXmQ5SRvyb+EZYbdcr/y3++GiCMV+qpGDNZE5LbEkXh8mmaOEh +t9zNon4M/V4z7YRpxhl93dLzDPLUZ+YEeuD3+GFVmGgFzAM7e1q0CAUk7RfSvuw4zTx D1RvRrUOs0eTrOVcVjeIF+jKHRPBNdTw4YA3NZOwVg5NWOaixVM/JFsv2t5FlKFzbj4M ROm/c78Xjaj7bxxX7a+KfK/pAEauq+zHHgWkxJf9B6HaadstDM0TBRob5WaSTgZMjNcJ SXTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UZUuizI4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=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 m125si11416636ybc.26.2019.02.28.10.32.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:32:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=UZUuizI4; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([127.0.0.1]:44704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQTm-0002ws-Rw for patch@linaro.org; Thu, 28 Feb 2019 13:32:22 -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-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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.17.1 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