From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A608C43334 for ; Tue, 7 Jun 2022 08:28:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EC2F284310; Tue, 7 Jun 2022 10:28:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="TqMCEvSi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 12723842F2; Tue, 7 Jun 2022 10:28:53 +0200 (CEST) Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 69B7F842EC for ; Tue, 7 Jun 2022 10:28:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wm1-x32a.google.com with SMTP id l126-20020a1c2584000000b0039c1a10507fso3255751wml.1 for ; Tue, 07 Jun 2022 01:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6IspYiZVr4pYOAB+Hkj5C+nkdpDXCcwZNNgHMpxPqAo=; b=TqMCEvSiuymtEALNT/cW/z8nO42ozvDa9h3MuIW7RXcaPxUFC03u/luCjtsdXIq8aT svMEFCf0oCjmwhhM1Mzi90ZWUWwEnACgaz2B8wapQycD4vJom3UqtHMFwjYkp/D3bz1e JSq1plEEX4uyhMmQRyTWXQU4tIGHNVrx2Lh2ECnUT9042jvHMwRzk2AjexTABlKc6yf4 72X0iXQZ41b3RUPa/su9ZYeXvUXI9ArlORxcJHG5nvoJZ5nJrUMB4JwzjzgX/HlkI88n EkqQWq7NNQ0ndJvE5q2n+7o+oi3U4pFGKSF2pKXMpORkgQPBms2NRz6C/JahsSmEiHBB 2LQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6IspYiZVr4pYOAB+Hkj5C+nkdpDXCcwZNNgHMpxPqAo=; b=sg8AU6UAFQwQnddJqePCtX25e4gEshFPkqhMAWltUWVS0rykabd9etTCdA4K82fwPF o+EtD4NPMxLFLbxfiAUHp6iEXRZQsRQE1vBgKczPghcqNPqXD2ze9/GxTUcZRo6hr9r2 v3UKoUrlZHvxxG06Npir7OeVMkq3cRVyiRmOpengTfNm/jNwPYnDAm+IzsTEnK0kqero EV0J2U1kCmEZavLGFei6XO/Mc18GAXvFjvgyxSVB4UdRlTVwwh707Q2Uy7awUZ88Xbeo KMOtshFAuTQ0z7gunb4pWVEyqTRGiNzBkBpx4Mfwu8lNkhEzYXpZy9q+IKNWQUrFHVAt Ks3Q== X-Gm-Message-State: AOAM530ZaPhY1G8cYDAhUTLNn6kmbvsaQYtcUo+enGFncNhccvBnR8Wa OfCXo6O1gSkku4gx6tVWYdKWK+9nycwF8g== X-Google-Smtp-Source: ABdhPJxhiIrttYpN09ty4X0EH2lvnlGf/AHda8LedDZ0kVtr/VYiYd+3XTIiFRzoT3xO0WHokFEqzQ== X-Received: by 2002:a05:600c:1d19:b0:39c:4aee:fe3a with SMTP id l25-20020a05600c1d1900b0039c4aeefe3amr13774320wms.89.1654590527866; Tue, 07 Jun 2022 01:28:47 -0700 (PDT) Received: from hera (ppp089210241233.access.hol.gr. [89.210.241.233]) by smtp.gmail.com with ESMTPSA id k7-20020a5d6d47000000b0020e5e906e47sm17116344wri.75.2022.06.07.01.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 01:28:47 -0700 (PDT) Date: Tue, 7 Jun 2022 11:28:44 +0300 From: Ilias Apalodimas To: Simon Glass Cc: U-Boot Mailing List Subject: Re: [PATCH 1/8] tpm: Export the TPM-version functions Message-ID: References: <20220301001125.1554442-1-sjg@chromium.org> <20220301001125.1554442-2-sjg@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220301001125.1554442-2-sjg@chromium.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Hi Simon, Apologies the late reply. I wasn't cc'ed on those and missed them in my mailbox. On Mon, Feb 28, 2022 at 05:11:18PM -0700, Simon Glass wrote: > These functions should really be available outside the TPM code, so that > other callers can find out which version the TPM is. Rename them to have > a tpm_ prefix() and add them to the header file. > > Signed-off-by: Simon Glass > --- > > include/tpm_api.h | 10 ++++++ > lib/tpm_api.c | 92 +++++++++++++++++++++-------------------------- > 2 files changed, 51 insertions(+), 51 deletions(-) > > diff --git a/include/tpm_api.h b/include/tpm_api.h > index ef45b43a8f..11aa14eb79 100644 > --- a/include/tpm_api.h > +++ b/include/tpm_api.h > @@ -319,4 +319,14 @@ u32 tpm_write_lock(struct udevice *dev, u32 index); > */ > u32 tpm_resume(struct udevice *dev); > > +static inline bool tpm_is_v1(struct udevice *dev) > +{ > + return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1; > +} > + > +static inline bool tpm_is_v2(struct udevice *dev) > +{ > + return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2; > +} > + > #endif /* __TPM_API_H */ > diff --git a/lib/tpm_api.c b/lib/tpm_api.c > index 4c662640a9..4ac4612c81 100644 > --- a/lib/tpm_api.c > +++ b/lib/tpm_api.c > @@ -11,21 +11,11 @@ > #include > #include > > -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 (tpm_is_v1(dev)) { > return tpm1_startup(dev, mode); > - } else if (is_tpm2(dev)) { > + } else if (tpm_is_v2(dev)) { > enum tpm2_startup_types type; > > switch (mode) { > @@ -47,9 +37,9 @@ u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) > > u32 tpm_resume(struct udevice *dev) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_startup(dev, TPM_ST_STATE); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_startup(dev, TPM2_SU_STATE); > else > return -ENOSYS; > @@ -57,9 +47,9 @@ u32 tpm_resume(struct udevice *dev) > > u32 tpm_self_test_full(struct udevice *dev) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_self_test_full(dev); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_self_test(dev, TPMI_YES); > else > return -ENOSYS; > @@ -67,9 +57,9 @@ u32 tpm_self_test_full(struct udevice *dev) > > u32 tpm_continue_self_test(struct udevice *dev) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_continue_self_test(dev); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_self_test(dev, TPMI_NO); > else > return -ENOSYS; > @@ -86,7 +76,7 @@ u32 tpm_clear_and_reenable(struct udevice *dev) > return ret; > } > > - if (is_tpm1(dev)) { > + if (tpm_is_v1(dev)) { > ret = tpm1_physical_enable(dev); > if (ret != TPM_SUCCESS) { > log_err("TPM: Can't set enabled state\n"); > @@ -105,9 +95,9 @@ u32 tpm_clear_and_reenable(struct udevice *dev) > > u32 tpm_nv_enable_locking(struct udevice *dev) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return -ENOSYS; > else > return -ENOSYS; > @@ -115,9 +105,9 @@ u32 tpm_nv_enable_locking(struct udevice *dev) > > u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_nv_read_value(dev, index, data, count); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_nv_read_value(dev, index, data, count); > else > return -ENOSYS; > @@ -126,9 +116,9 @@ u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count) > u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data, > u32 count) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_nv_write_value(dev, index, data, count); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_nv_write_value(dev, index, data, count); > else > return -ENOSYS; > @@ -141,9 +131,9 @@ u32 tpm_set_global_lock(struct udevice *dev) > > u32 tpm_write_lock(struct udevice *dev, u32 index) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return -ENOSYS; > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_write_lock(dev, index); > else > return -ENOSYS; > @@ -152,9 +142,9 @@ u32 tpm_write_lock(struct udevice *dev, u32 index) > u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest, > void *out_digest) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_extend(dev, index, in_digest, out_digest); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest, > TPM2_DIGEST_LEN); > else > @@ -163,9 +153,9 @@ u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest, > > u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_pcr_read(dev, index, data, count); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return -ENOSYS; > else > return -ENOSYS; > @@ -173,14 +163,14 @@ u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count) > > u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(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)) > + else if (tpm_is_v2(dev)) > return 0; > else > return -ENOSYS; > @@ -188,11 +178,11 @@ u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence) > > u32 tpm_finalise_physical_presence(struct udevice *dev) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_finalise_physical_presence(dev); > > /* Nothing needs to be done with tpm2 */ > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return 0; > else > return -ENOSYS; > @@ -200,9 +190,9 @@ u32 tpm_finalise_physical_presence(struct udevice *dev) > > u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_read_pubek(dev, data, count); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return -ENOSYS; /* not implemented yet */ > else > return -ENOSYS; > @@ -210,9 +200,9 @@ u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count) > > u32 tpm_force_clear(struct udevice *dev) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_force_clear(dev); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_clear(dev, TPM2_RH_PLATFORM, NULL, 0); > else > return -ENOSYS; > @@ -220,11 +210,11 @@ u32 tpm_force_clear(struct udevice *dev) > > u32 tpm_physical_enable(struct udevice *dev) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_physical_enable(dev); > > /* Nothing needs to be done with tpm2 */ > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return 0; > else > return -ENOSYS; > @@ -232,11 +222,11 @@ u32 tpm_physical_enable(struct udevice *dev) > > u32 tpm_physical_disable(struct udevice *dev) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_physical_disable(dev); > > /* Nothing needs to be done with tpm2 */ > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return 0; > else > return -ENOSYS; > @@ -244,10 +234,10 @@ u32 tpm_physical_disable(struct udevice *dev) > > u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_physical_set_deactivated(dev, state); > /* Nothing needs to be done with tpm2 */ > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return 0; > else > return -ENOSYS; > @@ -256,9 +246,9 @@ u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state) > u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap, > void *cap, size_t count) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_get_capability(dev, cap_area, sub_cap, cap, count); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return tpm2_get_capability(dev, cap_area, sub_cap, cap, count); > else > return -ENOSYS; > @@ -266,9 +256,9 @@ u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap, > > u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_get_permissions(dev, index, perm); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return -ENOSYS; /* not implemented yet */ > else > return -ENOSYS; > @@ -276,9 +266,9 @@ u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) > > u32 tpm_get_random(struct udevice *dev, void *data, u32 count) > { > - if (is_tpm1(dev)) > + if (tpm_is_v1(dev)) > return tpm1_get_random(dev, data, count); > - else if (is_tpm2(dev)) > + else if (tpm_is_v2(dev)) > return -ENOSYS; /* not implemented yet */ > else > return -ENOSYS; > -- > 2.35.1.574.g5d30c73bfb-goog > Reviewed-by: Ilias Apalodimas