Patrick Georgi | 593124d | 2020-05-10 19:44:08 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
Vadim Bendebury | e31d243 | 2016-04-09 18:33:49 -0700 | [diff] [blame] | 2 | |
Vadim Bendebury | e31d243 | 2016-04-09 18:33:49 -0700 | [diff] [blame] | 3 | #include <console/console.h> |
Philipp Deppenwiese | d88fb36 | 2017-10-18 20:26:18 +0200 | [diff] [blame] | 4 | #include <security/tpm/tis.h> |
Vadim Bendebury | e31d243 | 2016-04-09 18:33:49 -0700 | [diff] [blame] | 5 | |
| 6 | #include "tpm.h" |
| 7 | |
Vadim Bendebury | e31d243 | 2016-04-09 18:33:49 -0700 | [diff] [blame] | 8 | static 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 Rudolph | 7bcd9a1 | 2020-03-20 09:55:43 +0100 | [diff] [blame] | 15 | { 0x104a, 0x0000, "ST33HTPH2E32" }, |
Yidi Lin | 93447c4 | 2022-08-16 15:19:32 +0800 | [diff] [blame] | 16 | { 0x6666, 0x504a, "TI50" }, |
Vadim Bendebury | e31d243 | 2016-04-09 18:33:49 -0700 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | static 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 Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame] | 30 | static tpm_result_t tpm_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, |
| 31 | uint8_t *recvbuf, size_t *rbuf_len) |
Vadim Bendebury | e31d243 | 2016-04-09 18:33:49 -0700 | [diff] [blame] | 32 | { |
| 33 | int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len); |
Aaron Durbin | 6ef52cd | 2017-03-27 17:04:26 -0500 | [diff] [blame] | 34 | |
| 35 | if (len == 0) |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 36 | return TPM_CB_FAIL; |
Aaron Durbin | 6ef52cd | 2017-03-27 17:04:26 -0500 | [diff] [blame] | 37 | |
Vadim Bendebury | e31d243 | 2016-04-09 18:33:49 -0700 | [diff] [blame] | 38 | *rbuf_len = len; |
Aaron Durbin | 6ef52cd | 2017-03-27 17:04:26 -0500 | [diff] [blame] | 39 | |
Jon Murphy | d7b8dc9 | 2023-09-05 11:36:43 -0600 | [diff] [blame] | 40 | return TPM_SUCCESS; |
Vadim Bendebury | e31d243 | 2016-04-09 18:33:49 -0700 | [diff] [blame] | 41 | } |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame] | 42 | |
Sergii Dmytruk | 3e5cefc | 2022-11-01 00:48:43 +0200 | [diff] [blame^] | 43 | tis_sendrecv_fn spi_tis_probe(enum tpm_family *family) |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame] | 44 | { |
| 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 Dmytruk | febf9b9 | 2022-10-31 15:30:15 +0200 | [diff] [blame] | 59 | /* tpm2_process_command() is used unconditionally in tpm_sendrecv() */ |
| 60 | if (family != NULL) |
| 61 | *family = TPM_2; |
| 62 | |
Sergii Dmytruk | 963f7b9 | 2022-10-29 20:42:28 +0300 | [diff] [blame] | 63 | 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 | } |