All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lino Sanfilippo <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,
	LinoSanfilippo@gmx.de, lukas@wunner.de, p.rosenberger@kunbus.com,
	Lino Sanfilippo <l.sanfilippo@kunbus.com>
Subject: [PATCH v4 2/6] tpm, tpm_tis: Claim and release locality only once
Date: Mon,  9 May 2022 10:05:55 +0200	[thread overview]
Message-ID: <20220509080559.4381-3-LinoSanfilippo@gmx.de> (raw)
In-Reply-To: <20220509080559.4381-1-LinoSanfilippo@gmx.de>

From: Lino Sanfilippo <l.sanfilippo@kunbus.com>

It is not necessary to claim and release the default locality for each TPM
command. Instead claim the locality once at driver startup and release it
at driver shutdown.

Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
---
 drivers/char/tpm/tpm_tis_core.c | 50 +++++++++------------------------
 1 file changed, 13 insertions(+), 37 deletions(-)

diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
index 52369ef39b03..46f504fb5084 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -638,9 +638,6 @@ static int probe_itpm(struct tpm_chip *chip)
 	if (vendor != TPM_VID_INTEL)
 		return 0;
 
-	if (request_locality(chip, 0) != 0)
-		return -EBUSY;
-
 	rc = tpm_tis_send_data(chip, cmd_getticks, len);
 	if (rc == 0)
 		goto out;
@@ -659,7 +656,6 @@ static int probe_itpm(struct tpm_chip *chip)
 
 out:
 	tpm_tis_ready(chip);
-	release_locality(chip, priv->locality);
 
 	return rc;
 }
@@ -721,17 +717,11 @@ static int tpm_tis_gen_interrupt(struct tpm_chip *chip)
 	cap_t cap;
 	int ret;
 
-	ret = request_locality(chip, 0);
-	if (ret < 0)
-		return ret;
-
 	if (chip->flags & TPM_CHIP_FLAG_TPM2)
 		ret = tpm2_get_tpm_pt(chip, 0x100, &cap2, desc);
 	else
 		ret = tpm1_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc, 0);
 
-	release_locality(chip, 0);
-
 	return ret;
 }
 
@@ -855,6 +845,8 @@ void tpm_tis_remove(struct tpm_chip *chip)
 
 	tpm_tis_write32(priv, reg, ~TPM_GLOBAL_INT_ENABLE & interrupt);
 
+	release_locality(chip, 0);
+
 	tpm_tis_clkrun_enable(chip, false);
 
 	if (priv->ilb_base_addr)
@@ -925,8 +917,6 @@ static const struct tpm_class_ops tpm_tis = {
 	.req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
 	.req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
 	.req_canceled = tpm_tis_req_canceled,
-	.request_locality = request_locality,
-	.relinquish_locality = release_locality,
 	.clk_enable = tpm_tis_clkrun_enable,
 };
 
@@ -963,9 +953,15 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 
 	dev_set_drvdata(&chip->dev, priv);
 
+	rc = request_locality(chip, 0);
+	if (rc)
+		return rc;
+
 	rc = tpm_tis_read32(priv, TPM_DID_VID(0), &vendor);
-	if (rc < 0)
+	if (rc < 0) {
+		release_locality(chip, 0);
 		return rc;
+	}
 
 	priv->manufacturer_id = vendor;
 
@@ -978,8 +974,10 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 	if (is_bsw()) {
 		priv->ilb_base_addr = ioremap(INTEL_LEGACY_BLK_BASE_ADDR,
 					ILB_REMAP_SIZE);
-		if (!priv->ilb_base_addr)
+		if (!priv->ilb_base_addr) {
+			release_locality(chip, 0);
 			return -ENOMEM;
+		}
 
 		clkrun_val = ioread32(priv->ilb_base_addr + LPC_CNTRL_OFFSET);
 		/* Check if CLKRUN# is already not enabled in the LPC bus */
@@ -1006,14 +1004,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 		   TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT;
 	intmask &= ~TPM_GLOBAL_INT_ENABLE;
 
-	rc = request_locality(chip, 0);
-	if (rc < 0) {
-		rc = -ENODEV;
-		goto out_err;
-	}
-
 	tpm_tis_write32(priv, TPM_INT_ENABLE(priv->locality), intmask);
-	release_locality(chip, 0);
 
 	rc = tpm_chip_start(chip);
 	if (rc)
@@ -1072,15 +1063,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 		 * to make sure it works. May as well use that command to set the
 		 * proper timeouts for the driver.
 		 */
-
-		rc = request_locality(chip, 0);
-		if (rc < 0)
-			goto out_err;
-
 		rc = tpm_get_timeouts(chip);
-
-		release_locality(chip, 0);
-
 		if (rc) {
 			dev_err(dev, "Could not get TPM timeouts and durations\n");
 			rc = -ENODEV;
@@ -1169,16 +1152,9 @@ int tpm_tis_resume(struct device *dev)
 	 * TPM 1.2 requires self-test on resume. This function actually returns
 	 * an error code but for unknown reason it isn't handled.
 	 */
-	if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
-		ret = request_locality(chip, 0);
-		if (ret < 0)
-			return ret;
-
+	if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
 		tpm1_do_selftest(chip);
 
-		release_locality(chip, 0);
-	}
-
 	return 0;
 }
 EXPORT_SYMBOL_GPL(tpm_tis_resume);
-- 
2.36.0


  parent reply	other threads:[~2022-05-09  8:29 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09  8:05 [PATCH v4 0/6] TPM irq fixes Lino Sanfilippo
2022-05-09  8:05 ` [PATCH v4 1/6] tpm, tpm_tis_spi: Request threaded irq Lino Sanfilippo
2022-05-11 11:22   ` Jarkko Sakkinen
2022-05-11 19:18     ` Lino Sanfilippo
2022-05-13 18:08       ` Jarkko Sakkinen
2022-05-16 19:52         ` Lino Sanfilippo
2022-05-17 18:23           ` Jarkko Sakkinen
2022-05-09  8:05 ` Lino Sanfilippo [this message]
2022-05-11 11:27   ` [PATCH v4 2/6] tpm, tpm_tis: Claim and release locality only once Jarkko Sakkinen
2022-05-11 19:29     ` Lino Sanfilippo
2022-05-13 17:59       ` Jarkko Sakkinen
2022-05-16 20:23         ` Lino Sanfilippo
2022-05-09  8:05 ` [PATCH v4 3/6] tpm, tpm_tis: enable irq test Lino Sanfilippo
2022-05-09  8:05 ` [PATCH v4 4/6] tpm, tpm_tis: avoid CPU cache incoherency in " Lino Sanfilippo
2022-05-11 15:06   ` Jarkko Sakkinen
2022-05-11 19:35     ` Lino Sanfilippo
2022-05-09  8:05 ` [PATCH v4 5/6] tpm, tpm_tis: Move irq test from tpm_tis_send() to tpm_tis_probe_irq_single() Lino Sanfilippo
2022-05-11 15:09   ` Jarkko Sakkinen
2022-05-11 19:56     ` Lino Sanfilippo
2022-05-16 17:51       ` Jarkko Sakkinen
2022-05-16 20:25         ` Lino Sanfilippo
2022-05-17 18:19           ` Michael Niewöhner
2022-05-18  1:26             ` Jarkko Sakkinen
2022-05-18 16:08               ` Michael Niewöhner
2022-05-09  8:05 ` [PATCH v4 6/6] tpm, tpm_tis: Only enable supported IRQs Lino Sanfilippo
2022-05-11 15:08   ` Jarkko Sakkinen
2022-05-11 19:58     ` Lino Sanfilippo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220509080559.4381-3-LinoSanfilippo@gmx.de \
    --to=linosanfilippo@gmx.de \
    --cc=jarkko@kernel.org \
    --cc=jgg@ziepe.ca \
    --cc=l.sanfilippo@kunbus.com \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@mniewoehner.de \
    --cc=lukas@wunner.de \
    --cc=p.rosenberger@kunbus.com \
    --cc=peterhuewe@gmx.de \
    --cc=stefanb@linux.vnet.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.