From: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
To: tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: Jerry Snitselaar
<jsnitsel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
open list <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
linux-security-module-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH v3 3/3] tpm_crb: request and relinquish locality 0
Date: Wed, 8 Feb 2017 13:11:37 +0200 [thread overview]
Message-ID: <20170208111137.15153-4-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <20170208111137.15153-1-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Request and relinquish locality for the driver use in order to be a
better citizen in a multi locality environment like TXT.
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
drivers/char/tpm/tpm_crb.c | 73 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 64 insertions(+), 9 deletions(-)
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 853bd7b..96f661a 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -34,6 +34,15 @@ enum crb_defaults {
CRB_ACPI_START_INDEX = 1,
};
+enum crb_loc_ctrl {
+ CRB_LOC_CTRL_REQUEST_ACCESS = BIT(0),
+ CRB_LOC_CTRL_RELINQUISH = BIT(1),
+};
+
+enum crb_loc_state {
+ CRB_LOC_STATE_LOC_ASSIGNED = BIT(1),
+};
+
enum crb_ctrl_req {
CRB_CTRL_REQ_CMD_READY = BIT(0),
CRB_CTRL_REQ_GO_IDLE = BIT(1),
@@ -165,13 +174,42 @@ static int __maybe_unused crb_cmd_ready(struct device *dev,
CRB_CTRL_REQ_CMD_READY /* mask */,
0, /* value */
TPM2_TIMEOUT_C)) {
- dev_warn(dev, "cmdReady timed out\n");
+ dev_warn(dev, "TPM_CRB_CTRL_REQ_x.cmdReady timed out\n");
+ return -ETIME;
+ }
+
+ return 0;
+}
+
+static int crb_request_locality(struct tpm_chip *chip)
+{
+ struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+ if (!priv->regs_h)
+ return 0;
+
+ iowrite32(CRB_LOC_CTRL_REQUEST_ACCESS, &priv->regs_h->loc_ctrl);
+ if (!crb_wait_for_reg_32(&priv->regs_h->loc_state,
+ CRB_LOC_STATE_LOC_ASSIGNED, /* mask */
+ CRB_LOC_STATE_LOC_ASSIGNED, /* value */
+ TPM2_TIMEOUT_C)) {
+ dev_warn(&chip->dev, "TPM_LOC_STATE_x.requestAccess timed out\n");
return -ETIME;
}
return 0;
}
+static void crb_relinquish_locality(struct tpm_chip *chip)
+{
+ struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+ if (!priv->regs_h)
+ return;
+
+ iowrite32(CRB_LOC_CTRL_RELINQUISH, &priv->regs_h->loc_ctrl);
+}
+
static u8 crb_status(struct tpm_chip *chip)
{
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
@@ -188,23 +226,33 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
{
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
unsigned int expected;
+ int rc;
/* sanity check */
if (count < 6)
return -EIO;
- if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR)
- return -EIO;
+ rc = crb_request_locality(chip);
+ if (rc)
+ return rc;
+
+ if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR) {
+ rc = -EIO;
+ goto out;
+ }
memcpy_fromio(buf, priv->rsp, 6);
expected = be32_to_cpup((__be32 *) &buf[2]);
-
- if (expected > count)
- return -EIO;
+ if (expected > count) {
+ rc = -EIO;
+ goto out;
+ }
memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6);
- return expected;
+out:
+ crb_relinquish_locality(chip);
+ return rc ? rc : expected;
}
static int crb_do_acpi_start(struct tpm_chip *chip)
@@ -227,7 +275,11 @@ static int crb_do_acpi_start(struct tpm_chip *chip)
static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
{
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
- int rc = 0;
+ int rc;
+
+ rc = crb_request_locality(chip);
+ if (rc)
+ return rc;
/* Zero the cancel register so that the next command will not get
* canceled.
@@ -237,7 +289,8 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
if (len > priv->cmd_size) {
dev_err(&chip->dev, "invalid command count value %zd %d\n",
len, priv->cmd_size);
- return -E2BIG;
+ rc = -E2BIG;
+ goto out;
}
memcpy_toio(priv->cmd, buf, len);
@@ -251,6 +304,8 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
if (priv->flags & CRB_FL_ACPI_START)
rc = crb_do_acpi_start(chip);
+out:
+ crb_relinquish_locality(chip);
return rc;
}
--
2.9.3
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
WARNING: multiple messages have this Message-ID (diff)
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: tpmdd-devel@lists.sourceforge.net
Cc: linux-security-module@vger.kernel.org,
Jerry Snitselaar <jsnitsel@redhat.com>,
Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
Peter Huewe <peterhuewe@gmx.de>,
Marcel Selhorst <tpmdd@selhorst.net>,
Jason Gunthorpe <jgunthorpe@obsidianresearch.com>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v3 3/3] tpm_crb: request and relinquish locality 0
Date: Wed, 8 Feb 2017 13:11:37 +0200 [thread overview]
Message-ID: <20170208111137.15153-4-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <20170208111137.15153-1-jarkko.sakkinen@linux.intel.com>
Request and relinquish locality for the driver use in order to be a
better citizen in a multi locality environment like TXT.
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
drivers/char/tpm/tpm_crb.c | 73 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 64 insertions(+), 9 deletions(-)
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c
index 853bd7b..96f661a 100644
--- a/drivers/char/tpm/tpm_crb.c
+++ b/drivers/char/tpm/tpm_crb.c
@@ -34,6 +34,15 @@ enum crb_defaults {
CRB_ACPI_START_INDEX = 1,
};
+enum crb_loc_ctrl {
+ CRB_LOC_CTRL_REQUEST_ACCESS = BIT(0),
+ CRB_LOC_CTRL_RELINQUISH = BIT(1),
+};
+
+enum crb_loc_state {
+ CRB_LOC_STATE_LOC_ASSIGNED = BIT(1),
+};
+
enum crb_ctrl_req {
CRB_CTRL_REQ_CMD_READY = BIT(0),
CRB_CTRL_REQ_GO_IDLE = BIT(1),
@@ -165,13 +174,42 @@ static int __maybe_unused crb_cmd_ready(struct device *dev,
CRB_CTRL_REQ_CMD_READY /* mask */,
0, /* value */
TPM2_TIMEOUT_C)) {
- dev_warn(dev, "cmdReady timed out\n");
+ dev_warn(dev, "TPM_CRB_CTRL_REQ_x.cmdReady timed out\n");
+ return -ETIME;
+ }
+
+ return 0;
+}
+
+static int crb_request_locality(struct tpm_chip *chip)
+{
+ struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+ if (!priv->regs_h)
+ return 0;
+
+ iowrite32(CRB_LOC_CTRL_REQUEST_ACCESS, &priv->regs_h->loc_ctrl);
+ if (!crb_wait_for_reg_32(&priv->regs_h->loc_state,
+ CRB_LOC_STATE_LOC_ASSIGNED, /* mask */
+ CRB_LOC_STATE_LOC_ASSIGNED, /* value */
+ TPM2_TIMEOUT_C)) {
+ dev_warn(&chip->dev, "TPM_LOC_STATE_x.requestAccess timed out\n");
return -ETIME;
}
return 0;
}
+static void crb_relinquish_locality(struct tpm_chip *chip)
+{
+ struct crb_priv *priv = dev_get_drvdata(&chip->dev);
+
+ if (!priv->regs_h)
+ return;
+
+ iowrite32(CRB_LOC_CTRL_RELINQUISH, &priv->regs_h->loc_ctrl);
+}
+
static u8 crb_status(struct tpm_chip *chip)
{
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
@@ -188,23 +226,33 @@ static int crb_recv(struct tpm_chip *chip, u8 *buf, size_t count)
{
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
unsigned int expected;
+ int rc;
/* sanity check */
if (count < 6)
return -EIO;
- if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR)
- return -EIO;
+ rc = crb_request_locality(chip);
+ if (rc)
+ return rc;
+
+ if (ioread32(&priv->regs_t->ctrl_sts) & CRB_CTRL_STS_ERROR) {
+ rc = -EIO;
+ goto out;
+ }
memcpy_fromio(buf, priv->rsp, 6);
expected = be32_to_cpup((__be32 *) &buf[2]);
-
- if (expected > count)
- return -EIO;
+ if (expected > count) {
+ rc = -EIO;
+ goto out;
+ }
memcpy_fromio(&buf[6], &priv->rsp[6], expected - 6);
- return expected;
+out:
+ crb_relinquish_locality(chip);
+ return rc ? rc : expected;
}
static int crb_do_acpi_start(struct tpm_chip *chip)
@@ -227,7 +275,11 @@ static int crb_do_acpi_start(struct tpm_chip *chip)
static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
{
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
- int rc = 0;
+ int rc;
+
+ rc = crb_request_locality(chip);
+ if (rc)
+ return rc;
/* Zero the cancel register so that the next command will not get
* canceled.
@@ -237,7 +289,8 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
if (len > priv->cmd_size) {
dev_err(&chip->dev, "invalid command count value %zd %d\n",
len, priv->cmd_size);
- return -E2BIG;
+ rc = -E2BIG;
+ goto out;
}
memcpy_toio(priv->cmd, buf, len);
@@ -251,6 +304,8 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
if (priv->flags & CRB_FL_ACPI_START)
rc = crb_do_acpi_start(chip);
+out:
+ crb_relinquish_locality(chip);
return rc;
}
--
2.9.3
next prev parent reply other threads:[~2017-02-08 11:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-08 11:11 [PATCH v3 0/3] Locality support for tpm_crb Jarkko Sakkinen
2017-02-08 11:11 ` Jarkko Sakkinen
[not found] ` <20170208111137.15153-1-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-02-08 11:11 ` [PATCH v3 1/3] tpm_crb: map locality registers Jarkko Sakkinen
2017-02-08 11:11 ` Jarkko Sakkinen
2017-02-08 11:11 ` [PATCH v3 2/3] tpm_crb: encapsulate crb_wait_for_reg_32 Jarkko Sakkinen
2017-02-08 11:11 ` Jarkko Sakkinen
2017-02-08 11:11 ` Jarkko Sakkinen [this message]
2017-02-08 11:11 ` [PATCH v3 3/3] tpm_crb: request and relinquish locality 0 Jarkko Sakkinen
2017-03-04 1:27 ` [PATCH v3 0/3] Locality support for tpm_crb Jerry Snitselaar
2017-03-06 15:35 ` Jarkko Sakkinen
[not found] ` <20170306153515.7hxoylfqfvy5rito-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-03-07 16:41 ` Wei, Gang
2017-03-07 16:41 ` Wei, Gang
[not found] ` <D0B11485C64D4B47B66902F8A4E901BE3B9AF0F7-E2R4CRU6q/6iAffOGbnezLfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2017-03-07 18:31 ` Jarkko Sakkinen
2017-03-07 18:31 ` Jarkko Sakkinen
[not found] ` <87efydvnk8.fsf-RR6//3E8fTwgb5+hjvvj3w@public.gmane.org>
2017-03-07 10:41 ` Jarkko Sakkinen
2017-03-07 10:41 ` Jarkko Sakkinen
-- strict thread matches above, loose matches on Subject: below --
2016-12-07 11:49 Jarkko Sakkinen
[not found] ` <20161207115001.18332-1-jarkko.sakkinen-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-12-07 11:50 ` [PATCH v3 3/3] tpm_crb: request and relinquish locality 0 Jarkko Sakkinen
2016-12-07 11:50 ` Jarkko Sakkinen
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=20170208111137.15153-4-jarkko.sakkinen@linux.intel.com \
--to=jarkko.sakkinen-vuqaysv1563yd54fqh9/ca@public.gmane.org \
--cc=jsnitsel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-security-module-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=tpmdd-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/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.