From patchwork Mon Aug 20 20:26:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144661 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4410101ljj; Mon, 20 Aug 2018 13:31:08 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwk+Ccos+FOu8jqr8A/D7tcq8v1ikB2RRQfSr9qpyT4KtShYmtwm1vT01UpR5F1zVjYIGZW X-Received: by 2002:a37:2b13:: with SMTP id r19-v6mr18857620qkh.286.1534797068826; Mon, 20 Aug 2018 13:31:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797068; cv=none; d=google.com; s=arc-20160816; b=xA7lD1m1sRVODCrWmycAZ6Ea5/q68CqlTvFvaeqvDCa9fItLtZSU6iFOgBg6Wo2EIn qL4rtMMbpbhVFD6OagRbj20yAx7yYeQkKTKHkhTqfSW9RrcdyMSdqHajPnDMQupvrMXx ygJ4b90WnItjZkpJ5/Qu+qgnOsg1cVBKixB6PdRxjLW8p/aeA0H3mu+IauRlD/Y0Kn16 AONLzPt8OiZsR9jEedDX7foECDwEcu1adCwWUkens600wSjy8Pb032alSEpcLkmniNAK nFLNCu+BSoZArIWeCKUlM/xlfdSV62dQP9eiqdNf/k/fuL3a4KvtnWJDijMUhmJ2cxYY 6gTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=it1qCBrNdyxUz/mt2nkaTHsGcqJGU1Y02vsMXZeZ/iU=; b=Lu3jNkjYCIqhGEU5y2bAf0kseZu4EDPG1mkPe1ZKdGtvZn6JTmtdH6fM7B4QZneBId SgcyAoy2KnwSap7Xo6SDLywV0bo5a8+k8moz8B6W3ccDuPr/H6sZzIeipHFPEX4OfEpE mBm4iM/O+reasLpFypVCMG9rSDE1J6Q5ZMj0GLtch9irxKtM1uSzBYoZR7UUjEPsm/5/ ZCwQcjutXxv6Tawj4RD2P8ndkTR0U3INTxV4sfoJ1fOVChP8cTTxr9iIhTLwa2XRz3r1 XY+/ssH2vDIrZ4JblZRQbocIEyR4SoffrJ0qcRCJprbzzGsz8Nwio6x1+ANHtQYnri26 5BCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="oEQzAVh/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d38-v6si9834357qta.209.2018.08.20.13.31.08 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:31:08 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="oEQzAVh/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqpQ-00059c-88 for patch@linaro.org; Mon, 20 Aug 2018 16:31:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51557) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlC-0002pX-Uk for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frql0-0002SA-FW for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:45 -0400 Received: from mail-oi0-x22f.google.com ([2607:f8b0:4003:c06::22f]:46700) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqkw-0002HZ-Ji for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:30 -0400 Received: by mail-oi0-x22f.google.com with SMTP id y207-v6so28125416oie.13 for ; Mon, 20 Aug 2018 13:26:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=it1qCBrNdyxUz/mt2nkaTHsGcqJGU1Y02vsMXZeZ/iU=; b=oEQzAVh/xjA4AKNo3Xs6cJeOIdtxdNOieopE3DnG3VN+WgkH0iMTn3cH1tDCbeFJq7 bMqVZ2XyCEk4ha5zTdw46NoCma0/2Xxli9IVzPRoN4ZgkBpROAcqqOEzliwDKWJdwX1p wM6AOgEaLKek5JRsVaTfLCctnhl+Px+fgNmTaawETIdMmPCwo58KNojEcEeDFR1cdkcC Q+iY1kZZzO5Ndb1/oD4L+uT3145z/gkkJ1DQmSWZ6lSGGpR/ttqnNhJWoXRkH1e0z2U3 Hpx0fOBvBOFoQAd7dSac+y26ClV0YvfuViW/P3CRBQpgwoTES0BGBnCH7jEpVG/G3BHQ dPLg== 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=it1qCBrNdyxUz/mt2nkaTHsGcqJGU1Y02vsMXZeZ/iU=; b=VL271HeXWCeg/8Pr8mPzkY+ktvLqzk2xJ0GKltmuyZfV1xXxTBDYZ80PGTtUapI4lB v1TYJqhSy4QRPhvv09+oOcQVmSewhQRVNkGqolIHRs8CI64wJy0CZ4o5cqh7XrfehAmL 7PF8MQaBeCGXgWLAmk6JUkiO8rpWScdp2ikmk62+6kPKW666BhXrKEvBtpdEP0XL37ly ojWoqZR4zzajlGnAl6hEq/Dl36gS9Di5GSAtXMrATUpPYmVilITRZ2kEWBr1WdtNfF0X ydhQWzqPQJOxuRYZxO5CDq87FhYWv4CEVqoEFx+cmvnZ5at5L6SJuSJEpyAbt72B2Veo dJZg== X-Gm-Message-State: AOUpUlG9hlIcDsrcn9V8TNh8O1f2xFawr4swB8qNPw5okHXH/EeOZMj3 lvwix61bB42U/N0ZsBAjxw== X-Received: by 2002:aca:3a57:: with SMTP id h84-v6mr15446977oia.336.1534796788246; Mon, 20 Aug 2018 13:26:28 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id s142-v6sm8961497oie.48.2018.08.20.13.26.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:25 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id E95DEE1D; Mon, 20 Aug 2018 15:26:23 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 24A913000F4; Mon, 20 Aug 2018 15:26:20 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:01 -0500 Message-Id: <1534796770-10295-2-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::22f Subject: [Qemu-devel] [PATCH v2 01/10] i2c:pm_smbus: Clean up some style issues X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Fix some spacing issues, remove extraneous comments, add some defines instead of hard-coding numbers. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini --- hw/i2c/pm_smbus.c | 58 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) -- 2.7.4 Reviewed-by: Philippe Mathieu-Daudé diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 0d26e0f..83c2377 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -22,8 +22,6 @@ #include "hw/i2c/pm_smbus.h" #include "hw/i2c/smbus.h" -/* no save/load? */ - #define SMBHSTSTS 0x00 #define SMBHSTCNT 0x02 #define SMBHSTCMD 0x03 @@ -32,19 +30,34 @@ #define SMBHSTDAT1 0x06 #define SMBBLKDAT 0x07 -#define STS_HOST_BUSY (1) -#define STS_INTR (1<<1) -#define STS_DEV_ERR (1<<2) -#define STS_BUS_ERR (1<<3) -#define STS_FAILED (1<<4) -#define STS_SMBALERT (1<<5) -#define STS_INUSE_STS (1<<6) -#define STS_BYTE_DONE (1<<7) +#define STS_HOST_BUSY (1 << 0) +#define STS_INTR (1 << 1) +#define STS_DEV_ERR (1 << 2) +#define STS_BUS_ERR (1 << 3) +#define STS_FAILED (1 << 4) +#define STS_SMBALERT (1 << 5) +#define STS_INUSE_STS (1 << 6) +#define STS_BYTE_DONE (1 << 7) /* Signs of successfully transaction end : * ByteDoneStatus = 1 (STS_BYTE_DONE) and INTR = 1 (STS_INTR ) */ -//#define DEBUG +#define CTL_INTREN (1 << 0) +#define CTL_KILL (1 << 1) +#define CTL_LAST_BYTE (1 << 5) +#define CTL_START (1 << 6) +#define CTL_PEC_EN (1 << 7) +#define CTL_RETURN_MASK 0x1f + +#define PROT_QUICK 0 +#define PROT_BYTE 1 +#define PROT_BYTE_DATA 2 +#define PROT_WORD_DATA 3 +#define PROT_PROC_CALL 4 +#define PROT_BLOCK_DATA 5 +#define PROT_I2C_BLOCK_DATA 6 + +/*#define DEBUG*/ #ifdef DEBUG # define SMBUS_DPRINTF(format, ...) printf(format, ## __VA_ARGS__) @@ -70,11 +83,12 @@ static void smb_transaction(PMSMBus *s) if ((s->smb_stat & STS_DEV_ERR) != 0) { goto error; } + switch(prot) { - case 0x0: + case PROT_QUICK: ret = smbus_quick_command(bus, addr, read); goto done; - case 0x1: + case PROT_BYTE: if (read) { ret = smbus_receive_byte(bus, addr); goto data8; @@ -82,7 +96,7 @@ static void smb_transaction(PMSMBus *s) ret = smbus_send_byte(bus, addr, cmd); goto done; } - case 0x2: + case PROT_BYTE_DATA: if (read) { ret = smbus_read_byte(bus, addr, cmd); goto data8; @@ -91,16 +105,17 @@ static void smb_transaction(PMSMBus *s) goto done; } break; - case 0x3: + case PROT_WORD_DATA: if (read) { ret = smbus_read_word(bus, addr, cmd); goto data16; } else { - ret = smbus_write_word(bus, addr, cmd, (s->smb_data1 << 8) | s->smb_data0); + ret = smbus_write_word(bus, addr, cmd, + (s->smb_data1 << 8) | s->smb_data0); goto done; } break; - case 0x5: + case PROT_I2C_BLOCK_DATA: if (read) { ret = smbus_read_block(bus, addr, cmd, s->smb_data); goto data8; @@ -158,8 +173,9 @@ static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, break; case SMBHSTCNT: s->smb_ctl = val; - if (val & 0x40) + if (s->smb_ctl & CTL_START) { smb_transaction_start(s); + } break; case SMBHSTCMD: s->smb_cmd = val; @@ -198,7 +214,7 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) break; case SMBHSTCNT: s->smb_index = 0; - val = s->smb_ctl & 0x1f; + val = s->smb_ctl & CTL_RETURN_MASK; break; case SMBHSTCMD: val = s->smb_cmd; @@ -221,7 +237,9 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) val = 0; break; } - SMBUS_DPRINTF("SMB readb port=0x%04" HWADDR_PRIx " val=0x%02x\n", addr, val); + SMBUS_DPRINTF("SMB readb port=0x%04" HWADDR_PRIx " val=0x%02x\n", + addr, val); + return val; } From patchwork Mon Aug 20 20:26:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144664 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4416793ljj; Mon, 20 Aug 2018 13:39:02 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbL9Ija2LkOu6d8/xRprqaO5qOjWxRq+/TwNlse1cFxknt298c8U+yIVJU0tyuMcf9LsZcT X-Received: by 2002:aed:3d71:: with SMTP id h46-v6mr14462974qtf.416.1534797542512; Mon, 20 Aug 2018 13:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797542; cv=none; d=google.com; s=arc-20160816; b=B45Xjfc/FR+pW6fkrebOY9/HFZBLs8IWx+W0zKx6P2iE889knjUTLN7ATJELbnNOSG 31BeYc5buSx2x+KSJFIaklxY2e3hnoOKZ0esx18rKlbzwKwmATMNnCNZFreCI29D7eXp j0hcS9iOtjVky/xIKdfGypfpFJx5HiGLYrcUJqbmdJblB9qJNC5UNb9NJRV51IuzsY8B 9Tut+ZzHSgEpXIB0+rmHQe2yQo7cLIPzPS8K5SYlUREIW2OJWzLsfmF4BKzY1qJ7Lvjt 7f+stiJcRIemyJdP635giZUFli39m65Vzhj6x3H5hNrXsagWIZQGIH3dH8MzPgUbVlaE i8Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=LRO8EElwYxFb7czCHQ6NC/4MgeOza6zCgrSvHqTY8Jo=; b=P+biiisLD0w9yiia7Yih61saZWPkQduWsAgwF1SME6NHKC2WQa5fa9byXtFU5I6Ygj CiLx18aH65u4CUkap43K9nbWBL7FVflx5Q2x5eGK5/ZpZq5ksqV6a8d4dbjq56Y3qC+1 KY/hwTaSG0dRhbfoPpLl0qEYIH3FvirO4NLGMC/xgL2GCsGOZufilzRFBym52sc36wVZ EYzQRMqEBwrZX4So0Ed7KVgc+uAgEovBnUHZQWpNinRzmvc8J/Eiic+JK0Z16oA8dSST +7AYGTB7x1lkrcDfp02IjaGg1S5J8Y7FpsE5LM8WXEBrqMwsES4F+PxVMFYqXLqq0FL5 6aBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YLgxRlDh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id h98-v6si2373219qkh.363.2018.08.20.13.39.02 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:39:02 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YLgxRlDh; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqx3-0002hv-Qg for patch@linaro.org; Mon, 20 Aug 2018 16:39:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51553) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlC-0002pR-Rw for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frql0-0002SL-Ff for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:45 -0400 Received: from mail-oi0-x235.google.com ([2607:f8b0:4003:c06::235]:39195) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqkw-0002F7-8s for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:30 -0400 Received: by mail-oi0-x235.google.com with SMTP id d189-v6so28171248oib.6 for ; Mon, 20 Aug 2018 13:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=LRO8EElwYxFb7czCHQ6NC/4MgeOza6zCgrSvHqTY8Jo=; b=YLgxRlDhueOmvN2xXJ5LogI38KRCH4iFCQWxByEbGPCQcQsT3QYlInpFKpcH6Vh1GX Z6+dQWVhbnRiTYe1whJmk/xRKPiwHwc7WGBLPjMqjzN/m7d5se3M2dOKp5x6Qyu37hI4 Gzz+j4kg0rv1JhifkUa9Aic2g8Ymd47tPYkMJY4uYNfFDJeZpafmGCAVoNFUjmzLwYhq wMklN9hK9vsl+6JWjwGmFmiaN4PQnlMmydwOOpMu942uVz7WSYzmIPQnWs9++Yi4SH+Z Tpfon2YZiOlsHHZweQkpWQA35wZz5c66oI6YdqR96cujXQ4n1eNj0FQRhKz3USOdChNl qJmw== 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=LRO8EElwYxFb7czCHQ6NC/4MgeOza6zCgrSvHqTY8Jo=; b=XRBNl3KwwIjla0zyf/JhoV1TNz6g/tBkg2vYZMk5RQ+ezXKbmE6hpDhErb5uDpC+fZ xU3ro35qqB8b1TYo/HW7mWx4H6ms3bLGjkI3PIdT/Zx6z1k6U1CdHmzsE75ienpXps8Q YV+zh39cLujgWXY6LtYIOZ5gSuEWZb5F4t6+uI5eP7NgCBY3d9rBqXvbq2tMzA1OVGd+ Y92SNg46r+1UTm9TTXFMcDecAVOSptzssJ5MB0zI/mPSW5Kk4zc0m8slgkKrgKbC31Ch +dFEWOLRf/miRwgYfuX32yogRXQTEq9fe37xZP/iTOvgIew+bUew9+0YPu/Tb2kIWmld OcyQ== X-Gm-Message-State: AOUpUlFN1U9HI2D6twHg8wGHXZOXpqmh7ozwqjYd84Nh2g/YOw93NMHg J41Em9H9wq/8Vg5OCiAt2A== X-Received: by 2002:a54:4f88:: with SMTP id g8-v6mr16003957oiy.191.1534796786319; Mon, 20 Aug 2018 13:26:26 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id x5-v6sm10839832oix.3.2018.08.20.13.26.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:25 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id C016CC16; Mon, 20 Aug 2018 15:26:23 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 476273000FF; Mon, 20 Aug 2018 15:26:20 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:02 -0500 Message-Id: <1534796770-10295-3-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::235 Subject: [Qemu-devel] [PATCH v2 02/10] i2c:pm_smbus: Fix the semantics of block I2C transfers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The I2C block transfer commands was not implemented correctly, it read a length byte and such like it was an smbus transfer. So fix the smbus_read_block() and smbus_write_block() functions so they can properly handle I2C transfers, and normal SMBus transfers (for upcoming changes). Pass in a transfer size and a bool to know whether to use the size byte (like SMBus) or use the length given (like I2C). Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini --- hw/i2c/pm_smbus.c | 10 ++++++++-- hw/i2c/smbus.c | 37 ++++++++++++++++++++++++------------- include/hw/i2c/smbus.h | 17 +++++++++++++++-- 3 files changed, 47 insertions(+), 17 deletions(-) -- 2.7.4 diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 83c2377..f1fe889 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -117,10 +117,16 @@ static void smb_transaction(PMSMBus *s) break; case PROT_I2C_BLOCK_DATA: if (read) { - ret = smbus_read_block(bus, addr, cmd, s->smb_data); + 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 { - ret = smbus_write_block(bus, addr, cmd, s->smb_data, s->smb_data0); + ret = smbus_write_block(bus, addr, cmd, s->smb_data, s->smb_data0, + false); goto done; } break; diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c index 587ce1a..6ff77c5 100644 --- a/hw/i2c/smbus.c +++ b/hw/i2c/smbus.c @@ -293,33 +293,42 @@ int smbus_write_word(I2CBus *bus, uint8_t addr, uint8_t command, uint16_t data) return 0; } -int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data) +int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, + int len, bool recv_len, bool send_cmd) { - int len; + int rlen; int i; - if (i2c_start_transfer(bus, addr, 0)) { - return -1; + if (send_cmd) { + if (i2c_start_transfer(bus, addr, 0)) { + return -1; + } + i2c_send(bus, command); } - i2c_send(bus, command); if (i2c_start_transfer(bus, addr, 1)) { - i2c_end_transfer(bus); + if (send_cmd) { + i2c_end_transfer(bus); + } return -1; } - len = i2c_recv(bus); - if (len > 32) { - len = 0; + if (recv_len) { + rlen = i2c_recv(bus); + } else { + rlen = len; } - for (i = 0; i < len; i++) { + if (rlen > len) { + rlen = 0; + } + for (i = 0; i < rlen; i++) { data[i] = i2c_recv(bus); } i2c_nack(bus); i2c_end_transfer(bus); - return len; + return rlen; } int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, - int len) + int len, bool send_len) { int i; @@ -330,7 +339,9 @@ int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, return -1; } i2c_send(bus, command); - i2c_send(bus, len); + if (send_len) { + i2c_send(bus, len); + } for (i = 0; i < len; i++) { i2c_send(bus, data[i]); } diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus.h index 4fdba02..d8b1b9e 100644 --- a/include/hw/i2c/smbus.h +++ b/include/hw/i2c/smbus.h @@ -72,9 +72,22 @@ 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); -int smbus_read_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_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); + 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, From patchwork Mon Aug 20 20:26:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144666 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4419572ljj; Mon, 20 Aug 2018 13:42:27 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwWosjChCVLRZ6GYlvpu2SnbqePdL3QILJhh6HCHQ/30Nv74qA2/tuSmFVT1sxYAHGb4NAQ X-Received: by 2002:aed:3fd5:: with SMTP id w21-v6mr44837506qth.226.1534797747452; Mon, 20 Aug 2018 13:42:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797747; cv=none; d=google.com; s=arc-20160816; b=PX0yahLdFSAmrbxdvRdAVBG1WUcvs/qyV17N5habBr4lCjsLWvvQi/ceshD+/oIQBx T7wbgMWj5ehryZV3sV4uvbl06vBOulQH28oqHnaaXBRuIN+Otm8RUWtRtOn6Wt2ZqJHr Y2yKpxFtUXrdJQIvfs8fLd4suOG6vMaMPHFpfs1tvlRaWuIU89tEByVjmOKGk4cQ/97X RlX3Yr/4pTG40rtvvvEZfGSG8g9d6Cw4xxQbPFjQxQFssou/dMeEEMUfaQ3nFuMFuWng E2bzPn4xf7IZQYYVQ06Fhj6fkZ1Nx5cIkfDsLVNWAe2PRdrIXg6rcbWO8Eskb9NxQMJt RvOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=EEx/mTtPmqp5TcInvMTNAaRwhvCXPWgetsyrcj9Cyjk=; b=gVkpiGZiz/Gb2CH31I+GF47xkVzhq7c7EABi0XSEL2PAm4VZsSRE4pGiUCnb6TgLAn i71hMzRYWhpJ35UsY6aMxRCyPK3hR3dEDmTZanB9fF46qa4SG/R8xqp8XE8Kk0vtW4Hh w55oht8yUiOwdVchG7DPrNPDFvXQu5AGFJ3MfJhDNeUnGQIbUNRSBShSjtiwJLsWnVSj 4gCrC5qCXy/fWuI7iVwXrCMbA50Wuw4PQ7cCVWHbDdQGpdAcwXuCfMyBBNiy2vE5iSWB tSMD3zQdMK78MhOTiJw88oIH6mgPh+tiNaV71/TPEo6Vb8txiiT49dMtXfg1VC1YHvyo lGEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="J/t1JVsc"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u24-v6si291307qkk.109.2018.08.20.13.42.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:42:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="J/t1JVsc"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frr0M-00075V-VQ for patch@linaro.org; Mon, 20 Aug 2018 16:42:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqll-0003Hs-Et for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:27:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frqlY-0003ip-9w for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:27:14 -0400 Received: from mail-oi0-x232.google.com ([2607:f8b0:4003:c06::232]:34088) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqlM-0003Jq-Du for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:59 -0400 Received: by mail-oi0-x232.google.com with SMTP id 13-v6so28172335ois.1 for ; Mon, 20 Aug 2018 13:26:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EEx/mTtPmqp5TcInvMTNAaRwhvCXPWgetsyrcj9Cyjk=; b=J/t1JVscWFrltUqfD/kGBuqfKQJIgmg+rFqBcN0vMuw+upePKw+JItyWkUMpvkMkhv SabSc2SKdUR28SWUylfJO7ryGYnvgeqV+lrxT2w9S/ezOvnfZWqq8XOmCcoEVEcVCWrP 1vnkr8IkdHC/RO9OMBIZ7dLF39K1dKMoL7TIEGxoZFdh/gzrhe3b4DLS1tEylhZRwEKC 4TCI++1nkqJcIPXkKN87P4d/flGeg0xnOvnh8MnVOvMINTUFTOkJLQlcFzNAnCsE8T75 +m7eZ4f0rLzkzy41LSSY7qllhceahTM6Gqto0H+V3y01pZg7t8hqRtu6LTgpI3wQfGa4 8N8w== 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=EEx/mTtPmqp5TcInvMTNAaRwhvCXPWgetsyrcj9Cyjk=; b=ic1XrooeFsDXHH1VSHov5V2TAuIL1vt7Z3XhCb0LWnr5iV0oM3i33k3+J9i+7+E24W wKIrC2PKXg8Oj7PqPcWS6UmvhKhbUZ2zF64SHnUWFHgDwRaAaGpEiqQKZ92I90bSioVm b9HALOgy+qpgZGm7LZBvc/ZVqiApwnchb8BzgePLBo5GV10AiMZ950QI8omv8a0z3LKD mLcs1MZTJ543KVNe6I1ejMWv4siPuX1xaBqSyvnpZEIBVyPxnrZ+uDkvAgK38ol4UQKG 30wbiX79qVPQm9nhi7HIdJz7X41N5cUfg2ctLu1DvJc9+Krw3Ekg+v4GSv+mBLz0H8U9 eXuQ== X-Gm-Message-State: AOUpUlEFzur6hYo/s46UgiaVtTWxyIx6Q4JayzKIUeSyfpaCkUhXjyKR x/bJWQ2t3+RkFx7/nSWqIQ== X-Received: by 2002:aca:100f:: with SMTP id 15-v6mr14144564oiq.110.1534796815463; Mon, 20 Aug 2018 13:26:55 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id p132-v6sm14512255oia.31.2018.08.20.13.26.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:54 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id 49B478AE; Mon, 20 Aug 2018 15:26:23 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 60097300105; Mon, 20 Aug 2018 15:26:21 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:03 -0500 Message-Id: <1534796770-10295-4-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::232 Subject: [Qemu-devel] [PATCH v2 03/10] i2c:pm_smbus: Make the I2C block read command read-only X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard It did have write capability, but the manual says the behavior with write enabled is undefined. So just set an error in this case. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini --- hw/i2c/pm_smbus.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index f1fe889..dc61f2c 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -55,7 +55,7 @@ #define PROT_WORD_DATA 3 #define PROT_PROC_CALL 4 #define PROT_BLOCK_DATA 5 -#define PROT_I2C_BLOCK_DATA 6 +#define PROT_I2C_BLOCK_READ 6 /*#define DEBUG*/ @@ -115,7 +115,7 @@ static void smb_transaction(PMSMBus *s) goto done; } break; - case PROT_I2C_BLOCK_DATA: + case PROT_I2C_BLOCK_READ: if (read) { int xfersize = s->smb_data0; if (xfersize > sizeof(s->smb_data)) { @@ -125,9 +125,8 @@ static void smb_transaction(PMSMBus *s) xfersize, false, true); goto data8; } else { - ret = smbus_write_block(bus, addr, cmd, s->smb_data, s->smb_data0, - false); - goto done; + /* The manual says the behavior is undefined, just set DEV_ERR. */ + goto error; } break; default: From patchwork Mon Aug 20 20:26:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144659 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4406820ljj; Mon, 20 Aug 2018 13:27:26 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxKoDFWG2z5GdPoeoDIkaAlBAGCzbbIp4ObdZtwRGWq2w//vbyQPsUwERRZU991kyfnndwL X-Received: by 2002:a0c:9aef:: with SMTP id k47-v6mr43158146qvf.134.1534796846727; Mon, 20 Aug 2018 13:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534796846; cv=none; d=google.com; s=arc-20160816; b=K3fdBOzOeSDtBBYuKYY/FrFagcBHGmt34EWH3mnFrZNTO2V29moE5cNxH0DV0MZUnL w2Qh6ZF0M9cWm4V7E8VneIP6BQ+I2yjLDg0/t1woBNHALxcP9TiyJpLqFEdPIitRPLPz EY5c9PFf+IqTIkUvD6+BPfcVq73TFIT7vhO8chk3g+3tg30rUG/ywZVojBIm2AxHum7T YSuGzwS/oUrt8RGmcqDZTZ1K3SiU+AVJt0BEHjJrcjcsDR1bsijuqx1NB2fFjwk3zDu3 P9KE/7rtQHzSpezKzpVBa6iwzmm7jVcaTDq3a8q2WId7lrRIADmpvVAfZhFPt64xn2AB 0liw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=4N6tj6d0ZGXQ6F6OK9ZcFzf600InDZZfhdLAGuyoSbk=; b=m5KJDGaWCuOZ88vETFah1BkxbkWWdw6pH8jRKMcdGUcjHJMsmPzOlS7pwbfDC0cWND DWxjVlmjRiYXZ80kwMql/ROztFuGnAtsKUhXmJDyCsXkXmPSOk3wCIrXy8YqlBJmIJor ptbFZbWvZ/UpJ75BLzGecmWj+dwH1vRLTdeFQJfyGW0JJ72vgKYKkJ0MJ6aFGA9kRhMK I9EMrVUSdJVgoqYocKzcMWg0C79XPaqpYSqnWjqCnhJqIQRpmZmDLcKyfxC0nKWqxeSn ZuYxS19ouNL2ynq87Uw7qnQFysK7BoK4dcjUlde3itdUf61aScAWX1VVazJogMA7Tf1Q wmvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=MRO9BaaI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u190-v6si8315819qkf.356.2018.08.20.13.27.26 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:27:26 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=MRO9BaaI; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlq-0002yA-3s for patch@linaro.org; Mon, 20 Aug 2018 16:27:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51554) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlC-0002pS-Sg for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frql0-0002SN-G4 for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:45 -0400 Received: from mail-oi0-x230.google.com ([2607:f8b0:4003:c06::230]:36266) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqkw-0002GL-8v for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:30 -0400 Received: by mail-oi0-x230.google.com with SMTP id n21-v6so28177081oig.3 for ; Mon, 20 Aug 2018 13:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=4N6tj6d0ZGXQ6F6OK9ZcFzf600InDZZfhdLAGuyoSbk=; b=MRO9BaaITFxzx1d0xvjp55eWGsgEN/aCkou3ClFLtmplom4IMANUN1kFimiR7sXJO9 wf+xZoTXqcJZn/rHh2kn7+MO73FzwBdWm/eNtEPUAP3YmrHv+TKEwsHOi1lgrSzth7a+ CPE+EIuysUoFnKsMhOItt6s68nzrT7TIuyHd5/R4FI7pGjcSUPyYK8WtAzNTdwI8OxuU KjbiJ6q5oi7vAOQ3tr9fvteZ6hNRoIWrovnqwvHw+m06FWO5b66tQGZ9qPaLeJXxxb5o zOMOyhXzVaJwU+ZMlkKx8dgXDHGBKCPSvGlIHySwKpCfIlGBv0On1/9cQY0KWSthZ/0E GFqA== 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=4N6tj6d0ZGXQ6F6OK9ZcFzf600InDZZfhdLAGuyoSbk=; b=i/N08Kkjv9AzYr6FQJLZ8qNE4kLXnUwgdgUa9T+0A39h8xKiM7IiB8X6aYNR66dtLh IPSvjvGA/PR5HdAUPT3xiWfuQjSm6dBZu6q6l26Y7qAU8HHCCtMALkOOaa5uv2Vxdgpf rT2G2MxkIiQBGrqA6Xxb7vhoIUC5+9auQIPaun9M4nuR2baso/Tc/HhOCiHDtR73NB9O REt6wiIZClVpyDLoAmJHsP5Ez1iNyAdaHXlDMwQLF8loMu5BUWfDf9ocvhfK7LMrHPeM FAy9ui5Uoy4jpTjNFjzFUdI2vGDI9ZmmXeNpCeEOmFM0vyjVu6ld17ayfwvOTTijUr53 7YIg== X-Gm-Message-State: AOUpUlEB3KMBePslPqqQ1vQmYn5YqdEmPpR0mSkeOOHBgxJXkRDhooE8 461U6yWm28Nmn+DmI+32NA== X-Received: by 2002:aca:7596:: with SMTP id q144-v6mr14496155oic.105.1534796787045; Mon, 20 Aug 2018 13:26:27 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id r187-v6sm13782752oie.43.2018.08.20.13.26.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:25 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id 5D8EABAC; Mon, 20 Aug 2018 15:26:23 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 7A885300106; Mon, 20 Aug 2018 15:26:21 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:04 -0500 Message-Id: <1534796770-10295-5-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::230 Subject: [Qemu-devel] [PATCH v2 04/10] i2c:pm_smbus: Add block transfer capability X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard There was no block transfer code in pm_smbus.c, and it is needed for some devices. So add it. This adds both byte-by-byte block transfers and buffered block transfers. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini --- hw/i2c/pm_smbus.c | 151 ++++++++++++++++++++++++++++++++++++++++++---- hw/i2c/smbus_ich9.c | 8 ++- include/hw/i2c/pm_smbus.h | 20 +++++- 3 files changed, 164 insertions(+), 15 deletions(-) -- 2.7.4 diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index dc61f2c..32132be 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -29,6 +29,7 @@ #define SMBHSTDAT0 0x05 #define SMBHSTDAT1 0x06 #define SMBBLKDAT 0x07 +#define SMBAUXCTL 0x0d #define STS_HOST_BUSY (1 << 0) #define STS_INTR (1 << 1) @@ -57,6 +58,10 @@ #define PROT_BLOCK_DATA 5 #define PROT_I2C_BLOCK_READ 6 +#define AUX_PEC (1 << 0) +#define AUX_BLK (1 << 1) +#define AUX_MASK 0x3 + /*#define DEBUG*/ #ifdef DEBUG @@ -129,6 +134,51 @@ static void smb_transaction(PMSMBus *s) goto error; } break; + case PROT_BLOCK_DATA: + if (read) { + ret = smbus_read_block(bus, addr, cmd, s->smb_data, + sizeof(s->smb_data), !s->i2c_enable, + !s->i2c_enable); + if (ret < 0) { + goto error; + } + s->smb_index = 0; + s->op_done = false; + if (s->smb_auxctl & AUX_BLK) { + s->smb_stat |= STS_INTR; + } else { + s->smb_blkdata = s->smb_data[0]; + s->smb_stat |= STS_HOST_BUSY | STS_BYTE_DONE; + } + s->smb_data0 = ret; + goto out; + } else { + if (s->smb_auxctl & AUX_BLK) { + if (s->smb_index != s->smb_data0) { + s->smb_index = 0; + goto error; + } + /* Data is already all written to the queue, just do + the operation. */ + s->smb_index = 0; + ret = smbus_write_block(bus, addr, cmd, s->smb_data, + s->smb_data0, !s->i2c_enable); + if (ret < 0) { + goto error; + } + s->op_done = true; + s->smb_stat |= STS_INTR; + s->smb_stat &= ~STS_HOST_BUSY; + } else { + s->op_done = false; + s->smb_stat |= STS_HOST_BUSY | STS_BYTE_DONE; + s->smb_data[0] = s->smb_blkdata; + s->smb_index = 0; + ret = 0; + } + goto out; + } + break; default: goto error; } @@ -148,13 +198,13 @@ done: if (ret < 0) { goto error; } - s->smb_stat |= STS_BYTE_DONE | STS_INTR; + s->smb_stat |= STS_INTR; +out: return; error: s->smb_stat |= STS_DEV_ERR; return; - } static void smb_transaction_start(PMSMBus *s) @@ -173,14 +223,61 @@ static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, " val=0x%02" PRIx64 "\n", addr, val); switch(addr) { case SMBHSTSTS: - s->smb_stat = (~(val & 0xff)) & s->smb_stat; - s->smb_index = 0; + s->smb_stat &= ~(val & ~STS_HOST_BUSY); + if (!s->op_done && !(s->smb_auxctl & AUX_BLK)) { + uint8_t read = s->smb_addr & 0x01; + + s->smb_index++; + if (!read && s->smb_index == s->smb_data0) { + uint8_t prot = (s->smb_ctl >> 2) & 0x07; + uint8_t cmd = s->smb_cmd; + uint8_t addr = s->smb_addr >> 1; + int ret; + + if (prot == PROT_I2C_BLOCK_READ) { + s->smb_stat |= STS_DEV_ERR; + goto out; + } + + ret = smbus_write_block(s->smbus, addr, cmd, s->smb_data, + s->smb_data0, !s->i2c_enable); + if (ret < 0) { + s->smb_stat |= STS_DEV_ERR; + goto out; + } + s->op_done = true; + s->smb_stat |= STS_INTR; + s->smb_stat &= ~STS_HOST_BUSY; + } else if (!read) { + s->smb_data[s->smb_index] = s->smb_blkdata; + 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]; + 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]; + s->smb_stat |= STS_BYTE_DONE; + } + } break; case SMBHSTCNT: - s->smb_ctl = val; - if (s->smb_ctl & CTL_START) { + s->smb_ctl = val & ~CTL_START; /* CTL_START always reads 0 */ + if (val & CTL_START) { + if (!s->op_done) { + s->smb_index = 0; + s->op_done = true; + } smb_transaction_start(s); } + if (s->smb_ctl & CTL_KILL) { + s->op_done = true; + s->smb_index = 0; + s->smb_stat |= STS_FAILED; + s->smb_stat &= ~STS_HOST_BUSY; + } break; case SMBHSTCMD: s->smb_cmd = val; @@ -195,13 +292,24 @@ static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, s->smb_data1 = val; break; case SMBBLKDAT: - s->smb_data[s->smb_index++] = val; - if (s->smb_index > 31) + if (s->smb_index >= PM_SMBUS_MAX_MSG_SIZE) { s->smb_index = 0; + } + if (s->smb_auxctl & AUX_BLK) { + s->smb_data[s->smb_index++] = val; + } else { + s->smb_blkdata = val; + } + break; + case SMBAUXCTL: + s->smb_auxctl = val & AUX_MASK; break; default: break; } + + out: + return; } static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) @@ -218,7 +326,6 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) } break; case SMBHSTCNT: - s->smb_index = 0; val = s->smb_ctl & CTL_RETURN_MASK; break; case SMBHSTCMD: @@ -234,9 +341,22 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) val = s->smb_data1; break; case SMBBLKDAT: - val = s->smb_data[s->smb_index++]; - if (s->smb_index > 31) + if (s->smb_index >= PM_SMBUS_MAX_MSG_SIZE) { s->smb_index = 0; + } + if (s->smb_auxctl & AUX_BLK) { + val = s->smb_data[s->smb_index++]; + if (!s->op_done && s->smb_index == s->smb_data0) { + s->op_done = true; + s->smb_index = 0; + s->smb_stat &= ~STS_HOST_BUSY; + } + } else { + val = s->smb_blkdata; + } + break; + case SMBAUXCTL: + val = s->smb_auxctl; break; default: val = 0; @@ -248,6 +368,13 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) return val; } +static void pm_smbus_reset(PMSMBus *s) +{ + s->op_done = true; + s->smb_index = 0; + s->smb_stat = 0; +} + static const MemoryRegionOps pm_smbus_ops = { .read = smb_ioport_readb, .write = smb_ioport_writeb, @@ -258,6 +385,8 @@ static const MemoryRegionOps pm_smbus_ops = { void pm_smbus_init(DeviceState *parent, PMSMBus *smb) { + smb->op_done = true; + smb->reset = pm_smbus_reset; smb->smbus = i2c_init_bus(parent, "i2c"); memory_region_init_io(&smb->io, OBJECT(parent), &pm_smbus_ops, smb, "pm-smbus", 64); diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c index 007cb67..a66a114 100644 --- a/hw/i2c/smbus_ich9.c +++ b/hw/i2c/smbus_ich9.c @@ -61,12 +61,16 @@ static void ich9_smbus_write_config(PCIDevice *d, uint32_t address, pci_default_write_config(d, address, val, len); if (range_covers_byte(address, len, ICH9_SMB_HOSTC)) { uint8_t hostc = s->dev.config[ICH9_SMB_HOSTC]; - if ((hostc & ICH9_SMB_HOSTC_HST_EN) && - !(hostc & ICH9_SMB_HOSTC_I2C_EN)) { + if (hostc & ICH9_SMB_HOSTC_HST_EN) { memory_region_set_enabled(&s->smb.io, true); } else { memory_region_set_enabled(&s->smb.io, false); } + s->smb.i2c_enable = (hostc & ICH9_SMB_HOSTC_I2C_EN) != 0; + if (hostc & ICH9_SMB_HOSTC_SSRESET) { + s->smb.reset(&s->smb); + s->dev.config[ICH9_SMB_HOSTC] &= ~ICH9_SMB_HOSTC_SSRESET; + } } } diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h index 2a837af..99d5489 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 +#define PM_SMBUS_MAX_MSG_SIZE 32 + typedef struct PMSMBus { I2CBus *smbus; MemoryRegion io; @@ -11,8 +13,22 @@ typedef struct PMSMBus { uint8_t smb_addr; uint8_t smb_data0; uint8_t smb_data1; - uint8_t smb_data[32]; - uint8_t smb_index; + uint8_t smb_data[PM_SMBUS_MAX_MSG_SIZE]; + uint8_t smb_blkdata; + uint8_t smb_auxctl; + uint32_t smb_index; + + /* Set by pm_smbus.c */ + void (*reset)(struct PMSMBus *s); + + /* Set by the user. */ + bool i2c_enable; + + /* Internally used by pm_smbus. */ + + /* 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; } PMSMBus; void pm_smbus_init(DeviceState *parent, PMSMBus *smb); From patchwork Mon Aug 20 20:26:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144667 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4421075ljj; Mon, 20 Aug 2018 13:44:11 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyKPG4oq83ue28OhbVs8eMdgSQ3JAlpfau0rdYjvBeZ9CXvuOXXgmBGkFoZWN4zHz+6FCXt X-Received: by 2002:ac8:4789:: with SMTP id k9-v6mr12396271qtq.253.1534797851044; Mon, 20 Aug 2018 13:44:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797851; cv=none; d=google.com; s=arc-20160816; b=dAloWm35YsGG+k6PSvNA4ubu679TBT0GQmDw71UxtSJRpl8qhmkDElUUosiA6YjpB1 k1Wy6u1+aNCJ+Xjrij3aQ19eDLIGrs/APP+jyS+Swwnxhksin5CGghO98hDvO9dp6DIl tzEQjfxVhK8yJ+V7QcxiJy+/gzjGDgutLJ498E2RMWJoMGzQJ/IWZuaWdnxe+h9FItA2 EQv34Ux8c0x+IUcqKdCPryJV6h3IbEeSkNMLJpVdmi2UbLYPND2U4nuqs+5TIQjYfPzR 5OxZS5ijS2/lc8D2zSJomYuKrMx+COSJfZqv9/+H1RJs96a8I1/GjTAw2ePRFaXnSoeE QmuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=6um9LCgQm8RB2FF4sWnJ/rKBGigVWim2d8i4e7toEqQ=; b=aF7UpI45SqCBknh0bhXKt54M0Mtl9W+UI2CV5f8KmwH9mlRzZMAmPwrKg6gR6jlL2b vdqTgiiBTZUR/V6hx4PLxPFXFJdiWcE9dzQIJDDWTwJj0utf5D3LJJUhwDU0crR5i9tc k+E2nNwS2Y9AiwvWMuzkscZd+w6TqZG46iCdZBExByIW8j8PmVQCPivOm9kktZREptNv qgbDnNw4X4d7RXqnn5ImNt4+/RCbb40ntrvbvVr/5+xjevVvRw7D8ivBOtVWmFZ/2izj CvF4c8Y7r5N6AmEmDiPt+GB198dNvoKoanfLKnFfThx3hMYpgyQ6PoPwV5LV4ZYvTEMT /Dhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="PaI8k4/Z"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k8-v6si1087751qtg.106.2018.08.20.13.44.10 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:44:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="PaI8k4/Z"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frr22-0001Vu-HL for patch@linaro.org; Mon, 20 Aug 2018 16:44:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlF-0002rN-2p for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frql2-0002WH-Bi for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:46 -0400 Received: from mail-oi0-x244.google.com ([2607:f8b0:4003:c06::244]:45091) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqkw-0002Jh-Lv for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:32 -0400 Received: by mail-oi0-x244.google.com with SMTP id q11-v6so28133482oic.12 for ; Mon, 20 Aug 2018 13:26:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6um9LCgQm8RB2FF4sWnJ/rKBGigVWim2d8i4e7toEqQ=; b=PaI8k4/ZanzyPw1jVc5PETFIAAHP0rypRI5xM35m69CzoV9CRVx+lZg+wG+FbNlYo2 g8MPxoD26jRFRHjlyXsF1KYuDR+QYmDK97LjGgUz49zMCXABfxeyD2I5bOyrt0wfQvft 3jdvlonPdEXw/rK0HSun/Izd431QI00oc4JFEJ6jKeFpCUO+4PfsWy/V37CCtN/SRQ80 ILkggWkeEC/1+YzrJikzVn140IB2402xNfWBJ8VSFh0VRpdJz0wCoVQbHk5o1Z1A3TZb 44/QZATaGuB8f1jAcJoT9eM3/jDCoB2X6SXuQ8g634ZDuMICSUxEv/lJXBTlPB8Ldgok omng== 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=6um9LCgQm8RB2FF4sWnJ/rKBGigVWim2d8i4e7toEqQ=; b=nwsKd4oq1b8klu/xdyekGCLYhu7InbhkuINOxHV+LGOW01P9DuI3gaZTrvQ+cqkxml /VxO11lbb5cKH9p0YMbQA3ubavDNN+mHJl3l8Q2jQZdlCDXPjkTQeHkA8ySfxRhpxJOm wB0ZqbDwZKvKr5xXV8uReTUI806zZSP+AH6zM0qy1NTtJbMh9C5W872FTeN4T2h/vCi/ gClK+Rt8AiAjxJYePWRsqe1/3fbp750DlpYhqOlKSKq7EYNDkUKadcHp+uOYOmT2iEDX MXRBLgH+pn4sA9XwH5xcqf/uR1BpPTfZ+IPvLFPZsTIaKirtd/2tDU92KoqzojBq8++T DyzQ== X-Gm-Message-State: AOUpUlE6fuksQhbAgFqvWqRpRG5E/pLEAc2e8bgds5JkTQcmUEZhBYuk b6RGz2kYayFXGdRzq4o7QTgsQz0= X-Received: by 2002:aca:a56:: with SMTP id 83-v6mr14539080oik.57.1534796789172; Mon, 20 Aug 2018 13:26:29 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id p7-v6sm9339221oif.35.2018.08.20.13.26.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:28 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id 76919127C; Mon, 20 Aug 2018 15:26:24 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 8B5A9300108; Mon, 20 Aug 2018 15:26:21 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:05 -0500 Message-Id: <1534796770-10295-6-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::244 Subject: [Qemu-devel] [PATCH v2 05/10] i2c:pm_smbus: Fix state transfer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Dr . David Alan Gilbert" , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Transfer the state information for the SMBus registers and internal data so it will work on a VM transfer. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Dr. David Alan Gilbert --- hw/acpi/piix4.c | 3 ++- hw/i2c/pm_smbus.c | 20 ++++++++++++++++++++ hw/i2c/smbus_ich9.c | 5 +++-- include/hw/i2c/pm_smbus.h | 2 ++ 4 files changed, 27 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index 6404af5..f8d8d2e 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -309,7 +309,7 @@ static const VMStateDescription vmstate_cpuhp_state = { */ static const VMStateDescription vmstate_acpi = { .name = "piix4_pm", - .version_id = 3, + .version_id = 4, .minimum_version_id = 3, .minimum_version_id_old = 1, .load_state_old = acpi_load_old, @@ -320,6 +320,7 @@ 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(smb, PIIX4PMState, 4, 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 32132be..9e11d47 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -383,6 +383,26 @@ static const MemoryRegionOps pm_smbus_ops = { .endianness = DEVICE_LITTLE_ENDIAN, }; +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_BOOL(i2c_enable, PMSMBus), + VMSTATE_BOOL(op_done, PMSMBus), + VMSTATE_END_OF_LIST() + } +}; + void pm_smbus_init(DeviceState *parent, PMSMBus *smb) { smb->op_done = true; diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c index a66a114..c8b8413 100644 --- a/hw/i2c/smbus_ich9.c +++ b/hw/i2c/smbus_ich9.c @@ -45,10 +45,11 @@ typedef struct ICH9SMBState { static const VMStateDescription vmstate_ich9_smbus = { .name = "ich9_smb", - .version_id = 1, + .version_id = 2, .minimum_version_id = 1, .fields = (VMStateField[]) { - VMSTATE_PCI_DEVICE(dev, struct ICH9SMBState), + VMSTATE_PCI_DEVICE(dev, ICH9SMBState), + VMSTATE_STRUCT(smb, ICH9SMBState, 2, pmsmb_vmstate, PMSMBus), VMSTATE_END_OF_LIST() } }; diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h index 99d5489..b1e1970 100644 --- a/include/hw/i2c/pm_smbus.h +++ b/include/hw/i2c/pm_smbus.h @@ -33,4 +33,6 @@ typedef struct PMSMBus { void pm_smbus_init(DeviceState *parent, PMSMBus *smb); +extern const VMStateDescription pmsmb_vmstate; + #endif /* PM_SMBUS_H */ From patchwork Mon Aug 20 20:26:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144665 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4417883ljj; Mon, 20 Aug 2018 13:40:22 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYGFB/E2JOMVjwBrKbqLYNNkQiG2lGelNddbvTadb4ZBukyPUKkAmg0drb7J2E8oSXRPioC X-Received: by 2002:a37:6747:: with SMTP id b68-v6mr4099047qkc.108.1534797622357; Mon, 20 Aug 2018 13:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797622; cv=none; d=google.com; s=arc-20160816; b=mJIxy0m1WttBnvWCLBiddSWoZhKXNidMGuYapnT6WiJM8xTLKMLv8YEDejOoBeRNvA paAWqEtYe2fCbqOj6eaGnwAjRehyp/2z768rVptlFPaM8w3cwYHy9LJ94WrLjiU9tvez 8DZLi8QhldSNUY9srp67BgqJvdCToy+Z33Hdh0Egcwlsdf9yfKeZQTin9uOxSYO7LuL9 laq257ix/+EFbmwPhs3idO/s1qy5+QwYOigQ4ZfoiwJnAMUiri0s4xlkLAHprhFlG3VQ nG+t8Ni96tnCRSMk3exMG9I5vm7PV3FjeKpKCp31x/sZa5gnf6uMVX7th/07/fYow74b JHFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=IJQAbtRGAP1eRHGmjX5N0dPohyN92tJOEZD+Yo0r4Ao=; b=K8AX73GY4seAHG675Om2IrpAGkUn7OKql4ztJSSVMBezHv7T5LP2nR2Fev11Kuipau qOBQPh5mivQylkGnu0J4/qo7IwSUCLhV5oqg3rfvCdScs4OHx1rXq72RayBfgfa9HO5k HA+XCKJJoIG496Q7Jyn3U4AnPOKPQAEjg43uGVYJ272VQGWPOQhcxf1+IYuu8h5K/xsq Mpvvy8mgtj/Nle3ZeQnPraUgvDAakzww9kdsZlRhnc3BlZ1IehJ+GOdEespoMSYtiWvv O+21OlTIC+QKDZSXH+NNlCooq4OvvTJB0a9yS1qrKXLBKTiF9JXKOyzuBO1C2XOGuJ8H B2BQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SPYH9S5H; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id m14-v6si584183qvo.155.2018.08.20.13.40.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:40:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=SPYH9S5H; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqyL-0003o6-Nn for patch@linaro.org; Mon, 20 Aug 2018 16:40:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqll-0003Ht-Ez for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:27:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frqlb-0003qP-Gb for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:27:14 -0400 Received: from mail-oi0-x232.google.com ([2607:f8b0:4003:c06::232]:45840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqlR-0003Nr-Qq for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:27:05 -0400 Received: by mail-oi0-x232.google.com with SMTP id q11-v6so28135827oic.12 for ; Mon, 20 Aug 2018 13:26:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=IJQAbtRGAP1eRHGmjX5N0dPohyN92tJOEZD+Yo0r4Ao=; b=SPYH9S5HReV1wto2AE4zhOrVa1aEd5NJL05hUQfhH2ookwY++8e2Rk6gi3Yuv3EYqO H/QZed0kSsHy2mBDBkh5r4jYkgQM5i5wuKB92eT+iZafJyjH/+oJj9ibDipGvpg3cEFm Hm359o5pfgwaaC9DprXJJ6OsS75e8nYmt0H46gPAWQUP1tfaksJbeFyWfG+mM6NpVzTj 9UDyk94wa946jb+EG5RDffPMGofC4yPwGWi0aOFvL8a/W7MmoqoR+vWWtKA3QWyokqYI 9DYO24NSqi76JqPYI9ExfpV+PNAwt/dZOpqfCpv9z4uihgIIz/PYYqYtnD6jDWPkI7gI Yhvw== 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=IJQAbtRGAP1eRHGmjX5N0dPohyN92tJOEZD+Yo0r4Ao=; b=E7tjaco1O/oq41vJ1BYU4LCsCKA7uC/h3qAd8JlLw6TuHZPERam4WMPtHFew1OCGMI 3vfNyFMEYOrVzF977sEBYAHfOvpo1AQGuVkGEESA1WC5q3zRtqU35yeqrRmFAnQE9gkW m3JjPy2IoIdrJZLfLJS/Ppq+Xg6jGsirZyZ2TVI+/WLWakS6GdZdeColsvEKP5eE9UZL o8GTt3nHfyNMBGhnqdD6xa+YODqz0qCwbUhzwAxnv2LWDGzJfJgTsOdlmFFvawir6HX7 Xat+Tj16tQ62m5Ewt6yAxRbaawSR8kHiuw0e35iu2xGl3doWBUbnklHruYxtsaduVA8Z NJbw== X-Gm-Message-State: AOUpUlHHa9FsrsZkQ4ftR5moPLW5tslljD9JHtIVrqXmjk5udHd8kToe ureH1og6+Q9Bm8IOekAFsjvoMF4= X-Received: by 2002:aca:e184:: with SMTP id y126-v6mr14576325oig.313.1534796817042; Mon, 20 Aug 2018 13:26:57 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id v202-v6sm11017123oie.47.2018.08.20.13.26.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:56 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id 69DBC1271; Mon, 20 Aug 2018 15:26:24 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id A6C4D300109; Mon, 20 Aug 2018 15:26:21 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:06 -0500 Message-Id: <1534796770-10295-7-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::232 Subject: [Qemu-devel] [PATCH v2 06/10] i2c:pm_smbus: Add interrupt handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Add the necessary code so that interrupts actually work from the pm_smbus device. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini --- hw/i2c/pm_smbus.c | 14 +++++++++++++- hw/i2c/smbus_ich9.c | 19 ++++++++++++++++++- include/hw/i2c/pm_smbus.h | 2 ++ 3 files changed, 33 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 9e11d47..664a6b1 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -214,6 +214,12 @@ static void smb_transaction_start(PMSMBus *s) s->smb_stat |= STS_HOST_BUSY; } +static bool +smb_irq_value(PMSMBus *s) +{ + return ((s->smb_stat & ~STS_HOST_BUSY) != 0) && (s->smb_ctl & CTL_INTREN); +} + static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, unsigned width) { @@ -309,7 +315,9 @@ static void smb_ioport_writeb(void *opaque, hwaddr addr, uint64_t val, } out: - return; + if (s->set_irq) { + s->set_irq(s, smb_irq_value(s)); + } } static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) @@ -365,6 +373,10 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) SMBUS_DPRINTF("SMB readb port=0x%04" HWADDR_PRIx " val=0x%02x\n", addr, val); + if (s->set_irq) { + s->set_irq(s, smb_irq_value(s)); + } + return val; } diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c index c8b8413..316c2a4 100644 --- a/hw/i2c/smbus_ich9.c +++ b/hw/i2c/smbus_ich9.c @@ -40,15 +40,18 @@ typedef struct ICH9SMBState { PCIDevice dev; + bool irq_enabled; + PMSMBus smb; } ICH9SMBState; static const VMStateDescription vmstate_ich9_smbus = { .name = "ich9_smb", - .version_id = 2, + .version_id = 3, .minimum_version_id = 1, .fields = (VMStateField[]) { VMSTATE_PCI_DEVICE(dev, ICH9SMBState), + VMSTATE_BOOL_V(irq_enabled, ICH9SMBState, 3), VMSTATE_STRUCT(smb, ICH9SMBState, 2, pmsmb_vmstate, PMSMBus), VMSTATE_END_OF_LIST() } @@ -110,11 +113,25 @@ static void ich9_smb_class_init(ObjectClass *klass, void *data) dc->user_creatable = false; } +static void ich9_smb_set_irq(PMSMBus *pmsmb, bool enabled) +{ + ICH9SMBState *s = pmsmb->opaque; + + if (enabled == s->irq_enabled) { + return; + } + + s->irq_enabled = enabled; + pci_set_irq(&s->dev, enabled); +} + I2CBus *ich9_smb_init(PCIBus *bus, int devfn, uint32_t smb_io_base) { PCIDevice *d = pci_create_simple_multifunction(bus, devfn, true, TYPE_ICH9_SMB_DEVICE); ICH9SMBState *s = ICH9_SMB_DEVICE(d); + s->smb.set_irq = ich9_smb_set_irq; + s->smb.opaque = s; return s->smb.smbus; } diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h index b1e1970..cfe596f 100644 --- a/include/hw/i2c/pm_smbus.h +++ b/include/hw/i2c/pm_smbus.h @@ -23,6 +23,8 @@ typedef struct PMSMBus { /* Set by the user. */ bool i2c_enable; + void (*set_irq)(struct PMSMBus *s, bool enabled); + void *opaque; /* Internally used by pm_smbus. */ From patchwork Mon Aug 20 20:26:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144668 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4423096ljj; Mon, 20 Aug 2018 13:46:34 -0700 (PDT) X-Google-Smtp-Source: AA+uWPy5OzxjLC3BIcKsBv91+SgE8zubatQqAGHg/RPYzBU2hSw4VqgkiOwcMymZ/cIDDSr1mjBM X-Received: by 2002:a37:6b84:: with SMTP id g126-v6mr42544625qkc.231.1534797994083; Mon, 20 Aug 2018 13:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797994; cv=none; d=google.com; s=arc-20160816; b=DU/oJVeT7Phmz2eufuTMXEVObwol7eTE9pH7XzDJQ5/g0iOBExfeifIph1gtfLiP3C 2+LIokibfce0RGi1Uc7ZwU/0TDcO/Ncp6joUs17ATCCXkznIxAUON3uG5r9QYScdyVNU Ur2NMPRB0ODz06Ep3JeZLMNx9AISIqSDxr7rmMbgD2kMwqd9YJXA+J0tYB7GY6dkwoHi 0mzIC1W5M9gkDihh1O5KrMhfr8YdHbYoNwJQF4k3R6YkCCthzQ1zZSHu9uQfAiqp0chI jnH2TPLlW5HzLBaqYLOGLtC7dlUhjfz2ap3U3N5C/JDwEFCtWV6tHhMGi7J8tE8I+6YJ 46kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=vhtOYdHcEbT9TflkxyUlcUwo0tSCvGmf5NTsWpvpQak=; b=OvRXspf7Td4eHz5DeuqfM8P5JLTWjOViWLOmhLjAQDSvpesMqP5i/KFVoIWqq1R0DS Q/n+mJcPiQFOQnE3q4/O2tZiA9x9eUs0gDpLEwUo9Gju5o3dBR6PuZ7h24hTyy+CRjJ2 bIEcCvkwpwvFUahBn5ZZaPU1DLOfxiG2LZyScy7b7V+1H0TEedCk8246B+apO76j8N+K gOolBhsTU5e+F+lsyEAX7TDzv0D5wgNG7R9vF4JE8wBtM9x8RRo4o9wsM1dbKn0qYEsC Dk1iw3LZioqWDs19Tz+k2WPdj1PTixEaa5rsX8pfm3x5gLWzmZ9TRCwvr5Or1/toMwOs pJoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="kdik/S5f"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id r19-v6si680854qta.244.2018.08.20.13.46.33 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:46:34 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b="kdik/S5f"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49250 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frr4L-0002qi-KE for patch@linaro.org; Mon, 20 Aug 2018 16:46:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlq-0003L3-2N for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:27:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frqll-0004BK-G9 for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:27:25 -0400 Received: from mail-oi0-x231.google.com ([2607:f8b0:4003:c06::231]:33756) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqlb-0003PT-JP for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:27:14 -0400 Received: by mail-oi0-x231.google.com with SMTP id 8-v6so28223526oip.0 for ; Mon, 20 Aug 2018 13:26:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vhtOYdHcEbT9TflkxyUlcUwo0tSCvGmf5NTsWpvpQak=; b=kdik/S5fOJ3d3/rr6zdUXf9BOFTHIy0ofz2hHaz407850xlG6V2MPgrHajOhOw6myg zSlJ7LQYOMnL/kdnlId29HUoY9Rksmc25DpsK1U6M4dsPOdbX9bzObXO+dLrOk4m6Ygs OF2CQP3ZqLTTcO8qDVe7CZQ0ECBVAloebBnV0FTyyBgmomDz+VI9xdjUjZ4HimR4V376 sJUSap0KczFpDiSwR/KuxZyz73VRu69dhw/dceUD0TjqHdDB65Bkn36t6J5aYjTIm7Qe C7kxF2ND9uHdhHJiFtcGJuE/MUW1ndHa1KoSVLTjTnUF5lHO9NrSKzhiNm//FKGQWM4H dZug== 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=vhtOYdHcEbT9TflkxyUlcUwo0tSCvGmf5NTsWpvpQak=; b=Nug6ci8UysCnmEZxqTSHiRrhrrs5/tszczLZGPDS9FYRXqdT04UFLXkP0LKseboNpC 4meeaxWo4vcs/PJql7G2CJPSEWInmVt9q6OPd7oxBtVB0oRImVOO0KFyX1/JWK8fCdhi NzIMKJDFRrKqLo1/ZeF4KHUXQQwolkBxA9lnzJWU54P9q2N3CoUg1/LJlqzn8ANtvnQL aNWkJKmW9eNW3+Q3fcPoPx/AZWqaVOne1xvMD4ayiZYm/NZ0IXwDOJwVL6XX2gKaBcsz 0Yz3Y3ggjoXI2KPX7AP9FOEa3RzZ9N3uqOba2PsaHS7ubkc2RadgEN/xD65KOQBwSN19 5PUA== X-Gm-Message-State: AOUpUlFVDvbsC+DtjUMojbv549i8TnjaRj6owzem+gxF9MTa+/HyCjt8 v80kdsSO8p+1UO2IozhLyQ== X-Received: by 2002:aca:5885:: with SMTP id m127-v6mr14444739oib.162.1534796817868; Mon, 20 Aug 2018 13:26:57 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id q18-v6sm11585777oic.18.2018.08.20.13.26.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:57 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id B148D1307; Mon, 20 Aug 2018 15:26:24 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id BE8AD30010A; Mon, 20 Aug 2018 15:26:21 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:07 -0500 Message-Id: <1534796770-10295-8-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::231 Subject: [Qemu-devel] [PATCH v2 07/10] Don't delay host status register busy bit when interrupts are enabled X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , =?utf-8?q?Herv=C3=A9_Poussineau?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Change 880b1ffe6ec2f0ae "smbus: do not immediately complete commands" changed pm_smbus to delay setting the host busy bit until the status register was read, to work around a bug in AMIBIOS. Unfortunately, when interrupts are enabled, the status register will never get read and the processing will never happen. Modify the code to only delay setting the host busy bit if interrupts are not enabled. Signed-off-by: Corey Minyard Cc: Hervé Poussineau Cc: Philippe Mathieu-Daudé --- hw/i2c/pm_smbus.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) -- 2.7.4 Reviewed-by: Philippe Mathieu-Daudé diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 664a6b1..10ba208 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -80,9 +80,6 @@ static void smb_transaction(PMSMBus *s) I2CBus *bus = s->smbus; int ret; - assert(s->smb_stat & STS_HOST_BUSY); - s->smb_stat &= ~STS_HOST_BUSY; - SMBUS_DPRINTF("SMBus trans addr=0x%02x prot=0x%02x\n", addr, prot); /* Transaction isn't exec if STS_DEV_ERR bit set */ if ((s->smb_stat & STS_DEV_ERR) != 0) { @@ -209,9 +206,18 @@ error: static void smb_transaction_start(PMSMBus *s) { - /* Do not execute immediately the command ; it will be - * executed when guest will read SMB_STAT register */ - s->smb_stat |= STS_HOST_BUSY; + if (s->smb_ctl & CTL_INTREN) { + smb_transaction(s); + } else { + /* Do not execute immediately the command; it will be + * executed when guest will read SMB_STAT register. This + * is to work around a bug in AMIBIOS (that is working + * around another bug in some specific hardware) where + * it waits for STS_HOST_BUSY to be set before waiting + * checking for status. If STS_HOST_BUSY doesn't get + * set, it gets stuck. */ + s->smb_stat |= STS_HOST_BUSY; + } } static bool @@ -330,6 +336,7 @@ static uint64_t smb_ioport_readb(void *opaque, hwaddr addr, unsigned width) val = s->smb_stat; if (s->smb_stat & STS_HOST_BUSY) { /* execute command now */ + s->smb_stat &= ~STS_HOST_BUSY; smb_transaction(s); } break; From patchwork Mon Aug 20 20:26:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144662 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4412100ljj; Mon, 20 Aug 2018 13:33:30 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZwx9pHzbb71p/VkmdU0g4qejOThXvPDD7bvC2XVC+c1ZdJ/x2xRfilPZFb48Xz4h+eJ9Bf X-Received: by 2002:a37:214b:: with SMTP id h72-v6mr3996928qkh.372.1534797210730; Mon, 20 Aug 2018 13:33:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797210; cv=none; d=google.com; s=arc-20160816; b=DbTmsFJXcUwX/z6smBvUoitIDUcTNJ3t/DmQUqrE3WizN0MFUDjsee3MSc2WGYuvXN PHoONJs0Nn5fRHw5hj+0f6YYxXeB4aGxZKccTQ9nbXPT6jPd3bZnv0895qwMJqmvGJYm P3tfUQnUC5p96XZnk+z9t0t7vSwrHsb38nTkeAa5aTg9rJHagetvupxvCLVPqxD8DDVI h5jnhoDk76mTjCyfL4tGUfRRO7Nctj/6fJr8jpqH6gnUmJekqgeguanMWvsl04uEgdIU 6uNkVC0a6goNKW5WkjR2/cEjL6SfvRZMwuMwzAQG+j3nXUEmwguJF+q/2SlWCW9ENWs4 lOMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=ZsmQ2hvBLFdp+KRGnG27sGz3M2zpxvU0ctrBLKjEYS4=; b=UWVeA4AUXCFzM86liIp5n3dFiYIzJCvMUw57EL6FrON9Oyy7RkjO2HXEFspRbUMR0b dReKJHSoYFeVvipBn6xfBFBKejdPav13k4ttAj9rgDlR3xV5C/qz5v97iSdbMwGmR4Ns y6Ph+gqIbicHTY7hGWEQtN03VFcQho56T5fipRR3GC6jOImhSmLP130lgNRHImzM8eGx 1wMlg9YKliACdFRlpAqksUPXRB7Z6OF9wWbw4s/UOClXWANXt8RgfvEEdgxRRiFjtb+p kFGIKA8wcqgQqQQ5s0ip3vhgKNY1AFgdyAcFKeJbMrCVWcAoBO1PD6KjiSHG1UUPQkI8 RZ3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TerUvU6X; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o128-v6si1458029qkd.116.2018.08.20.13.33.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:33:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=TerUvU6X; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqri-0007iN-4h for patch@linaro.org; Mon, 20 Aug 2018 16:33:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlF-0002rI-0e for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frql2-0002Wf-CJ for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:46 -0400 Received: from mail-oi0-x242.google.com ([2607:f8b0:4003:c06::242]:42156) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqky-0002M7-CS for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:34 -0400 Received: by mail-oi0-x242.google.com with SMTP id b16-v6so28173923oic.9 for ; Mon, 20 Aug 2018 13:26:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZsmQ2hvBLFdp+KRGnG27sGz3M2zpxvU0ctrBLKjEYS4=; b=TerUvU6XfVlVtj5j7uadn0qzOTQJ2mmjuQttzfel7Nifk0C117Ey7mEgc5r9csfWiN aoP+IDk+CWGD1aSVeXV9Y9LzR+KGZTcqT31oAwKKUQzLmY9BN5lORrpzxN7XJjCqkQsG NombJ7Wh89IO0eUJsZeYrw9fWcd5ZIYaBIWzhraNN53rFMKlsLC2CB2qxjxUfTaNpWiZ h1qVFNgy5eMHyFKzOqQRtGrUWoNC3UVWLJ5xdm07ARmitAUwjtuer5OVFnSg5FtgNj74 fmAvlh1iC+1ef/aM2MVybP+bPCncTlM/MmgH3IlBlLXD2luf5RkCGZe01V+kAJ+oMYcN I08w== 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=ZsmQ2hvBLFdp+KRGnG27sGz3M2zpxvU0ctrBLKjEYS4=; b=hF0yXx2itWI6n83CbVKopLTD0f7xca4jn0O/vj1KfkZl8IN6krBL88Bal5XentCRRJ ilxDrBTkBJ4erGknIMjg8S2auHHXpC+noEhBYY52tOOzj+hYkKr+SjbPoduZRpW4cw3v 2GV3/Gwm4x0KYBP6MYPrI8eW3+ObX3GRSo8IuhCFdjwr/vNy2ZxUizd3+3HJ9XQBK+FH 9yQbcAIyCxKtf4wmy6OLTIsDRaQE8J8hmaqQj7c7YUo3fvf/x4VnX9cuBAkujGc/KF9N NDRFzQRhCyWMMTY+JydI/vcXCIzU1i+G7pDr/aofwSfsH5grq5Qq4GTuf8UXdn8G6lSn ADNg== X-Gm-Message-State: AOUpUlH/YvS+XL59NbsDjk1tMdaOHsAJ4cyARkF1kxFnUoOoNs6+++7C CCUtq5gRpLBNb5FXNiOaAIRx0E8= X-Received: by 2002:aca:5754:: with SMTP id l81-v6mr16853421oib.100.1534796790548; Mon, 20 Aug 2018 13:26:30 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id i132-v6sm9420368oif.20.2018.08.20.13.26.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:28 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id C236D13F5; Mon, 20 Aug 2018 15:26:24 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id D0FA130010B; Mon, 20 Aug 2018 15:26:21 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:08 -0500 Message-Id: <1534796770-10295-9-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::242 Subject: [Qemu-devel] [PATCH v2 08/10] i2c:pm_smbus: Add the ability to force block transfer enable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard The PIIX4 hardware has block transfer buffer always enabled in the hardware, but the i801 does not. Add a parameter to pm_smbus_init to force on the block transfer so the PIIX4 handler can enable this by default, as it was disabled by default before. Signed-off-by: Corey Minyard Cc: Michael S. Tsirkin Cc: Paolo Bonzini --- hw/acpi/piix4.c | 2 +- hw/i2c/pm_smbus.c | 5 ++++- hw/i2c/smbus_ich9.c | 2 +- hw/isa/vt82c686.c | 2 +- include/hw/i2c/pm_smbus.h | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) -- 2.7.4 Reviewed-by: Philippe Mathieu-Daudé diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c index f8d8d2e..313305f 100644 --- a/hw/acpi/piix4.c +++ b/hw/acpi/piix4.c @@ -513,7 +513,7 @@ static void piix4_pm_realize(PCIDevice *dev, Error **errp) pci_conf[0x90] = s->smb_io_base | 1; pci_conf[0x91] = s->smb_io_base >> 8; pci_conf[0xd2] = 0x09; - pm_smbus_init(DEVICE(dev), &s->smb); + pm_smbus_init(DEVICE(dev), &s->smb, true); memory_region_set_enabled(&s->smb.io, pci_conf[0xd2] & 1); memory_region_add_subregion(pci_address_space_io(dev), s->smb_io_base, &s->smb.io); diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index 10ba208..4d021bb 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -422,11 +422,14 @@ const VMStateDescription pmsmb_vmstate = { } }; -void pm_smbus_init(DeviceState *parent, PMSMBus *smb) +void pm_smbus_init(DeviceState *parent, PMSMBus *smb, bool force_aux_blk) { smb->op_done = true; smb->reset = pm_smbus_reset; smb->smbus = i2c_init_bus(parent, "i2c"); + if (force_aux_blk) { + smb->smb_auxctl |= AUX_BLK; + } memory_region_init_io(&smb->io, OBJECT(parent), &pm_smbus_ops, smb, "pm-smbus", 64); } diff --git a/hw/i2c/smbus_ich9.c b/hw/i2c/smbus_ich9.c index 316c2a4..5860fc9 100644 --- a/hw/i2c/smbus_ich9.c +++ b/hw/i2c/smbus_ich9.c @@ -88,7 +88,7 @@ static void ich9_smbus_realize(PCIDevice *d, Error **errp) pci_set_byte(d->config + ICH9_SMB_HOSTC, 0); /* TODO bar0, bar1: 64bit BAR support*/ - pm_smbus_init(&d->qdev, &s->smb); + pm_smbus_init(&d->qdev, &s->smb, false); pci_register_bar(d, ICH9_SMB_SMB_BASE_BAR, PCI_BASE_ADDRESS_SPACE_IO, &s->smb.io); } diff --git a/hw/isa/vt82c686.c b/hw/isa/vt82c686.c index cff1946..7302f6d 100644 --- a/hw/isa/vt82c686.c +++ b/hw/isa/vt82c686.c @@ -370,7 +370,7 @@ static void vt82c686b_pm_realize(PCIDevice *dev, Error **errp) pci_conf[0x90] = s->smb_io_base | 1; pci_conf[0x91] = s->smb_io_base >> 8; pci_conf[0xd2] = 0x90; - pm_smbus_init(&s->dev.qdev, &s->smb); + pm_smbus_init(&s->dev.qdev, &s->smb, false); memory_region_add_subregion(get_system_io(), s->smb_io_base, &s->smb.io); apm_init(dev, &s->apm, NULL, s); diff --git a/include/hw/i2c/pm_smbus.h b/include/hw/i2c/pm_smbus.h index cfe596f..471345e 100644 --- a/include/hw/i2c/pm_smbus.h +++ b/include/hw/i2c/pm_smbus.h @@ -33,7 +33,7 @@ typedef struct PMSMBus { bool op_done; } PMSMBus; -void pm_smbus_init(DeviceState *parent, PMSMBus *smb); +void pm_smbus_init(DeviceState *parent, PMSMBus *smb, bool force_aux_blk); extern const VMStateDescription pmsmb_vmstate; From patchwork Mon Aug 20 20:26:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144660 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4409236ljj; Mon, 20 Aug 2018 13:30:16 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwRrZKkbjPsv1SesX8WHlYj0IjAWU3GcZXPjNlf5icrZE+FQmxbnlVixl57ZyF356x9aslM X-Received: by 2002:ac8:4983:: with SMTP id f3-v6mr10944496qtq.411.1534797016526; Mon, 20 Aug 2018 13:30:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797016; cv=none; d=google.com; s=arc-20160816; b=vsGTdJERpZP6vrEZFEzAVnmgWSRdOjsax5LIDOQfi4KIlL1Szqp3syqexzdjOCGyHA 1uXdTy9t4Dvev17Qgr5i7wGtvXK5b/CVCwbaJkYgCvY7Yhm85626wJjlGWXEzQCaSBoD QzLGVkAFcfw/ac/H1wZBx7Ve+6rHVhA1l0LP1C0ZF+Gd+kO6Hk3aUBezUWzyXP0cpsj9 FJz5qpjUh89qqQIC1hUvURSHeD3EJ/Fz+CyhxVtQbpXmbRIQWxX2bZD/6gepjOWJavQT FRM4czBRWxwHktfH5q6aqHwYB6YCHYcO1lVSLjzOJMEsmIslfL1FpVE84C0+eMGCtsKu 2gFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=PjwLZzEhNIGCQw37hFyqw777IOcUEZ03GRWlf0ddFl4=; b=u8yXut6u425x+CS10Jlh9clve4ouwGbeU8lnExbRhku3GKuOOeK6T8uvfCQ9ep8dYN rvL28gt/6EG1W2tdQOtgDe4qyWKqAV1mMfmn0i1a2irxsop+Sw2c/40DykAKDzu+S7qz v1qXga//gu0mFbv/VXq3ZZoPMt6E7DYKX68grtcjKeX2HRt/AmDvwrZo+VdlEleridf7 4M21mNhfw5rtsLvQGLjtuN08LQJwFmKudFiz541ULkAUm/jTWos6C4T2tIhYs1Bzrw2K kfQEADTi/G7MCaG8rGlmi3ZEagk9lf/Pg5VChBPdtuWcaJOp6Gk7WAYQN6UJ/oNUYEKu JDAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Ii4mzlFV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id f9-v6si9853667qvd.37.2018.08.20.13.30.16 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:30:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=Ii4mzlFV; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49151 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqoa-0005Lp-1L for patch@linaro.org; Mon, 20 Aug 2018 16:30:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlF-0002rH-0b for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frql2-0002Wm-EV for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:46 -0400 Received: from mail-oi0-x22c.google.com ([2607:f8b0:4003:c06::22c]:33747) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqky-0002NE-Sd for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:34 -0400 Received: by mail-oi0-x22c.google.com with SMTP id 8-v6so28221104oip.0 for ; Mon, 20 Aug 2018 13:26:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=PjwLZzEhNIGCQw37hFyqw777IOcUEZ03GRWlf0ddFl4=; b=Ii4mzlFVnxlkB5PINoOJbN4aulbia/Ns5mHqcr9Rtu6UccmwfqODwCoeMvF0xWLU92 Eygh8l/+Nhpvc5i6kcPG9E4tJjZSUB6D2VaUCBV3EpTPhYK1C6fVJRTyjDoVlYq51jv3 HJmva5EZMcTjXfZZdJJsiEWlWDTrhklL5w3TKmmLQ8/8v+yW9CPOCzgJOldDL6JRW5aL R3oe+DfFrQofl5EKaRIV+NNpV8g6obB10+6243nQzT3UrYVUjI8CKhBoHvIKTG9FkO+P mpKM6kAAV5JPv/1tsLCTzTFXMPV9y/ntijZV5xIu8a+32JbADVW600/fDgq5iVmRn06G bixQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PjwLZzEhNIGCQw37hFyqw777IOcUEZ03GRWlf0ddFl4=; b=Ltqb2vc8TJ8P9nPxTaZiZsrcxoR33+BMGWrCHc5UzNiJmpmVBreit17OkpS1jxNMEJ 0nGowLedZ/zyS1DQ1JGTveHaDyjcTgPP2K9Z9qB1a/AaF+RBEVnjuzs/3WFdRYTfqStG E9qAJuTi9u6ELU76vlUq4D9WprClV/fT9qqekTwGuQvZFeiGIVHp1R6FcdNJWRvwKlsP IWU2HQfSxtoJEX/AIHjdVJ4wyFn7cHSeS3he8ms+lxJvOlWWAF5nzxbKMy+zLlH0unaZ JTkJgDpAxFpJLJQh6990tiWI9x1UGYWqVS5zNvL8uopwWE9344tj9HB1N7G8L0yO2ufF JSkA== X-Gm-Message-State: AOUpUlFmUCTjPu35zG7O+IdMiffGrtkh4Ee2Bow7l8pw48LA2fu/M0/J U5TKje8YG/7byUtWh7UP6+1ugyY= X-Received: by 2002:aca:68da:: with SMTP id o87-v6mr14234110oik.96.1534796791341; Mon, 20 Aug 2018 13:26:31 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id m24-v6sm5670702oic.26.2018.08.20.13.26.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:28 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id E1E511547; Mon, 20 Aug 2018 15:26:24 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 07B4A30010C; Mon, 20 Aug 2018 15:26:21 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:09 -0500 Message-Id: <1534796770-10295-10-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::22c Subject: [Qemu-devel] [PATCH v2 09/10] i2c: Add an SMBus vmstate structure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Dr . David Alan Gilbert" , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: "Michael S . Tsirkin" Cc: Dr. David Alan Gilbert --- hw/i2c/smbus.c | 14 ++++++++++++++ include/hw/i2c/smbus.h | 18 +++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/hw/i2c/smbus.c b/hw/i2c/smbus.c index 6ff77c5..b0774d7 100644 --- a/hw/i2c/smbus.c +++ b/hw/i2c/smbus.c @@ -349,6 +349,20 @@ int smbus_write_block(I2CBus *bus, uint8_t addr, uint8_t command, uint8_t *data, return 0; } +const VMStateDescription vmstate_smbus_device = { + .name = TYPE_SMBUS_DEVICE, + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_I2C_SLAVE(i2c, SMBusDevice), + VMSTATE_INT32(mode, SMBusDevice), + VMSTATE_INT32(data_len, SMBusDevice), + VMSTATE_UINT8_ARRAY(data_buf, SMBusDevice, SMBUS_DATA_MAX_LEN), + VMSTATE_UINT8(command, SMBusDevice), + VMSTATE_END_OF_LIST() + } +}; + static void smbus_device_class_init(ObjectClass *klass, void *data) { I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass); diff --git a/include/hw/i2c/smbus.h b/include/hw/i2c/smbus.h index d8b1b9e..7b52020 100644 --- a/include/hw/i2c/smbus.h +++ b/include/hw/i2c/smbus.h @@ -53,14 +53,16 @@ typedef struct SMBusDeviceClass uint8_t (*read_data)(SMBusDevice *dev, uint8_t cmd, int n); } SMBusDeviceClass; +#define SMBUS_DATA_MAX_LEN 34 /* command + len + 32 bytes of data. */ + struct SMBusDevice { /* The SMBus protocol is implemented on top of I2C. */ I2CSlave i2c; /* Remaining fields for internal use only. */ - int mode; - int data_len; - uint8_t data_buf[34]; /* command + len + 32 bytes of data. */ + int32_t mode; + int32_t data_len; + uint8_t data_buf[SMBUS_DATA_MAX_LEN]; uint8_t command; }; @@ -93,4 +95,14 @@ void smbus_eeprom_init_one(I2CBus *smbus, uint8_t address, uint8_t *eeprom_buf); void smbus_eeprom_init(I2CBus *smbus, int nb_eeprom, const uint8_t *eeprom_spd, int size); +extern const VMStateDescription vmstate_smbus_device; + +#define VMSTATE_SMBUS_DEVICE(_field, _state) { \ + .name = (stringify(_field)), \ + .size = sizeof(SMBusDevice), \ + .vmsd = &vmstate_smbus_device, \ + .flags = VMS_STRUCT, \ + .offset = vmstate_offset_value(_state, _field, SMBusDevice), \ +} + #endif From patchwork Mon Aug 20 20:26:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 144663 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp4412919ljj; Mon, 20 Aug 2018 13:34:27 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwT5cIW+S8Onl8JblfMzfqm+1OofNG0jU8y/drLdpgKVK3DwU32xOUbglA0zRZ9L0kyolcy X-Received: by 2002:a37:c0d3:: with SMTP id v80-v6mr14378958qkv.256.1534797267720; Mon, 20 Aug 2018 13:34:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534797267; cv=none; d=google.com; s=arc-20160816; b=UiKxAckXi0EU49NkYxv7pre8YPo4P3biEu7Z0oy/aibw3w5V3AvAJZDlkYnzWoiiSF HVDD5L98vyQwEs5Tvw/7qpHMHIaMDNex1qIbgMptfUxh9t+gOwNBxcDgEJQ7BVZHtn37 /6LudP7capWqDC+YIFg4AzMyMDaaPUgg3k0s7t1mdSUYwB5vVxQKZsEpIWII/XKYKvE+ YoHQIbCqudLjF7EAPOa9dQXTiVOc6d6W4QAnvHSBahLaGgOkbmonlAYnSHqYFrqKHJE1 15PW+qmLFwCGb76aCDjBRiZvmkswGAmngachJPH/u3aADsuyO4cyZHUrKAykVnAoU0S3 GWdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=j+Yp0UZkajf5t3AswMPnhMvJanDi0W7vrct2f1lQk/o=; b=wtTn6ZCfACyh3Bcoxq1lCM/suMXlmTWG0gjdE9mRW7+TFOsU3wkPbpuc5DEr1IW20y FoFVPKoXRNscgFIlpQU4oEkycsjYBFA1x32DVzexLKUCSLNoE4m2dDV8CBiRksO8rEIl o74SBWGj1GhMpGZ9mNCF3LvVVAvYKboBl+pfgyk4HwBqLTS81XrjdBJqrgLHCBELfdq7 wCFPuSGx1jgSvXhYzo1IrusAVHyp5Z2gQ+Sd8tupYC2vcO0k57fjGjKPzLcQE4O/eq5s Md1Fwd+wcLVRsccLD4x25UjrrnmLGSsHSbC8Vs/DYn2ekMxrWg6+nfMEkqwHNr+xKG/1 Sf7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=EVND+yG0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id l25-v6si4125912qtn.267.2018.08.20.13.34.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 20 Aug 2018 13:34:27 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=EVND+yG0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:49164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqsd-0007Z8-3A for patch@linaro.org; Mon, 20 Aug 2018 16:34:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqlF-0002rL-1n for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1frql2-0002WO-BI for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:46 -0400 Received: from mail-oi0-x244.google.com ([2607:f8b0:4003:c06::244]:43036) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1frqkw-0002Km-R7 for qemu-devel@nongnu.org; Mon, 20 Aug 2018 16:26:32 -0400 Received: by mail-oi0-x244.google.com with SMTP id b15-v6so28119896oib.10 for ; Mon, 20 Aug 2018 13:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=j+Yp0UZkajf5t3AswMPnhMvJanDi0W7vrct2f1lQk/o=; b=EVND+yG09g50NpeKjLTHIc6nbpBWuwmAoq4K/Rwsg32I690+StXFhFahg4/78zYop/ 0gY1MeSHXl0nCntwxC5Nzqk350haG7wLIOlh8Jqu2P4vQsInhc+xB252Je/ekpEBpwrG xle7u/s9F/PqsiRcxLTO10DwfgKrgRDPGnoUxL+BfHqIop1GX/J6B9D0F37LlX30GJDC eeaGtdTEcVLYvyXPdurIDijGULltvBYvnoz8WF+G9+expKv3lSx00thufbIBxt3zucY6 W3CFdXnv6H9Xaa/GhifX+a/1z3FGDTNl1PKP+X7o2a4HWKTIHdnOv4D38pF5+GviDrns +tHA== 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=j+Yp0UZkajf5t3AswMPnhMvJanDi0W7vrct2f1lQk/o=; b=XlMJPDrOzgRX4s17tOQPmLFzDs5yi+JGKVMfPH3bs2NjGykQ+AJb5wYrfML2XqnBYD hYfCQSnRQ7N3N3DCS+aW2l+1NGbCw9a01EXovmG8g2nBPlKDDH4tNabIPRVf8Z23NzT3 yMHPNyDw4baC0A9nQmZZosaX9/VXGPk+o+4pAdYAUqfXdSpK2Vl+sLHUlQLkvXsS6KAj zwJq1u0kfIyJrKCLUWBDElXGDYoI8LniYqEmMZYfxnjclPvbXXxcBYUUVXKarCR5yC9N X5JpDQfoOBgq/HSY+sVUD/xW0tupsd5hFNwHY+7u2UIFq52qN15CVyAPzcAEcR+OPR4o NLHQ== X-Gm-Message-State: AOUpUlHZZThe1PmTVg1t3bZbiT6Ac3/TDDHCNM/2i+njFVGx96qXYBGF PEXjZVGck/aYN9xf54kx7A== X-Received: by 2002:aca:b885:: with SMTP id i127-v6mr15817630oif.180.1534796789861; Mon, 20 Aug 2018 13:26:29 -0700 (PDT) Received: from serve.minyard.net ([47.184.170.128]) by smtp.gmail.com with ESMTPSA id 16-v6sm7205849oin.5.2018.08.20.13.26.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 13:26:28 -0700 (PDT) Received: from t430.minyard.net (unknown [IPv6:2001:470:b8f6:1b:7d98:76b7:e7fd:495f]) by serve.minyard.net (Postfix) with ESMTPA id D4C2B1453; Mon, 20 Aug 2018 15:26:24 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id 2E88030010D; Mon, 20 Aug 2018 15:26:22 -0500 (CDT) From: minyard@acm.org To: Paolo Bonzini , qemu-devel@nongnu.org Date: Mon, 20 Aug 2018 15:26:10 -0500 Message-Id: <1534796770-10295-11-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1534796770-10295-1-git-send-email-minyard@acm.org> References: <1534796770-10295-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::244 Subject: [Qemu-devel] [PATCH v2 10/10] i2c: Add vmstate handling to the smbus eeprom X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard , "Dr . David Alan Gilbert" , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Signed-off-by: Corey Minyard Cc: Paolo Bonzini Cc: "Michael S . Tsirkin" Cc: Dr. David Alan Gilbert --- hw/i2c/smbus_eeprom.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/hw/i2c/smbus_eeprom.c b/hw/i2c/smbus_eeprom.c index f18aa3d..d4430b0 100644 --- a/hw/i2c/smbus_eeprom.c +++ b/hw/i2c/smbus_eeprom.c @@ -29,6 +29,8 @@ //#define DEBUG +#define TYPE_SMBUS_EEPROM_DEVICE "smbus-eeprom" + typedef struct SMBusEEPROMDevice { SMBusDevice smbusdev; void *data; @@ -97,6 +99,17 @@ static uint8_t eeprom_read_data(SMBusDevice *dev, uint8_t cmd, int n) return eeprom_receive_byte(dev); } +static const VMStateDescription vmstate_smbus_eeprom = { + .name = TYPE_SMBUS_EEPROM_DEVICE, + .version_id = 1, + .minimum_version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_SMBUS_DEVICE(smbusdev, SMBusEEPROMDevice), + VMSTATE_UINT8(offset, SMBusEEPROMDevice), + VMSTATE_END_OF_LIST() + } +}; + static void smbus_eeprom_realize(DeviceState *dev, Error **errp) { SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev; @@ -121,12 +134,13 @@ static void smbus_eeprom_class_initfn(ObjectClass *klass, void *data) sc->write_data = eeprom_write_data; sc->read_data = eeprom_read_data; dc->props = smbus_eeprom_properties; + dc->vmsd = &vmstate_smbus_eeprom; /* Reason: pointer property "data" */ dc->user_creatable = false; } static const TypeInfo smbus_eeprom_info = { - .name = "smbus-eeprom", + .name = TYPE_SMBUS_EEPROM_DEVICE, .parent = TYPE_SMBUS_DEVICE, .instance_size = sizeof(SMBusEEPROMDevice), .class_init = smbus_eeprom_class_initfn,