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

Go to the source code of this file.

Macros

#define VBDEBUG(format, args...)   printk(BIOS_DEBUG, format, ## args)
 

Functions

static int tpm_send_receive (const uint8_t *request, uint32_t request_length, uint8_t *response, uint32_t *response_length)
 
static void set_tpm_command_size (uint8_t *buffer, uint32_t size)
 
static int tpm_command_size (const uint8_t *buffer)
 
static int tpm_command_code (const uint8_t *buffer)
 
static int tpm_return_code (const uint8_t *buffer)
 
static uint32_t tlcl_send_receive_no_retry (const uint8_t *request, uint8_t *response, int max_length)
 
uint32_t tlcl_send_receive (const uint8_t *request, uint8_t *response, int max_length)
 Perform a raw TPM request/response transaction. More...
 
static uint32_t send (const uint8_t *command)
 
uint32_t tlcl_lib_init (void)
 Call this first. More...
 
uint32_t tlcl_startup (void)
 Send a TPM_Startup(ST_CLEAR). More...
 
uint32_t tlcl_resume (void)
 Resume by sending a TPM_Startup(ST_STATE). More...
 
uint32_t tlcl_save_state (void)
 Save TPM state by sending either TPM_SaveState() (TPM1.2) or TPM_Shutdown(ST_STATE) (TPM2.0). More...
 
uint32_t tlcl_self_test_full (void)
 Run the self test. More...
 
uint32_t tlcl_continue_self_test (void)
 Run the self test in the background. More...
 
uint32_t tlcl_define_space (uint32_t index, uint32_t perm, uint32_t size)
 
uint32_t tlcl_write (uint32_t index, const void *data, uint32_t length)
 Write [length] bytes of [data] to space at [index]. More...
 
uint32_t tlcl_read (uint32_t index, void *data, uint32_t length)
 Read [length] bytes from space at [index] into [data]. More...
 
uint32_t tlcl_assert_physical_presence (void)
 Assert physical presence in software. More...
 
uint32_t tlcl_physical_presence_cmd_enable (void)
 Enable the physical presence command. More...
 
uint32_t tlcl_finalize_physical_presence (void)
 Finalize the physical presence settings: software PP is enabled, hardware PP is disabled, and the lifetime lock is set. More...
 
uint32_t tlcl_set_nv_locked (void)
 Set the nvLocked bit. More...
 
uint32_t tlcl_force_clear (void)
 Issue a ForceClear. More...
 
uint32_t tlcl_set_enable (void)
 
uint32_t tlcl_set_deactivated (uint8_t flag)
 
uint32_t tlcl_get_permanent_flags (TPM_PERMANENT_FLAGS *pflags)
 
uint32_t tlcl_get_flags (uint8_t *disable, uint8_t *deactivated, uint8_t *nvlocked)
 
uint32_t tlcl_set_global_lock (void)
 Set the bGlobalLock flag, which only a reboot can clear. More...
 
uint32_t tlcl_extend (int pcr_num, const uint8_t *in_digest, uint8_t *out_digest)
 Perform a TPM_Extend. More...
 
uint32_t tlcl_get_permissions (uint32_t index, uint32_t *permissions)
 Get the permission bits for the NVRAM space with |index|. More...
 

Variables

static uint8_t tlcl_init_done
 

Macro Definition Documentation

◆ VBDEBUG

#define VBDEBUG (   format,
  args... 
)    printk(BIOS_DEBUG, format, ## args)

Definition at line 25 of file tss.c.

Function Documentation

◆ send()

static uint32_t send ( const uint8_t command)
static

◆ set_tpm_command_size()

static void set_tpm_command_size ( uint8_t buffer,
uint32_t  size 
)
inlinestatic

Definition at line 43 of file tss.c.

References buffer, and to_tpm_uint32().

Referenced by tlcl_write().

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

◆ tlcl_assert_physical_presence()

uint32_t tlcl_assert_physical_presence ( void  )

Assert physical presence in software.

The TPM error code is returned.

Definition at line 249 of file tss.c.

References s_tpm_ppassert_cmd::buffer, send(), tpm_ppassert_cmd, and VBDEBUG.

Referenced by tpm_setup().

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

◆ tlcl_continue_self_test()

uint32_t tlcl_continue_self_test ( void  )

Run the self test in the background.

Definition at line 184 of file tss.c.

References s_tpm_continueselftest_cmd::buffer, tlcl_send_receive_no_retry(), tpm_continueselftest_cmd, TPM_LARGE_ENOUGH_COMMAND_SIZE, and VBDEBUG.

Referenced by tlcl_send_receive().

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

◆ tlcl_define_space()

uint32_t tlcl_define_space ( uint32_t  index,
uint32_t  perm,
uint32_t  size 
)

Definition at line 193 of file tss.c.

References s_tpm_nv_definespace_cmd::buffer, s_tpm_nv_definespace_cmd::index, memcpy(), s_tpm_nv_definespace_cmd::perm, send(), s_tpm_nv_definespace_cmd::size, to_tpm_uint32(), tpm_nv_definespace_cmd, and VBDEBUG.

Referenced by safe_define_space(), and tlcl_set_nv_locked().

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

◆ tlcl_extend()

uint32_t tlcl_extend ( int  pcr_num,
const uint8_t in_digest,
uint8_t out_digest 
)

Perform a TPM_Extend.

Definition at line 334 of file tss.c.

References s_tpm_extend_cmd::buffer, s_tpm_extend_cmd::inDigest, kPcrDigestLength, kTpmResponseHeaderLength, memcpy(), s_tpm_extend_cmd::pcrNum, tlcl_send_receive(), to_tpm_uint32(), tpm_extend_cmd, and TPM_SUCCESS.

Referenced by tpm_extend_pcr(), and tspi_measure_cache_to_pcr().

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

◆ tlcl_finalize_physical_presence()

uint32_t tlcl_finalize_physical_presence ( void  )

Finalize the physical presence settings: software PP is enabled, hardware PP is disabled, and the lifetime lock is set.

The TPM error code is returned.

Definition at line 261 of file tss.c.

References s_tpm_finalizepp_cmd::buffer, send(), tpm_finalizepp_cmd, and VBDEBUG.

Referenced by _factory_initialize_tpm().

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

◆ tlcl_force_clear()

uint32_t tlcl_force_clear ( void  )

Issue a ForceClear.

The TPM error code is returned.

Definition at line 273 of file tss.c.

References s_tpm_forceclear_cmd::buffer, send(), tpm_forceclear_cmd, and VBDEBUG.

Referenced by tpm_clear_and_reenable().

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

◆ tlcl_get_flags()

uint32_t tlcl_get_flags ( uint8_t disable,
uint8_t deactivated,
uint8_t nvlocked 
)

◆ tlcl_get_permanent_flags()

uint32_t tlcl_get_permanent_flags ( TPM_PERMANENT_FLAGS pflags)

Definition at line 294 of file tss.c.

References s_tpm_getflags_cmd::buffer, from_tpm_uint32(), kTpmResponseHeaderLength, memcpy(), tlcl_send_receive(), TPM_E_IOERROR, tpm_getflags_cmd, TPM_LARGE_ENOUGH_COMMAND_SIZE, and TPM_SUCCESS.

Referenced by _factory_initialize_tpm(), and tlcl_get_flags().

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

◆ tlcl_get_permissions()

uint32_t tlcl_get_permissions ( uint32_t  index,
uint32_t permissions 
)

Get the permission bits for the NVRAM space with |index|.

Definition at line 355 of file tss.c.

References s_tpm_getpermissions_cmd::buffer, from_tpm_uint32(), s_tpm_getpermissions_cmd::index, kNvDataPublicPermissionsOffset, kTpmResponseHeaderLength, memcpy(), tlcl_send_receive(), to_tpm_uint32(), tpm_getpermissions_cmd, TPM_LARGE_ENOUGH_COMMAND_SIZE, and TPM_SUCCESS.

Referenced by antirollback_read_space_kernel().

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

◆ tlcl_lib_init()

uint32_t tlcl_lib_init ( void  )

Call this first.

Returns 0 if success, nonzero if error.

Definition at line 145 of file tss.c.

References tis_init(), tis_open(), and tlcl_init_done.

Referenced by mainboard_update_soc_chip_config(), mrc_cache_update_hash(), mrc_cache_verify_hash(), tpm_extend_pcr(), tpm_setup(), and vboot_save_data().

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

◆ tlcl_physical_presence_cmd_enable()

uint32_t tlcl_physical_presence_cmd_enable ( void  )

Enable the physical presence command.

The TPM error code is returned.

Definition at line 255 of file tss.c.

References s_tpm_ppenable_cmd::buffer, send(), tpm_ppenable_cmd, and VBDEBUG.

Referenced by tpm_setup().

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

◆ tlcl_read()

uint32_t tlcl_read ( uint32_t  index,
void data,
uint32_t  length 
)

Read [length] bytes from space at [index] into [data].

The TPM error code is returned.

Definition at line 224 of file tss.c.

References s_tpm_nv_read_cmd::buffer, from_tpm_uint32(), s_tpm_nv_read_cmd::index, kTpmResponseHeaderLength, length, s_tpm_nv_read_cmd::length, memcpy(), tlcl_send_receive(), to_tpm_uint32(), TPM_E_IOERROR, TPM_LARGE_ENOUGH_COMMAND_SIZE, tpm_nv_read_cmd, TPM_SUCCESS, and VBDEBUG.

Referenced by antirollback_read_space_kernel(), and read_space_firmware().

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

◆ tlcl_resume()

uint32_t tlcl_resume ( void  )

Resume by sending a TPM_Startup(ST_STATE).

The TPM error code is returned (0 for success).

Definition at line 166 of file tss.c.

References s_tpm_resume_cmd::buffer, send(), tpm_resume_cmd, and VBDEBUG.

Referenced by tpm_setup_s3_helper().

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

◆ tlcl_save_state()

uint32_t tlcl_save_state ( void  )

Save TPM state by sending either TPM_SaveState() (TPM1.2) or TPM_Shutdown(ST_STATE) (TPM2.0).

The TPM error code is returned (0 for success).

Definition at line 172 of file tss.c.

References s_tpm_savestate_cmd::buffer, send(), tpm_savestate_cmd, and VBDEBUG.

Here is the call graph for this function:

◆ tlcl_self_test_full()

uint32_t tlcl_self_test_full ( void  )

Run the self test.

Note—this is synchronous. To run this in parallel with other firmware, use ContinueSelfTest(). The TPM error code is returned.

Definition at line 178 of file tss.c.

References s_tpm_selftestfull_cmd::buffer, send(), tpm_selftestfull_cmd, and VBDEBUG.

Referenced by factory_initialize_tpm().

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

◆ tlcl_send_receive()

uint32_t tlcl_send_receive ( const uint8_t request,
uint8_t response,
int  max_length 
)

Perform a raw TPM request/response transaction.

Definition at line 104 of file tss.c.

References tlcl_continue_self_test(), tlcl_send_receive_no_retry(), TPM_E_DOING_SELFTEST, TPM_E_NEEDS_SELFTEST, and TPM_SUCCESS.

Referenced by send(), tlcl_extend(), tlcl_get_permanent_flags(), tlcl_get_permissions(), tlcl_read(), and tlcl_write().

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

◆ tlcl_send_receive_no_retry()

static uint32_t tlcl_send_receive_no_retry ( const uint8_t request,
uint8_t response,
int  max_length 
)
static

Definition at line 75 of file tss.c.

References tpm_command_code(), tpm_command_size(), tpm_return_code(), tpm_send_receive(), and VBDEBUG.

Referenced by tlcl_continue_self_test(), and tlcl_send_receive().

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

◆ tlcl_set_deactivated()

uint32_t tlcl_set_deactivated ( uint8_t  flag)

Definition at line 285 of file tss.c.

References s_tpm_physicalsetdeactivated_cmd::buffer, s_tpm_physicalsetdeactivated_cmd::deactivated, memcpy(), send(), tpm_physicalsetdeactivated_cmd, and VBDEBUG.

Referenced by tpm_clear_and_reenable().

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

◆ tlcl_set_enable()

uint32_t tlcl_set_enable ( void  )

Definition at line 279 of file tss.c.

References s_tpm_physicalenable_cmd::buffer, send(), tpm_physicalenable_cmd, and VBDEBUG.

Referenced by tpm_clear_and_reenable().

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

◆ tlcl_set_global_lock()

uint32_t tlcl_set_global_lock ( void  )

Set the bGlobalLock flag, which only a reboot can clear.

The TPM error code is returned.

Definition at line 328 of file tss.c.

References NULL, tlcl_write(), TPM_NV_INDEX0, and VBDEBUG.

Referenced by antirollback_lock_space_firmware().

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

◆ tlcl_set_nv_locked()

uint32_t tlcl_set_nv_locked ( void  )

Set the nvLocked bit.

The TPM error code is returned.

Definition at line 267 of file tss.c.

References tlcl_define_space(), TPM_NV_INDEX_LOCK, and VBDEBUG.

Referenced by _factory_initialize_tpm().

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

◆ tlcl_startup()

uint32_t tlcl_startup ( void  )

Send a TPM_Startup(ST_CLEAR).

The TPM error code is returned (0 for success).

Definition at line 160 of file tss.c.

References s_tpm_startup_cmd::buffer, send(), tpm_startup_cmd, and VBDEBUG.

Referenced by tpm_setup().

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

◆ tlcl_write()

uint32_t tlcl_write ( uint32_t  index,
const void data,
uint32_t  length 
)

Write [length] bytes of [data] to space at [index].

The TPM error code is returned.

Definition at line 204 of file tss.c.

References assert, s_tpm_nv_write_cmd::buffer, s_tpm_nv_write_cmd::data, s_tpm_nv_write_cmd::index, kTpmRequestHeaderLength, kWriteInfoLength, length, s_tpm_nv_write_cmd::length, memcpy(), set_tpm_command_size(), tlcl_send_receive(), to_tpm_uint32(), TPM_LARGE_ENOUGH_COMMAND_SIZE, tpm_nv_write_cmd, and VBDEBUG.

Referenced by safe_write(), and tlcl_set_global_lock().

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

◆ tpm_command_code()

static int tpm_command_code ( const uint8_t buffer)
inlinestatic

Definition at line 58 of file tss.c.

References buffer, and from_tpm_uint32().

Referenced by tlcl_send_receive_no_retry(), and tpm_return_code().

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

◆ tpm_command_size()

static int tpm_command_size ( const uint8_t buffer)
inlinestatic

Definition at line 50 of file tss.c.

References buffer, and from_tpm_uint32().

Referenced by tlcl_send_receive_no_retry().

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

◆ tpm_return_code()

static int tpm_return_code ( const uint8_t buffer)
inlinestatic

Definition at line 66 of file tss.c.

References buffer, and tpm_command_code().

Referenced by tlcl_send_receive_no_retry().

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

◆ tpm_send_receive()

static int tpm_send_receive ( const uint8_t request,
uint32_t  request_length,
uint8_t response,
uint32_t response_length 
)
static

Definition at line 27 of file tss.c.

References tis_sendrecv().

Referenced by tlcl_send_receive_no_retry().

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

Variable Documentation

◆ tlcl_init_done

uint8_t tlcl_init_done
static

Definition at line 143 of file tss.c.

Referenced by tlcl_lib_init().