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: 10684929 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 CC48E13B5 for ; Thu, 15 Nov 2018 19:30:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BAD1C2CFFA for ; Thu, 15 Nov 2018 19:30:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8BBF2D00A; Thu, 15 Nov 2018 19:30:11 +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=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3B99E2CFAD for ; Thu, 15 Nov 2018 19:30:11 +0000 (UTC) Received: from localhost ([::1]:40457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gNNL8-0007lW-Ho for patchwork-qemu-devel@patchwork.kernel.org; Thu, 15 Nov 2018 14:30:10 -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-Google-Smtp-Source: AJdET5e52irButnyKlBJudxz82Pah7l1IaghYzBBed7dUQAXRVDK6PVLrx7hrMQHtz0w10DCprfhkQ== 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+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 --- 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 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