From patchwork Wed Dec 7 11:50:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 703547 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tYcJG2j7Bz9t1B for ; Wed, 7 Dec 2016 22:50:38 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cEak5-00085c-80; Wed, 07 Dec 2016 11:50:33 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cEak3-00085Q-QY for tpmdd-devel@lists.sourceforge.net; Wed, 07 Dec 2016 11:50:31 +0000 X-ACL-Warn: Received: from mga07.intel.com ([134.134.136.100]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1cEak2-0004Vm-3U for tpmdd-devel@lists.sourceforge.net; Wed, 07 Dec 2016 11:50:31 +0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga105.jf.intel.com with ESMTP; 07 Dec 2016 03:50:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,310,1477983600"; d="scan'208";a="909642490" Received: from jsakkine-mobl1.tm.intel.com (HELO localhost) ([10.237.50.54]) by orsmga003.jf.intel.com with ESMTP; 07 Dec 2016 03:50:22 -0800 From: Jarkko Sakkinen To: Peter Huewe Date: Wed, 7 Dec 2016 13:50:00 +0200 Message-Id: <20161207115001.18332-4-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161207115001.18332-1-jarkko.sakkinen@linux.intel.com> References: <20161207115001.18332-1-jarkko.sakkinen@linux.intel.com> X-Spam-Score: -3.0 (---) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [134.134.136.100 listed in list.dnswl.org] -3.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.0 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1cEak2-0004Vm-3U Cc: open list , linux-security-module@vger.kernel.org, "moderated list:TPM DEVICE DRIVER" Subject: [tpmdd-devel] [PATCH v3 3/3] tpm_crb: request and relinquish locality 0 X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net 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 --- 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; }