From patchwork Thu Feb 28 18:16:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159407 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp974609oce; Thu, 28 Feb 2019 10:18:36 -0800 (PST) X-Google-Smtp-Source: APXvYqyLmhj6EhH+jBYiJCTYz2fHDhz2Lxh9CjtSTFUvx74oC0CgpJ6Lj5u/HLxlgECeA5kbMCFk X-Received: by 2002:a25:4e41:: with SMTP id c62mr709436ybb.304.1551377916270; Thu, 28 Feb 2019 10:18:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551377916; cv=none; d=google.com; s=arc-20160816; b=KR0LY5IC1ggsuNXNF6+x83IHCLDMce25W+dJ3gGGF6iDejKIx0PetvBlw10FrCTr6T emiENYtjlnUou5gX0FsSRnBRmMum48puiYR2IvNX9mFp0m0ST2zl9T73JDMRKzFUsjkd XS1KFMi7jjxiT5wDS7TiBjG6sAdtDXj57ZYyN85BfiQjV/AUrnX9ILqK8qG94xWIusJw TC9PY7UU7ONjaREJAzwuLerED37zAhWtz8jxvpvlFbcklL75Dgcc1/9F3iXEjB5hk7pp XM9dpXK1lVri7YaCACVVtYwBPu3T8YrdK4JKn5hiKmGLcbXEPW/v6GP2kJ3EhUWrQJaU u+Qg== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=vJ0w7sLYD8ZgQh7SZdHcrw4nvYb23Z7A6pHi07R+bbM=; b=w1ncghBMVT9YpgCsDP25QNYnYiRCjCfCDolKbkCbR1FcN/9kMXsDu/pWVBIJwe3Mxw JNVep/EM4oq0OLmTwxzvT6/Jv/hJ1xdW7rWXwAbpmZzHjkQQVACsiUVMN34g7/QZ/kzu D04ZtgObIKXv3z+HOoDTuRnvRoepCb97VxQNdUFFhoI6FgSfXcnNEORUzXOpd/8xnA6l k3dPwQs/EV9G9aiDeHJ6Tdwp2ZHmvM2YGe3LWpfLVlXTC3N8zYtnJUz8dN45fv57vkYZ DtsW1xQqp1GjmrVNBbVzCYipLhlQo2ex679mr1wgCN3gcwHiouzyD/HoeKjlcr2FETmW zH1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=P7jRjTqo; 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 83si10541354ybz.147.2019.02.28.10.18.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:18:36 -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=P7jRjTqo; 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]:44495 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQGR-0000dP-K0 for patch@linaro.org; Thu, 28 Feb 2019 13:18:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46634) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFe-0000VM-BN for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002Hk-GY for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:42 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:39518) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-00029M-5E for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x344.google.com with SMTP id e15so8962330otk.6 for ; Thu, 28 Feb 2019 10:17:16 -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 :mime-version:content-transfer-encoding; bh=vJ0w7sLYD8ZgQh7SZdHcrw4nvYb23Z7A6pHi07R+bbM=; b=P7jRjTqoFTv/XHcC+oSxxUrPl0VDb/JHh3GXbS7BVtN1re9ZrmQoPe7QjCwzO3Ip95 7lbWY+tr2zsEvkW3zZWtwxO6oYVNbeyzZQ4SlrlL/l2K4sfulDWMf0/1J1bvUW4wF7Zz RSW46oAGlVvjLwWAg0WF3rraTe7CoF+UWudyc2OkA/dk7k6gN+2F5y6LmMoilYRlgIp2 juFjY1YJa0gjo/4Hr+hdXTWcGEMi7skQhqDqd6LkeAMMzMIBJkc3vWaFJ295gCiSUyde 37Yy3/1F9K3dsQzHGoAQQB+QXmBa6gmBIL94wJCLyO5aiqxkw7WNMu+mpzHuZAPPp2gx PEgA== 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:mime-version:content-transfer-encoding; bh=vJ0w7sLYD8ZgQh7SZdHcrw4nvYb23Z7A6pHi07R+bbM=; b=o9W5irLToCuRnv2+Wn6vJYWT9RCZ3++oFpDeO1uo0m8UBdPdbJqJ4ySQtvPDibgbvW QVopC53713I71TRYbPCaaG+c7+v5S8Qe4+HYH2CwHZim/hkZ4nH7GsKwZ8wsK6o9EkhC 00WaLOdF5nBcSSODInS7Tx2GX7q5cKOc1hJvs+kVRN4cyRrqsDFLi66+EtIXJRdQDfxW RRbObOP6De/XvNas/PRxmCef54o4qZ58dl2V1QMG4RoR8BpdGhSyfGe+S6q43D+4Iff8 PwJf/+s3DAsANHKigaAU5y1zfjT1NB+Li0SQbJ5LfKs8wNqt7I+YNP3fuE0xt+qC7dZ/ CUzQ== X-Gm-Message-State: APjAAAXcbV3KzhvAhnRWPjIb8CJeQpCPLmWj05sO2Ci+Uk8sPSQfXaqe LARZgZWVTda8PbHh5Ib4Kg== X-Received: by 2002:a9d:7d85:: with SMTP id j5mr611733otn.5.1551377835555; Thu, 28 Feb 2019 10:17:15 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id u24sm8271425otj.44.2019.02.28.10.17.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:14 -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 B55B91808F3; Thu, 28 Feb 2019 18:17:13 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 19E583028CF; Thu, 28 Feb 2019 12:17:12 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:16:52 -0600 Message-Id: <20190228181710.2477-2-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> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::344 Subject: [Qemu-devel] [PULL 01/19] i2c: Split smbus into parts 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard smbus.c and smbus.h had device side code, master side code, and smbus.h has some smbus_eeprom.c definitions. Split them into separate files. Signed-off-by: Corey Minyard Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- MAINTAINERS | 12 ++ hw/arm/aspeed.c | 2 +- hw/i2c/Makefile.objs | 2 +- hw/i2c/pm_smbus.c | 2 +- hw/i2c/smbus_eeprom.c | 3 +- hw/i2c/smbus_ich9.c | 2 - hw/i2c/smbus_master.c | 165 ++++++++++++++++++++++ hw/i2c/{smbus.c => smbus_slave.c} | 153 +------------------- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/isa/vt82c686.c | 1 - hw/mips/mips_fulong2e.c | 2 +- hw/mips/mips_malta.c | 2 +- hw/ppc/sam460ex.c | 2 +- include/hw/i2c/pm_smbus.h | 2 + include/hw/i2c/smbus_eeprom.h | 35 +++++ include/hw/i2c/smbus_master.h | 55 ++++++++ include/hw/i2c/{smbus.h => smbus_slave.h} | 40 +----- 18 files changed, 288 insertions(+), 196 deletions(-) create mode 100644 hw/i2c/smbus_master.c rename hw/i2c/{smbus.c => smbus_slave.c} (65%) create mode 100644 include/hw/i2c/smbus_eeprom.h create mode 100644 include/hw/i2c/smbus_master.h rename include/hw/i2c/{smbus.h => smbus_slave.h} (63%) -- 2.17.1 diff --git a/MAINTAINERS b/MAINTAINERS index 7be8c578ea..04246a63cf 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2160,6 +2160,18 @@ M: Viktor Prutyanov S: Maintained F: contrib/elf2dmp/ +I2C and SMBus +M: Corey Minyard +S: Maintained +F: hw/i2c/core.c +F: hw/i2c/smbus_slave.c +F: hw/i2c/smbus_master.c +F: hw/i2c/smbus_eeprom.c +F: include/hw/i2c/i2c.h +F: include/hw/i2c/smbus_master.h +F: include/hw/i2c/smbus_slave.h +F: include/hw/i2c/smbus_eeprom.h + Usermode Emulation ------------------ Overall diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index 5158985482..996812498d 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -18,7 +18,7 @@ #include "hw/arm/aspeed.h" #include "hw/arm/aspeed_soc.h" #include "hw/boards.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_eeprom.h" #include "qemu/log.h" #include "sysemu/block-backend.h" #include "hw/loader.h" diff --git a/hw/i2c/Makefile.objs b/hw/i2c/Makefile.objs index cecee486f7..9205cbee16 100644 --- a/hw/i2c/Makefile.objs +++ b/hw/i2c/Makefile.objs @@ -1,4 +1,4 @@ -common-obj-$(CONFIG_I2C) += core.o smbus.o +common-obj-$(CONFIG_I2C) += core.o smbus_slave.o smbus_master.o common-obj-$(CONFIG_SMBUS_EEPROM) += smbus_eeprom.o common-obj-$(CONFIG_DDC) += i2c-ddc.o common-obj-$(CONFIG_VERSATILE_I2C) += versatile_i2c.o diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 03062740cc..6cfb7eb1b3 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -20,7 +20,7 @@ #include "qemu/osdep.h" #include "hw/hw.h" #include "hw/i2c/pm_smbus.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_master.h" #define SMBHSTSTS 0x00 #define SMBHSTCNT 0x02 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 01b9439014..c8f6f4b442 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -27,7 +27,8 @@ #include "qapi/error.h" #include "hw/hw.h" #include "hw/i2c/i2c.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_slave.h" +#include "hw/i2c/smbus_eeprom.h" //#define DEBUG diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c index 2a8b49e02f..e6d8d28194 100644 --- a/hw/i2c/smbus_ich9.c +++ b/hw/i2c/smbus_ich9.c @@ -29,8 +29,6 @@ #include "hw/i2c/pm_smbus.h" #include "hw/pci/pci.h" #include "sysemu/sysemu.h" -#include "hw/i2c/i2c.h" -#include "hw/i2c/smbus.h" #include "hw/i386/ich9.h" diff --git a/hw/i2c/smbus_master.c b/hw/i2c/smbus_master.c new file mode 100644 index 0000000000..0a6223744c --- /dev/null +++ b/hw/i2c/smbus_master.c @@ -0,0 +1,165 @@ +/* + * QEMU SMBus host (master) emulation. + * + * This code emulates SMBus transactions from the master point of view, + * it runs the individual I2C transaction to do the SMBus protocol + * over I2C. + * + * Copyright (c) 2007 CodeSourcery. + * Written by Paul Brook + * + * This code is licensed under the LGPL. + */ + +#include "qemu/osdep.h" +#include "hw/hw.h" +#include "hw/i2c/i2c.h" +#include "hw/i2c/smbus_master.h" + +/* Master device commands. */ +int smbus_quick_command(I2CBus *bus, uint8_t addr, int read) +{ + if (i2c_start_transfer(bus, addr, read)) { + return -1; + } + i2c_end_transfer(bus); + return 0; +} + +int smbus_receive_byte(I2CBus *bus, uint8_t addr) +{ + uint8_t data; + + if (i2c_start_transfer(bus, addr, 1)) { + return -1; + } + data = i2c_recv(bus); + i2c_nack(bus); + i2c_end_transfer(bus); + return data; +} + +int smbus_send_byte(I2CBus *bus, uint8_t addr, uint8_t data) +{ + if (i2c_start_transfer(bus, addr, 0)) { + return -1; + } + i2c_send(bus, data); + i2c_end_transfer(bus); + return 0; +} + +int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command) +{ + uint8_t data; + if (i2c_start_transfer(bus, addr, 0)) { + return -1; + } + i2c_send(bus, command); + if (i2c_start_transfer(bus, addr, 1)) { + i2c_end_transfer(bus); + return -1; + } + data = i2c_recv(bus); + i2c_nack(bus); + i2c_end_transfer(bus); + return data; +} + +int smbus_write_byte(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t data) +{ + if (i2c_start_transfer(bus, addr, 0)) { + return -1; + } + i2c_send(bus, command); + i2c_send(bus, data); + i2c_end_transfer(bus); + return 0; +} + +int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command) +{ + uint16_t data; + if (i2c_start_transfer(bus, addr, 0)) { + return -1; + } + i2c_send(bus, command); + if (i2c_start_transfer(bus, addr, 1)) { + i2c_end_transfer(bus); + return -1; + } + data = i2c_recv(bus); + data |= i2c_recv(bus) << 8; + i2c_nack(bus); + i2c_end_transfer(bus); + return data; +} + +int smbus_write_word(I2CBus *bus, uint8_t addr, uint8_t command, uint16_t data) +{ + if (i2c_start_transfer(bus, addr, 0)) { + return -1; + } + i2c_send(bus, command); + i2c_send(bus, data & 0xff); + i2c_send(bus, data >> 8); + i2c_end_transfer(bus); + return 0; +} + +int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, + int len, bool recv_len, bool send_cmd) +{ + int rlen; + int i; + + if (send_cmd) { + if (i2c_start_transfer(bus, addr, 0)) { + return -1; + } + i2c_send(bus, command); + } + if (i2c_start_transfer(bus, addr, 1)) { + if (send_cmd) { + i2c_end_transfer(bus); + } + return -1; + } + if (recv_len) { + rlen = i2c_recv(bus); + } else { + rlen = len; + } + if (rlen > len) { + rlen = 0; + } + for (i = 0; i < rlen; i++) { + data[i] = i2c_recv(bus); + } + i2c_nack(bus); + i2c_end_transfer(bus); + return rlen; +} + +int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, + int len, bool send_len) +{ + int i; + + if (len > 32) { + len = 32; + } + + if (i2c_start_transfer(bus, addr, 0)) { + return -1; + } + i2c_send(bus, command); + if (send_len) { + i2c_send(bus, len); + } + for (i = 0; i < len; i++) { + i2c_send(bus, data[i]); + } + i2c_end_transfer(bus); + return 0; +} diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus_slave.c similarity index 65% rename from hw/i2c/smbus.c rename to hw/i2c/smbus_slave.c index 30028bfcc2..463fafe3c5 100644 --- a/hw/i2c/smbus.c +++ b/hw/i2c/smbus_slave.c @@ -1,6 +1,10 @@ /* * QEMU SMBus device emulation. * + * This code is a helper for SMBus device emulation. It implements an + * I2C device inteface and runs the SMBus protocol from the device + * point of view and maps those to simple calls to emulate. + * * Copyright (c) 2007 CodeSourcery. * Written by Paul Brook * @@ -12,7 +16,7 @@ #include "qemu/osdep.h" #include "hw/hw.h" #include "hw/i2c/i2c.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_slave.h" //#define DEBUG_SMBUS 1 @@ -206,153 +210,6 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data) return 0; } -/* Master device commands. */ -int smbus_quick_command(I2CBus *bus, uint8_t addr, int read) -{ - if (i2c_start_transfer(bus, addr, read)) { - return -1; - } - i2c_end_transfer(bus); - return 0; -} - -int smbus_receive_byte(I2CBus *bus, uint8_t addr) -{ - uint8_t data; - - if (i2c_start_transfer(bus, addr, 1)) { - return -1; - } - data = i2c_recv(bus); - i2c_nack(bus); - i2c_end_transfer(bus); - return data; -} - -int smbus_send_byte(I2CBus *bus, uint8_t addr, uint8_t data) -{ - if (i2c_start_transfer(bus, addr, 0)) { - return -1; - } - i2c_send(bus, data); - i2c_end_transfer(bus); - return 0; -} - -int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command) -{ - uint8_t data; - if (i2c_start_transfer(bus, addr, 0)) { - return -1; - } - i2c_send(bus, command); - if (i2c_start_transfer(bus, addr, 1)) { - i2c_end_transfer(bus); - return -1; - } - data = i2c_recv(bus); - i2c_nack(bus); - i2c_end_transfer(bus); - return data; -} - -int smbus_write_byte(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t data) -{ - if (i2c_start_transfer(bus, addr, 0)) { - return -1; - } - i2c_send(bus, command); - i2c_send(bus, data); - i2c_end_transfer(bus); - return 0; -} - -int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command) -{ - uint16_t data; - if (i2c_start_transfer(bus, addr, 0)) { - return -1; - } - i2c_send(bus, command); - if (i2c_start_transfer(bus, addr, 1)) { - i2c_end_transfer(bus); - return -1; - } - data = i2c_recv(bus); - data |= i2c_recv(bus) << 8; - i2c_nack(bus); - i2c_end_transfer(bus); - return data; -} - -int smbus_write_word(I2CBus *bus, uint8_t addr, uint8_t command, uint16_t data) -{ - if (i2c_start_transfer(bus, addr, 0)) { - return -1; - } - i2c_send(bus, command); - i2c_send(bus, data & 0xff); - i2c_send(bus, data >> 8); - i2c_end_transfer(bus); - return 0; -} - -int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, - int len, bool recv_len, bool send_cmd) -{ - int rlen; - int i; - - if (send_cmd) { - if (i2c_start_transfer(bus, addr, 0)) { - return -1; - } - i2c_send(bus, command); - } - if (i2c_start_transfer(bus, addr, 1)) { - if (send_cmd) { - i2c_end_transfer(bus); - } - return -1; - } - if (recv_len) { - rlen = i2c_recv(bus); - } else { - rlen = len; - } - if (rlen > len) { - rlen = 0; - } - for (i = 0; i < rlen; i++) { - data[i] = i2c_recv(bus); - } - i2c_nack(bus); - i2c_end_transfer(bus); - return rlen; -} - -int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, - int len, bool send_len) -{ - int i; - - if (len > 32) - len = 32; - - if (i2c_start_transfer(bus, addr, 0)) { - return -1; - } - i2c_send(bus, command); - if (send_len) { - i2c_send(bus, len); - } - for (i = 0; i < len; i++) { - i2c_send(bus, data[i]); - } - i2c_end_transfer(bus); - return 0; -} - static void smbus_device_class_init(ObjectClass *klass, void *data) { I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass); diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index fd0f2c268f..3e9037a19a 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -42,7 +42,7 @@ #include "sysemu/sysemu.h" #include "hw/sysbus.h" #include "sysemu/arch_init.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_eeprom.h" #include "hw/xen/xen.h" #include "exec/memory.h" #include "exec/address-spaces.h" diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 4a175ea50e..503eeb46f5 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -33,7 +33,7 @@ #include "hw/hw.h" #include "hw/loader.h" #include "sysemu/arch_init.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_eeprom.h" #include "hw/boards.h" #include "hw/timer/mc146818rtc.h" #include "hw/xen/xen.h" diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index 7302f6d74b..85d0532dd5 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -14,7 +14,6 @@ #include "hw/hw.h" #include "hw/isa/vt82c686.h" #include "hw/i2c/i2c.h" -#include "hw/i2c/smbus.h" #include "hw/pci/pci.h" #include "hw/isa/isa.h" #include "hw/isa/superio.h" diff --git a/hw/mips/mips_fulong2e.c b/hw/mips/mips_fulong2e.c index eec6fd02c8..fbbc543eed 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -28,7 +28,7 @@ #include "hw/isa/superio.h" #include "net/net.h" #include "hw/boards.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_eeprom.h" #include "hw/block/flash.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" diff --git a/hw/mips/mips_malta.c b/hw/mips/mips_malta.c index 7a403ef1ce..39aef4b6db 100644 --- a/hw/mips/mips_malta.c +++ b/hw/mips/mips_malta.c @@ -33,7 +33,7 @@ #include "hw/char/serial.h" #include "net/net.h" #include "hw/boards.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_eeprom.h" #include "hw/block/flash.h" #include "hw/mips/mips.h" #include "hw/mips/cpudevs.h" diff --git a/hw/ppc/sam460ex.c b/hw/ppc/sam460ex.c index 75250d49e4..d455c4bd07 100644 --- a/hw/ppc/sam460ex.c +++ b/hw/ppc/sam460ex.c @@ -34,7 +34,7 @@ #include "hw/sysbus.h" #include "hw/char/serial.h" #include "hw/i2c/ppc4xx_i2c.h" -#include "hw/i2c/smbus.h" +#include "hw/i2c/smbus_eeprom.h" #include "hw/usb/hcd-ehci.h" #include "hw/ppc/fdt.h" diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h index 060d3c6ac0..6dd5b7040b 100644 --- a/include/hw/i2c/pm_smbus.h +++ b/include/hw/i2c/pm_smbus.h @@ -1,6 +1,8 @@ #ifndef PM_SMBUS_H #define PM_SMBUS_H +#include "hw/i2c/smbus_master.h" + #define PM_SMBUS_MAX_MSG_SIZE 32 typedef struct PMSMBus { diff --git a/include/hw/i2c/smbus_eeprom.h b/include/hw/i2c/smbus_eeprom.h new file mode 100644 index 0000000000..0f96836bab --- /dev/null +++ b/include/hw/i2c/smbus_eeprom.h @@ -0,0 +1,35 @@ +/* + * QEMU SMBus EEPROM API + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef HW_SMBUS_EEPROM_H +#define HW_SMBUS_EEPROM_H + +#include "hw/i2c/i2c.h" + +void smbus_eeprom_init_one(I2CBus *bus, uint8_t address, uint8_t *eeprom_buf); +void smbus_eeprom_init(I2CBus *bus, int nb_eeprom, + const uint8_t *eeprom_spd, int size); + +enum sdram_type { SDR = 0x4, DDR = 0x7, DDR2 = 0x8 }; +uint8_t *spd_data_generate(enum sdram_type type, ram_addr_t size, Error **errp); + +#endif diff --git a/include/hw/i2c/smbus_master.h b/include/hw/i2c/smbus_master.h new file mode 100644 index 0000000000..bb13bc423c --- /dev/null +++ b/include/hw/i2c/smbus_master.h @@ -0,0 +1,55 @@ +/* + * QEMU SMBus host (master) API + * + * Copyright (c) 2007 Arastra, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef HW_SMBUS_MASTER_H +#define HW_SMBUS_MASTER_H + +#include "hw/i2c/i2c.h" + +/* Master device commands. */ +int smbus_quick_command(I2CBus *bus, uint8_t addr, int read); +int smbus_receive_byte(I2CBus *bus, uint8_t addr); +int smbus_send_byte(I2CBus *bus, uint8_t addr, uint8_t data); +int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command); +int smbus_write_byte(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t data); +int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command); +int smbus_write_word(I2CBus *bus, uint8_t addr, uint8_t command, uint16_t data); + +/* + * Do a block transfer from an I2C device. If recv_len is set, then the + * first received byte is a length field and is used to know how much data + * to receive. Otherwise receive "len" bytes. If send_cmd is set, send + * the command byte first before receiving the data. + */ +int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, + int len, bool recv_len, bool send_cmd); + +/* + * Do a block transfer to an I2C device. If send_len is set, send the + * "len" value before the data. + */ +int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, + int len, bool send_len); + +#endif diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus_slave.h similarity index 63% rename from include/hw/i2c/smbus.h rename to include/hw/i2c/smbus_slave.h index 89dfea1a08..46b8948f0f 100644 --- a/include/hw/i2c/smbus.h +++ b/include/hw/i2c/smbus_slave.h @@ -1,8 +1,5 @@ -#ifndef QEMU_SMBUS_H -#define QEMU_SMBUS_H - /* - * QEMU SMBus API + * QEMU SMBus device (slave) API * * Copyright (c) 2007 Arastra, Inc. * @@ -25,6 +22,9 @@ * THE SOFTWARE. */ +#ifndef HW_SMBUS_SLAVE_H +#define HW_SMBUS_SLAVE_H + #include "hw/i2c/i2c.h" #define TYPE_SMBUS_DEVICE "smbus-device" @@ -66,36 +66,4 @@ struct SMBusDevice { uint8_t command; }; -/* Master device commands. */ -int smbus_quick_command(I2CBus *bus, uint8_t addr, int read); -int smbus_receive_byte(I2CBus *bus, uint8_t addr); -int smbus_send_byte(I2CBus *bus, uint8_t addr, uint8_t data); -int smbus_read_byte(I2CBus *bus, uint8_t addr, uint8_t command); -int smbus_write_byte(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t data); -int smbus_read_word(I2CBus *bus, uint8_t addr, uint8_t command); -int smbus_write_word(I2CBus *bus, uint8_t addr, uint8_t command, uint16_t data); - -/* - * Do a block transfer from an I2C device. If recv_len is set, then the - * first received byte is a length field and is used to know how much data - * to receive. Otherwise receive "len" bytes. If send_cmd is set, send - * the command byte first before receiving the data. - */ -int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, - int len, bool recv_len, bool send_cmd); - -/* - * Do a block transfer to an I2C device. If send_len is set, send the - * "len" value before the data. - */ -int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, - int len, bool send_len); - -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); - -enum sdram_type { SDR = 0x4, DDR = 0x7, DDR2 = 0x8 }; -uint8_t *spd_data_generate(enum sdram_type type, ram_addr_t size, Error **errp); - #endif From patchwork Thu Feb 28 18:16:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159405 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp974498oce; Thu, 28 Feb 2019 10:18:29 -0800 (PST) X-Google-Smtp-Source: APXvYqxO7QInhT8rVMWSlQWTNTsIJmvQLEnTjLUBrQgXMONWJm20XpixOOTLeISn1mAOWbQtNwB1 X-Received: by 2002:a0d:df15:: with SMTP id i21mr242343ywe.27.1551377908976; Thu, 28 Feb 2019 10:18:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551377908; cv=none; d=google.com; s=arc-20160816; b=WxMviO90j54dGla1DIXircytg+to5L3KPWgxUDsumeeb4iCbX7emHBCOhMl/RKj/6w AnbdxmluyCJhFz1w5DDFFNss6l3NT2u1JF7UjXnjx/brqc/l4BBwFqR/Q477NDJm6/ZR fw8LXsIqgJnAB6KMiYc0lE6r0+li0znJJmcuEifB4ABMkMFVkfefTDJw4Bpcp6jklGk5 uzwiiAj4dr6mQv01+k9Le1RK9G2FFmmS6oOknnGrUm4zYYWUWcAy44ci1vC1vWuromVr T+C1P4vqzp8oeqTfeKRobRw2TNjzr31sdLcEilQ8xdr0F2wmAwea68uLgADlNEjq36BD P0JA== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=q3HzY62CF69PYoUzSkwefLjdYNoX47tEb2xxB85KIlM=; b=ELRnn1RQCgCvgn7ozxWI5GZUSFsYMNs0QsRP/oAjRa96Ct/RlQKD+v9izXgd1DrQfj 69aUGZ5/JDuxeFkGhBte0RDCGhl7PoWFPgCygzXaDM9yms/HKvqyfDMKy6LfrIRMyiG5 hSPbjEkwm5oLWgg6ZyBhowCQfjQxC7ASg70LzbYCrWRLw/d+N9mLkpeBq/wvIEKJGnJw 1edYzyFNNz38POvr/xF5v9kM5qm/QT+J9m7Uf6SSocd5MIZDWHWaDrJUPilmpTOCnLok 1Bj1NKwxS/Vvk6E+iUdIqAyW+RIZ3bsH0gUegEjwzux04a3ZPgRNriuGRX6EpG0evJIY f+1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=kQUfpbd1; 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 j66si11242460ywc.423.2019.02.28.10.18.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:18:28 -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=kQUfpbd1; 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]:44489 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQGK-0000ao-A3 for patch@linaro.org; Thu, 28 Feb 2019 13:18:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46630) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFe-0000VL-BL for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002HT-Ef for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:42 -0500 Received: from mail-oi1-x22f.google.com ([2607:f8b0:4864:20::22f]:40125) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-00029s-3s for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-oi1-x22f.google.com with SMTP id x187so17254815oia.7 for ; Thu, 28 Feb 2019 10:17:18 -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 :mime-version:content-transfer-encoding; bh=q3HzY62CF69PYoUzSkwefLjdYNoX47tEb2xxB85KIlM=; b=kQUfpbd1sSXTfbDNjmS+yKcccwT7BXcMVif5vc+r2yyyqySxivxcTR5B0OK44bsqYF YYH1ULlNfD6+yVk796KHmzCsjvX+Z20n7iVQV3EHAIQiL65kOHwPY1ZLf09ZXtyxcsi2 vTmzxLKkl5vcmu5jvEAC+c6BqtJbRSLm7pk9iDR7QsGInygOGntp4S+pSznt7iBM08cg o+y1RxpCUZRSVEFBipS2vSdpY9gK8WKSTuaKG4JPTUtzTV3mIFmPjBXKMzgmhy+0462o Ba3S6ducDKJezgIs23WYkkFdj0ecLSlaPaJV4je9clftg2Q/hNTgglRUJAHG/kosEaLd fbGA== 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:mime-version:content-transfer-encoding; bh=q3HzY62CF69PYoUzSkwefLjdYNoX47tEb2xxB85KIlM=; b=o7EXQrZ5tpqjcVgt1xFMRyKXt0V4+edwMhg//nCvou/W/0e2roQgwZH8/qbn5bMi38 pFX5KDrZ+9t1hv739mshnHRmSsUkiFB6NnVc0oDQclx6nEOyYF5ITnPPSdSb/mfnmJuF leQUShSRAjlRu819NwJY8WGGNwQHoKvkHTSu3eKhMtgJQpu90L1+JHXq1haHYu5XsAy/ bV+ztrbmew0SGvW3nf6CwyYJVmOpj1RTp/3qc6lrdcmwUt/vL1H27nMspa6f/g/3xfks YdsHlMMZoJOxYeajvFPXOzJAk81ex4Zi5Eh5k4By15dWViXcC4k1J61mwgyic22QmzoI dLjw== X-Gm-Message-State: AHQUAubtDsvdRRxaX99Y4ItyBzl4vWvxddTmcJGfA1NXYH+0UsbbAioS Qm+8TgRvQ2Oba9Idjri0Bw== X-Received: by 2002:aca:35c1:: with SMTP id c184mr683313oia.39.1551377837438; Thu, 28 Feb 2019 10:17:17 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id l134sm8564244oih.43.2019.02.28.10.17.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:15 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id B3DA81808F2; Thu, 28 Feb 2019 18:17:13 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 3EA3C3028D0; Thu, 28 Feb 2019 12:17:13 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:16:53 -0600 Message-Id: <20190228181710.2477-3-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> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::22f Subject: [Qemu-devel] [PULL 02/19] i2c: have I2C receive operation return uint8_t 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard It is never supposed to fail and cannot return an error, so just have it return the proper type. Have it return 0xff on nothing available, since that's what would happen on a real bus. Signed-off-by: Corey Minyard Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé --- hw/arm/pxa2xx.c | 2 +- hw/arm/tosa.c | 4 ++-- hw/arm/z2.c | 2 +- hw/audio/wm8750.c | 2 +- hw/display/sii9022.c | 2 +- hw/display/ssd0303.c | 4 ++-- hw/gpio/max7310.c | 2 +- hw/i2c/core.c | 32 +++++++++++++------------------- hw/i2c/i2c-ddc.c | 2 +- hw/i2c/smbus_slave.c | 4 ++-- hw/input/lm832x.c | 2 +- hw/misc/pca9552.c | 2 +- hw/misc/tmp105.c | 2 +- hw/misc/tmp421.c | 2 +- hw/nvram/eeprom_at24c.c | 4 ++-- hw/timer/ds1338.c | 2 +- hw/timer/m41t80.c | 2 +- hw/timer/twl92230.c | 2 +- include/hw/i2c/i2c.h | 7 +++---- 19 files changed, 37 insertions(+), 44 deletions(-) -- 2.17.1 diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c index f598a1c053..3d7c88910e 100644 --- a/hw/arm/pxa2xx.c +++ b/hw/arm/pxa2xx.c @@ -1286,7 +1286,7 @@ static int pxa2xx_i2c_event(I2CSlave *i2c, enum i2c_event event) return 0; } -static int pxa2xx_i2c_rx(I2CSlave *i2c) +static uint8_t pxa2xx_i2c_rx(I2CSlave *i2c) { PXA2xxI2CSlaveState *slave = PXA2XX_I2C_SLAVE(i2c); PXA2xxI2CState *s = slave->host; diff --git a/hw/arm/tosa.c b/hw/arm/tosa.c index 7a925fa5e6..eef9d427e7 100644 --- a/hw/arm/tosa.c +++ b/hw/arm/tosa.c @@ -197,10 +197,10 @@ static int tosa_dac_event(I2CSlave *i2c, enum i2c_event event) return 0; } -static int tosa_dac_recv(I2CSlave *s) +static uint8_t tosa_dac_recv(I2CSlave *s) { printf("%s: recv not supported!!!\n", __func__); - return -1; + return 0xff; } static void tosa_tg_init(PXA2xxState *cpu) diff --git a/hw/arm/z2.c b/hw/arm/z2.c index 697a822f1e..6f18d924df 100644 --- a/hw/arm/z2.c +++ b/hw/arm/z2.c @@ -243,7 +243,7 @@ static int aer915_event(I2CSlave *i2c, enum i2c_event event) return 0; } -static int aer915_recv(I2CSlave *slave) +static uint8_t aer915_recv(I2CSlave *slave) { AER915State *s = AER915(slave); int retval = 0x00; diff --git a/hw/audio/wm8750.c b/hw/audio/wm8750.c index f4aa838f62..169b006ade 100644 --- a/hw/audio/wm8750.c +++ b/hw/audio/wm8750.c @@ -561,7 +561,7 @@ static int wm8750_tx(I2CSlave *i2c, uint8_t data) return 0; } -static int wm8750_rx(I2CSlave *i2c) +static uint8_t wm8750_rx(I2CSlave *i2c) { return 0x00; } diff --git a/hw/display/sii9022.c b/hw/display/sii9022.c index eaf11a6e7b..9994385c35 100644 --- a/hw/display/sii9022.c +++ b/hw/display/sii9022.c @@ -79,7 +79,7 @@ static int sii9022_event(I2CSlave *i2c, enum i2c_event event) return 0; } -static int sii9022_rx(I2CSlave *i2c) +static uint8_t sii9022_rx(I2CSlave *i2c) { sii9022_state *s = SII9022(i2c); uint8_t res = 0x00; diff --git a/hw/display/ssd0303.c b/hw/display/ssd0303.c index eb90ba26be..8edf34986c 100644 --- a/hw/display/ssd0303.c +++ b/hw/display/ssd0303.c @@ -62,10 +62,10 @@ typedef struct { uint8_t framebuffer[132*8]; } ssd0303_state; -static int ssd0303_recv(I2CSlave *i2c) +static uint8_t ssd0303_recv(I2CSlave *i2c) { BADF("Reads not implemented\n"); - return -1; + return 0xff; } static int ssd0303_send(I2CSlave *i2c, uint8_t data) diff --git a/hw/gpio/max7310.c b/hw/gpio/max7310.c index 1a2478b5a9..c6f686c3eb 100644 --- a/hw/gpio/max7310.c +++ b/hw/gpio/max7310.c @@ -39,7 +39,7 @@ static void max7310_reset(DeviceState *dev) s->command = 0x00; } -static int max7310_rx(I2CSlave *i2c) +static uint8_t max7310_rx(I2CSlave *i2c) { MAX7310State *s = MAX7310(i2c); diff --git a/hw/i2c/core.c b/hw/i2c/core.c index b54725985a..15237ad073 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -191,23 +191,17 @@ int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send) } return ret ? -1 : 0; } else { - if ((QLIST_EMPTY(&bus->current_devs)) || (bus->broadcast)) { - return -1; - } - - sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt); - if (sc->recv) { - s = QLIST_FIRST(&bus->current_devs)->elt; - ret = sc->recv(s); - trace_i2c_recv(s->address, ret); - if (ret < 0) { - return ret; - } else { - *data = ret; - return 0; + ret = 0xff; + if (!QLIST_EMPTY(&bus->current_devs) && !bus->broadcast) { + sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt); + if (sc->recv) { + s = QLIST_FIRST(&bus->current_devs)->elt; + ret = sc->recv(s); + trace_i2c_recv(s->address, ret); } } - return -1; + *data = ret; + return 0; } } @@ -216,12 +210,12 @@ int i2c_send(I2CBus *bus, uint8_t data) return i2c_send_recv(bus, &data, true); } -int i2c_recv(I2CBus *bus) +uint8_t i2c_recv(I2CBus *bus) { - uint8_t data; - int ret = i2c_send_recv(bus, &data, false); + uint8_t data = 0xff; - return ret < 0 ? ret : data; + i2c_send_recv(bus, &data, false); + return data; } void i2c_nack(I2CBus *bus) diff --git a/hw/i2c/i2c-ddc.c b/hw/i2c/i2c-ddc.c index 0a0367ff38..7aa8727771 100644 --- a/hw/i2c/i2c-ddc.c +++ b/hw/i2c/i2c-ddc.c @@ -51,7 +51,7 @@ static int i2c_ddc_event(I2CSlave *i2c, enum i2c_event event) return 0; } -static int i2c_ddc_rx(I2CSlave *i2c) +static uint8_t i2c_ddc_rx(I2CSlave *i2c) { I2CDDCState *s = I2CDDC(i2c); diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 463fafe3c5..6e4d542f51 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -156,11 +156,11 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) return 0; } -static int smbus_i2c_recv(I2CSlave *s) +static uint8_t smbus_i2c_recv(I2CSlave *s) { SMBusDevice *dev = SMBUS_DEVICE(s); SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev); - int ret; + uint8_t ret; switch (dev->mode) { case SMBUS_RECV_BYTE: diff --git a/hw/input/lm832x.c b/hw/input/lm832x.c index cffbf586d4..1fc7b86f19 100644 --- a/hw/input/lm832x.c +++ b/hw/input/lm832x.c @@ -401,7 +401,7 @@ static int lm_i2c_event(I2CSlave *i2c, enum i2c_event event) return 0; } -static int lm_i2c_rx(I2CSlave *i2c) +static uint8_t lm_i2c_rx(I2CSlave *i2c) { LM823KbdState *s = LM8323(i2c); diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c index 9775d5274a..7325d3f287 100644 --- a/hw/misc/pca9552.c +++ b/hw/misc/pca9552.c @@ -115,7 +115,7 @@ static void pca9552_autoinc(PCA9552State *s) } } -static int pca9552_recv(I2CSlave *i2c) +static uint8_t pca9552_recv(I2CSlave *i2c) { PCA9552State *s = PCA9552(i2c); uint8_t ret; diff --git a/hw/misc/tmp105.c b/hw/misc/tmp105.c index f6d7163273..0c32f6f8b6 100644 --- a/hw/misc/tmp105.c +++ b/hw/misc/tmp105.c @@ -147,7 +147,7 @@ static void tmp105_write(TMP105State *s) } } -static int tmp105_rx(I2CSlave *i2c) +static uint8_t tmp105_rx(I2CSlave *i2c) { TMP105State *s = TMP105(i2c); diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c index eeb11000f0..ce6d40ac9c 100644 --- a/hw/misc/tmp421.c +++ b/hw/misc/tmp421.c @@ -249,7 +249,7 @@ static void tmp421_write(TMP421State *s) } } -static int tmp421_rx(I2CSlave *i2c) +static uint8_t tmp421_rx(I2CSlave *i2c) { TMP421State *s = TMP421(i2c); diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c index 27cd01e615..d1456dafbd 100644 --- a/hw/nvram/eeprom_at24c.c +++ b/hw/nvram/eeprom_at24c.c @@ -74,10 +74,10 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event) } static -int at24c_eeprom_recv(I2CSlave *s) +uint8_t at24c_eeprom_recv(I2CSlave *s) { EEPROMState *ee = AT24C_EE(s); - int ret; + uint8_t ret; ret = ee->mem[ee->cur]; diff --git a/hw/timer/ds1338.c b/hw/timer/ds1338.c index 3849b74a68..03da75486b 100644 --- a/hw/timer/ds1338.c +++ b/hw/timer/ds1338.c @@ -117,7 +117,7 @@ static int ds1338_event(I2CSlave *i2c, enum i2c_event event) return 0; } -static int ds1338_recv(I2CSlave *i2c) +static uint8_t ds1338_recv(I2CSlave *i2c) { DS1338State *s = DS1338(i2c); uint8_t res; diff --git a/hw/timer/m41t80.c b/hw/timer/m41t80.c index 734d7d95fc..c45b9297d8 100644 --- a/hw/timer/m41t80.c +++ b/hw/timer/m41t80.c @@ -40,7 +40,7 @@ static int m41t80_send(I2CSlave *i2c, uint8_t data) return 0; } -static int m41t80_recv(I2CSlave *i2c) +static uint8_t m41t80_recv(I2CSlave *i2c) { M41t80State *s = M41T80(i2c); struct tm now; diff --git a/hw/timer/twl92230.c b/hw/timer/twl92230.c index 51ec355f3f..c83d803dd8 100644 --- a/hw/timer/twl92230.c +++ b/hw/timer/twl92230.c @@ -737,7 +737,7 @@ static int menelaus_tx(I2CSlave *i2c, uint8_t data) return 0; } -static int menelaus_rx(I2CSlave *i2c) +static uint8_t menelaus_rx(I2CSlave *i2c) { MenelausState *s = TWL92230(i2c); diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h index cf4c45a98f..8e236f7bb4 100644 --- a/include/hw/i2c/i2c.h +++ b/include/hw/i2c/i2c.h @@ -33,10 +33,9 @@ typedef struct I2CSlaveClass { /* * Slave to master. This cannot fail, the device should always - * return something here. Negative values probably result in 0xff - * and a possible log from the driver, and shouldn't be used. + * return something here. */ - int (*recv)(I2CSlave *s); + uint8_t (*recv)(I2CSlave *s); /* * Notify the slave of a bus state change. For start event, @@ -78,7 +77,7 @@ void i2c_end_transfer(I2CBus *bus); void i2c_nack(I2CBus *bus); int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send); int i2c_send(I2CBus *bus, uint8_t data); -int i2c_recv(I2CBus *bus); +uint8_t i2c_recv(I2CBus *bus); DeviceState *i2c_create_slave(I2CBus *bus, const char *name, uint8_t addr); From patchwork Thu Feb 28 18:16:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159408 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp977546oce; Thu, 28 Feb 2019 10:21:55 -0800 (PST) X-Google-Smtp-Source: APXvYqwV8sm44ds9VnbR0O3Ef/hsOGpddjp+sl9FFb+OMnqZO96EZx8wFss1W3lHqRuo4SCvTLbY X-Received: by 2002:a5b:9:: with SMTP id a9mr709488ybp.321.1551378115798; Thu, 28 Feb 2019 10:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378115; cv=none; d=google.com; s=arc-20160816; b=LTX535iQOSB3ohkX1p78KxRx0Oy7+0awnYKeFDiir9SceoBU3tioHxm9E//pPea/Ur tztTBw1j8lGTRYbjbl+8pK38E2O4hg8AvziadG+vUfWRi4NCg1MAKcoGYOxDttNxeRFw y7OURnCWjawfZIG7R3UFo5x6JVmBpBg/VsdRU7ow00LGHMuOFd8LLYVrgK1ZabbVK0Ev spuLo4s9xdGVVndQzTPA7u+8D7ORcfbFeovS0j/FIsuc+blieb1IorSoagIa2dRvP889 2prQb/KJMwzNumOdLutcI87vtASZ/tnXzqrazSEp2djvJSHNrG9YdLZL0vobRU99eO/6 CNVg== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=QtEwVgsVkNKo8P3JnAy466q1OLHvwt1fGAGtvogK55Q=; b=0yjB3QdHX49Kde4QDFPGcm0FCQIvIOFU2r2QtIZgtcxMcTYsVgOB8UV0MpWCwnaqJw F0IZmtZHKxNTbfkQ7f+GTVo9sXZEKS4Ipgnx7Net1H3YSiLgQ/B0KmNdh4iIODdGiEMX LGk8RAxGtltD8PrFA+i9tIOtJ8qNKxFAwJkV4S6w1ubv2bZ/0dW0y96nZKNxz8v48iS8 Nq9jbe8VnYML5XNvLCQ14b1tBtQwOh8/ps4pxk8wg0SsRfc6NoDzzqscxnf3EGt6EY0t 3qPjDmnrQx8IivzetTg6cY53mFYdpCqgNuTSGSowaCHVTn1VEntwKd9zFRkyFwlqYWDT Uzjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=BPMVSU0y; 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 j128si10722775ywb.125.2019.02.28.10.21.55 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:21:55 -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=BPMVSU0y; 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]:44547 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQJf-0003E2-7n for patch@linaro.org; Thu, 28 Feb 2019 13:21:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFg-0000WW-GZ for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002HH-9w for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:48 -0500 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]:43703) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-00029d-3f for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x331.google.com with SMTP id n71so18527736ota.10 for ; Thu, 28 Feb 2019 10:17:17 -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 :mime-version:content-transfer-encoding; bh=QtEwVgsVkNKo8P3JnAy466q1OLHvwt1fGAGtvogK55Q=; b=BPMVSU0ycOUe6Eq3Gtq7rbak0wkoU5g2gdoSymnY8zlz8ohFXykwtHSH07yUBVVwrW x+JoMTVD9HY0F/rNHDtyFvvte2zL18nxp5nZyMEoEGpGqbr2fG1p4geDlSL6ZcAXz1Z6 nzDRRAiC1KukZYqkeGk8s2HK2ykt8FecCNFJPq9u6b8uEVYN6px17S0jy1ah4XJhmd1y hB//tcyGPAwr9AmCNSCLJ0vDrp9miXQnQ2d0a5SRt0drpbd6Y6pSzXz3XZTpua1E9LTR ZmS2y5QdBONgOEwa6VVedti0EPilGZ6aKGpDCRRGtrdr0xMZ5Nmofqo+03DEuJa/sQtk b8xg== 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:mime-version:content-transfer-encoding; bh=QtEwVgsVkNKo8P3JnAy466q1OLHvwt1fGAGtvogK55Q=; b=U1uHJgB/e0eGgl9Y5gqVv1LPUwq9AYcAr7eexZlFs+NsyM6+GusE9iR+inXakVhhTj mGdjbebaD1SBCp0Nv/IGdI3y3TcZTck1dlORWzze9B6D+SH4+Nq2y+5VOygomQg+HL2n 96bSgcLwsK/YQrBIqwLT2USaElZ+Wmh5u7Sc7pZvCgD0JYr9ExayE0JCPV+EtBEKgfgN WgVWIqEzvH0w3xm10SVddnM1sIz4P9hHS8Ha4MeEl09zn1HuYA1tgIm/tQfKHpHfwtB1 nlZV3Ig5GtJ81JrUgRE7b1gdiHCwUKFnamkKDQmw4dPDqdwCMseQBM0cyYMd4Pb9lNbU 56FQ== X-Gm-Message-State: APjAAAWfc5SuydIT8dwqGFMsP65i3WSYkOQOctgn3p0KtBpXxzXRoL4Q xXXspN7rlr363vaX6myUsQ== X-Received: by 2002:a9d:6f0e:: with SMTP id n14mr614342otq.156.1551377836661; Thu, 28 Feb 2019 10:17:16 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id q67sm8432861oif.40.2019.02.28.10.17.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:15 -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 BB0971808F4; Thu, 28 Feb 2019 18:17:13 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 5D4B0302AF5; Thu, 28 Feb 2019 12:17:13 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:16:54 -0600 Message-Id: <20190228181710.2477-4-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> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::331 Subject: [Qemu-devel] [PULL 03/19] arm:i2c: Don't mask return from i2c_recv() 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard It can't fail, and now that it returns a uint8_t a 0xff mask is unnecessary. Signed-off-by: Corey Minyard Suggested-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Tested-by: Philippe Mathieu-Daudé Reviewed-by: Peter Maydell --- hw/arm/stellaris.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.17.1 diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c index 442529cc65..7b45fe3ccf 100644 --- a/hw/arm/stellaris.c +++ b/hw/arm/stellaris.c @@ -811,7 +811,7 @@ static void stellaris_i2c_write(void *opaque, hwaddr offset, /* TODO: Handle errors. */ if (s->msa & 1) { /* Recv */ - s->mdr = i2c_recv(s->bus) & 0xff; + s->mdr = i2c_recv(s->bus); } else { /* Send */ i2c_send(s->bus, s->mdr); From patchwork Thu Feb 28 18:16:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159414 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp980423oce; Thu, 28 Feb 2019 10:25:05 -0800 (PST) X-Google-Smtp-Source: APXvYqwtXJFQuLrbU69bJMaaj8BSoOJnRnC+AsqKnIFwUEBOoAtVQzlPivB08SbXB5fQKANIMslT X-Received: by 2002:a25:9945:: with SMTP id n5mr681269ybo.453.1551378305185; Thu, 28 Feb 2019 10:25:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378305; cv=none; d=google.com; s=arc-20160816; b=U5zNB2jtVaXpy24oMY1HCnZuo0IHkYT1AktNYnPqULWHK0zwK9V4soV5QgJt8JaNGt 2vNOpgHwXBd5G3YiD0DP4aifXSM+icrg9dLsRuILEaDbnKpJK1jB862UPnuogn3J1edm gUV4ZDPoX9Awo7uQ+FnCr0GzARVmisgqhjG29Mdomqqzj1cYE77VIVHFTKstDN10COao 48PxsYK897z4lY4WSjyjItP+TRLYoNKDbzL1WdsOcLEwY0XXasX5pn4B5ZYBCfZnFnGe Afi6ovCC6UzwmeNXPvs3XM7bVPUSOh25aaIsD1z4tn4wQHxS/6tspbooUioBDalItcx6 eNwQ== 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=Excm8HgHGnquQpA1JYPDe1clppMYhUvhbZU4Zai+sO0=; b=qPZTrux2FuZo244ksz5wHGl5ATzL7oAMZ8aoii306r4FecjPy2Q/t4JoG6+Ve7zec3 ee6U5hA2IpSw1/f9lSUxFRgmy2EWDWU8MfwMxqUKAh0yk69nwlal8+4b4dwNlOQ+Jl5o hTCnIkhr5CbTFZYz6UqcyR4pzAj/bzkLcyg0lLfSE0E0N6CL1Y/D18fCENFDe4p5C63P 6/5UYd4Y72atJ3XL7TKiwIAxELyBIKH8AlVKioU/XeNKB/RmgSVFGP6DVx1XceeTbrvm EqFym5NT/YpTI275ZGqjIUPtyRYoeUR6e3Mm0rduiP97b9TmOpjxX1w2/OPHr4G7yzil D9ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=biQRL1ou; 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 d15si11201772ywb.64.2019.02.28.10.25.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:25:05 -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=biQRL1ou; 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]:44580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQMi-0005eM-NT for patch@linaro.org; Thu, 28 Feb 2019 13:25:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFi-0000XR-8w for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFY-0002Jr-D4 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:50 -0500 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:42340) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFY-00029S-6X for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:40 -0500 Received: by mail-oi1-x243.google.com with SMTP id s16so17258412oih.9 for ; Thu, 28 Feb 2019 10:17:17 -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=Excm8HgHGnquQpA1JYPDe1clppMYhUvhbZU4Zai+sO0=; b=biQRL1ouBMgkMhP1pF06EvuEp23+bmz1L6gdHU3f9Fw5tWlUrh2tYiLFYGbvqOx8lt 3UpSdLNOUQmvsoGoX3A2R2YGlcJrdTkRNf0R/h+erGg/NMIYUhjfZJSlKzqGNnM/HY6t yp7wr4Ahs3XiNNWON+BnI6WkhExTOuto8S4dQTraRlTayS82oGJZK6u9ZUxLua93mCes X5KZUxl4WDNnMx/vAjZBF8o2+22t8TErK4rggq3YFcjCQ3BfFcWdTVROBOQopPDWXMRb Bi48RHjKFVlh1U+79DivdbdM8S9nFI14VhxyKvOrG45WFfwnXz1OS0yRJhrQ9cUzKgo6 ovMA== 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=Excm8HgHGnquQpA1JYPDe1clppMYhUvhbZU4Zai+sO0=; b=X27yTgbV7NQjQBc9jOuRNI7tda0fIeFGCPKOgasXjAhcUjelZ+RMowLZQTkdd6Xf0l cMyT4R9TXzmF0h1Bth7I/D7YuJmWC4msooQ9oB/SkVsh+G+3kG5rMNMlugsESRfqnfCq BCo7d9eOQnfbsiXWFMCM2chzSX/6Rt3UxIZ5dr2aP5B8cs4JnSNJHDXgq1x6t+BDrBMk zCdd0P6iMGRQKZWWiM6UIcLBBwVtv/HD6u6L5ce31R6vlzfSIfcjjXW8TKWKDdC7ldum 6Kpb+cviz/gAmfCP24eFaXUkfGjvr0SlKuMCtVwQ1PvY1aLCmKRo8Zofv/SIETro2QFw 9v+w== X-Gm-Message-State: AHQUAubJuIG2ckvPUGrOCvL0fCoQoEyCRbyEomGb/ruhWzY+g1usjVjb aEANg7sj/+dI/hHvJpSxsQ== X-Received: by 2002:aca:c1c6:: with SMTP id r189mr672668oif.179.1551377836060; Thu, 28 Feb 2019 10:17:16 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id n187sm8061145oia.34.2019.02.28.10.17.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:14 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id B01661808ED; Thu, 28 Feb 2019 18:17:13 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 6DAA9302AF6; Thu, 28 Feb 2019 12:17:13 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:16:55 -0600 Message-Id: <20190228181710.2477-5-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::243 Subject: [Qemu-devel] [PULL 04/19] i2c: Don't check return value from i2c_recv() 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard i2c_recv() cannot fail, so there is no need to check the return value. It also returns unt8_t, so comparing with < 0 is not meaningful. Fix up various I2C controllers to remove the unneeded code. Signed-off-by: Corey Minyard Suggested-by: Peter Maydell --- hw/i2c/aspeed_i2c.c | 9 ++------- hw/i2c/exynos4210_i2c.c | 8 +------- hw/i2c/imx_i2c.c | 12 ++---------- 3 files changed, 5 insertions(+), 24 deletions(-) -- 2.17.1 diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c index a2dfa82760..a085510cfd 100644 --- a/hw/i2c/aspeed_i2c.c +++ b/hw/i2c/aspeed_i2c.c @@ -189,16 +189,11 @@ static uint8_t aspeed_i2c_get_state(AspeedI2CBus *bus) static void aspeed_i2c_handle_rx_cmd(AspeedI2CBus *bus) { - int ret; + uint8_t ret; aspeed_i2c_set_state(bus, I2CD_MRXD); ret = i2c_recv(bus->bus); - if (ret < 0) { - qemu_log_mask(LOG_GUEST_ERROR, "%s: read failed\n", __func__); - ret = 0xff; - } else { - bus->intr_status |= I2CD_INTR_RX_DONE; - } + bus->intr_status |= I2CD_INTR_RX_DONE; bus->buf = (ret & I2CD_BYTE_BUF_RX_MASK) << I2CD_BYTE_BUF_RX_SHIFT; if (bus->cmd & I2CD_M_S_RX_CMD_LAST) { i2c_nack(bus->bus); diff --git a/hw/i2c/exynos4210_i2c.c b/hw/i2c/exynos4210_i2c.c index c96fa7d7be..d154b05739 100644 --- a/hw/i2c/exynos4210_i2c.c +++ b/hw/i2c/exynos4210_i2c.c @@ -106,16 +106,10 @@ static inline void exynos4210_i2c_raise_interrupt(Exynos4210I2CState *s) static void exynos4210_i2c_data_receive(void *opaque) { Exynos4210I2CState *s = (Exynos4210I2CState *)opaque; - int ret; s->i2cstat &= ~I2CSTAT_LAST_BIT; s->scl_free = false; - ret = i2c_recv(s->bus); - if (ret < 0 && (s->i2ccon & I2CCON_ACK_GEN)) { - s->i2cstat |= I2CSTAT_LAST_BIT; /* Data is not acknowledged */ - } else { - s->i2cds = ret; - } + s->i2cds = i2c_recv(s->bus); exynos4210_i2c_raise_interrupt(s); } diff --git a/hw/i2c/imx_i2c.c b/hw/i2c/imx_i2c.c index 6c81b98ebd..6da5224e2e 100644 --- a/hw/i2c/imx_i2c.c +++ b/hw/i2c/imx_i2c.c @@ -120,7 +120,7 @@ static uint64_t imx_i2c_read(void *opaque, hwaddr offset, value = s->i2dr_read; if (imx_i2c_is_master(s)) { - int ret = 0xff; + uint8_t ret = 0xff; if (s->address == ADDR_RESET) { /* something is wrong as the address is not set */ @@ -133,15 +133,7 @@ static uint64_t imx_i2c_read(void *opaque, hwaddr offset, } else { /* get the next byte */ ret = i2c_recv(s->bus); - - if (ret >= 0) { - imx_i2c_raise_interrupt(s); - } else { - qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: read failed " - "for device 0x%02x\n", TYPE_IMX_I2C, - __func__, s->address); - ret = 0xff; - } + imx_i2c_raise_interrupt(s); } s->i2dr_read = ret; From patchwork Thu Feb 28 18:16:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159416 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp983148oce; Thu, 28 Feb 2019 10:28:10 -0800 (PST) X-Google-Smtp-Source: APXvYqwM/IMZvx6MzwN18xnjXcWWOdUlfOejG52KHCn1NCKmEkiMJPGYHJvOdTsEtQyjgO1mffvI X-Received: by 2002:a81:7bc5:: with SMTP id w188mr257460ywc.265.1551378490586; Thu, 28 Feb 2019 10:28:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378490; cv=none; d=google.com; s=arc-20160816; b=zLdVbJs0gP+YRnA+46rpau7e+gswPXUGR3h0Z8gLDkB3tuQ8puH0tLvpi1pcx5xSEG HEhv6vZXUZj/lCedbcHy3myZ1WUV0TTMv02oVym6ZO9q54NBcJMVrQ+sMtc0cw794Lb0 CWTHN9BMGFk0vz2WMc9H0YKpiD7x6GND7GIgbqVHPjNAQVBllW+cWVhp1m/VIo9xRPRY a+ltg/T0X05wLvSBHsC5jkr5zdJ5XwXb96m9o8Eo5Uue6U7qLpgC5bwlWuWi7F73+o5T 6dbQbj6PH8p5GsBW6/FO3SuaCqTnrhZGAE44h/K9GMwx/6Hyq3Mkifvo9IoJNUodgiYR Fvlw== 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=+I7WOBJKScZxxI8BQQihtBpw1M5lszgobVCD62ghJ6E=; b=BMBZ5mU1HjZfFcn8cVM3hoRw8fyHgAPfXbAsAY+gRB3FRIv2U6VVh98SPZ7rEjppCR UFp0GQpAbWJ7a2NlsFBYv1l9mvTYFHI3XF//J53bxQh4rjF9WodwGcbNp1k868zMyfrN gnITvr8nYmnLJYs3K6iUAexfVFjVNyKLt/gYydEACcStFCGY972YJRDAW3NmYulV5xHa yTEuxWACKURQ/31qL5ym/tIOkLaqZ+HYsMh4DY03X1egxWbtd/F0k7OoLQyTzpCn0V4r xB1P4UtFJAQqAiED+tSE0P5YiC48b2BNw3fzoYCZaVDoy3MOnLirQhkVD251Wt6aK21y zPmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ZH8dDKw3; 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 192si9617017ybm.318.2019.02.28.10.28.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:28:10 -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=ZH8dDKw3; 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]:44638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQPi-0008Iu-2J for patch@linaro.org; Thu, 28 Feb 2019 13:28:10 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFo-0000aE-1j 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 1gzQFc-0002ME-TH for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:56 -0500 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:35969) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFY-0002A4-EJ for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:42 -0500 Received: by mail-ot1-x342.google.com with SMTP id v62so18538838otb.3 for ; Thu, 28 Feb 2019 10:17:19 -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=+I7WOBJKScZxxI8BQQihtBpw1M5lszgobVCD62ghJ6E=; b=ZH8dDKw3yyU0WjdD2bjbg5iTTj1B5lKgdfMy5cKoq4fcH1VYmNMuiC+xMwFMwqsBX2 ah1WG8yqWh5Ri9glKpJVUMIL1lpCZFVa9Dcfd6BotuKOHqQE0jZHSsAY4RitOD7ea4fQ CLqLaBVG9iVf31mGK4E1sNx/1eqFxiEadUGx/evYtR6iCzmqxiGg8tOUQ3YbtO4W6K1I fY7XS6Z1XyV9e4we5FBLvRT42gxlkU60ft78Xfy5L76iPldxVMpLJMdc+T1SdpyMawyN vH4RMbjHOXNGSy3Kz53PeJ/i6dNqOTi62QEVnX0R53ZM+mAyUt50kpeQcsgtZz1jdAvo 9RBg== 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=+I7WOBJKScZxxI8BQQihtBpw1M5lszgobVCD62ghJ6E=; b=p6XmUo1MWkFkuFaPHgh1YEJIeLFIbYXAOO0E0uCKRBTUrP454BwJNLfbxSxvNUXPv4 bume62QDaBm/96HANuP/SkMqRM42M1C3QeiN+FaLy+HFooS0hdF8EfxXxjzsO+4CsNQ5 +UM4hFeecxSjmdp+fhK0671g94BAq1YQXmp1f8F0VWLNb/Dl/VtSMQjRPusDTpDOh6m8 1q4GAnZwlAiL9Kqk8pxPJ5fskzI2odq4/9J2TscBW9vfr+stcU5BL/+b/N2kBir+Rqbk rxX9JusUQdqAzR21+nw3IUSeb4l37drkozaEii3eHjEVm1XPta8IHNhTHNtLTZoDtEBj B4gg== X-Gm-Message-State: APjAAAV7yhKdQf7B9coZKufzlt8yNUwO35c3rpTa9Y3Njig/iSqSi4Da MVMWmPtbj2jQfuXKvVU+jQ== X-Received: by 2002:a9d:6012:: with SMTP id h18mr576565otj.341.1551377838089; Thu, 28 Feb 2019 10:17:18 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id k25sm2751650otl.58.2019.02.28.10.17.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:16 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id D8B1A1808F5; Thu, 28 Feb 2019 18:17:13 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 9EB54302AF8; Thu, 28 Feb 2019 12:17:13 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:16:56 -0600 Message-Id: <20190228181710.2477-6-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::342 Subject: [Qemu-devel] [PULL 05/19] i2c:smbus: Correct the working of quick commands 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The logic of handling quick SMBus commands was wrong. If you get a finish event with no data, that's a quick command. Document the quick command while we are at it. Signed-off-by: Corey Minyard --- hw/i2c/smbus_slave.c | 35 +++++++++++++++++++---------------- include/hw/i2c/smbus_slave.h | 5 +++++ 2 files changed, 24 insertions(+), 16 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 6e4d542f51..6a89a286e3 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -54,9 +54,7 @@ static void smbus_do_write(SMBusDevice *dev) { SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev); - if (dev->data_len == 0) { - smbus_do_quick_cmd(dev, 0); - } else if (dev->data_len == 1) { + if (dev->data_len == 1) { DPRINTF("Send Byte\n"); if (sc->send_byte) { sc->send_byte(dev, dev->data_buf[0]); @@ -120,19 +118,24 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) break; case I2C_FINISH: - switch (dev->mode) { - case SMBUS_WRITE_DATA: - smbus_do_write(dev); - break; - case SMBUS_RECV_BYTE: - smbus_do_quick_cmd(dev, 1); - break; - case SMBUS_READ_DATA: - BADF("Unexpected stop during receive\n"); - break; - default: - /* Nothing to do. */ - break; + if (dev->data_len == 0) { + if (dev->mode == SMBUS_WRITE_DATA || dev->mode == SMBUS_READ_DATA) { + smbus_do_quick_cmd(dev, dev->mode == SMBUS_READ_DATA); + } + } else { + switch (dev->mode) { + case SMBUS_WRITE_DATA: + smbus_do_write(dev); + break; + + case SMBUS_READ_DATA: + BADF("Unexpected stop during receive\n"); + break; + + default: + /* Nothing to do. */ + break; + } } dev->mode = SMBUS_IDLE; dev->data_len = 0; diff --git a/include/hw/i2c/smbus_slave.h b/include/hw/i2c/smbus_slave.h index 46b8948f0f..5ef1c72ad0 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -40,6 +40,11 @@ typedef struct SMBusDevice SMBusDevice; typedef struct SMBusDeviceClass { I2CSlaveClass parent_class; + + /* + * An operation with no data, special in SMBus. + * This may be NULL, quick commands are ignore in that case. + */ void (*quick_cmd)(SMBusDevice *dev, uint8_t read); void (*send_byte)(SMBusDevice *dev, uint8_t val); uint8_t (*receive_byte)(SMBusDevice *dev); From patchwork Thu Feb 28 18:16:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159409 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp979228oce; Thu, 28 Feb 2019 10:23:50 -0800 (PST) X-Google-Smtp-Source: APXvYqwHd4EodHy0FVLW58UTYtc4S31RdrNu63VxR/HQX/vSmmarENB5W23vsxfk3Ze/Rf5F1mU+ X-Received: by 2002:a25:57c2:: with SMTP id l185mr700208ybb.161.1551378230582; Thu, 28 Feb 2019 10:23:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378230; cv=none; d=google.com; s=arc-20160816; b=RpYL5+NuHyHYN6KT05bOTsyhhlYiRSLcDoZUz96zsD2ekFAqMJpcQV1pZAo3quSGmq IbdeG7l9DPK3Ne2IHHhj+1O+cHQwzXg7KyZ8K2viKueJYBzruxZY4CjeTtFIG5C5v2Ly JTrFSfgPscMiFCPBLJGXjc33qKbLSAlFHSBZ6a0I3VVSazAj9CeJ7dV0hMDg4ITeuaQK Rf80R+Ge/YfbzrrHhPNL/n3WSrj1NeKBBBH8fMBoJT49Jdrlaw72Nbpik/7yySTHvzS3 oSTEg5gQHNVGDQZ/tre/AxEjndkJ2CRAseODZMgXEH5/rImTCK9hAujM/KfBjcLM1XAQ dA4w== 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=kmGuLPE0xd0NHZLHoAWNBJlvkfppEobdtKRTK+UBiaQ=; b=t5i0xeIOa+Muj0XhsHgwmUnEIntm1gINvPADOu/Za51+vR0eYw+jLkHAAOVywY75Nd VoNC9SqcfnV09IIQL0sGnJsaaQfSPNut0Y5yq6sWmAKpOLkblftqdpQawWUuyolHRH3j jvpwmK5BeT5VrTvKgi9e0g+VVrRLRZDELcgKwOK/AMr9corWO+ozxYjPvUFeS7IlRMyd COwvq7JqYkc6ktL9D8m/RrhuxwBV+TLZ1uqyw4BeyF0N1IWxiiAvLUXJU0qsnAgRBzQ0 Buuu6iKmhvp6gMLbQdoKhMNlQRPL1bAlxQsHm5Awd7HaAK2fSabxrjkfzhSpTJxzmZzb AztQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=r1yae0yL; 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 p22si8979571yba.370.2019.02.28.10.23.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:23:50 -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=r1yae0yL; 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]:44557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQLW-0003pf-1u for patch@linaro.org; Thu, 28 Feb 2019 13:23:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFe-0000VN-BM for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002Hp-Gd for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:44 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:35200) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002AK-6O for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x343.google.com with SMTP id z19so18560171otm.2 for ; Thu, 28 Feb 2019 10:17:19 -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=kmGuLPE0xd0NHZLHoAWNBJlvkfppEobdtKRTK+UBiaQ=; b=r1yae0yLZfY9IS0XWH4WnTI+QuskbL6m/NJI0S/I6MzuqrT7H2BNxCr+KyveGWx+3V YxB0IzCH0bNMS+K9rzsJBbcpOLtGpiVsg/c3IgcaeO72FppgYw1NaU8Z2oahhwfrHdJM A3GX145NTeQeOD95EfAfMeJlNv1pA2XYlpDxHW+Ll7fsqHn5FT77CXRNmI8OWhS06kcU dO5fhGj2lLpwX2VW0dkRptAjVWCAzx305gPdG283G3U2IEifLYc9yiQgeDMWCLlPoyAK UlyZgaKWzKcHOV5aDXQPogb1yjHK+mYE+gF7eP98BtQQIij9TgDiuNKLH8C/Nq8dMr+t wQkA== 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=kmGuLPE0xd0NHZLHoAWNBJlvkfppEobdtKRTK+UBiaQ=; b=RQSsK0fS4FUdBR7bMOWK5l4fJBSZIdorOMLIO4jhKDhgBFIJKxrO65DEDdV6UCE8jg fLSEPDxfSWPzhKMvFshwvWWvoR4nDu1DoUuCB82PECZCtNCdufzEttvLWAl3xnHDXCFV Vz7Ep3cBUobma+jPzXOPuktq6+7iKgNjEyHjmRxROb5vfettuqUcnXUMw6LPfZoSyckG 2M2LhQW/5/uOChRbEWdcZ5m3I1OTSjuvQS2yBaElQsyz5I8YkNcwqTfPkqr4DO9eQTns WwG72NHTM0Y9eW6grIcbVlodkJ77Jlv1RhVBMihzHxiUehpXahDU+XbEIYCFyxowGePb IbaQ== X-Gm-Message-State: APjAAAX1R4+HRlFWGPJN9LvefpOgNm/i0f7HRB2XZJt8A4y5bU7/oI8y l1u+FCXIAzCZVLzl14xqNg== X-Received: by 2002:a05:6830:1458:: with SMTP id w24mr603762otp.303.1551377838883; Thu, 28 Feb 2019 10:17:18 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id g2sm8073618otq.24.2019.02.28.10.17.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:16 -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 D9E9C1808F6; Thu, 28 Feb 2019 18:17:13 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id A9082302AF7; Thu, 28 Feb 2019 12:17:13 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:16:57 -0600 Message-Id: <20190228181710.2477-7-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 06/19] i2c:smbus: Simplify write operation 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard There were two different write functions and the SMBus code kept track of the command. Keeping track of the command wasn't useful, in fact it wasn't quite correct for the eeprom_smbus code. And there is no need for two write functions. Just have one write function and the first byte in the buffer is the command. Signed-off-by: Corey Minyard --- hw/i2c/smbus_eeprom.c | 47 ++++++++++++------------------------ hw/i2c/smbus_slave.c | 25 ++++--------------- include/hw/i2c/smbus_slave.h | 21 ++++++++++------ 3 files changed, 34 insertions(+), 59 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index c8f6f4b442..7fbb5ca27f 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -45,16 +45,6 @@ static void eeprom_quick_cmd(SMBusDevice *dev, uint8_t read) #endif } -static void eeprom_send_byte(SMBusDevice *dev, uint8_t val) -{ - SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; -#ifdef DEBUG - printf("eeprom_send_byte: addr=0x%02x val=0x%02x\n", - dev->i2c.address, val); -#endif - eeprom->offset = val; -} - static uint8_t eeprom_receive_byte(SMBusDevice *dev) { SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; @@ -67,34 +57,30 @@ static uint8_t eeprom_receive_byte(SMBusDevice *dev) return val; } -static void eeprom_write_data(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int len) +static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) { SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; - int n; + uint8_t *data = eeprom->data; + #ifdef DEBUG printf("eeprom_write_byte: addr=0x%02x cmd=0x%02x val=0x%02x\n", - dev->i2c.address, cmd, buf[0]); + dev->i2c.address, buf[0], buf[1]); #endif - /* A page write operation is not a valid SMBus command. - It is a block write without a length byte. Fortunately we - get the full block anyway. */ - /* TODO: Should this set the current location? */ - if (cmd + len > 256) - n = 256 - cmd; - else - n = len; - memcpy(eeprom->data + cmd, buf, n); - len -= n; - if (len) - memcpy(eeprom->data, buf + n, len); + /* len is guaranteed to be > 0 */ + eeprom->offset = buf[0]; + buf++; + len--; + + for (; len > 0; len--) { + data[eeprom->offset] = *buf++; + eeprom->offset = (eeprom->offset + 1) % 256; + } + + return 0; } -static uint8_t eeprom_read_data(SMBusDevice *dev, uint8_t cmd, int n) +static uint8_t eeprom_read_data(SMBusDevice *dev, int n) { - SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; - /* If this is the first byte then set the current position. */ - if (n == 0) - eeprom->offset = cmd; /* As with writes, we implement block reads without the SMBus length byte. */ return eeprom_receive_byte(dev); @@ -119,7 +105,6 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) dc->realize = smbus_eeprom_realize; sc->quick_cmd = eeprom_quick_cmd; - sc->send_byte = eeprom_send_byte; sc->receive_byte = eeprom_receive_byte; sc->write_data = eeprom_write_data; sc->read_data = eeprom_read_data; diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 6a89a286e3..92c7a5086c 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -54,18 +54,9 @@ static void smbus_do_write(SMBusDevice *dev) { SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev); - if (dev->data_len == 1) { - DPRINTF("Send Byte\n"); - if (sc->send_byte) { - sc->send_byte(dev, dev->data_buf[0]); - } - } else { - dev->command = dev->data_buf[0]; - DPRINTF("Command %d len %d\n", dev->command, dev->data_len - 1); - if (sc->write_data) { - sc->write_data(dev, dev->command, dev->data_buf + 1, - dev->data_len - 1); - } + DPRINTF("Command %d len %d\n", dev->data_buf[0], dev->data_len); + if (sc->write_data) { + sc->write_data(dev, dev->data_buf, dev->data_len); } } @@ -98,13 +89,7 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) BADF("Read after write with no data\n"); dev->mode = SMBUS_CONFUSED; } else { - if (dev->data_len > 1) { - smbus_do_write(dev); - } else { - dev->command = dev->data_buf[0]; - DPRINTF("%02x: Command %d\n", dev->i2c.address, - dev->command); - } + smbus_do_write(dev); DPRINTF("Read mode\n"); dev->data_len = 0; dev->mode = SMBUS_READ_DATA; @@ -177,7 +162,7 @@ static uint8_t smbus_i2c_recv(I2CSlave *s) break; case SMBUS_READ_DATA: if (sc->read_data) { - ret = sc->read_data(dev, dev->command, dev->data_len); + ret = sc->read_data(dev, dev->data_len); dev->data_len++; } else { ret = 0; diff --git a/include/hw/i2c/smbus_slave.h b/include/hw/i2c/smbus_slave.h index 5ef1c72ad0..fa92201ec6 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -46,18 +46,24 @@ typedef struct SMBusDeviceClass * This may be NULL, quick commands are ignore in that case. */ void (*quick_cmd)(SMBusDevice *dev, uint8_t read); - void (*send_byte)(SMBusDevice *dev, uint8_t val); + uint8_t (*receive_byte)(SMBusDevice *dev); - /* We can't distinguish between a word write and a block write with - length 1, so pass the whole data block including the length byte - (if present). The device is responsible figuring out what type of - command this is. */ - void (*write_data)(SMBusDevice *dev, uint8_t cmd, uint8_t *buf, int len); + + /* + * We can't distinguish between a word write and a block write with + * length 1, so pass the whole data block including the length byte + * (if present). The device is responsible figuring out what type of + * command this is. + * This may be NULL if no data is written to the device. Writes + * will be ignore in that case. + */ + int (*write_data)(SMBusDevice *dev, uint8_t *buf, uint8_t len); + /* Likewise we can't distinguish between different reads, or even know the length of the read until the read is complete, so read data a byte at a time. The device is responsible for adding the length byte on block reads. */ - uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n); + uint8_t (*read_data)(SMBusDevice *dev, int n); } SMBusDeviceClass; struct SMBusDevice { @@ -68,7 +74,6 @@ struct SMBusDevice { int mode; int data_len; uint8_t data_buf[34]; /* command + len + 32 bytes of data. */ - uint8_t command; }; #endif From patchwork Thu Feb 28 18:16:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159417 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp984388oce; Thu, 28 Feb 2019 10:29:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwvAh98bC3yrj2INTBNO6+WexDY2DRSS1OMLzZruDf9km2a9pF0X270l0RRX10rlRxdiPxY X-Received: by 2002:a81:100a:: with SMTP id 10mr255938ywq.341.1551378580267; Thu, 28 Feb 2019 10:29:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378580; cv=none; d=google.com; s=arc-20160816; b=RRCOmCCNP6C9JO8A8Oq7qbECaFlVNOcsFqLAingKlIO1Xp1cZ50K26RU0vtYHGi3Q8 JpO9YMrD1uzf5i4PunGOjV1/GOUygsQEKH7j2NoyLO4wVAZXiATW85JEoPY2bbsEqq4N Sii9/+ea4A7DlfQoFzZuBvfeqniBy69SHSCAOSUhdzAHBJv9fuoMStn8Nl1To+4JFhHr m8Erz/myvEmWpB61qVVW81GpcCfhkkhXdQg4Yq5n7OLbRsE87S+iTTZLsNKOuR7LANrN YAt5WJIOlcZaFJ4Nukc12Py1eikzA/etDItMDYjLGg6/69XUKBrH2S+jvuOegThvboVv 6iHw== 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=FWe2Dhv89KodfuqowwWrK2ETS2o3tITKLnWO0wMvKec=; b=P+wTEfvgoiF3p8e48kq3yVkUD6G0nbnlk5CY1msfMC1Rn3lgVhgLn6qcz/xCFleh0T SLNiUYJkGnAKr1YyC5rG9fRnPgLW0dmGJ7RHi71aeND3hIJ6apuC3R0Y6P8km4it9Jrf PQXPZUQnqpSzVjUGuo68gbn9AHUJV/LDgv9PsBKfjC0Ti8XeyJjsw4xE8UH7GU/mY6eR hJ9G/vLbtC6p7ZNBxS95FQwbxWZZe6/v7V39brXRp+HgOdthTyfXa8Hw3HF6FH3s9Npw UNfWu9dDSDE5mP2W1313rL0I2T96/wAPQAgWhQOq2T1OjdQGufvhC6NUS7aA/d5YazER uPQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=vJi6I3vc; 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 y12si11157194ywd.351.2019.02.28.10.29.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:29:40 -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=vJi6I3vc; 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]:44640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQR9-0000Tu-PK for patch@linaro.org; Thu, 28 Feb 2019 13:29:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46763) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFo-0000aC-12 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 1gzQFc-0002Lk-NM for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:55 -0500 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:37585) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFY-0002BN-9D for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:40 -0500 Received: by mail-oi1-x243.google.com with SMTP id w66so17269980oia.4 for ; Thu, 28 Feb 2019 10:17:23 -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=FWe2Dhv89KodfuqowwWrK2ETS2o3tITKLnWO0wMvKec=; b=vJi6I3vc7ey5uh7DtydPqNJ4AIjnBwQdjrCwYQ/I7p7JGKLpdikHDifuDPGLkXSRQX R/7I1QLXelDRleDQHx0Mmul+c7j8rCLVRic3dduNKcTgeEFPB0AiQC0SCfnAlgnJouQf oDWuFJYkKAm2G4UbEbFl60ZIh0nHTBGUGU0Nhlx2xSVL4rNb6jJZLguqvC+byRWZr4JZ jDuBqpnfw5DeM52OWUzBG/L3GUwT9rBS0QhxL6M6f/AIWCxpArS+ca0WS7wGVJE/CQYf /f1J+UUk8igTrDSJxA8u+xfmOnU6hzbCH7wQxGi4OH20myp/Qpw9nQ364tX9WoiJ5KJM QpdQ== 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=FWe2Dhv89KodfuqowwWrK2ETS2o3tITKLnWO0wMvKec=; b=n+jzKEmoQkJwZdsIjLDiZ5ShpWZsqf4yEQKPkvJv6Zr3ehZcph6TSMpKw1QZP1VMb6 +x1yQnmfy2wLmoy3Pz2oC14G1s2KjSVKSr0DbpnM6i449H4UpV+Bd/XrIw/Eu/0B/mI0 GEiXSLf+ObGIY2vgQrgobcQJLrZYOtlpFWyxxsWTLWXe491Qx0wqe5JaE/qS93w0ukrb 5QEmNt0tmN7vCuKtj0z7AB+/pDYj+XK0OBHtZjySM7NTyA5ZWz3/V4yYc+08AhZ8O6oP UX3GDe6UwKUEaUU0KAnLo+/NGMwnLpCX6ypRRgH28ZBPwl7Ov1ZeLNNQV7DIPvMO1K/p CpBA== X-Gm-Message-State: AHQUAuZ5zi/C757C/ZNbIyHNMm0TUasstRpe8H7Fr5xwg1eQhLIACeeK UuXxfPtKPrQbBgGFJ+2jWQ== X-Received: by 2002:aca:4d42:: with SMTP id a63mr696895oib.57.1551377842674; Thu, 28 Feb 2019 10:17:22 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id c38sm7871037otb.3.2019.02.28.10.17.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:17 -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 007C91808F7; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id C19F4302AF9; Thu, 28 Feb 2019 12:17:13 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:16:58 -0600 Message-Id: <20190228181710.2477-8-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::243 Subject: [Qemu-devel] [PULL 07/19] i2c:smbus: Simplify read handling 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard There were two different read functions, and with the removal of the command passed in there is no functional difference. So remove one of them. With that you don't need one of the states, so that can be removed, too. Signed-off-by: Corey Minyard --- hw/i2c/smbus_eeprom.c | 8 -------- hw/i2c/smbus_slave.c | 21 +++------------------ include/hw/i2c/smbus_slave.h | 17 ++++++++++------- 3 files changed, 13 insertions(+), 33 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 7fbb5ca27f..760594b3f1 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -79,13 +79,6 @@ static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) return 0; } -static uint8_t eeprom_read_data(SMBusDevice *dev, int n) -{ - /* As with writes, we implement block reads without the - SMBus length byte. */ - return eeprom_receive_byte(dev); -} - static void smbus_eeprom_realize(DeviceState *dev, Error **errp) { SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev; @@ -107,7 +100,6 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) sc->quick_cmd = eeprom_quick_cmd; sc->receive_byte = eeprom_receive_byte; sc->write_data = eeprom_write_data; - sc->read_data = eeprom_read_data; dc->props = smbus_eeprom_properties; /* Reason: pointer property "data" */ dc->user_creatable = false; diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 92c7a5086c..52a57423ee 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -34,7 +34,6 @@ do { fprintf(stderr, "smbus: error: " fmt , ## __VA_ARGS__);} while (0) enum { SMBUS_IDLE, SMBUS_WRITE_DATA, - SMBUS_RECV_BYTE, SMBUS_READ_DATA, SMBUS_DONE, SMBUS_CONFUSED = -1 @@ -82,7 +81,7 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) switch (dev->mode) { case SMBUS_IDLE: DPRINTF("Read mode\n"); - dev->mode = SMBUS_RECV_BYTE; + dev->mode = SMBUS_READ_DATA; break; case SMBUS_WRITE_DATA: if (dev->data_len == 0) { @@ -91,7 +90,6 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) } else { smbus_do_write(dev); DPRINTF("Read mode\n"); - dev->data_len = 0; dev->mode = SMBUS_READ_DATA; } break; @@ -148,31 +146,18 @@ static uint8_t smbus_i2c_recv(I2CSlave *s) { SMBusDevice *dev = SMBUS_DEVICE(s); SMBusDeviceClass *sc = SMBUS_DEVICE_GET_CLASS(dev); - uint8_t ret; + uint8_t ret = 0xff; switch (dev->mode) { - case SMBUS_RECV_BYTE: + case SMBUS_READ_DATA: if (sc->receive_byte) { ret = sc->receive_byte(dev); - } else { - ret = 0; - } - DPRINTF("Receive Byte %02x\n", ret); - dev->mode = SMBUS_DONE; - break; - case SMBUS_READ_DATA: - if (sc->read_data) { - ret = sc->read_data(dev, dev->data_len); - dev->data_len++; - } else { - ret = 0; } DPRINTF("Read data %02x\n", ret); break; default: BADF("Unexpected read in state %d\n", dev->mode); dev->mode = SMBUS_CONFUSED; - ret = 0; break; } return ret; diff --git a/include/hw/i2c/smbus_slave.h b/include/hw/i2c/smbus_slave.h index fa92201ec6..79050fb92d 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -47,8 +47,6 @@ typedef struct SMBusDeviceClass */ void (*quick_cmd)(SMBusDevice *dev, uint8_t read); - uint8_t (*receive_byte)(SMBusDevice *dev); - /* * We can't distinguish between a word write and a block write with * length 1, so pass the whole data block including the length byte @@ -59,11 +57,16 @@ typedef struct SMBusDeviceClass */ int (*write_data)(SMBusDevice *dev, uint8_t *buf, uint8_t len); - /* Likewise we can't distinguish between different reads, or even know - the length of the read until the read is complete, so read data a - byte at a time. The device is responsible for adding the length - byte on block reads. */ - uint8_t (*read_data)(SMBusDevice *dev, int n); + /* + * Likewise we can't distinguish between different reads, or even know + * the length of the read until the read is complete, so read data a + * byte at a time. The device is responsible for adding the length + * byte on block reads. This call cannot fail, it should return + * something, preferably 0xff if nothing is available. + * This may be NULL if no data is read from the device. Reads will + * return 0xff in that case. + */ + uint8_t (*receive_byte)(SMBusDevice *dev); } SMBusDeviceClass; struct SMBusDevice { From patchwork Thu Feb 28 18:16:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159419 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp984711oce; Thu, 28 Feb 2019 10:30:02 -0800 (PST) X-Google-Smtp-Source: APXvYqw88MfVPz04NV39YzQTUqQPMvwvdnYbaWfUtOrVc6zLt+1gEOVbNnxjXth7S5TVp9rhCTX+ X-Received: by 2002:a25:ca4a:: with SMTP id a71mr752103ybg.408.1551378602097; Thu, 28 Feb 2019 10:30:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378602; cv=none; d=google.com; s=arc-20160816; b=eI/DHbjTgzpxoY9HeKHqAcAgV8aGSvyUE0yXon+kWNfZtDj/pPvw2DINwpFycjXGfq mu2DTuwtK4WSOmX5GnCyIv62jg2HqERd0N9aaEgx+JuI63ZPrzPR43VHR1I4SjuE3r44 VAEVIvfZ8uL/PCwlYr0j/q98OSiY0vLshwnmctLBKWy0wzmvh2VjkAuVRmkOB6rBFNAr IgNGru9XB1OfpZDAdXX86KmXrlWHRpJ6N3FKhz11ISIbQjpK4Pr2xoFg6TWDteQoj4i+ ACjkdXGvTcax8+7CS356XmBCrLgSyDdhBIJGMrHJ1U8GX7DKvx5xBDNLuyZsMk/J2bzm XRoQ== 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=PxmXlovPy4UmaSiUNVr3SIc5dpi6UCs2xw4qY2YArSI=; b=meZNx8QLToegWMT/BSvHfH75pd75LOJDeAe8xIbxpciCyVvfhjMV+84LzvpJ3QKWZt z8qYRrPGzKXUnDbAb1XaNRHcPkR4Zpy7OaImtGtmnr/aRbJTCvUXAwfurIq9ZijGIRPq qtl7IY6wcfec4ovOmYk5WL1udUlXRmwWhCp9IW0C4jEhsQM7oPolxtzIQxKE9E/KUus2 oK0R3j3ookrZkFF8duqS4xvJ7Wx0eAi2XKYQ2NEYQEINIe1K2h6kkNbNGxIlvDWld8r4 A8tUT6lYrMgxy3xzSWvK2Cibpul6SLhFaN9ZJnRGU7MjJmzcxhCQGkq+BkvLQuepNi+L C2fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=T2vgCc9A; 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 f128si10407277ybf.416.2019.02.28.10.30.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:30:02 -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=T2vgCc9A; 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]:44648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQRV-0001Ob-Ky for patch@linaro.org; Thu, 28 Feb 2019 13:30:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFm-0000ZH-5w for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002IX-Sk for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:53 -0500 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]:33366) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002BE-Jz for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-oi1-x230.google.com with SMTP id z14so17318413oid.0 for ; Thu, 28 Feb 2019 10:17:23 -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=PxmXlovPy4UmaSiUNVr3SIc5dpi6UCs2xw4qY2YArSI=; b=T2vgCc9A4AVM8ALK6GKWK7Jh8myVbohLokBhPkpxhCuj6KY8pcjViPbfX5W7n1TAyc D+ZwXatULKxEYWmVe5oalrJhT6XidSel2oF14l6ha0vp7LntbF95bHB7WFHHh6wDdK4t tpjscK99kudzxH1qZdVCxxtWszEYodQzQLUBn/6pDH0OAMTiJvOA/z1pr0lhQiNEfxvu aQm4htgRppUb1XLkh00Fl8G7WhwaNrpfU7rPTp6RGI64J66dV9bvDywP5fEk71EVWkCg U5oz6zosoywFtaPaLQgDzzLzb05cgZQFMZkqo7NA1OjymxsQAjGSvjH4tsIE5PLy/8hv fC6A== 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=PxmXlovPy4UmaSiUNVr3SIc5dpi6UCs2xw4qY2YArSI=; b=I845CVB8C0+psPdqGV1eXKf5GNt45f/6Uzs+lVIiiWDht7aIZXOoAEePZZWCwvLOrC UdjmaZwe51M+gW7/gwmHhEjeaOHS6GKbLbOO7toPyDkJ7wl1uErCZH0CoQ5M9UOvqUEt hSbN6IvcN7VVwCjRGJq+fV6SiLfU4dH+aGSEKSHJp2otgcOVHxpJCfOuv1rbogARIiRl FdZhLXr8XkovAmmTpfihiHgJrru/gk0MEaS791uo0IozBgtfEL27uVnG+VCUplmzNtsM BcHGhzYKe957H8EGM7JZLnwmohD8/JPzAo39JdlhqUYBcs4kAcnGDp/6IcJW/2haV/wa MyPQ== X-Gm-Message-State: APjAAAWpvlToVUQLLmQ0ixeAkmHU2KHXg3JJQHZqE2YpVlvZ0z7Ca6m0 9I1x5UAN3R9ahQsXZ1DY6w== X-Received: by 2002:aca:c682:: with SMTP id w124mr678200oif.117.1551377842194; Thu, 28 Feb 2019 10:17:22 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id k25sm2751654otl.58.2019.02.28.10.17.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:17 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 06D481808F8; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id EC7DC3028D0; Thu, 28 Feb 2019 12:17:13 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:16:59 -0600 Message-Id: <20190228181710.2477-9-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::230 Subject: [Qemu-devel] [PULL 08/19] i2c:smbus_eeprom: Get rid of the quick command 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard It's not necessary, it won't be called if it's NULL. Signed-off-by: Corey Minyard --- hw/i2c/smbus_eeprom.c | 8 -------- 1 file changed, 8 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 760594b3f1..2f90287b69 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -38,13 +38,6 @@ typedef struct SMBusEEPROMDevice { uint8_t offset; } SMBusEEPROMDevice; -static void eeprom_quick_cmd(SMBusDevice *dev, uint8_t read) -{ -#ifdef DEBUG - printf("eeprom_quick_cmd: addr=0x%02x read=%d\n", dev->i2c.address, read); -#endif -} - static uint8_t eeprom_receive_byte(SMBusDevice *dev) { SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; @@ -97,7 +90,6 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(klass); dc->realize = smbus_eeprom_realize; - sc->quick_cmd = eeprom_quick_cmd; sc->receive_byte = eeprom_receive_byte; sc->write_data = eeprom_write_data; dc->props = smbus_eeprom_properties; From patchwork Thu Feb 28 18:17:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159430 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp990250oce; Thu, 28 Feb 2019 10:34:57 -0800 (PST) X-Google-Smtp-Source: APXvYqx/XV3D21iFFzmSimOZ6/S8NNExlWkj7hKNYMNdfckTCM9Pt469geAmg9y3gWW1WrF1RsxD X-Received: by 2002:a81:12d6:: with SMTP id 205mr331321yws.338.1551378897216; Thu, 28 Feb 2019 10:34:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378897; cv=none; d=google.com; s=arc-20160816; b=exmZWbtY2CsYKQUsNjAiBNNb8UbqH71cXfvlS3WVxNpSiKg+W7OyyXcnWGnCwYDVsF cJsvCs87i26VqKTUZ27EFmw2nqjal+cbZ/8uvAtYhKniJPxGYVXo07guKENX1TtChz4O X4pZinABi8sPHZwllgoyV2rNztbGZiKPTi5OsB+0QPtvvu/dkfFpkf5VmgQej+FUJ+0N lO5O3SqjnBJTmvwzT9yrfM3Lt+O+ep+DFLOhibYbIiTzua9NmIZhjTPRgUJ31T2hgyAj 0GJ3nPKUswSzO63SKZ/wfzUiFsJX+erMVrc2OE4NDvRiHtsQkWxE/7FXYdI5IanomZFN 4QlQ== 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=oH9xhrkt9kjzk6DixNaMkUYIa8qMXBRPQYhjGJFyUxM=; b=mqkhX4LsG1XnGV+7YFu1MVkDusEvewKlIg+C2uZa1ZJngMtpYt+H6AYz5xF1Zd+DdS Ei5kHo2Xl0HpuLBFurRAbJZ7VU3g7DKup3zWTh9v0Y46p1+1yX+c3Xxy7nPZPHRf/bea F3GgGAWVIoDboQtDcgRzJdTYwwt8Bz1mWum/EmRWizqXW+uFVu3SU/+NiliQNjgNjnvJ pqxBIHKL5xWzEA2GFUObiGElvrr+HmU+C2XEk6eRu68B522pZfTi3kIHLYygbFNJ/LIo v/qIVrRy8QIY4qLjhsuxd2Wq36VddPMU/m4VvQ5q9g1209RujsbHHgVDRzk/26xLItH4 wihA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Ts2LUfmh; 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 y67si10670577ywa.409.2019.02.28.10.34.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:34:57 -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=Ts2LUfmh; 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]:44723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQWG-0004gw-Pa for patch@linaro.org; Thu, 28 Feb 2019 13:34:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFo-0000aD-1a 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 1gzQFc-0002MR-TB for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:56 -0500 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]:43698) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFY-0002Bg-Bx for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:42 -0500 Received: by mail-ot1-x32b.google.com with SMTP id n71so18528058ota.10 for ; Thu, 28 Feb 2019 10:17:24 -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=oH9xhrkt9kjzk6DixNaMkUYIa8qMXBRPQYhjGJFyUxM=; b=Ts2LUfmhrSid+GZYaTq1WV3kb1GLnXiF/0xoia3YEsipUYBmaPpxNN0LxYsAqcBxLC JNwwLlNVJ3m+G6ZgkiUGf6nvSi6bDc4T7BM+Kyri/O236CA16nZ2x3YlvLi2Qltd/97A YPJqeo10gTJcRZv1bCLI0QwbHft+ONCelA8+tln/MskR/2J9xGiDdYjNJvn22htTElUf qvlDMRxDpFYevlXEB1yOJmRqQbf+W9gKPSJ+15tMMcd7tzoGLZU44y7lrGlnjoV7uM96 guM5gvhoy1/rq4+Q62sToCP/CRIL23RZTtcm84uJVmGi6hnkOzfd4TdxJ5T33p/AwgxA NY1A== 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=oH9xhrkt9kjzk6DixNaMkUYIa8qMXBRPQYhjGJFyUxM=; b=VBrhPmTL3WWhHYSsLmiLWLoOqlyTywMnTcKbBUn8l1I+4ClY8iGXSOXEdGBBoMtf9Z 0iosldcosMl6nS4nQYh0PeGp/nISTWImi34Ec4GWhaga7bY0y8of/91yk8tqftL/Ezn5 lCUp8fHaNqar8Cxnpo+6p3S5aiUGSrbiDDY9gh13MdyS+U5Wbw724HLsXihqWDhLCPAf Klfx9LkYAoWhPnAgTZzG0OPLff/Q7s8QkR1P1QubvvS5PQtLvSLKBKkny0rVnw9xTSBT UV9+Gw5o6ESNpbx+RKHd4+AZDhpBk80MZaomaIPxl4zjJ12ECbAy6glaX65bc2Bf+DQK ym1Q== X-Gm-Message-State: APjAAAWCxZaqrLdoVs0g6m6zpjkGOmPnAPJG7IDgjZQL1QSLAn2Imtln /rlWcPqWV78wXFQh5gA57Q== X-Received: by 2002:a9d:74c1:: with SMTP id a1mr659954otl.107.1551377843266; Thu, 28 Feb 2019 10:17:23 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id u5sm7978349otb.62.2019.02.28.10.17.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:17 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 1CFBE1808F9; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 00A6D3028CF; Thu, 28 Feb 2019 12:17:13 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:00 -0600 Message-Id: <20190228181710.2477-10-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::32b Subject: [Qemu-devel] [PULL 09/19] i2c:smbus: Make white space in switch statements consistent 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard It had spaces between cases in some places and not others. Add a space for every one. Signed-off-by: Corey Minyard --- hw/i2c/smbus_eeprom.c | 1 + hw/i2c/smbus_slave.c | 9 +++++++++ 2 files changed, 10 insertions(+) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 2f90287b69..2816e35bcc 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -43,6 +43,7 @@ static uint8_t eeprom_receive_byte(SMBusDevice *dev) SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; uint8_t *data = eeprom->data; uint8_t val = data[eeprom->offset++]; + #ifdef DEBUG printf("eeprom_receive_byte: addr=0x%02x val=0x%02x\n", dev->i2c.address, val); diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 52a57423ee..5b3046f6a3 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -70,6 +70,7 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) DPRINTF("Incoming data\n"); dev->mode = SMBUS_WRITE_DATA; break; + default: BADF("Unexpected send start condition in state %d\n", dev->mode); dev->mode = SMBUS_CONFUSED; @@ -83,6 +84,7 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) DPRINTF("Read mode\n"); dev->mode = SMBUS_READ_DATA; break; + case SMBUS_WRITE_DATA: if (dev->data_len == 0) { BADF("Read after write with no data\n"); @@ -93,6 +95,7 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) dev->mode = SMBUS_READ_DATA; } break; + default: BADF("Unexpected recv start condition in state %d\n", dev->mode); dev->mode = SMBUS_CONFUSED; @@ -129,9 +132,11 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event event) case SMBUS_DONE: /* Nothing to do. */ break; + case SMBUS_READ_DATA: dev->mode = SMBUS_DONE; break; + default: BADF("Unexpected NACK in state %d\n", dev->mode); dev->mode = SMBUS_CONFUSED; @@ -155,11 +160,13 @@ static uint8_t smbus_i2c_recv(I2CSlave *s) } DPRINTF("Read data %02x\n", ret); break; + default: BADF("Unexpected read in state %d\n", dev->mode); dev->mode = SMBUS_CONFUSED; break; } + return ret; } @@ -176,10 +183,12 @@ static int smbus_i2c_send(I2CSlave *s, uint8_t data) dev->data_buf[dev->data_len++] = data; } break; + default: BADF("Unexpected write in state %d\n", dev->mode); break; } + return 0; } From patchwork Thu Feb 28 18:17:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159410 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp979666oce; Thu, 28 Feb 2019 10:24:20 -0800 (PST) X-Google-Smtp-Source: APXvYqz15h/3OAAvX0VcoMwW8L0FLeCIBXQuOhAeR0UKacvj+xk+xrp1NOPnS/60LYgPPZuOf0H7 X-Received: by 2002:a5b:f4a:: with SMTP id y10mr771602ybr.322.1551378260712; Thu, 28 Feb 2019 10:24:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378260; cv=none; d=google.com; s=arc-20160816; b=TTgQxj63omvLESN95y+Ywd+XxWXYZX5Pks8Z/hJu55J6dH2n3Tp9zvlkStyVSMZORO ZACYvSNvll8sf6QYZs5uOa22zXiJl3hHP0iH54dPcuXTkQyssMuCTTyfrmCPCO00dq2X pSnOSSoZZ1/ApMhpAnyfDxd+ih6/wbXXgSYDUJEIoJoNeV5JLiWRWNyVIWm2+TxzZ0zf 9sQIDkI1A0bXfcUg65Y7CY8qTCREi9LslsMkjvuF74zPShfjR6Fttz7s8oub2EvEZ0RX w5ZIz7++gZuO+G3Px7s7kdR4UdgbKxRSaNzishIf7Ap7KwB4CeFPMmoWkt2Gu1hRKKQf GuVg== 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=EwSqbdRnTzTl3dmEwc+GEA5GXiTvpVaCpm03V40SbgQ=; b=o2k2NTBar4tq3e+82DWNc6ZBWcLFNjdPM8wZjzuLVEnHI9bVBNnicG9MJr2O+DKmpP vH/A+TFy1FGixJwU67/Bqu0andJKfv7b4N8oXyKrzsBB1nzqB6YPdKafuraPc4D5lpXp ycMfl+TutCS33wxr9R8CEKjN88o+G9vIx/IADHb3B3F4pJR5A2Qmk+2/pwuq+xmrHVAt uxzIsVvPSYe1Cjt3EZdJ+gJhBdfsaCP83Tcmz39otDW3owWNGUP9NjdDgLEQJyT4swz+ 2oVj8djqs6n7K7e9C9R68UjiGZcUtNGGQpBLzgd/Ty5jOp06aJcPyFF24XkKMpJnv3gk OUbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="h/f4yUDl"; 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 l12si10773577ybp.102.2019.02.28.10.24.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:24:20 -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="h/f4yUDl"; 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]:44568 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQM0-00052A-5f for patch@linaro.org; Thu, 28 Feb 2019 13:24:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFk-0000Yu-8R for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002H7-2l for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:52 -0500 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:33098) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFU-0002Br-PY for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-oi1-x243.google.com with SMTP id z14so17318475oid.0 for ; Thu, 28 Feb 2019 10:17:24 -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=EwSqbdRnTzTl3dmEwc+GEA5GXiTvpVaCpm03V40SbgQ=; b=h/f4yUDlskoACyDV1GLxPBrEm2BVPSuVNYy5ur5DR7k9CrUHbAHIdyBLjtHnsVjUxy o7H+ubD/8Ve5HNkhVR4a3I7fi+oc3rqFNYCgqmS4DgoQtaG/6+aB8gzrDQU4/J1AqCUe ieaBtay4Cd1H03mJEuqnalv12IWJQG5SXGMZplIlO+bQeKUWddYtQl8qe4kFktqAKQH0 dGPij+j4A57ZyN0ClhCfNPBS842xKkJAWBNxj0ivPdijfKY5n7lKr3pQk+A0oYaCO/p4 ZdNV1v2qRATpIbOk3IZojVX7rCLg2aoJx5WQfshedyQE9TaOHUAc2ePoBO8GhrXXtr0y weoA== 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=EwSqbdRnTzTl3dmEwc+GEA5GXiTvpVaCpm03V40SbgQ=; b=DF09YYM/e3gDcQRVc9uMzl5r7AlaDCqIrWwDpdTDoFxqdg+zq1ZmusqSdG11/q3uck uhfmjhsFuie/nuE2N4QnCYjvl/9wFsZJLn1I/+EncSCjvr4crih9i3w6Hc6yFmjUiOwx 8vfoOgbO6icomXcmOwD7AzUWlJ1ufALEBU27v7N51h2jF6dBca5xes3cSHFRNhCrJf8B ZVfa6erw6qpsVOxlXpKrT+uwDiH0NM47l+4vLToR4RedpqzFbNz9f28hRYO4uLerFoZ5 gGrIWkokDd5P+KA3OdTuvoSRxOaYRwYgFq6UqV0zxdl9tom3te7JY/EWWwnCVJD2dmpy p/dA== X-Gm-Message-State: APjAAAXonglujilvTreC+8KO7Orhqy/fYZgFy7xLwml+0M2+PH2kbDp7 0uBW2WG0PS6GANqNRF3Ivw== X-Received: by 2002:aca:60c1:: with SMTP id u184mr667831oib.45.1551377843814; Thu, 28 Feb 2019 10:17:23 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id y19sm7513960oih.42.2019.02.28.10.17.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:17 -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 26FF01808FA; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 1729B3028D0; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:01 -0600 Message-Id: <20190228181710.2477-11-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::243 Subject: [Qemu-devel] [PULL 10/19] boards.h: Ignore migration for SMBus devices on older machines 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 , QEMU Developers , minyard@acm.org, Eduardo Habkost Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Migration capability is being added for pm_smbus and SMBus devices. This change will allow backwards compatibility to be kept when migrating back to an old qemu version. Add a bool to the machine class tho keep smbus migration from happening. Future changes will use this. Signed-off-by: Corey Minyard Cc: Eduardo Habkost Cc: Marcel Apfelbaum Reviewed-by: Dr. David Alan Gilbert --- hw/i386/pc_piix.c | 1 + hw/i386/pc_q35.c | 1 + include/hw/boards.h | 1 + 3 files changed, 3 insertions(+) -- 2.17.1 diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c index 3e9037a19a..8770ecada9 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -444,6 +444,7 @@ static void pc_i440fx_3_1_machine_options(MachineClass *m) pc_i440fx_4_0_machine_options(m); m->is_default = 0; + m->smbus_no_migration_support = true; m->alias = NULL; pcmc->pvh_enabled = false; compat_props_add(m->compat_props, hw_compat_3_1, hw_compat_3_1_len); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 503eeb46f5..cfb9043e12 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -380,6 +380,7 @@ static void pc_q35_3_1_machine_options(MachineClass *m) pc_q35_4_0_machine_options(m); m->default_kernel_irqchip_split = false; + m->smbus_no_migration_support = true; m->alias = NULL; pcmc->pvh_enabled = false; compat_props_add(m->compat_props, hw_compat_3_1, hw_compat_3_1_len); diff --git a/include/hw/boards.h b/include/hw/boards.h index 05f9f45c3d..21212f0859 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -206,6 +206,7 @@ struct MachineClass { void (*numa_auto_assign_ram)(MachineClass *mc, NodeInfo *nodes, int nb_nodes, ram_addr_t size); bool ignore_boot_device_suffixes; + bool smbus_no_migration_support; HotplugHandler *(*get_hotplug_handler)(MachineState *machine, DeviceState *dev); From patchwork Thu Feb 28 18:17:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159418 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp984508oce; Thu, 28 Feb 2019 10:29:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyaRPFGnv2umlaW+SdoNTIV2HocGXeEMZ5Pa7h7Q22hBqNwAMzHcQtPjoV1+ORSFYVw6RjJ X-Received: by 2002:a25:bacd:: with SMTP id a13mr762205ybk.175.1551378588349; Thu, 28 Feb 2019 10:29:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378588; cv=none; d=google.com; s=arc-20160816; b=truS9VMXI6dubJ9qA/+Ht3S6IG/WdY0NwBe0DPSSB2S+EcRHh8c4sP/3HhxkM69FfQ /wxXVGYM/oHKA4NW/7koh+Z02VktUHXv1REYCsUex1zwDZrLDW7/C+FgpbU4Iq5iWNJW x3o7VVnohSlv2MUGOsyZEuv83oDVIk7rRbePG119poP4LlOGUxkmD+aA3zoxj9HWoOIB u0Z/5nPg3WOJhWdYeWtFNdx0nJ2Vr4FTxRGD4kfF8EuE2jVlUqNQU+2iLsXNB+pq23Z2 zmZFzGwvF5zqA5kGLaN/Jv9MyjGn4n4oFvswdVqAtjtp5ciV6PyaIrPOggVbx+Oto6z2 /gfg== 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=vCzpvVmLyXpfuQofAv3zcqXy6IBz4pj9h28tnU3AUe8=; b=d5SOJixOeRnA/uOYf/gR09kE7P3LXuyK27CV+5Ccl1xn8KnYTW7NG0FjVvvpuojlHI 80pM2zbS27bRjN7JnSLoAoyd5SSwH1vQ/6uyMROcAtZVzYvNXlrflkC60vFK4A9ndIJQ UCWFTglR+DRhr0cEiZzRCooMw9QJNHteu6vR61INRdcKZPD/fr5E8oE5t7jHywzgPvVf CFWLwm1WLYPEszwf85hZNQj8JbEoJWvGBplU5iLdNy861Ou2kLyO6HWCvea2Z9eWjSMj IdUjV9pN+OuRpHJyF/ha6uPdvSJRv69cVYfTNMWFyBPqEld7bq9L3J9yWtoIQyFlYBz1 23ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="e/hqWnla"; 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 s22si11737376ywa.41.2019.02.28.10.29.48 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:29:48 -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="e/hqWnla"; 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]:44642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQRH-0000aq-Oi for patch@linaro.org; Thu, 28 Feb 2019 13:29:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFe-0000VP-BZ for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002Hv-JO for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:44 -0500 Received: from mail-oi1-x241.google.com ([2607:f8b0:4864:20::241]:37584) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002C2-95 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-oi1-x241.google.com with SMTP id w66so17270046oia.4 for ; Thu, 28 Feb 2019 10:17:25 -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=vCzpvVmLyXpfuQofAv3zcqXy6IBz4pj9h28tnU3AUe8=; b=e/hqWnla9W0W7pOCamG7EeP2X+6p1IA8pt9r5lnC45s7voge1XPwxqav+j6vnpgUAb tflakcl/XjIwMIXo3KrsbFZl5xUkkgudkcvg6IskwRCDK0cLgsutC4uYCqnippP45qDb yWxt+yj/7jE/pPPS9h9dXuSnczKaOkRo4PLBX/T2xY1XDlP4SldTA5K2cplUW64GM+h0 k1lRmmS6auPucXHFG16UMkU5OxwelbgV/oZLZ5iECIaSBzGqSDV1/eI0kfRLxggSc952 iVuew9SDUEdKcBnr0byhIcEnMDOvpn2gs22mNK2pT62aXwTL/4Gd2s+B6siJHs7+hcf1 77gw== 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=vCzpvVmLyXpfuQofAv3zcqXy6IBz4pj9h28tnU3AUe8=; b=h6LGgJ0jHsfyjRpPNratyAntRAAgGObaFZrD07SLdyCSQttmVyhDRZ0IEY+EZFD8ld djKJTA0slEq8CmKP0+knzKl7c3WS2eeOToPJkAH+PE53KbHaQPcQJUVL9aSr67dmDh1G ooKD5+N6DKx9bDozVP4XHct8Ghv/U9aj70V0+7sz15agcrACFkPYHUGptmP0vh1yfn3b Y7aVUpU/RljkF8GLJmOIl35NhbpUMe1U/Isot4qP9DIcxYmm1mx6CfNDtJbTuP9WYPK6 clMbcA+HA6ybqHedOYU4cxO04VEFCiDa5wnkINqzVhUtozaKADlDCt5pH1QijFOvtvWM xaZw== X-Gm-Message-State: AHQUAuZMuPov1xTxKa5T1CnXvohrESez6D5u3QSh6GkQKE5MF4Z12Zng ibNb5wIfC7pDrnTGDxY87A== X-Received: by 2002:aca:55d0:: with SMTP id j199mr699345oib.110.1551377844392; Thu, 28 Feb 2019 10:17:24 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id n25sm8805196otj.76.2019.02.28.10.17.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:19 -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 4C5781808FB; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 21941302AF5; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:02 -0600 Message-Id: <20190228181710.2477-12-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::241 Subject: [Qemu-devel] [PULL 11/19] i2c:pm_smbus: Fix pm_smbus handling of I2C block read 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The I2C block read function of pm_smbus was completely broken. It required doing some direct I2C handling because it didn't have a defined size, the OS code just reads bytes until it marks the transaction finished. This also required adjusting how the AMIBIOS workaround code worked, the I2C block mode was setting STS_HOST_BUSY during a transaction, so that bit could no longer be used to inform the host status read code to start the transaction. Create a explicit bool for that operation. Also, don't read the next byte from the device in byte-by-byte mode unless the OS is actually clearing the byte done bit. Just assuming that's what the OS is doing is a bad idea. Signed-off-by: Corey Minyard --- hw/i2c/pm_smbus.c | 86 ++++++++++++++++++++++++++++++--------- include/hw/i2c/pm_smbus.h | 6 +++ 2 files changed, 73 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 6cfb7eb1b3..81d2a425ec 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -118,19 +118,30 @@ static void smb_transaction(PMSMBus *s) } break; case PROT_I2C_BLOCK_READ: - if (read) { - int xfersize = s->smb_data0; - if (xfersize > sizeof(s->smb_data)) { - xfersize = sizeof(s->smb_data); - } - ret = smbus_read_block(bus, addr, s->smb_data1, s->smb_data, - xfersize, false, true); - goto data8; - } else { - /* The manual says the behavior is undefined, just set DEV_ERR. */ + /* According to the Linux i2c-i801 driver: + * NB: page 240 of ICH5 datasheet shows that the R/#W + * bit should be cleared here, even when reading. + * However if SPD Write Disable is set (Lynx Point and later), + * the read will fail if we don't set the R/#W bit. + * So at least Linux may or may not set the read bit here. + * So just ignore the read bit for this command. + */ + if (i2c_start_transfer(bus, addr, 0)) { goto error; } - break; + ret = i2c_send(bus, s->smb_data1); + if (ret) { + goto error; + } + if (i2c_start_transfer(bus, addr, 1)) { + goto error; + } + s->in_i2c_block_read = true; + s->smb_blkdata = i2c_recv(s->smbus); + s->op_done = false; + s->smb_stat |= STS_HOST_BUSY | STS_BYTE_DONE; + goto out; + case PROT_BLOCK_DATA: if (read) { ret = smbus_read_block(bus, addr, cmd, s->smb_data, @@ -208,6 +219,7 @@ static void smb_transaction_start(PMSMBus *s) { if (s->smb_ctl & CTL_INTREN) { smb_transaction(s); + s->start_transaction_on_status_read = false; } else { /* Do not execute immediately the command; it will be * executed when guest will read SMB_STAT register. This @@ -217,6 +229,7 @@ static void smb_transaction_start(PMSMBus *s) * checking for status. If STS_HOST_BUSY doesn't get * set, it gets stuck. */ s->smb_stat |= STS_HOST_BUSY; + s->start_transaction_on_status_read = true; } } @@ -226,19 +239,38 @@ smb_irq_value(PMSMBus *s) return ((s->smb_stat & ~STS_HOST_BUSY) != 0) && (s->smb_ctl & CTL_INTREN); } +static bool +smb_byte_by_byte(PMSMBus *s) +{ + if (s->op_done) { + return false; + } + if (s->in_i2c_block_read) { + return true; + } + return !(s->smb_auxctl & AUX_BLK); +} + static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, unsigned width) { PMSMBus *s = opaque; + uint8_t clear_byte_done; SMBUS_DPRINTF("SMB writeb port=0x%04" HWADDR_PRIx " val=0x%02" PRIx64 "\n", addr, val); switch(addr) { case SMBHSTSTS: + clear_byte_done = s->smb_stat & val & STS_BYTE_DONE; s->smb_stat &= ~(val & ~STS_HOST_BUSY); - if (!s->op_done && !(s->smb_auxctl & AUX_BLK)) { + if (clear_byte_done && smb_byte_by_byte(s)) { uint8_t read = s->smb_addr & 0x01; + if (s->in_i2c_block_read) { + /* See comment below PROT_I2C_BLOCK_READ above. */ + read = 1; + } + s->smb_index++; if (s->smb_index >= PM_SMBUS_MAX_MSG_SIZE) { s->smb_index = 0; @@ -268,12 +300,23 @@ static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, s->smb_stat |= STS_BYTE_DONE; } else if (s->smb_ctl & CTL_LAST_BYTE) { s->op_done = true; - s->smb_blkdata = s->smb_data[s->smb_index]; + if (s->in_i2c_block_read) { + s->in_i2c_block_read = false; + s->smb_blkdata = i2c_recv(s->smbus); + i2c_nack(s->smbus); + i2c_end_transfer(s->smbus); + } else { + s->smb_blkdata = s->smb_data[s->smb_index]; + } s->smb_index = 0; s->smb_stat |= STS_INTR; s->smb_stat &= ~STS_HOST_BUSY; } else { - s->smb_blkdata = s->smb_data[s->smb_index]; + if (s->in_i2c_block_read) { + s->smb_blkdata = i2c_recv(s->smbus); + } else { + s->smb_blkdata = s->smb_data[s->smb_index]; + } s->smb_stat |= STS_BYTE_DONE; } } @@ -284,6 +327,10 @@ static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, if (!s->op_done) { s->smb_index = 0; s->op_done = true; + if (s->in_i2c_block_read) { + s->in_i2c_block_read = false; + i2c_end_transfer(s->smbus); + } } smb_transaction_start(s); } @@ -337,8 +384,9 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) switch(addr) { case SMBHSTSTS: val = s->smb_stat; - if (s->smb_stat & STS_HOST_BUSY) { + if (s->start_transaction_on_status_read) { /* execute command now */ + s->start_transaction_on_status_read = false; s->smb_stat &= ~STS_HOST_BUSY; smb_transaction(s); } @@ -359,10 +407,10 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) val = s->smb_data1; break; case SMBBLKDAT: - if (s->smb_index >= PM_SMBUS_MAX_MSG_SIZE) { - s->smb_index = 0; - } - if (s->smb_auxctl & AUX_BLK) { + if (s->smb_auxctl & AUX_BLK && !s->in_i2c_block_read) { + if (s->smb_index >= PM_SMBUS_MAX_MSG_SIZE) { + s->smb_index = 0; + } val = s->smb_data[s->smb_index++]; if (!s->op_done && s->smb_index == s->smb_data0) { s->op_done = true; diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h index 6dd5b7040b..7bcca97672 100644 --- a/include/hw/i2c/pm_smbus.h +++ b/include/hw/i2c/pm_smbus.h @@ -33,6 +33,12 @@ typedef struct PMSMBus { /* Set on block transfers after the last byte has been read, so the INTR bit can be set at the right time. */ bool op_done; + + /* Set during an I2C block read, so we know how to handle data. */ + bool in_i2c_block_read; + + /* Used to work around a bug in AMIBIOS, see smb_transaction_start() */ + bool start_transaction_on_status_read; } PMSMBus; void pm_smbus_init(DeviceState *parent, PMSMBus *smb, bool force_aux_blk); From patchwork Thu Feb 28 18:17:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159420 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp986900oce; Thu, 28 Feb 2019 10:31:56 -0800 (PST) X-Google-Smtp-Source: APXvYqweDOhTxB7rIt5viwbd/L9V2UdHB6kROquz6XMdIuaGqg8eIl4zjYvVlz+qXmjfGhIckGFa X-Received: by 2002:a81:f102:: with SMTP id h2mr316550ywm.272.1551378716179; Thu, 28 Feb 2019 10:31:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378716; cv=none; d=google.com; s=arc-20160816; b=JoqVTyBKs0JraSNFBJPfAkd3Pmw+zAbwVFFpL2odNwuW6H5qIx1w+sBMK5nkQUlTuC sjbVpIYSz2CeVV1KrMn4f8Qgmj1UiII64es6kCHB4bdEvN20pgPgC2mnxPtGMtumGLbH mujVS8crpgqZE1E86VDWw6fStYOnmeJhrkk/7WkIsRZjm0mN2kze1iYao4Use24mwbfY nACsvV9zv1587C4mz+AfGfTlPcQFDA/608PZrjiQOY0orpI5nqtbEydfugFVglxLEXn7 S8Ipt7WfQcZVQvW0QHSceKpylly5ubgH2igMDn4rOH/wxA+PVOxW8MqOcFRfFFr3NooX Zymw== 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=98XV8+tO+xHYRvb4UcZhVimQe7LR4Du0EPxu1yJbd+M=; b=b7gqbpkJUjIiM2Cv5sh79E1uy/t9wumsupUg89GUewyat6nYQ6x/7R1cmus+FMTxed uhUAbez1JET2POp2qhcmljTGO+U9X7n/yV0mors4FXszZml9AWFZDNovMOFiLuW8HhYk et+/CPnUjzNTJj3SMsC0I0T7NM839syAJQzyLlr1D93XgA62i4y6wp1olCdxq3roodoZ 48uzfLL9vufaSEQuO6ED5fLJXap80d+9gseQcFvhomFjJ07z+/iJxwXcqGopscb9Ccch kOPPHLvWNtC2Di3NbsA5M6a7Bn1avihPEvQUI+irJ9zjiZkKDdSt0w4Za9ZTt2eQJkZA uS3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dtV7byQ0; 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 189si10511437ywz.463.2019.02.28.10.31.56 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:31:56 -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=dtV7byQ0; 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]:44694 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQTL-0002Gx-ML for patch@linaro.org; Thu, 28 Feb 2019 13:31:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46735) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFm-0000ZF-5g 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 1gzQFY-0002JW-7S for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:53 -0500 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:43867) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002CH-TM for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:40 -0500 Received: by mail-oi1-x231.google.com with SMTP id i8so17259350oib.10 for ; Thu, 28 Feb 2019 10:17:25 -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=98XV8+tO+xHYRvb4UcZhVimQe7LR4Du0EPxu1yJbd+M=; b=dtV7byQ0s2Gu6uW/q3BOZ9HoUIUzY/jVcoATyS4Z30USucQ49M+lslfCPjCSFWaa3y WkYdQZ/FrijldPmIUa5/77NI4v5aQaq0jmZk9F/W6/2+V10NO/0oAOdlyqbBWJaW4cBU hA7iW0mmo9dI8BzWVVzlZuMVOkcz0mgsfVkM8j+RhMqRUB7HpngzxUCgI5WEXIwfDxwr PEJUmXicRyxizNuYiA5JGDwzK3T5mZq0Z8/Y3seRpek9m2IEFRGv7xB/RJfaUyTBK3OF bM+D9re3dEsTamd+LoDKdvy7isD0tI0pWAZp4YC52NVOo6pHjcltpxXFByIJkJJGo+3X QJIA== 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=98XV8+tO+xHYRvb4UcZhVimQe7LR4Du0EPxu1yJbd+M=; b=gdoKWALe19d+2Ez7BznED4OCgznjBEwUaY8CFaGN09KYjYi0qiXS/aR2aN5KP6UBCo vdknRs7XGZn6TN8uh56py7YW/iQ3PoeSxjfkrFbO25vv/OnfwhBpbotgaqb+C8LFeijM hUmN7jhf+yxT2+aodVj1kps4FRB7kMR+1/N1te29hXHE2J6mJKtB8YOOXrbx9V9gHOdx Tjcc4h7bH4J0Tf6NvRZe9IjwJp60IjCV+RqVB+y3nlTmnfML3ZCIO9IZl8MMjhWWQjCL hPryBRWobgjQHdNKUBxGOZPViNqdPnOarnJqaqF0Or1iTb239C8sCAFxz07Z9h0fI9yO Krmw== X-Gm-Message-State: AHQUAuZ6m6xcR23VVuQ/0Re5bVbbUFmXg0AKJJApFWwHzT4hgo2ACLIg Ey3yqEvO6wmagDB8vMrG6k6lV5w= X-Received: by 2002:aca:f2c4:: with SMTP id q187mr681954oih.168.1551377844915; Thu, 28 Feb 2019 10:17:24 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id r184sm7246604oif.31.2019.02.28.10.17.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 10:17:19 -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 5EE111808FC; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 445193028D0; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:03 -0600 Message-Id: <20190228181710.2477-13-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::231 Subject: [Qemu-devel] [PULL 12/19] migration: Add a VMSTATE_BOOL_TEST() macro 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard This will be needed by coming I2C changes. Signed-off-by: Corey Minyard Reviewed-by: Dr. David Alan Gilbert --- include/migration/vmstate.h | 3 +++ 1 file changed, 3 insertions(+) -- 2.17.1 diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h index 067b126cf1..a668ec75b8 100644 --- a/include/migration/vmstate.h +++ b/include/migration/vmstate.h @@ -851,6 +851,9 @@ extern const VMStateInfo vmstate_info_qtailq; #define VMSTATE_INT32_POSITIVE_LE(_f, _s) \ VMSTATE_SINGLE(_f, _s, 0, vmstate_info_int32_le, int32_t) +#define VMSTATE_BOOL_TEST(_f, _s, _t) \ + VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_bool, bool) + #define VMSTATE_INT8_TEST(_f, _s, _t) \ VMSTATE_SINGLE_TEST(_f, _s, _t, 0, vmstate_info_int8, int8_t) From patchwork Thu Feb 28 18:17:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159413 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp980345oce; Thu, 28 Feb 2019 10:25:02 -0800 (PST) X-Google-Smtp-Source: APXvYqy4dWKKSh5tvaSCwclltq7K+E53D7O6TYocqx+q6kCRAYQ6rssNrwTRw5/+0KUkRII7t35D X-Received: by 2002:a0d:c544:: with SMTP id h65mr266214ywd.35.1551378302601; Thu, 28 Feb 2019 10:25:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378302; cv=none; d=google.com; s=arc-20160816; b=AEOm9op/bU/mRrRWFIQGyA/ZbBnMm2i0vMUkhE52EXcH7xuQeoIcESGzxc6S5mAzV8 VXO1XEQ1rjf417bQQuzCrduzP1BSr7Bdd/guT1Sp3Pv+U6cci7Fm+BscC88U2BzCB22M GPNzmIfVHcb5MEyX6xxBVBMvkeFuHzb9X6bgRYRA3g0xUAvW8niA02arXBqjrt72fHFk dDq5eFVzITzhEm9stbMkkqmf3REM/GPctvDdzXdIawQIEX5FqL3bl1m5GH5fXNxIJhME w86FmZquRwWauYtgWNH46K4+7P7cXzG6l8LUPZFLWjQlzewPnkXpEyopG9BE1/7DI9jH 8MYg== 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=3UFlQ3shD3IizolfVnuZXQqGFynAqm90AKBUEoy7fD0=; b=06HlMODaZ2pUyW4I2v5VUY/5FDPPHrVDhvOw9BLxVo6TOxfB5/xLC9Q3wvkEfbs/NY ddFIFuOmeIpDvOz2DR5kfRkJW6yEpqnEwbmRZbyrXxDwA4aRu0EYqFCUeP7GcoyoQKFi GwfgPWI428QCYkpwTmhdGk0+OFsV3ZJI0sOCzlpygfSlfINP65OWtv31214tyqpzlkU9 FOjxagugnqQBs6AslEKuNHymSkOq3qtJsLHGvCfmCc1uViw+6v0n+JBfri1W/6cKGrQY q4FkJe7qoQACloPau9DQpdakJzbmUZ/1NOSiBp6jwQ9F0+3oeYRgqB79/ijKM4Zbikd2 iThw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=bqBhCTeJ; 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 f132si11496937ywc.198.2019.02.28.10.25.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:25:02 -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=bqBhCTeJ; 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]:44578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQMg-0005c1-2c for patch@linaro.org; Thu, 28 Feb 2019 13:25:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFo-0000aG-Ic for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFc-0002Mg-Ts for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:56 -0500 Received: from mail-ot1-x32c.google.com ([2607:f8b0:4864:20::32c]:33637) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFY-0002DA-CO for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:42 -0500 Received: by mail-ot1-x32c.google.com with SMTP id q24so18585007otk.0 for ; Thu, 28 Feb 2019 10:17:28 -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=3UFlQ3shD3IizolfVnuZXQqGFynAqm90AKBUEoy7fD0=; b=bqBhCTeJN/Q0wiLB7dyPHL6HCEVcVI98YoB7ozyffW3psFEhkXFKun4G417PCU1Z0F h0Pyz8ypZqWrs64bK6wbueAW7PhrGTlq+ApAcEjV1x+22rFCDu5zuOqjVllnp1Zc35WH SQBnLOCzjXriipX1hk8fqrKAnJMob3HGFfUAErzDJRRqr0SEC/CbcDnSJMfkE1MSGztC 3K9OkGi61wh+0802xBkUfjg8VnHu0PckYB0u26rXr2DbjFZHhYKcLcYIsx5OKN4mo+rK a6XXQXlfDx+JcAVWimSgymiqwU4PZvpWgmdXlYJKccjgIiNKCHyR0gCXYyoefiG8eny1 Edwg== 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=3UFlQ3shD3IizolfVnuZXQqGFynAqm90AKBUEoy7fD0=; b=jjO9qSM+OJosFxr3+8jg4qb1vZUT9J2eOATsUVg/eij0AQ+cps5EPZfYLVgnabn+8c GkxC5OAtL7YEY9ZcHVfjTHeBuWrjXMqF6+7NuV+U1F1aOCTSf58ZtecGL+Y5U7kOaw6o zviAkOs9UPsy6QTSEtclH7SjHavCKqcT+OmUxJy9xy9C1yPniqQzsfA7VthD6PlhF38O st1UCecNTI7Q1vHz6xQU19o2aWDL2FBLlNxKwWNeExxamYPb+ET2m4v4e0BSB4D+59yI ye3dJvUOqvjR7NDimxwbFa8UU1AUKi4rQ5a/cDfzkFotzO2FJvO1efgXMuaoZ8m3PrcN QKfQ== X-Gm-Message-State: APjAAAXPo3IOYBUn19tV5V9n5e4hCDO0V7P3GytN9VK+cq+q2loWyHnz VR8Ct7ImRzEIrsmZ2MNhvg== X-Received: by 2002:a9d:5509:: with SMTP id l9mr649608oth.200.1551377847281; Thu, 28 Feb 2019 10:17:27 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id g80sm7691137otg.38.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 6845E1808FD; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 573CD3028CF; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:04 -0600 Message-Id: <20190228181710.2477-14-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::32c Subject: [Qemu-devel] [PULL 13/19] i2c:pm_smbus: Fix state transfer 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 Transfer the state information for the SMBus registers and internal data so it will work on a VM transfer. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- hw/acpi/piix4.c | 7 +++++++ hw/i2c/pm_smbus.c | 31 +++++++++++++++++++++++++++++++ hw/i2c/smbus_ich9.c | 10 +++++++++- include/hw/i2c/pm_smbus.h | 9 +++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index df8c0db909..8fd25a5926 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -302,6 +302,11 @@ static const VMStateDescription vmstate_cpuhp_state = { } }; +static bool piix4_vmstate_need_smbus(void *opaque, int version_id) +{ + return pm_smbus_vmstate_needed(); +} + /* qemu-kvm 1.2 uses version 3 but advertised as 2 * To support incoming qemu-kvm 1.2 migration, change version_id * and minimum_version_id to 2 below (which breaks migration from @@ -321,6 +326,8 @@ static const VMStateDescription vmstate_acpi = { VMSTATE_UINT16(ar.pm1.evt.en, PIIX4PMState), VMSTATE_UINT16(ar.pm1.cnt.cnt, PIIX4PMState), VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_apm, APMState), + VMSTATE_STRUCT_TEST(smb, PIIX4PMState, piix4_vmstate_need_smbus, 3, + pmsmb_vmstate, PMSMBus), VMSTATE_TIMER_PTR(ar.tmr.timer, PIIX4PMState), VMSTATE_INT64(ar.tmr.overflow_time, PIIX4PMState), VMSTATE_STRUCT(ar.gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE), diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 81d2a425ec..e48544f909 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -19,6 +19,7 @@ */ #include "qemu/osdep.h" #include "hw/hw.h" +#include "hw/boards.h" #include "hw/i2c/pm_smbus.h" #include "hw/i2c/smbus_master.h" @@ -453,6 +454,36 @@ static const MemoryRegionOps pm_smbus_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; +bool pm_smbus_vmstate_needed(void) +{ + MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + + return !mc->smbus_no_migration_support; +} + +const VMStateDescription pmsmb_vmstate = { + .name = "pmsmb", + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_UINT8(smb_stat, PMSMBus), + VMSTATE_UINT8(smb_ctl, PMSMBus), + VMSTATE_UINT8(smb_cmd, PMSMBus), + VMSTATE_UINT8(smb_addr, PMSMBus), + VMSTATE_UINT8(smb_data0, PMSMBus), + VMSTATE_UINT8(smb_data1, PMSMBus), + VMSTATE_UINT32(smb_index, PMSMBus), + VMSTATE_UINT8_ARRAY(smb_data, PMSMBus, PM_SMBUS_MAX_MSG_SIZE), + VMSTATE_UINT8(smb_auxctl, PMSMBus), + VMSTATE_UINT8(smb_blkdata, PMSMBus), + VMSTATE_BOOL(i2c_enable, PMSMBus), + VMSTATE_BOOL(op_done, PMSMBus), + VMSTATE_BOOL(in_i2c_block_read, PMSMBus), + VMSTATE_BOOL(start_transaction_on_status_read, PMSMBus), + VMSTATE_END_OF_LIST() + } +}; + void pm_smbus_init(DeviceState *parent, PMSMBus *smb, bool force_aux_blk) { smb->op_done = true; diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c index e6d8d28194..7b24be8256 100644 --- a/hw/i2c/smbus_ich9.c +++ b/hw/i2c/smbus_ich9.c @@ -43,12 +43,20 @@ typedef struct ICH9SMBState { PMSMBus smb; } ICH9SMBState; +static bool ich9_vmstate_need_smbus(void *opaque, int version_id) +{ + return pm_smbus_vmstate_needed(); +} + static const VMStateDescription vmstate_ich9_smbus = { .name = "ich9_smb", .version_id = 1, .minimum_version_id = 1, .fields = (VMStateField[]) { - VMSTATE_PCI_DEVICE(dev, struct ICH9SMBState), + VMSTATE_PCI_DEVICE(dev, ICH9SMBState), + VMSTATE_BOOL_TEST(irq_enabled, ICH9SMBState, ich9_vmstate_need_smbus), + VMSTATE_STRUCT_TEST(smb, ICH9SMBState, ich9_vmstate_need_smbus, 1, + pmsmb_vmstate, PMSMBus), VMSTATE_END_OF_LIST() } }; diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h index 7bcca97672..fb55c44444 100644 --- a/include/hw/i2c/pm_smbus.h +++ b/include/hw/i2c/pm_smbus.h @@ -43,4 +43,13 @@ typedef struct PMSMBus { void pm_smbus_init(DeviceState *parent, PMSMBus *smb, bool force_aux_blk); +/* + * For backwards compatibility on migration, older versions don't have + * working migration for pm_smbus, this lets us ignore the migrations + * for older machine versions. + */ +bool pm_smbus_vmstate_needed(void); + +extern const VMStateDescription pmsmb_vmstate; + #endif /* PM_SMBUS_H */ 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 From patchwork Thu Feb 28 18:17:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159412 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp979911oce; Thu, 28 Feb 2019 10:24:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzyySOdrYKNSIlQOEZTjZttUBI/Eqom8ASCaE0UYupNkrkhQPCDVScLxRsBSmn2hmxQwf0p X-Received: by 2002:a25:b96:: with SMTP id 144mr740914ybl.31.1551378274634; Thu, 28 Feb 2019 10:24:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378274; cv=none; d=google.com; s=arc-20160816; b=OSs5O7QEL9sLiIfF4sV3m0VdZr03PTqiVGCEKQbCanZW/xma3sgrYJrL9+Jun3rdAe 9IP5NSZ2knwuB+hi/db+jH08ozfA1cqtq5yNRa6Psp10m8AC0qWcSVmZr2x38aG/lVVj 53Fu3PbJND6vGHR7jWE58cg2DyqXWLiLYiVMUHUf0SvbURRh9lco/dS+oIghscqFvZ+4 marQ0RTDyFEWuoZetvm12q6i8Q/gRd3sg4UQc1eTrKUBOiNdCgOy3SPG2BihWWLTcXRj Ef2N6aXd+w3ciBy93AKREo5sN4IZ5i4HdYyCej01xO0lbBdgMNimcVIiQ1DG1aAFIgYa +O8Q== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=phVcIZ91pPZo7YJfCc5Psb+Hz4cvw3ogTugWINPoDh8=; b=ug4FxIjuBiLHPZTdxn0TpkRSkGSQzZ+golZatXNgpsPDVBavcg0WTtvPbB2PKNDjXB mwOuvhzXk9MF+EhM3B4RYS3Gn5deQdTgVU+L4blQWBD4BvreDwWCaTj8ws5AXDU9B1y6 Z/SBJnulTSccSgDuEmDIFsCq7FK9ExwJGqiANUa1hHb7kxU0quo4QJ041jv85LEwCgpz tHohyAurWB5t2AoOuYnUU2UTJP+Lus9vW2NHAFXK08T86/qy9Ur+J+AJHnukURxjAlj4 kgq0G4DGx5wOLRTQjnLM9uV59qqLc2rU6SwAa0PSbT5t+qXMFYIoK3ZiTjjLNs/ClQem fUTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=I7CSSJF+; 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 g16si11373632ybk.427.2019.02.28.10.24.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:24:34 -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=I7CSSJF+; 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]:44564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQME-0004S4-6I for patch@linaro.org; Thu, 28 Feb 2019 13:24:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFe-0000VK-BM for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002I8-N8 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:42 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:46741) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002DP-E3 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x341.google.com with SMTP id c18so18489701otl.13 for ; Thu, 28 Feb 2019 10:17:29 -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 :mime-version:content-transfer-encoding; bh=phVcIZ91pPZo7YJfCc5Psb+Hz4cvw3ogTugWINPoDh8=; b=I7CSSJF+P2yXXOO2uudtf+4mzFOXaprMGtUInhKW96IZkCxtO+5qRXvjtFDnbzAKmd bY7HD1z8rnRuZ/m630jCgbhvpjRpxleLD/++Il9BE2QdtiR07oEKtn9vRODUWo5Ha87l lWxu8dejdqMdpT6e1Veut8IJ2lDCsZwm8HaQvq/2K7kr1LdoYoTrtXIb5W2HrOQbg258 5CNTyHwPp+3liV15+qd0z5MFJ/aJnMPbmliT9ec7koU1hG4fq+dj4CGUdKuwqr6Obqun ZhPK/LUm+hcI62myLKmqd4JqJ8rid8GrGhLNZofFqxLkyrAw1HK8kT3IF9pQQr+5iOfp MFMA== 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:mime-version:content-transfer-encoding; bh=phVcIZ91pPZo7YJfCc5Psb+Hz4cvw3ogTugWINPoDh8=; b=joi7hwxqKX5OsthBry3+70E27S12D82TZeB18YdS6WyvYOhhPWRVYrlK8ZyhFYxjKI hFVm4L2rDN5ucZQ8BdtYFlA7Yv78apm/T2rqHrhmi4C2w5avGPuzM68XeYz1pxx1ifcc SQlKwFcKrzVjzGZEZTn+hWC7hZVEMYtT2nbTcyFpngrhc4Z0XJ3+9CnxzFf61icjsy/u xtrPOANpxcj9qurMaqDnDsgIMP1k6fne6raFHMtcsY0NQ9L/bXSSITNbtwYL1vEexlXV nnfSmKh27/ozxGKlIXfiRk+mpozTccArXfyTVALULeIzH5AANLdIHPTJzXgQbWSE6YA4 Ovhw== X-Gm-Message-State: APjAAAXWaF0MqUXrdWBjzDiY0rSaYslkYQ3L9UaMJuwdzP0a2lR0IluF ZFslV0mlFiJzXbMCNhliSg== X-Received: by 2002:a9d:2944:: with SMTP id d62mr642525otb.193.1551377848407; Thu, 28 Feb 2019 10:17:28 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id 3sm5363623ots.75.2019.02.28.10.17.18 (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 (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id ACD9A1808FF; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 721B63028CF; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:06 -0600 Message-Id: <20190228181710.2477-16-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> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::341 Subject: [Qemu-devel] [PULL 15/19] i2c:smbus_eeprom: Add normal type name and cast to smbus_eeprom.c 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Create a type name and a cast macro and use those through the code. Signed-off-by: Corey Minyard Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- hw/i2c/smbus_eeprom.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 2816e35bcc..76f0d4aab0 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -32,6 +32,11 @@ //#define DEBUG +#define TYPE_SMBUS_EEPROM "smbus-eeprom" + +#define SMBUS_EEPROM(obj) \ + OBJECT_CHECK(SMBusEEPROMDevice, (obj), TYPE_SMBUS_EEPROM) + typedef struct SMBusEEPROMDevice { SMBusDevice smbusdev; void *data; @@ -40,7 +45,7 @@ typedef struct SMBusEEPROMDevice { static uint8_t eeprom_receive_byte(SMBusDevice *dev) { - SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; + SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); uint8_t *data = eeprom->data; uint8_t val = data[eeprom->offset++]; @@ -53,7 +58,7 @@ static uint8_t eeprom_receive_byte(SMBusDevice *dev) static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) { - SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *) dev; + SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); uint8_t *data = eeprom->data; #ifdef DEBUG @@ -75,7 +80,7 @@ static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) static void smbus_eeprom_realize(DeviceState *dev, Error **errp) { - SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev; + SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); eeprom->offset = 0; } @@ -99,7 +104,7 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) } static const TypeInfo smbus_eeprom_info = { - .name = "smbus-eeprom", + .name = TYPE_SMBUS_EEPROM, .parent = TYPE_SMBUS_DEVICE, .instance_size = sizeof(SMBusEEPROMDevice), .class_init = smbus_eeprom_class_initfn, @@ -116,7 +121,7 @@ void smbus_eeprom_init_one(I2CBus *smbus, uint8_t address, uint8_t *eeprom_buf) { DeviceState *dev; - dev = qdev_create((BusState *) smbus, "smbus-eeprom"); + dev = qdev_create((BusState *) smbus, TYPE_SMBUS_EEPROM); qdev_prop_set_uint8(dev, "address", address); qdev_prop_set_ptr(dev, "data", eeprom_buf); qdev_init_nofail(dev); From patchwork Thu Feb 28 18:17:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159411 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp979860oce; Thu, 28 Feb 2019 10:24:32 -0800 (PST) X-Google-Smtp-Source: APXvYqyMiMrWn5OO44YLxSFdt90rCodp1gUEPa1bGn4FOo3VD9l4gFo8j9gYixML9PugTXd95mZ+ X-Received: by 2002:a25:8683:: with SMTP id z3mr749202ybk.216.1551378272371; Thu, 28 Feb 2019 10:24:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378272; cv=none; d=google.com; s=arc-20160816; b=GwoBk8zOSpV7IBSyW7cp0b5GxUlmrrafCgryGtFY4qG/lirgQ5RIe4YkD6XhqKejeK 6bY9IkzZhS6e1zNWcEYwDASFLS/V8f+r2lPYaZHSMt+2qK9WM9LWuUUoc1cLhZTd/YdU jGtuzu3pWwzQzIxCeSLeAVEiDuzIY8Pi9Oj22q1fRoIpiYLV4EP8wc/MBbiK9EbeA5CR hy7TUq8UNd4lMGz0OH/FZEKXF6NbVGlDhY3EcnHriy2F4ypAEDVEyyXPYPeZiJhU6Z5K GNKh7abzJ/5KKz28ICVJBdImYJLmQRPZQa3eguvcmNi5y7GGffi3CKmBuZlRsP2Hjr89 bgPA== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=6NzHN8+bT4MvQ1gFeAYgeaVdN5GDDM/VncB+6EIJ1Xw=; b=gZ+l5rdk1ZjvYW7NgtHybh5P5cH3G9QvccdY5V/b2pvhDx+itVkCPFc1RSZIQ+KIzb J91rYdUPa/uyCwpiqJhdMgcryZwy8d1QfU8e/glNvOENw3m8YkXVvrEoJZsfzZuMwCHJ BOFNLuNPcNN6WW55ZZSBN9dl+MsdHmiDUftC8OjlDqFHpHqmPq56TsQ211w460DzxxSE XM6P8S1wij+MXZDXw6kn4YMrPuFK6rX7OMXgB4TnaFaXwmD4KqII0VIgc+PBoxOCJQqm nbfvXG5Xy+Ze2y3DVqlVLQe5WwCgvv9EXWXRaVCRnOYN+NsaUnXemZmTfSAA0FDZZw+w /x2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="oZQHgIa/"; 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 r2si10458296ybg.48.2019.02.28.10.24.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:24:32 -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="oZQHgIa/"; 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]:44562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQMB-0004PL-Q6 for patch@linaro.org; Thu, 28 Feb 2019 13:24:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFm-0000ZG-5u for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFY-0002JI-1d for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:53 -0500 Received: from mail-ot1-x331.google.com ([2607:f8b0:4864:20::331]:33980) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002CX-Nz for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x331.google.com with SMTP id 98so18591442oty.1 for ; Thu, 28 Feb 2019 10:17:26 -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 :mime-version:content-transfer-encoding; bh=6NzHN8+bT4MvQ1gFeAYgeaVdN5GDDM/VncB+6EIJ1Xw=; b=oZQHgIa/Y9fE76eVpekate921BjvL0BT1Ht4+SKMrH1r/wvDldkRSRaB/kpN8VlKOJ aPuNg3hs1DNnaZgtV5rm2oF1BicAe3V+T8k8SF7GrecVGp8ronGHbq5cQaLdZVO58FOO n/tsBcjcRW4vfOA6uuiuIF5jt68vDMGdhVgljzyZ5SW0ZLMsedYp9ea2n2uE7LnGdHD1 EwvwLvujkAc2l4d6MI3QlWowAJG+fDJSR79w/JqCGEke54xhOyYufJggbAMtVWt8xpCm 1wVBFNKijizAoV1lNyaNkTJSlRNCVhaI3r1rfvmhiSgNfME0nGW5cUnoWUG55s7DoLHK XGhQ== 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:mime-version:content-transfer-encoding; bh=6NzHN8+bT4MvQ1gFeAYgeaVdN5GDDM/VncB+6EIJ1Xw=; b=GoVC7yFwQau8R7IPoUJ6MjqlGaAUxWgPXokVJJz8cxMYKyyyGC+45DJsI1ExYAvBxn CWJdebybi9EzaKC/dbbC8//Iq4g9Rj4QoMslSU+xC2WyV0C2JGJGXlcwJwd84dwUvmXa SWLu7bLsmkGhU0Lg9HZ01K2FEUMb6XtVRTYTjPb6b1xzzAbR8GIAnDR2Cxi8HBJs1bAJ n7Xr8D2jPCseyeoK6TnQhcWGaLokwzgwmbA34MtY69e0dxKVdez/oRl9g5UQxjkcC6S9 yAniOTP6P+3/CmdtVFvDBkF3yEAHza6hZALRbkmbI+Rdkr86ZATNXAZ5UHF0KlBuifLY gmdQ== X-Gm-Message-State: APjAAAXXmpR89lKK5x0jFuka69FwHl0m5VX/wwBpeeaX93VOGbjmr9nl fQnjH//bsoBEMF4UsAG9aA== X-Received: by 2002:a9d:5e07:: with SMTP id d7mr644898oti.315.1551377846104; 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 c131sm8064759oif.3.2019.02.28.10.17.18 (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 B5F13180900; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id A52683028D0; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:07 -0600 Message-Id: <20190228181710.2477-17-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> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::331 Subject: [Qemu-devel] [PULL 16/19] i2c:smbus_eeprom: Add a size constant for the smbus_eeprom size 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard It was hard-coded to 256 in a number of places, create a constant for that. Signed-off-by: Corey Minyard Reviewed-by: Philippe Mathieu-Daudé --- hw/i2c/smbus_eeprom.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 76f0d4aab0..3fbbffb4de 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -37,6 +37,8 @@ #define SMBUS_EEPROM(obj) \ OBJECT_CHECK(SMBusEEPROMDevice, (obj), TYPE_SMBUS_EEPROM) +#define SMBUS_EEPROM_SIZE 256 + typedef struct SMBusEEPROMDevice { SMBusDevice smbusdev; void *data; @@ -72,7 +74,7 @@ static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) for (; len > 0; len--) { data[eeprom->offset] = *buf++; - eeprom->offset = (eeprom->offset + 1) % 256; + eeprom->offset = (eeprom->offset + 1) % SMBUS_EEPROM_SIZE; } return 0; @@ -131,13 +133,15 @@ void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom, const uint8_t *eeprom_spd, int eeprom_spd_size) { int i; - uint8_t *eeprom_buf = g_malloc0(8 * 256); /* XXX: make this persistent */ + /* XXX: make this persistent */ + uint8_t *eeprom_buf = g_malloc0(8 * SMBUS_EEPROM_SIZE); if (eeprom_spd_size > 0) { memcpy(eeprom_buf, eeprom_spd, eeprom_spd_size); } for (i = 0; i < nb_eeprom; i++) { - smbus_eeprom_init_one(smbus, 0x50 + i, eeprom_buf + (i * 256)); + smbus_eeprom_init_one(smbus, 0x50 + i, + eeprom_buf + (i * SMBUS_EEPROM_SIZE)); } } From patchwork Thu Feb 28 18:17:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159406 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp974589oce; Thu, 28 Feb 2019 10:18:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzEKJVjZJ9D6sK/o++UHtw0H8QcujpuchSlO9HAuSR2az4tc5NKHZT+N9Yx3VwmnAYdHL5N X-Received: by 2002:a25:5454:: with SMTP id i81mr741794ybb.142.1551377914725; Thu, 28 Feb 2019 10:18:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551377914; cv=none; d=google.com; s=arc-20160816; b=Gs0W0xaOwPVzNu2bBqQz0IYQz1GH3UwucXFRDzXOfiqU8Daat/Vdn6SMNDLfanz2Kn 4GktN383hLTIDdHvf11fzOnqPPrxytPYfQ2ADb9zUMVBrwuShxN1yb8v1CXywM8JFpWL /d5jb5KUqWY3recddPk1hWPdNdLCgcjwj91Aib3WWc28S3nGtHcKdDzKn1+Gl5j1KF65 JWVbF37VL7i1+XWum5kVwW9cQcVGyMPU/Hq+SC4N1eoKmM9f40mUyYB7/Wi2ZXiKAK1g JVaLANwAgV5Wxx49CYx9zam/Rs/o/cxiQmbVvVNgUevhKAIXgia1/tBSXSkTOtqzoyFs LFLg== 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=JYjjFU7iSnj9ynLadPIf8UYzDHe2jrZNf2Z7T2XbxME=; b=kzd8udXokOgK/BwLT+XVmIFRrufMGg2307afSeP0vTl+LJNLmD9BlDVIjTNf7smK/j L9Ut23O42Vuoo6SbndnHO7Od0tZCoF/r4oS/a7v3ggEtkrsPWCTW5kdpVx/zHsGh/Mou RXxVtDCpzFdXbDZnmyxCqd7PMZOsLKjGhNo4UleeeGNsjQHIkBwWmPHnVrDUfxg/7F4H I7kjcPhdsZ6po155V32zmrbuxQSsuH4sV7e0flW9qmXddiaWm+RQ9ix2w1d//ZJ/3srt 7JBMzGpe7zNYWkPiXbM1/jKMyrRrI6XyTUnCTAhYrIissOQFeIVdrw+0hqHfJzNmmJl7 yx/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=S8W+ciCX; 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 129si10714462ybm.204.2019.02.28.10.18.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:18:34 -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=S8W+ciCX; 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]:44493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQGQ-0000dI-6H for patch@linaro.org; Thu, 28 Feb 2019 13:18:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFh-0000Wp-2x for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002IO-Rw for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:49 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:33922) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002Di-IR for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x344.google.com with SMTP id 98so18591592oty.1 for ; Thu, 28 Feb 2019 10:17:30 -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=JYjjFU7iSnj9ynLadPIf8UYzDHe2jrZNf2Z7T2XbxME=; b=S8W+ciCXcxfYgHZqhfY8v1m9/pGJPAehp2pUuajbVN+Kw6MAHd7ioHdP+BZBjMB3vK ZDWGk9+C4H0d6lvKDkXTTNwheX7MFD2iXZLSB0qGQwXk6jmqMEj6RucP0uyf5pSprIB2 Sb6xhwcYLz7ecj/klyxrjyXfEwFu+rPvYCInjqSD1XA3Ds7rnT1Da9UJ6IcRyMPa0Li1 UvhA28XWagoEyccIT89l8Cq483COM6Wx/VQQMIs9gd0WJ7D4jxUC4p5PPgJYDYZsCdGB HOcWgD1LNnHIYrrxpjRoVKYc0GZVlrxYLxAOeA+jnMYlYPDtKXPPv3F+j8JrNy6H5hye ry2w== 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=JYjjFU7iSnj9ynLadPIf8UYzDHe2jrZNf2Z7T2XbxME=; b=F0KgkVvYsdSWfwiKYg8gjl37zYwrYVkJG6aseddtl37DvsXfaKuaasZ1SpD9KilNAz UcSX8QvEXuBjBT5ESkv29urt9Wl+PRsrOWULm4I04Nm2jE19Il3p2hdqSYgb9KuGIdhC dyfmkGHWEqn2UVPfzjwFGv7n/zEQ0qJrB+iad6yYvKAxw35oeyF8vKOYXM9Xv92FSbes pLU/bw7LcRZ62KtwfNTRDKYQSlrXPD8EMBRVATyKqi8RZs1n892mls102alJ1vVvqZpn If6ANRYPZXR7OPuF/PPX7AzZdANN/GEa+KkWzM4H7j+e+mKUlVTI3QMGO+Dk+9H6+kXy YXng== X-Gm-Message-State: APjAAAUCh4dmx88gm3HalHC9MMfYm/MKKxW2LeeqyLVLjmF0bvEMUHWs ffQujQMAHSVHXq6kWpfWzQ== X-Received: by 2002:a9d:718d:: with SMTP id o13mr606528otj.119.1551377849520; Thu, 28 Feb 2019 10:17:29 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id a14sm8101441otl.46.2019.02.28.10.17.19 (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 CDE47180901; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id AF866302AF4; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:08 -0600 Message-Id: <20190228181710.2477-18-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::344 Subject: [Qemu-devel] [PULL 17/19] i2c:smbus_eeprom: Add vmstate handling to the smbus eeprom 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 Transfer the state of the EEPROM on a migration. This way the data remains consistent on migration. This required moving the actual data to a separate array and using the data provided in the init function as a separate initialization array, since a pointer property has to be a void * and the array needs to be uint8_t[]. Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert Cc: Peter Maydell Reviewed-by: Dr. David Alan Gilbert --- hw/i2c/smbus_eeprom.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 3fbbffb4de..5b10c31ae7 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -26,6 +26,7 @@ #include "qemu/units.h" #include "qapi/error.h" #include "hw/hw.h" +#include "hw/boards.h" #include "hw/i2c/i2c.h" #include "hw/i2c/smbus_slave.h" #include "hw/i2c/smbus_eeprom.h" @@ -41,8 +42,10 @@ typedef struct SMBusEEPROMDevice { SMBusDevice smbusdev; - void *data; + uint8_t data[SMBUS_EEPROM_SIZE]; + void *init_data; uint8_t offset; + bool accessed; } SMBusEEPROMDevice; static uint8_t eeprom_receive_byte(SMBusDevice *dev) @@ -51,6 +54,7 @@ static uint8_t eeprom_receive_byte(SMBusDevice *dev) uint8_t *data = eeprom->data; uint8_t val = data[eeprom->offset++]; + eeprom->accessed = true; #ifdef DEBUG printf("eeprom_receive_byte: addr=0x%02x val=0x%02x\n", dev->i2c.address, val); @@ -63,6 +67,7 @@ static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); uint8_t *data = eeprom->data; + eeprom->accessed = true; #ifdef DEBUG printf("eeprom_write_byte: addr=0x%02x cmd=0x%02x val=0x%02x\n", dev->i2c.address, buf[0], buf[1]); @@ -80,15 +85,39 @@ static int eeprom_write_data(SMBusDevice *dev, uint8_t *buf, uint8_t len) return 0; } +static bool smbus_eeprom_vmstate_needed(void *opaque) +{ + MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine()); + SMBusEEPROMDevice *eeprom = opaque; + + return (eeprom->accessed || smbus_vmstate_needed(&eeprom->smbusdev)) && + !mc->smbus_no_migration_support; +} + +static const VMStateDescription vmstate_smbus_eeprom = { + .name = "smbus-eeprom", + .version_id = 1, + .minimum_version_id = 1, + .needed = smbus_eeprom_vmstate_needed, + .fields = (VMStateField[]) { + VMSTATE_SMBUS_DEVICE(smbusdev, SMBusEEPROMDevice), + VMSTATE_UINT8_ARRAY(data, SMBusEEPROMDevice, SMBUS_EEPROM_SIZE), + VMSTATE_UINT8(offset, SMBusEEPROMDevice), + VMSTATE_BOOL(accessed, SMBusEEPROMDevice), + VMSTATE_END_OF_LIST() + } +}; + static void smbus_eeprom_realize(DeviceState *dev, Error **errp) { SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); + memcpy(eeprom->data, eeprom->init_data, SMBUS_EEPROM_SIZE); eeprom->offset = 0; } static Property smbus_eeprom_properties[] = { - DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data), + DEFINE_PROP_PTR("data", SMBusEEPROMDevice, init_data), DEFINE_PROP_END_OF_LIST(), }; @@ -101,6 +130,7 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) sc->receive_byte = eeprom_receive_byte; sc->write_data = eeprom_write_data; dc->props = smbus_eeprom_properties; + dc->vmsd = &vmstate_smbus_eeprom; /* Reason: pointer property "data" */ dc->user_creatable = false; } From patchwork Thu Feb 28 18:17:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159415 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp982402oce; Thu, 28 Feb 2019 10:27:18 -0800 (PST) X-Google-Smtp-Source: APXvYqx96De6RtZywd/iL4ewNc+G/hNrxq1fZxplPWOsd+DqSqw7bWZLijvd4NfmGGKyKzvIt7rW X-Received: by 2002:a25:4902:: with SMTP id w2mr757382yba.26.1551378438822; Thu, 28 Feb 2019 10:27:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378438; cv=none; d=google.com; s=arc-20160816; b=DVZVDraFrKkeMzSgAJkNifeGlyGIXEA90Tglxdt1Jfq02ca0vYZgNYgrx/C6scW8wE iGabVGTJDz3BTRZoQ8gx/iIbDGuIpLCcl12cuNosLospRZchObcPGf9iZ8ose17edHkL HAtVo+AukK4u6gZjjAMmqhMkiuLCnwSPIVxxBEGLzJV75i8LY2aW8UJn0Fr/tMRuXjLK aXCUgwZw9ER5nLXzpH952W6lFNZ1rcmgi38pWGXQD4SW5iKAqaQmWDmRVIrikXd0ZfkM w8KtFsuDoDZYbbsr4izzcKK6aSHMlbxWoagZ+kNF97t2h1s5afR+0Xx96hS4hTEgh1Aa QWeA== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=578+1MXr+/10iSBsluW/Nwhfp8x/6PPyLTwDlnrEJC8=; b=UaWCe1cKsAZYiR5Srf5QSauIZlptMG6eHhm/ynkxGQ1ccdjyhXWEkhR30E8S9OsKq0 Ho4IPwkXSs59i3klaTe+lOph+vyup5Gt20IaENU32a3xWUIwKiHBRT+db9U9Mp/NUjcs N0WjAEaBhMjj+FlF62BrwQcWmBhVrWpNYYEy7uoJkWV8kKLlyhjPWmDag8wytj3QIFkr /OK1E3oH5d21+7z/dzhdcjKlm/6fNFU7udhtUAApoKPNbnPW11fX/E06HM82fSLqN/3f yUd2GzHS+RzB9tbYwLzsuAqVijl8BscGyaVzu9mFobFtK07BAEYlXU0ScrNgZjZnsYKy RSFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=qky0b50a; 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 d18si10977126ywh.325.2019.02.28.10.27.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:27:18 -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=qky0b50a; 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]:44614 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQOs-0006ld-B2 for patch@linaro.org; Thu, 28 Feb 2019 13:27:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46638) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFe-0000VO-BN for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFV-0002Ha-G9 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:44 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:35201) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFV-0002DZ-5v for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:37 -0500 Received: by mail-ot1-x343.google.com with SMTP id z19so18560642otm.2 for ; Thu, 28 Feb 2019 10:17:29 -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 :mime-version:content-transfer-encoding; bh=578+1MXr+/10iSBsluW/Nwhfp8x/6PPyLTwDlnrEJC8=; b=qky0b50aJcOrdSjirc6oTNag3iYNWLtRWIH0Dpaef1WPuPiLLxDaKQpTU1QQj6YvwN RF9X4tWnq+IzygXmAMsybw2B/tGJZBEs8q9xohMgzOwDZJbF3pJds0LNMlwu839Blass 7Bo2+mkLT2ISemtjIn0FaM65JG3mYnwMtV6GgQiEbvapGsZIUP8wP20e60QOzQh42ZqD G7H7aRAEePjrsnoDNLHIS0vu0pSrWrGgWm/aHyzADK0GQGR7ZW2AS7oScrsD2kdJvBmB v1DuEx+f33ccGCoCeS+mpOQx3b+eV3SefJ6foAkcGsYZBP9gkGVlaRbZAuQej00fe/jI PFDg== 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:mime-version:content-transfer-encoding; bh=578+1MXr+/10iSBsluW/Nwhfp8x/6PPyLTwDlnrEJC8=; b=L7d2j6oZ8TzOZGAEugaXCdf3wsyVQLMoXUK5cUNbFDvWWO7wQ7RYf2PVyESkLuTSLx shQeDnzZA8XrpGBDUh2u9QzPeB0EA/y1KT1zjPPrl4LsCvMO5+/6nKz9QPirvL6oQPr0 2q3RRptVGdhBJt0zcRxxiCGDxKz1ZTvyyxI0h+E3xuXNhrcRkCTiD5fBadsTDNnRJNog k3b+zmCOMnuMLvsfeY0OMZfR14dPqLyZbTX/F6NDHdwxLAxE0JKDpXjzqMtTjNFb77RY QC16HJIVv8cvrMdR9sHOxkipVxzniYlXgkguyD9Bk7hCygd4TBofWrEMFSsHPzEd/+bw zKdg== X-Gm-Message-State: APjAAAX/iVTmY9RZ3hh9LV8lMJNquya9Mjhh04tMwVEMrpfKkQzVkY/J qKeSjVbluJ1tHf+p8+sZ6Q== X-Received: by 2002:a9d:7cc2:: with SMTP id r2mr702193otn.282.1551377848969; Thu, 28 Feb 2019 10:17:28 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id b131sm5471757oia.28.2019.02.28.10.17.19 (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 (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id D7F79180902; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id C61783028D0; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:09 -0600 Message-Id: <20190228181710.2477-19-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> MIME-Version: 1.0 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 18/19] i2c:smbus_eeprom: Add a reset function to smbus_eeprom 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Reset the contents to init data and reset the offset on a machine reset. Signed-off-by: Corey Minyard Reviewed-by: Philippe Mathieu-Daudé --- hw/i2c/smbus_eeprom.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 5b10c31ae7..0ba5763fc2 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -108,7 +108,17 @@ static const VMStateDescription vmstate_smbus_eeprom = { } }; -static void smbus_eeprom_realize(DeviceState *dev, Error **errp) +/* + * Reset the EEPROM contents to the initial state on a reset. This + * isn't really how an EEPROM works, of course, but the general + * principle of QEMU is to restore function on reset to what it would + * be if QEMU was stopped and started. + * + * The proper thing to do would be to have a backing blockdev to hold + * the contents and restore that on startup, and not do this on reset. + * But until that time, act as if we had been stopped and restarted. + */ +static void smbus_eeprom_reset(DeviceState *dev) { SMBusEEPROMDevice *eeprom = SMBUS_EEPROM(dev); @@ -116,6 +126,11 @@ static void smbus_eeprom_realize(DeviceState *dev, Error **errp) eeprom->offset = 0; } +static void smbus_eeprom_realize(DeviceState *dev, Error **errp) +{ + smbus_eeprom_reset(dev); +} + static Property smbus_eeprom_properties[] = { DEFINE_PROP_PTR("data", SMBusEEPROMDevice, init_data), DEFINE_PROP_END_OF_LIST(), @@ -127,6 +142,7 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) SMBusDeviceClass *sc = SMBUS_DEVICE_CLASS(klass); dc->realize = smbus_eeprom_realize; + dc->reset = smbus_eeprom_reset; sc->receive_byte = eeprom_receive_byte; sc->write_data = eeprom_write_data; dc->props = smbus_eeprom_properties; From patchwork Thu Feb 28 18:17:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 159421 Delivered-To: patch@linaro.org Received: by 2002:ac9:18c7:0:0:0:0:0 with SMTP id i7csp987262oce; Thu, 28 Feb 2019 10:32:12 -0800 (PST) X-Google-Smtp-Source: APXvYqyGdw0qBRM/Q/XLnWhh3I3QmyyFupT975x4By+8ZhysBeGOn/TyVD4m5ETNbxRafjc+W3GI X-Received: by 2002:a25:9d07:: with SMTP id i7mr738610ybp.454.1551378732050; Thu, 28 Feb 2019 10:32:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551378732; cv=none; d=google.com; s=arc-20160816; b=gJtfTVfUI0x/M6Hj/gb0mH7L/SQcIwrFS3q7z44w7tZMC+lIFVcnSA2VCDxSd36hAx dPs/xFhOmc4CpHbZ8R7lkGUO6Umi+NonV9ghWYwO8e8Jb3aZULzWg6Dq5r/9kahLR/x0 sOPZpppp/WXSgnPFcudA2qOIhu9x3LcIf1QEL9/Vu+g/c6uDQtZ9zvSTTeBd3E9SII7/ mRgqwKMmzYlUpLMLvy7b7RN7lp+N7bySM6eKKOKtbNJ0JzsnXjKyu/UGrmz0NM0jHWeQ walMwvh/UG35zBus4g6MCuvCZEkzXxBsFNZMYcw9xmFZbcEsTWRFkW4RjKTK1Zq4Gaiq 3DiQ== 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=UnkEe3Lz2kCnlXnA1sXksP9chMKTTYD82HqDl1kU840=; b=Z6kD9yi67ImNqwMUYslgyshA0wSwxaYo+XRKFxcg8Br3ekLdi9VoTZJV6YpOanWnLO NUtZ443KPwUSL20QhmaIN2f9TcmoaulrZ26Wyi1OcPWqRfbHV+aPrUgopOr4+Bf0oXta cx2gsiBF7kYlhZMpJud7vqOlirEOkOCIvheEh/b8GThMIjLpQs1QCsQBM6Om88ltf6F/ YU2Chn+HoVP6pGnJNktF0JUHd+Ax3Z1PDKBTtuLTjVksO7wI2PiVJqQ6KEZzhpNBXcdC iwlg+UTPX9ji5VS3mr+SuIBzquP+kw6KyoL3dzJC7nRWaxj2j3mjudLStCaMKWQbrdOz 8HTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=VvjMQKkq; 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 i1si10488972ybk.389.2019.02.28.10.32.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 10:32:12 -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=VvjMQKkq; 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]:44698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQTb-0002qi-HW for patch@linaro.org; Thu, 28 Feb 2019 13:32:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzQFo-0000aF-B5 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:18:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzQFc-0002Lu-Ns for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:56 -0500 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:41540) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzQFY-0002DG-BD for qemu-devel@nongnu.org; Thu, 28 Feb 2019 13:17:40 -0500 Received: by mail-oi1-x231.google.com with SMTP id e7so17274032oia.8 for ; Thu, 28 Feb 2019 10:17:28 -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=UnkEe3Lz2kCnlXnA1sXksP9chMKTTYD82HqDl1kU840=; b=VvjMQKkq87dHE8JN6XudaB863L88/NbwejEehUfsicdMOnagefwJWLnaZGDDE2NrrB nXYekbKYAatT5TazulPi5p643eQo8zk9VsNIDoWZJcwHiQI4gw22txz+cAPsaC2Diiy6 LbPIJBb4h6fO5hANIOoNmXho9fRfrMnC6E2VuZKHPihQt6/O3W0tRSU5qXTmfFE81Vzv 7PABD1kZJhHv1joLSouC9bI4g85H0Etwpomvhdb1iVBPV0kwqRjWAy+G8OEu3TLyiS/f 5I93k138U0jPBu9PjnGPkObhYoiey9J8/jKkejAoWnIy+qn5l+JRh0/wdgXHNYocvsM8 LcpQ== 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=UnkEe3Lz2kCnlXnA1sXksP9chMKTTYD82HqDl1kU840=; b=ajCGx6XQkWS+3e6F8rrNJjd9xDPr2w6NOukSy5bm8dafU4smqGevl/WdIizHs/ZOMg TAYaLnWcPmklL2hfBxA0fgX+ppWsynPhsZWydlHPYoYiPFBrx7R4uPV3EutWlhl6+03Z JD/2Krtn9Ddv8ig8ZSDb8KCWrHoQYFEKZF53vQts3FqlG/HoV+veyefyAISZ0oCteDWV 4OFJMANdnHrRbkZ1EVLsqYOMLWTrKn2hLa/p8LS0LyUpMTWrzn4wpDxJwzKx8bumjRPC XGM+Yg6FWQj/dts2VCGCzd76Umc6NGVdfh+nKK3uc2YI7618cOgGH93GnUNzP1N2NuTa WQmg== X-Gm-Message-State: AHQUAubYHyCz7xQ0tsDzXSRdBoc7odMcK7tEbsRjsGHFExjTgAQmpNyR aFhhNpWDfnSojaheAQIhew== X-Received: by 2002:aca:da43:: with SMTP id r64mr633505oig.119.1551377847861; Thu, 28 Feb 2019 10:17:27 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id k25sm2751743otl.58.2019.02.28.10.17.22 (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 (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id E1ED0180903; Thu, 28 Feb 2019 18:17:14 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id D081B3028CF; Thu, 28 Feb 2019 12:17:14 -0600 (CST) From: minyard@acm.org To: Peter Maydell Date: Thu, 28 Feb 2019 12:17:10 -0600 Message-Id: <20190228181710.2477-20-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::231 Subject: [Qemu-devel] [PULL 19/19] i2c: Verify that the count passed in to smbus_eeprom_init() is valid 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 , QEMU Developers , minyard@acm.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Keep someone from passing in a bogus number Signed-off-by: Corey Minyard --- hw/i2c/smbus_eeprom.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 0ba5763fc2..37167e7244 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -180,6 +180,8 @@ void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom, { int i; /* XXX: make this persistent */ + + assert(nb_eeprom <= 8); uint8_t *eeprom_buf = g_malloc0(8 * SMBUS_EEPROM_SIZE); if (eeprom_spd_size > 0) { memcpy(eeprom_buf, eeprom_spd, eeprom_spd_size);