coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
tis.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 #include <console/console.h>
4 #include <security/tpm/tis.h>
5 
6 #include "tpm.h"
7 
8 static unsigned int tpm_is_open;
9 
10 static const struct {
13  const char *device_name;
14 } dev_map[] = {
15  { 0x15d1, 0x001b, "SLB9670" },
16  { 0x1ae0, 0x0028, "CR50" },
17  { 0x104a, 0x0000, "ST33HTPH2E32" },
18 };
19 
20 static const char *tis_get_dev_name(struct tpm2_info *info)
21 {
22  int i;
23 
24  for (i = 0; i < ARRAY_SIZE(dev_map); i++)
25  if ((dev_map[i].vid == info->vendor_id) &&
26  (dev_map[i].did == info->device_id))
27  return dev_map[i].device_name;
28  return "Unknown";
29 }
30 
31 int tis_open(void)
32 {
33  if (tpm_is_open) {
34  printk(BIOS_ERR, "%s() called twice.\n", __func__);
35  return -1;
36  }
37  return 0;
38 }
39 
40 int tis_close(void)
41 {
42  if (tpm_is_open) {
43 
44  /*
45  * Do we need to do something here, like waiting for a
46  * transaction to stop?
47  */
48  tpm_is_open = 0;
49  }
50 
51  return 0;
52 }
53 
54 int tis_init(void)
55 {
56  struct spi_slave spi;
57  struct tpm2_info info;
58 
59  if (spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS,
60  CONFIG_DRIVER_TPM_SPI_CHIP, &spi)) {
61  printk(BIOS_ERR, "Failed to setup TPM SPI slave\n");
62  return -1;
63  }
64 
65  if (tpm2_init(&spi)) {
66  printk(BIOS_ERR, "Failed to initialize TPM SPI interface\n");
67  return -1;
68  }
69 
71 
72  printk(BIOS_INFO, "Initialized TPM device %s revision %d\n",
73  tis_get_dev_name(&info), info.revision);
74 
75  return 0;
76 }
77 
78 int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
79  uint8_t *recvbuf, size_t *rbuf_len)
80 {
81  int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len);
82 
83  if (len == 0)
84  return -1;
85 
86  *rbuf_len = len;
87 
88  return 0;
89 }
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, uint8_t *recvbuf, size_t *rbuf_len)
Definition: tis.c:81
const char * device_name
Definition: tis.c:17
uint16_t vid
Definition: tis.c:15
int tis_close(void)
Definition: tis.c:51
uint16_t did
Definition: tis.c:16
int tis_open(void)
Definition: tis.c:33
int tis_init(void)
Definition: tis.c:65
int tpm2_init(void)
Definition: tpm.c:175
size_t tpm2_process_command(const void *tpm2_command, size_t command_size, void *tpm2_response, size_t max_response)
Definition: tpm.c:195
void tpm2_get_info(struct tpm2_info *tpm2_info)
Definition: tpm.c:266
static struct smmstore_params_info info
Definition: ramstage.c:12
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
int spi_setup_slave(unsigned int bus, unsigned int cs, struct spi_slave *slave)
Definition: spi-generic.c:122
static const char * tis_get_dev_name(struct tpm2_info *info)
Definition: tis.c:20
static unsigned int tpm_is_open
Definition: tis.c:8
static const struct @88 dev_map[]
unsigned short uint16_t
Definition: stdint.h:11
unsigned char uint8_t
Definition: stdint.h:8
Definition: tpm.h:54