tss: implement tlcl_save_state
When an untrusted OS is running, we would like to use the Cr50 vendor-specific VENDOR_CC_TPM_MODE command to disable TPM. Before doing this, we should save TPM state. Implement tlcl_save_state for this purpose. This needs to live in coreboot codebase since on S3 resume path, depthcharge is not reached. Implement the function in both tcg-1.2 and tcg-2.0 for completeness. BUG=b:70681930,b:118202153 TEST=hack a call to tlcl_save_state into coreboot on S3 resume verify in AP console that it is called Signed-off-by: Joel Kitching <kitching@google.com> Change-Id: I8b51ca68456fc9b655e4dc2d0958b7c040d50510 Reviewed-on: https://review.coreboot.org/c/29646 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
This commit is contained in:
parent
e102c5d54b
commit
2e690eeaf2
|
@ -101,6 +101,13 @@ uint32_t tlcl_startup(void);
|
|||
*/
|
||||
uint32_t tlcl_resume(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).
|
||||
*/
|
||||
uint32_t tlcl_save_state(void);
|
||||
|
||||
/**
|
||||
* Run the self test.
|
||||
*
|
||||
|
|
|
@ -178,6 +178,12 @@ uint32_t tlcl_resume(void)
|
|||
return send(tpm_resume_cmd.buffer);
|
||||
}
|
||||
|
||||
uint32_t tlcl_save_state(void)
|
||||
{
|
||||
VBDEBUG("TPM: Save state\n");
|
||||
return send(tpm_savestate_cmd.buffer);
|
||||
}
|
||||
|
||||
uint32_t tlcl_self_test_full(void)
|
||||
{
|
||||
VBDEBUG("TPM: Self test full\n");
|
||||
|
|
|
@ -87,6 +87,35 @@ uint32_t tlcl_resume(void)
|
|||
return tlcl_send_startup(TPM_SU_STATE);
|
||||
}
|
||||
|
||||
static uint32_t tlcl_send_shutdown(TPM_SU type)
|
||||
{
|
||||
struct tpm2_shutdown shutdown;
|
||||
struct tpm2_response *response;
|
||||
|
||||
shutdown.shutdown_type = type;
|
||||
response = tpm_process_command(TPM2_Shutdown, &shutdown);
|
||||
|
||||
/* IO error, tpm2_response pointer is empty. */
|
||||
if (response == NULL) {
|
||||
printk(BIOS_ERR, "%s: TPM communication error\n", __func__);
|
||||
return TPM_E_IOERROR;
|
||||
}
|
||||
|
||||
printk(BIOS_INFO, "%s: Shutdown return code is %x\n",
|
||||
__func__, response->hdr.tpm_code);
|
||||
|
||||
if (response->hdr.tpm_code == TPM2_RC_SUCCESS)
|
||||
return TPM_SUCCESS;
|
||||
|
||||
/* Collapse any other errors into TPM_E_IOERROR. */
|
||||
return TPM_E_IOERROR;
|
||||
}
|
||||
|
||||
uint32_t tlcl_save_state(void)
|
||||
{
|
||||
return tlcl_send_shutdown(TPM_SU_STATE);
|
||||
}
|
||||
|
||||
uint32_t tlcl_assert_physical_presence(void)
|
||||
{
|
||||
/*
|
||||
|
|
|
@ -28,6 +28,11 @@ static int marshal_startup(struct obuf *ob, struct tpm2_startup *cmd_body)
|
|||
return obuf_write_be16(ob, cmd_body->startup_type);
|
||||
}
|
||||
|
||||
static int marshal_shutdown(struct obuf *ob, struct tpm2_shutdown *cmd_body)
|
||||
{
|
||||
return obuf_write_be16(ob, cmd_body->shutdown_type);
|
||||
}
|
||||
|
||||
static int marshal_get_capability(struct obuf *ob,
|
||||
struct tpm2_get_capability *cmd_body)
|
||||
{
|
||||
|
@ -302,6 +307,10 @@ int tpm_marshal_command(TPM_CC command, void *tpm_command_body, struct obuf *ob)
|
|||
rc |= marshal_startup(ob, tpm_command_body);
|
||||
break;
|
||||
|
||||
case TPM2_Shutdown:
|
||||
rc |= marshal_shutdown(ob, tpm_command_body);
|
||||
break;
|
||||
|
||||
case TPM2_GetCapability:
|
||||
rc |= marshal_get_capability(ob, tpm_command_body);
|
||||
break;
|
||||
|
@ -497,6 +506,7 @@ struct tpm2_response *tpm_unmarshal_response(TPM_CC command, struct ibuf *ib)
|
|||
|
||||
switch (command) {
|
||||
case TPM2_Startup:
|
||||
case TPM2_Shutdown:
|
||||
break;
|
||||
|
||||
case TPM2_GetCapability:
|
||||
|
|
|
@ -71,6 +71,7 @@ struct tpm_header {
|
|||
#define TPM2_NV_WriteLock ((TPM_CC)0x00000138)
|
||||
#define TPM2_SelfTest ((TPM_CC)0x00000143)
|
||||
#define TPM2_Startup ((TPM_CC)0x00000144)
|
||||
#define TPM2_Shutdown ((TPM_CC)0x00000145)
|
||||
#define TPM2_NV_Read ((TPM_CC)0x0000014E)
|
||||
#define TPM2_GetCapability ((TPM_CC)0x0000017A)
|
||||
#define TPM2_PCR_Extend ((TPM_CC)0x00000182)
|
||||
|
@ -138,6 +139,10 @@ struct tpm2_startup {
|
|||
TPM_SU startup_type;
|
||||
};
|
||||
|
||||
struct tpm2_shutdown {
|
||||
TPM_SU shutdown_type;
|
||||
};
|
||||
|
||||
/* Various TPM capability types to use when querying the device. */
|
||||
typedef uint32_t TPM_CAP;
|
||||
#define TPM_CAP_TPM_PROPERTIES ((TPM_CAP)0x00000006)
|
||||
|
|
Loading…
Reference in New Issue