blob: b954a123f0f127b6165061b4bd29e6cf58298b85 [file] [log] [blame]
Patrick Georgi593124d2020-05-10 19:44:08 +02001/* SPDX-License-Identifier: BSD-3-Clause */
Vadim Bendeburye31d2432016-04-09 18:33:49 -07002
Vadim Bendeburye31d2432016-04-09 18:33:49 -07003#include <console/console.h>
Philipp Deppenwiesed88fb362017-10-18 20:26:18 +02004#include <security/tpm/tis.h>
Vadim Bendeburye31d2432016-04-09 18:33:49 -07005
6#include "tpm.h"
7
Vadim Bendeburye31d2432016-04-09 18:33:49 -07008static const struct {
9 uint16_t vid;
10 uint16_t did;
11 const char *device_name;
12} dev_map[] = {
13 { 0x15d1, 0x001b, "SLB9670" },
14 { 0x1ae0, 0x0028, "CR50" },
Patrick Rudolph7bcd9a12020-03-20 09:55:43 +010015 { 0x104a, 0x0000, "ST33HTPH2E32" },
Yidi Lin93447c42022-08-16 15:19:32 +080016 { 0x6666, 0x504a, "TI50" },
Vadim Bendeburye31d2432016-04-09 18:33:49 -070017};
18
19static const char *tis_get_dev_name(struct tpm2_info *info)
20{
21 int i;
22
23 for (i = 0; i < ARRAY_SIZE(dev_map); i++)
24 if ((dev_map[i].vid == info->vendor_id) &&
25 (dev_map[i].did == info->device_id))
26 return dev_map[i].device_name;
27 return "Unknown";
28}
29
Sergii Dmytruk963f7b92022-10-29 20:42:28 +030030static tpm_result_t tpm_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
31 uint8_t *recvbuf, size_t *rbuf_len)
Vadim Bendeburye31d2432016-04-09 18:33:49 -070032{
33 int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);
Aaron Durbin6ef52cd2017-03-27 17:04:26 -050034
35 if (len == 0)
Jon Murphyd7b8dc92023-09-05 11:36:43 -060036 return TPM_CB_FAIL;
Aaron Durbin6ef52cd2017-03-27 17:04:26 -050037
Vadim Bendeburye31d2432016-04-09 18:33:49 -070038 *rbuf_len = len;
Aaron Durbin6ef52cd2017-03-27 17:04:26 -050039
Jon Murphyd7b8dc92023-09-05 11:36:43 -060040 return TPM_SUCCESS;
Vadim Bendeburye31d2432016-04-09 18:33:49 -070041}
Sergii Dmytruk963f7b92022-10-29 20:42:28 +030042
Sergii Dmytruk3e5cefc2022-11-01 00:48:43 +020043tis_sendrecv_fn spi_tis_probe(enum tpm_family *family)
Sergii Dmytruk963f7b92022-10-29 20:42:28 +030044{
45 struct spi_slave spi;
46 struct tpm2_info info;
47
48 if (spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS,
49 CONFIG_DRIVER_TPM_SPI_CHIP, &spi)) {
50 printk(BIOS_ERR, "Failed to setup TPM SPI slave\n");
51 return NULL;
52 }
53
54 if (tpm2_init(&spi)) {
55 printk(BIOS_ERR, "Failed to initialize TPM SPI interface\n");
56 return NULL;
57 }
58
Sergii Dmytrukfebf9b92022-10-31 15:30:15 +020059 /* tpm2_process_command() is used unconditionally in tpm_sendrecv() */
60 if (family != NULL)
61 *family = TPM_2;
62
Sergii Dmytruk963f7b92022-10-29 20:42:28 +030063 tpm2_get_info(&info);
64
65 printk(BIOS_INFO, "Initialized TPM device %s revision %d\n",
66 tis_get_dev_name(&info), info.revision);
67
68 return &tpm_sendrecv;
69}