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;
}
{
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;
}
{
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;
}
log_err("TPM: Can't set deactivated state\n");
return ret;
}
- } else {
- return -ENOSYS;
}
return TPM_SUCCESS;
{
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;
}
{
if (is_tpm1(dev))
return tpm1_nv_read_value(dev, index, data, count);
+ else if (is_tpm2(dev))
+ return -ENOSYS;
else
return -ENOSYS;
}
{
if (is_tpm1(dev))
return tpm1_nv_write_value(dev, index, data, count);
+ else if (is_tpm2(dev))
+ return -ENOSYS;
else
return -ENOSYS;
}
{
if (is_tpm1(dev))
return -ENOSYS;
+ else if (is_tpm2(dev))
+ return -ENOSYS;
else
return -ENOSYS;
}
{
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;
}
{
if (is_tpm1(dev))
return tpm1_pcr_read(dev, index, data, count);
+ else if (is_tpm2(dev))
+ return -ENOSYS;
else
return -ENOSYS;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}
{
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;
}