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: 10822439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 80F15922 for ; Wed, 20 Feb 2019 15:59:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6703E2EC21 for ; Wed, 20 Feb 2019 15:59:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6508E2ED79; Wed, 20 Feb 2019 15:59:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BAA4F2EDAD for ; Wed, 20 Feb 2019 15:59:29 +0000 (UTC) Received: from localhost ([127.0.0.1]:41507 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUHQ-0004ON-Sl for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:59:28 -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-Google-Smtp-Source: AHgI3IZ7R/rflteVjkNQE9/3x/MbeTa3Rzgy9CZURg40qxPpkIfZicmj0LpaXrhrgMpk8to/0f++mw== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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%) 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: 10822415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA3EC139A for ; Wed, 20 Feb 2019 15:51:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D21C72ED8E for ; Wed, 20 Feb 2019 15:51:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFE0F2EDAF; Wed, 20 Feb 2019 15:51:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D9FD12EDAB for ; Wed, 20 Feb 2019 15:51:28 +0000 (UTC) Received: from localhost ([127.0.0.1]:41318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU9g-0005nx-3L for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:51:28 -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-Google-Smtp-Source: AHgI3Ib+CqYDJQutlb5EAABtVGulwdaKckmRreQl6S54YvCZ4uaDhnBbfzwfmjBujTCyvC2anqsDQQ== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4828C14E1 for ; Wed, 20 Feb 2019 15:39:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30A932D78F for ; Wed, 20 Feb 2019 15:39:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 221032D7CB; Wed, 20 Feb 2019 15:39:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 11B002D78F for ; Wed, 20 Feb 2019 15:39:15 +0000 (UTC) Received: from localhost ([127.0.0.1]:41046 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTxq-0003lk-AH for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:39:14 -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-Google-Smtp-Source: AHgI3IaL9Vdag1T8fYMTL3FkyaWZtvrdQgGo5ZqqjZH+bK5B4YPvcXtyJY73Z+EVek+S47Tue+10UA== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E7411399 for ; Wed, 20 Feb 2019 15:38:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66D2B2E6CD for ; Wed, 20 Feb 2019 15:38:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B2442E791; Wed, 20 Feb 2019 15:38:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7ED2E2E8CA for ; Wed, 20 Feb 2019 15:38:17 +0000 (UTC) Received: from localhost ([127.0.0.1]:41030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTwu-0002mV-QM for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:38:16 -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-Google-Smtp-Source: AHgI3IbTp6h9ZKlRfWjWFk7+6bI5Z5XMTS876XLOtm2TqCskNjo2mrOokNN2XAtjoZznOeZmpe3goA== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1C875922 for ; Wed, 20 Feb 2019 15:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01CDE2ED90 for ; Wed, 20 Feb 2019 15:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3E982ED97; Wed, 20 Feb 2019 15:51:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 78D8B2ED90 for ; Wed, 20 Feb 2019 15:51:09 +0000 (UTC) Received: from localhost ([127.0.0.1]:41316 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU9M-0005Wf-4W for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:51:08 -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-Google-Smtp-Source: AHgI3IasT5iEnwv+0rVZhinQc9/RGld6SrVa2uPrWCs9n7SAIvjo2fV8VKQEU2NN+DutFIQ0i3QO1A== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03F2117E9 for ; Wed, 20 Feb 2019 16:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC0F92F25C for ; Wed, 20 Feb 2019 16:40:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC0202F261; Wed, 20 Feb 2019 16:40:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BCECA2F25C for ; Wed, 20 Feb 2019 16:40:01 +0000 (UTC) Received: from localhost ([127.0.0.1]:42480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUuf-0006Td-1Z for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 11:40:01 -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-Google-Smtp-Source: AHgI3IY7RunNSZ9rOWcCE+lAgLwHofmaaCoGFNrkD3aQiq0znoi/k347ZpRSTXa/2S5hJyoFlOXN8A== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822333 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1491813B5 for ; Wed, 20 Feb 2019 15:25:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFE36266F3 for ; Wed, 20 Feb 2019 15:25:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3E772E531; Wed, 20 Feb 2019 15:25:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CED4B2E511 for ; Wed, 20 Feb 2019 15:25:42 +0000 (UTC) Received: from localhost ([127.0.0.1]:40827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTkh-0000iT-JN for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:25:39 -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-Google-Smtp-Source: AHgI3IbzPDpqcJQBij7Ub39iV2nh3QoKtjsUnrJ/+w9QTA8C8pP2DVaPlCspeJ5GmYy2QlSFb5NJkA== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E58461399 for ; Wed, 20 Feb 2019 15:46:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF8EA2EA2F for ; Wed, 20 Feb 2019 15:46:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1B232EA6A; Wed, 20 Feb 2019 15:46:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1D4C62EA2F for ; Wed, 20 Feb 2019 15:45:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:41219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU4I-0000qL-4Q for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:45:54 -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-Google-Smtp-Source: AHgI3IYyLmri2LiPyG0Kd569e77eWPopoOth5rrjmqojNv6EV9dfaH05pF26omrW9Xu+7BArXZXzkQ== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 030FC139A for ; Wed, 20 Feb 2019 15:49:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E06472CB42 for ; Wed, 20 Feb 2019 15:49:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3B752D1C5; Wed, 20 Feb 2019 15:49:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 753CA2CB42 for ; Wed, 20 Feb 2019 15:49:11 +0000 (UTC) Received: from localhost ([127.0.0.1]:41250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU7S-0003gd-L8 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:49:10 -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-Google-Smtp-Source: AHgI3IZT9cSSjpYrv6x/ZPC6/pbqKYY368KhIz4yyo2hbEL6GL+ynO92lYvqdPjJmH81IC7wiIPh6Q== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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: 10822373 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 599CE13B5 for ; Wed, 20 Feb 2019 15:31:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4284E2ECAE for ; Wed, 20 Feb 2019 15:31:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40D082ECAF; Wed, 20 Feb 2019 15:31:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C7D2B2ECA4 for ; Wed, 20 Feb 2019 15:31:25 +0000 (UTC) Received: from localhost ([127.0.0.1]:40934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTqG-0005nk-VV for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:31:25 -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-Google-Smtp-Source: AHgI3IaP7zt1JmNpLZqNn4vY0nV7s50stbebir+phfVJiaBzX+W6brcCD1PVDogaT6Imm5/TDRG2kg== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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: 10822401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CF4114E1 for ; Wed, 20 Feb 2019 15:42:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1490C2ED3D for ; Wed, 20 Feb 2019 15:42:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 128D42ED02; Wed, 20 Feb 2019 15:42:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D4BF62ED22 for ; Wed, 20 Feb 2019 15:42:12 +0000 (UTC) Received: from localhost ([127.0.0.1]:41120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU0i-0005xb-1M for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:42:12 -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-Google-Smtp-Source: AHgI3IbRwKwu9U5slPHcmnDnEzy8jSsPEpO+hKASjyfmZ3h9qFLF6gqE5B+Jq2XjGM0TOnIEx5bcBQ== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 663F7922 for ; Wed, 20 Feb 2019 15:52:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F5DA2EDC5 for ; Wed, 20 Feb 2019 15:52:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D5AA2EDDE; Wed, 20 Feb 2019 15:52:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E298B2EE0D for ; Wed, 20 Feb 2019 15:52:35 +0000 (UTC) Received: from localhost ([127.0.0.1]:41320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUAl-0006b4-2a for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:52:35 -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-Google-Smtp-Source: AHgI3IaCS0WUewsdQAVRrJm6xYAtbnl/LZVWBQ3wNhyet+XXw2NxCr3PTlq7V+dl1kc26K8rJzEHRg== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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: 10822437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B8894139A for ; Wed, 20 Feb 2019 15:56:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FF4D2EEF5 for ; Wed, 20 Feb 2019 15:56:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D7EA2EF01; Wed, 20 Feb 2019 15:56:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9D6D2EEF5 for ; Wed, 20 Feb 2019 15:56:16 +0000 (UTC) Received: from localhost ([127.0.0.1]:41431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUEJ-0001Ts-Jd for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:56:15 -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-Google-Smtp-Source: AHgI3IbETGD0bTBkCqPfW5ihHgthAZvLOdKn1z2eLsTC7yTIj98fwHL84uKscUNsYI3jpV8mfc7KmA== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E86317E9 for ; Wed, 20 Feb 2019 16:04:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57FF72EFB5 for ; Wed, 20 Feb 2019 16:04:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B5462EFC5; Wed, 20 Feb 2019 16:04:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C72DC2E7E7 for ; Wed, 20 Feb 2019 16:04:23 +0000 (UTC) Received: from localhost ([127.0.0.1]:41595 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwUMA-0000Be-C0 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 11:04:22 -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-Google-Smtp-Source: AHgI3IZbjQ9moDub5jIWwRw/nQxCC6+VbHYY4bSMS+xIolcB74nwjV0hIFt7PNGW1LPP05/G7VocQQ== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D4EF214E1 for ; Wed, 20 Feb 2019 15:36:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BC05C2E881 for ; Wed, 20 Feb 2019 15:36:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B013E2E932; Wed, 20 Feb 2019 15:36:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 739462E881 for ; Wed, 20 Feb 2019 15:36:39 +0000 (UTC) Received: from localhost ([127.0.0.1]:41005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTvK-0001c5-LE for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:36:38 -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-Google-Smtp-Source: AHgI3IbkhLneFTbluakxwFQsInpAsKmDvSIraotdUvJvFZUOcIDLCz1OOuXK0xMQgHY4H57rT2R0sQ== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A7B6B1399 for ; Wed, 20 Feb 2019 15:47:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90C022EA9A for ; Wed, 20 Feb 2019 15:47:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 84B5E2EAC5; Wed, 20 Feb 2019 15:47:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 29FA72EA9A for ; Wed, 20 Feb 2019 15:47:19 +0000 (UTC) Received: from localhost ([127.0.0.1]:41231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU5e-0001oH-CL for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:47:18 -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-Google-Smtp-Source: AHgI3IZXz8sB/DyZGzOViuEzZgDaGvsTP8RbF4v4tKPW01WH5JIgZe8o03vmBzNGe16NF2QsBO0Yzw== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEC141399 for ; Wed, 20 Feb 2019 15:38:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C558C2E68A for ; Wed, 20 Feb 2019 15:38:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7C092E6CD; Wed, 20 Feb 2019 15:38:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 918302E8CA for ; Wed, 20 Feb 2019 15:38:33 +0000 (UTC) Received: from localhost ([127.0.0.1]:41038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTxA-0002x4-Oj for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:38:32 -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-Google-Smtp-Source: AHgI3Ibah4kG80UZN8YFX5H9Zlbc87QOcRi4IIyeKXsGM70DNLL5aD4unLqv6WS3ZvdEMnPI6TS3DQ== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 99E6C6C2 for ; Wed, 20 Feb 2019 15:49:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8262F2D2C9 for ; Wed, 20 Feb 2019 15:49:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7685F2D3E3; Wed, 20 Feb 2019 15:49:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 205A62D2C9 for ; Wed, 20 Feb 2019 15:49:21 +0000 (UTC) Received: from localhost ([127.0.0.1]:41254 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwU7c-0003qF-D4 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:49:20 -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-Google-Smtp-Source: AHgI3IbUuOoyHWCGBD75RsVjU2R2hIP+eUDSnEscqRbPcL1chmJIi/ZZmHuQJnj3HaYg4rq1W2Qm4g== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: 10822383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E191713B5 for ; Wed, 20 Feb 2019 15:32:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C90422EBF2 for ; Wed, 20 Feb 2019 15:32:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD3772ECA7; Wed, 20 Feb 2019 15:32:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 76ADC2EBF2 for ; Wed, 20 Feb 2019 15:32:54 +0000 (UTC) Received: from localhost ([127.0.0.1]:40939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwTrh-0006nL-JM for patchwork-qemu-devel@patchwork.kernel.org; Wed, 20 Feb 2019 10:32:53 -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-Google-Smtp-Source: AHgI3IaqVun5Y0JXcMMibq75n0GoOVUq2Pa7jTRr+iYBsGsDJ9ksA+teqrozn25nXD5W0QNn9u7HYw== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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);