coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
tpm.c File Reference
#include <assert.h>
#include <commonlib/endian.h>
#include <console/console.h>
#include <delay.h>
#include <endian.h>
#include <security/tpm/tis.h>
#include <string.h>
#include <timer.h>
#include <types.h>
#include "tpm.h"
Include dependency graph for tpm.c:

Go to the source code of this file.

Data Structures

struct  spi_frame_header
 
union  fifo_transfer_buffer
 

Macros

#define TPM_ACCESS_REG   (TPM_LOCALITY_0_SPI_BASE + 0)
 
#define TPM_STS_REG   (TPM_LOCALITY_0_SPI_BASE + 0x18)
 
#define TPM_DATA_FIFO_REG   (TPM_LOCALITY_0_SPI_BASE + 0x24)
 
#define TPM_DID_VID_REG   (TPM_LOCALITY_0_SPI_BASE + 0xf00)
 
#define TPM_RID_REG   (TPM_LOCALITY_0_SPI_BASE + 0xf04)
 
#define TPM_FW_VER   (TPM_LOCALITY_0_SPI_BASE + 0xf90)
 
#define CR50_BOARD_CFG   (TPM_LOCALITY_0_SPI_BASE + 0xfe0)
 
#define CR50_TIMEOUT_INIT_MS   30000 /* Very long timeout for TPM init */
 
#define MAX_STATUS_TIMEOUT   120
 

Enumerations

enum  fifo_transfer_direction { fifo_transmit = 0 , fifo_receive = 1 }
 

Functions

void tpm2_get_info (struct tpm2_info *info)
 
__weak int tis_plat_irq_status (void)
 
static enum cb_err tpm_sync (void)
 
static enum cb_err start_transaction (int read_write, size_t bytes, unsigned int addr)
 
static void trace_dump (const char *prefix, uint32_t reg, size_t bytes, const uint8_t *buffer, int force)
 
static void write_bytes (const void *buffer, size_t bytes)
 
static void read_bytes (void *buffer, size_t bytes)
 
static enum cb_err tpm2_write_reg (unsigned int reg_number, const void *buffer, size_t bytes)
 
static enum cb_err tpm2_read_reg (unsigned int reg_number, void *buffer, size_t bytes)
 
static enum cb_err read_tpm_sts (uint32_t *status)
 
static enum cb_err __must_check write_tpm_sts (uint32_t status)
 
static uint32_t get_burst_count (void)
 
static uint8_t tpm2_read_access_reg (void)
 
static void tpm2_write_access_reg (uint8_t cmd)
 
static enum cb_err tpm2_claim_locality (void)
 
int tpm2_init (struct spi_slave *spi_if)
 
static enum cb_err wait_for_status (uint32_t status_mask, uint32_t status_expected)
 
static enum cb_err __must_check fifo_transfer (size_t transfer_size, union fifo_transfer_buffer buffer, enum fifo_transfer_direction direction)
 
size_t tpm2_process_command (const void *tpm2_command, size_t command_size, void *tpm2_response, size_t max_response)
 
enum cb_err tis_vendor_write (unsigned int addr, const void *buffer, size_t bytes)
 
enum cb_err tis_vendor_read (unsigned int addr, void *buffer, size_t bytes)
 

Variables

static struct spi_slave spi_slave
 
static struct tpm2_info tpm_info
 
static const int debug_level_ = CONFIG(DEBUG_TPM)
 
static const uint32_t supported_did_vids []
 

Macro Definition Documentation

◆ CR50_BOARD_CFG

#define CR50_BOARD_CFG   (TPM_LOCALITY_0_SPI_BASE + 0xfe0)

Definition at line 33 of file tpm.c.

◆ CR50_TIMEOUT_INIT_MS

#define CR50_TIMEOUT_INIT_MS   30000 /* Very long timeout for TPM init */

Definition at line 35 of file tpm.c.

◆ MAX_STATUS_TIMEOUT

#define MAX_STATUS_TIMEOUT   120

Definition at line 516 of file tpm.c.

◆ TPM_ACCESS_REG

#define TPM_ACCESS_REG   (TPM_LOCALITY_0_SPI_BASE + 0)

Definition at line 27 of file tpm.c.

◆ TPM_DATA_FIFO_REG

#define TPM_DATA_FIFO_REG   (TPM_LOCALITY_0_SPI_BASE + 0x24)

Definition at line 29 of file tpm.c.

◆ TPM_DID_VID_REG

#define TPM_DID_VID_REG   (TPM_LOCALITY_0_SPI_BASE + 0xf00)

Definition at line 30 of file tpm.c.

◆ TPM_FW_VER

#define TPM_FW_VER   (TPM_LOCALITY_0_SPI_BASE + 0xf90)

Definition at line 32 of file tpm.c.

◆ TPM_RID_REG

#define TPM_RID_REG   (TPM_LOCALITY_0_SPI_BASE + 0xf04)

Definition at line 31 of file tpm.c.

◆ TPM_STS_REG

#define TPM_STS_REG   (TPM_LOCALITY_0_SPI_BASE + 0x18)

Definition at line 28 of file tpm.c.

Enumeration Type Documentation

◆ fifo_transfer_direction

Enumerator
fifo_transmit 
fifo_receive 

Definition at line 536 of file tpm.c.

Function Documentation

◆ fifo_transfer()

◆ get_burst_count()

static uint32_t get_burst_count ( void  )
static

Definition at line 346 of file tpm.c.

References read_tpm_sts(), TPM_STS_BURST_COUNT_MASK, and TPM_STS_BURST_COUNT_SHIFT.

Here is the call graph for this function:

◆ read_bytes()

static void read_bytes ( void buffer,
size_t  bytes 
)
static

Definition at line 290 of file tpm.c.

References buffer, NULL, and spi_xfer().

Here is the call graph for this function:

◆ read_tpm_sts()

static enum cb_err read_tpm_sts ( uint32_t status)
static

Definition at line 290 of file tpm.c.

Referenced by fifo_transfer(), get_burst_count(), and tis_vendor_read().

Here is the caller graph for this function:

◆ start_transaction()

static enum cb_err start_transaction ( int  read_write,
size_t  bytes,
unsigned int  addr 
)
static

Definition at line 62 of file tpm.c.

References BIOS_WARNING, mdelay(), and printk.

Here is the call graph for this function:

◆ tis_plat_irq_status()

__weak int tis_plat_irq_status ( void  )

Definition at line 62 of file tpm.c.

Referenced by fifo_transfer().

Here is the caller graph for this function:

◆ tis_vendor_read()

◆ tis_vendor_write()

enum cb_err tis_vendor_write ( unsigned int  addr,
const void buffer,
size_t  bytes 
)

Definition at line 593 of file tpm.c.

◆ tpm2_claim_locality()

static enum cb_err tpm2_claim_locality ( void  )
static

Definition at line 362 of file tpm.c.

References assert, tpm2_write_reg(), and TPM_ACCESS_REG.

Referenced by fifo_transfer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tpm2_get_info()

void tpm2_get_info ( struct tpm2_info info)

Definition at line 57 of file tpm.c.

References info, and tpm_info.

◆ tpm2_init()

int tpm2_init ( struct spi_slave spi_if)

Definition at line 426 of file tpm.c.

◆ tpm2_process_command()

size_t tpm2_process_command ( const void tpm2_command,
size_t  command_size,
void tpm2_response,
size_t  max_response 
)

Definition at line 593 of file tpm.c.

◆ tpm2_read_access_reg()

static uint8_t tpm2_read_access_reg ( void  )
static

Definition at line 354 of file tpm.c.

References tpm2_read_reg(), TPM_ACCESS_ESTABLISHMENT, and TPM_ACCESS_REG.

Here is the call graph for this function:

◆ tpm2_read_reg()

static enum cb_err tpm2_read_reg ( unsigned int  reg_number,
void buffer,
size_t  bytes 
)
static

Definition at line 290 of file tpm.c.

Referenced by fifo_transfer(), tis_vendor_read(), and tpm2_read_access_reg().

Here is the caller graph for this function:

◆ tpm2_write_access_reg()

static void tpm2_write_access_reg ( uint8_t  cmd)
static

Definition at line 362 of file tpm.c.

◆ tpm2_write_reg()

static enum cb_err tpm2_write_reg ( unsigned int  reg_number,
const void buffer,
size_t  bytes 
)
static

Definition at line 290 of file tpm.c.

Referenced by tpm2_claim_locality().

Here is the caller graph for this function:

◆ tpm_sync()

static enum cb_err tpm_sync ( void  )
static

Definition at line 62 of file tpm.c.

◆ trace_dump()

static void trace_dump ( const char *  prefix,
uint32_t  reg,
size_t  bytes,
const uint8_t buffer,
int  force 
)
static

Definition at line 224 of file tpm.c.

References BIOS_DEBUG, buffer, debug_level_, printk, and TPM_DATA_FIFO_REG.

Referenced by tis_vendor_read().

Here is the caller graph for this function:

◆ wait_for_status()

static enum cb_err wait_for_status ( uint32_t  status_mask,
uint32_t  status_expected 
)
static

Definition at line 426 of file tpm.c.

Referenced by tis_vendor_read().

Here is the caller graph for this function:

◆ write_bytes()

static void write_bytes ( const void buffer,
size_t  bytes 
)
static

Definition at line 281 of file tpm.c.

References buffer, NULL, and spi_xfer().

Here is the call graph for this function:

◆ write_tpm_sts()

static enum cb_err __must_check write_tpm_sts ( uint32_t  status)
static

Definition at line 290 of file tpm.c.

Referenced by tis_vendor_read().

Here is the caller graph for this function:

Variable Documentation

◆ debug_level_

const int debug_level_ = CONFIG(DEBUG_TPM)
static

Definition at line 47 of file tpm.c.

Referenced by tis_vendor_read(), and trace_dump().

◆ spi_slave

struct spi_slave spi_slave
static

Definition at line 1 of file tpm.c.

◆ supported_did_vids

const uint32_t supported_did_vids[]
static
Initial value:
= {
0x00281ae0,
0x504a6666,
0x0000104a
}

Definition at line 420 of file tpm.c.

Referenced by fifo_transfer().

◆ tpm_info

struct tpm2_info tpm_info
static

Definition at line 1 of file tpm.c.

Referenced by fifo_transfer(), tis_vendor_read(), and tpm2_get_info().