From patchwork Mon Nov 26 20:04:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 152068 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp325495ljp; Mon, 26 Nov 2018 12:22:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/UXCWGNbK6W9EDVT3ovSg7LEcthEhKx8Oy3NxpG/SBG9nB1kfK/4ACg1q16WJqdNPgulq5b X-Received: by 2002:a81:2916:: with SMTP id p22mr26960772ywp.176.1543263733176; Mon, 26 Nov 2018 12:22:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543263733; cv=none; d=google.com; s=arc-20160816; b=cmevNyPPHCoZ02uPOLHF8xDquUfM6PEDjTNaQFChTyhvDuBVv6SOiA+va1Qt7HKpi+ kc+E3Ny/gS5ZB7/vtRIvLTrRyPG0AZNKUD00BvI28jiCUFgYCUKkKx8iFWjIo3CKhkfH 6KJK7GOKClvOE9K+rTRu5l9fVPnRK/14LxVwhsf/uSvqE1a//nowkEnpv0WCHALAfn48 ZHoHXzhRwhUfR3PVZXu0ORohOeTKE6tbdId7deJP7zdh03wXPNAgYM7e5DoAwBl0aCIp POQK0y+MUUPpsHWshuw1QbKa24rODgy92yV37lATfmCgaYfs1fF8ZB13M1+e8KPbt9JJ lakw== 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=TUBU7z59tOJdMFZN6MR1VpcPHg2YHgGd9a5Z3VpWJLA=; b=rNVIAucECfUDJZOV4tSUkpjDsmTJGJH+jB5zX0N0luu6V1k5WNObHyEvtEmHpyUA6Y JeqorD3LwU+EBZNNYdE7eMxsJJypHPWJz49zIN4wb5wMuEACIP/rK8UT6uilFKb8erc1 tvWadz3fRTc8FRkk8mBFQCD3m0tqr8VX9IMtsOv7znRxWVwphKvDlCgUDldrP5umMIvC 4f6aqc2N5ZcCQx0pZzF14SMk+bDqJxAnyMTgtRp42PWb1U2AhqLio+COuuBj6sFjkDQF oB/p/I79GMSBNPzY5U1qgyouwkMmSndZiJ9QgsCqcs25DY+/bfSTb9A/5HXhBYHJio+R NduQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=PsWMHjjc; 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 c7si974336ywd.123.2018.11.26.12.22.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 26 Nov 2018 12:22:13 -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=PsWMHjjc; 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]:38645 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRNOW-0000MO-GX for patch@linaro.org; Mon, 26 Nov 2018 15:22:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gRN81-0001lJ-DH for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gRN7y-0001M3-Vv for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:09 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:44972) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gRN7y-0001Hw-LF for qemu-devel@nongnu.org; Mon, 26 Nov 2018 15:05:06 -0500 Received: by mail-ot1-x343.google.com with SMTP id f18so16278317otl.11 for ; Mon, 26 Nov 2018 12:05:00 -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=TUBU7z59tOJdMFZN6MR1VpcPHg2YHgGd9a5Z3VpWJLA=; b=PsWMHjjcWTOQi8xLNRIoCq97XoYNGWOwCj+f3+50P1d4eQd5hV10d7QbG1TKKrlBKJ PF8YVJaw1d4j+6q5dcbgdoN3ApsmDVPiIfe9GW73Bmss7SbyOxu9bU4sNwpF0wu+EVkH ZNdSQpoIqt9jqQMyVwNjbSdjP/f5q7YVlbpOvd7X6Ctq92nKgxMvOfDpAY7zwSCmj9sl NmvivIazSTpo506BljzzyYug5Un0jXAEFGdmu7HCMHbrSH6NSqfLgtLRZtz74pxfWlr8 9fAAIUq720VawijV0vtBPyAzODxdnQ2Uiy/TDVKO1+c14S8y7+k4AlmSf1s8/2pbCJaK v9RQ== 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=TUBU7z59tOJdMFZN6MR1VpcPHg2YHgGd9a5Z3VpWJLA=; b=cu70ePaKj03nVJ8iYDKbI0CCkbaZQRSmpLuRtB/qP5siXxDV7x0/kWuUdoQywD3lm0 2ZpwIuvhw0HfTeDAkUpft3enuyrqvjIodFjTiNXZqhFezYNL9JN+XMN6/6lTCYOql47R Muvvxex9j84cglj/UPbLoCnSNYyOQ54UWE/xG8JheEAb05IOoFskgC/Mlp1LUxGeLwj4 NWcZR72SMeSRVkNwHgmIrpTXRbwx1lEtyGEgy3mDERqauE6iDmconawkt81Gy53jQ+0S gLoaIhdnphI5pinvc/bCl63WWCHm+8DwOIoLO3rKcYVpHUrT94dSqRvIDCS1v8+La4OL KrBA== X-Gm-Message-State: AA+aEWakp6k20n26kmObsRVe/i7Rd5f/+XN3TqtghHPKKonYww0CQ9dC apU6UoDRHOR9+Ed1ze4srA== X-Received: by 2002:a9d:908:: with SMTP id 8mr17271051otp.28.1543262699665; Mon, 26 Nov 2018 12:04:59 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id e6sm343916otp.68.2018.11.26.12.04.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 12:04:58 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 4DF5C1E5A; Mon, 26 Nov 2018 14:04:49 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id ACF4130146C; Mon, 26 Nov 2018 14:04:46 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Peter Maydell Date: Mon, 26 Nov 2018 14:04:30 -0600 Message-Id: <20181126200435.23408-12-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181126200435.23408-1-minyard@acm.org> References: <20181126200435.23408-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] [PATCH v3 11/16] 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: Paolo Bonzini , Corey Minyard , Corey Minyard , "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 Reviewed-by: Dr. David Alan Gilbert diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index d03f714608..e839c1dd11 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 fad2db9c76..78fd45cb51 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