treewide: convert to tpm_result_t

Convert TPM functions to return TPM error codes(referred to as
tpm_result_t) values to match the TCG standard.

BUG=b:296439237
TEST=build and boot to Skyrim
BRANCH=None

Change-Id: Ifdf9ff6c2a1f9b938dbb04d245799391115eb6b1
Signed-off-by: Jon Murphy <jpmurphy@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/77666
Reviewed-by: Raul Rangel <rrangel@chromium.org>
Reviewed-by: Matt DeVillier <matt.devillier@amd.corp-partner.google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Jon Murphy 2023-09-05 11:36:43 -06:00 committed by Raul Rangel
commit d7b8dc9cf5
44 changed files with 734 additions and 653 deletions

View file

@ -29,29 +29,31 @@ static const char *tis_get_dev_name(struct tpm2_info *info)
return "Unknown";
}
int tis_open(void)
tpm_result_t tis_open(void)
{
if (tpm_is_open) {
printk(BIOS_ERR, "%s() called twice.\n", __func__);
return -1;
return TPM_CB_FAIL;
}
return 0;
return TPM_SUCCESS;
}
int tis_init(void)
tpm_result_t tis_init(void)
{
struct spi_slave spi;
struct tpm2_info info;
tpm_result_t rc = TPM_SUCCESS;
if (spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS,
CONFIG_DRIVER_TPM_SPI_CHIP, &spi)) {
printk(BIOS_ERR, "Failed to setup TPM SPI slave\n");
return -1;
return TPM_CB_FAIL;
}
if (tpm2_init(&spi)) {
rc = tpm2_init(&spi);
if (rc) {
printk(BIOS_ERR, "Failed to initialize TPM SPI interface\n");
return -1;
return rc;
}
tpm2_get_info(&info);
@ -59,18 +61,18 @@ int tis_init(void)
printk(BIOS_INFO, "Initialized TPM device %s revision %d\n",
tis_get_dev_name(&info), info.revision);
return 0;
return TPM_SUCCESS;
}
int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
uint8_t *recvbuf, size_t *rbuf_len)
{
int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);
if (len == 0)
return -1;
return TPM_CB_FAIL;
*rbuf_len = len;
return 0;
return TPM_SUCCESS;
}

View file

@ -394,7 +394,7 @@ static const uint32_t supported_did_vids[] = {
0x0000104a /* ST33HTPH2E32 */
};
int tpm2_init(struct spi_slave *spi_if)
tpm_result_t tpm2_init(struct spi_slave *spi_if)
{
uint32_t did_vid, status, intf_id;
uint8_t cmd;
@ -433,7 +433,7 @@ int tpm2_init(struct spi_slave *spi_if)
if (!retries) {
printk(BIOS_ERR, "\n%s: Failed to connect to the TPM\n",
__func__);
return -1;
return TPM_CB_FAIL;
}
printk(BIOS_INFO, " done!\n");
@ -444,11 +444,11 @@ int tpm2_init(struct spi_slave *spi_if)
if (tpm2_read_reg(TPM_INTF_ID_REG, &intf_id, sizeof(intf_id)) != CB_SUCCESS) {
printk(BIOS_ERR, "\n%s: Failed to read interface ID register\n",
__func__);
return -1;
return TPM_CB_FAIL;
}
if ((be32toh(intf_id) & 0xF) == 0xF) {
printk(BIOS_DEBUG, "\n%s: Not a TPM2 device\n", __func__);
return -1;
return TPM_CB_FAIL;
}
}
@ -459,16 +459,16 @@ int tpm2_init(struct spi_slave *spi_if)
* initialization after reset.
*/
if (tpm2_claim_locality() != CB_SUCCESS)
return -1;
return TPM_CB_FAIL;
if (read_tpm_sts(&status) != CB_SUCCESS) {
printk(BIOS_ERR, "Reading status reg failed\n");
return -1;
return TPM_CB_FAIL;
}
if ((status & TPM_STS_FAMILY_MASK) != TPM_STS_FAMILY_TPM_2_0) {
printk(BIOS_ERR, "unexpected TPM family value, status: %#x\n",
status);
return -1;
return TPM_CB_FAIL;
}
/*
@ -492,7 +492,7 @@ int tpm2_init(struct spi_slave *spi_if)
cr50_set_board_cfg();
}
}
return 0;
return TPM_SUCCESS;
}
/*

View file

@ -4,6 +4,7 @@
#define __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H
#include <drivers/tpm/cr50.h>
#include <security/tpm/tss_errors.h>
#include <stddef.h>
#include <spi-generic.h>
@ -26,7 +27,7 @@ struct tpm2_info {
*
* Return 0 on success, non-zero on failure.
*/
int tpm2_init(struct spi_slave *spi_if);
tpm_result_t tpm2_init(struct spi_slave *spi_if);
/*
* Each command processing consists of sending the command to the TPM, by