From patchwork Mon Aug 20 20:26:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10570759 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 56FFC1390 for ; Mon, 20 Aug 2018 20:31:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45A0929BEA for ; Mon, 20 Aug 2018 20:31:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39F0C29BEC; Mon, 20 Aug 2018 20:31:21 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 D397A29BEA for ; Mon, 20 Aug 2018 20:31:20 +0000 (UTC) Received: from localhost ([::1]:49162 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqpc-0006Ww-4E for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Aug 2018 16:31:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlF-0002rH-0b for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frql2-0002Wm-EV for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:46 -0400 Received: from mail-oi0-x22c.google.com ([2607:f8b0:4003:c06::22c]:33747) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqky-0002NE-Sd for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:34 -0400 Received: by mail-oi0-x22c.google.com with SMTP id 8-v6so28221104oip.0 for ; Mon, 20 Aug 2018 13:26:31 -0700 (PDT) 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=PjwLZzEhNIGCQw37hFyqw777IOcUEZ03GRWlf0ddFl4=; b=Ii4mzlFVnxlkB5PINoOJbN4aulbia/Ns5mHqcr9Rtu6UccmwfqODwCoeMvF0xWLU92 Eygh8l/+Nhpvc5i6kcPG9E4tJjZSUB6D2VaUCBV3EpTPhYK1C6fVJRTyjDoVlYq51jv3 HJmva5EZMcTjXfZZdJJsiEWlWDTrhklL5w3TKmmLQ8/8v+yW9CPOCzgJOldDL6JRW5aL R3oe+DfFrQofl5EKaRIV+NNpV8g6obB10+6243nQzT3UrYVUjI8CKhBoHvIKTG9FkO+P mpKM6kAAV5JPv/1tsLCTzTFXMPV9y/ntijZV5xIu8a+32JbADVW600/fDgq5iVmRn06G bixQ== 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=PjwLZzEhNIGCQw37hFyqw777IOcUEZ03GRWlf0ddFl4=; b=Ltqb2vc8TJ8P9nPxTaZiZsrcxoR33+BMGWrCHc5UzNiJmpmVBreit17OkpS1jxNMEJ 0nGowLedZ/zyS1DQ1JGTveHaDyjcTgPP2K9Z9qB1a/AaF+RBEVnjuzs/3WFdRYTfqStG E9qAJuTi9u6ELU76vlUq4D9WprClV/fT9qqekTwGuQvZFeiGIVHp1R6FcdNJWRvwKlsP IWU2HQfSxtoJEX/AIHjdVJ4wyFn7cHSeS3he8ms+lxJvOlWWAF5nzxbKMy+zLlH0unaZ JTkJgDpAxFpJLJQh6990tiWI9x1UGYWqVS5zNvL8uopwWE9344tj9HB1N7G8L0yO2ufF JSkA== X-Gm-Message-State: AOUpUlFmUCTjPu35zG7O+IdMiffGrtkh4Ee2Bow7l8pw48LA2fu/M0/J U5TKje8YG/7byUtWh7UP6+1ugyY= X-Google-Smtp-Source: AA+uWPypozLfbUmxK3fEmB6sj3eh0OlMmRBeTOGPrkqlshM9QH05nJu5KO8U6oYa5HraRQqkDYUzOw== X-Received: by 2002:aca:68da:: with SMTP id o87-v6mr14234110oik.96.1534796791341; Mon, 20 Aug 2018 13:26:31 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id m24-v6sm5670702oic.26.2018.08.20.13.26.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:28 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id E1E511547; Mon, 20 Aug 2018 15:26:24 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 07B4A30010C; Mon, 20 Aug 2018 15:26:21 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:09 -0500 Message-Id: <1534796770-10295-10-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::22c Subject: [Qemu-devel] [PATCH v2 09/10] 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: Corey Minyard , "Dr . David Alan Gilbert" , "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 Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: "Michael S . Tsirkin" Cc: Dr. David Alan Gilbert --- hw/i2c/smbus.c | 14 ++++++++++++++ include/hw/i2c/smbus.h | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c index 6ff77c5..b0774d7 100644 --- a/hw/i2c/smbus.c +++ b/hw/i2c/smbus.c @@ -349,6 +349,20 @@ int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, return 0; } +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_UINT8(command, SMBusDevice), + VMSTATE_END_OF_LIST() + } +}; + static void smbus_device_class_init(ObjectClass *klass, void *data) { I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass); diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus.h index d8b1b9e..7b52020 100644 --- a/include/hw/i2c/smbus.h +++ b/include/hw/i2c/smbus.h @@ -53,14 +53,16 @@ typedef struct SMBusDeviceClass uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n); } 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]; uint8_t command; }; @@ -93,4 +95,14 @@ void smbus_eeprom_init_one(I2CBus *smbus, uint8_t address, uint8_t *eeprom_buf); void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom, const uint8_t *eeprom_spd, int size); +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), \ +} + #endif