From patchwork Thu Nov 15 19:24:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 151244 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp7401772ljp; Thu, 15 Nov 2018 11:29:02 -0800 (PST) X-Google-Smtp-Source: AJdET5cvjBxdWNnwYArDud+fyeTP4P9NDUSoneSQlSwwpPQ+mstByPD9krDsNvgBVAqeLsy2wKIi X-Received: by 2002:a0c:d268:: with SMTP id o37mr7565954qvh.136.1542310142222; Thu, 15 Nov 2018 11:29:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542310142; cv=none; d=google.com; s=arc-20160816; b=SsUsQxcI2rLlgYbkbC9BT8PH+UGV3KXZ31u1Xz1F3/64hA6xdyApKtCWpxxRbmUreI 8+LmF5Gga0ZN1ZznAnCGT5cUwpigiRGDfUo0s8ef0EFFVL2jxgjTjWA+/webBPkFdU6j 6+EqLP92iKI8U1ZN01up2ZJkL1I/7VSxKRtXVbSY4INUWoY2/CGL0RXIC4xVOU+qmnn5 OZ6s0JwgNROASRzNUbzSg7pUqfPRQ8mmQJeB2Tazj5FEYmPd06D1K59AVkm7EWK2xcfU +4ZmB1AljvN3M1o2Y5xIdl6yEbR9spOOmZ3GOMAsmB9JSAX13gZrnyKJy8gZJL5TFJhD nddg== 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=tq7k9Nd8uRc1ykYiahdQpUIkyDcZaJuQg1wrUQ8S3Fc=; b=pHBnPvIKbpFdfaEFO1ycGCm+XPKPwYkUDsjVSqHGf1uI2ZNj39OzXX2ul0A/EX1odU 6N5MtORMcdfcc1CmNq8R/+yWZU2XNHoGdm4kyWmZRG9G0dLQS+3NlplSfq8KNTudwOxf 9BdbwBCWqdlenCpylMrNwVeBa4X043mNrJUtvevkJOBuTEa2fpmGpYaUeLjAAU/vSlh3 F8mADzBUhD1etRUriz/FtpPP/hatX6yq9CeRzLDGnl5OlmF8uc8bbO6R34VefjA4dEVL gmC7kI/9TZhJ503BEKq0kPmPpW/M9t2lK3FR8LGFlNPp6LItFrgatWmeTzANaIWEy//a nohg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=mOLe+r+u; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m7si129887qvq.39.2018.11.15.11.29.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 15 Nov 2018 11:29:02 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=mOLe+r+u; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:40450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNK1-0006cE-I5 for patch@linaro.org; Thu, 15 Nov 2018 14:29:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNGJ-0003Wi-AU for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gNNG9-00082O-Th for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:11 -0500 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]:34283) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gNNG8-00080k-1d for qemu-devel@nongnu.org; Thu, 15 Nov 2018 14:25:01 -0500 Received: by mail-oi1-x241.google.com with SMTP id a202-v6so9591494oib.1 for ; Thu, 15 Nov 2018 11:24:59 -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=tq7k9Nd8uRc1ykYiahdQpUIkyDcZaJuQg1wrUQ8S3Fc=; b=mOLe+r+uJL5x3pK822Z8zXVYwjbpo+en+7Dx2U18ERV3K7fZWgQBmiQtg32pRMivBV MMF7pN9SGLtgmfCdT8Yqq0ZzatJHqrsCMmkasGHSqfInlVpD2Q+9I/RSPPFYZJHjo0Og dc+wilzZkdzIqb8DjgSpGp8Mwpe6A4fPTdTovIdvekzP2O0VNV1oUSsu23EjbCl6VQN/ Ck3nURdXSkW1Ao8Ao0WX0bGDDqJd6BReaamLXJbE120jRFgUP+WIx320w9oxSBmdiPMC ieuRUhoviRP0WtS/ysCv2nCbCNoC+Ub3Pi99EzKIh04ngXpMBbiVILC1D97u0VPvnAyp IkXw== 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=tq7k9Nd8uRc1ykYiahdQpUIkyDcZaJuQg1wrUQ8S3Fc=; b=kADsMakM23vPXfvWzebduQXoQPF+6t8IqtvvRlykcPdKkQedlV+2Ad4lfMNovuNDpm Ht3rz1lyEhrWXhyptrHq8LXazbcP1f9Z37RXGuEFbuUMLDMcbR9nFXEVZwbwvV7iWl6v oqcrmRt5oupjl0KEeuqDr48ULzEMVYNCoaHe2cIiDl4M2yVMgDC4eD+GRYZrgKLcwues 6+BuQEoLBMSlteb9LzSuYfiLr6zWoTbuTa9PqJSDlESFr4DKMW6zZTBFV2gx9twEVRFc tkEMWm965Ya1mGM1CMyFuCfG5koCStrGKidQwV3f6dFE74NI+lU67if0kUVDcEj18M14 4HCQ== X-Gm-Message-State: AGRZ1gLZECOyLkokvl4+4fSrhwl1l0u1Ab0WNqeIcdTt7T59FFnTLV3L B/6ZIdqecYC7/Vwk5ORx8Q== X-Received: by 2002:aca:c209:: with SMTP id s9-v6mr4158412oif.327.1542309898792; Thu, 15 Nov 2018 11:24:58 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id c4-v6sm894532oia.55.2018.11.15.11.24.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 11:24:55 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 48FEF1DA0; Thu, 15 Nov 2018 13:24:51 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id E758C301468; Thu, 15 Nov 2018 13:24:48 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Thu, 15 Nov 2018 13:24:42 -0600 Message-Id: <20181115192446.17187-9-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181115192446.17187-1-minyard@acm.org> References: <20181115192446.17187-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::241 Subject: [Qemu-devel] [PATCH v2 08/12] i2c: 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: Paolo Bonzini , Corey Minyard , "Dr . David Alan Gilbert" , minyard@acm.org, "Michael S . Tsirkin" 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 --- 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 fa988919d8..b8a2d521f4 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -206,6 +206,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 eabac1dd73..d53d691bf6 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -75,14 +75,32 @@ typedef struct SMBusDeviceClass void (*transaction_complete)(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