summaryrefslogtreecommitdiff
path: root/src/drivers/spi/tpm/tis.c
blob: b954a123f0f127b6165061b4bd29e6cf58298b85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* SPDX-License-Identifier: BSD-3-Clause */

#include <console/console.h>
#include <security/tpm/tis.h>

#include "tpm.h"

static const struct {
	uint16_t vid;
	uint16_t did;
	const char *device_name;
} dev_map[] = {
	{ 0x15d1, 0x001b, "SLB9670" },
	{ 0x1ae0, 0x0028, "CR50" },
	{ 0x104a, 0x0000, "ST33HTPH2E32" },
	{ 0x6666, 0x504a, "TI50" },
};

static const char *tis_get_dev_name(struct tpm2_info *info)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(dev_map); i++)
		if ((dev_map[i].vid == info->vendor_id) &&
		    (dev_map[i].did == info->device_id))
			return dev_map[i].device_name;
	return "Unknown";
}

static tpm_result_t tpm_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
				 uint8_t *recvbuf, size_t *rbuf_len)
{
	int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);

	if (len == 0)
		return TPM_CB_FAIL;

	*rbuf_len = len;

	return TPM_SUCCESS;
}

tis_sendrecv_fn spi_tis_probe(enum tpm_family *family)
{
	struct spi_slave spi;
	struct tpm2_info info;

	if (spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS,
			    CONFIG_DRIVER_TPM_SPI_CHIP, &spi)) {
		printk(BIOS_ERR, "Failed to setup TPM SPI slave\n");
		return NULL;
	}

	if (tpm2_init(&spi)) {
		printk(BIOS_ERR, "Failed to initialize TPM SPI interface\n");
		return NULL;
	}

	/* tpm2_process_command() is used unconditionally in tpm_sendrecv() */
	if (family != NULL)
		*family = TPM_2;

	tpm2_get_info(&info);

	printk(BIOS_INFO, "Initialized TPM device %s revision %d\n",
	       tis_get_dev_name(&info), info.revision);

	return &tpm_sendrecv;
}