All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: u-boot@lists.denx.de
Subject: [PATCH v3 06/11] tpm: Add a basic API implementation for TPMv2
Date: Mon, 25 Jan 2021 10:33:27 +0200	[thread overview]
Message-ID: <YA6CV4eTv/p3XQc2@apalos.home> (raw)
In-Reply-To: <20210123172607.2879600-6-sjg@chromium.org>

On Sat, Jan 23, 2021 at 10:26:02AM -0700, Simon Glass wrote:
> Add support for TPMv2 versions of API functions. So far this is not
> complete as the standard is quite large, but it implements everything
> currently available for TPMv2 in U-Boot.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
> 
> (no changes since v1)
> 
>  lib/tpm_api.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 77 insertions(+), 7 deletions(-)
> 
> diff --git a/lib/tpm_api.c b/lib/tpm_api.c
> index 758350bd18d..f1553512cc5 100644
> --- a/lib/tpm_api.c
> +++ b/lib/tpm_api.c
> @@ -16,18 +16,41 @@ static bool is_tpm1(struct udevice *dev)
>  	return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1;
>  }
>  
> +static bool is_tpm2(struct udevice *dev)
> +{
> +	return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2;
> +}
> +
>  u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode)
>  {
> -	if (is_tpm1(dev))
> +	if (is_tpm1(dev)) {
>  		return tpm1_startup(dev, mode);
> -	else
> +	} else if (is_tpm2(dev)) {
> +		enum tpm2_startup_types type;
> +
> +		switch (mode) {
> +		case TPM_ST_CLEAR:
> +			type = TPM2_SU_CLEAR;
> +			break;
> +		case TPM_ST_STATE:
> +			type = TPM2_SU_STATE;
> +			break;
> +		default:
> +		case TPM_ST_DEACTIVATED:
> +			return -EINVAL;
> +		}
> +		return tpm2_startup(dev, type);
> +	} else {
>  		return -ENOSYS;
> +	}
>  }
>  
>  u32 tpm_resume(struct udevice *dev)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_startup(dev, TPM_ST_STATE);
> +	else if (is_tpm2(dev))
> +		return tpm2_startup(dev, TPM2_SU_STATE);
>  	else
>  		return -ENOSYS;
>  }
> @@ -36,6 +59,8 @@ u32 tpm_self_test_full(struct udevice *dev)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_self_test_full(dev);
> +	else if (is_tpm2(dev))
> +		return tpm2_self_test(dev, TPMI_YES);
>  	else
>  		return -ENOSYS;
>  }
> @@ -44,6 +69,8 @@ u32 tpm_continue_self_test(struct udevice *dev)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_continue_self_test(dev);
> +	else if (is_tpm2(dev))
> +		return tpm2_self_test(dev, TPMI_NO);
>  	else
>  		return -ENOSYS;
>  }
> @@ -71,8 +98,6 @@ u32 tpm_clear_and_reenable(struct udevice *dev)
>  			log_err("TPM: Can't set deactivated state\n");
>  			return ret;
>  		}
> -	} else {
> -		return -ENOSYS;
>  	}
>  
>  	return TPM_SUCCESS;
> @@ -82,6 +107,8 @@ u32 tpm_nv_enable_locking(struct udevice *dev)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0);
> +	else if (is_tpm2(dev))
> +		return -ENOSYS;
>  	else
>  		return -ENOSYS;
>  }
> @@ -90,6 +117,8 @@ u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_nv_read_value(dev, index, data, count);
> +	else if (is_tpm2(dev))
> +		return -ENOSYS;
>  	else
>  		return -ENOSYS;
>  }
> @@ -99,6 +128,8 @@ u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_nv_write_value(dev, index, data, count);
> +	else if (is_tpm2(dev))
> +		return -ENOSYS;
>  	else
>  		return -ENOSYS;
>  }
> @@ -112,6 +143,8 @@ u32 tpm_write_lock(struct udevice *dev, u32 index)
>  {
>  	if (is_tpm1(dev))
>  		return -ENOSYS;
> +	else if (is_tpm2(dev))
> +		return -ENOSYS;
>  	else
>  		return -ENOSYS;
>  }
> @@ -121,6 +154,9 @@ u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest,
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_extend(dev, index, in_digest, out_digest);
> +	else if (is_tpm2(dev))
> +		return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest,
> +				       TPM2_DIGEST_LEN);
>  	else
>  		return -ENOSYS;
>  }
> @@ -129,6 +165,8 @@ u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_pcr_read(dev, index, data, count);
> +	else if (is_tpm2(dev))
> +		return -ENOSYS;
>  	else
>  		return -ENOSYS;
>  }
> @@ -137,6 +175,13 @@ u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_tsc_physical_presence(dev, presence);
> +
> +	/*
> +	 * Nothing to do on TPM2 for this; use platform hierarchy availability
> +	 * instead.
> +	 */
> +	else if (is_tpm2(dev))
> +		return 0;
>  	else
>  		return -ENOSYS;
>  }
> @@ -145,6 +190,10 @@ u32 tpm_finalise_physical_presence(struct udevice *dev)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_finalise_physical_presence(dev);
> +
> +	/* Nothing needs to be done with tpm2 */
> +	else if (is_tpm2(dev))
> +		return 0;
>  	else
>  		return -ENOSYS;
>  }
> @@ -153,14 +202,18 @@ u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_read_pubek(dev, data, count);
> -	else
> +	else if (is_tpm2(dev))
>  		return -ENOSYS; /* not implemented yet */
> +	else
> +		return -ENOSYS;
>  }
>  
>  u32 tpm_force_clear(struct udevice *dev)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_force_clear(dev);
> +	else if (is_tpm2(dev))
> +		return tpm2_clear(dev, TPM2_RH_PLATFORM, NULL, 0);
>  	else
>  		return -ENOSYS;
>  }
> @@ -169,6 +222,10 @@ u32 tpm_physical_enable(struct udevice *dev)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_physical_enable(dev);
> +
> +	/* Nothing needs to be done with tpm2 */
> +	else if (is_tpm2(dev))
> +		return 0;
>  	else
>  		return -ENOSYS;
>  }
> @@ -177,6 +234,10 @@ u32 tpm_physical_disable(struct udevice *dev)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_physical_disable(dev);
> +
> +	/* Nothing needs to be done with tpm2 */
> +	else if (is_tpm2(dev))
> +		return 0;
>  	else
>  		return -ENOSYS;
>  }
> @@ -185,6 +246,9 @@ u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_physical_set_deactivated(dev, state);
> +	/* Nothing needs to be done with tpm2 */
> +	else if (is_tpm2(dev))
> +		return 0;
>  	else
>  		return -ENOSYS;
>  }
> @@ -194,6 +258,8 @@ u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap,
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_get_capability(dev, cap_area, sub_cap, cap, count);
> +	else if (is_tpm2(dev))
> +		return tpm2_get_capability(dev, cap_area, sub_cap, cap, count);
>  	else
>  		return -ENOSYS;
>  }
> @@ -202,14 +268,18 @@ u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_get_permissions(dev, index, perm);
> -	else
> +	else if (is_tpm2(dev))
>  		return -ENOSYS; /* not implemented yet */
> +	else
> +		return -ENOSYS;
>  }
>  
>  u32 tpm_get_random(struct udevice *dev, void *data, u32 count)
>  {
>  	if (is_tpm1(dev))
>  		return tpm1_get_random(dev, data, count);
> -	else
> +	else if (is_tpm2(dev))
>  		return -ENOSYS; /* not implemented yet */
> +	else
> +		return -ENOSYS;
>  }
> -- 
> 2.30.0.280.ga3ce27912f-goog
> 

Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

  reply	other threads:[~2021-01-25  8:33 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-23 17:25 [PATCH v3 00/11] tpm: Support using TPM1 and TPM2 from a single API Simon Glass
2021-01-23 17:25 ` [PATCH v3 01/11] tpm: Don't include cr50 in TPL/SPL Simon Glass
2021-01-25  8:26   ` Ilias Apalodimas
2021-01-23 17:25 ` [PATCH v3 02/11] tpm: Use logging in the uclass Simon Glass
2021-01-25  8:26   ` Ilias Apalodimas
2021-01-23 17:25 ` [PATCH v3 03/11] tpm: Add debugging of request in tpm_sendrecv_command() Simon Glass
2021-01-25  8:28   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 04/11] tpm: Add an API that can support v1.2 and v2 Simon Glass
2021-01-25  8:31   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 05/11] tpm: Switch TPMv1 over to use the new API Simon Glass
2021-01-25  8:32   ` Ilias Apalodimas
2021-02-07 14:37     ` Simon Glass
2021-01-23 17:26 ` [PATCH v3 06/11] tpm: Add a basic API implementation for TPMv2 Simon Glass
2021-01-25  8:33   ` Ilias Apalodimas [this message]
2021-01-23 17:26 ` [PATCH v3 07/11] tpm: Reduce duplication in a few functions Simon Glass
2021-01-25  8:34   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 08/11] tpm: Add an implementation of define_space Simon Glass
2021-01-25  8:36   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 09/11] tpm: Add TPM2 support for read/write values Simon Glass
2021-01-25  8:37   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 10/11] tpm: Add TPM2 support for write_lock Simon Glass
2021-01-25  8:38   ` Ilias Apalodimas
2021-01-23 17:26 ` [PATCH v3 11/11] tpm: Allow disabling platform hierarchy with TPM2 Simon Glass
2021-01-25  8:38   ` Ilias Apalodimas

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=YA6CV4eTv/p3XQc2@apalos.home \
    --to=ilias.apalodimas@linaro.org \
    --cc=u-boot@lists.denx.de \
    /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.