1 /* SPDX-License-Identifier: BSD-3-Clause */
3 #include <console/console.h>
4 #include <drivers/crb/tpm.h>
5 #include <drivers/i2c/tpm/tpm.h>
6 #include <drivers/pc80/tpm/tpm.h>
7 #include <drivers/spi/tpm/tpm.h>
8 #include <security/tpm/tis.h>
9 #include <security/tpm/tss.h>
12 * This unit is meant to dispatch to either TPM1.2 or TPM2.0 TSS implementation
13 * based on TPM family determined on probing during initialization.
16 enum tpm_family tlcl_tpm_family
= TPM_UNKNOWN
;
18 tis_sendrecv_fn tlcl_tis_sendrecv
;
20 /* Probe for TPM device and choose implementation based on the returned TPM family. */
21 tpm_result_t
tlcl_lib_init(void)
23 /* Don't probe for TPM more than once per stage. */
24 static bool init_done
;
26 return tlcl_tpm_family
== TPM_UNKNOWN
? TPM_CB_NO_DEVICE
: TPM_SUCCESS
;
28 /* Set right away to make recursion impossible. */
31 tlcl_tis_sendrecv
= NULL
;
33 tlcl_tis_sendrecv
= crb_tis_probe(&tlcl_tpm_family
);
34 if (CONFIG(MEMORY_MAPPED_TPM
) && tlcl_tis_sendrecv
== NULL
)
35 tlcl_tis_sendrecv
= pc80_tis_probe(&tlcl_tpm_family
);
36 if (CONFIG(I2C_TPM
) && tlcl_tis_sendrecv
== NULL
)
37 tlcl_tis_sendrecv
= i2c_tis_probe(&tlcl_tpm_family
);
38 if (CONFIG(SPI_TPM
) && tlcl_tis_sendrecv
== NULL
)
39 tlcl_tis_sendrecv
= spi_tis_probe(&tlcl_tpm_family
);
41 if (tlcl_tis_sendrecv
== NULL
) {
42 printk(BIOS_ERR
, "%s: TIS probe failed\n", __func__
);
43 tlcl_tpm_family
= TPM_UNKNOWN
;
44 } else if (tlcl_tpm_family
!= TPM_1
&& tlcl_tpm_family
!= TPM_2
) {
45 printk(BIOS_ERR
, "%s: TIS probe returned incorrect TPM family: %d\n", __func__
,
47 tlcl_tpm_family
= TPM_UNKNOWN
;
50 return tlcl_tpm_family
== TPM_UNKNOWN
? TPM_CB_NO_DEVICE
: TPM_SUCCESS
;