diff options
author | Eric Richter <erichte@linux.ibm.com> | 2020-03-06 11:13:16 -0600 |
---|---|---|
committer | Oliver O'Halloran <oohall@gmail.com> | 2020-03-11 17:32:08 +1100 |
commit | c2ba08e8ec3745d9c6a917a21d81d196160fd977 (patch) | |
tree | 0ce71ca65967d2fa44e2ab2d95f7092116b9bbb6 /libstb | |
parent | a08549a9e7a4e3f5eb3dd5525097d472fc363888 (diff) | |
download | skiboot-c2ba08e8ec3745d9c6a917a21d81d196160fd977.zip skiboot-c2ba08e8ec3745d9c6a917a21d81d196160fd977.tar.gz skiboot-c2ba08e8ec3745d9c6a917a21d81d196160fd977.tar.bz2 |
tpm_i2c_nuvoton: check TPM vendor id register during probe
The driver for the nuvoton i2c TPM does not currently check if there is
a functional TPM at the bus and address given by the device tree.
This patch adds a simple check of the TPM vendor id register, compares
against the known expected value for the chip, skips registering it if
the chip is inaccessible or returns an unexpected id.
Signed-off-by: Eric Richter <erichte@linux.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Diffstat (limited to 'libstb')
-rw-r--r-- | libstb/drivers/tpm_i2c_nuvoton.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libstb/drivers/tpm_i2c_nuvoton.c b/libstb/drivers/tpm_i2c_nuvoton.c index d668000..2348e82 100644 --- a/libstb/drivers/tpm_i2c_nuvoton.c +++ b/libstb/drivers/tpm_i2c_nuvoton.c @@ -30,6 +30,7 @@ #define TPM_BURST_COUNT 0x01 #define TPM_DATA_FIFO_W 0x20 #define TPM_DATA_FIFO_R 0x40 +#define TPM_VID_DID 0x60 /* Bit masks for the TPM STATUS register */ #define TPM_STS_VALID 0x80 @@ -42,6 +43,8 @@ /* TPM Driver values */ #define MAX_STSVALID_POLLS 5 #define TPM_TIMEOUT_INTERVAL 10 +#define TPM_NUVOTON_VID 0x5010FE00 +#define TPM_VENDOR_ID_MASK 0xFFFFFF00 static struct tpm_dev *tpm_device = NULL; @@ -553,6 +556,7 @@ void tpm_i2c_nuvoton_probe(void) struct dt_node *node = NULL; struct i2c_bus *bus; const char *name; + uint32_t vendor = 0; dt_for_each_compatible(dt_root, node, "nuvoton,npct650") { if (!dt_node_is_enabled(node)) @@ -589,6 +593,16 @@ void tpm_i2c_nuvoton_probe(void) "found, tpm node parent %p\n", node->parent); goto disable; } + /* ensure there's really the TPM we expect at that address */ + if (tpm_i2c_request_send(tpm_device, SMBUS_READ, TPM_VID_DID, + 1, &vendor, sizeof(vendor))) { + prlog(PR_ERR, "NUVOTON: i2c device inaccessible\n"); + goto disable; + } + if ((vendor & TPM_VENDOR_ID_MASK) != TPM_NUVOTON_VID) { + prlog(PR_ERR, "NUVOTON: expected vendor id mismatch\n"); + goto disable; + } if (tpm_register_chip(node, tpm_device, &tpm_i2c_nuvoton_driver)) { free(tpm_device); |