From patchwork Fri Jul 22 16:02:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592468 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp634779mab; Fri, 22 Jul 2022 09:02:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vgmP61upLlygEfqCffVJkN9zSgiMKmLByCEG3hyFWWCvo33k4aV/yOOh8tSC4hLFUE0et5 X-Received: by 2002:a05:6e02:1686:b0:2dc:7a0a:2f81 with SMTP id f6-20020a056e02168600b002dc7a0a2f81mr295822ila.8.1658505772094; Fri, 22 Jul 2022 09:02:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505772; cv=none; d=google.com; s=arc-20160816; b=TcwyywGiHS/5yEgoX6Hz8MBGKNHJCB8f1k+qMe33c2pTSsKrQ2XpzF3P6iHtJZnmd8 GDN9XEPDJc6dEG1vTgybx8RMqqpfsveoL5Lsuk8ddQXz9umKgefMwLnMACzZUzfS/APW hpQGzmPiqsOd5U2bB5p6W9GzmR+8W30l1NyrVYjUTWoQRf81OX7/TKBQ7fauqVXmdc9H mVuBv1cQ6/vwsaGZ6wD0monSTvJseBV/qJ67rUAvKP4f9D7rVqm7Qgaz7thMkptuVOz5 oT0n803346FA49JAMWSKiEgMoyyRhue+h3DWAYhHjOUvd3O3GY//FX9KSCQ5Z/DdRjuY lVQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=awPQbrjafUvi+OpfVNyzLyXb2M7Qlg8J3NRysQ2SIs0=; b=dqu7xHWaWpxgOkwSD7H/MfAfZxr84z0KlW9WKVlgBJqmrNEh01CrmbjVMcYCoz9cym x37ZCNv7e/9/rDnPdYMzZLAP3X91Cf9tLaA/owZDz1qg8RDQg4TkDmXXaQpsQfQClTHM Z5DHZ4yRvXa2XhCXx+wLyHKGuVvKtampulYxRPD7ys0AljPO+3Eq2fBCf7nxtRG9xoqz jHaAvGwxyzgrJS+q9G034S+N6WVE/ZgrLrZB3eb0H2FUVThnj5jMR9Ju4OWvpgWBKA+3 vQU03OHz5aJFMkKrChbIez7JP4XiS+UI7ugcuE0pY64Qw8JFuo+0WBN+IZo2kYb06Kjl yMEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id k44-20020a056638372c00b0033cbd707ab1si5492732jav.10.2022.07.22.09.02.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:02:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4CCB783FA0; Fri, 22 Jul 2022 18:02:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 6A08B83F9B; Fri, 22 Jul 2022 18:02:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id D44FC83AC3 for ; Fri, 22 Jul 2022 18:02:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68A23106F; Fri, 22 Jul 2022 09:02:30 -0700 (PDT) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E519A3F73D; Fri, 22 Jul 2022 09:02:27 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini Subject: [PATCH v8 1/8] tpm: Export the TPM-version functions Date: Fri, 22 Jul 2022 21:32:02 +0530 Message-Id: <20220722160209.863840-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 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.6 at phobos.denx.de X-Virus-Status: Clean From: Simon Glass 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 Reviewed-by: Ilias Apalodimas --- Changes since V7: None 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;