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: 10570783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E6AD1390 for ; Mon, 20 Aug 2018 20:39:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DCC229B10 for ; Mon, 20 Aug 2018 20:39:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31B8629B60; Mon, 20 Aug 2018 20:39:01 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,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 C0AE829B10 for ; Mon, 20 Aug 2018 20:39:00 +0000 (UTC) Received: from localhost ([::1]:49198 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1frqx2-0003o6-2h for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Aug 2018 16:39:00 -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-Google-Smtp-Source: AA+uWPwVIeZT5XthDxRWBTo9zyPXIRNPiRALxj5mlmsyMehIyZ99HCObZ3masqy58f8QY74hD7O/1Q== 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+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 | 19 ++++++++++++++++++- include/hw/i2c/pm_smbus.h | 2 ++ 3 files changed, 33 insertions(+), 2 deletions(-) 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. */