From df853501f854f8e6cfc989b0881026331940cf30 Mon Sep 17 00:00:00 2001 From: Sergii Dmytruk Date: Sun, 30 Oct 2022 17:18:33 +0200 Subject: drivers/spi/tpm: verify device supports TPM2 This is to handle the situation when device ID is the same for TPM1 and TPM2 versions of a device. Change-Id: Ib2840a21b3be8928d39570281f86a0e26b38b5f9 Ticket: https://ticket.coreboot.org/issues/433 Signed-off-by: Sergii Dmytruk Reviewed-on: https://review.coreboot.org/c/coreboot/+/69022 Reviewed-by: Julius Werner Tested-by: build bot (Jenkins) --- src/drivers/spi/tpm/tpm.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/drivers') diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c index 68f9588d53..976a8d894e 100644 --- a/src/drivers/spi/tpm/tpm.c +++ b/src/drivers/spi/tpm/tpm.c @@ -28,6 +28,7 @@ #define TPM_ACCESS_REG (TPM_LOCALITY_0_SPI_BASE + 0) #define TPM_STS_REG (TPM_LOCALITY_0_SPI_BASE + 0x18) #define TPM_DATA_FIFO_REG (TPM_LOCALITY_0_SPI_BASE + 0x24) +#define TPM_INTF_ID_REG (TPM_LOCALITY_0_SPI_BASE + 0x30) #define TPM_DID_VID_REG (TPM_LOCALITY_0_SPI_BASE + 0xf00) #define TPM_RID_REG (TPM_LOCALITY_0_SPI_BASE + 0xf04) #define TPM_FW_VER (TPM_LOCALITY_0_SPI_BASE + 0xf90) @@ -412,7 +413,7 @@ static const uint32_t supported_did_vids[] = { int tpm2_init(struct spi_slave *spi_if) { - uint32_t did_vid, status; + uint32_t did_vid, status, intf_id; uint8_t cmd; int retries; @@ -454,6 +455,20 @@ int tpm2_init(struct spi_slave *spi_if) printk(BIOS_INFO, " done!\n"); + /* Google TPMs haven't always been 100% accurate in reflecting the spec (particularly + * on older versions) and are always TPM 2.0. */ + if (!CONFIG(TPM_GOOGLE)) { + 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; + } + if ((be32toh(intf_id) & 0xF) == 0xF) { + printk(BIOS_DEBUG, "\n%s: Not a TPM2 device\n", __func__); + return -1; + } + } + // FIXME: Move this to tpm_setup() if (tpm_first_access_this_boot()) /* -- cgit v1.2.3