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)
35 #define CR50_TIMEOUT_INIT_MS 30000
54 unsigned char body[4];
64 static int warning_displayed;
66 if (!warning_displayed) {
68 " Cr50!\n", __func__);
69 warning_displayed = 1;
104 static int tpm_sync_needed;
112 int wakeup_needed = 1;
115 if (tpm_sync_needed) {
152 header.body[0] = (read_write ? 0x80 : 0) | 0x40 | (bytes - 1);
155 for (i = 0; i < 3; i++)
156 header.body[i + 1] = (
addr >> (8 * (2 - i))) & 0xff;
188 header_resp.
body[3] = 0;
193 header_resp.
body,
sizeof(header_resp.
body));
200 if (header_resp.
body[3] & 1)
215 }
while (!(
byte & 1));
228 static char prev_prefix;
229 static unsigned int prev_reg;
230 static int current_char;
231 const int BYTES_PER_LINE = 32;
245 if (prev_prefix != *prefix || (prev_reg != reg)) {
246 prev_prefix = *prefix;
265 for (i = 0; i < bytes; i++) {
267 !(current_char % BYTES_PER_LINE)) {
365 assert (!(cmd & (cmd - 1)));
413 "Failed to claim locality 0 after %ld ms, status: %#x\n",
443 for (retries = 15; retries > 0; retries--) {
497 printk(
BIOS_INFO,
"Connected to device vid:did:rid of %4.4x:%4.4x:%2.2x\n",
516 #define MAX_STATUS_TIMEOUT 120
531 }
while ((status & status_mask) != status_expected);
555 size_t transaction_size;
557 size_t handled_so_far = 0;
563 }
while (!burst_count);
565 transaction_size = transfer_size - handled_so_far;
566 transaction_size =
MIN(transaction_size, burst_count);
572 transaction_size =
MIN(transaction_size, 64);
576 buffer.rx_buffer + handled_so_far,
581 buffer.tx_buffer + handled_so_far,
586 handled_so_far += transaction_size;
588 }
while (handled_so_far != transfer_size);
600 const uint8_t *cmd_body = tpm2_command;
603 const int HEADER_SIZE = 6;
613 if (payload_size != command_size) {
615 "Command size mismatch: encoded %zd != requested %zd\n",
616 payload_size, command_size);
675 if (payload_size > max_response) {
691 bytes_to_go = payload_size - 1 - HEADER_SIZE;
692 fifo_buffer.
rx_buffer = rsp_body + HEADER_SIZE;
701 if ((status & expected_status_bits) != expected_status_bits) {
struct arm64_kernel_header header
void * memcpy(void *dest, const void *src, size_t n)
void * memset(void *dstpp, int c, size_t len)
#define assert(statement)
cb_err
coreboot error codes
@ CB_ERR
Generic error code.
@ CB_SUCCESS
Call completed successfully.
static uint32_t read_be32(const void *src)
#define printk(level,...)
size_t tpm2_process_command(const void *tpm2_command, size_t command_size, void *tpm2_response, size_t max_response)
void tpm2_get_info(struct tpm2_info *tpm2_info)
void mdelay(unsigned int msecs)
static struct smmstore_params_info info
enum cb_err cr50_get_firmware_version(struct cr50_firmware_version *version)
enum cb_err cr50_set_board_cfg(void)
Set the BOARD_CFG register on the TPM chip to a particular compile-time constant value.
static int stopwatch_expired(struct stopwatch *sw)
static long stopwatch_duration_msecs(struct stopwatch *sw)
static void stopwatch_init_msecs_expire(struct stopwatch *sw, long ms)
static void stopwatch_init_usecs_expire(struct stopwatch *sw, long us)
#define BIOS_INFO
BIOS_INFO - Expected events.
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
u8 buffer[C2P_BUFFER_MAXSIZE]
const struct smm_save_state_ops *legacy_ops __weak
int spi_claim_bus(const struct spi_slave *slave)
int spi_xfer(const struct spi_slave *slave, const void *dout, size_t bytesout, void *din, size_t bytesin)
void spi_release_bus(const struct spi_slave *slave)
static void write_bytes(const void *buffer, size_t bytes)
static uint32_t get_burst_count(void)
#define CR50_TIMEOUT_INIT_MS
static enum cb_err tpm_sync(void)
static enum cb_err tpm2_read_reg(unsigned int reg_number, void *buffer, size_t bytes)
__weak int tis_plat_irq_status(void)
static const uint32_t supported_did_vids[]
enum cb_err tis_vendor_read(unsigned int addr, void *buffer, size_t bytes)
static enum cb_err __must_check write_tpm_sts(uint32_t status)
static void tpm2_write_access_reg(uint8_t cmd)
#define TPM_DATA_FIFO_REG
static void read_bytes(void *buffer, size_t bytes)
static struct tpm2_info tpm_info
static enum cb_err tpm2_write_reg(unsigned int reg_number, const void *buffer, size_t bytes)
static void trace_dump(const char *prefix, uint32_t reg, size_t bytes, const uint8_t *buffer, int force)
static const int debug_level_
static uint8_t tpm2_read_access_reg(void)
#define MAX_STATUS_TIMEOUT
static enum cb_err __must_check fifo_transfer(size_t transfer_size, union fifo_transfer_buffer buffer, enum fifo_transfer_direction direction)
static enum cb_err start_transaction(int read_write, size_t bytes, unsigned int addr)
static enum cb_err wait_for_status(uint32_t status_mask, uint32_t status_expected)
enum cb_err tis_vendor_write(unsigned int addr, const void *buffer, size_t bytes)
static enum cb_err read_tpm_sts(uint32_t *status)
static enum cb_err tpm2_claim_locality(void)
@ TPM_STS_BURST_COUNT_MASK
@ TPM_STS_BURST_COUNT_SHIFT
static bool tpm_first_access_this_boot(void)
@ TPM_ACCESS_ACTIVE_LOCALITY
@ TPM_ACCESS_ESTABLISHMENT
const uint8_t * tx_buffer