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 <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/69022
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Sergii Dmytruk 2022-10-30 17:18:33 +02:00 committed by Felix Held
parent d43154486d
commit df853501f8
1 changed files with 16 additions and 1 deletions

View File

@ -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())
/*