[PATCH v6 1/7] tpm: Export the TPM-version functions
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 --- Changes since V5: 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
Re: [PATCH v6 1/7] tpm: Export the TPM-version functions
On Mon, Jul 04, 2022 at 07:04:38PM +0530, Sughosh Ganu wrote: > 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 > --- > Changes since V5: 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_