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

Go to the source code of this file.

Data Structures

struct  tpm_inf_dev
 

Macros

#define MAX_COUNT   3
 
#define SLEEP_DURATION   60 /* in usec */
 
#define SLEEP_DURATION_LONG   210 /* in usec */
 
#define SLEEP_DURATION_PROBE_MS   1000 /* in msec */
 
#define MAX_COUNT_LONG   50
 
#define TPM_TIS_I2C_DID_VID_9635   0x000b15d1L
 
#define TPM_TIS_I2C_DID_VID_9645   0x001a15d1L
 

Enumerations

enum  i2c_chip_type { SLB9635 , SLB9645 , UNKNOWN }
 

Functions

static int iic_tpm_read (uint8_t addr, uint8_t *buffer, size_t len)
 
static int iic_tpm_write_generic (uint8_t addr, uint8_t *buffer, size_t len, unsigned int sleep_time, uint8_t max_count)
 
static int iic_tpm_write (uint8_t addr, uint8_t *buffer, size_t len)
 
static int iic_tpm_write_long (uint8_t addr, uint8_t *buffer, size_t len)
 
static int check_locality (struct tpm_chip *chip, int loc)
 
static void release_locality (struct tpm_chip *chip, int loc, int force)
 
static int request_locality (struct tpm_chip *chip, int loc)
 
static uint8_t tpm_tis_i2c_status (struct tpm_chip *chip)
 
static void tpm_tis_i2c_ready (struct tpm_chip *chip)
 
static ssize_t get_burstcount (struct tpm_chip *chip)
 
static int wait_for_stat (struct tpm_chip *chip, uint8_t mask, int *status)
 
static int recv_data (struct tpm_chip *chip, uint8_t *buf, size_t count)
 
static int tpm_tis_i2c_recv (struct tpm_chip *chip, uint8_t *buf, size_t count)
 
static int tpm_tis_i2c_send (struct tpm_chip *chip, uint8_t *buf, size_t len)
 
int tpm_vendor_probe (unsigned int bus, uint32_t addr)
 
int tpm_vendor_init (struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
 
void tpm_vendor_cleanup (struct tpm_chip *chip)
 

Variables

static const char *const chip_name []
 
static struct tpm_inf_dev tpm_dev
 

Macro Definition Documentation

◆ MAX_COUNT

#define MAX_COUNT   3

Definition at line 30 of file tpm.c.

◆ MAX_COUNT_LONG

#define MAX_COUNT_LONG   50

Definition at line 41 of file tpm.c.

◆ SLEEP_DURATION

#define SLEEP_DURATION   60 /* in usec */

Definition at line 32 of file tpm.c.

◆ SLEEP_DURATION_LONG

#define SLEEP_DURATION_LONG   210 /* in usec */

Definition at line 33 of file tpm.c.

◆ SLEEP_DURATION_PROBE_MS

#define SLEEP_DURATION_PROBE_MS   1000 /* in msec */

Definition at line 34 of file tpm.c.

◆ TPM_TIS_I2C_DID_VID_9635

#define TPM_TIS_I2C_DID_VID_9635   0x000b15d1L

Definition at line 44 of file tpm.c.

◆ TPM_TIS_I2C_DID_VID_9645

#define TPM_TIS_I2C_DID_VID_9645   0x001a15d1L

Definition at line 45 of file tpm.c.

Enumeration Type Documentation

◆ i2c_chip_type

Enumerator
SLB9635 
SLB9645 
UNKNOWN 

Definition at line 47 of file tpm.c.

Function Documentation

◆ check_locality()

static int check_locality ( struct tpm_chip chip,
int  loc 
)
static

Definition at line 222 of file tpm.c.

References buf, chip, iic_tpm_read(), tpm_vendor_specific::locality, TPM_ACCESS, TPM_ACCESS_ACTIVE_LOCALITY, TPM_ACCESS_VALID, and tpm_chip::vendor.

Referenced by request_locality().

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

◆ get_burstcount()

static ssize_t get_burstcount ( struct tpm_chip chip)
static

Definition at line 291 of file tpm.c.

References buf, chip, iic_tpm_read(), tpm_vendor_specific::locality, mdelay(), TPM_STS, TPM_TIMEOUT, and tpm_chip::vendor.

Referenced by recv_data(), and tpm_tis_i2c_send().

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

◆ iic_tpm_read()

static int iic_tpm_read ( uint8_t  addr,
uint8_t buffer,
size_t  len 
)
static

◆ iic_tpm_write()

static int iic_tpm_write ( uint8_t  addr,
uint8_t buffer,
size_t  len 
)
static

Definition at line 206 of file tpm.c.

References addr, buffer, iic_tpm_write_generic(), i2c_msg::len, MAX_COUNT, tpm_inf_dev::sleep_short, and tpm_dev.

Referenced by release_locality(), request_locality(), and tpm_tis_i2c_send().

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

◆ iic_tpm_write_generic()

static int iic_tpm_write_generic ( uint8_t  addr,
uint8_t buffer,
size_t  len,
unsigned int  sleep_time,
uint8_t  max_count 
)
static

Definition at line 154 of file tpm.c.

References addr, tpm_inf_dev::addr, BIOS_DEBUG, tpm_inf_dev::buf, buffer, tpm_inf_dev::bus, count, i2c_write_raw(), i2c_msg::len, memcpy(), printk, tpm_inf_dev::sleep_short, TPM_BUFSIZE, tpm_dev, and udelay().

Referenced by iic_tpm_write(), and iic_tpm_write_long().

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

◆ iic_tpm_write_long()

static int iic_tpm_write_long ( uint8_t  addr,
uint8_t buffer,
size_t  len 
)
static

Definition at line 216 of file tpm.c.

References addr, buffer, iic_tpm_write_generic(), i2c_msg::len, MAX_COUNT_LONG, tpm_inf_dev::sleep_long, and tpm_dev.

Referenced by tpm_tis_i2c_ready().

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

◆ recv_data()

static int recv_data ( struct tpm_chip chip,
uint8_t buf,
size_t  count 
)
static

Definition at line 328 of file tpm.c.

References buf, chip, count, get_burstcount(), iic_tpm_read(), tpm_vendor_specific::locality, TPM_DATA_FIFO, and tpm_chip::vendor.

Referenced by tpm_tis_i2c_recv().

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

◆ release_locality()

static void release_locality ( struct tpm_chip chip,
int  loc,
int  force 
)
static

Definition at line 238 of file tpm.c.

References buf, iic_tpm_read(), iic_tpm_write(), TPM_ACCESS, TPM_ACCESS_ACTIVE_LOCALITY, TPM_ACCESS_REQUEST_PENDING, and TPM_ACCESS_VALID.

Referenced by tpm_vendor_cleanup(), and tpm_vendor_init().

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

◆ request_locality()

static int request_locality ( struct tpm_chip chip,
int  loc 
)
static

Definition at line 251 of file tpm.c.

References buf, check_locality(), chip, iic_tpm_write(), mdelay(), TPM_ACCESS, TPM_ACCESS_REQUEST_USE, and TPM_TIMEOUT.

Referenced by tpm_vendor_init().

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

◆ tpm_tis_i2c_ready()

static void tpm_tis_i2c_ready ( struct tpm_chip chip)
static

Definition at line 284 of file tpm.c.

References buf, chip, iic_tpm_write_long(), tpm_vendor_specific::locality, TPM_STS, TPM_STS_COMMAND_READY, and tpm_chip::vendor.

Referenced by tpm_tis_i2c_recv(), tpm_tis_i2c_send(), and tpm_vendor_init().

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

◆ tpm_tis_i2c_recv()

static int tpm_tis_i2c_recv ( struct tpm_chip chip,
uint8_t buf,
size_t  count 
)
static

Definition at line 354 of file tpm.c.

References BIOS_DEBUG, buf, chip, count, memcpy(), printk, recv_data(), TPM_HEADER_SIZE, TPM_RSP_SIZE_BYTE, TPM_STS_DATA_AVAIL, TPM_STS_VALID, tpm_tis_i2c_ready(), and wait_for_stat().

Referenced by tpm_vendor_init().

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

◆ tpm_tis_i2c_send()

static int tpm_tis_i2c_send ( struct tpm_chip chip,
uint8_t buf,
size_t  len 
)
static

Definition at line 400 of file tpm.c.

References buf, chip, count, get_burstcount(), iic_tpm_write(), i2c_msg::len, tpm_vendor_specific::locality, TPM_BUFSIZE, TPM_DATA_FIFO, TPM_STS, TPM_STS_COMMAND_READY, TPM_STS_DATA_EXPECT, TPM_STS_GO, TPM_STS_VALID, tpm_tis_i2c_ready(), tpm_tis_i2c_status(), tpm_chip::vendor, and wait_for_stat().

Referenced by tpm_vendor_init().

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

◆ tpm_tis_i2c_status()

static uint8_t tpm_tis_i2c_status ( struct tpm_chip chip)
static

Definition at line 272 of file tpm.c.

References buf, chip, iic_tpm_read(), tpm_vendor_specific::locality, TPM_STS, and tpm_chip::vendor.

Referenced by tpm_tis_i2c_send(), tpm_vendor_init(), and wait_for_stat().

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

◆ tpm_vendor_cleanup()

void tpm_vendor_cleanup ( struct tpm_chip chip)

Definition at line 555 of file tpm.c.

References chip, tpm_vendor_specific::locality, release_locality(), and tpm_chip::vendor.

Here is the call graph for this function:

◆ tpm_vendor_init()

◆ tpm_vendor_probe()

◆ wait_for_stat()

static int wait_for_stat ( struct tpm_chip chip,
uint8_t  mask,
int *  status 
)
static

Definition at line 314 of file tpm.c.

References chip, mask, mdelay(), TPM_TIMEOUT, and tpm_tis_i2c_status().

Referenced by tpm_tis_i2c_recv(), and tpm_tis_i2c_send().

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

Variable Documentation

◆ chip_name

const char* const chip_name[]
static
Initial value:
= {
[SLB9635] = "slb9635tt",
[SLB9645] = "slb9645tt",
[UNKNOWN] = "unknown/fallback to slb9635",
}
@ SLB9645
Definition: tpm.c:49
@ UNKNOWN
Definition: tpm.c:50
@ SLB9635
Definition: tpm.c:48

Definition at line 53 of file tpm.c.

Referenced by tpm_vendor_init().

◆ tpm_dev

struct tpm_inf_dev tpm_dev
static