From patchwork Wed Feb 20 13:59:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158834 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5088434jaa; Wed, 20 Feb 2019 08:01:03 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib+BqYoyhj2VAPUeDHqH9iGq0tUh0D6ZxIbwFLfKJ2drhkCkrBRWPIklZeOcZw6Y//I4n2e X-Received: by 2002:a25:8106:: with SMTP id o6mr10191806ybk.515.1550678463862; Wed, 20 Feb 2019 08:01:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550678463; cv=none; d=google.com; s=arc-20160816; b=uI4cAgTBv12oh9Sm284hPYTVH5WZiS/VKqDMJ0xhHRV1TNE9x6yxAWOtE3BgqhO4tW N3ItQU0MkVdAgW6F+aBvohRPkdqAWfkWl0t2LWYfPF+hFbZqJFQRL1/w+UWKBgEXczMB CAwiSPnK+flOJVPZ77UTZfM6eFYgCs7kW8J7vNhz/72B5o6t+BhU3n8YC9bEGhXC84BK siXikHB4e/DVHZbGHRibgDeEariLT9WKLS38rWNnC7qhqNxv9FlMJwoOOKnHYnFf0MrB GxzsFa87LIF+cwmXf7W8EilCzhmrdq5H0KsLjMoAhilxGTQUAfUnKn4BU+Ehjct9AH1y Wq/w== 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=X1Cjz0bo6WApItMblwbXNzJr2rVCe90SQObyBKyFqWRvqHkonFijfzP82VOqgnTeLY xywQTlc+h8O93TMq0sV5J49URbip+Yp5LJXMohE5hRcR5DboSNOJkCz4IYAGr1faTaja gIdh202IvwQJExLfOUzeFszyV55oYd7+7+pT0+X3oWZi0pKT6dzX5d6K+DcutmrGhxzk XeHtqKB51qm8p4kmArxPDAR6SyDuLGK5ifBV4ETwF3++COY8cnz/j1ZSHhQhySIHuwBz 54fhaCuxWzNxGQOhtpAZQLRcRfe/azTylXAb8xg4bp+nhIjMGFhAAL+Q0PjwRKqhG8C9 8FIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Rfb0MAm3; 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 a31si11621807ybi.247.2019.02.20.08.01.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 08:01:03 -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=Rfb0MAm3; 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]:41507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUIx-0004ON-8m for patch@linaro.org; Wed, 20 Feb 2019 11:01:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTtA-0008A6-NH for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:34:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTt0-0003sW-JO for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:34:23 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:39595) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTsy-0003YM-I4 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:34:14 -0500 Received: by mail-ot1-x341.google.com with SMTP id n8so40788020otl.6 for ; Wed, 20 Feb 2019 07:33:55 -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=Rfb0MAm36GJPGYlNsRyIE4aIohrjZXmB7EYfadANt5PbtdLo0Tkpt1Rvkov7EA9f+J LkJfHnRwfska7TEdDszpDNJUAGQ6wnBFEEM/19MgXhPZ93L24tdtYtKtISoA26p+Nkco IBwuBjNOMUAEN6Dn231KFdEOLkfgseYUKhk2texa0uSU7YmcQFjkY2Oah6X+DAzMwopV yPjEnNOZbLPmytoFgtQxmNOJC8PelLjrWix2mW7v/N2F0oMABPofyXcq5+++K1MHyko9 mCD//9BTYhjRegTLjdK3cYETTrHtW/rp6xdXWYjnT4C2edgLKnto4P9S6vlfMTZsM+Ip NUrA== 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=gwSVn9oR3SrQ9Lg4FHYJncLtIWNe/pFHM+6QWTqBTw+QUlBPE0mij4zo9xo+Gb8m15 4uah9YKA0ypLpECzFWFdEUFW+jV2MDMl62wloyz5gUxGrQx+HcxCUeNoNbMBtAxOHb8e MeYU9mzcNaOnoKqWBD4H/Q3x3rBGxzNITuD12PJ2VFGN+M9M5ov3ltTqUBU0tBh/mMKF JmvNt8/5CZRnjzCZVyqHSDp5mssZVZ96rS/y0rtIt+hIbmsZqMU5C8vq5asjyZiNIVqs 4LCtP6IbdeBYONv5VAjco9FCFC4VxCM2OdsQiBJ2DkiYBEIIvPvMDZDvylIMZUDSn2MP G4OA== X-Gm-Message-State: AHQUAuY3yNGfB+zRvINf0aVf5n34DBvQjPK86M/JqD/sTuRMvPOfT8JS ipb2s4eHQCEcWaWTCRfIGT0f/wZEUw== X-Received: by 2002:aca:fd4c:: with SMTP id b73mr6137902oii.33.1550671212722; Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id q5sm3272973otf.73.2019.02.20.06.00.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:09 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 859E11801EE; Wed, 20 Feb 2019 14:00:08 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id AEB30302A6B; Wed, 20 Feb 2019 08:00:06 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:38 -0600 Message-Id: <20190220135956.22589-2-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::341 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158831 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5080753jaa; Wed, 20 Feb 2019 07:53:08 -0800 (PST) X-Google-Smtp-Source: AHgI3IZBpkmKYVyJQheDsdfrPCiZyyI577qy8LLXgR7XVJchbb39AosNzS+yNn0TF5GijrGJjGIT X-Received: by 2002:a25:8388:: with SMTP id t8mr28204249ybk.376.1550677988002; Wed, 20 Feb 2019 07:53:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677987; cv=none; d=google.com; s=arc-20160816; b=yM95jsYKIvnHGND1+n49/QTRt6AZVOke2uuv3eedlN8SHEE5BduUOUUhVbTc7JOGXC fQwsfn3LEx2gOO67pcaOmtPVFq1qTc4FMnffoFKokXFuX0RukIzlp7LruWGAjBsdW6HR 0mTH/Q6vvbH72DPF3BLWGsKwOYQNW62oDE1AkKIHcp/3+oacFLNPT81fVpqgyJneFYzR Mqt//q2B4OuGD33P6bCP8oZygSMV3Rn1dMrzJsKv9Oj5FJX1eLtMyfBvelU6f3aG95rt Btj+uEOxE/X9SVYq6r8DvJB2joXRQ8DxOwQ0NKzHZqiDjel7VixEa+JhjeMLyTtPJ6PO Xv2A== 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=wGjMThEelx61cYbmF3emLm9CtiOuLuaH8Ezqf09IOFK3bPnRrlpgcHjlrrBjzpMFMA V35KiHlrSnLwZjoVIg/oMEWbv0fKx6fVY1rz30jXDPK8ovbOmC5nFN6NAv/hTpww/x// Z2wOQkGXBAOOgoYhy9Pk0xPvXwMNb+RKCD73IFRV+ThQw2sd+NXqr9/T60qMtR6/Yl/2 BKAWqoFQQcwQdsHgskPWNwNxFvAyTkTuac/hHFRSrIm9iAoKzaMKfIUfHinD2hPmiC6l 1bBzuxSdutfXQhhNcBejNi3M+4fbT+rkML8+QxEGvby8XX8q3Ln+9vPt5zkoBwgud86T u+5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=shjlXgAf; 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 t1si11454047ybp.222.2019.02.20.07.53.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:53:07 -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=shjlXgAf; 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]:41318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUBH-0005nx-Cc for patch@linaro.org; Wed, 20 Feb 2019 10:53:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTtJ-0008GF-2M for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:34:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTtA-0004CM-RC for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:34:32 -0500 Received: from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329]:36170) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTt7-0003yH-G8 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:34:23 -0500 Received: by mail-ot1-x329.google.com with SMTP id v62so31956037otb.3 for ; Wed, 20 Feb 2019 07:34: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=q3HzY62CF69PYoUzSkwefLjdYNoX47tEb2xxB85KIlM=; b=shjlXgAf+RJW1YAU5+yVRRTILy/5aOZ5c9LQwQgljgeKsqpCVPZgMHLT0yMv1YwnHd 3oHuyt3Oc/8aFSs67Aiscf3tDnaexL4kKCRPQTC3wsafnvHItQ6i/UcJNcs49/vCREff mtxw7DIqRmZokTB+DpkprJaEZhRxDuVL54zXu/3WZ+KnDyV4NlZjrodLneg491UOn/md wV5VIH2RSOS27PMGvJad17q2wif/Tj+ufk+lrqx69ibwpfgKvdFIWLJA0AulOiOyDbPf uURbhunVZq7ns+k1Dtk/qL36AW/8dNkBIGfMZJQpr5F28Q1tv7K7J1zjwKFxn8KhkVh4 5JoQ== 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=BVSJMJJg7x7QTcmHFJf5/IzlfVfzie6tEZVyBtRdfGfWIbWMjOdeW8UXlHUOMRFfG3 Gx8WjgkG9bKkVJtVtjJwjW19Ew53FAM8FMu9EKdWOumCS8JSn2vWwic7A7UMX7oFpjI1 Dv2mEsdGeQ/gmPOhgZPcyMDzpj38cwmfI6MNNSVHU3yXVwR7KuB9RrdOEkIKnMgkZ9B3 KZAzjZ6iswHQF3Ptl9WZ2A7t8dyzadPyVWsFxoCDWi0ozJRUPXIkHI/QllWvhYr7p9E4 xgx3fBiVgmDkg7TD9xDIRYDFZXPSwv3QKnooBLU5ZzslrVgMOIV1jnuYZoMnp09aoCx0 mE+A== X-Gm-Message-State: AHQUAubcmfJvYnafZnM2XAbDfKdTuz4rYOxVJBYj7ujUhYIV7a8AaGfY jWj+X2Fwd3N7jJLJcuP4nQI89O2O9A== X-Received: by 2002:a9d:7990:: with SMTP id h16mr10656640otm.129.1550671212154; Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id m26sm7911520otl.32.2019.02.20.06.00.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:09 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 89D421808F0; Wed, 20 Feb 2019 14:00:08 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 85446302A6D; Wed, 20 Feb 2019 08:00:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:39 -0600 Message-Id: <20190220135956.22589-3-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-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::329 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158824 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5067684jaa; Wed, 20 Feb 2019 07:40:57 -0800 (PST) X-Google-Smtp-Source: AHgI3IY7nskJcMeXieInqvKzHeadj0yzuF1ys46mb4fC20E9oPoM6yvs8wlNwhV83wnkXauR2cUo X-Received: by 2002:a81:7155:: with SMTP id m82mr28246818ywc.505.1550677257886; Wed, 20 Feb 2019 07:40:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677257; cv=none; d=google.com; s=arc-20160816; b=MIyTqML1sc0/NiCiR7lE1K8sF1G44fytckjht9tiLA8P+jZnzu3mBDkIe7KVc6JAi8 iKv0vlJHNX85ZOQbsU7qaojCaI5AYkFmwFRWgWNDf+hdmhQEXs2ze/4nfSEfV5axJyVz d0bP0/ISMSu80J1zv8NyEpKgtwh96tGGNjN7DQES717iPP5HNgQeD4Exm/h4x2Dm1i1i H7cGLeeeu5ogqDmljzbVnyEflXW/ZWbHUC1U/UuhIoZDUrufRhnUENFGsB1q71CRGPhU wKxIDyl7EjqLTuQ54fpG+xokfSR8IBMnn5J4DBYJQ6ixs7jj3ANYo/C089QOCOVR2cPW 55sg== 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=OJ4GGY8FTOkUvpjFZSKWZCNEj7f60DpY1TGZMSvKpSq19vbjAxJjMp/DA5XNqGhWN6 RVJPRVb8PbyehgKbi41DPrb0XI+zyErorI8k5gZWgNaSJBr7GiELiOSLPnlUU57NKQkE cNqQfh/jhVEFjNj3IFXb6b234jOU32dQmyjUG91r+fs6myN1ZjQ1Ce9fiAK8OB86mbfn y2Ci0MDflD0wx650dyqSyILEPvh8C0q9DesJXqYBkTlEvtDtz9Ov0pD3hkFJbChSj7af 1D4H123fQ0q0zfgVLTZBWEindjLuQbcVNx0L5raAL3Dea3TkAk7k4Rro2GNuBwtazpac WZtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="C/8hX8gP"; 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 j191si10905501ywa.144.2019.02.20.07.40.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:40: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="C/8hX8gP"; 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]:41046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTzV-0003lk-AI for patch@linaro.org; Wed, 20 Feb 2019 10:40:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44837) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTo6-0003fD-9y for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:29:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTo5-00014P-Cy for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:29:10 -0500 Received: from mail-ot1-x342.google.com ([2607:f8b0:4864:20::342]:38165) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTo3-00012u-AX for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:29:09 -0500 Received: by mail-ot1-x342.google.com with SMTP id m1so40791131otf.5 for ; Wed, 20 Feb 2019 07:29:04 -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=C/8hX8gPzswRFARF/uvb/rH2U7Xy6TAIUKEwl1W/fenwwQbLoL1cX6fGEoMf5mXOob F6hXc+dcBYPN3L6kUViRS/q+d75Xc5rW6Noyi2GOgTELzOHAlyR9ZHdrbFbrOGSiqZY8 4II6SW1I3grF1DsVUUVsoDnfDujs3opEQr8uSgqiCL1nDSaxFMR+zZzsVYhfoAytl4C1 2YdjROVc/KgKl/AKDuMn1/IsZUaBJOpt6wkt4Hgn3X9lRXJ54T39NBg82je+RDaDVwDi curkUwv6y+OlK778dAetBFeWrppQBBxkCKn4W7v6FSffykbQX8kiGTsU8mxkXpHQ43+c 2/0Q== 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=pIlxZbXwTqQbX0mqhXejbiYe33CUwS2ukTGeYlwLfiwGiD0d1dIjnLZMAiJSiIqrgx yHdZv+F2sOGQDDKHhZZ5gxMERoLRUAaOfYwDcdgecZO1qTBsRu3eLKxhj58B0U2kZo17 WNsz2AWEKVLgM/aZKyJsmaFeSkj5Pp07dI7ySwUTIbh95PqDKrgysshiES09s2PJqfn+ dphFsScHRPlKn8WhmY+JJc7EcqUV1I6+5lBbnyDt1ApIipYdcbpsbpcMF8QsFhSXclDm 0Ql4yAbpOXKJQsRQWxNI1HYuH8ePgbXZH/gmeuusRln2m51ypaKf/uqscqSjbfc2yfuX cstg== X-Gm-Message-State: AHQUAubHlt8vYF/MfLRVn60ISGKvcGmonm6ZoaLFs0acFU5mFJS6Uib9 3RdMXvfSeZURPdGrQf2CVUuwqYQbrg== X-Received: by 2002:aca:4c58:: with SMTP id z85mr5789698oia.140.1550671211523; Wed, 20 Feb 2019 06:00:11 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id b4sm8936790oti.71.2019.02.20.06.00.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:09 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:d1f6:7172:48bb:512b]) by serve.minyard.net (Postfix) with ESMTPA id 8EA531808F1; Wed, 20 Feb 2019 14:00:08 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 165E6302A62; Wed, 20 Feb 2019 08:00:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:40 -0600 Message-Id: <20190220135956.22589-4-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-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::342 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158821 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5063333jaa; Wed, 20 Feb 2019 07:37:00 -0800 (PST) X-Google-Smtp-Source: AHgI3IaJ3SWxzHgfE6aJkVA+zZxrx7qVAtRWSmNhUKjQTALZCI3YnwIDrho6MLmh9jK6ojnQWbBS X-Received: by 2002:a81:4e82:: with SMTP id c124mr29022290ywb.277.1550677020507; Wed, 20 Feb 2019 07:37:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677020; cv=none; d=google.com; s=arc-20160816; b=u8NkZrioYbEgjydcwV8LAtjbeQEfM0ZRvEcuAXmK+bUsKsPklQ2NVxeET78iu8kkoW BF9kseA/7K6ScdKoNgmzIgOaCUtC4LGl0WoXiNF57NVGPuB5+7jveQSGec/Hnni19rNM +oug2vG/5M0JzgAd6+Gevx0hJP9OU69Ta8koxjWkaAovwSbDRRWLKahtuyd1GX9d2CNy jaNjLDVWwObeq2AGucIKDh54S08BahBbjrz8v+hR7OsygR26Ed94pWuIp6Og+3DOhZTR BfLDsdZKTFnbxVfVE4cWlMjznB4X3wO58iZ0FLqDf63MeCtrFSfvrf4xaWCnlk7S5djd ezYQ== 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=goF/+B6PVxcycg82kXeNDMO9X5wcycyJ+ZFAarZEKhJsw+9O0jl7J17BnpZRUiDgbz l6ydLbZB61z99Ajs2X3KgtjUxas3ShKcPbty8Fhs/L1WIGELNSaR3TZzUdmve6ykkwFU Sd3d84Id+TcnCaJOwsE5QoumNSy1czYeKPktjsIU+BVqMmc61jILQDcjBmcdT/A22PLq tbMjRGrzrofFg8m5J+4amHQDX9yPIkaxiv8cD5/lAPhAhX+FX2pzu+jyQQUSJk0A0bfC 2XwivCbntpMYfcMm5ViR3d/KevwRCXJx0Hl8VxWxcC4OcNc5nO6pKAYMB/AZ4lBp9l6x nliA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=QzSy7FpT; 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 y11si11584739ybm.40.2019.02.20.07.37.00 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:37:00 -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=QzSy7FpT; 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]:41003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTvf-0001VI-Up for patch@linaro.org; Wed, 20 Feb 2019 10:37:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTkF-0000As-RE for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:25:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTkB-0007kR-8o for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:25:10 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:35291) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTk9-000781-4r for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:25:05 -0500 Received: by mail-ot1-x341.google.com with SMTP id z19so40799313otm.2 for ; Wed, 20 Feb 2019 07:23:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Excm8HgHGnquQpA1JYPDe1clppMYhUvhbZU4Zai+sO0=; b=QzSy7FpTT2GmJk5slseBTgiprHjwUOKccL5cagCLcu4SFnRqNpj32MV1nYY/facvlm 2SqBtuMXgg4zmlYelD9SF95b4wMv/m9h2fzXtdJ5G8DmBn9BTcPqkBqJdPsw8WV/PHY1 KWmC1niVTtov11+23kuwmIpLGzNJwqwydABa9L6JKipD7EVQWDVK2F9domAlPV/BwBwR iX2aaG0V5HgUAGKs9/WdSRS2ZupBowT9zmrwjEWK7qo9swVoPiGq1JZTQsI5AbKw6Sh4 WgmcSibNv10ArWPoXgKpFPjxMwnVxUXp9D4e24CvUtHK/pb9I/Unao1o1XHmO+5L2R/e uAPA== 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=l35gXx03xPJFJZ92SLPwLJHlzZSFhjHWZmPp8mqTyuo5M7D0EQhluLq6+dc0fJ3DbM aR63mmh7rliTvgnxKGHFw6JtagFbdLTGn97RG8tXp6SE3vjoGZShc8ShDw2BYlJHjJjQ KNNyRVF41hRA4w2sdOmdEVvcT9VZtlaHRW1b5+VWMOJMMfFzfVljsG5Gf3Mm5OqGZ+1q NwldXad78fC47bdxFsnltxQy5owjZlkdrZeg+yut44cszYBnWX/vA8lEPSm5+W9rKxzD P9LlYPkHpIDlt0430lThLL7ebwqyUDXa70yba1+lBce7IVrSXYwa23z7sWnt4My/Oa61 yCCA== X-Gm-Message-State: AHQUAuZLEBS244H+3UG8YZ0WRN2Qw2jkd0tGD7sZugGQdZaQv+13TYvM o0McTQ+dkaD00wVECYdgADE4bNHgJg== X-Received: by 2002:aca:ed06:: with SMTP id l6mr6001608oih.7.1550671213411; Wed, 20 Feb 2019 06:00:13 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id k100sm4694695otk.5.2019.02.20.06.00.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 361D11808F4; Wed, 20 Feb 2019 14:00:09 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 12FB4302A62; Wed, 20 Feb 2019 08:00:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:41 -0600 Message-Id: <20190220135956.22589-5-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-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::341 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158830 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5080278jaa; Wed, 20 Feb 2019 07:52:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IYHHMS3aJyh3MusZiC0SqtGrMWFGsnRY5bF5r65awRC7gQ6a4kHOXnzcNx/PEfQg5bXxVH3 X-Received: by 2002:a25:a0ca:: with SMTP id i10mr28971947ybm.54.1550677961777; Wed, 20 Feb 2019 07:52:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677961; cv=none; d=google.com; s=arc-20160816; b=OHY08UmnPKDnCKJN/1ufVy0IB69MYDthbSmnU1Rs2GgvTmE03PzdBNaZxNlFQgxiGA qIjIEo99a45kk9H/Vonibx4HfZsbXTuDlAikEijTUtSxiOiBswCoP5dzjFCm+T8eUt8h +9GEpEOTiGkwBdEaFoOXXqnEYRstp9wAKBisMWh68IwRmXgy4rsSS4sKwiXBam9hjih2 1vQkeB1SZhPy2zFp3fvMiFmzA3fwTeYowcwWma8lVoGsv5+z616bjU7k6wuGHLBcA4MD ZgoH3g5MO8bnMsc9WJxQSVTdg2TinRA7WHoqd57G1rSHGj8hgwcl1LNWFwsjiUk0QHTt 2dZg== 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=HMjSmgiY0oJ3FbeOvJkwhJ5SLY9sSbf/R72jvokoPs9XbXyzvpB1uQXeaPQO0nF00S 2Ru8dx39VQ59fHahttEeKmll6qmG2uLwyCa1nsirGkGbozdk2ATisBKwbL3w4sG8HBJf UNEiY4hloeheOXNsp3Bevwgm2Dc8ySbuqqGjjAFFx+N2RV5hlFd4eEJydbuNO/Pzeasl V6lafa4pz4Z7Ncxtr4fysEvG7aJ6mWtbSMiREYlCo4bzHqySOgMB8iGNCkDeyf3t0iti tX+J5DY6GB7pbMyi16U/Q1G2iv6F423zMKT6E9gThnxlxSm3+ckKeotm8aIBfqbfQvCc +O7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TCyCHvQo; 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 f37si12400052ybj.125.2019.02.20.07.52.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:52: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=TCyCHvQo; 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]:41316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUAr-0005Wf-8S for patch@linaro.org; Wed, 20 Feb 2019 10:52:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTmX-00029M-Hv for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTmV-0000ET-Eq for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:33 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:35335) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTmT-0008Ss-9K for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:31 -0500 Received: by mail-ot1-x344.google.com with SMTP id z19so40821193otm.2 for ; Wed, 20 Feb 2019 07:27:04 -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=TCyCHvQokrqqNXBMN7D+hsYN2Q9k+rvWpXK12XLpGAsLFNH3cE/7NbPrPK8nUreeLU Qzm08ptoTM2mD017ASPuAeFsud651nHSZcfB+coVO2uAKgmNQVfwHW846wJST9/GihVd awFeA0vj/7zYoPZCpgQC+OX/R9U33TpPO7Mi3Pu13TF3GXIKzoqbduaGwaKWqh10DRq+ l3EjmM/gI76etBlUbo+nDKKylLhM2oAXACUCD7PwY/A+DH92Y0wl6++DPg0AErKu+9nP famU28nLIZhHY1CtD+BwTSI5864OAp/XrAcw5eLv1hBXJaxTDKo3VWg8BauDKCn2jJNx Oc9Q== 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=umHhwxGreiqwMIaL3HDn+c7tiKqwRS2HrVDqMyxajQ8wJPpx1ooERjgd3cRwZmrBJk PbRoKiefrTm1KjHcnafgHhV6YNtkYNs506QbY/CjZEqOZ49kP6EsoFSK9exLIDW+zRQ2 zx0tt5w8aR3r9IJ72ERd8NyeiA7xFZaiQ94f41ZXukhYzKCeLShhlJxewN6OOpNDbxaD Xyor1xsnYjJlhELqJ0giSOnL+Y3nJKHliCALwdWAE3r2KESkPmtCAfesMihXHg/suMeJ ALBa2PICZN0RyVwkMvx7XbXSqL1QvISc7ihMMBDWhimAQ8FN2X2QabxEz/XBZno8um8q dQPA== X-Gm-Message-State: AHQUAuZEgrI8NJ6dK+gciJqIBiMkfbBOvKFpJWhDxbZg5eRNc+HVYr4r qw92VfQgGfkemAVtdygAHGZn6PH4mQ== X-Received: by 2002:a9d:138:: with SMTP id 53mr4958447otu.169.1550671210971; Wed, 20 Feb 2019 06:00:10 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id a62sm14491230otb.72.2019.02.20.06.00.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:09 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:d1f6:7172:48bb:512b]) by serve.minyard.net (Postfix) with ESMTPA id AE90A1808F2; Wed, 20 Feb 2019 14:00:08 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 78186302A6C; Wed, 20 Feb 2019 08:00:07 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:42 -0600 Message-Id: <20190220135956.22589-6-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::344 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158836 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5135218jaa; Wed, 20 Feb 2019 08:41:28 -0800 (PST) X-Google-Smtp-Source: AHgI3IYgy5DX9VOqA7wteo36E18dJ+E7IzE1m+kAnMGkCzvgGEjQbkmEpaTF0xtIBAlyv+wMgbPl X-Received: by 2002:a81:4ac6:: with SMTP id x189mr28815825ywa.249.1550680887997; Wed, 20 Feb 2019 08:41:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550680887; cv=none; d=google.com; s=arc-20160816; b=aSzCxUITOKQZd77sjpe74upk8la2qk/U5zeI1PZ/fEUOIz4i4r2Dnrqj2iyzMgyeQJ d1c0wNrLZEVKoYCva2vmF5CPV+hAtClNGg3pdRtO50oAA+X4fTIdT3OCojYtShjoAs/Q P/GMO/mnemdSKWa/IITbLWTC3+iY/LEhZv2DDhl0673wecpSWt0XFVOqcpPcAfwwuE72 zYlXhFfAjL6b2wujHZjPeGB/ukoOwal2TmwIsOarWpolXGa8HbICDPtuLH6h2f87iI0n 0rxoqJ20IZHny4vxxYWjUuDJgtP6p6RcOqJu5lfA227YhsPQzMtgv1Bc6sf/DyK8nRmq JHDQ== 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=AH2N8QEFXoLyFBfeT0h8weHtCk8eWpw0ppKFCaF4/m2WLd9iQPoZI84Ba3KgzmBIAt YbnuttJa3aasjdJldXObyPyVqPvewdHs34tiVT8eO8VfNzcKMJfgCIMBMdWOLZTwZnoH WkMGs0Xm7fUbyFR1YkfnkmEchP+hI1PjNVZ7KoGsOvW2ProWYgYia0AoPH6D0tfqTvS3 vEBM4c38HRRxs075x0EMKAeHggOJkt0YWjp4JiWA7BA0n1IZ2fA9O+5N5lGCaVmudywn JRw+7/XajiqNF/SCt18RPO2NY+jtWTygIwtJ+l64cd1LMd9OmT5Gf7rmWkexCy+ztrZO xknw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="Z/zn9l4W"; 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 n131si7567427yba.290.2019.02.20.08.41.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 08:41: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="Z/zn9l4W"; 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]:42480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUw3-0006Td-Bq for patch@linaro.org; Wed, 20 Feb 2019 11:41:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUK8-0006z0-PW for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:02:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwUK0-0003LM-1n for qemu-devel@nongnu.org; Wed, 20 Feb 2019 11:02:16 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:36033) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwThn-0005pK-TD for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:22:40 -0500 Received: by mail-ot1-x344.google.com with SMTP id v62so31873013otb.3 for ; Wed, 20 Feb 2019 07:21: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=r3vzE3iMO2lxtAlRHJptW6ozanNzYhiqBJrBz7a1j4k=; b=Z/zn9l4WXWBtuAMVo/VdPrLAv1ySTy44czUvOT5qI3iCzoPAz3n/Ixnif+Py8kJWNV yjoDOpGneAlM0j8oJcA8JTwzaml/xNxxO9YnBUWmiZUJkT1ITdOYBxaIPgQEY/KJ/xwk QYQ2gxj1D3AmQWKzL+ofJJYhBkh47hXvHW4Kp04VNer7vZZ18Mwp7kw+m2NytYCC6AME UUEzM10vpEaZn8z3S7uALCJVMUjHkwq6YfIoM/dmIS5Ysq/7cjRcMfghCj6ak3BOFiaJ BTy9vJ7A0m6RhoHpZ6tfnOeNhYd06kvhRuTFykLBDX6Dwunf6+vcJTnVVyapPNRmK4Db uQPA== 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=c0V6lKlzlVTbxk3NQbVuPNneHA631+CyAiQpJZ7oQtTztsk+hLT1qByGiQ9ZQrqsR2 88GzXULADPS0QZxebZ4vwlgCEPexDi5L9I9bduiuB6mlLI+ZF4ctvgxvlh+cub4FC7nB 0jopkFUcLIJuGxrmgMltBIleQI9xh2KswZWat7yiZJHwwhDS9s7V6TUB7Bhcyj6t0ku9 ZbuiJRh7fCE3gkn+IpnZFEk9t/k5Wsb5b9zlbTqUYymrs+htJWgv/tJyXMNGbIUGnrS1 hjWRjyH0Q6luxRq9nyuY3IwVUySvqFRkYVLE+9Nu+jtxVkGC0KldK7lxEnxt33cPcVyy yD3g== X-Gm-Message-State: AHQUAubhMrdkY3RH4zbGTSD0EIXoiYI6eluve55nh5PsPvC6k0vV/Ozz LC1uX5bxBwwgHEMHEatT7gFDuUUiLA== X-Received: by 2002:aca:eb01:: with SMTP id j1mr5717665oih.165.1550671214589; Wed, 20 Feb 2019 06:00:14 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id b4sm8936820oti.71.2019.02.20.06.00.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 21B121808F3; Wed, 20 Feb 2019 14:00:09 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id A15A5302A6E; Wed, 20 Feb 2019 08:00:08 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:43 -0600 Message-Id: <20190220135956.22589-7-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::344 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158814 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5050823jaa; Wed, 20 Feb 2019 07:26:54 -0800 (PST) X-Google-Smtp-Source: AHgI3IYyUJXYmmmcBYUvK22A+ttyVmTyKTsDKz9W9tqHWzRed2Lo4D6MPC77KyZJgUUNlqyss+VS X-Received: by 2002:a81:a186:: with SMTP id y128mr28326030ywg.172.1550676414245; Wed, 20 Feb 2019 07:26:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550676414; cv=none; d=google.com; s=arc-20160816; b=GDdVM3Lt4GszMTtPlzA0KrMzRmocnbgdhxEvaGot5hjz2W3oh3/maO3DzmdJHFlMzP zI36TTI4n0Gu78+VGy11CrC1g/KJECcB+Gu8/som5REBvZR6QrF7PUxnFQDNl6GiFHmm Q2sMM7D2IZ2UJjXsD+uaVksIxO5bxs/m+WUrY5CJ0lnyQ8kgwb1dOMydZCqPKCksxPs9 5rshOuHW8BsZW35gC6xJwz43SfUSfHGZe3unzPtumh6FlXDemSP1/Ae0kiunzaMQSR6q KCKEcz6vuUCSDdj7aeBzYLEmYi8iczp1CETd4EYp4DW54P+vRBQGs7h0gBiz0nEyhdTp aw+Q== 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=ltrKvL1wFCmsevanDOByHV0CH3UrQ7XGYa631gmmz6ycyPbi4NJq1Y6wlaO3Hv4a/p V7iyFZQ/bkRkuOnCGeeUMyLREIIBJnrAQQu+wChMYwOm2RugPveqRDellgiTkdFfYlax +2yj4wu7+RpTu8HamEuKq1bYRE/F/4T4c//6usw5DFvcEUIeT88mDmNzvaARk3MCg5vW PeLvmeU/zRbrWAfHwn6H1WBlp9RivfxzZlO+SfRqlxCPS2o3jNs4htAZ2y8qgIs16Q93 fi5spJC+opCxtJk5HBGEMohSmEr2iv+HwFUEzJ+Ad/T1zbAhNoTulAcJODIZ2UyBou4+ GSrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="QZxJr/pW"; 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 e83si2897449ywb.380.2019.02.20.07.26.54 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:26:54 -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="QZxJr/pW"; 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]:40827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTlt-0000iT-Ki for patch@linaro.org; Wed, 20 Feb 2019 10:26:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTiz-0007Jn-4K for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:24:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTiT-00075J-4y for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:23:40 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:40085) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTiL-0006vA-Bo for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:23:17 -0500 Received: by mail-ot1-x341.google.com with SMTP id v20so8767573otk.7 for ; Wed, 20 Feb 2019 07:22:50 -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=QZxJr/pW1T4/uCqtkUp0O6VskQ7Dqb0YkAIXdt0p/07rTsn9ABZRkoeiZL3HEBHWp9 wV1eNnNj9X4g+df17L3B2bcJlZiqyuo86liE9qvTHyy1ahvsn71iiwPu8IVIZl0vQnwi 8pOCzi0Ow5YjkJdAAJHkRi0NEYLT51EqULgD2YxT9Ph+GcE2nUK6HuEUYCwZzBh9v5oa VmZnJ/CpsITH0cxH5v8cA91XL/ttB6nb5QdXbEcDGz2xcmZ/Mw0AxLpk1VqOoneFT9FO ReBW3nUvxj3fsk3VYJ8Ks3PQetRBj3eOYswiCjtjG8aKfpwlhiIZz4uUp4f27JYb93Qc 43Aw== 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=A4xkkb0zAOQhrR3x1Oo5vkdInaGPCiScd/tngb5YyjoBc0TyNMMgzhXjLJ8AEBaHFl +6jpAzkI+PIHZUL7z4WEt49Ty73NVI+/D47eKcfqYO+6RbfoVS+PAlntoykL6b1LUG0Y 4Hv7+cJ4sVXOQ5yf6THpV/Oa63zcGcB/QXaPZf+YmzctMNHPuI3yvWchG8L+ATcbldek SYZNdJCNIoCWA5cOTSi5Kj5lKsxofKkCCLt8t3HZU5Fv+DR3stb0ACxTzJUDshqaz3mr PYedtq83NJgaRQzKWglN+Mu9z4dmDekucC9ps9+LwktqsJsJ17tuRRQji6HLRhOfjTAG FtvA== X-Gm-Message-State: AHQUAubTjci0oElRGNnxOP1IB8noD1veN+UNoIR/l98cmAYiBRxNm39d JNZ1OX5C7gi8r62fADPnDX0h3dERRw== X-Received: by 2002:aca:4c10:: with SMTP id z16mr5850770oia.53.1550671215714; Wed, 20 Feb 2019 06:00:15 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id r184sm7889556oif.56.2019.02.20.06.00.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id F249C1808F7; Wed, 20 Feb 2019 14:00:09 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 9786E302812; Wed, 20 Feb 2019 08:00:08 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:44 -0600 Message-Id: <20190220135956.22589-8-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-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::341 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158826 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5075250jaa; Wed, 20 Feb 2019 07:47:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IZKrKahvSBlkL2vvIWrfr8CV4CxLCSRJnwl0PdOmjDBS29k30C0MSPi1jrF7FCOZnmbefDw X-Received: by 2002:a81:5509:: with SMTP id j9mr28707582ywb.409.1550677657474; Wed, 20 Feb 2019 07:47:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677657; cv=none; d=google.com; s=arc-20160816; b=qavpP/ZJArv11At1p17EZ185AqBMMVXgnHnQJGrD1vES/rKgp/c33LHh61tOpYxgv3 KZayPWiBRREvtO+sGSKVbgjcbI6sPUpwKXZMkNqZsEc7xcOb+XxtY5iP+SPTfBqjWzm+ KWLyImhFapdg7AUEzraVcT98sd9qIn0eGH1s1GIVaYfgUMDJY6IhVvxVG5Uyc6WPn15u ydr/msFq4dPEj0xMdekSRit43FxCfpPFnYRg5y5ePu3xf8D9Lw15YlsXx+zzmtJl5j5L SF9csKWqxM+xVsuQfH9tSV1t0BQu6f4MSTjA2Kt/gS+B5FkR1y8fQAjBpxsDa0/5EgZj yl3g== 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=jjfhYEVfdj6PxkJVbhWNlPohUCSqPlccYrx2el7pxkx4eDh5+1220j4Q0dMvnbPTEU CyvhfCZJjG8uCeBriWQSlaslQ+9lvdyMopMd1qFsMAktyLs9bNBVSdK9HuSeMmxLVZ5b 2I4T/saJ6KAxsR9V7ogaWwmK+5XTjP0yDY1QNugdYDXarEqfTENRR6wKpsBe4vOHF6uK 1TTHDtAoPsiJ934X/0DToM+nqBGUY9z3y2Je9S993mCk7vLh4n9O+yN01ycdKvEG4ry9 z5eVAVND135/azaMj1/vdBMxctj8vMfQa+DqWznEJjwAzeD/IsWkqGO6kOP6A8Ua1N5y Ow0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=qqatf8i+; 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 l79si11111345ywl.413.2019.02.20.07.47.37 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:47:37 -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=qqatf8i+; 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]:41219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU5x-0000qL-04 for patch@linaro.org; Wed, 20 Feb 2019 10:47:37 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTvk-0001uW-As for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTvi-0005fY-G7 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:03 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:46191) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTvZ-0004aU-3S for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:36:56 -0500 Received: by mail-ot1-x344.google.com with SMTP id c18so19220996otl.13 for ; Wed, 20 Feb 2019 07:34:44 -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=qqatf8i+5UfM2XRPYDMTb5BhscvDZSqBDDw5d0fH+3u+tfNHpOlN5aohRjBWpbPWNw Usto7xoOKRTY/7Yhf7jtb1UHEjdc/qfiqe+V9YNnRXjrx37aZM+u6Y683svqMVtkGe3t Hl5W0w2yv5yWsmjDQXSIIuT64OtnIqUKuk0jz1uKMzO/9QNap1rO9KZSDxzkaO1RJWuh E7/meIIJKASwY+XHgIXaH8EVb9dKgUdM8aFz4XWazkgQ8rJmI19GlBxzsIDQ3untpM3P LQjXoSNs9jvXpjLgc/Z3Hz1y4xBnn2ZIxbQe+K+ggYik+pw2isMzU7D22gEK5AxV2vRL NvRg== 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=LI0NpZjOcDuvQApldWsWbB3j5//OqQfTKJIeqkmNLudGCmcIv39xJaMxV/Qcf8K3PE 6OoctI7PCyQHcOKQ2fTvmTVxrIv5tjqymc+8gVitMhYc089RFdxWHs1c53z6M70yNtia WBsyHjh7GYLp4ovhkOgU3dASQe3JLt5rMR7dqE9mXaeSDhC58mOnDvkrc64GwDAmCcln st6ZoHmNVMHP+4m8UseQAysTkhZRsTak0kafLix2sc70pf7hP9HyLCyX28S4CeWsZitN PlLrUwk7t9FfbYjh6oLAfTMYg8jNbVhUr2n18y2L7y/8q6ZVHx18XDkIpYQ58fRjPYEl aWsA== X-Gm-Message-State: AHQUAuZQ1Wu0qK8jjMLiWj7WNmg7tXhJR9DyHyTSfPJN6Ha8qlSqqvMB S+DRWNkWv5oacrugQ+ZrfxZQXyH+XA== X-Received: by 2002:aca:75cf:: with SMTP id q198mr6067698oic.125.1550671215197; Wed, 20 Feb 2019 06:00:15 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id l134sm3198160oih.43.2019.02.20.06.00.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:d1f6:7172:48bb:512b]) by serve.minyard.net (Postfix) with ESMTPA id 7B7CC1808F5; Wed, 20 Feb 2019 14:00:09 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 2F8A8302812; Wed, 20 Feb 2019 08:00:08 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:45 -0600 Message-Id: <20190220135956.22589-9-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::344 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158828 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5078425jaa; Wed, 20 Feb 2019 07:50:51 -0800 (PST) X-Google-Smtp-Source: AHgI3IaSs+FSE528NqHYM4lRhXiZk9N2F8Hs+jHHJt+zs6CFBtY4B/wklF4ccBPTapNAhdtWxfaF X-Received: by 2002:a81:9a0e:: with SMTP id r14mr27704421ywg.423.1550677851511; Wed, 20 Feb 2019 07:50:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677851; cv=none; d=google.com; s=arc-20160816; b=lBEbO9CIaSzwfGdsfKgk3VKLCIoSFxeCRRltQp/tud2bCpST3N0yreQmJhKJQz9QXD 55SOSCGz6AEAJAhKif4mdBnqxWFOqRDEZ8Vbe7m8wMzG5yOmXtiFvc2oegt1TcDa+G5n MFPZQmNbfP10+AYKlSCHvKw5gzE1UsC0eRwBCyfEvnb5D69gueJ1DAMd+dKmDzV7F/ja fuLnrKvVEKmxTtFboUO4uQRi8ScCHvKe5ivfHo4OyQDv0aSCrYjWJ5iG9S+kUVjG+7Yk wTKTWGZaFeER8aRD83pgoW7tYc8PF7pMmBlT8MbhNlteIz+D3so9/4e2JapzbUqAx9bK ibGg== 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=bGHEUDtovpwcT3PZlFG/fI8E/5QZOAGTkf+Z+c7pcQF5JMWmM2PS+D/S1ry8Rz+DSb j/mpJ4FlgdT+v/uoVaA/WpqNM2SRrjFIqCcU7CyqU10WxQC+cqEgt+GGMkpMTsjUMMOY 0HIxKLkLGpAmO7mV/ZWi2apRjT8PFu6yL0wsEmjLeoeXbKebe6OHfEDg2FdtejJWlHlM GcGhA+hDd+oTkEXZ5GpUog41xP8iPZPgA6Bx8bf9cpVzHm4ltQAtM6oFzH6/DCSKgevY b6iuMmwv4c9QUbXenGFPxPBW/SeqpnLlwhBaKzU0ATGH+ffUPfwL4NsXbotqVDelwoYr BbdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="p+xozL8/"; 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 z5si11448902ybc.157.2019.02.20.07.50.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:50: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="p+xozL8/"; 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]:41250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU94-0003gd-Sy for patch@linaro.org; Wed, 20 Feb 2019 10:50:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTo6-0003gZ-Mu for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:29:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTo5-00014Z-Lw for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:29:10 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:34620) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTo5-00010D-Eg for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:29:09 -0500 Received: by mail-ot1-x343.google.com with SMTP id 98so40874770oty.1 for ; Wed, 20 Feb 2019 07:28:56 -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=p+xozL8//L/89RyMeYFEmACOEpVcnjd4a/sVnV4473LKUhekwnDhKzkfDrjvG7Nnk2 aFCBhgAubqxi+8ZlZBMF4iS8MFhBUWxV1D27oa3jIWG1SiWeddLdGVgENmsHATh+pBqw XpZvaO6l9+OUZf/o43C5doZ9iRrTsLJA1MFGW9nUMIOq/dMFbQd1MhZZxwho+dH9f37S 8+11Mm+jxbqSeMLRao7Uyj7bweCSQ+iILA1wDYUf7AQAb4tStGs92FhIUzG1Ro38xXp/ 4MhYo2WR1IeyOz41zCfSg8bkU6jULLi3dlxvsP8iVeYJfm9Xiq5wFo9YUoPYmZmg9bO/ ScMQ== 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=H4TKamFSY1+UF09BUCtWUR4hpLo1ZNwpuV7Lc5kOaiZvoMReNzTfh/oMRb1iKft4k4 t+G43tFDT3lLBymjRdgC2DgWi9H7rsdniI81cKnt5urHBu5Bhi6jxS7hyjNslw7eqjCG SVzePwOV0365jmzp5zWS0+92QCha6wBh6mVYjRiWuOBHmASx4VgViuDnVBPVBbBRVWYU p6N8BxzbCRpz7Z96nKtYjvY33UYRnbdRODDrF9OabyQJDF+bFTNhwmiOOyu3dxnqqF7A 1YkUqSHOOOX2mXkSoqJCX11R8yVkR8rXXyHSRcjElUF+gQ1lhFaEkgg6B0Wj3K6ZUmez wWQA== X-Gm-Message-State: AHQUAuYZHsQPPCgX2cowkpPDGe2Ght1/AeGrhtTSD1/+DMEyuEA7hpmD RwaevyBsWnfaYC3T22Cl8StYJE8pGw== X-Received: by 2002:a9d:27a5:: with SMTP id c34mr21734405otb.30.1550671214026; Wed, 20 Feb 2019 06:00:14 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id u24sm9460427otj.44.2019.02.20.06.00.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id A09741808F6; Wed, 20 Feb 2019 14:00:09 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 74CAE302A6C; Wed, 20 Feb 2019 08:00:09 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:46 -0600 Message-Id: <20190220135956.22589-10-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::343 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158816 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5058586jaa; Wed, 20 Feb 2019 07:33:10 -0800 (PST) X-Google-Smtp-Source: AHgI3IZrH0djBHqHxim/ejT+Kdds+9Cohayo+T+q0B3F68ODxIk6m2+HIJmcJV0TgcTa+d2228+S X-Received: by 2002:a25:2d6e:: with SMTP id s46mr29368410ybe.503.1550676790142; Wed, 20 Feb 2019 07:33:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550676790; cv=none; d=google.com; s=arc-20160816; b=A5XLGtbWJh5Mu66JZNKy4s7szNY3KBQx5G/r/8QsVMgeb7pYg5vB/SR3JhpLtNaOoi xyajGPRHJWOs8H9xvb4uhvXuPSJldjekYH7Wh8fqpDrL18gNDnWM0cpHQyQdTmVGoOhx TZpIMU3Ph2MifN40vnpD4e15fEyMNJ2rf4M1xLko8cgOMgfmWCwzakWrskZwofRWCnj2 5iD9uKIWeuQPppCeFU1pXnSwqMLabAD7cNS6o2PeSt16Byx/mcvL/xY0n18/vwafRkVB 8dnSr4b7hU88waQ1jwrr9IUqK5GbuWiqgzeNmsebd/8KfiroXeHVZAlFvskc5tqsi6zO ZlPg== 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=VTOzNq/I/y0IaO+bg2mnNH4We+Bf8EBkQhlDviyiWMY=; b=bR4qdnAjjFlqQfACETYnO/sNu3hgvu5V8XT2deIoEo/bsI65wkGe+vmu0ej3wZLc8h MBab4dgE1hb4+iFTJnhyJDgmYAxg1bJDD5dqn1BntV3Fg5VQJnUKDuESCxwVqESvjUld spXjIkV1/b+s9cp46D8+NgBu4XmwGgqTQxQdqGr1EoLgigT+04s6YNSa9X2rqXlmcYdc ejkgVK2BIVzhd4p6wMnFAv0l9XGPTyphTV+W5h+nY4dxKSS0GB5j5VAVYVdk1Qi8Opwl ZzfIARDyz5glj1hYLNqq5apcKI5DtT+AHIHXAnabk7bGdlIu7NKmwivv1xdl9GZXbSvM SRRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Nup3nK6E; 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 x84si11552856ywa.79.2019.02.20.07.33.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:33:10 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Nup3nK6E; 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]:40934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTrx-0005nk-HK for patch@linaro.org; Wed, 20 Feb 2019 10:33:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTlk-0001Y1-Vu for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:26:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTlf-0008Iz-Nm for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:26:42 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:36095) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTlb-00089j-QV for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:26:37 -0500 Received: by mail-ot1-x341.google.com with SMTP id v62so31907311otb.3 for ; Wed, 20 Feb 2019 07:26: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=VTOzNq/I/y0IaO+bg2mnNH4We+Bf8EBkQhlDviyiWMY=; b=Nup3nK6EgWgPHq10CiqRSCcOewJlqUTV3afc755LBxx9Pd8L65TBr5pK0gKQ2K3wrM rTzhnAzOJ8n/zhgDu78/1uovT3YUZGmXyreClS++dRzuL2f2ioUHfeWh2CkSQ5blNsWg sT3VT6fcgKKpLFxv6xo7LQSK/DTgPd7t0q0OYpV5AJfuYQEa5FXVnvoWkSZXJhNzDEJz w6ma/+o5XvWUKkI6lfnESv/U8BWePTlfL07uYyBscKQ9BlCeWkHNrlliXbGaEWipykAx tfxY3rnJCNin+ZpCU4XB3fukjBf8xDCQdUNjuP6dHH3Sw+zqi4if2/8L3HAaoiIdsKYM 9+FA== 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=VTOzNq/I/y0IaO+bg2mnNH4We+Bf8EBkQhlDviyiWMY=; b=I/SKo3VFwGJLybeB0SqBsVsZE5oB6oTbmEIV4p6cpDOZ5zQW+/O4UG0tFvDNxyxG+s BYGk5ozNOr/DeIGqLjZ57LL5Pc3rOR3oXkHMLdILO/23gAU6Ez5y+z2j4aGtMRjii3lx jElVMhBhmUdAeQjZntB1hyTRtTNPYium/W+dPUggwbBq5zd6e1n9xny4X5BrRBnuaw3r ltuTCGcNre6s8ao1TMm/XOwMvs7cdSw++YOplAseK6ci10FodJQCTAOnCi5LFI0MFe7A Oloys1iuEeVtIWUCqteGmWbTnKovDuWVEw9RiKEy1iNO5vkp9tLFE9B/uJWf0XXRF1fv usUg== X-Gm-Message-State: AHQUAuZsZyc1uvLK5w9EWicF4OnRAACUi80+qekY8guDaU13pCzJ1JKK CPtFSmahQ5CsUCtts9IqS8I3BuwOuQ== X-Received: by 2002:a9d:5e02:: with SMTP id d2mr16181419oti.327.1550671216296; Wed, 20 Feb 2019 06:00:16 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id w18sm6432962otp.70.2019.02.20.06.00.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 7539E1808FA; Wed, 20 Feb 2019 14:00:10 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 44AF6302A62; Wed, 20 Feb 2019 08:00:09 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:47 -0600 Message-Id: <20190220135956.22589-11-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-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::341 Subject: [Qemu-devel] [PATCH 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" , "Dr . David Alan Gilbert" , 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..3bead1143f 100644 --- a/hw/i386/pc_piix.c +++ b/hw/i386/pc_piix.c @@ -442,6 +442,7 @@ static void pc_i440fx_3_1_machine_options(MachineClass *m) { pc_i440fx_4_0_machine_options(m); m->is_default = 0; + m->smbus_no_migration_support = true; m->alias = NULL; compat_props_add(m->compat_props, hw_compat_3_1, hw_compat_3_1_len); compat_props_add(m->compat_props, pc_compat_3_1, pc_compat_3_1_len); diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c index 1689885cac..f24ee74cc5 100644 --- a/hw/i386/pc_q35.c +++ b/hw/i386/pc_q35.c @@ -378,6 +378,7 @@ static void pc_q35_3_1_machine_options(MachineClass *m) { pc_q35_4_0_machine_options(m); m->default_kernel_irqchip_split = false; + m->smbus_no_migration_support = true; m->alias = NULL; compat_props_add(m->compat_props, hw_compat_3_1, hw_compat_3_1_len); compat_props_add(m->compat_props, pc_compat_3_1, pc_compat_3_1_len); 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 Wed Feb 20 13:59: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: 158825 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5070607jaa; Wed, 20 Feb 2019 07:43:47 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ/0XXCzuTxguzITg6bWv0L4M5wqqRxsZ+VGe4nmZWfC+szPM0c/c7o6TSzKsCGD6Mfacaz X-Received: by 2002:a25:4056:: with SMTP id n83mr9652830yba.471.1550677427027; Wed, 20 Feb 2019 07:43:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677427; cv=none; d=google.com; s=arc-20160816; b=xdcBoZZxMtj+m7eaF9GjbpVR1I33wLh8lGrJBxOoYJzmnFnDX9FfA6y4kO+KMWCs3M OI4QPNwsr/cKW+Kz8nEx1RzQtqgNS7P2jsJ9DE/y8yO7XC7mIYayQxf/6kXgS2NOnIAj KfhZRvgTYDH3EHDRmIuIEcitZ+pOl8uoD1HkLGhJxJwsTZcWWe5lpzTCSrtmS5iG3PAM HBGJwdPVtZlDloF2KTHxvIhyN+IY4hTo+Q3sLetZz2FJZyulgcUGqmGp1oecbBFUnaa+ D9OAAdmy9oZFcdCaCnYAIHybf+c00hDRtqhYwwbMHxxz+RnlTgDmWoA8o4gNXW6S0ebs 5w2g== 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=dOJuzU+xgz8lvq3FDLd5MKADrDVYfX2XNIhbX1U+mlnxTHrB8kF3ycZQEGvyVi9sHo R4btQko0k2pUDHXh8Dw2X4J7wVNQ1B6Bx+n+4n8J1tjNDBEcC3REIM7uZ8NzZ1ZWjXSq EDGzafdt27SONuSkyNCiTUq4N2k0UHnP9WykvQDw5c0mt8Qj8i16i7XSlhDSPEQJgu8z jYpy4hKp9e2RRagsLqryPjXQMGreoqjfCYVVZtKOfnG9Nkf92gWaHCd1YQxELKDYUqyc 60A1BF8HsJw/u1gt5sHyY0uvrgMA40hoCcSr/POPK52HjHH5kLOqmCBR0qKuN+DaguDP X3tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="rj3W/50K"; 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 t8si11303522yba.36.2019.02.20.07.43.46 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:43:47 -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="rj3W/50K"; 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]:41120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU2E-0005xb-En for patch@linaro.org; Wed, 20 Feb 2019 10:43:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTmu-0002Rh-B7 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTmq-0000Pu-MJ for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:56 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:35329) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTmc-0008L5-LI for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:42 -0500 Received: by mail-ot1-x341.google.com with SMTP id z19so40819061otm.2 for ; Wed, 20 Feb 2019 07:26:43 -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=rj3W/50KIP/g8l/XLh/SwpEYTSiJ2jwxLtth67WOegVWfb+j8ijKwy+ab41k4TboMR maIhUgzOido6BuWYt3an+n5xraXdVfe0ydpgPnkWyTWrvvMiD4Pf/XjUXbbg2SJ1ANkn oOgsY2IVENI+zDGdkU0XYxkWoF1z9qBX72x6G5LWpFYiVsUUjne477XYMDFijyVgKUvw IjX/JNwmhXe1I1wcWk/InpIpzF7LiRbHPZkous/O4M9a7n0gvIKRXf22qrL+7Yc4w5ag A+HLDMTeGvKuHVg9uP7lcKn8tqxWFPgu9FG7JI+iOG+nyqvvu1rV/aJdyP5BtnKIKzxf O/7Q== 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=mqHOMFK2Oe0vQev0AfP9f0YSq1VN1Y1nG8VFdMiMLC2hWRp1Cc+pi1J/ZPWiSnKZky 5pjAptsGl8MhcAf6Pi6h5GRgQ6BldYwadB3+x5MbA9UwyAaz0+wwovDhb1p+RE583krS zH3ZqSb5bs827hK9PhQhZ60k2HYYe8nM3ibJDnn3XFKCn9T9QKGVeIKSTXn0n//qDRB3 Ew/1FjMIxjflXpwMW46ZF0KVm4Gt50IrKiLC4NRJ8Fg6S0NWuSE/P0HaC7PeUmcwMdg5 n3cYZncxUiMoiypM6HJG14k65bAxbjliEkXeeJuicEIy2PHSdCYrYJm8i3sIcoNUFxew tfJA== X-Gm-Message-State: AHQUAubWCvmMD2/weWFfUnJQxV8c6znu03OrZ/uZ1D7zW7hjafm7ybeZ QVIYZ4OjjEKSvgXgcoA7oBZsGYUAFQ== X-Received: by 2002:a05:6830:e:: with SMTP id c14mr6651857otp.144.1550671220522; Wed, 20 Feb 2019 06:00:20 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id r124sm3990133oih.7.2019.02.20.06.00.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:d1f6:7172:48bb:512b]) by serve.minyard.net (Postfix) with ESMTPA id 9F9E81808EF; Wed, 20 Feb 2019 14:00:10 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 6B8BD302A6A; Wed, 20 Feb 2019 08:00:09 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:48 -0600 Message-Id: <20190220135956.22589-12-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-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::341 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158832 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5081882jaa; Wed, 20 Feb 2019 07:54:16 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ2TuV1xGmhGIQjch+wSM5ZA3WvqKj8SVRop3ZrIKkupZw63DUNGI7eTA/ReNvesSvgez6c X-Received: by 2002:a81:a192:: with SMTP id y140mr28407761ywg.380.1550678056848; Wed, 20 Feb 2019 07:54:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550678056; cv=none; d=google.com; s=arc-20160816; b=rIC0T/4F38a5iB42KdfQSGA/o2YN0ajgh3k88xSD1GcL5jo+kIQXnn/roqN/ZDd4gV sAwmu3u3ewOAVS4ssUrxnbyC5bwhb4z0SI8O6aQ8WkhlAbFRZNAIlssq0iwLvJcrs14w /0RJh5kKu/+Jgl2xbCEAfbMHhkNKFWPyIj/JaNznJfP1eBUz1nQibjLcmkmtW0cjjT0h 5e1Xnt5RMClgdhm6UK7BPgw1wQ0Nk/PUWgX6Bu/lHQdFBWSHTjUy191uUD5PAqJjRRKZ jxwfc7lPyB+cEdX3qVgIB5sr8D91GlXbVTOvxJzRBdMkXq57Hyh9y0Z9jWeILM8eFIiG v+yg== 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=RXhW1J5eTCCu8LqZ3q5nry6DqlsysjKpAATfES27Mn7BH3l8xs50zD5hpfTDCfpw9G mU2E6OkgZcmZ4wX1sGVpCgY1j2+LI09iHrFp+dEIedtqG3yBAhTGv4kEny7anJSnAcWW EL4J4+enHYSnxztfr3BcoICwcLIwaLyqlW1qZ7AFeW8dn+7z1VVs2+Nu9vS+BBDeKzBE aTU4MMIp+ViwcHJkIv7fTVu2KonwE2UfbF6Unp5fGmbKICsNSm1C8HZpZf3QeNxlQFXg xHP+EKDrVShmqz3RHoE+6Fmv2s1XhJGB1R9NCtmVqUSHhOZCSULKBqtgXSCtPPrI7xrN qscA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=tEqhuxKC; 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 c64si9461407ywf.295.2019.02.20.07.54.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:54: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=tEqhuxKC; 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]:41320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUCO-0006b4-9G for patch@linaro.org; Wed, 20 Feb 2019 10:54:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTow-0004eF-Ga for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:30:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTou-0001Qy-1H for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:30:02 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:42547) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwToq-0001Od-2e for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:29:57 -0500 Received: by mail-ot1-x344.google.com with SMTP id i5so40735901oto.9 for ; Wed, 20 Feb 2019 07:29:52 -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=tEqhuxKC0YzwX3x9Bhi4etQDGSVeuWDSuMaRQu/tjlZxyRbnwZzIlE4h/rAdIEN5u6 1wo4aiY5/J8BSR1uvnRyN07x/aM3Gb5Ug6Srt6kfUFEnLQKUEiX5yaBHW0Yltw0eq35b wxMrhodiNBXV2bKaGeGCpe+5wxJzbNS76d1nbqTB9kqqImWrskno+HubgowwZ1J+mNER yHz1m9jSBbjqWDUrIVheKn51Ie9Ds+QUteH5v4b3ZB7ntb6V3YIZIzPUh985H/QskBaS EF0TDX2FzcIrcvphAsQf+X/ZhvaWljbqgQmGKafC4fiqYas4BwwH3tVxggN4Ln1MeBQO vMCQ== 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=BxWTNMjxpqFDS9SlBaKX89bNDf3+FW1DFoJCXV+Xsjq+YVK2vaYo0I1y+7w2Ygb2Dd 6WD5/hD3guwQCsnXThN9VIeu/HVo59yUbDTZm53WdcA+N9W+rE9ehcf2pdJ860gl7sKY TosmO8SPDEiQ6uhxCO/gyxpNhyHo7AXaQr2VG3FjmMK+ZsYODkzpn+w/o512xcW6q6Ta /gdP55BUCzb9uhy3PuIr/xYD+4khRYGlGbEDDAtkRZpbpKT2Gyi1L72siJvaVtXp1dTU 9zAbase/qD5+Tpr1cP5Is3a3m3ltp3t52jEl3mDEav1BKik4B46tJJWjX+t+SWmyxCcj oFsg== X-Gm-Message-State: AHQUAuYdO1O57mTyBF13i7h/XKBEch2EAD4WbAINbq4SuMXHURovgLS7 8abIwt6svYl+j46sT/QLMHrJ82r05A== X-Received: by 2002:a9d:5e14:: with SMTP id d20mr21526668oti.172.1550671217533; Wed, 20 Feb 2019 06:00:17 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id y124sm4111493oie.57.2019.02.20.06.00.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 4E30C1808F9; Wed, 20 Feb 2019 14:00:10 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 23C36302A6A; Wed, 20 Feb 2019 08:00:09 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:49 -0600 Message-Id: <20190220135956.22589-13-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::344 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158833 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5085030jaa; Wed, 20 Feb 2019 07:57:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IaKLbozEfG71A+xyCFjaoMeJeoBRHNueqE8avc7mAFY9kinaEC1HzCndyuM66x4QCdWGCGU X-Received: by 2002:a25:32c9:: with SMTP id y192mr29500937yby.244.1550678263527; Wed, 20 Feb 2019 07:57:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550678263; cv=none; d=google.com; s=arc-20160816; b=Ol+vJ/iLZ+tLgieImQnOYT+Fze2xk6KAxgR8D00InT3grRnFcgssTSTPX+3F/eI5Sn dXbhwQombC92rjzb74oa7CpnV2okunJRxM56SIUYKl02H93KFBhL/ZXY1VmBMrr4HsdD Cp6AWvdwXpF5IR43PCBJ9kI+jTQ5ykRrBuC2D6YqLjr6GVMju+Np7OS9EANP71H9dEj5 VX2U0reX17DCLe+It2p4vmoGUnja4DO4khSPh2BxEESgwvgqAdAz5mfPbhY27NtMy8uO d8yMAGrjbz0WZFwH0uFxZQTBet542X5fV6nVct2fRKfbeM9RNXtc64TuW4q9PtHDZvue M9+g== 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=HrLP0g1P/fNxo2j1ZygwD6qK3qkV3Nnnx13TqSXpsn5lpNPwsF/N9aKxLh4vrvO/+0 21BPFMQcKJR95Hdm2kHtFGaf8DyuiB8SX165x8swiAvoRSLxceqBQiPvJxvUXB6EDHUx SeE2pTIhPpDyZe048zURKvWK/1N8R6NxXxIODrUIlT1opa6SBmfL3Qx7T8Kw6grBduHF VHbMYU3EVFfC0JKPf2lM12h3h1z9MZzrrdO5FzsgU281ipqCyGVHKCe/jvjtzbtDTFkp Kw7r+gyPWZGdnIBLIU5nwInTx3T+lt0LXca/3cVS9Di3pL1ufVy2rFdlNkuAuA05//cQ gSrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Ot7Q8PKB; 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 q17si11344752ybp.368.2019.02.20.07.57.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:57:43 -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=Ot7Q8PKB; 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]:41431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUFi-0001Ts-TK for patch@linaro.org; Wed, 20 Feb 2019 10:57:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTwH-0002KT-Kv for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTvv-000634-0T for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:27 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:37318) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTvq-0004yZ-Ub for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:14 -0500 Received: by mail-ot1-x343.google.com with SMTP id b3so40817683otp.4 for ; Wed, 20 Feb 2019 07:35:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ysp9jG7buWT7lrGZ69hqgy8eTQ886skoQ080vnSGPR8=; b=Ot7Q8PKB6jEyjcT/kYdT3DXO9sInl/d71s7CEB0HMrunS/jjhxfyL6zaNGpRBgJt36 xFRefp8AXLbCVYnJ9Bfk/BriXw7ihp+rfm+uuX/p69tlgfe5lGyDtudMzNcTnM13+KdX Kplc0LeYQhl6z7+Kqm/RpXdlivjTY1a1ahuF8wT4EQ/51p8fTdHmL2Ttwsx54vtXsjKq WfQ+EVfKnt4cpr6Lw6reCe205pEdVSUKG5+3gFx+vzPZDRRlmXvniiDIhITOoMXa5069 UpxfuGufSMO0oH3ASr+x52ey7uHoYeBaZC9ZtoIhS2tRsijhiF0dT97d/kiX7s70tFcP hImA== 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=sJBDKMAdUf33yVQ26DkJw0fGuCjS9d+JLoKKGiQ4PbuMq9bwfiwAiES8PC6kXwaGS6 kSgZB0xs0uYoQPHBI4c4o4WbCz86XUXF43xP6uX7tAV8hZzE8O77qBzytZYgMitORll7 qSCTUeQE1IXWY2n3bPow+cplcyNgwtAOyWrkgTt8A+18NOxWe2glgRvginMmPvnKb52n b6rVsCkM0jSAYQLg+Y+uGzu/IYaXjcQ5E68owXosUNlJwxyxGnkU3FlJ9aonOe/gC4j6 GBZvrr0hJMsLOSOdmPxEIGomhR/270WrCF6HpDMtqC7S3Abw7uFjbo5stCyDEim+Gnjv OM8Q== X-Gm-Message-State: AHQUAuZY/JuEUfms45ZsQC63oMPqFsryKxssL02bUHHC34Fqg+JfyTPW kuwGNNI5yr6a0AXsKzBq/fSd4Wmo4Q== X-Received: by 2002:aca:ad8f:: with SMTP id w137mr6171599oie.12.1550671216937; Wed, 20 Feb 2019 06:00:16 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id i9sm1561125oth.13.2019.02.20.06.00.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:12 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 2D09D1808F8; Wed, 20 Feb 2019 14:00:10 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id E9279302A6C; Wed, 20 Feb 2019 08:00:09 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:50 -0600 Message-Id: <20190220135956.22589-14-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::343 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Transfer the state information for the SMBus registers and internal data so it will work on a VM transfer. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- hw/acpi/piix4.c | 7 +++++++ hw/i2c/pm_smbus.c | 31 +++++++++++++++++++++++++++++++ hw/i2c/smbus_ich9.c | 10 +++++++++- include/hw/i2c/pm_smbus.h | 9 +++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 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 Wed Feb 20 13:59: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: 158835 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5095396jaa; Wed, 20 Feb 2019 08:06:04 -0800 (PST) X-Google-Smtp-Source: AHgI3IbzwJLODd91NQ400pRLAdPWKLQ+uyuBXnXJ2xCDeEoMeNqOGLW9HTJ5OqzFxsae+JxRoBnK X-Received: by 2002:a25:73cc:: with SMTP id o195mr28045067ybc.310.1550678764678; Wed, 20 Feb 2019 08:06:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550678764; cv=none; d=google.com; s=arc-20160816; b=GypZD+MWE4ZoW75nZeEtGOWHootBx6ksMjc8wejge/wpGR2PatI5+hUU/SAKbITFcj 1Ff1/uxXvjVOCUWFnI2U1nFsqhN2kjfODqLNcowmYQXaivmDBy4bQNS6D5e190Eudd9v ETnKkTB/1YuAVYGj3V0s5sQ8OZ3KCkqG4TbC2d8xBhUa3LfI0K7kdCtahsq+TtxwlfAz mZMIpunpjMjsIXu8J2Eyrj82UFxJaQoyRGgn1QutqtE65LwGJBWWzLh/JqiRoDthV6Kq SMiQSKeEGPLMlEK3LzLODfQy3O0SLQ4O8e4JpMY/PWbjW4wflROeD8+fi+txTsFICr1F 7snQ== 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=FY6zAx27U5OLm8dckKrS00O5g2dQKBgUvZWKMdXElyrXH/fC70nUE7UVddmC9x6gJR T2h/3iHtGg5YsTsiXzs5BZiqkjUj3tyXW83G5gvDTXBL2RKYQzGjHBfspO/jDJ18bMXM QV2V4mHeFGkQPutw8+QRmtbf2WSEfWLrCUgNTs6r7t98vNayRrQEI/KJnmcz5xmx2Ksp HXhvA1UxslnM5F1P7RpdNuIkp1F/xUSEhLav5RaS02fqwfI3mfBMPk37QqbtEwq530VN Caq49+icfiKs7YHmOIynZMvpVOCPZF9mvtsHMvT2ih3KcdBJ9ulav3f0eVvUXd6gY4A/ qHNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Ce8Kn6VB; 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 r133si11187711yba.429.2019.02.20.08.06.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 08:06:04 -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=Ce8Kn6VB; 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]:41595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUNo-0000Be-56 for patch@linaro.org; Wed, 20 Feb 2019 11:06:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTxK-00036O-2w for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:38:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTxH-00070z-QJ for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:38:41 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:37344) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTxH-0006t2-9Y for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:38:39 -0500 Received: by mail-ot1-x341.google.com with SMTP id b3so40834618otp.4 for ; Wed, 20 Feb 2019 07:38: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=AoLcNOQ30aKzN3oO2kA4DzR6j6MGF6e7733YDW7t8Z0=; b=Ce8Kn6VB9B5RcfYIO9ZHZX4t0NIDPRED4xOIRca3HnjZn++qKrl5JGu4YdAKZyqj6o Y9ZFwOrOes8WO809kjYpmJNvmmIa6OexNHY2uE1sc6FdR7Lnm19AISmVxls6IWA0crYx aaqVupkqvmIQgP7kbpo00/Sbb2uCQQoScbx4tl0LN4JnaFtLXVkHbtw1+spvfawtw1Ex xM/BiSnIY3H53FShAU7JMbV0rhQMP618ZVHHk5kNGmnoR4+3mlE8V7zYs4cCvdSfQ07F e7KoLOsXH8/4RjPaIQnAIWq3BKQC0cf/afsY1E+bSuzoSznpBwW/vkL4uBR2BdMO+wK6 d+/Q== 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=eHHqxg//nrV7PPwP8G3GKPdls6k5pisKid09qv1eDSbDW0N33J2NywFY3gc8yxfm33 kbijIV9kEd4HP/Q72c7k5kftUZMa1h31kFA8ITzTB66bgRvKkugwFBX4wBT1QoWtAZ4s 4E28wBc5QjPLhVCE6oVZh8W9b6ihjEaBXUkn+JrDIFlOtXn/gu0D+owLi5uHA1GufBKM kGvH3286P3SIsd+gQjhuyCgJFvzTqubnqeNaGUdFRKKm1Mprs1vQBHZZCr3j1YdoDRFI CaFyU2kU4mzuZfGXvERJ/I/WfLwg5zQ+KN83quONX7stj18LPJFtF95nOTxGi+6U0r34 S9rw== X-Gm-Message-State: AHQUAuZXVkiCyj3362chCwgUUGgJdIuvQCKGtzFJ4k9XIQfsdtFDqHAe nT0UZy2Tt4U9pMH4seXtEBLD2ISe2g== X-Received: by 2002:a9d:22a4:: with SMTP id y33mr9689812ota.218.1550671218875; Wed, 20 Feb 2019 06:00:18 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id d10sm4773842otl.69.2019.02.20.06.00.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:17 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id E5A941808FC; Wed, 20 Feb 2019 14:00:10 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id BB477302A6B; Wed, 20 Feb 2019 08:00:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:51 -0600 Message-Id: <20190220135956.22589-15-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-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::341 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard There is no vmstate handling for SMBus, so no device sitting on SMBus can have a state transfer that works reliably. So add it. Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert Reviewed-by: Dr. David Alan Gilbert --- hw/i2c/smbus_slave.c | 18 ++++++++++++++++++ include/hw/i2c/smbus_slave.h | 24 +++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 5b3046f6a3..9a2d314d1a 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -201,6 +201,24 @@ static void smbus_device_class_init(ObjectClass *klass, void *data) sc->send = smbus_i2c_send; } +bool smbus_vmstate_needed(SMBusDevice *dev) +{ + return dev->mode != SMBUS_IDLE; +} + +const VMStateDescription vmstate_smbus_device = { + .name = TYPE_SMBUS_DEVICE, + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_I2C_SLAVE(i2c, SMBusDevice), + VMSTATE_INT32(mode, SMBusDevice), + VMSTATE_INT32(data_len, SMBusDevice), + VMSTATE_UINT8_ARRAY(data_buf, SMBusDevice, SMBUS_DATA_MAX_LEN), + VMSTATE_END_OF_LIST() + } +}; + static const TypeInfo smbus_device_type_info = { .name = TYPE_SMBUS_DEVICE, .parent = TYPE_I2C_SLAVE, diff --git a/include/hw/i2c/smbus_slave.h b/include/hw/i2c/smbus_slave.h index 79050fb92d..ebe068304e 100644 --- a/include/hw/i2c/smbus_slave.h +++ b/include/hw/i2c/smbus_slave.h @@ -69,14 +69,32 @@ typedef struct SMBusDeviceClass uint8_t (*receive_byte)(SMBusDevice *dev); } SMBusDeviceClass; +#define SMBUS_DATA_MAX_LEN 34 /* command + len + 32 bytes of data. */ + struct SMBusDevice { /* The SMBus protocol is implemented on top of I2C. */ I2CSlave i2c; /* Remaining fields for internal use only. */ - int mode; - int data_len; - uint8_t data_buf[34]; /* command + len + 32 bytes of data. */ + int32_t mode; + int32_t data_len; + uint8_t data_buf[SMBUS_DATA_MAX_LEN]; }; +extern const VMStateDescription vmstate_smbus_device; + +#define VMSTATE_SMBUS_DEVICE(_field, _state) { \ + .name = (stringify(_field)), \ + .size = sizeof(SMBusDevice), \ + .vmsd = &vmstate_smbus_device, \ + .flags = VMS_STRUCT, \ + .offset = vmstate_offset_value(_state, _field, SMBusDevice), \ +} + +/* + * Users should call this in their .needed functions to know if the + * SMBus slave data needs to be transferred. + */ +bool smbus_vmstate_needed(SMBusDevice *dev); + #endif From patchwork Wed Feb 20 13:59:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158822 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5064783jaa; Wed, 20 Feb 2019 07:38:19 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibo63ePWLrbgWJY/pwRNU3RwLGAipke2U6qNXT8NBN//OkKDaV+MNuGp1PeDgA/y4v3+P6p X-Received: by 2002:a25:d090:: with SMTP id h138mr20367348ybg.0.1550677099895; Wed, 20 Feb 2019 07:38:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677099; cv=none; d=google.com; s=arc-20160816; b=BcEInZQllpFTrJRbhN2gaUetzVtlZuw5GVzTksWK5VpQbebEhPqSJlzMjHP6F5U/i8 HrSQL4GguEWNLG0YSYPayzXuH7i0rDy54dztkF8gbPFDUzK3ptGkPk8IJrfrXlG5g4Zs FV9E+ycMN2/xbPjRxTSWzdPtyRmaKzbFPEtQwdmheWxdINU3NBgJISeu5YY7yYJ4wQzk NWjER3Zfe6ULkU9ZhgaXgFgH3f0pHopsX1rMiT5wN6wj12UTD9HBk/p2Mn8/JvwwblZB DaDIn/Gjlw1vpfs4Z/E8X3xp9oWyCju4jYgfLK7Fcvqu+c5UDCmQIIfzQ2HKNFr8zmUF LLcQ== 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=QxF+p+LfjUdh9WEGc+TYID4ANibck8WNknHB9WT06fRU545BHO9RwMv+bI7IDhBc7f jat9IZUOAoWJkxP8eyqzCEzTH9ILwFRrWVtpWjGXuBrGleRK9wuqLZYhhSKwZNGC45mY 1fp94lwjvxTbkx6y4NRex9hBfDLIvshyGYlgPpiD7RM+n50HE0JwfmhntuU9LUyKaHm/ cr3/MHv04WOVyW/gpFZdftisc9rO6VLOQw5KY0fOxVOaxrWDaPkZ53fhrxtPX8x/8r4p wuKRGeV70sU7RjlOvqOMLgckyaxaETQWO0ERPjVcMq5CvpmVwRWVmWh5ndzLRdgjjZKK Zu3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ZYA55BC6; 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 p191si11818212ywe.69.2019.02.20.07.38.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:38:19 -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=ZYA55BC6; 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]:41005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTwx-0001c5-Aq for patch@linaro.org; Wed, 20 Feb 2019 10:38:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTkD-00006H-PZ for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:25:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTkB-0007kb-9G for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:25:09 -0500 Received: from mail-ot1-f65.google.com ([209.85.210.65]:34571) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTk9-0007cI-5P for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:25:05 -0500 Received: by mail-ot1-f65.google.com with SMTP id 98so40817037oty.1 for ; Wed, 20 Feb 2019 07:24:39 -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=ZYA55BC65sEb8shIyn2te8Mlar8qd9iqNp2lkiCg/M6Gya8ig3ix3Q76R67GFgT4Vz Y6nLeBMKpj3q+fuuRYcSPdHQ+3NcVDh7XQ3zcOVfX7LiA3cDWHuTZXIHD5cJu8X3hegn Ph/GcH00A6Ins7fhno1y2QPUt6bMcAjmeI2GmBo2XY34Vjut4FuKuAhG8AKl/jOscQiL hIPYIncFZNmoewmWraG8xu1XWQp1Ie2me0fR0eL6NYIRkI9CQDaRJFCHyarXksrYJRuv DJmwhyHaUZm9HdpJOyPsmZHJ7L1bzcKk3vsnwD1Yix6ctkmxWR+0x/HhEqW0ML1PKuzC t7Sw== 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=dypSaGieaY48CPhFZBNb8LX+63C/mWuuWLhheLfzAmXdIyWP7OYrGu/cIdTlMoLlPK foz0zavtbivQMVy7MVfvTEPIPSG5eyRsWx/M570VyETb59us3ru0l7FRnCjHe3P+j+X6 KVDeT5vhkHFPfG+rkH3ucm+lfoZ+P4FP7HgRW1BeO+z7zl/JTeNpOabcap50/ZQLztrQ TQ5AhNWJPmzM0DhQiGraXsLt8HiGyJnxMVjYVG9h0o0zGhKpg3YEi5uwjjr2e1HgxPo6 Y6xFA72fFF0XJbIEcNhbdFwLHzrfWmqiBKeBZGSBDR64TIFUqIhN0tFsXv3Jc8urtkZ6 zXmA== X-Gm-Message-State: AHQUAuZTauwFCpxkavnjmdz3ap9wtmJozNk5cbbN5gHAYJCSs6JEk2Ee Vlw3ChsPCKMkO1QmDai7/lavx5+OgA== X-Received: by 2002:aca:3746:: with SMTP id e67mr6211685oia.103.1550671221813; Wed, 20 Feb 2019 06:00:21 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id n65sm8579718oib.12.2019.02.20.06.00.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:20 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 2C2EB1808FD; Wed, 20 Feb 2019 14:00:11 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 06F48302A62; Wed, 20 Feb 2019 08:00:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:52 -0600 Message-Id: <20190220135956.22589-16-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.210.65 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158827 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5076470jaa; Wed, 20 Feb 2019 07:48:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IbZjGfrEfFeCtYCzCeawJtLz4QYHZbpoedM6hZVUYSmy7LPudhBWm8X+NC7RP8/ua5Y+XZw X-Received: by 2002:a25:9b49:: with SMTP id u9mr10253509ybo.475.1550677732686; Wed, 20 Feb 2019 07:48:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677732; cv=none; d=google.com; s=arc-20160816; b=a3zYoYEdZB8j9vcF/ff1hlvTSwAq6R92ZSNwC4QWkiw6y+9bC1WQjyAQkKINRUiTBy w7RmDT8ROveG1OgxWDLU1s52E3MrrpcXWE4mpx6BlB8iJIVEUONIVVq0BB85JvwwV6r5 oAxdcqYVgGEludmtenFkM6k7piPM2IAuxPXBOr0WblSDFCCB2zvvtXkAzTYO/Tu6Vgzu p3XK96jKIEA9AVGQcKEa+ruUzVgcegyrHFXL2bMPLhxSchA56c9kJuCHc8Ff3oNbpoIF +eXX2DvyxGlS15Ax6d8/JFAdHe6H37jCnhgfzd8zrJnofCDqNqGbQ4xFWUwJnYbGuROX yYgQ== 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=e/3mgYtv2lqiG7CQAOqdIOsCvu0S7VASswklRynkk5oQdjHhdwg8V01811xKJUpzmh TVgC9TK2heak+gHIyHAskpvSoDch2ObsyY0+oTsXQBaPFHaSZHL0fdiU1OKaRvk/rdd7 4anSNMB7ZjO/+uFsl8nvKO8j4mCBbVcWQNSn6stVlN9JzPyZWQqnQ0i6IqCZ5mcG0rK8 qN0d3LJP8JDZ1OZ+DCaNS7EeIARtMvLW8QxWD1XLzBLD9DaiJxIXf8snNa+uawUmoVj1 NgYrHPSPVH4PB/8aWSjCBRtNamOpi6cTliOgxzhd2brv73/wKhZ06p5qNPATl5H760kK DLSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=oV11Np8r; 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 q203si2644968ybc.34.2019.02.20.07.48.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:48:52 -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=oV11Np8r; 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]:41231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU79-0001oH-Po for patch@linaro.org; Wed, 20 Feb 2019 10:48:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46138) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTqJ-0005qN-Tc for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:31:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTqH-000237-NY for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:31:27 -0500 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]:39564) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTq7-0001yu-R0 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:31:17 -0500 Received: by mail-ot1-x341.google.com with SMTP id n8so40771762otl.6 for ; Wed, 20 Feb 2019 07:31: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 :mime-version:content-transfer-encoding; bh=9BByOpfKlj5BdmNNBOif+f406Blfw2gzhg0xpDJUO0Y=; b=oV11Np8rOnBdZXzoFi+b1JajqDCjZwLaZc8Ue2XlTeERFSwQILHqpH99ungjxj5WcB OhfhiHgPjUm9xfVaWTKNVISuu9XoPsBfHgndRwfh4pt3ohxyxm7bSH74WuJBW0XzBSVf DwCxTZkfVpHhL83rBNdOJTKtxOFwyN61i/J/lH/7Saak/6GWj+H1WkUAffPaSkX+fn+X Zb5/PW3xjcGZab1jZO9CFpKDD0+IyWfT7tlBALBbR8n7OTh1AwJK6ee54nE9AO7XtJv9 KJIjTozuwSbDi2TECuCmdpFN4Vzq+KQn5V3rwEg2xC0PsthmfIbNB9kDqcyFgpkOIiCi dlEA== 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=OSKy9J9SRWd+pC43+x3OjsHH/4qnY3C1IwZV6WoCv+LyIO8CYKMFvT1OzWtq82v3H4 R1wPp6rY/igWxksqm7p05Bwco1CEhyIkd8LqemGUyVJVwGAuTm8stvph8MmHBssoWOO/ vUbnkJAQOoARAWDWGcClr0boWRmU4v1M1RHUjVi8+0LvTJUiTPNvfDM8lHH72UqyRBYH ky8Sec3IufDKEG5FZUdBlOzOrqCir7g6nWhK6TQ7QcBGanIY4DFDoqOfKdxsoGzDHJfn aN5UcFsTMQsdxWnvw7O0ZvsQRjrz70XzZGrwvhv5W6E0ZoFPZE9IztA/EOlvAro8vXeD dXKA== X-Gm-Message-State: AHQUAuYymiY5lP2HdIAHM1LGAdxKTreoO41w15Dpoov+e2ysSWi8bA7G UYCe8h0na1hkBi2X+nfh5Kk/iJDwTA== X-Received: by 2002:a05:6830:1103:: with SMTP id w3mr1135421otq.61.1550671219478; Wed, 20 Feb 2019 06:00:19 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id q67sm2024648oif.40.2019.02.20.06.00.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:17 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 0FFED1808F2; Wed, 20 Feb 2019 14:00:11 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id DBFF9302812; Wed, 20 Feb 2019 08:00:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:53 -0600 Message-Id: <20190220135956.22589-17-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::341 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 158823 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5066920jaa; Wed, 20 Feb 2019 07:40:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IbG4+tGo+XcpjYyO33ly+5k3C9Fk9GrEtWm0QOrKqvOhQZfliciGPjS4mk2i4Ikkqsarmoc X-Received: by 2002:a81:3cc3:: with SMTP id j186mr27556788ywa.315.1550677213437; Wed, 20 Feb 2019 07:40:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677213; cv=none; d=google.com; s=arc-20160816; b=Cztc1SdPlZYmeLmqBNjQ/Tz0HmtJ8ygLcTgZ/g/OyU+0SyjMb2uBfI2g49/siFYRvs 7/Pte3ybO0thx0YwdkZb1LCeYL374ruTzjbBm6jmCiY02bXmhCkRnhY2pQ8kWzhyxwI+ L17VOg3r/vd21URbujA5/VCxZSrLxqCvgHSqHGQlyDDnooKoSWR7jU+zhBUtxxyoK0kW nAaOeUVbvc4lflPPSfD0kKGL3vuz7RVZO6VWkTHsAhTwQ4gaqmBF+CadtRVWAORKFobl 4QFsh5yCD7WNd/2sm39lyRIr+Wsq6jkmmMIMZtMJPlehQsjBTJzODllcLhYTX9VpLWEa z5lw== 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=R2QQ9FuAXTWBBv9l90TEYTVwewiuhTm/T6eQeFCrJcQcXWMOj8w/shf5VAR5OqqXXQ +VFLzi7x+nmht1ZxfehyRKVsPi/dGbr6na0xKX2eYoG+7mlmnnZ0hWRfLx0qQzJ5GBAj s5I+P4TuMmMLBicNA6eCcM6xKBrYM7uat3EdcqKGlbmm92uDg2OE7qJWxQprkIp1GNUR xM3L7bW6GnVMl4w9/tWEqtAYBYM41XGbRKNMUf3OPUFP4TL68IaAiFooSDbjP/MzK8Kl da/1NTHq24WrL+5Fveqv4puMWWp9SOq4KvNlsR+lNb5OiW523aEWmKKm+zvG4FTtGOo2 VQmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=XqljcMPq; 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 b65si3106916ywc.333.2019.02.20.07.40.12 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:40: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=XqljcMPq; 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]:41038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTym-0002x4-HX for patch@linaro.org; Wed, 20 Feb 2019 10:40:12 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTma-0002E5-Jf for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTmX-0000G7-Ng for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:35 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:36110) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTmV-0000CX-Hi for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:27:33 -0500 Received: by mail-ot1-x343.google.com with SMTP id v62so31914474otb.3 for ; Wed, 20 Feb 2019 07:27: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=57kh67Tu41hZVnC/NJgxfWgmjYyLR+EzK4WyD222hhs=; b=XqljcMPqCYEZhtfx4jpFu60TdYCbwupCqoTeLBWKUNRD2vyNWGcER/hFRu44vTGUCm sB74cRDKcRbq1KLLmgwNgyuhPeJCatU+3eLSSfWnIIcLI3WWQT3B8yK9XjHwH4l5QMoE 4bmJ2TkpELDSjBRw/iddyy9LTREdkNd31BrbLCtAseQ+XbMjZlZE2J4W0kd9xsqQRAGD oclesWLQSBzeHQd+njBj0+JIHCRXJmbYyZ8wIJCHu7QXwRTZE+ujwnVsSHcVG4yzRKgn 3J92Lbn7xckwMgCPP1WROptAp1AXdKPkOWswcHDsXnar10Ox3U3BLmnn1q1+63z9huDa L2YA== 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=uO+iYaeBWhh4R+ntDcZr1HMF4h+6pj9+G6+IHi0ABi6/zW7GtVgSyaUN8o+3R+iNgI Fj7kZhWromwDl1s5PwjMlsudpiGlQlP4pifHS2bGKwuAybamrYIc8pstv7M89Yt4acYK NNxJ3ovOy4L6ectdLdVh6IuNIaViIUsjBs57eG/SIUjllt42H2rq2aP7V7aRFQLcdTWS 0LiSxyLdPowBxNvVPhbOV8WeBEBGdIdqITVvWDxZ2E5vHuzRMbewWQ8NGyLTXldcdGmT l7fSmOmdD55DrsJURBggBJmaG6mYzsoFBjuYlfOtZtG6vUHXcBm2S9YVOXRnjwLqB3Yo m9Dw== X-Gm-Message-State: AHQUAubNTZ52jBe4E4wzxNW+k8B1HD/UAn+cji0Ba4M2QqR88H0UqAML IqImEKqjMn0Wpn5+lBrJfoSLx160Yw== X-Received: by 2002:aca:d6cc:: with SMTP id n195mr6124979oig.27.1550671219993; Wed, 20 Feb 2019 06:00:19 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id d6sm8107661oia.30.2019.02.20.06.00.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:16 -0800 (PST) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:d1f6:7172:48bb:512b]) by serve.minyard.net (Postfix) with ESMTPA id C48141808FB; Wed, 20 Feb 2019 14:00:10 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 98793302A62; Wed, 20 Feb 2019 08:00:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:54 -0600 Message-Id: <20190220135956.22589-18-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::343 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Transfer the state of the EEPROM on a migration. This way the data remains consistent on migration. This required moving the actual data to a separate array and using the data provided in the init function as a separate initialization array, since a pointer property has to be a void * and the array needs to be uint8_t[]. Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: Michael S. Tsirkin Cc: Dr. David Alan Gilbert Cc: Peter Maydell Reviewed-by: Dr. David Alan Gilbert --- hw/i2c/smbus_eeprom.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index 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 Wed Feb 20 13:59: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: 158829 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5078555jaa; Wed, 20 Feb 2019 07:50:59 -0800 (PST) X-Google-Smtp-Source: AHgI3IbLM76oxC+PKyn86sJS1ogmOAVyY5Ef9q7Jcoc7+rPDBcdOnQxz6ZXnx8b18Er7abZPL6y6 X-Received: by 2002:a81:5a86:: with SMTP id o128mr26781161ywb.205.1550677859664; Wed, 20 Feb 2019 07:50:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550677859; cv=none; d=google.com; s=arc-20160816; b=nbxq5BuGclF9if9wwde6XgW2JiXM6DA9Lqd5QEjOipVLbjZ2dXHCxhh7M5Ju8D4oq/ IXFp26b3Tpsrmb6v4/GH6EcE+M3Nho+yq8KFoARJ8zK9KEj1LJGoAHpAIzam394hujp8 yGwESg8hWfpbRKW5BNiGjwvUBoLY0vLTDP9TqtpeMj5JtHzs7+VGbBuH8+HcaK0hkBW0 RObDDfHc9y31A2qWBiuL5Esgz1bpAG4oA64n4c8C6sFQceClzasmgtBNkCB23f7bLXVf AP3HFQpGmDX8gkcA/ctK85yJQzUuANY5kzrkqM18PhlAZrEj8ZBBkn3iTb+wSoh347k8 6RCA== 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=svFWRYkmbdwqgf4LRRgD/9BhWqpy/1Abi25DzZ5+tO3I2s//xXlmuw+YlOxyP/3oPe oXtjb02a1Xwy0Njci+D5mpRpFZ/s2maiN539Tt9j05Hj8MODzS7uTJl0wxNpgUa4N2gv l2MTqyUnoErzRARa7/oyJ/Ap2He94GTnLPGKedkeBeeV5kwshBTPv8zG6k49CJutVBlh 8v574UTU65lv4NbUAY5K2xQ1z5UBeM2yPvb/vK7sbLXFDlYQbg/BL6sZVzXCOWjaVuVI 735BQxxRoSmEU4AvS3Klec2yAZ5yWP9+W2PNJVXpOaPmATW1Rf7rlDqbvg4+MBkoKLuQ hXJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dskQAQcM; 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 v127si11032732ybv.113.2019.02.20.07.50.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:50: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=dskQAQcM; 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]:41254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU9D-0003qF-3T for patch@linaro.org; Wed, 20 Feb 2019 10:50:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52003) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTvu-000200-6z for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTvq-0005u9-3Z for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:13 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:43372) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTvn-0005UN-8a for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:37:09 -0500 Received: by mail-ot1-x344.google.com with SMTP id n71so40778176ota.10 for ; Wed, 20 Feb 2019 07:36:34 -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=dskQAQcMSKCTpMNshfMFyHEton0vbBwqjFEisPnrrQJZ8SwGIvP7SOTE+34/t5d3jo K4Pv7hpEWvl+EvjhW2BlxLPDeNCI5Ax5eiCoT7YHBbGMgAv3KOw8Xe/dSoIkhVvJyUSP Nq9qymjd4SL3fRcvgLMCeIsFK5fMkZzDfSn5frKnBmwjTegjGKk/Bvqd3smPK4ZU92ue yenYiMhVJar/ojNa6nTDVK+sKOI+eXVyvY3J3Pr/QxQKOHjDdKsbDU+mLPi/Q3WP0uJU EExboCNdRr+GNI62XkO7Hrj44zKwONyf4gAQFAwZcgtRnmuHXBenJp3uhWo8oAYQZFJQ OpUQ== 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=OwOWrNSxh+6aPU6uB177WKwIAkaRbllj1v9eIchlSR37npJEaJA50CSoMA7NCdy9E/ spYP7/g4L8veuDLfRcRshjqX5zOdMbRn222ndzOf4LfmjCaacRquy6wtVp5BwzeAprMd vd/lVcJWOW1cdBRyaqByyLFL7NRHMiJpnAYrDkv+VkhJKAynPgCvZUH20tcS/PYR5E6Q /gVdzosN8uvadoonEMEuTpM6MpjQ3BdQ9N+gkL2Tcj2o5qFIiBUe7B24UtKiZ5PmtwNK bEXQAMuYxt74hVx1mRgrz+2VGlC8n3DtSXbq7wXM2TQ0e81cENA/r7R7kvIpXqAokN8E ko6g== X-Gm-Message-State: AHQUAubMGZLuAfx4DBjHQ6U05ZpojCo0gk11XPcq2bpQY3TmN49ZUIlo fy7S5/9j69ZiT2hAdNECjCLOHBPeqA== X-Received: by 2002:a9d:5617:: with SMTP id e23mr22212269oti.193.1550671222553; Wed, 20 Feb 2019 06:00:22 -0800 (PST) Received: from serve.minyard.net ([47.184.128.64]) by smtp.gmail.com with ESMTPSA id q24sm8037917otk.46.2019.02.20.06.00.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:20 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 4F8BE1808FE; Wed, 20 Feb 2019 14:00:11 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 23A7F302812; Wed, 20 Feb 2019 08:00:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:55 -0600 Message-Id: <20190220135956.22589-19-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::344 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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 Wed Feb 20 13:59: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: 158817 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5060223jaa; Wed, 20 Feb 2019 07:34:31 -0800 (PST) X-Google-Smtp-Source: AHgI3IbN0Mv57Gn/tWx7nHFPh6P3CVadmGMWfatKfbL9ojIRlMDieZ/te0U55ekoucACNxgEpL6b X-Received: by 2002:a25:1e43:: with SMTP id e64mr28834526ybe.513.1550676871508; Wed, 20 Feb 2019 07:34:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550676871; cv=none; d=google.com; s=arc-20160816; b=oQHUYCrxH0DP0gHLvAdwVCX0PDIAUyi1g0gZ+uUd9Uw0XbWeiRN9pDCHsGezgrGu0e kN8Qi3/DHoDEn4Tuhm6LSnF2mwBrrtk/t+kq62yO59fV7pbL/fQJaFpmaj9WH1md6c8w 2VMvlkw+KxK1bXYJnhX52c7hzOEn/O6Cu3Fuyr5u4uVJGNU9xvHJHCz7jUFKdT201UV+ vCezwQczTrFEX/qLceZC5aTnndWw3QBLS0BPUdS3LQJoD8T5WxI8/Ay4pNvdKOErXygH z6yoakqzWHaUh64mLluy15JI/rPqOIWxZed9+T1YVxmzg0Gz7pQIXkJP3OlMy7tqItmC 6avg== 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=OIGzb9Ia9yq3MmFF0UtL4yvEPIt9QX07Z2gtgFi/kwOh/wIY4S/3Em7/434DkRnPp3 OMhEW2Aw/8VTvFpyKhSITORZucbYp+BiqCOWRM+/42Fn0B99htxwaz+1R8pqvSW+mL7H atLqegW/fDJUrm4Ny4pruHBj6ZGFbG+bgAPuRyLjatNzlVRJA4taWUXcPGIEcXW6frgm qqchzER6UHbcrC8G/BjNh1cbGlQOv57yNRwldJFWhAH6eShj3+YaQ8Ii61RtJQYTbuhX JeKRzjLak9E5wUtLx6SQwR2WszlO8cpjLLEZiZ3GV7UdD+HXqCF68BpT9JAnPFLzgBDt Qcww== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=sBnF4ppF; 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 j190si11317616ywd.368.2019.02.20.07.34.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 20 Feb 2019 07:34: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=sBnF4ppF; 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]:40939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTtH-0006nL-2a for patch@linaro.org; Wed, 20 Feb 2019 10:34:31 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42366) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTk2-0008N9-Db for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:24:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwTjj-0007cZ-4o for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:24:53 -0500 Received: from mail-ot1-x343.google.com ([2607:f8b0:4864:20::343]:40082) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gwTjf-0006mH-T3 for qemu-devel@nongnu.org; Wed, 20 Feb 2019 10:24:37 -0500 Received: by mail-ot1-x343.google.com with SMTP id v20so8764131otk.7 for ; Wed, 20 Feb 2019 07:22: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=vUBNL7iuL2tms8dcSHLWhPEfJJ8Hjvn6D7ICUweDvw0=; b=sBnF4ppFXVrauj4d7eoQu9li9O6ASLXW49+bNseY2iVf6TYomXnQ7XEyLYHYKKyh4k 0I/Drs0l/3P1fzC/ppbkRxVZMTyaB0NnWslW79lQRrnk2i4dmUj5n/aLE58wjeQCTu94 qEMoOxKxpjJAWgYmY+y26zahiQLbfCpX1fyLKS3BMt5MLwgb0gLHxz4zWEUznnp6Syf0 dSeQXarPBy0x6v8Sk0LCppFBywpapcLFX/qfSyJoYLVBn7LTAs1+QNVcYd5so4RLYNLC 9e8sU3AQ1T34bP1FrBUsniOsSVkPKwGUeDoB2Iscr0EH1kdmt63JAfKT/MsIIsErutbr Pi4g== 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=qA6okOcNDYpNyWNf7xEo8UpwTVIgRz1UgYGZx7zu25jMD6GWJdn6bsvf3bWptjumVe 9y4g5BRdlFnFF4AFNr2zFfKlLKq3M3bJSxPTigMVlEhiJdszL8Mfg/2oeZRzq240jz63 5xCi//sdAapdb4hgDNhFHW43PUD4LSS4S3i5Qh1Fbyt5XtBxNsgdWFvLh1HNPk8Wq463 TYzCKc3kgOw+8PFWh/bna4miPgiuKrKBzgHdHAB6/ga6EuYBe67BdlcNhCyfLTbs2c4B abc34pifnW3awZRrHTA/WWdfc7FyexQvptt8rAFFhSFZ8N9tWB8pFIIMCwtX6aScpV3d JgUw== X-Gm-Message-State: AHQUAuY7/zbnD7Ew1qgmbDmade+uqtHSk7erJ8twPRf2VxF1qOjfISeb GfeB84Z07D9b5rfcv5MiFnsl7D8S6g== X-Received: by 2002:aca:2ec9:: with SMTP id u192mr6110012oiu.147.1550671221172; Wed, 20 Feb 2019 06:00:21 -0800 (PST) Received: from serve.minyard.net (serve.minyard.net. [2001:470:b8f6:1b::1]) by smtp.gmail.com with ESMTPSA id b63sm9483324oih.24.2019.02.20.06.00.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Feb 2019 06:00:20 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 6DABE1808FF; Wed, 20 Feb 2019 14:00:11 +0000 (UTC) Received: by t430.minyard.net (Postfix, from userid 1000) id 46560302A62; Wed, 20 Feb 2019 08:00:10 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Wed, 20 Feb 2019 07:59:56 -0600 Message-Id: <20190220135956.22589-20-minyard@acm.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190220135956.22589-1-minyard@acm.org> References: <20190220135956.22589-1-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::343 Subject: [Qemu-devel] [PATCH 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 , Corey Minyard , Corey Minyard , "Michael S . Tsirkin" , "Dr . David Alan Gilbert" , Paolo Bonzini 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);