summaryrefslogtreecommitdiff
path: root/src/security/tpm/tss/tss.c
diff options
context:
space:
mode:
authorSergii Dmytruk <sergii.dmytruk@3mdeb.com>2022-10-31 18:41:52 +0200
committerMartin L Roth <gaumless@gmail.com>2024-03-28 15:16:19 +0000
commit094a051732341d20e82c349ea10f85faea6e58d1 (patch)
treea6da34deaf0607885577218e0fb950f1bec18034 /src/security/tpm/tss/tss.c
parentfebf9b9f24f537b88ea5d4845a8d350d94d9e295 (diff)
security/tpm: resolve conflicts in TSS implementations
No functional changes. Refactor code such that there won't be any compiler or linker errors if TSS 1.2 and TSS 2.0 were both compiled in. One might want to support both TPM families for example if TPM is pluggable, while currently one has to reflash firmware along with switching TPM device. Change-Id: Ia0ea5a917c46ada9fc3274f17240e12bca98db6a Ticket: https://ticket.coreboot.org/issues/433 Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/69160 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/security/tpm/tss/tss.c')
-rw-r--r--src/security/tpm/tss/tss.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/security/tpm/tss/tss.c b/src/security/tpm/tss/tss.c
new file mode 100644
index 0000000000..bd0e98582b
--- /dev/null
+++ b/src/security/tpm/tss/tss.c
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#include <console/console.h>
+#include <security/tpm/tis.h>
+#include <security/tpm/tss.h>
+
+/*
+ * This unit is meant to dispatch to either TPM1.2 or TPM2.0 TSS implementation
+ * based on TPM family determined on probing during initialization.
+ */
+
+enum tpm_family tlcl_tpm_family = TPM_UNKNOWN;
+
+tis_sendrecv_fn tlcl_tis_sendrecv;
+
+/* Probe for TPM device and choose implementation based on the returned TPM family. */
+tpm_result_t tlcl_lib_init(void)
+{
+ /* Don't probe for TPM more than once per stage. */
+ static bool init_done;
+ if (init_done)
+ return tlcl_tpm_family == TPM_UNKNOWN ? TPM_CB_NO_DEVICE : TPM_SUCCESS;
+
+ /* Set right away to make recursion impossible. */
+ init_done = true;
+
+ tlcl_tis_sendrecv = tis_probe(&tlcl_tpm_family);
+
+ if (tlcl_tis_sendrecv == NULL) {
+ printk(BIOS_ERR, "%s: tis_probe failed\n", __func__);
+ tlcl_tpm_family = TPM_UNKNOWN;
+ } else if (tlcl_tpm_family != TPM_1 && tlcl_tpm_family != TPM_2) {
+ printk(BIOS_ERR, "%s: tis_probe returned incorrect TPM family: %d\n", __func__,
+ tlcl_tpm_family);
+ tlcl_tpm_family = TPM_UNKNOWN;
+ }
+
+ return tlcl_tpm_family == TPM_UNKNOWN ? TPM_CB_NO_DEVICE : TPM_SUCCESS;
+}