From patchwork Fri Jun 10 11:08:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12877475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8D59C43334 for ; Fri, 10 Jun 2022 11:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348677AbiFJLJ2 (ORCPT ); Fri, 10 Jun 2022 07:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348086AbiFJLJX (ORCPT ); Fri, 10 Jun 2022 07:09:23 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7F39146416; Fri, 10 Jun 2022 04:09:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1654859345; bh=p955SyiSzBhWDKZyzjCb0RQrzzzHMlRchzhBPwUvL9c=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Uedbp9PiIwiSA/4jX7EyXN7wrD93q8GdX6vyvHoIJEJWaPkbdSsZDql9w2L8lKRSX rYdc/HGsra9oM4x5he6ITRilDoRuGkNT4mev7vmJIE0+1oPipXusGoeDsJHcEbgfx+ P1200JSGOBOgYZQFc1bDNY266ZrE1t9mplWertW8= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.165]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N3bWr-1nYZHe0aHr-010cAT; Fri, 10 Jun 2022 13:09:05 +0200 From: LinoSanfilippo@gmx.de To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca Cc: stefanb@linux.vnet.ibm.com, linux@mniewoehner.de, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, l.sanfilippo@kunbus.com, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com Subject: [PATCH v5 05/10] tpm, tpm_tis: Store result of interrupt capability query Date: Fri, 10 Jun 2022 13:08:41 +0200 Message-Id: <20220610110846.8307-6-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220610110846.8307-1-LinoSanfilippo@gmx.de> References: <20220610110846.8307-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:BY2VZJgYcZdy5zIhVGCICkZ8eePhQQc4vLdN+/MI383CBnP2/uF VIFiiFQuv6pKsETm1HfMeLdoIezpnagNlHViF3AXuwdsrDaV/sSkdKP1hYcg24IX0ZjlXux FgvQH94dcrFKCKMqO8UngfCJOmirlXt7yrEFhN9eKBV8zmeVCdoMLg+hxXJdHvyIawLl19+ qGrg3lse45tsWYsVgc2ww== X-UI-Out-Filterresults: notjunk:1;V03:K0:+SrIRyz0C/w=:sNiyQ6W9TEhnIIqWjbBPLZ UJApolDV3vfx4d5UQxjaN89QrRWSpPZiuye9/AqtUlK5kkVrmmWfiX0HGD1E6XBFHnQab/ivA Fs5nonakShpW3omY7YidNzeY+g1UL84SmTyF6Q2s2PE3uflHRV2u6yZqxgGTo48gc6JkykO8h CogY6l2nTWi9YcPJyqqaBkBoYtUsLiKRgtbFuS3CPLjgkAtK4MCZXjc2ckSokLCAkBuBg83ZU aA9gnI5qeS//jsiS6qn2Od0gG2v5AgiABVhExIWirpvtb/xAK22tQKCcmHASJ8oh0bRRwfsuR 2+Pf1d32aQUohqVDB8bLw57snN2401gkNHycNLdGIwT2qWOsajSHja4jRVH1IPjLH80u83E9l cT+gyBQJCHS7nxRboKRvBeWJywkR/PkBS36bIQZmbAJJdAkhaIhnzSLis5CeeVP1VjW5rinNU B8i4371yY19LPCAYQ5eBGVPPHRiCFai8TmzFlIcNebRylPvzORXa091//ZAWOCHu3QaKXYw4x FQq3tLqzKGW1UvSqQvUz7IaY0Qm1Wj7kueglOwGIUC6v8ZjGj86SgR6I4xihE+SfulDsjYUL4 k4RR/urEmwd6pbmY/QUbbLLkeTGV6MD2+AFdwgurq1+pFdU5BMLTQqSoGJAcTRljiAx0HZAWI WinTPIfYVpYQdXBmIXp6L1jnjv2kp3KVLKf+f+Ka7X2hCxWrC8PQpzyUqVQsgCFga+dqMuAhw nigfniTJX/MTPTZOnIf6WW2Wz2t1H2USTN2Hz4livJcQLkZ7CrjNeRoq1wxeDYpy6oIPVT+Mj iNzVcHUCiar1NukMZWdjFOE6owErYbMLQOH375RFVMlu0Aeol0bUYi9P69zDL0l0R/sSBjNIc 22o2Bg7dEiDoP6U+lqmYJddQwCMKnDwAF+3YNLUu+WrjJyYhMVzxqJGm0kHATRXIEdyfitrvF 15Htseh0uxdMu4EW2PK7ULLY9rUVJ+FdwIl3JVR8a0MlKQgRrZnk5xQ0Sh9imz11czebPvdcX mBliLN50/yuS733hj8/H2KERLaJ6IBi1KHHYURP1xDmx+pxA1e1DXqskm1he8qNYHkB23QpQL +C45WAH9Tz24l8aMxrFEIYY0dJ1/I/ZG8fT6B+S+R+bPUdVEdXWvsZNwg== Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo According to the TPM Interface Specification (TIS) support for "stsValid" and "commandReady" interrupts is only optional. This has to be taken into account when handling the interrupts in functions like wait_for_tpm_stat(). So query the set of supported interrupts and store it in a global variable so that it can be accessed later. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 73 +++++++++++++++++---------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 718525fcadc0..2f03fefa1706 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -1007,8 +1007,39 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, if (rc < 0) goto out_err; - intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT | - TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT; + /* Figure out the capabilities */ + rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); + if (rc < 0) + goto out_err; + + dev_dbg(dev, "TPM interface capabilities (0x%x):\n", + intfcaps); + if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) + dev_dbg(dev, "\tBurst Count Static\n"); + if (intfcaps & TPM_INTF_CMD_READY_INT) { + intmask |= TPM_INTF_CMD_READY_INT; + dev_dbg(dev, "\tCommand Ready Int Support\n"); + } + if (intfcaps & TPM_INTF_INT_EDGE_FALLING) + dev_dbg(dev, "\tInterrupt Edge Falling\n"); + if (intfcaps & TPM_INTF_INT_EDGE_RISING) + dev_dbg(dev, "\tInterrupt Edge Rising\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_LOW) + dev_dbg(dev, "\tInterrupt Level Low\n"); + if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) + dev_dbg(dev, "\tInterrupt Level High\n"); + if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) + intmask |= TPM_INTF_LOCALITY_CHANGE_INT; + dev_dbg(dev, "\tLocality Change Int Support\n"); + if (intfcaps & TPM_INTF_STS_VALID_INT) { + intmask |= TPM_INTF_STS_VALID_INT; + dev_dbg(dev, "\tSts Valid Int Support\n"); + } + if (intfcaps & TPM_INTF_DATA_AVAIL_INT) { + intmask |= TPM_INTF_DATA_AVAIL_INT; + dev_dbg(dev, "\tData Avail Int Support\n"); + } + intmask &= ~TPM_GLOBAL_INT_ENABLE; rc = request_locality(chip, 0); @@ -1042,32 +1073,6 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, goto out_err; } - /* Figure out the capabilities */ - rc = tpm_tis_read32(priv, TPM_INTF_CAPS(priv->locality), &intfcaps); - if (rc < 0) - goto out_err; - - dev_dbg(dev, "TPM interface capabilities (0x%x):\n", - intfcaps); - if (intfcaps & TPM_INTF_BURST_COUNT_STATIC) - dev_dbg(dev, "\tBurst Count Static\n"); - if (intfcaps & TPM_INTF_CMD_READY_INT) - dev_dbg(dev, "\tCommand Ready Int Support\n"); - if (intfcaps & TPM_INTF_INT_EDGE_FALLING) - dev_dbg(dev, "\tInterrupt Edge Falling\n"); - if (intfcaps & TPM_INTF_INT_EDGE_RISING) - dev_dbg(dev, "\tInterrupt Edge Rising\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_LOW) - dev_dbg(dev, "\tInterrupt Level Low\n"); - if (intfcaps & TPM_INTF_INT_LEVEL_HIGH) - dev_dbg(dev, "\tInterrupt Level High\n"); - if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT) - dev_dbg(dev, "\tLocality Change Int Support\n"); - if (intfcaps & TPM_INTF_STS_VALID_INT) - dev_dbg(dev, "\tSts Valid Int Support\n"); - if (intfcaps & TPM_INTF_DATA_AVAIL_INT) - dev_dbg(dev, "\tData Avail Int Support\n"); - /* INTERRUPT Setup */ init_waitqueue_head(&priv->read_queue); init_waitqueue_head(&priv->int_queue); @@ -1098,7 +1103,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, else tpm_tis_probe_irq(chip, intmask); - if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) { + if (chip->flags & TPM_CHIP_FLAG_IRQ) { + priv->irqs_in_use = intmask; + } else { dev_err(&chip->dev, FW_BUG "TPM interrupt not working, polling instead\n"); @@ -1145,13 +1152,7 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip) if (rc < 0) goto out; - rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); - if (rc < 0) - goto out; - - intmask |= TPM_INTF_CMD_READY_INT - | TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT - | TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE; + intmask = priv->irqs_in_use | TPM_GLOBAL_INT_ENABLE; tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 0f29d0b68c3e..8e02faa4079d 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -96,6 +96,7 @@ struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; + unsigned int irqs_in_use; unsigned long irqtest_flags; unsigned long flags; void __iomem *ilb_base_addr;