coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
tpm.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* This is a driver for a SPI interfaced TPM2 device.
3  *
4  * It assumes that the required SPI interface has been initialized before the
5  * driver is started. A 'sruct spi_slave' pointer passed at initialization is
6  * used to direct traffic to the correct SPI interface. This driver does not
7  * provide a way to instantiate multiple TPM devices. Also, to keep things
8  * simple, the driver unconditionally uses of TPM locality zero.
9  *
10  * References to documentation are based on the TCG issued "TPM Profile (PTP)
11  * Specification Revision 00.43".
12  */
13 
14 #include <assert.h>
15 #include <commonlib/endian.h>
16 #include <console/console.h>
17 #include <delay.h>
18 #include <endian.h>
19 #include <security/tpm/tis.h>
20 #include <string.h>
21 #include <timer.h>
22 #include <types.h>
23 
24 #include "tpm.h"
25 
26 /* Assorted TPM2 registers for interface type FIFO. */
27 #define TPM_ACCESS_REG (TPM_LOCALITY_0_SPI_BASE + 0)
28 #define TPM_STS_REG (TPM_LOCALITY_0_SPI_BASE + 0x18)
29 #define TPM_DATA_FIFO_REG (TPM_LOCALITY_0_SPI_BASE + 0x24)
30 #define TPM_DID_VID_REG (TPM_LOCALITY_0_SPI_BASE + 0xf00)
31 #define TPM_RID_REG (TPM_LOCALITY_0_SPI_BASE + 0xf04)
32 #define TPM_FW_VER (TPM_LOCALITY_0_SPI_BASE + 0xf90)
33 #define CR50_BOARD_CFG (TPM_LOCALITY_0_SPI_BASE + 0xfe0)
34 
35 #define CR50_TIMEOUT_INIT_MS 30000 /* Very long timeout for TPM init */
36 
37 /* SPI slave structure for TPM device. */
38 static struct spi_slave spi_slave;
39 
40 /* Cached TPM device identification. */
41 static struct tpm2_info tpm_info;
42 
43 /*
44  * TODO(vbendeb): make CONFIG(DEBUG_TPM) an int to allow different level of
45  * debug traces. Right now it is either 0 or 1.
46  */
47 static const int debug_level_ = CONFIG(DEBUG_TPM);
48 
49 /*
50  * SPI frame header for TPM transactions is 4 bytes in size, it is described
51  * in section "6.4.6 Spi Bit Protocol".
52  */
53 typedef struct {
54  unsigned char body[4];
56 
58 {
59  *info = tpm_info;
60 }
61 
63 {
64  static int warning_displayed;
65 
66  if (!warning_displayed) {
67  printk(BIOS_WARNING, "%s() not implemented, wasting 10ms to wait on"
68  " Cr50!\n", __func__);
69  warning_displayed = 1;
70  }
71  mdelay(10);
72 
73  return 1;
74 }
75 
76 /*
77  * TPM may trigger a IRQ after finish processing previous transfer.
78  * Waiting for this IRQ to sync TPM status.
79  */
80 static enum cb_err tpm_sync(void)
81 {
82  struct stopwatch sw;
83 
85  while (!tis_plat_irq_status()) {
86  if (stopwatch_expired(&sw))
87  return CB_ERR;
88  }
89 
90  return CB_SUCCESS;
91 }
92 
93 /*
94  * Each TPM2 SPI transaction starts the same: CS is asserted, the 4 byte
95  * header is sent to the TPM, the master waits til TPM is ready to continue.
96  */
97 static enum cb_err start_transaction(int read_write, size_t bytes, unsigned int addr)
98 {
99  spi_frame_header header, header_resp;
100  uint8_t byte;
101  int i;
102  int ret;
103  struct stopwatch sw;
104  static int tpm_sync_needed;
105  static struct stopwatch wake_up_sw;
106 
107  if (CONFIG(TPM_GOOGLE)) {
108  /*
109  * First Cr50 access in each coreboot stage where TPM is used will be
110  * prepended by a wake up pulse on the CS line.
111  */
112  int wakeup_needed = 1;
113 
114  /* Wait for TPM to finish previous transaction if needed */
115  if (tpm_sync_needed) {
116  if (tpm_sync() != CB_SUCCESS)
117  printk(BIOS_ERR, "Timeout waiting for TPM IRQ!\n");
118 
119  /*
120  * During the first invocation of this function on each stage
121  * this if () clause code does not run (as tpm_sync_needed
122  * value is zero), during all following invocations the
123  * stopwatch below is guaranteed to be started.
124  */
125  if (!stopwatch_expired(&wake_up_sw))
126  wakeup_needed = 0;
127  } else {
128  tpm_sync_needed = 1;
129  }
130 
131  if (wakeup_needed) {
132  /* Just in case Cr50 is asleep. */
134  udelay(1);
136  udelay(100);
137  }
138 
139  /*
140  * The Cr50 on H1 does not go to sleep for 1 second after any
141  * SPI slave activity, let's be conservative and limit the
142  * window to 900 ms.
143  */
144  stopwatch_init_msecs_expire(&wake_up_sw, 900);
145  }
146 
147  /*
148  * The first byte of the frame header encodes the transaction type
149  * (read or write) and transfer size (set to length - 1), limited to
150  * 64 bytes.
151  */
152  header.body[0] = (read_write ? 0x80 : 0) | 0x40 | (bytes - 1);
153 
154  /* The rest of the frame header is the TPM register address. */
155  for (i = 0; i < 3; i++)
156  header.body[i + 1] = (addr >> (8 * (2 - i))) & 0xff;
157 
158  /* CS assert wakes up the slave. */
160 
161  /*
162  * The TCG TPM over SPI specification introduces the notion of SPI
163  * flow control (Section "6.4.5 Flow Control").
164  *
165  * Again, the slave (TPM device) expects each transaction to start
166  * with a 4 byte header trasmitted by master. The header indicates if
167  * the master needs to read or write a register, and the register
168  * address.
169  *
170  * If the slave needs to stall the transaction (for instance it is not
171  * ready to send the register value to the master), it sets the MOSI
172  * line to 0 during the last clock of the 4 byte header. In this case
173  * the master is supposed to start polling the SPI bus, one byte at
174  * time, until the last bit in the received byte (transferred during
175  * the last clock of the byte) is set to 1.
176  *
177  * Due to some SPI controllers' shortcomings (Rockchip comes to
178  * mind...) we transmit the 4 byte header without checking the byte
179  * transmitted by the TPM during the transaction's last byte.
180  *
181  * We know that cr50 is guaranteed to set the flow control bit to 0
182  * during the header transfer. Real TPM2 are fast enough to not require
183  * to stall the master. They might still use this feature, so test the
184  * last bit after shifting in the address bytes.
185  * crosbug.com/p/52132 has been opened to track this.
186  */
187 
188  header_resp.body[3] = 0;
189  if (CONFIG(TPM_GOOGLE))
190  ret = spi_xfer(&spi_slave, header.body, sizeof(header.body), NULL, 0);
191  else
192  ret = spi_xfer(&spi_slave, header.body, sizeof(header.body),
193  header_resp.body, sizeof(header_resp.body));
194  if (ret) {
195  printk(BIOS_ERR, "SPI-TPM: transfer error\n");
197  return CB_ERR;
198  }
199 
200  if (header_resp.body[3] & 1)
201  return CB_SUCCESS;
202 
203  /*
204  * Now poll the bus until TPM removes the stall bit. Give it up to 100
205  * ms to sort it out - it could be saving stuff in nvram at some point.
206  */
207  stopwatch_init_msecs_expire(&sw, 100);
208  do {
209  if (stopwatch_expired(&sw)) {
210  printk(BIOS_ERR, "TPM flow control failure\n");
212  return CB_ERR;
213  }
214  spi_xfer(&spi_slave, NULL, 0, &byte, 1);
215  } while (!(byte & 1));
216 
217  return CB_SUCCESS;
218 }
219 
220 /*
221  * Print out the contents of a buffer, if debug is enabled. Skip registers
222  * other than FIFO, unless debug_level_ is 2.
223  */
224 static void trace_dump(const char *prefix, uint32_t reg,
225  size_t bytes, const uint8_t *buffer,
226  int force)
227 {
228  static char prev_prefix;
229  static unsigned int prev_reg;
230  static int current_char;
231  const int BYTES_PER_LINE = 32;
232 
233  if (!force) {
234  if (!debug_level_)
235  return;
236 
237  if ((debug_level_ < 2) && (reg != TPM_DATA_FIFO_REG))
238  return;
239  }
240 
241  /*
242  * Do not print register address again if the last dump print was for
243  * that register.
244  */
245  if (prev_prefix != *prefix || (prev_reg != reg)) {
246  prev_prefix = *prefix;
247  prev_reg = reg;
248  printk(BIOS_DEBUG, "\n%s %2.2x:", prefix, reg);
249  current_char = 0;
250  }
251 
252  if ((reg != TPM_DATA_FIFO_REG) && (bytes == 4)) {
253  /*
254  * This must be a regular register address, print the 32 bit
255  * value.
256  */
257  printk(BIOS_DEBUG, " %8.8x", *(const uint32_t *)buffer);
258  } else {
259  int i;
260 
261  /*
262  * Data read from or written to FIFO or not in 4 byte
263  * quantiites is printed byte at a time.
264  */
265  for (i = 0; i < bytes; i++) {
266  if (current_char &&
267  !(current_char % BYTES_PER_LINE)) {
268  printk(BIOS_DEBUG, "\n ");
269  current_char = 0;
270  }
271  (current_char)++;
272  printk(BIOS_DEBUG, " %2.2x", buffer[i]);
273  }
274  }
275 }
276 
277 /*
278  * Once transaction is initiated and the TPM indicated that it is ready to go,
279  * write the actual bytes to the register.
280  */
281 static void write_bytes(const void *buffer, size_t bytes)
282 {
283  spi_xfer(&spi_slave, buffer, bytes, NULL, 0);
284 }
285 
286 /*
287  * Once transaction is initiated and the TPM indicated that it is ready to go,
288  * read the actual bytes from the register.
289  */
290 static void read_bytes(void *buffer, size_t bytes)
291 {
292  spi_xfer(&spi_slave, NULL, 0, buffer, bytes);
293 }
294 
295 /*
296  * To write a register, start transaction, transfer data to the TPM, deassert
297  * CS when done.
298  */
299 static enum cb_err tpm2_write_reg(unsigned int reg_number, const void *buffer, size_t bytes)
300 {
301  trace_dump("W", reg_number, bytes, buffer, 0);
302  if (start_transaction(false, bytes, reg_number) != CB_SUCCESS)
303  return CB_ERR;
304  write_bytes(buffer, bytes);
306  return CB_SUCCESS;
307 }
308 
309 /*
310  * To read a register, start transaction, transfer data from the TPM, deassert
311  * CS when done.
312  *
313  * In case of failure zero out the user buffer.
314  */
315 static enum cb_err tpm2_read_reg(unsigned int reg_number, void *buffer, size_t bytes)
316 {
317  if (start_transaction(true, bytes, reg_number) != CB_SUCCESS) {
318  memset(buffer, 0, bytes);
319  return CB_ERR;
320  }
321  read_bytes(buffer, bytes);
323  trace_dump("R", reg_number, bytes, buffer, 0);
324  return CB_SUCCESS;
325 }
326 
327 /*
328  * Status register is accessed often, wrap reading and writing it into
329  * dedicated functions.
330  */
331 static enum cb_err read_tpm_sts(uint32_t *status)
332 {
333  return tpm2_read_reg(TPM_STS_REG, status, sizeof(*status));
334 }
335 
336 static enum cb_err __must_check write_tpm_sts(uint32_t status)
337 {
338  return tpm2_write_reg(TPM_STS_REG, &status, sizeof(status));
339 }
340 
341 /*
342  * The TPM may limit the transaction bytes count (burst count) below the 64
343  * bytes max. The current value is available as a field of the status
344  * register.
345  */
347 {
348  uint32_t status;
349 
350  read_tpm_sts(&status);
352 }
353 
355 {
356  uint8_t access;
357  tpm2_read_reg(TPM_ACCESS_REG, &access, sizeof(access));
358  /* We do not care about access establishment bit state. Ignore it. */
359  return access & ~TPM_ACCESS_ESTABLISHMENT;
360 }
361 
363 {
364  /* Writes to access register can set only 1 bit at a time. */
365  assert (!(cmd & (cmd - 1)));
366 
367  tpm2_write_reg(TPM_ACCESS_REG, &cmd, sizeof(cmd));
368 }
369 
370 static enum cb_err tpm2_claim_locality(void)
371 {
372  uint8_t access;
373  struct stopwatch sw;
374 
375  /*
376  * Locality is released by TPM reset.
377  *
378  * If locality is taken at this point, this could be due to the fact
379  * that the TPM is performing a long operation and has not processed
380  * reset request yet. We'll wait up to CR50_TIMEOUT_INIT_MS and see if
381  * it releases locality when reset is processed.
382  */
384  do {
385  access = tpm2_read_access_reg();
386  if (access & TPM_ACCESS_ACTIVE_LOCALITY) {
387  /*
388  * Don't bombard the chip with traffic, let it keep
389  * processing the command.
390  */
391  mdelay(2);
392  continue;
393  }
394 
395  /*
396  * Ok, the locality is free, TPM must be reset, let's claim
397  * it.
398  */
399 
401  access = tpm2_read_access_reg();
402  if (access != (TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY)) {
403  break;
404  }
405 
406  printk(BIOS_INFO, "TPM ready after %ld ms\n",
408 
409  return CB_SUCCESS;
410  } while (!stopwatch_expired(&sw));
411 
413  "Failed to claim locality 0 after %ld ms, status: %#x\n",
414  stopwatch_duration_msecs(&sw), access);
415 
416  return CB_ERR;
417 }
418 
419 /* Device/vendor ID values of the TPM devices this driver supports. */
420 static const uint32_t supported_did_vids[] = {
421  0x00281ae0, /* H1 based Cr50 security chip. */
422  0x504a6666, /* H1D3C based Ti50 security chip. */
423  0x0000104a /* ST33HTPH2E32 */
424 };
425 
426 int tpm2_init(struct spi_slave *spi_if)
427 {
428  uint32_t did_vid, status;
429  uint8_t cmd;
430  int retries;
431 
432  memcpy(&spi_slave, spi_if, sizeof(*spi_if));
433 
434  /* clear any pending IRQs */
436 
437  /*
438  * 150 ms should be enough to synchronize with the TPM even under the
439  * worst nested reset request conditions. In vast majority of cases
440  * there would be no wait at all.
441  */
442  printk(BIOS_INFO, "Probing TPM: ");
443  for (retries = 15; retries > 0; retries--) {
444  int i;
445 
446  /* In case of failure to read div_vid is set to zero. */
447  tpm2_read_reg(TPM_DID_VID_REG, &did_vid, sizeof(did_vid));
448 
449  for (i = 0; i < ARRAY_SIZE(supported_did_vids); i++)
450  if (did_vid == supported_did_vids[i])
451  break; /* TPM is up and ready. */
452 
454  break;
455 
456  /* TPM might be resetting, let's retry in a bit. */
457  mdelay(10);
458  printk(BIOS_INFO, ".");
459  }
460 
461  if (!retries) {
462  printk(BIOS_ERR, "\n%s: Failed to connect to the TPM\n",
463  __func__);
464  return -1;
465  }
466 
467  printk(BIOS_INFO, " done!\n");
468 
469  // FIXME: Move this to tpm_setup()
471  /*
472  * Claim locality 0, do it only during the first
473  * initialization after reset.
474  */
476  return -1;
477 
478  if (read_tpm_sts(&status) != CB_SUCCESS) {
479  printk(BIOS_ERR, "Reading status reg failed\n");
480  return -1;
481  }
482  if ((status & TPM_STS_FAMILY_MASK) != TPM_STS_FAMILY_TPM_2_0) {
483  printk(BIOS_ERR, "unexpected TPM family value, status: %#x\n",
484  status);
485  return -1;
486  }
487 
488  /*
489  * Locality claimed, read the revision value and set up the tpm_info
490  * structure.
491  */
492  tpm2_read_reg(TPM_RID_REG, &cmd, sizeof(cmd));
493  tpm_info.vendor_id = did_vid & 0xffff;
494  tpm_info.device_id = did_vid >> 16;
495  tpm_info.revision = cmd;
496 
497  printk(BIOS_INFO, "Connected to device vid:did:rid of %4.4x:%4.4x:%2.2x\n",
499 
500  /* Do some GSC-specific things here. */
501  if (CONFIG(TPM_GOOGLE)) {
503  /* This is called for the side-effect of printing the firmware version
504  string */
507  }
508  }
509  return 0;
510 }
511 
512 /*
513  * This is in seconds, certain TPM commands, like key generation, can take
514  * long time to complete.
515  */
516 #define MAX_STATUS_TIMEOUT 120
517 static enum cb_err wait_for_status(uint32_t status_mask, uint32_t status_expected)
518 {
519  uint32_t status;
520  struct stopwatch sw;
521 
523  do {
524  udelay(1000);
525  if (stopwatch_expired(&sw)) {
526  printk(BIOS_ERR, "failed to get expected status %x\n",
527  status_expected);
528  return CB_ERR;
529  }
530  read_tpm_sts(&status);
531  } while ((status & status_mask) != status_expected);
532 
533  return CB_SUCCESS;
534 }
535 
538  fifo_receive = 1
539 };
540 
541 /* Union allows to avoid casting away 'const' on transmit buffers. */
545 };
546 
547 /*
548  * Transfer requested number of bytes to or from TPM FIFO, accounting for the
549  * current burst count value.
550  */
551 static enum cb_err __must_check fifo_transfer(size_t transfer_size,
553  enum fifo_transfer_direction direction)
554 {
555  size_t transaction_size;
556  size_t burst_count;
557  size_t handled_so_far = 0;
558 
559  do {
560  do {
561  /* Could be zero when TPM is busy. */
562  burst_count = get_burst_count();
563  } while (!burst_count);
564 
565  transaction_size = transfer_size - handled_so_far;
566  transaction_size = MIN(transaction_size, burst_count);
567 
568  /*
569  * The SPI frame header does not allow to pass more than 64
570  * bytes.
571  */
572  transaction_size = MIN(transaction_size, 64);
573 
574  if (direction == fifo_receive) {
576  buffer.rx_buffer + handled_so_far,
577  transaction_size) != CB_SUCCESS)
578  return CB_ERR;
579  } else {
581  buffer.tx_buffer + handled_so_far,
582  transaction_size) != CB_SUCCESS)
583  return CB_ERR;
584  }
585 
586  handled_so_far += transaction_size;
587 
588  } while (handled_so_far != transfer_size);
589 
590  return CB_SUCCESS;
591 }
592 
593 size_t tpm2_process_command(const void *tpm2_command, size_t command_size,
594  void *tpm2_response, size_t max_response)
595 {
596  uint32_t status;
597  uint32_t expected_status_bits;
598  size_t payload_size;
599  size_t bytes_to_go;
600  const uint8_t *cmd_body = tpm2_command;
601  uint8_t *rsp_body = tpm2_response;
602  union fifo_transfer_buffer fifo_buffer;
603  const int HEADER_SIZE = 6;
604 
605  /* Do not try using an uninitialized TPM. */
606  if (!tpm_info.vendor_id)
607  return 0;
608 
609  /* Skip the two byte tag, read the size field. */
610  payload_size = read_be32(cmd_body + 2);
611 
612  /* Sanity check. */
613  if (payload_size != command_size) {
615  "Command size mismatch: encoded %zd != requested %zd\n",
616  payload_size, command_size);
617  trace_dump("W", TPM_DATA_FIFO_REG, command_size, cmd_body, 1);
618  printk(BIOS_DEBUG, "\n");
619  return 0;
620  }
621 
622  /* Let the TPM know that the command is coming. */
624  printk(BIOS_ERR, "TPM_STS_COMMAND_READY failed\n");
625  return 0;
626  }
627 
628  /*
629  * TPM commands and responses written to and read from the FIFO
630  * register (0x24) are datagrams of variable size, prepended by a 6
631  * byte header.
632  *
633  * The specification description of the state machine is a bit vague,
634  * but from experience it looks like there is no need to wait for the
635  * sts.expect bit to be set, at least with the 9670 and cr50 devices.
636  * Just write the command into FIFO, making sure not to exceed the
637  * burst count or the maximum PDU size, whatever is smaller.
638  */
639  fifo_buffer.tx_buffer = cmd_body;
640  if (fifo_transfer(command_size, fifo_buffer, fifo_transmit) != CB_SUCCESS) {
641  printk(BIOS_ERR, "fifo_transfer %zd command bytes failed\n",
642  command_size);
643  return 0;
644  }
645 
646  /* Now tell the TPM it can start processing the command. */
648  printk(BIOS_ERR, "TPM_STS_GO failed\n");
649  return 0;
650  }
651 
652  /* Now wait for it to report that the response is ready. */
653  expected_status_bits = TPM_STS_VALID | TPM_STS_DATA_AVAIL;
654  if (wait_for_status(expected_status_bits, expected_status_bits) != CB_SUCCESS) {
655  /*
656  * If timed out, which should never happen, let's at least
657  * print out the offending command.
658  */
659  trace_dump("W", TPM_DATA_FIFO_REG, command_size, cmd_body, 1);
660  printk(BIOS_DEBUG, "\n");
661  return 0;
662  }
663 
664  /*
665  * The response is ready, let's read it. First we read the FIFO
666  * payload header, to see how much data to expect. The response header
667  * size is fixed to six bytes, the total payload size is stored in
668  * network order in the last four bytes.
669  */
670  tpm2_read_reg(TPM_DATA_FIFO_REG, rsp_body, HEADER_SIZE);
671 
672  /* Find out the total payload size, skipping the two byte tag. */
673  payload_size = read_be32(rsp_body + 2);
674 
675  if (payload_size > max_response) {
676  /*
677  * TODO(vbendeb): at least drain the FIFO here or somehow let
678  * the TPM know that the response can be dropped.
679  */
680  printk(BIOS_ERR, " TPM response too long (%zd bytes)",
681  payload_size);
682  return 0;
683  }
684 
685  /*
686  * Now let's read all but the last byte in the FIFO to make sure the
687  * status register is showing correct flow control bits: 'more data'
688  * until the last byte and then 'no more data' once the last byte is
689  * read.
690  */
691  bytes_to_go = payload_size - 1 - HEADER_SIZE;
692  fifo_buffer.rx_buffer = rsp_body + HEADER_SIZE;
693  if (fifo_transfer(bytes_to_go, fifo_buffer, fifo_receive) != CB_SUCCESS) {
694  printk(BIOS_ERR, "fifo_transfer %zd receive bytes failed\n",
695  bytes_to_go);
696  return 0;
697  }
698 
699  /* Verify that there is still data to read. */
700  read_tpm_sts(&status);
701  if ((status & expected_status_bits) != expected_status_bits) {
702  printk(BIOS_ERR, "unexpected intermediate status %#x\n",
703  status);
704  return 0;
705  }
706 
707  /* Read the last byte of the PDU. */
708  tpm2_read_reg(TPM_DATA_FIFO_REG, rsp_body + payload_size - 1, 1);
709 
710  /* Terminate the dump, if enabled. */
711  if (debug_level_)
712  printk(BIOS_DEBUG, "\n");
713 
714  /* Verify that 'data available' is not asseretd any more. */
715  read_tpm_sts(&status);
716  if ((status & expected_status_bits) != TPM_STS_VALID) {
717  printk(BIOS_ERR, "unexpected final status %#x\n", status);
718  return 0;
719  }
720 
721  /* Move the TPM back to idle state. */
723  printk(BIOS_ERR, "TPM_STS_COMMAND_READY failed\n");
724  return 0;
725  }
726 
727  return payload_size;
728 }
729 
730 enum cb_err tis_vendor_write(unsigned int addr, const void *buffer, size_t bytes)
731 {
732  return tpm2_write_reg(addr, buffer, bytes);
733 }
734 
735 enum cb_err tis_vendor_read(unsigned int addr, void *buffer, size_t bytes)
736 {
737  return tpm2_read_reg(addr, buffer, bytes);
738 }
struct arm64_kernel_header header
Definition: fit_payload.c:30
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
void * memset(void *dstpp, int c, size_t len)
Definition: memset.c:12
#define assert(statement)
Definition: assert.h:74
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define MIN(a, b)
Definition: helpers.h:37
cb_err
coreboot error codes
Definition: cb_err.h:15
@ CB_ERR
Generic error code.
Definition: cb_err.h:17
@ CB_SUCCESS
Call completed successfully.
Definition: cb_err.h:16
static u32 addr
Definition: cirrus.c:14
static uint32_t read_be32(const void *src)
Definition: endian.h:85
#define printk(level,...)
Definition: stdlib.h:16
#define __must_check
Definition: compiler.h:23
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
void mdelay(unsigned int msecs)
Definition: delay.c:2
static struct smmstore_params_info info
Definition: ramstage.c:12
enum cb_err cr50_get_firmware_version(struct cr50_firmware_version *version)
Definition: cr50.c:186
enum cb_err cr50_set_board_cfg(void)
Set the BOARD_CFG register on the TPM chip to a particular compile-time constant value.
Definition: cr50.c:100
@ CONFIG
Definition: dsi_common.h:201
static int stopwatch_expired(struct stopwatch *sw)
Definition: timer.h:152
static long stopwatch_duration_msecs(struct stopwatch *sw)
Definition: timer.h:182
static void stopwatch_init_msecs_expire(struct stopwatch *sw, long ms)
Definition: timer.h:133
static void stopwatch_init_usecs_expire(struct stopwatch *sw, long us)
Definition: timer.h:127
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
u8 buffer[C2P_BUFFER_MAXSIZE]
Definition: psp_smm.c:18
const struct smm_save_state_ops *legacy_ops __weak
Definition: save_state.c:8
int spi_claim_bus(const struct spi_slave *slave)
Definition: spi-generic.c:9
int spi_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)
Definition: spi-generic.c:68
void spi_release_bus(const struct spi_slave *slave)
Definition: spi-generic.c:17
static void write_bytes(const void *buffer, size_t bytes)
Definition: tpm.c:281
static uint32_t get_burst_count(void)
Definition: tpm.c:346
#define CR50_TIMEOUT_INIT_MS
Definition: tpm.c:35
fifo_transfer_direction
Definition: tpm.c:536
@ fifo_transmit
Definition: tpm.c:537
@ fifo_receive
Definition: tpm.c:538
#define TPM_STS_REG
Definition: tpm.c:28
static enum cb_err tpm_sync(void)
Definition: tpm.c:80
static enum cb_err tpm2_read_reg(unsigned int reg_number, void *buffer, size_t bytes)
Definition: tpm.c:315
__weak int tis_plat_irq_status(void)
Definition: tpm.c:62
static const uint32_t supported_did_vids[]
Definition: tpm.c:420
enum cb_err tis_vendor_read(unsigned int addr, void *buffer, size_t bytes)
Definition: tpm.c:735
static enum cb_err __must_check write_tpm_sts(uint32_t status)
Definition: tpm.c:336
#define TPM_DID_VID_REG
Definition: tpm.c:30
static void tpm2_write_access_reg(uint8_t cmd)
Definition: tpm.c:362
#define TPM_DATA_FIFO_REG
Definition: tpm.c:29
static void read_bytes(void *buffer, size_t bytes)
Definition: tpm.c:290
static struct tpm2_info tpm_info
Definition: tpm.c:41
static enum cb_err tpm2_write_reg(unsigned int reg_number, const void *buffer, size_t bytes)
Definition: tpm.c:299
static void trace_dump(const char *prefix, uint32_t reg, size_t bytes, const uint8_t *buffer, int force)
Definition: tpm.c:224
static const int debug_level_
Definition: tpm.c:47
static uint8_t tpm2_read_access_reg(void)
Definition: tpm.c:354
#define TPM_RID_REG
Definition: tpm.c:31
#define MAX_STATUS_TIMEOUT
Definition: tpm.c:516
static enum cb_err __must_check fifo_transfer(size_t transfer_size, union fifo_transfer_buffer buffer, enum fifo_transfer_direction direction)
Definition: tpm.c:551
static enum cb_err start_transaction(int read_write, size_t bytes, unsigned int addr)
Definition: tpm.c:97
static enum cb_err wait_for_status(uint32_t status_mask, uint32_t status_expected)
Definition: tpm.c:517
enum cb_err tis_vendor_write(unsigned int addr, const void *buffer, size_t bytes)
Definition: tpm.c:730
#define TPM_ACCESS_REG
Definition: tpm.c:27
static enum cb_err read_tpm_sts(uint32_t *status)
Definition: tpm.c:331
static enum cb_err tpm2_claim_locality(void)
Definition: tpm.c:370
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
unsigned char uint8_t
Definition: stdint.h:8
unsigned char body[4]
Definition: tpm.c:54
Definition: tpm.h:54
uint16_t device_id
Definition: tpm.h:56
uint16_t revision
Definition: tpm.h:57
uint16_t vendor_id
Definition: tpm.h:55
@ TPM_STS_BURST_COUNT_MASK
Definition: tis.h:26
@ TPM_STS_FAMILY_TPM_2_0
Definition: tis.h:21
@ TPM_STS_GO
Definition: tis.h:29
@ TPM_STS_VALID
Definition: tis.h:27
@ TPM_STS_FAMILY_MASK
Definition: tis.h:20
@ TPM_STS_DATA_AVAIL
Definition: tis.h:30
@ TPM_STS_COMMAND_READY
Definition: tis.h:28
@ TPM_STS_BURST_COUNT_SHIFT
Definition: tis.h:25
static bool tpm_first_access_this_boot(void)
Definition: tis.h:114
@ TPM_ACCESS_REQUEST_USE
Definition: tis.h:14
@ TPM_ACCESS_ACTIVE_LOCALITY
Definition: tis.h:12
@ TPM_ACCESS_ESTABLISHMENT
Definition: tis.h:15
@ TPM_ACCESS_VALID
Definition: tis.h:11
void udelay(uint32_t us)
Definition: udelay.c:15
uint8_t * rx_buffer
Definition: tpm.c:543
const uint8_t * tx_buffer
Definition: tpm.c:544