From patchwork Tue Nov 6 22:21:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 993963 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42qPYH1Mzdz9sBk for ; Wed, 7 Nov 2018 09:36:51 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id DF9C9C22784; Tue, 6 Nov 2018 22:30:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id DC490C2275B; Tue, 6 Nov 2018 22:23:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 32FE9C2278F; Tue, 6 Nov 2018 22:22:49 +0000 (UTC) Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by lists.denx.de (Postfix) with ESMTPS id BC52AC22737 for ; Tue, 6 Nov 2018 22:22:45 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id 92so28260452qkx.19 for ; Tue, 06 Nov 2018 14:22:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=28ptG4izAUChPCaETXxuVCl+0HjZUUfWjeD1ba0JmsM=; b=by3+ftQot4leTu/FYT00c2Bg0O8RsflLeUR7DAg/19MfJBjBsMhIlYb7IQETyiPTNQ 8YQtrauSP6xHFq1z3O57FT8HGHr0u/4BkFclUciJVE3tkNlH27kwJMzACU1yC1p8OSNN XXVW7Hj/GB1na/vFnzdQX0DAp1O+vzWFkEAyjJUJ9SDGz9+cT97yImJp2zDUfk7VrEvP kqasgJhtBXR5XxfNexqFUtwltG4pO34R3VTNmxNMP0Pz/WwqWlnAB2EOjKelUPMc/Osu vpPrOIETiHZuKSTw+WyPoO4tsaVTnzsVQy4MkUweZxtVkO91i2ssNYRBEIwxLtwflbb/ sVyQ== X-Gm-Message-State: AGRZ1gLo3RlnzM1Ct4yjXQQm4eBT4K8rWJoiEu5Wot0X7/PbvoIrpS9B YZ8F8+iqXTZMzs2wL+afm1hnTpU= X-Google-Smtp-Source: AJdET5chGC2Ibrf02+d1Q982YTIcrMJDobwBroBNHJNLYJNEZf0x5s/XEbD7WUy11suwGBVQ5Dx2ijM= X-Received: by 2002:ac8:25fc:: with SMTP id f57mr11744169qtf.12.1541542964894; Tue, 06 Nov 2018 14:22:44 -0800 (PST) Date: Tue, 6 Nov 2018 15:21:34 -0700 In-Reply-To: <20181106222142.94537-1-sjg@chromium.org> Message-Id: <20181106222142.94537-18-sjg@chromium.org> Mime-Version: 1.0 References: <20181106222142.94537-1-sjg@chromium.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog From: Simon Glass To: U-Boot Mailing List Cc: Miquel Raynal Subject: [U-Boot] [PATCH 17/25] tpm: Export the open/close functions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" At present these functions are not accessible outside the TPM library, but in some cases we need to call them. Export them in the header file and add a define for the SHA1 digest size. Also adjust tpm_open() to call tpm_close() first so that the TPM is in a known state before opening (e.g. by a previous phase of U-Boot). Signed-off-by: Simon Glass --- drivers/tpm/tpm_tis_lpc.c | 50 +++++++++++++++++++++++---------------- include/tpm-common.h | 20 ++++++++++++++++ lib/tpm-utils.h | 18 -------------- 3 files changed, 50 insertions(+), 38 deletions(-) diff --git a/drivers/tpm/tpm_tis_lpc.c b/drivers/tpm/tpm_tis_lpc.c index e993fd9f833..d76d7ca75af 100644 --- a/drivers/tpm/tpm_tis_lpc.c +++ b/drivers/tpm/tpm_tis_lpc.c @@ -388,6 +388,27 @@ static int tis_readresponse(struct udevice *dev, u8 *buffer, size_t len) return offset; } +static int tpm_tis_lpc_close(struct udevice *dev) +{ + struct tpm_tis_lpc_priv *priv = dev_get_priv(dev); + struct tpm_locality *regs = priv->regs; + u8 locality = 0; + + if (tpm_read_word(priv, ®s[locality].access) & + TIS_ACCESS_ACTIVE_LOCALITY) { + tpm_write_word(priv, TIS_ACCESS_ACTIVE_LOCALITY, + ®s[locality].access); + + if (tis_wait_reg(priv, ®s[locality].access, + TIS_ACCESS_ACTIVE_LOCALITY, 0) == -ETIMEDOUT) { + printf("%s:%d - failed to release locality %d\n", + __FILE__, __LINE__, locality); + return -ETIMEDOUT; + } + } + return 0; +} + static int tpm_tis_lpc_open(struct udevice *dev) { struct tpm_tis_lpc_priv *priv = dev_get_priv(dev); @@ -395,6 +416,12 @@ static int tpm_tis_lpc_open(struct udevice *dev) u8 locality = 0; /* we use locality zero for everything. */ int ret; + ret = tpm_tis_lpc_close(dev); + if (ret) { + printf("%s: Failed to close TPM\n", __func__); + return ret; + } + /* now request access to locality. */ tpm_write_word(priv, TIS_ACCESS_REQUEST_USE, ®s[locality].access); @@ -408,29 +435,12 @@ static int tpm_tis_lpc_open(struct udevice *dev) return ret; } + /* Certain TPMs need some delay here or they hang */ + udelay(10); + tpm_write_word(priv, TIS_STS_COMMAND_READY, ®s[locality].tpm_status); - return 0; -} - -static int tpm_tis_lpc_close(struct udevice *dev) -{ - struct tpm_tis_lpc_priv *priv = dev_get_priv(dev); - struct tpm_locality *regs = priv->regs; - u8 locality = 0; - - if (tpm_read_word(priv, ®s[locality].access) & - TIS_ACCESS_ACTIVE_LOCALITY) { - tpm_write_word(priv, TIS_ACCESS_ACTIVE_LOCALITY, - ®s[locality].access); - if (tis_wait_reg(priv, ®s[locality].access, - TIS_ACCESS_ACTIVE_LOCALITY, 0) == -ETIMEDOUT) { - printf("%s:%d - failed to release locality %d\n", - __FILE__, __LINE__, locality); - return -ETIMEDOUT; - } - } return 0; } diff --git a/include/tpm-common.h b/include/tpm-common.h index 5f8bc6bc528..f8c5569003e 100644 --- a/include/tpm-common.h +++ b/include/tpm-common.h @@ -26,6 +26,8 @@ enum tpm_duration { /* Max buffer size supported by our tpm */ #define TPM_DEV_BUFSIZE 1260 +#define TPM_PCR_MINIMUM_DIGEST_SIZE 20 + /** * enum tpm_version - The version of the TPM stack to be used * @TPM_V1: Use TPM v1.x stack @@ -179,6 +181,24 @@ int do_##cmd(cmd_tbl_t *cmdtp, int flag, \ return report_return_code(cmd()); \ } +/** + * tpm_open() - Request access to locality 0 for the caller + * + * After all commands have been completed the caller is supposed to + * call tpm_close(). + * + * Returns 0 on success, -ve on failure. + */ +int tpm_open(struct udevice *dev); + +/** + * tpm_close() - Close the current session + * + * Releasing the locked locality. Returns 0 on success, -ve 1 on + * failure (in case lock removal did not succeed). + */ +int tpm_close(struct udevice *dev); + /** * tpm_get_desc() - Get a text description of the TPM * diff --git a/lib/tpm-utils.h b/lib/tpm-utils.h index a9cb7dc7ee5..ac95f262f56 100644 --- a/lib/tpm-utils.h +++ b/lib/tpm-utils.h @@ -18,24 +18,6 @@ #define tpm_u16(x) __MSB(x), __LSB(x) #define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF) -/** - * tpm_open() - Request access to locality 0 for the caller - * - * After all commands have been completed the caller is supposed to - * call tpm_close(). - * - * Returns 0 on success, -ve on failure. - */ -int tpm_open(struct udevice *dev); - -/** - * tpm_close() - Close the current session - * - * Releasing the locked locality. Returns 0 on success, -ve 1 on - * failure (in case lock removal did not succeed). - */ -int tpm_close(struct udevice *dev); - /** * Pack data into a byte string. The data types are specified in * the format string: 'b' means unsigned byte, 'w' unsigned word,