security/tpm: make tis_probe() return tpm_family

Via an out parameter. This is needed to be able to dynamically pick TSS
implementation based on the information discovered on probing.

Change-Id: I5006e0cdfef76ff79ce9e1cf280fcd5515ae01b0
Ticket: https://ticket.coreboot.org/issues/433
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/69159
Reviewed-by: Martin L Roth <gaumless@gmail.com>
Reviewed-by: Jérémy Compostella <jeremy.compostella@intel.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Christian Walter <christian.walter@9elements.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Sergii Dmytruk 2022-10-31 15:30:15 +02:00 committed by Martin L Roth
commit febf9b9f24
11 changed files with 99 additions and 31 deletions

View file

@ -32,6 +32,12 @@ enum tis_status {
TPM_STS_RESPONSE_RETRY = (1 << 1),
};
enum tpm_family {
TPM_UNKNOWN = 0,
TPM_1 = 1,
TPM_2 = 2,
};
/*
* tis_sendrecv()
*
@ -50,13 +56,16 @@ typedef tpm_result_t (*tis_sendrecv_fn)(const u8 *sendbuf, size_t send_size, u8
/*
* tis_probe()
*
* Probe for the TPM device and set it up for use within locality 0. Returns
* pointer to send-receive function on success or NULL on failure.
* Probe for the TPM device and set it up for use within locality 0.
*
* @family - pointer which is set to TPM family of the device
*
* Returns pointer to send-receive function on success or NULL on failure.
*
* Do not call this explicitly, it's meant to be used exclusively by TSS
* implementation (tlcl_lib_init() function to be specific).
*/
tis_sendrecv_fn tis_probe(void);
tis_sendrecv_fn tis_probe(enum tpm_family *family);
/*
* tis_vendor_write()

View file

@ -153,13 +153,20 @@ static tpm_result_t send(const uint8_t *command)
tpm_result_t tlcl_lib_init(void)
{
enum tpm_family family;
if (tis_sendrecv != NULL)
return TPM_SUCCESS;
tis_sendrecv = tis_probe();
tis_sendrecv = tis_probe(&family);
if (tis_sendrecv == NULL)
return TPM_CB_NO_DEVICE;
if (family != TPM_1) {
tis_sendrecv = NULL;
return TPM_CB_INTERNAL_INCONSISTENCY;
}
return TPM_SUCCESS;
}

View file

@ -211,15 +211,24 @@ tpm_result_t tlcl_clear_control(bool disable)
/* This function is called directly by vboot, uses vboot return types. */
tpm_result_t tlcl_lib_init(void)
{
enum tpm_family family;
if (tis_sendrecv != NULL)
return TPM_SUCCESS;
tis_sendrecv = tis_probe();
tis_sendrecv = tis_probe(&family);
if (tis_sendrecv == NULL) {
printk(BIOS_ERR, "%s: tis_probe returned error\n", __func__);
return TPM_CB_NO_DEVICE;
}
if (family != TPM_2) {
tis_sendrecv = NULL;
printk(BIOS_ERR, "%s: tis_probe returned unsupported TPM family: %d\n",
__func__, family);
return TPM_CB_INTERNAL_INCONSISTENCY;
}
return TPM_SUCCESS;
}