From patchwork Thu Dec 7 21:46:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 10101141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6C07960329 for ; Thu, 7 Dec 2017 21:49:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D58F28438 for ; Thu, 7 Dec 2017 21:49:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51060286DF; Thu, 7 Dec 2017 21:49:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BF29528438 for ; Thu, 7 Dec 2017 21:49:41 +0000 (UTC) Received: from localhost ([::1]:34510 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eN433-0006oO-1d for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Dec 2017 16:49:41 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51373) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eN402-000426-7K for qemu-devel@nongnu.org; Thu, 07 Dec 2017 16:46:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eN401-0006QJ-7M for qemu-devel@nongnu.org; Thu, 07 Dec 2017 16:46:34 -0500 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:38375) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eN401-0006P2-0a for qemu-devel@nongnu.org; Thu, 07 Dec 2017 16:46:33 -0500 Received: by mail-pf0-x244.google.com with SMTP id u25so5674745pfg.5 for ; Thu, 07 Dec 2017 13:46:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=3lo9mOd7Qe/S5grO0QCpk+ZWH8dtXaq/JBE7TcbML0k=; b=M43Golz6DzC6On2kLpuoNBkRQuvzW2RGHlSicxd3Z+8YSqf5YJAtyyv3j/LNIvg5Ra USCQF4ItoPajhS7WtyezxRs2Wz5NaXYR80GEjnv7R9SoW+WLD/EOcd99UJcR/AbYtYne AI/2YSpeXH2ea5GfQwioJMR7QW2kFmuM0lEjCxQEO/eZ1hEkfCABxSLuVYZZYahBYZFL S68LJVnTmghPpyIOtvl9Oto6xe2CbHKZ/sOrxXZtvcuG7u33lSGqHwnQbcRx8YgwtPsr rweddtdiVbnqB4eF7iB0QZilw66wZiH78SMYHlOko91Rkxzy/cBqtgeZ/xx4qtWsxMYd +JTw== 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=3lo9mOd7Qe/S5grO0QCpk+ZWH8dtXaq/JBE7TcbML0k=; b=hSlGAIuvNzt5+HyOjvax21dpc+xWW8qOqPr2MZllCYsBoSsTLjjAPO6YFHQZrC6tn9 zVAEbnw4tT7tCdwfC3EL1IgxJcq/v8bUGFp65sRcdJwPfPeCokLWb1IOa2UQTX9gqSrP SlGoJExEJf8rF6nozGwEpdop7/3lYLytw3CCl4+dVDVxx3KdDD+OLqRzWGSzMB0n6LYY 55mgmh81ymdYVHIfrW3MHXIXVIhbI5JJNnqTzaT8JxxVXoaOUiXa8GZ2bUQntm40tCWI st2W+hc2x6fOhPeybOMb4hY5TouDha7ZOa99LWYLbnnsJHCmeo9WUVmL5nJnzF2ZUKAp oJHA== X-Gm-Message-State: AJaThX4vXiZNF+2s1WfHssHfDB4jUmEm2uv3gAN5TijVIrt2svOhU4Y2 gJBTLdrLtLbltxa0Et56wteh8KM= X-Google-Smtp-Source: AGs4zMYMYZWuzb0T/IH4a4gIUB/q4OZCtmcKwbmcleXIg1uBo2ipKJw8hK841AyqkocBQAXGYwjDBw== X-Received: by 10.99.112.89 with SMTP id a25mr26601135pgn.2.1512683191910; Thu, 07 Dec 2017 13:46:31 -0800 (PST) Received: from serve.minyard.net ([47.184.168.85]) by smtp.gmail.com with ESMTPSA id j62sm8796887pgc.35.2017.12.07.13.46.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Dec 2017 13:46:29 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 4A734DF0; Thu, 7 Dec 2017 15:46:25 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 367DE300092; Thu, 7 Dec 2017 15:46:23 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Thu, 7 Dec 2017 15:46:13 -0600 Message-Id: <1512683181-8420-7-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512683181-8420-1-git-send-email-minyard@acm.org> References: <1512683181-8420-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:400e:c00::244 Subject: [Qemu-devel] [PATCH 06/14] 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 , Paolo Bonzini , "Michael S . Tsirkin" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Corey Minyard 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 | 17 +++++++++++++++++ include/hw/i2c/pm_smbus.h | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/hw/i2c/pm_smbus.c b/hw/i2c/pm_smbus.c index eb2df4d..2fb00d0 100644 --- a/hw/i2c/pm_smbus.c +++ b/hw/i2c/pm_smbus.c @@ -205,6 +205,12 @@ error: return; } +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) { @@ -300,7 +306,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) @@ -352,6 +360,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 706b9ec..d029816 100644 --- a/hw/i2c/smbus_ich9.c +++ b/hw/i2c/smbus_ich9.c @@ -41,6 +41,8 @@ typedef struct ICH9SMBState { PCIDevice dev; + bool irq_enabled; + PMSMBus smb; } ICH9SMBState; @@ -50,6 +52,7 @@ static const VMStateDescription vmstate_ich9_smbus = { .minimum_version_id = 1, .fields = (VMStateField[]) { VMSTATE_PCI_DEVICE(dev, ICH9SMBState), + VMSTATE_BOOL(irq_enabled, ICH9SMBState), VMSTATE_STRUCT(smb, ICH9SMBState, 1, pmsmb_vmstate, PMSMBus), VMSTATE_END_OF_LIST() } @@ -111,11 +114,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. */