From patchwork Mon May 9 08:05:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12843169 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 80425C4332F for ; Mon, 9 May 2022 08:44:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237044AbiEIIq1 (ORCPT ); Mon, 9 May 2022 04:46:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235762AbiEIIOx (ORCPT ); Mon, 9 May 2022 04:14:53 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF12F15C195; Mon, 9 May 2022 01:10:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1652083627; bh=jawVDLK4M6JXYsElU3UFwvf75JxMX5G0f1UyaQ8LpM8=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=MYq/iQWDyjCk3gl9ZzISAo+kOBHX0vIWgQr+yFDFkkA/lt01KFFh1bkuiOJiGFfyP Jct9mC2RA5L/uDvJL2DDVjxiTM1V7uqc3r3AgyxvEWi8XQsqmYLoi8KMOp/U+Dx4Nt DhkYVhlMAo2NEuZfbVhTqeY7/URD2s6lQmfXFcQA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.3.89]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M9nxt-1nky9W31oD-005uUi; Mon, 09 May 2022 10:07:07 +0200 From: Lino Sanfilippo 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, LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com, Lino Sanfilippo Subject: [PATCH v4 6/6] tpm, tpm_tis: Only enable supported IRQs Date: Mon, 9 May 2022 10:05:59 +0200 Message-Id: <20220509080559.4381-7-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220509080559.4381-1-LinoSanfilippo@gmx.de> References: <20220509080559.4381-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:zN1qIufImPbOTF8Is3GDJkJznI80WelGmSFiugxoRZj2XUS++h+ 1eHp9FzDglV6EEpbH7OpA1kRdwVbSVVrV1t2wtnfKKY2ftKltf7YfvGD3LAiTXDHgHuLIfO /4wgQW/7ic7KWfI7Jf7r2i0ypxgy21ZnJLqKSBc/W7mttzVHePrsDjk+3eeErjWwhPIRFmQ fDQJZDflUGeV+080MhNCg== X-UI-Out-Filterresults: notjunk:1;V03:K0:18GPfPn+WSU=:RafU13f5qOfv30/wg4kEea XmVUVnk3HZKa/t2simI+8Kt7RObFWCF4rh790m581amymT0SmNgIPHyVrELmbSbhoAvFQs+M0 C6aXPvzjyRxGflvXL8nihcaKq3WWVJTuoTMlUZMAmWk9FfSOPE7xqWK0oMPUuBdtWLIHXa6f5 A87baQlDSXVMNBYRtmQ/DnrEcwyWbt+rYUVGgyba3tT2YfDtp2+rBqdK5pfc9hGT0el8HGLpd GRIl0iuyyQ3VELaw4stalFuXavpeoPgmo06mCVhLS0vSz1vUv+EaOr0NGQS/9IZhOI14NwqNR xzMOVtNw83scIVDVmcPM2Qb+X8HcF3ka7996IVg4KZNyHuG8ERaNNrmSOEi+dD5rdEm4J2tYp 8s5UKfGbCRXPHgyu+bqzjBGix6g8Ywt5mV2vXwy3vp3HYNyUAINWdjR51EvaLbqTG5W7Fb6v+ YkeqTnmQc1A2b6Vu+tghtUNB6zRZmFKFFD8b/AL2YbJMcpGHjeJYUbU6pBUVcz9Cy5aekcb85 NOdwoI7zmQ9sK10iedTsQrgOgdRi2fM3blZYnwL/ZWVuC4zoTCwOqimnuV21MaLpjpSmPPdrr lNXiHdredIqtPZZ1G90J15/44DNoQSAj/rGGiBHUEsw5XiI9mPjaYfHPJiCm0mRwVYtkj3Qzq QULsauq+wlI5LpcXt6fAhzbJ3OH3aT+f+maAz3GL+5hN2dFkcqoEKL5+O9+HKt7KqQxDDV6Mt jrbFfA15A3+Wb7kauqWeMrou49veH1gP2XVC8VfGqBcfuHP47AODh0eO9i0kYfNkgWWE4fwrw VL09PmvTxSQlDp8JpXI6/d5cRTADYohkqJIp//spYo5jIB+Lxhj7NXPJsd+5ACQave5+jWsSy mYVy5tS8/c6U6O1Kkb3RYdprxnoy+WNAY9ACDnawjH3NTwwm+5VoTpzTw6xdsJOgNNhk+tK8x X5dCMsLSgf6tBuTJvq6IYrJtWG2FmbfqYLkPaWzQmhamjcHA3Sic/TPzZC0gbiffD3GYwASjD IQhLVtb7XHzf1H/WsKvL3oF1B6XOrUwasfqXByulcBgtEiFeGVByeUVTA3qwEDXKJ4eUts5u5 519qldSRqNvO6I= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org From: Lino Sanfilippo Instead of blindly trying to enable all possible interrupts, use the result from the capability query and request only the interrupts that are actually supported. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm_tis_core.c | 67 ++++++++++++++++++--------------- drivers/char/tpm/tpm_tis_core.h | 1 + 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 4c65718feb7d..784e153e2895 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -976,13 +976,46 @@ 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) { + priv->supported_irqs |= 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) { + priv->supported_irqs |= TPM_INTF_LOCALITY_CHANGE_INT; + dev_dbg(dev, "\tLocality Change Int Support\n"); + } + if (intfcaps & TPM_INTF_STS_VALID_INT) { + priv->supported_irqs |= TPM_INTF_STS_VALID_INT; + dev_dbg(dev, "\tSts Valid Int Support\n"); + } + if (intfcaps & TPM_INTF_DATA_AVAIL_INT) { + priv->supported_irqs |= TPM_INTF_DATA_AVAIL_INT; + dev_dbg(dev, "\tData Avail Int Support\n"); + } + /* Take control of the TPM's interrupt hardware and shut it off */ rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask); 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; + intmask |= priv->supported_irqs; intmask &= ~TPM_GLOBAL_INT_ENABLE; tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask); @@ -1009,32 +1042,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); @@ -1101,9 +1108,7 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip) 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->supported_irqs | 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 c8972ea8e13e..3d6b05c6fdba 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -97,6 +97,7 @@ struct tpm_tis_data { u16 manufacturer_id; int locality; int irq; + unsigned int supported_irqs; unsigned long irqtest_flags; unsigned long flags; void __iomem *ilb_base_addr;