From patchwork Mon Jan 28 17:54:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156855 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3742731jaa; Mon, 28 Jan 2019 10:27:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN4yITOeyBChH0xAW7pFym/Rg0+nR6f0uIC1tzFX5TbcIZFAeXsCIegSGel5M1ej6AV3RGxd X-Received: by 2002:a1c:2e43:: with SMTP id u64mr18520493wmu.52.1548700071672; Mon, 28 Jan 2019 10:27:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548700071; cv=none; d=google.com; s=arc-20160816; b=yT27dg2ZlpG5kgiodnTiYv+AWYQJ04srG24gRI6qxulEsrlIbRG5urLm3BPYCv4Zxg FmcZsyKSSA4tcD9tcNbx0KDwcXcdo9MUr3UTd6tAhiEZSq2jiR9S1utZ0xqhkE/XQwiX aiVeMsy59SqAhufHhNEOJIOZkil/SwXblfdycT9tTIw8uXDZqaxQ4TE9JKZU5SeEuPjW 5WxR6ClhcgoCD+9Vc1Br7y6KlYW3hb0vLDWzrb/1Ra2EfSy1/NrXUL80FNWV/OV3ysQ0 2ZTabxELl66PRz3dNjt9LS1YP64p8lobX5p60hM12/lwKh+1CLJbMgMSTpBGxcNZuQ5t pOeA== 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=7xm10acdtoFIuMH3f/sDy1gu31FToPVeCjyvT+Zh/ew=; b=k6cnLq+XojyFUIj5YhC2KDsD3PxOPdo7WpwJ+ZS1kH/sITkapf7F/iKUQdQo6goxFQ ZTmirOnNeKyu/AFZGu2PTACJn2GTSV4S3sLrkK5NerEMg+aTFbOy0CQgPeelI3YQ4BvQ ykOI/t+wBtp1DCDDWyDtUKN+TmqZjun/dnu6e/YQP7IK75LfmU1iThMdvSmmk7lii02u It5sbleY/gBFnE+irHUUDHIxNAXLScI8Mg5WbZyL4kyP3IlUP383E3Moqhiaxkhzr4Wr U3n7ZMFfC7/txUzquR4FXu2FOS2j8RoqHDy4iowVPPW8lvbML16urEb+IGE/Cfe1jceZ SWdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=k8krH+WB; 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 s16si127000wme.48.2019.01.28.10.27.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:27:51 -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=k8krH+WB; 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]:36591 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBdO-00074X-DW for patch@linaro.org; Mon, 28 Jan 2019 13:27:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEH-0003Zq-94 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7u-0005Y7-9u for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:31 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:40765) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7t-0005XL-UI for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:18 -0500 Received: by mail-pl1-x642.google.com with SMTP id u18so8063343plq.7 for ; Mon, 28 Jan 2019 09:55: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=7xm10acdtoFIuMH3f/sDy1gu31FToPVeCjyvT+Zh/ew=; b=k8krH+WBERnawC7v6k56DPmOWCwCmViYjTGfOEAs8Ru8rB08K7UQyPF8tYITECrwGq ve9td/pCFmoAxkAoI4Aqjdz2Z20bR2nVoiTXWXe1ivIzWcmWnax3J7f9RNlkIWLF2rrg NkCjFv01B4NwlASdyJOLAcmSYaX9qRlLa/HwBeqp3zYqpL3h3bsPvCTkXwRkbsl0JgZJ N4jgKQLEmgi7b+Zl5lvpv2T1yng7KKCrxcigPjvCeWZ/hsWDJr13KKzYSsQSr97zhyXD DktcvFujk44Rox1fW5ueRPCUFaYzdP5T9M93o+6iJh6p4rNQ15HbAr3+jZuQK0eWj8Lm NkAA== 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=7xm10acdtoFIuMH3f/sDy1gu31FToPVeCjyvT+Zh/ew=; b=PbHa+S02Z1SxE19o1dLAzfN3HybWZQ36y3AW081OUT6jrOB4JYSS1gdHTMk1nyaWnw HAptmy//v9wAS5RwKCwjqm09sAQ0yRIMvQ3Ay1rzfIDi5uTpUFER2E2I5ig1Wv6Qaeod kLFpudBOt3C2Fy+I91LPRwrR3J1zjG2JDLehAlnVrgZO+APCHQ9Ht4Lr90/ofumfJxyd Kq4KJ1FGNxICDl6T3IkYLw4qulURT/GKuRhKcZ6A5Nctt9cjQSjB6h91bzd/iyc7z5vZ BM99phboX4X106hwkLKfHEb9FL4mGxTffxAj7MBcLpWLCoQpjq1h6OHgsGCzHLVtqi94 5Gyg== X-Gm-Message-State: AJcUukeOyVoPRyjXMo8IDEQICSFW2Yfhxk3ciljSIfGlRo/khNL3PD7j hadz8U/TG2gIJhpW9TIzdw== X-Received: by 2002:a17:902:9691:: with SMTP id n17mr23332975plp.9.1548698116543; Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id c9sm66660595pfc.92.2019.01.28.09.55.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:13 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 01F1FBAD; Mon, 28 Jan 2019 11:55:11 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 7A52E30052D; Mon, 28 Jan 2019 11:55:06 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:40 -0600 Message-Id: <20190128175458.27255-2-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::642 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 | 32 +++++ include/hw/i2c/smbus_master.h | 55 ++++++++ include/hw/i2c/{smbus.h => smbus_slave.h} | 37 +---- 18 files changed, 285 insertions(+), 193 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} (65%) -- 2.17.1 diff --git a/MAINTAINERS b/MAINTAINERS index 59e1f24d68..aaa80d0b59 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2142,6 +2142,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 37cacde978..8973edfa22 100644 --- a/hw/i2c/Makefile.objs +++ b/hw/i2c/Makefile.objs @@ -1,4 +1,4 @@ -common-obj-$(CONFIG_I2C) += core.o smbus.o smbus_eeprom.o +common-obj-$(CONFIG_I2C) += core.o smbus_slave.o smbus_master.o smbus_eeprom.o common-obj-$(CONFIG_DDC) += i2c-ddc.o common-obj-$(CONFIG_VERSATILE_I2C) += versatile_i2c.o common-obj-$(CONFIG_ACPI_X86) += smbus_ich9.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 f18aa3de35..d82423aa7e 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -25,7 +25,8 @@ #include "qemu/osdep.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 63c84e3827..6ba163ccbb 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 b7b7959934..1689885cac 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 2fbba32c48..dae8acc108 100644 --- a/hw/mips/mips_fulong2e.c +++ b/hw/mips/mips_fulong2e.c @@ -27,7 +27,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 c1cf0fe12e..1fb7170f5e 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 84ea592749..a04d471433 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..46fb1a37d6 --- /dev/null +++ b/include/hw/i2c/smbus_eeprom.h @@ -0,0 +1,32 @@ +/* + * 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); + +#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 65% rename from include/hw/i2c/smbus.h rename to include/hw/i2c/smbus_slave.h index 5c61c05999..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,33 +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); - #endif From patchwork Mon Jan 28 17:54:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156835 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3725335jaa; Mon, 28 Jan 2019 10:10:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN6U0vcuKA2CtrWDFaSc7RhUaCv0ZiWCHh7e9CBgta1C1g1oacMJhlSEbQiAtRZwfbIyjSk/ X-Received: by 2002:adf:ca13:: with SMTP id o19mr22528751wrh.148.1548699027671; Mon, 28 Jan 2019 10:10:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699027; cv=none; d=google.com; s=arc-20160816; b=HakTgRxIvIMcvd5KGaPkR7P472P2Wo50773ed7kpDDu/YISVNNGshugbP3bht+rfP2 +fgajGEe8zMsM/io2oDdI4SLrLZQPb1XclljOy4SSl7h+ZGHMfBGaA/ZUNZBbiHYW1/l G+rUYKzcqoq0TOezSX5EWi7/uTI2qE7br7ZKFsfO2xEXQx0toKla24CByGGYf1c1T9LC rWjHD9HeJ4nQxZG9MgavUiGHxKepc4rNA6ObJdEdV60K9+1DecEccXj3SgxnR9ENHEdS RozS8RlkrNnSve3kVJ+/DR+WD7o6M1DuZYzFRyBBaI8oCYkDV7AT03xjpxzGAtugAIHG Z8lQ== 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=eRLv4Q2u1wLGMwFuH2kL+sXaWvCxX+l1djjLJiyz4crKiKLy7VXMISqudgSRD1ibkI 7VLATub8LnABOhoqDkV2PL8Q6uo81kXSR5yr/Ki375qDzivdXCkMCcLCqwla4Mf7X++A x9J9aedijtdFfrEqJjRWePX3z+l7HaRS8yAuyLVNtxndxJ1Gg6GyFt3hGzfgGxgTQDfy cFYtKohY3lpZFBHRLD1czrHRSz7oxTEuESzleRmE/cEPYabpp3j93zYEzFxSOtF9kq1g q31ZZ5HCkKkQ9pBfmdz2t9EKYGL2cQ2291qS4If3nN83bGWX5yvbHk+ggi0QFd+xBGWE 30sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="R7mlyo/K"; 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 f7si94361wml.34.2019.01.28.10.10.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:10:27 -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="R7mlyo/K"; 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]:36319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBMY-0001js-4l for patch@linaro.org; Mon, 28 Jan 2019 13:10:26 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEG-000396-Bs for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7t-0005XV-HN for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:30 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:40766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7t-0005Wt-3U for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:17 -0500 Received: by mail-pl1-x644.google.com with SMTP id u18so8063315plq.7 for ; Mon, 28 Jan 2019 09:55: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=q3HzY62CF69PYoUzSkwefLjdYNoX47tEb2xxB85KIlM=; b=R7mlyo/K3Z3KzrbY0FRuckc7S+ey0PTXBrBw/yH8yWgC20EfTxtXLOOx0XC5aiRvzb JYIODWVsMC8UGEi+mg5tzd4kYEpyKQmg+Kb3bUL1u+yg7uSuazhRS6ridCprLKVXLy2r Ilby4pMqnJZnNFV0qh+maotb1diYVzxUChsPHEm0EYftmYoFI9ifJVxDEUj07WtFyw0K 5/TGmRN1dfiNgXIagVi+j0tfhv6/k5ieyTGdhx7jsjT7i6EdQUqg5d5tyLLesTxnxAVl BY+woCX21fedJ/l1NcqMfi3MmLkCOB8RvT1NnYHTztFtLSd8xEIx8jn3asehTVltTZU9 sz4w== 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=rP9GYT1Q1XwBks3Ux4A+bGEbYyywR9KOoNcah+nRstSwIcKhIRrLA7Vv4vT8WW9Ue7 SrKdD89fl8uzTgEYLsGUHPiLmz2qs43XEh1CW23yV5xA8n/ntIUnxsDrs0WCfg+nxk72 /ZnRDnjv8dzPohkcEfGLWfTgr5s7lpRCOa0sZSAZhxNPQ8WKmkZEspIFte+Ps5ryu06p TBCHbPMjGAgkh14u0XKL0GvJCDs7VPbtr4zwnLmwtXY43G+PGvodq339AfwFMycOQlEU uGzRa+V9LsHdrcKrHkNujiPx32Uqh81uRTIqC167UtlE5tgeEkCn5oF1qVsiM0gysVP8 r4WQ== X-Gm-Message-State: AJcUukcXaMYbypnw08B2zs76ZO4EyHVe5Ld9MRynmMHNn3drKBIOXMWx P1p2AOMR/GYzs5rMXVuTng== X-Received: by 2002:a17:902:bc3:: with SMTP id 61mr22851792plr.15.1548698115612; Mon, 28 Jan 2019 09:55:15 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id z186sm43574364pfz.119.2019.01.28.09.55.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:13 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 23271BD2; Mon, 28 Jan 2019 11:55:11 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id EED1530115D; Mon, 28 Jan 2019 11:55:06 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:41 -0600 Message-Id: <20190128175458.27255-3-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::644 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 Mon Jan 28 17:54:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156836 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3725470jaa; Mon, 28 Jan 2019 10:10:36 -0800 (PST) X-Google-Smtp-Source: AHgI3IbbpKkRJZvB/fJCBMRuagIjGoOyP2MK4+9P1PQ31tTQcQDYemc5gJ6VOdDgSv+nsFbXDwyE X-Received: by 2002:a1c:e10a:: with SMTP id y10mr8517674wmg.73.1548699036168; Mon, 28 Jan 2019 10:10:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699036; cv=none; d=google.com; s=arc-20160816; b=sFOEA+sPPPnknwzXtSPGWz0jv8ixMiYkuUdOlApXF8RJDAbzMsREwQGQ+iimrKhdjl JZNzjB70QON9cHfrIKncJ7zphubUjTgU45Hfxxk84fo9htsQjSFzeCeVjCxfazcB8I9f Au+JL9iWDQWCG25TPu/+R/Wlo5gJ26H7l8vmIjfInMxk+49R8P1yoWtFn40RH4qh1VLX nnr2jExei8sKpF9L1ugHFqLgYRYKVEn0dvrePw/dUqa3y17rZ8AHZIgmJidkQe40c9dy qth7pufQfd0yPnPHacC5XD39ofYYBtEBxW66ro3q/jQzC+W+YhFelj2KcKpRGwuwDR8n dyzg== 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=CahfqUNRtQ0ioayZ4sVxn3y0cMHXeN6cMSkJSyfMvrsRIKXnqR4dC7iAEk/WZ9N7Tq wi1Dd/iT3i4/eLnMe1JZF2NHwcbq6c4LAuWQ56oyNK8BmhcUUjLzhlXfcqknMRZFlCen X+lFnWswgnBLVbpgGujJcqU63iYbhDEGsWns2giSvcU+p+sUowH2K5Sx0wB2ywHJ2LED X6OeTQQThE7eNWjxJrnrex375k3r9Q/kQau1AQYN7YfsC1RlWTW+ZKPxxJCxD8S8pFDX ESeYelzP6CeF5MN6nxF0KJ4OYa24iqk1tE0WH5xOdFAw3jyKvuF5fG9Qv+wbp+AyCIFa gwwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="vbp+/Qv+"; 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 l1si85809wmg.90.2019.01.28.10.10.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:10: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="vbp+/Qv+"; 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]:36306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBMh-00015E-1s for patch@linaro.org; Mon, 28 Jan 2019 13:10:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBED-000396-Fa for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8V-0005ur-Me for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:04 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:43662) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8V-0005Yl-El for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:55 -0500 Received: by mail-pl1-x644.google.com with SMTP id gn14so8050928plb.10 for ; Mon, 28 Jan 2019 09:55:20 -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=vbp+/Qv+tLwxfZll/uLeErLiVwmV9uwKl7ZD+rzM38yQD+BDnXvhsL96psjD8G+7cF V2lzuGoAo8CzcWHM/wTz+oU/VF82VJ+Iip5iIket4EFmx0cbs8ccLqv9gV3lnLeX56kh PjKfj5sVu2BScnKMicGkjCFIUYG/woMPU9nR50IV9RaLmzBPye/uId5KCHjYQojKemJg pZJnzvmf3pKyoxL7qoTgNrffC2uuBUvdep1n8zjzQMw3RPJZTcVzV6hEaOn4/lWzeOvN KebLi17oN5VLnUOEV/L+NK9CusZN/GXqE/g66kPeIQOYP77uvIY28EXHbCaWfApV7Aum WTEQ== 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=HAEjUD56jSd5WKOGp6loCOdzUzcWlV5gqdQ7OTloljnKfx00nqZf1gkbWdHN8cLzXr U1e2I6LFxv1IPHKu0Dgnv/7LZdkatEb6Lwu7UVWxx3Vfub5fb0vWXM6hlilC/TW6tKo/ G7C2HkfJGroRgvLUc9WzgnWQNtCe4PrB+mMZWID2QIWJ3kN6o6q7mGKSIUTKJ21RFMEt eAVLhqQWaKh7ESvHYjX4d5hZRDZzC7+AvVdrvr9nx3TBeV+fps1w2vemymnARKSt4Nl7 tp2xkgxHnHBa5QPZfLRzXyKO3MPFKMrnyO4WFW8l1p/fKSgnHG7LDZ7kK37Scuv1DT8p 2LrA== X-Gm-Message-State: AJcUukcEtQWhlesPMYZ/dnrVn4nZ/bN/Xzox98ETjhHBH8hrUu4N9C/p kNqS0vcO8MzF6rgWleKpRA== X-Received: by 2002:a17:902:2868:: with SMTP id e95mr22804057plb.317.1548698119219; Mon, 28 Jan 2019 09:55:19 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id b202sm50579825pfb.88.2019.01.28.09.55.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 800D8EE6; Mon, 28 Jan 2019 11:55:12 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id B4D7030115B; Mon, 28 Jan 2019 11:55:06 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:42 -0600 Message-Id: <20190128175458.27255-4-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::644 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 Mon Jan 28 17:54:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156848 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3732317jaa; Mon, 28 Jan 2019 10:17:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN42eG8YMw3guapNKuN1U/uW6jsvMJyT2nwdq7rOR60ih7IGFwOnvZLSjuOcKpDz0q3oEyFd X-Received: by 2002:adf:fc09:: with SMTP id i9mr21912014wrr.299.1548699433764; Mon, 28 Jan 2019 10:17:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699433; cv=none; d=google.com; s=arc-20160816; b=mSvBQjLGEemeBUzxwoKUZqUJTdFiQBYTRsHuIF+s7xfqTnQkBUFfy4HgNV9oXp3QDa J0xi9ysbqwpqjfvCycWDlLyBLTgC4YnoQWJWi0sEmemePpvgergvI3Gn3M9CHuFwVG+y uWJbAwBJzOVVo9AEec/MisGVw53OkQ+bRXKlvO2CtZmxg7irGqOXj4dOwA4L+or7JOs6 NjQfDeKl46AFNYI60aqbYCKFgRJdavKe7K7Gcc9WYvbAfTvkoilHGQM3XR+aY+maoJSU yaUjcf0kXm44B/wJulJtB1vKQOWNcoUS5pE+cR70XRbVV3tLoXCP7p2jv+YGIVqpcT9b a1vA== 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=FNiQrRlEMmtgedliCfGvZiRfNP/9M+/UA9Sr0bLmgvKTpKX6EcVkbdjmRCwjYyEmg1 2TkVbJ4ozL/loQs8RPhQOkfR25spqKwA6XxTqY8+eWSqrpxD1+p/5v4yOX/Z5jKfc68G ie3AvW5UVtz9PVueCFEvIbpP9Tu1fB7FdKoulO3c+J7PJP4w+97toksuoeGBO2Oucflk enRaRuFvQaPnVLHOl4+dKAP1KZ/1ztCyW4I/X/v9oT0HBVq1gX4kXuXfbeOcVj6QrCx8 t+DpCT6oDopRMiefkEZTSvf/ARKzHxPZoonM2ty6zs52Ke3tiaW/FK3DQ09aU23ovnR/ uDtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Z5BqRhln; 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 i81si114948wma.22.2019.01.28.10.17.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:17:13 -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=Z5BqRhln; 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]:36436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBT6-0007o8-E4 for patch@linaro.org; Mon, 28 Jan 2019 13:17:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEH-0003b9-CN for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7t-0005Xf-N9 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:30 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:40764) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7t-0005Wz-GV for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:17 -0500 Received: by mail-pl1-x641.google.com with SMTP id u18so8063320plq.7 for ; Mon, 28 Jan 2019 09:55: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=Z5BqRhlnyh/TpdMF4nGoNNnqX90BWQtbmiuxU221nj2J6+iR/NsSw5tJVBlfpgoWlK 9Am/vYW3hA9P1zqtBQjKak7SIwYfigNtGmJZ2n7vvXIqmYXv4sW1gT7+vTNHkRy0N3Ps z8d5upHhvayEYvISJt1I9zTSIWBNK8mpuSTxiYZ5PP9+TF43wMjqA+31uFanmjWIKMHx EffYi+5IdybIc5yk7vivaK6P3Cfh1+D+tx9SaXYHng3VKpiNJQ9FyIjmELHAb8HZSG8O 7vlq905n7Al3ujqJcjfSiAGdE4El8FG97rjYlBmRERTvK4w6rLVxwPDb/zDjmpjPc8cA y7CA== 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=Rn5/sYQg2sEtn0Qommz8jamrVslP3O2wA7Ne9uxXtReM6GZeMIz01fyTTlzsgQGQcC YhxB03F1i0SItbvqGVfgoT8b1xzbZOdDVCCM44l4jg9DBH0IPDt/Qc386gTBx3WdSQz+ 7EdtZL6S1rF4BWW7Dou1Zqj8R5xdJG/ICjAjuZKFhvQd0ya7y4PeGNont+VeUhcQb5pt vrRCxJnSh7hsFiAKf2TUu+KSQNOAAZkQ5TlNkA3yKPBMI2uv5CaFY493mAu0ucLSgw8L wIJLhX/T7ow/k4Q7ixpHFvCM8mQVqXF7qxyhHp9TuVoapLmEa4zFgdWthyllq+ZQERwb XoFA== X-Gm-Message-State: AJcUukffy1Yd867XuIHaSsVIthdKwbx5kXWW5Q5k4eIGEif/E1uK99LS 3lP9AkGrNv5hwb++nHVSsg== X-Received: by 2002:a17:902:8a8a:: with SMTP id p10mr23026441plo.50.1548698116056; Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id 128sm56630272pfu.129.2019.01.28.09.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:13 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 6CC86CA8; Mon, 28 Jan 2019 11:55:12 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id BCC3E30115A; Mon, 28 Jan 2019 11:55:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:43 -0600 Message-Id: <20190128175458.27255-5-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::641 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 Mon Jan 28 17:54:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156832 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3721926jaa; Mon, 28 Jan 2019 10:07:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN4mc4muw+q6xmHPqSbfgeSF7StAY5FsptjKyyOCQxGFsdS14YE9ioGTWz9DBkBv1rh9k8Zu X-Received: by 2002:a1c:c70f:: with SMTP id x15mr17952668wmf.130.1548698826588; Mon, 28 Jan 2019 10:07:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548698826; cv=none; d=google.com; s=arc-20160816; b=xcjuJvT8l/8/j5SgN2Aagmp8AZ3D9cfo0fkRr2JYimYm4v04zjGmPSashAZu1lZPTE LbwwGHGGHMJpTmeH/6UqUYKkQvzdKe0vY5EhrE44vlzJszzF61G8S5M+hji+76BXJtvG zMQV4cMu4kfSnH4lEFwE8DKGmMyyo48cdXNtGGylYET5SOvPF/SY/qBTJa/bXgnY4+at pfI3+aNzlE54Q8hu4uKrASc4q8AfMmIXIM64aBcRRz0USh9Ux5u0uTWwjM3RUwgHoBiG 1YiVz4tVsSUxqiccdI5vk/vAH9wKnlBPxr+7L5LsJxlfuUTfX657WgCljEjw0g4f2xEV +W3A== 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=vfCxqYRfJPhX2fj8vENKKEumXT87MkbK2AiQbJhNdDLqf8K0B0eKXbJUlAzJg7xWnR MlUy+CK0Rx98QO2fGH952J2zt49E7E3wMBXhANybVcOm0DpceqtNE1v1x9MrvEvKHMSK eE2DOSff3e8p/BxnvJ7bcn8ha0j/7VIBCU8TftxB0Ur/hFh+Pnv+ngnZ+EPnGwUDIjMy Jjrlb+N0UHaLklyiQAiNMyOkdoOt0/95k4TBG7tSWnDVgXda4bp5SL/96pI4Fe84+Y3L IqPpgqMi1NUlJf963vy9b4Xi5oXdMfO+50/+5LLkJN8gt8s59n2n4wcDpSRP8pXkYACY Frtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=S9DOUmG0; 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 q15si79408098wrr.127.2019.01.28.10.07.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:07:06 -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=S9DOUmG0; 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]:36278 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBJJ-0006f0-EX for patch@linaro.org; Mon, 28 Jan 2019 13:07:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEF-0003b9-Rc for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7r-0005WU-Sb for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:30 -0500 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]:37734) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7r-0005WA-Np for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:15 -0500 Received: by mail-io1-xd41.google.com with SMTP id g8so14245248iok.4 for ; Mon, 28 Jan 2019 09:55:15 -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=S9DOUmG0H0tEWkIwTCBYa51K4Twm8L3pouBIKgJssUUXjYtmL9dAIWNTH8paAqCCZd er8wgPuumXFgcwlCjn97cq9HjaIW2SwUEUagxv7tyLkRQCme2eXVoh1C/vqh+cmBErpO 0+JGbw8KMkiiYA9KBUoryHvuUWPjbd/hDwhZ+tpLgHMpJTe+EXCy3CaJ39blVBJLie9f lcD87JYA9Nh3x8COl8E9uUi6nPGzWAe9GGaRkA9Fl6bOR1xkP78kvWa70VitAhpqOOtg xALqKzFUbrFVpuQRcu8tOSsXOCO3NmMvsOneHZRo/o1Jv/fXemjKaPzYEqdkYX0IM/Zh 6bXg== 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=D1yeA0/Jg1oa1EE4aNdJqpZhYb2uyIgQzaBhCWN2GeogmQqvF8VDa009jew77z9PmE 9HItceRDEhoAPbME33szIkKIJn7sfjAA4s6iHVNlHMjLUEe7CVmt9GtYez4rH0dVzeDr y4iStWg5yUkivDNeksaunFSP5LOmhrzU2t1Cpo11tGLvaWfzJdEI84c6220EmBL5ufWU lprzSnQVscK8CzyjfIDHzA9Tpj33NslySyLDIaMgnYNFxf3Ph1vHxUdme0+W6a8/bGK3 jgz8w4hg89BE0WGVPeT4JSNIFQrDZuuuUlp/M+y26ckA3N+d0nPP7TWk6gcNJ+0Ox1W+ 1yGQ== X-Gm-Message-State: AHQUAuYSxgkyXUvTkBg3nIDrIYRQwl3DVqdDtKKbHOtg4+ehZQT3Q3Ue V7vZ0KpU6c3YYg0XN1FZ4e4sjv4= X-Received: by 2002:a5e:8908:: with SMTP id k8mr13545127ioj.300.1548698115030; Mon, 28 Jan 2019 09:55:15 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id f21sm46148itc.14.2019.01.28.09.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:13 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 6800BBEF; Mon, 28 Jan 2019 11:55:12 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 8B74D30115C; Mon, 28 Jan 2019 11:55:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:44 -0600 Message-Id: <20190128175458.27255-6-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::d41 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 Mon Jan 28 17:54:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156847 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3731019jaa; Mon, 28 Jan 2019 10:15:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN4mLtYbG9INpe8vRgvxs06Pp9BhK1optH44ux2aTRf8eAMifP/hMseQ/Jcp+vIHHQ5cMCbi X-Received: by 2002:a5d:4c8a:: with SMTP id z10mr22099936wrs.75.1548699357681; Mon, 28 Jan 2019 10:15:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699357; cv=none; d=google.com; s=arc-20160816; b=u6ekdqJ2GYIiE2VaZuMT/JG168DqnEB3vAOE23/nlRGtGXBMpA73IMcpdvz9MrVkMr ANMpaeskJPnL//vDHjM+PFjp4/YUEMZumWAkdFHikM7ea5qLxxrmYhKv/zYdSyEAvlJa v3dQ8Thk1N9dppWsZ/Z+Ow6K4vHRnLN/iNpI1X8uK2qlj/dQ33WTXi1OX0aV/7GxOk67 OPfclN1tz+B0o+wsd22bCSc+Pw3djS/iprw36VyzyEaY4NvJ4yoSR/E+knxLnfZvlPAZ E+5vnJJLXLnAxN8CaiDX1qFiFO0Me6AQsi0KRVEZiwR0aAdrlT/bcFBf7DK5O0GqMd3F Pvtw== 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=r3vzE3iMO2lxtAlRHJptW6ozanNzYhiqBJrBz7a1j4k=; b=Oke6oJl7nDah33Vdts4MFG4Z/o2z55LdCqO+OrS9iE7rs2e8631e/Ui2M33RzbbFPp EH3s6TszMeb2SS3ZvbijZGs8OrmnBCnRUG3HncrtLtEYdUN72hkh23MkdhEeI7iuuBWQ GnS8H/m2b2QjVPXYgBb+S9s6Em4MJQ7pRVbeQ6NK+NjK0FKneLvGWJ5ILxdhlu3PmSS6 dZhyx+2Mo0WKDXWgRzSEQsVZAHDBz9LF+8evWQlYnYLRMPrhLl61VYNBhkdbkBHuxIcZ zA9JjPgP5rTstmuaB0JEsJUi+dKxge/8ccpS6swLr07ykdW1Joq15AOVzh/XeSEBX0du QdVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=FCwUD36+; 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 v24si74760wmh.197.2019.01.28.10.15.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:15: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=FCwUD36+; 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]:36427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBRs-0006os-Ep for patch@linaro.org; Mon, 28 Jan 2019 13:15:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEI-0003Db-6q for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7u-0005YD-CU for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:31 -0500 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:45620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7u-0005Xj-7D for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:18 -0500 Received: by mail-io1-xd42.google.com with SMTP id c2so14189424iom.12 for ; Mon, 28 Jan 2019 09:55: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; bh=r3vzE3iMO2lxtAlRHJptW6ozanNzYhiqBJrBz7a1j4k=; b=FCwUD36+iz83kFF6tGbN9gaoetMdoTljevdfTxkyClHl/HMbggptIdQdH6/xy/0WRk tNv1oOILOaE46elFyvhk/XJTZab8geJRr22MeJOUSOO8M4F/2BO+V3zKu2M1dJJnwvsc WScDIr85Gfn3u7TRixG6kdBQDfkA/YPqeIP7d4B9Tn7XW3P9OX5bLvyuV4+D8cztdm2m hx1JRuAD87O7Ql7AGqud8M5WgAnaXLkNOQkm+YEWoUmCaVzNkLVYAYYzftk/bJaJiFkn OH2n6EU6q/3pEdnUvERBqERnM4KOvW7FIVC0t6Cy/lLV8WVCtSV/l63fpwYgccqPUDjD BXkw== 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=r3vzE3iMO2lxtAlRHJptW6ozanNzYhiqBJrBz7a1j4k=; b=BJ2uv4ERvEXfNsfO9aNO3cWMnAbfH+kjqu3v0eFrOIz0uf3in3+MQGsP0KCaJ3+bPU qg3if92zKgYX/edfvLsatDCe3ER5Li2jWqtcVO8qrbPd+kLXOWW5sHg2qzsZH7JZhAG/ l1/OKO8heW9ABu2yH+D3EMcn70fDuybzqNy6b64IO7sbAfOUGxJEcqi3q0hyJFOoYkvd QYsl00fUDm2xErvd8qWZGT7tT0liMw+Txmx9gBuzEV7MwOvMp+OJqsv4HU2Tr89/DauL 9MajnqcdS6w4HvNoppLGLAWcmHmRPyuTY9qpdYUdcY/3YURrh7g396bq7Iz8KOd+gYp/ heBA== X-Gm-Message-State: AHQUAuaIwyFKKspVFpMQtW4ilMgES0hSFQ/JXukIpTYvSST4TFfTcIDq G+KjdV6wLGGMDIvcAV9Icg== X-Received: by 2002:a5e:d617:: with SMTP id w23mr12106005iom.75.1548698117334; Mon, 28 Jan 2019 09:55:17 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id j129sm32256itb.41.2019.01.28.09.55.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 80331FAF; Mon, 28 Jan 2019 11:55:12 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id DF639301159; Mon, 28 Jan 2019 11:55:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:45 -0600 Message-Id: <20190128175458.27255-7-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::d42 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard There 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 d82423aa7e..3f9ed266f8 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -43,16 +43,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; @@ -65,34 +55,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); @@ -117,7 +103,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 Mon Jan 28 17:54:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156853 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3739966jaa; Mon, 28 Jan 2019 10:24:59 -0800 (PST) X-Google-Smtp-Source: ALg8bN44i5Dkii2lctqM+OxAWfBRH10WFjy8EC/2eXr/7ex2+zp108spcjhZ+wEf/upLtaCut3o4 X-Received: by 2002:adf:a357:: with SMTP id d23mr23927928wrb.195.1548699899098; Mon, 28 Jan 2019 10:24:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699899; cv=none; d=google.com; s=arc-20160816; b=AkxHW97hp9/2ywmZRMYm1pdQSCGxe3O80ksvotrqxZHbC0fECBnKSO9Jd60EMP500M JsQyqDItDi/LaYVY7OqcdgQPXYavoXBTqNQVBXwk5apLRabLwBIRui/G8suIKxEmlt/M 9HYNg4XxMBcuFblkGhSDqix/YxuUyqy6EQTO70FjkdB2DklzZypE3U3AIrDaLacNOCwL +UjRMnNn6YbHhIzt4TUuMQwAaNGt4XYJw6F8iXhd3ZwLLcfZcQ6GPFQDDc/QkEEVKwBd qbkaJX2UAte7KZiY1tFn2abnxtoty4bRL9+WZ1NKuIBMR5O6YsrAPp8mrQEZgY7OVSJT 50PQ== 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=dMr8GG5RUPuVrWmsKwUgwYyd+2AfoQjp+Mu6L4T+oXc=; b=LIG6rk8NGTHLoFAiJHhXJvXLX8SRxQ7MFEL2ZSgSGIoSeqEu2d5hXlP1f1MGEJWxfv 1QzxuiDz22L+3yHW4XQBdc8YFR/yXXjeYARQ17F3ULYOMhIo7J7v5rfdZEPBu0lfJdMh OB1S984fwbEW00Jx1FlgQSqEkafbQec05qgN6jK5QW/2T6OK0zWyioefVvjXjXrLbznu vVa7QZfOC7eJhBnSs7u0w/LzDv6PpvjeFAi9NUOz/WKk2upZci/fOs3Fqqqzh/GOxJag bol5SRxGfI42P5ES4WZmG6ZFuU1+MKedxvFItLceP3HqE2qtMkaWnLALb3D9GgGbEpxQ JgOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=knzS5y5T; 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 v27si87815434wra.457.2019.01.28.10.24.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:24:59 -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=knzS5y5T; 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]:36534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBab-0004Nd-Up for patch@linaro.org; Mon, 28 Jan 2019 13:24:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEI-0003dP-OW for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7r-0005W6-Fk for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:30 -0500 Received: from mail-it1-x142.google.com ([2607:f8b0:4864:20::142]:55047) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7r-0005Uw-9H for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:15 -0500 Received: by mail-it1-x142.google.com with SMTP id i145so21907045ita.4 for ; Mon, 28 Jan 2019 09:55:14 -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=dMr8GG5RUPuVrWmsKwUgwYyd+2AfoQjp+Mu6L4T+oXc=; b=knzS5y5TY9qvA9tl2n/edK9TKVw7yxQl23WsheGuitS/rKW/gEdD5GvDkpqPy2ZO2e d30ib1yYFBN9NE20BGYb2ShULm6hYR5UGUj7/TywHtxbvPwDrXI8ya9fOZKsU95eW+fi AnnBCcpglcVvHc6lxi8s9NLTYh4UxiPpZrq7+jmYjl8bOnWCPaFSH8EJp7wgYrPEtWCN dsKJCPmtC8U+Shuls2okf+RmS9ZYT/aeVyu5zJuzpNfkGPYBo3oxrgMjXb10lNtnqwhf dc21JXCForip2YcbO98j76u39kdGCRKY696YmHT0K3+OijVQJpkScyPw6EHK+9/An6KV fzgg== 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=dMr8GG5RUPuVrWmsKwUgwYyd+2AfoQjp+Mu6L4T+oXc=; b=M2hwFmb3paP9ttkrLGJ6Z2svgwQbZvx2lD9ghsitnMp7xutKPtHKPnSFJmWyAXbVTP kfZ4mDLVUr5pLAS8pEXYgur/wQJRvqPND09VjZnPhVnPx12RyeSk6R8/WfBbgYt2WaS1 pWoMDDgmXTI7LqsTMMDHcBuhQoqmnh/L4hQeNwBW6uu34pY4EgH3pdE695cwiIgcy8J3 QvjInZWETdNzYuF4ul1Ub3Kx+Be5P0EV/HYZkOxSOXBJCdj2jtw7KDv9HIuF0j+kjY1N P5Dlg3p1Sjm0lysXxFS/atVgZ3/icLyuyQijX09wzIw/nAU9GkzHU8jJussduRhTXlPP zdrQ== X-Gm-Message-State: AJcUukdQbbom8SmALbQs15emmUTBzmnhz7yJJQYeDoq9KPmdZ4LS/vt2 ZbafzSxyYW0UGiXqW8VsOw== X-Received: by 2002:a24:1495:: with SMTP id 143mr10135276itg.13.1548698113647; Mon, 28 Jan 2019 09:55:13 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id n26sm13703512iob.30.2019.01.28.09.55.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id BE6173A3; Mon, 28 Jan 2019 11:55:10 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 1B461301154; Mon, 28 Jan 2019 11:55:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:46 -0600 Message-Id: <20190128175458.27255-8-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::142 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard There 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 3f9ed266f8..c2b9e3383e 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -77,13 +77,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; @@ -105,7 +98,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 Mon Jan 28 17:54:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156839 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3726484jaa; Mon, 28 Jan 2019 10:11:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN5o+EWWb/XbPWD9Og+WJB35nkj+Y1R03/lZfB4QVO/wT+KdNATMFF1HWieJrjj27r1QeIiq X-Received: by 2002:adf:f211:: with SMTP id p17mr22543797wro.293.1548699094995; Mon, 28 Jan 2019 10:11:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699094; cv=none; d=google.com; s=arc-20160816; b=AvJ1OWxlS8Cm6i2rZtlL97W33qFQpaVF8+w5EypTtJUgpFmZ5f/rKjEzg9wdV427ff TxkA6K7UyfBsZuyB6vxN8HWEWs2UGmBRsEUnN/Y3jJZRVUUcQ1Px2nPc2Lu95w8k7JP7 m7HYcWbE2bo2/LH9xPdOegYbyHN2TqdlR0X7vSXtpxeJ66J8aahFdjRW3C0RU8Sm5+iA WpvLOvOiAfzWrkUqTuYuvJhbbx/bU9QAWZUiu27t5+RE1D0cAFLUChh0O4a9uKab4J0Z ewvYfpg4UZijpTNWs+psKIBbGYE+CxfOcyvSlOfBu8VNDOMAG+pe8a8cQ8hC5Uni4xlf vbvg== 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=8zVyIe1cY6HugBqehzuwkdCf1WHIryJGgXM2dZd5dtU=; b=svuzWVNFVxTePD7ae2vZHZ2knvcJaHejcIGBHx/4TyyuAWEOb8+oXSkD/ol9ZljYms vMsADMeWa9JXmthTHHZ4e5K3gu2mtoeV8Ee9mahXp68CdVlhpH+2m6dLe52KE13Cbk90 wwJp9hdsDtNhiBEbtiHPyMQx5HCt3ibNbpdPSEGlTYaSQDmfZvO0KW7Mr4LlYv8+vblG XLHfKBewGOoLP+7TdlBbXY1kU0734aD2pmP9txEdUg0Ht6m1WH9ft//cU/xhS3JcvVrA FGh71LpQUm2MrbV3ls4d3KC1dwz4ET7FM34HbY3fL8CXrwLK4O3HjdifAaOHHXTExA7r e6sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="TtA6V/Ma"; 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 g7si75470wme.195.2019.01.28.10.11.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:11: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="TtA6V/Ma"; 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]:36352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBNd-0002qs-Tr for patch@linaro.org; Mon, 28 Jan 2019 13:11:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEF-0003Zq-Sx for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7r-0005W0-EY for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:30 -0500 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]:43120) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7r-0005UU-9D for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:15 -0500 Received: by mail-io1-xd41.google.com with SMTP id b23so14206132ios.10 for ; Mon, 28 Jan 2019 09:55:13 -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=8zVyIe1cY6HugBqehzuwkdCf1WHIryJGgXM2dZd5dtU=; b=TtA6V/Mac4db4NB8K83uk1e61SvGKgMEUuivqYz658VsUUKqdFM/XxOhPJwupmbIFN Rcl5eRskTWzfs2DmQqEvZMadZvrrcQXecUxG2qynbJU9x19cmI//j779fwt1kFsoaJv9 2EbdgMT0kxhbp0H3F/wZbmxuJ0gWkwmrTK6Dix5a0HL9TONFeT+3bZFxh6eq54c+jG2M D/tKLYRIubMj6PL+Bfug7ftXwBD0/IMuS937ArsnZNonLXm/7iGyMxrKKj23dfhyudV6 S8edFeEGEevf8+Kl2/c3DoEh6yrJhc/v5Yd0d5HNoHd8lGMikIjyTuPm+aglAwJ2kiwN lYBg== 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=8zVyIe1cY6HugBqehzuwkdCf1WHIryJGgXM2dZd5dtU=; b=RE7zfA1l011W+OYvUTARPprKuFrgp2gky/I4PYZ0mlUxQDlAZAghZh+We87tXkx77v xTERecKrecVCB+vh8gt/sh1vCN0lvmVKyKsdrD35WxD9dlS8Xws1XttdcLhjwHBWmDfC 5Iaci+DagRZLkxgA9y6hAm6Rkboe4YGabILvdk3FjBmdW35LnMeep25Ec+TEK9s/Xmji JJORP2z6BiGjz3we6oLY1DOAbQqyJ0lfLpYpPjO8AeGuChGQzFO2wb5qd15ebcCPy0cx MhNUnAMZ+lqoQU3JPaVuwzmrEBCNvx1tuelbeXsHThy9mcUvQlN+lIlQeZpjCEQYiYM2 pZjA== X-Gm-Message-State: AJcUukf8Ja3ZNLxW8QQc4uMc3DE5viRwYmiwDBuqCu63WCYhTK4qyKh9 iJgZ2ZlfxHj9ooyOWbSqxg== X-Received: by 2002:a6b:900b:: with SMTP id s11mr13359931iod.159.1548698112686; Mon, 28 Jan 2019 09:55:12 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id 193sm41954itl.19.2019.01.28.09.55.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id E573AB93; Mon, 28 Jan 2019 11:55:10 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id D209F30054B; Mon, 28 Jan 2019 11:55:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:47 -0600 Message-Id: <20190128175458.27255-9-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::d41 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 c2b9e3383e..4bc579e69e 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -36,13 +36,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; @@ -95,7 +88,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 Mon Jan 28 17:54:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156833 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3722474jaa; Mon, 28 Jan 2019 10:07:35 -0800 (PST) X-Google-Smtp-Source: AHgI3Iav2Jfno50hXK6kN1GakF5fIWREtPYLJOFesATlua2Z4o9Ve/aG6uSn3pN2XGy3y2UNLtp2 X-Received: by 2002:adf:a743:: with SMTP id e3mr215368wrd.56.1548698855897; Mon, 28 Jan 2019 10:07:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548698855; cv=none; d=google.com; s=arc-20160816; b=vBVMFcOH+1119twcg/eZhWY7TBxDf0B/OIGa97Kxlasj2/0HUTi8mLjMGqWvXBQyf+ OC9Qi4cttHbMOxNSVZ8GQd0v5nNHV2hvOsPdUDcc/O+U7+FpwxibOzFmQVuFBdC9F9Yo nqjT2R9lZxv7GNBk4SjXl5FYuFXpWapU+T9IW65c9ud0Fqgz5Zi1twVEY9wUz/O5DcnS 9IDiODHKQaPrWQarSojiw9VVOsNSAofIMUUVNhQYmuVnfyJ/q9OwOIBcXvF1XrgWMg5/ P+RxmkYfG2q9eBdDcEsF+2ChiDyfpzPCJkheHod+6ZxDtkFAx3JEsgWojBvwODZvNmK8 SbYQ== 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=DeXSrCT3B6p8DUPYURe2MDxRH/yvcRPnqNQHR91f/+o=; b=kdNicqgOm1KaZtgONESSWiPGyYeZd0EJHYRNZX2WFmb3iFMaYyMAtHJyNkfGoEodEl RFAnPfhbR51UzjJ89HGEQnmYtpBzaybpsALegRsyMsPEhn8eumfmHzWlLIK9OrdXZCZc q6cu4NrtRHOCFSEKuOzNySI95LAqT2ELlTWD4plM+45YIK0hsKcShixLNvmuMxo1SGTL 5X6E8d9WZ3fbkg0WDww9oQ725xeq2wZQViFyjA9uNtioVuIHFNlQj/V3Ay+dpXjvJfbg JDXRpqQUKF1K0t+U0xQW/BD7f9cZM7I9rfbeYuA7ShH/TksQSWukI5zigIAOq/qpnTcg /TvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dQcFAWcg; 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 p5si78101757wrt.259.2019.01.28.10.07.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:07:35 -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=dQcFAWcg; 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]:36288 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBJm-0007pe-3A for patch@linaro.org; Mon, 28 Jan 2019 13:07:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEG-0003Db-Hw for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7z-0005dh-Qz for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:36 -0500 Received: from mail-it1-x144.google.com ([2607:f8b0:4864:20::144]:38418) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7x-0005YU-Ih for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:22 -0500 Received: by mail-it1-x144.google.com with SMTP id z20so20674377itc.3 for ; Mon, 28 Jan 2019 09:55: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=DeXSrCT3B6p8DUPYURe2MDxRH/yvcRPnqNQHR91f/+o=; b=dQcFAWcg0BjT7ub2/b95TpRcODFMuZq5o4+ehwGSAxjIcmZwwwy1NLuiTtWn/InFgs sD834gChUICu9WED5l6HbLSyGwsu7FEQvBO24O1Dwb7B26oBhhKqPZ1mBJhCmocKZUGB IevcOrpP69cphxGQPKRVIdFMsE+NTRl5txU9eeZc+e6GxhGKq87gNQN1w7uKgEYkA3BZ zBdaqv7L3lBwsOsI3GnLVZw8iGgrXIz+i6H6YnYBFkkNuh075GNszhPboGUvNRWr+TWn W+nGyWYegLmWfSe9B612y0/NP37+BpPw7U55nkhmnRW7EGBfdkQ0LRv4MGEjDysZdvyl N66A== 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=DeXSrCT3B6p8DUPYURe2MDxRH/yvcRPnqNQHR91f/+o=; b=gF3vdIehvPftYv3S18pkIv28D3FshAuG+TVioPl9yhv+gqiCsc/Y4S1Qq5IdDquuND r7CkQV4DEipkrRG+EmF1rnwODcyMxgnQpKAy/Kl/mPTVwZ7NSQHkfj7L+UNHF42kA06y VXmk3m0Jo136RfKl+0IZW2uLE+CxC7fySdCDGW3TwutzAY3h9qbV+hbUYT0ZUDyZoKBR U7k0d98D+qeM33OfqxACMrGL48MfhXuOXDeaEO5KTqXu7lY3C2G2OGv61OTHdJlzLPwk JeC3iWeEqTokcZqGVozojGIGInnAfG9TOxXHL1XNYwrtxPlaOvfjNGhvwh7A4Wyk7FeZ Yakg== X-Gm-Message-State: AJcUukccAih7dUeauPtXzHp6R10tw0GTYK4/FpIe/2hs4Ih+mVkWFmW3 NSBv9kL9Dosf/wqR9kZAWg== X-Received: by 2002:a02:183:: with SMTP id 3mr14160742jak.130.1548698118421; Mon, 28 Jan 2019 09:55:18 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id y76sm49429ita.18.2019.01.28.09.55.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 09283B93; Mon, 28 Jan 2019 11:55:13 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 16547301161; Mon, 28 Jan 2019 11:55:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:48 -0600 Message-Id: <20190128175458.27255-10-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::144 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 4bc579e69e..62e634c745 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -41,6 +41,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 Mon Jan 28 17:54:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156837 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3726038jaa; Mon, 28 Jan 2019 10:11:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN727XdgGxp31LG0VCqp5RqXoh4DJ8ek+VCEulx21GJwEPh1l5GL1gDT0Zg0I/QnGw3EA2cy X-Received: by 2002:adf:8421:: with SMTP id 30mr23434836wrf.153.1548699069371; Mon, 28 Jan 2019 10:11:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699069; cv=none; d=google.com; s=arc-20160816; b=UWd3S5GWDKr1Wa1rbaGTcmgJ2u8KRqCVGRp9vlwSKxyPLXsgjaNTdj827TldbytoCM ixiZMH4dMiA0YpsTumfmQ5JvQwVdxmYk4aSjtbZOioTiVxDaaHzZbs0wJXwTafNHGLuI CQDAORC0SbrO6yFIVN6toBrQbCuO2ExZqvQvGFGv3HiORPTmGEP0b4j9HUY8TNRhordp SJ2RBZswomtviyXAuKaCVIuRAEkQzBPtUjXO4xL4HGm5KbG8oqCXYKkvJEX9e6IfBQMf c28fETY93DMC/ihkC8c61B0FPbhuz0EBZc/oN7HDPIAT2A6swopxWer9/0G+mzG6H+cL 4Ydw== 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=l40kzKz9JkmeTlxEE6dSQ+1ie3pa28hzwK8gTnRGwPg=; b=faB64uQuzept4LxVEFwm/cPF3m2f/TpBXjkDcy2NLwRbtwdrDPm3p6+L8Kn3k89XgT E/Y5/Ef3Hzi/e00yXhoUQtFrOitAsq2SetI9TKhg/LGTQEKmP2W+T3jctNzKMThJJ0I4 wLhRln7ZlAjN8ioIowi7orq5GJhL6HPracsBoUDlNb0WJZqLomsMnL6gd2pGpZATXrUC tIE9CWePCkCycd1WSnyN/T589/DCEI3cGwd9olDW3rRC4uPLI0o2rUb+TIiITBPiMk85 YEDU+BrnDLccE9Fsn8xnppZgQdHd/w14dp2mwSpAOmuUw73WhGAcA2uDQB4rww8LCgqm DLrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=IEPu7eA0; 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 m6si61325055wrp.29.2019.01.28.10.11.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:11:09 -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=IEPu7eA0; 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]:36308 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBNE-0001Wq-7i for patch@linaro.org; Mon, 28 Jan 2019 13:11:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEC-0003Db-FW for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8V-0005ug-Ka for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:05 -0500 Received: from mail-io1-xd43.google.com ([2607:f8b0:4864:20::d43]:42314) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8V-0005ZL-Dg for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:55 -0500 Received: by mail-io1-xd43.google.com with SMTP id x6so14214373ioa.9 for ; Mon, 28 Jan 2019 09:55:21 -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=l40kzKz9JkmeTlxEE6dSQ+1ie3pa28hzwK8gTnRGwPg=; b=IEPu7eA03x72+0UE/cJWjQwiqAmdpmxsWsl7Zvd8zrwBSsJbc4SvK7IM+y7gwyts5C hiI+wWLorIhd6it1Sj4IZ4+kS1SAhdG5wL4ZYlGjZMZH62urw/zRCSTsxIJVHa5yD6+P 1/d10QQ+Pd8CXi/lyMD/5uufjIS2K1Ysz10DJdhHO+5i10orQTmJUDMvujra+XONX0kQ D2DF278iVuNXVe9FR2ZvHzjue4F/4v/1pN5uSyiEp91PIjErl0E1o55KDkxS0irHd3iH Zd1GWs20Hpb934yvXJO+4dPeA+nUmeoRbNETB8RWyBM26t3ieZAuPdnzR9p5LHiVHMzS XtLg== 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=l40kzKz9JkmeTlxEE6dSQ+1ie3pa28hzwK8gTnRGwPg=; b=eIrWqkwqHyt2rcJmdxusczUp8zYdandPJjkz6o/Gk4L1WL9YHqW4suEDWpSLmXi/5m OCTNlCq7Ra2SkrWfhZrIEDdsZclYiaTazaipwyM47N/ofqjO/DcBHkGOPZAvpY4AZTRI 9UHBiMhA21VULhXI4qm/cEGeFPCyNJT0glwtM4LkDu0NKiY9TVVuPz19I1WRWjJdXuOd OFvdHo3x/rw2frXgIsjJmPZhYuvgj+vmaaxTEEPotYsZnuMgNPF1D+LJWbYI06jXwIUR tNIr3PO4g6rzGdHPM7EE+opXJ5sa0Uuw25s1SJ8teoU5IUPi+QSoj7fdTTY3rW05jMaZ sVzA== X-Gm-Message-State: AJcUukfhbkcsABuDG2FrUMKwYs8Wo7xPbKxINo/LWeC7KOyLjmndweue ymntUCDDCHQzwYu1kOsB8Q== X-Received: by 2002:a5d:81c3:: with SMTP id t3mr14317023iol.93.1548698120430; Mon, 28 Jan 2019 09:55:20 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id p20sm14065538ioh.0.2019.01.28.09.55.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 42E2CB5D; Mon, 28 Jan 2019 11:55:13 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 7017E301160; Mon, 28 Jan 2019 11:55:08 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:49 -0600 Message-Id: <20190128175458.27255-11-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::d43 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Eduardo Habkost , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , Paolo Bonzini 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 6ba163ccbb..a8331b82f2 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -431,6 +431,7 @@ static void pc_i440fx_machine_options(MachineClass *m) static void pc_i440fx_4_0_machine_options(MachineClass *m) { pc_i440fx_machine_options(m); + m->smbus_no_migration_support = true; m->alias = "pc"; m->is_default = 1; } diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 1689885cac..bafc73b2d9 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -368,6 +368,7 @@ static void pc_q35_machine_options(MachineClass *m) static void pc_q35_4_0_machine_options(MachineClass *m) { pc_q35_machine_options(m); + m->smbus_no_migration_support = true; m->alias = "q35"; } diff --git a/include/hw/boards.h b/include/hw/boards.h index 02f114085f..e7f7b85008 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -207,6 +207,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 Mon Jan 28 17:54:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156844 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3729055jaa; Mon, 28 Jan 2019 10:14:06 -0800 (PST) X-Google-Smtp-Source: ALg8bN5ZwH9AfWbvGCuX57sh+xInctnlL5ApyqPYdbgFP6kAc7gs8A2RNxa4lGTGbtgRMU7Wdxb/ X-Received: by 2002:adf:ec83:: with SMTP id z3mr23473108wrn.264.1548699245970; Mon, 28 Jan 2019 10:14:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699245; cv=none; d=google.com; s=arc-20160816; b=hXZx320yarvfL4dhwOMzWypC9a6mEwtD39e6PGNKmCFWNRVQiViVHPCy0v2zbeaCIV LAjYBRM9rL7N6OIeND+9srpxDCo8vXvz/LEPx6/cKpWGKYonCphtVDbObshODmkApH+T 8YUx4f+OT0ejkqxWaO1fAVcE2phdmMM2gktgS1hq9/Aqqgvi0s6OJN4EN0ItFHdfsyW6 NrmUCkIAMMWG/egUZlBvQsswDIsh6ndk+nyM61rReK6uD9vkywgW2/CEMf1I/uXmLSv0 ej5dTXJ5ghruKKIADWpggyKk0XuJmOVfiVvrB/4RcriJBLEKOMcRpQArflfftgazWVNh 4Zig== 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=ne4dRzP87htJ5P0OTzpCblnizm49m/70OfaGK86YXzNs4z0B+XT+ck1tkhiKCMUjS0 PR6RFMoEPsO41rQdxzIlnrEZy9ytGCrEt0yko8lyVgO3RJ/etGzXurB8t85w3f+WThD5 k9Etu4Ze1b2/1zMzMd2XEOr6paEEVHFdE3aJoY+H0QqPA/u3YAWi6Dhwa9NOLwvPSbEH Cdo0MEBE7X1sNxddORVbMFLRyQE+KYzsyt451ZOAg0nPE5/vuJJ037JEp0imFCHvawZp dvFOWHtvuj51h45WXv0sgbVgEmvr4pl5lxofiEIpTKMUpW0dUMeD1Ni78k0b6+VCiFGS /mDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=qhL54q58; 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 b8si95497wmc.115.2019.01.28.10.14.05 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:14: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=qhL54q58; 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]:36366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBQ4-0004Hj-O4 for patch@linaro.org; Mon, 28 Jan 2019 13:14:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEF-00038N-Bs for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8B-0005jK-R3 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:48 -0500 Received: from mail-it1-x144.google.com ([2607:f8b0:4864:20::144]:40374) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7z-0005Zb-Pm for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:26 -0500 Received: by mail-it1-x144.google.com with SMTP id h193so20646663ita.5 for ; Mon, 28 Jan 2019 09:55:21 -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=qhL54q58EE7ueKU4jeWTQUK7BVJMeymUBdM38wunecUe6k75ijrl4p9ASyj8FXpnZe x3qwph41pjyNU7KUH706iwHR4udQ5ffRqtw8YeC0yGvNjz7NZ0EeofF6r9uJz4906pIS 4SbF8DoHjSEblfd56W0hHi6Q3KlaMdfgIDe/fk9EHn/3BvV1R/bvaJ1CMBJMEocVvZD2 vXrWxhyKnp7TZX1hWNrKKlvReCt0C2WyDx95LtCmjueh08/85+IRXKBH96BwS4jo7imS /PzqgZBLRjNwaA301//cnE5fKbjbzECEmeizWyCzuczoh4Xt6cRm8HoVIHOc8fRTsuil IjVA== 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=bf3a2QXerpXI0CZzugi+PLjH4LUJKpCE6FuoO53NomIm6P4B7/4LcLqgAvU4JKP9ZJ I/aYVgO1tcVzJWbjVhTR0yNuFd5Bsj2IurNDZ+//oPKy3e99TYq7AibZ5kB7k2bs1bNm Cc/nnRwIgMURIMEKAwKJp5v5BPZOt/rdiGKKMnZS5r5kkkWMM2t6eYde1njBbmMpMqpp mSYgPo0o3Eq0SODB1JftPzoCs2GauZeLWqZ9poPshUOd77UIVqeK20QmzFkCrXCw4MNy QsqkUtt5g55i4PZgn4zVO3iEThiJApgZdxI86h3NU18gRmJ6KL269nbJgTibK9kuuqP/ Bo+w== X-Gm-Message-State: AJcUukcLEJq22pPSS0lVyrRuC7kaPWUGro74wlL0uqVaqtiVuqMTn985 F5gatDbp7PfTc9CQnY4qUA== X-Received: by 2002:a05:660c:91:: with SMTP id t17mr8989085itj.41.1548698120942; Mon, 28 Jan 2019 09:55:20 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id x10sm13631834iop.54.2019.01.28.09.55.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 54E2BFCB; Mon, 28 Jan 2019 11:55:13 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 2CD3D30115E; Mon, 28 Jan 2019 11:55:08 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:50 -0600 Message-Id: <20190128175458.27255-12-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::144 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 Mon Jan 28 17:54:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156846 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3730583jaa; Mon, 28 Jan 2019 10:15:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN6gykgX7Yd/zo0rSqZBKcdpICv/CcRjKGqfLcwJlBmKxZdRcFKXmCQfL0bY0eiCz80KslMv X-Received: by 2002:adf:cc91:: with SMTP id p17mr23161956wrj.118.1548699331047; Mon, 28 Jan 2019 10:15:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699331; cv=none; d=google.com; s=arc-20160816; b=vzqc+W6yqqoya3t0hYVxkzZ6Oc1UC/JocRP5PZGsAdCH1MMbbZ8i4/KijcY2AYBTlr pdmhoZX1t4AK3KGV8LpUsUNMILOe5bLlEedm/vnf6kSQ9PaefZvOhEx5TgX7D9Hao+57 aeuGoIikPzmkj2Z1LJgwKxDFbPXMNCWeC+Sns2beTmM4K54uam9MYi3ViJosz+CIFXM0 2Utq1a0p8Zi+nveULHrBjndV+Y9ZShbUwLU1rdkqs1R92qzgMcaZpU+q5819lDJEYhJk kgnj5Crts9GevCddxQU48GW0y1i4aaKUa2ZQEy6ufmq/Q8mWWMd6FDDZU/4Njc0l38Ig 1CmA== 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=ltM4+I3qHaykWyP/d2lbXd6SRE5C/Fu+MXwEkwid/GUgcJlXf/SpcviLOja4W37yUZ ek7cRAgHIQxalfzLLrlLNMB+rmRN9OTjLfJhEry3Mq7lPwWfzlCJPq1QB+Yidq87GSk1 owt2N3CuEhQ21A/DVJGHMEDhyOYRTXm297xHxPLoW9L6eKAUi7Uf3ywm7GIyUuZZOh49 Wmyg4jlAQ8zKz3jrkwLyoULARaHw6FrSED3+l9YEouE0NRUhWvmXZ5QR3igLjAiNXikm GoExh0ml+scny2E5qRqAhrA3G8gOWjk9LtOjPKq3snP383+lbiw/DAYC50FMVTp3wbIm EXyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=IFzNiiiy; 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 b145si95247wmd.110.2019.01.28.10.15.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:15:31 -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=IFzNiiiy; 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]:36381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBRR-0005Uc-VY for patch@linaro.org; Mon, 28 Jan 2019 13:15:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEH-00038N-Vc for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7r-0005WG-Iw for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:30 -0500 Received: from mail-it1-x142.google.com ([2607:f8b0:4864:20::142]:53885) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7r-0005V9-EW for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:15 -0500 Received: by mail-it1-x142.google.com with SMTP id g85so21920893ita.3 for ; Mon, 28 Jan 2019 09:55:14 -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=IFzNiiiy+t1QNW7H4egkEEF+YbWJL3eNGLq42QrtXC4QWkNcEslBo/G28n0rSdeor1 5p6saF+J77y0S4n/SGNPy7QGADFIYHWjMwtZe9k9fb1fjZlcyZE6DsExwGYktsOKRUcP eJN76un2y5Ysga34vT4unvypFevdnF26Tk6QEs6lywivFUoZmA+fY3Sdmku7DNsAbpUo o9YZ/Oq3wkuLcoD+m8MbSVXBG+gRlvo5A6NjoivR9WfLUhaTEk8lBIBNnbfC1SPDpKKN B7OEfP0xtVEdci3zXNRVX/KDLcYaqXQCqP6iMS6uRiT3F3CQD1BKnm/IKTSC0LEuepvd VfAw== 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=t8PazKP8O02p5qIxGxCe/Lkzb4+iy8ks+hY1xD8JVfhz7n14o/C1iN14NoxgK8I1V2 sivBjJrgvJ3FEHlPpNA5//VTVg44f/w99yramyGVMyxO0RhY7GFvzfmG7Dy+18DTPRl+ TwHnu5G34rCGoNdcQkUVlr/O1NZ0ySQq7nRWEjeI+5cDAmzN0+/D9jOf5OQrzIpg8oic qqCK+V58XpJHkseOYKoES9dKS/y3TqgxdCmIawKmuUlVb95RIMncg571eqVnUqCTMbeP LXCckhpFlsdI5Vc4Aj5g5piQKcGEP0OLlA2fCLZb5C14ySAZ7NuFxBTax1fua5rrE9zT rb9Q== X-Gm-Message-State: AHQUAuYNpDInjysVOseUCNrbyfwKIbVHwdngU/taPXVzWI/+sXywEQe5 ehK5MNNiu2ze1jd/RJ+nyg== X-Received: by 2002:a24:ac02:: with SMTP id s2mr11037971ite.94.1548698114251; Mon, 28 Jan 2019 09:55:14 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id q197sm44771itb.22.2019.01.28.09.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:13 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 747CDDF1; Mon, 28 Jan 2019 11:55:12 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id EDE0F301158; Mon, 28 Jan 2019 11:55:08 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:51 -0600 Message-Id: <20190128175458.27255-13-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::142 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 Mon Jan 28 17:54:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156845 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3729218jaa; Mon, 28 Jan 2019 10:14:16 -0800 (PST) X-Google-Smtp-Source: ALg8bN7HsB/iD5p/7iOxUGb2faIc5Q0cD4p7y3WP3jFDQkdFu0NWnwhy4LeNla2YIIwtLFFnsM+Y X-Received: by 2002:a05:6000:108d:: with SMTP id y13mr21863712wrw.135.1548699256097; Mon, 28 Jan 2019 10:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699256; cv=none; d=google.com; s=arc-20160816; b=ZwiRNR6rS/vzabKF0vW6YFEw3HMbA7Md9Le2+Kja00wsxcsb2kKgVHB/2/tdSnAiHf FEVt8ddmzuzv4a7TcmXCsLVFvIcEwEO49BdL1xbbt64omDt6Zua3PLLkv2KrQD60HaTs qfCjUR/ILUTwkXP6PhGcrf2fluGm4J15NEYVt/HtOGe2OCR6CeG5EDABLqOw0hZiy+Hb f3TXVovWYiKHuyVNAVfvQPZUtzuc0Re4vWpvp1UZ9Qb316PzfrPe5u7Sd5OWxlx35RWu dChfBMSOBpwkxA0K/K9xDAeSYSQxDoABQdb4DJbE70KbbJiHUeElfNuiNlfF2W1LN0WV 5wzg== 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=Ysp9jG7buWT7lrGZ69hqgy8eTQ886skoQ080vnSGPR8=; b=erGmCgyQ/kD7GJjcUeHYnV4O9rIz5lFeKqHkOGd2xWWE5vajzW5drRI5x99biFyh+F 9UiuyARoqxUk0QwGPOr+PU+61zt1IRBd8tOhR7cWsxbQEGOBAxqzaaOb7kdNXYgiPs0H 11cx0P/AqFsi4YgBwATvB+JsAoquV+rPCxH0NiEfahooZWf0FQjUEidYLth2yl0Jxlqt keeHVcChlFlrmFYYq3lnTdLMVbgEvVvFYwjx2ey80qr2+UrJN5evtMBVeeKsE4HOZObM AG4ePSSc9/xklgfIYVMOV4Aq08WsXsTxSgzCqTbHeERIeE6bWlYhfJaTNLKyVI5O0/HW 5SHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Qm5vVuXh; 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 p25si96896wmh.85.2019.01.28.10.14.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:14:16 -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=Qm5vVuXh; 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]:36376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBQE-0005IQ-Si for patch@linaro.org; Mon, 28 Jan 2019 13:14:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEH-0003dP-0f for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB7v-0005Yr-Rj for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:31 -0500 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:34310) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB7u-0005YJ-Nv for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:18 -0500 Received: by mail-io1-xd42.google.com with SMTP id b16so14263903ior.1 for ; Mon, 28 Jan 2019 09:55: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; bh=Ysp9jG7buWT7lrGZ69hqgy8eTQ886skoQ080vnSGPR8=; b=Qm5vVuXhxnwPOb8UNNJWQdyu5W90zDfdpcTBy9u8TYfosqaZrXbYWOTtY2ZIulKyCJ mw36DfFs1lmb4FW0FpJFXd3CNNJT1NJ+cl6tYFjItk/jnDiCOGXxJzR6b8hbGMjhDyLX o8tbFkl/2Mk6LUonKSPKGcBg6ROybUrokpm7DzsEIKqPBn+W/4346P4ToGIoAH1o/8VU 9RqpHKEBJQkJc2tQ9Bz/WHOUVjssuEKQKHXOXrZJsoxLWyWGRy/OHMzKr2mmWI+HqyM+ njZ6vX1yFLpTzMyhPqG5kC+v3rtD74rArENe6bIvz2QjfEcBDJuHWoxzE2v2++lxeSvW 0x0w== 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=Ysp9jG7buWT7lrGZ69hqgy8eTQ886skoQ080vnSGPR8=; b=XQYHCgltcxIiUEA41LT5DLOx0fxVngrqnynGz8YRDzCRxG35rsRHSrHCS9LmgZwAng /OhPkX8ibDplZ+o/sZCBqw18HCVdBHPVZAVh40ao3WZ8nnoJnYreB7BBiTIMjwWS3917 zaW9Y6zOpjKRKRUn0E3nJ+Ny1f4lEWueLVC8CmUtmTnSWtQHKsyDZpNZG4fpDIgF8xDx mZJ0qh1kfJLboLFrWj138zLG2v1Z6x1AQyqHBAWo+Z5k/sGzKHcHFA3rVwhRzrF1pWT+ 2cqIQWnmWxXbpJn0K+f1Jt4ol2S/9wh60ISLizh8e694EpOq6fB7dnQFV+HB40YkxPwW xgtA== X-Gm-Message-State: AHQUAubGOINJZZrfyK6BieSEW+Nblb2iQnOlDY65V0qVJqG9QdhpMs95 KxXqQy/Jvrfmqt7c7BG9ZQ== X-Received: by 2002:a6b:92d6:: with SMTP id u205mr14190202iod.221.1548698118012; Mon, 28 Jan 2019 09:55:18 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id t70sm50994ita.17.2019.01.28.09.55.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 9318EFC9; Mon, 28 Jan 2019 11:55:12 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 7E75530115F; Mon, 28 Jan 2019 11:55:09 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:52 -0600 Message-Id: <20190128175458.27255-14-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::d42 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 88f9a9ec09..7f8efe9997 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 Mon Jan 28 17:54:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156820 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3719968jaa; Mon, 28 Jan 2019 10:05:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN54ftFK4ttgkQ7ofqZ5j1dvKnwj0DljoWGN3qlibSpFftzyikJQUMGXfXhPjJ7vWHEy+LEi X-Received: by 2002:adf:9d08:: with SMTP id k8mr24056552wre.203.1548698715505; Mon, 28 Jan 2019 10:05:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548698715; cv=none; d=google.com; s=arc-20160816; b=T21Vd+FD/g3nlM3BFFQYa8PCi+ggHN4jp1RcL2f4GtXkpjOcol62P2d471Uh2eNKSh h2T13DeV4EjyMcJ5BesGlBtBWbK7ssC0nZ7Wdo/ewivkxw//Qtp8K8ANLQgp14/roVkQ GH1pFGdW/Wy0C2FuP6BnDztoyDJPfRTwP6yN1+K4dKnLOSW7WxMVyPW8N66/v+V6RTWB R4Bvl4SrVUWUA3fg2m9ur6ZWsnud8I03hL9p5pjYCUFFHgNcFwqJPt8dmkHLqCSi5wdh 615oVJd/7cCgHyiyecvAOooYnmU4wNgu642RxoUvsnVsY7z87V3OIcJKKrAFBXNTmrDD IVUw== 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=pzsRPgiHf17/1PeeSc5A/Y9emLthi2uCzQsRx5ZW0zNavcsROzADEWJh92txBZeyrA +9DEKU6Nk0w7lMcLkLgf3ghPeWW+N7K9JFgs7IYApr1ixTSKzppBwxRJ1JqXUfFPZv96 a+CCs5oaId2U1KOBbQgR5dudmD7bHhbIerr/GIBnlAVVjk/3gewjuDzkTYLKChcYjFsj Bdo5lB6omyTSxun68CvaK8ne/SV46cbg9H87/f+xAvIzEUDka/NTP/QLkOUhAkiav+SV cjUtoorqw1f6tQMg/4NNfS3nZIeG6Oc0xvHsW/smr9YSqtSADNhVhpuKF3NsqK/g4aSe G56w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=quTQ5Lf8; 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 o142si260398wmd.1.2019.01.28.10.05.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:05:15 -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=quTQ5Lf8; 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]:36239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBHW-0005uD-Ft for patch@linaro.org; Mon, 28 Jan 2019 13:05:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEC-00038N-SB for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8U-0005ss-OE for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:04 -0500 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]:44473) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8U-0005fY-IY for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:54 -0500 Received: by mail-io1-xd42.google.com with SMTP id r200so14206443iod.11 for ; Mon, 28 Jan 2019 09:55: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; bh=AoLcNOQ30aKzN3oO2kA4DzR6j6MGF6e7733YDW7t8Z0=; b=quTQ5Lf8vi5SjOnCrGezV0whDhcQPXm+staV9MAsDPW8febVenQnNZMwW1n5IFORg6 wvg4Vx3jMROg94HuvwsdJ2qzMD2+fFoEQo6esoeSK8ahRO5/j6/dNHR43Z09K+C0XsU7 nixwj73N/oXQLyPbxN6puvtMWX0JUh8bNAhCwuJoYDBl8dpyuJIhwZIYERcTLHchDAnW FE6AulUW1gVoe1Z47riekwZ2B6/OfLSc+eHSMsPGNMdGeDoxDUmSXDbS0VCAUW+H6pYE tKi4vY3GaEzkYwvpJ/VC8wx95JfE7FhybKU79pY57WpUFmg5+HSAAFc+BKYRWuvA+s6V 4G9Q== 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=ZKLGyy8SJrg8l/t9Vos9p3N0bSxfWJjFUZ2Qjt867MOMRkt/2mERJrz3NUAQppPe09 cRSDP48NMvlCL9ZbMA0uzad4Y6VizFf5LowmCfrBw5QXLwOjAFueklubvZR3xSrFpxi3 amvvGa7PBEbHs1WAJU0vQJXQJK1CS7c+t3W9mPq5Ow8adXFt2sFOhScS1uv0XX6ljswD IULJVry2Ip3MbOH3ulOxoGpkE+pEWyw9AwTZ7zgc4eecUtbEJqTg67Ov316EzRUZkGtG 41ejscuqVtmNempiYqjFVAgDa6DQ/XMAR56HZO8ra0IxKXFmxGH1hrjQ9abkxm7eTV9H k7rw== X-Gm-Message-State: AHQUAuaTRTCssJNxWsUadwM2TkgI2RoMoUsR8EmhG3KYPZSp6CJxgybl FmWGdaZmiVSHDVKBdJRh0g== X-Received: by 2002:a6b:c8c9:: with SMTP id y192mr12602184iof.183.1548698125651; Mon, 28 Jan 2019 09:55:25 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id e21sm54357itc.6.2019.01.28.09.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:22 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id BAB12BAD; Mon, 28 Jan 2019 11:55:17 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 5EE82301154; Mon, 28 Jan 2019 11:55:09 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:53 -0600 Message-Id: <20190128175458.27255-15-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::d42 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard There is no vmstate handling for SMBus, so no device sitting on SMBus can have a state transfer that works reliably. So add it. Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert 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 Mon Jan 28 17:54: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: 156840 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3728176jaa; Mon, 28 Jan 2019 10:13:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN7gN3c6xlNrtroNn5UY8tj6cqfzwtgHM+wkEhqurl3RfljCPySZjEv2ckGwkNL6I9wac2cE X-Received: by 2002:adf:90e5:: with SMTP id i92mr21811974wri.210.1548699198572; Mon, 28 Jan 2019 10:13:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699198; cv=none; d=google.com; s=arc-20160816; b=AjK+XlLsQ/Cyh1doSRztYzGHD9/cSIaV56l8EL8QSj2IUbdweVlRoYwHFvcTR3rrVC Jj1Ih3OB4ySAy0Oc+BgskAqrXczQtcej6k7aKZrbDrZvZ4SUAsE8bCoArIqfGstsKjLX 3SpiAqfeNsFOfzDx7TsktS1ucC0Pc0z76D/10e1EC57RvUTqPCniFvKp87/ZKf1Bfetp FNzoXpQWA2zWchzo+hMK9XHmlTrDb3hTm10MTF3O7h6Lvo+mOKzDrZQBusW0gaCwj0MR 1Cb3Hk1RvV+VisSOdfuQIymdeVP8bZW9x/imU6f6k1SHVl2GvSQu3koXAcheGxmcTamU rQVA== 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=XH0JtuomOh1872pyaHH51ab2ohSNk7NtbAOrPXjiPwE=; b=lmeQuhWgaghKGSK3+t9YyW3JlVIOaZUf1vTdSb1G3e/rZNwE4F2g5V7jTav4w+19pp U42tjnYETeRARUsxqy+pL50eJUFGmnHW8UTCsS1z8ZYrxVkSI1Lt15wsJGYAfBeYR5R8 0sJ5tfsX1aQosoP646LcCzBnigThAMq3JlWCdoX40FXUiOcs3NzRZ+APcdSa+cIHUQM3 yYkD3ZF/6rSZwRJ0D/grUZKppxorC17nbYK+R6Fs/Gz3joBHNDg2s3cwLAq9hOrCGneC PWqR4qXkA3tasl4njSkNThjuoszBAX1u27GnNOYUvZY6HMTbYmkgDYdmW1xYlImJo7Y5 W00Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ronz2TwG; 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 x186si100381wmb.66.2019.01.28.10.13.18 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:13: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=ronz2TwG; 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]:36360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBPJ-0003Xv-6R for patch@linaro.org; Mon, 28 Jan 2019 13:13:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBED-0003Db-HM for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8V-0005ta-06 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:03 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:34205) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8U-0005cJ-PN for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:54 -0500 Received: by mail-pf1-x442.google.com with SMTP id h3so8353036pfg.1 for ; Mon, 28 Jan 2019 09:55: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 :mime-version:content-transfer-encoding; bh=XH0JtuomOh1872pyaHH51ab2ohSNk7NtbAOrPXjiPwE=; b=ronz2TwGoiGqFeF/fTokk5g7TxeFIUOjQSlrW+u8zGZW91PGBQARMDiCtBp5pBBk9W qkUqOf/YJKU8lIAjuJB7usZbnkAC86FiZoMNYOtwTnJq7Vjo0WbJGhqobn+1mOE0vcUD PY43h6WwlMHGowtBvagi8rB4KrgFm1swzgWbEqmiIWGs5QHlLMJmEiQWZD2TcouD65bt tPXMx7lNW6oInay/Te5rNdefTG8pNQkEOg/OdkoFBBopUpSdx8g5t8a5t5KgI0iLPrhe 515ipCsuE0qe3ry3qjh0kdMx5vrFevmRw5SUTFVEWj+7RUx/Yz0IccBY8+IyhdyXthSU pYtA== 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=XH0JtuomOh1872pyaHH51ab2ohSNk7NtbAOrPXjiPwE=; b=XAHTugXXP6iSPsr6WHK1bRa8Lsj4p8gMngQ6J9m6k1LM01mAXu5j8Pyx7oBwMFFFYf 8QWN3bWnnsy7p11zw/rP6/TNJlk1USS+n5QU5ZGK0e1pfIsdyo8ztO6j5pZt+mojLrDA uWzHml2hm3hBk1h4i4tCP5KzhQbr0gtNDHTt1YABbHQi/Rrrmv7N95s7bs7FKaFa373a HgHK2Fhl3XCvJI1I9nDtzthmUbHjurFEEaHz+bqE7g2pWQOSafZmubtlQZLEJh8wFBh4 aOnTb6+QgKB+yACeHVXiCJjafLzMM01SyRBC3J+6R/NWWJouXvB1u00acgziGELvPk7i ymAg== X-Gm-Message-State: AJcUukfRJZj2tF7/2Kpsk+uA+oyTTDl1RDZwHczfRgKt2Wjjqx2CEYiO Nno8WxJ0SOFTAKVhR8qBLg== X-Received: by 2002:a63:61c8:: with SMTP id v191mr20881248pgb.242.1548698122152; Mon, 28 Jan 2019 09:55:22 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id l70sm62441308pgd.20.2019.01.28.09.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 68F9C106D; Mon, 28 Jan 2019 11:55:13 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 86AF1301162; Mon, 28 Jan 2019 11:55:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:54 -0600 Message-Id: <20190128175458.27255-16-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::442 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 62e634c745..91d68ff588 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -30,6 +30,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; @@ -38,7 +43,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++]; @@ -51,7 +56,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 @@ -73,7 +78,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; } @@ -97,7 +102,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, @@ -114,7 +119,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 Mon Jan 28 17:54:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156828 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3720630jaa; Mon, 28 Jan 2019 10:05:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN6KLBweMSlxybbGFyp7uEtKMObXcrwkWvtrqr2/1QcORtxYRKTYF1No3fW0XMLEJuyGcYRm X-Received: by 2002:a1c:7306:: with SMTP id d6mr17458524wmb.98.1548698753435; Mon, 28 Jan 2019 10:05:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548698753; cv=none; d=google.com; s=arc-20160816; b=ggLDn5dYo1FCQgmubkzW45axZQAE6sOZeLXkbdQy81vweFsNQrJDo9pVvIQh9aytGj CQRYpK7QctbHG4kXAQ0ShNBa4tmHdZFNLZrYn15hMmPSjw7r+3OEGFGcEi02GTGjkUCC m51aqupVCWuY388vLIp73zSt2BJ2N5LsCZH3UOxh5WbjtDOz6IVGL4KDCeJT21jtf2K7 nrC72Y7qI9oxLCh+0a1kAgWGUAAdQJdqqraYYKO/qro/Pq5QDXEwP5j8tT9gTvRjLAZW A8qk+y5I6u1ZSeXdStd/nHu7iISarfQ7uLNi8fFo3I1THJatNdxvEUDU7JSQya6ldhF4 sydg== 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=9BByOpfKlj5BdmNNBOif+f406Blfw2gzhg0xpDJUO0Y=; b=hM54xKHNMPKEPrbe3p0IRlYplJBwgFO1Kz4sA6bV9YCsx5N0M/prHbYXQ0OGny1r3l VVM0B388uovTGg2yM0xivdxQw2Ahm68tdsFkcne+hlg3WQci9otNtpxcowHgeQ4OEjxF 0iXj+xXZtwah71EhlmOFv9TC9O+AIbsh8AqYTrUMxDL80DVGVleQN+ciAv/BzykubBX4 mxQi0xOEmuGMsMlMah+qLhX4StuhJYe4/ejEbu3MSGfLmuk0GOxj45chMnrKbyrdVjLd eic/f1mmMgYmLWffMndeGQrLBoZiQNES+fcywsdIT8WKuUkT4vmsYs6+biqBoT0sMFYc ED8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Vrna27ms; 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 c16si80135285wrp.71.2019.01.28.10.05.53 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:05:53 -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=Vrna27ms; 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]:36274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBI8-0006Vu-Dy for patch@linaro.org; Mon, 28 Jan 2019 13:05:52 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEC-000396-By for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8U-0005si-JM for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:06 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:45329) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8U-0005Z4-DR for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:54 -0500 Received: by mail-pl1-x644.google.com with SMTP id a14so8043357plm.12 for ; Mon, 28 Jan 2019 09:55:20 -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=9BByOpfKlj5BdmNNBOif+f406Blfw2gzhg0xpDJUO0Y=; b=Vrna27msDMEOVJKbz6NAquTcrFpwWLnXSfDrYh4a6/qTjlMQ9UlPkI1O+HXSgl5dLH FBig2fItf6KP5c4G8nA7NXV25POP6lRlbtCNhzxHWcwWs7iPPD7tEHCbvZ3kaOpIKNkN ELfxC8x/sUDWxLbvOtmeAXBflOYpKwTRskejSvuZAkGIU5X/5gqaHj5GbgZVkQWAKf7C jQyXnZiw9Cevky+y7r1qWMBdCKMto7HZHz0Wwe2ZofX3miYp08+KTsUj+ZSz9L5JkCWA LtTYP3yyT79iIGMNORA4df8/p0RY6x3TgNve1evqAoh7ecCAhUS1thC26sEU26rvAAcK OlvQ== 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=9BByOpfKlj5BdmNNBOif+f406Blfw2gzhg0xpDJUO0Y=; b=QoaRoAk9TglzBUU7tfwyqPB/vR378S/2MI6TGyQRABRhZ0y5pMOxw+wSi+1fz9fmDt CAIRPZsK7ajexraEt411wMB856Af361B4J31Rh3TinBuxDs39s96jXphWPG/DFWFTvKu mmrqH9R37jxP/aBcPjXqZf+ixzkryjHLvX1bql5HWb6ZNVxOGl/JOHFomaHEG0SD7aAy DWlA6lCpBJcHLMD9gQh4hlPzhVYl6YcBoYs9XvZ8ZZEJSPY9g19DTVQXfRoCI/IfVWex 6sewgtDTJoZuP+bHDV2UOJHmXnhJNaKrBUUDXzZ7pEhQxqvXMoxuYz9fIzRYdP632uIw VqUw== X-Gm-Message-State: AJcUukct0IhqZ9FMExY1W7KjXcfXuJctKLH3AcbC3XC+PKoTUvrlQNH7 owc3l6wde2MnaZ8VaF/0ug== X-Received: by 2002:a17:902:1126:: with SMTP id d35mr21346176pla.1.1548698119705; Mon, 28 Jan 2019 09:55:19 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id t24sm64300967pfm.127.2019.01.28.09.55.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 879DEFB0; Mon, 28 Jan 2019 11:55:12 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 2B409301164; Mon, 28 Jan 2019 11:55:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:55 -0600 Message-Id: <20190128175458.27255-17-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::644 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 91d68ff588..b3cc9c7083 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -35,6 +35,8 @@ #define SMBUS_EEPROM(obj) \ OBJECT_CHECK(SMBusEEPROMDevice, (obj), TYPE_SMBUS_EEPROM) +#define SMBUS_EEPROM_SIZE 256 + typedef struct SMBusEEPROMDevice { SMBusDevice smbusdev; void *data; @@ -70,7 +72,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; @@ -129,12 +131,14 @@ 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 Mon Jan 28 17:54: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: 156838 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3726294jaa; Mon, 28 Jan 2019 10:11:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN55Mq2vq6gNJFvrFWEwnz0NbydWkpnavPrlNCUX99bwdKLEGV8DVXLInzSqrhvAgKtuz8L9 X-Received: by 2002:a1c:7511:: with SMTP id o17mr17748126wmc.42.1548699084308; Mon, 28 Jan 2019 10:11:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548699084; cv=none; d=google.com; s=arc-20160816; b=h6BMaCFFzf+i+BayEwDNTSGvx9PElZhhUBIqLOuOHlYMwspXeOsfnxys/OXqp/nIyz gJcuUEGT4rGm5CmC8SKb5DDNY+RC1eRvYO+hpeTfuduyp02BKKevmLMCG95X51t8vzOd 5llq2O/PQcp3zMF52pjFIZWH6AHmSdxreXOfPXZcxibZuMFCYxLNkgcZNWPlKRI22rCC rFSLiQpSsJZxxS31PRCip1W1nPEMnuGrVvOYNSzU5RsgBSxO04PZ0JfoUwqPXyosdSW2 saFFEdj4uD3zhIQnW8N7rSvW5WfddmG9Bi/VeSHZeDIWmkiWMWEHl5TOc163su1galuF b2YA== 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=57kh67Tu41hZVnC/NJgxfWgmjYyLR+EzK4WyD222hhs=; b=JcRBycFgrWl5K2A1ECqVlfICzmyn8KVSxh5spmBV+pyuR5POXnzhAY1vFiMwPAfoJy 1FyTZZAvt2lgt5ki+jRliu9IUq8O70HIaN32qVGgGyqwp3dBqkMRQJYZEvL1wtI04jB7 Bh6jshp7lSr8LgtD6XJuyQPilVVqu6Cg8Rhbe8jjVH5ECWBUzjeFoi9DofFvt1ky/UB3 /ieg0b7VS02KOkYh2l8Szz9+OK4SrCaN7ien1iGTrx3dnTBs6YELyHZ8EDLxxmI01QFp K3f30cSlF2B4x68XoCVjzT3w9LEDiMrI2WCxgJzWh0JfB6ahIm7gxZs6L/7Y2JnTyQAN HSLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=VL3xUvuf; 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 f17si85368041wru.378.2019.01.28.10.11.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:11:24 -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=VL3xUvuf; 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]:36322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBNS-0001kI-Pi for patch@linaro.org; Mon, 28 Jan 2019 13:11:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBED-0003Zq-Vc for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8U-0005sK-Di for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:02 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:37865) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8S-0005fH-DT for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:53 -0500 Received: by mail-pg1-x543.google.com with SMTP id c25so7528635pgb.4 for ; Mon, 28 Jan 2019 09:55: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; bh=57kh67Tu41hZVnC/NJgxfWgmjYyLR+EzK4WyD222hhs=; b=VL3xUvufk3QjmbnIAvpO0iSEQbC2c4YLIKhq62LRQknO3Vvv+Jvfyj0Si6PZocihFQ +YL8R1c2Icpq98GO0UlOQO3bxKGvOgHYsa8O9Wop/EX3OG5JNcSOM0J35XZHuh5LEm6V 3Ha66K4IDHOXP+cvN7g7xxByS6pyF0rjGQZUP/s3ih+pxLta/VwX9AKfiKup2ChUlT2t ypIvRVqo7BNRaOGXsEhuQNHafLKdXXYXZCc1z1quOlaWt753k8r25UCyKluUk+ndnJhn ErPgAjPhdAowszz9GVnjQaKIaG6ZFchsR8bM4zhwL6/C7aCkO1DlkElF9ekVEMoy28c5 cXow== 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=57kh67Tu41hZVnC/NJgxfWgmjYyLR+EzK4WyD222hhs=; b=cC7gLMfuQTWP5ANZ3HDYcBkosbRLjVhcY8au8iy8MwllxFrpmteGIkMb7VeR56isqY Wj7J/Zizri7wJxk5q+gnn94/b2qZezBfzYa69LuSyjWDv9Ls1SLi027+w2mU5YiRBaff 4ciei9tBwslPl1R4Hg9jMT3XjxdTufIBIjN486PY/vkTnTSh9+xsqPS7B83+gOX371By B/tg0gwsaZcEH2oiWRnzLucj41XsemRlENRyo6mniFk+HqDXOrgn/fWQl8cUMEqSZbT/ L6ngcaCVhqfd0TZl2q9Nez2VJgvx1PYFA10EES160Dg5CgMCy0V1rzr5ZWW2so+q1KVl h7uQ== X-Gm-Message-State: AJcUukew2DJL1HbCMfEFgSubXl5s9ed7GbWrJi480qph1FweMONtvDGS n9GDB3EKSbqWtt6R1n4zHg== X-Received: by 2002:a62:e704:: with SMTP id s4mr23074902pfh.124.1548698125167; Mon, 28 Jan 2019 09:55:25 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id b7sm53376950pga.39.2019.01.28.09.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:22 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 823803A3; Mon, 28 Jan 2019 11:55:17 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id D04CF30052D; Mon, 28 Jan 2019 11:55:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:56 -0600 Message-Id: <20190128175458.27255-18-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::543 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 b3cc9c7083..c0a0c4d501 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -24,6 +24,7 @@ #include "qemu/osdep.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" @@ -39,8 +40,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) @@ -49,6 +52,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); @@ -61,6 +65,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]); @@ -78,15 +83,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(), }; @@ -99,6 +128,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 Mon Jan 28 17:54:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 156834 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3723610jaa; Mon, 28 Jan 2019 10:08:40 -0800 (PST) X-Google-Smtp-Source: ALg8bN7TzVDhkaOiuxrd5+RM/W5hoJtovMLigSzxd0KOvVFvEftOgw5rWox9ih9aWj2SqTJ3ddzE X-Received: by 2002:a1c:87cc:: with SMTP id j195mr17804794wmd.2.1548698920563; Mon, 28 Jan 2019 10:08:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548698920; cv=none; d=google.com; s=arc-20160816; b=aTYZn6lzLGTGnKZ1MFyjvmSu/dRPhYKI/mQXEHPHzxPfeu3Q3MERvgqfSMV3qflMDu wM8htbgjVp9OTar1XjiEQtXOBl/lBwnML0LdcBvlOs0/XraPJ4nzexzhpfRMUNVNwkkY ci5nZGzwAtKQdSmdOpYwYWAcm6mK7o8fzJORvIAo3Jf+ejAvVeH0tLz5+Jq+KxjzrznQ AywzHUY1v6plQclwoGIV/qVXCvLuEff8WQmqOVtvm9pgm4ax0srcaUg2kPDk0w2dRTzP mCoq5+qz5Qvo7ASmskyij5Z0PMK54PNk9ISSmA9l44r9JwNuuUeOp/RYsr+Fkfghgvis iphQ== 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=WonWmYMnT8u7LZWW1RNFTm76th+WgxeztPZLRKTOfE4=; b=NombUi5IPvjkVCE/seVpNbqWxT6/YGHreeiD1f06gn8M8OhIBtn/1CMtrJsYNZVAGN 4BCvMlombKjy1ZR6iujXk5O5yKa+51GxyGMxAi9d6Eoq/kZH2WMmz42qIvztTe8xuIvn ALui/Aqy0yYk58GYzllei34v/W+je8WPmvXXYIgF0JfN9YxJtdc6nMH9m5eKL4ynEgES AcRAIIc6LLZzsm68mwH8tQDqPh8T0H8ALJW4Izcfp5HcMUUcbWj0KFRtW6Ne5kPmoGcB /+IdSHrdQJdFHSoFf0QLEYiD4hgjbVcqF4VLIjuQ0yCXC0VpsYTwXoPMT6UaOCxW8bz6 5kvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="JmH/T84G"; 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 v76si88373wmf.105.2019.01.28.10.08.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:08: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="JmH/T84G"; 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]:36290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBKl-0007q6-Et for patch@linaro.org; Mon, 28 Jan 2019 13:08:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEC-0003Zq-K0 for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8U-0005tU-Vr for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:04 -0500 Received: from mail-it1-x142.google.com ([2607:f8b0:4864:20::142]:38418) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8U-0005eu-Pj for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:54 -0500 Received: by mail-it1-x142.google.com with SMTP id z20so20674869itc.3 for ; Mon, 28 Jan 2019 09:55: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 :mime-version:content-transfer-encoding; bh=WonWmYMnT8u7LZWW1RNFTm76th+WgxeztPZLRKTOfE4=; b=JmH/T84G/XlZ/0h8GK5SIo7bqvVFU/nja/i8J0RAExoWyxSKvnjH91MJXETDx5d4Wd qRQ1CqW2puQD360YTjlsYPxpD6/WOZBGefOPsIKtDT7O417yTmH4c+69O5vwApCUc0Ft 22+ekcQWnb+VDJM7JzrspvovYXu8My4ucBi1PtPZXUl34M7FL6/jj+UXYj0apxVAxJh7 CrfK68lzlbYSRHYhXQyEwYgo+fK79j70Qha68CsiDVRIVR+4Rk97mcr/iw+ldp70Nn+B i1rPzmM6CETRVqRuZiZkCkTtuPBQusYadBznC68hQRSuYRijaIsUji6Cj16wmSBHG6BI PR4Q== 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=WonWmYMnT8u7LZWW1RNFTm76th+WgxeztPZLRKTOfE4=; b=fbtj/D0oYlLHNbUelFwfW47Zn33R9odbVxnb9WT1SDa6bXObyju9AK3KDjFXtEq4kT zLAS6PxSDc6aaZeG4Wkg+BgkZtqDQUOHvHoczaZdYb7BxtRw0eXhjoNYODJJomBCHVxm VzdbDlo2v0XdZCHm8hOEXRIKUgz3Vt1fPUF2AvRAUJiobYlk+dc3lfvl7qEoym6PltUv WBlKfGzccHMN7WClhSLi95opWAWF5qAzZwU27I0MhtaPGZetIxGadMapLd2+Y9srG2fj J5muNfZrRbp+zsG2n4SLGU1J15RNm4rXqgP9oSsh1eG4mOH3k812Ecxrxy+2z3NCEwZX aQng== X-Gm-Message-State: AJcUukduEG9bZL/+KcthfIElCZ4ua+y2PjLHUzJplVvMvhw4UNZOlgvX LDQ/K75Ttkl6Zbzn411WwA== X-Received: by 2002:a24:ba0b:: with SMTP id p11mr10809557itf.113.1548698124649; Mon, 28 Jan 2019 09:55:24 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id 193sm42060itl.19.2019.01.28.09.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:22 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id EFDFCBD2; Mon, 28 Jan 2019 11:55:17 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 95CEE301156; Mon, 28 Jan 2019 11:55:11 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:57 -0600 Message-Id: <20190128175458.27255-19-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::142 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 c0a0c4d501..44887b4a27 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -106,7 +106,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); @@ -114,6 +124,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(), @@ -125,6 +140,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 Mon Jan 28 17:54: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: 156825 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3720431jaa; Mon, 28 Jan 2019 10:05:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN69glFeAoZsKauRClwyVcOCU/eDBOysCquR8+9yVt7DVMLOsWRUf+/V6M0rldFCe+73aFEi X-Received: by 2002:a1c:ab87:: with SMTP id u129mr18201863wme.104.1548698741099; Mon, 28 Jan 2019 10:05:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548698741; cv=none; d=google.com; s=arc-20160816; b=SNd6HrLmTGFglM6GM1wrDH2Do3rELYuHPv+jO7GpxAtnYyBAlMcn7H0a4b1XUzzZrD XD722cwVZoqsPQao69LxAuoYPU2DupA4CvLygK3xJ+Nqp5XbVqouWm0baseHzamnCx3R VUBIN1iGCGqCnK60FmPqCGT+RHeLKAfvwcKFGZIvtwQSznpnzDU6dkxBCldiaVD9hx+z FjNkXPx87TMoDQauDn7yOLsz+qLDa7N9M9iJvlSwaKFXEbuvkKQxOPFBhRmKl4pXamWo vy+V8gaQ/5+hy+PwahTJj39Es8ORGjiWxMoUbo/35bzenL/RRocPKLCqv6aLqAPuC+kx nMpQ== 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=vUBNL7iuL2tms8dcSHLWhPEfJJ8Hjvn6D7ICUweDvw0=; b=uDZkhGc3p98a+Loa2wEZr/SgVFCeKepKh+dFTxVUIcudvFFJmTDcsw69iIf9PEE2ZT D2UpTsbpn32vHWSqn4Ilol+qrcg/+5czEJP+cCElWwMytxR+bmP+vBCd3KzMgOMQcn4c ypU0jmQj3iLB20N40LmL82l3PavV/ENWiWv2IEsafKxVZJMHvRUYvYo2O4oTc2r/6LEJ iAZAAhQzS5Mh1jlzZsVTgPmA+U/w5/YGq+DO+TH24XdEcGT70wNqcAVYxhlejc8p5ZjX /rVmooeXwVvDuNy8uZ5Sos8DSBR9D9MEoSZukoVZSWqdlWJYZ7MSfQbLl32ngZnbSHKn EQ1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=H6HtgR0p; 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 h16si77586106wrq.337.2019.01.28.10.05.40 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 28 Jan 2019 10:05:41 -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=H6HtgR0p; 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]:36233 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBHw-0005OK-4M for patch@linaro.org; Mon, 28 Jan 2019 13:05:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBEB-0003Db-JP for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:01:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goB8V-0005tq-AD for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:56:06 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:40548) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goB8V-0005gC-0d for qemu-devel@nongnu.org; Mon, 28 Jan 2019 12:55:55 -0500 Received: by mail-pf1-x442.google.com with SMTP id i12so8329606pfo.7 for ; Mon, 28 Jan 2019 09:55: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=vUBNL7iuL2tms8dcSHLWhPEfJJ8Hjvn6D7ICUweDvw0=; b=H6HtgR0pz1DUvhzywy1BzBCsYFiWEu5VFy+kYQpl1PGQcBBf/BS1f977d6bQZqn+SV dzoKuorLDsesmBIb1/4J5Je9hA4NrGFpyibbq1A43HeXfc53mcwCV8KarrjHU8pZOLky QE3TWmhyho3LYmC37qdS2vEkCKBRvnVMCTgvhmAKdBaT054aDuW6n2NmZjFoDPBlr3jY sshs+a0WPa6KKgAQwgx31wteb8ltpCx10Ozf996lbZ80JCDj8B+CKeAo4PIpeepW2oI7 HTbFebPg1yqwOIwz+T1E9oqbZ/I+9PTAycN7EBbBVpsaRwjp3SqB0PLkJMpkcraPYYFn 83Vw== 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=vUBNL7iuL2tms8dcSHLWhPEfJJ8Hjvn6D7ICUweDvw0=; b=om205cV1CMZXDNM+BcS5woRZ5AFVOq4wo0zQeZkChF8H0bjVqsvyY2suNEnxkr0HzW 6pNIbUAW5TxfOs6TU2q2qhStVsviJpe8tj3PJv6lrKiRCE2AHKVK4S432KVuN0icuQcX S/HYTuxMdzQQLuhZVRaW0pHe2c8rRAGHJ++wlVzhPaBSFHRC+NLFH59AwZS7CC4PHKob JwAJwXooGd8wGZWi41J7NTdqL2DSMKmCBDRBdmec2QovEirydjr9qnuZ/GVw3LZ66izw Zaw/DPvboD292ubkzwVk8HLRBqnFtAmLhM7AVYKxz1WkddS25P8vLwBjKBI7/0P5k2nj gxkQ== X-Gm-Message-State: AJcUukcoiOqxo4YIJfPDp3ozOt/+xBMRmb9eBiz0urnZV5zuwuMSEv4H LZBO+Ih9+h2IBl4/I01zfw== X-Received: by 2002:a63:ed42:: with SMTP id m2mr20756223pgk.147.1548698126981; Mon, 28 Jan 2019 09:55:26 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id h82sm68862235pfa.105.2019.01.28.09.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 09:55:25 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:c8f8:7971:e432:a838]) by serve.minyard.net (Postfix) with ESMTPA id 23BE7BEF; Mon, 28 Jan 2019 11:55:18 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id BAB4930052D; Mon, 28 Jan 2019 11:55:15 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org, "Dr . David Alan Gilbert" Date: Mon, 28 Jan 2019 11:54:58 -0600 Message-Id: <20190128175458.27255-20-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190128175458.27255-1-minyard@acm.org> References: <20190128175458.27255-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::442 Subject: [Qemu-devel] [PATCH v4 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: Peter Maydell , Paolo Bonzini , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard 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 44887b4a27..ee392f7cb1 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -178,6 +178,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);