Sergii Dmytruk | 094a051 | 2022-10-31 18:41:52 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <security/tpm/tis.h> |
| 5 | #include <security/tpm/tss.h> |
| 6 | |
| 7 | /* |
| 8 | * This unit is meant to dispatch to either TPM1.2 or TPM2.0 TSS implementation |
| 9 | * based on TPM family determined on probing during initialization. |
| 10 | */ |
| 11 | |
| 12 | enum tpm_family tlcl_tpm_family = TPM_UNKNOWN; |
| 13 | |
| 14 | tis_sendrecv_fn tlcl_tis_sendrecv; |
| 15 | |
| 16 | /* Probe for TPM device and choose implementation based on the returned TPM family. */ |
| 17 | tpm_result_t tlcl_lib_init(void) |
| 18 | { |
| 19 | /* Don't probe for TPM more than once per stage. */ |
| 20 | static bool init_done; |
| 21 | if (init_done) |
| 22 | return tlcl_tpm_family == TPM_UNKNOWN ? TPM_CB_NO_DEVICE : TPM_SUCCESS; |
| 23 | |
| 24 | /* Set right away to make recursion impossible. */ |
| 25 | init_done = true; |
| 26 | |
| 27 | tlcl_tis_sendrecv = tis_probe(&tlcl_tpm_family); |
| 28 | |
| 29 | if (tlcl_tis_sendrecv == NULL) { |
| 30 | printk(BIOS_ERR, "%s: tis_probe failed\n", __func__); |
| 31 | tlcl_tpm_family = TPM_UNKNOWN; |
| 32 | } else if (tlcl_tpm_family != TPM_1 && tlcl_tpm_family != TPM_2) { |
| 33 | printk(BIOS_ERR, "%s: tis_probe returned incorrect TPM family: %d\n", __func__, |
| 34 | tlcl_tpm_family); |
| 35 | tlcl_tpm_family = TPM_UNKNOWN; |
| 36 | } |
| 37 | |
| 38 | return tlcl_tpm_family == TPM_UNKNOWN ? TPM_CB_NO_DEVICE : TPM_SUCCESS; |
| 39 | } |