summaryrefslogtreecommitdiff
path: root/src/security/tpm/tss/tcg-1.2
diff options
context:
space:
mode:
authorJon Murphy <jpmurphy@google.com>2023-09-05 11:36:43 -0600
committerRaul Rangel <rrangel@chromium.org>2023-09-28 16:54:37 +0000
commitd7b8dc9cf5978809912dcffefce2eda5937c9653 (patch)
tree56befbc9563ce2baca6f31ccbfb041e99fb858d6 /src/security/tpm/tss/tcg-1.2
parent53fc667943052bd592b8406bdf4bf652c6c9cd3a (diff)
treewide: convert to tpm_result_t
Convert TPM functions to return TPM error codes(referred to as tpm_result_t) values to match the TCG standard. BUG=b:296439237 TEST=build and boot to Skyrim BRANCH=None Change-Id: Ifdf9ff6c2a1f9b938dbb04d245799391115eb6b1 Signed-off-by: Jon Murphy <jpmurphy@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/77666 Reviewed-by: Raul Rangel <rrangel@chromium.org> Reviewed-by: Matt DeVillier <matt.devillier@amd.corp-partner.google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/security/tpm/tss/tcg-1.2')
-rw-r--r--src/security/tpm/tss/tcg-1.2/tss.c100
1 files changed, 52 insertions, 48 deletions
diff --git a/src/security/tpm/tss/tcg-1.2/tss.c b/src/security/tpm/tss/tcg-1.2/tss.c
index 076b8a7562..e73db388e8 100644
--- a/src/security/tpm/tss/tcg-1.2/tss.c
+++ b/src/security/tpm/tss/tcg-1.2/tss.c
@@ -24,19 +24,21 @@
#include <console/console.h>
#define VBDEBUG(format, args...) printk(BIOS_DEBUG, format, ## args)
-static int tpm_send_receive(const uint8_t *request,
+static tpm_result_t tpm_send_receive(const uint8_t *request,
uint32_t request_length,
uint8_t *response,
uint32_t *response_length)
{
size_t len = *response_length;
- if (tis_sendrecv(request, request_length, response, &len))
- return VB2_ERROR_UNKNOWN;
+ tpm_result_t rc = tis_sendrecv(request, request_length, response, &len);
+ if (rc)
+ return rc;
/* check 64->32bit overflow and (re)check response buffer overflow */
if (len > *response_length)
- return VB2_ERROR_UNKNOWN;
- *response_length = len;
- return VB2_SUCCESS;
+ rc = TPM_CB_FAIL;
+ else
+ *response_length = len;
+ return rc;
}
/* Sets the size field of a TPM command. */
@@ -55,15 +57,15 @@ static inline int tpm_command_size(const uint8_t *buffer)
}
/* Gets the code field of a TPM command. */
-static inline int tpm_command_code(const uint8_t *buffer)
+static inline tpm_result_t tpm_command_code(const uint8_t *buffer)
{
- uint32_t rc;
+ tpm_result_t rc;
from_tpm_uint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &rc);
return rc;
}
/* Gets the return code field of a TPM result. */
-static inline int tpm_return_code(const uint8_t *buffer)
+static inline tpm_result_t tpm_return_code(const uint8_t *buffer)
{
return tpm_command_code(buffer);
}
@@ -72,15 +74,15 @@ static inline int tpm_return_code(const uint8_t *buffer)
* Like TlclSendReceive below, but do not retry if NEEDS_SELFTEST or
* DOING_SELFTEST errors are returned.
*/
-static uint32_t tlcl_send_receive_no_retry(const uint8_t *request,
+static tpm_result_t tlcl_send_receive_no_retry(const uint8_t *request,
uint8_t *response, int max_length)
{
uint32_t response_length = max_length;
- uint32_t rc;
+ tpm_result_t rc;
rc = tpm_send_receive(request, tpm_command_size(request),
response, &response_length);
- if (rc != 0) {
+ if (rc != TPM_SUCCESS) {
/* Communication with TPM failed, so response is garbage */
VBDEBUG("TPM: command %#x send/receive failed: %#x\n",
tpm_command_code(request), rc);
@@ -96,15 +98,15 @@ static uint32_t tlcl_send_receive_no_retry(const uint8_t *request,
VBDEBUG("TPM: command %#x returned %#x\n",
tpm_command_code(request), rc);
-return rc;
+ return rc;
}
/* Sends a TPM command and gets a response. Returns 0 if success or the TPM
* error code if error. Waits for the self test to complete if needed. */
-uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
+tpm_result_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
int max_length)
{
- uint32_t rc = tlcl_send_receive_no_retry(request, response,
+ tpm_result_t rc = tlcl_send_receive_no_retry(request, response,
max_length);
/* If the command fails because the self test has not completed, try it
* again after attempting to ensure that the self test has completed. */
@@ -132,7 +134,7 @@ uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
}
/* Sends a command and returns the error code. */
-static uint32_t send(const uint8_t *command)
+static tpm_result_t send(const uint8_t *command)
{
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
return tlcl_send_receive(command, response, sizeof(response));
@@ -142,46 +144,48 @@ static uint32_t send(const uint8_t *command)
static uint8_t tlcl_init_done;
-uint32_t tlcl_lib_init(void)
+tpm_result_t tlcl_lib_init(void)
{
+ tpm_result_t rc = TPM_SUCCESS;
if (tlcl_init_done)
- return VB2_SUCCESS;
-
- if (tis_init())
- return VB2_ERROR_UNKNOWN;
- if (tis_open())
- return VB2_ERROR_UNKNOWN;
+ return rc;
+ rc = tis_init();
+ if (rc)
+ return rc;
+ rc = tis_open();
+ if (rc)
+ return rc;
tlcl_init_done = 1;
- return VB2_SUCCESS;
+ return rc;
}
-uint32_t tlcl_startup(void)
+tpm_result_t tlcl_startup(void)
{
VBDEBUG("TPM: Startup\n");
return send(tpm_startup_cmd.buffer);
}
-uint32_t tlcl_resume(void)
+tpm_result_t tlcl_resume(void)
{
VBDEBUG("TPM: Resume\n");
return send(tpm_resume_cmd.buffer);
}
-uint32_t tlcl_save_state(void)
+tpm_result_t tlcl_save_state(void)
{
VBDEBUG("TPM: Save state\n");
return send(tpm_savestate_cmd.buffer);
}
-uint32_t tlcl_self_test_full(void)
+tpm_result_t tlcl_self_test_full(void)
{
VBDEBUG("TPM: Self test full\n");
return send(tpm_selftestfull_cmd.buffer);
}
-uint32_t tlcl_continue_self_test(void)
+tpm_result_t tlcl_continue_self_test(void)
{
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
VBDEBUG("TPM: Continue self test\n");
@@ -190,7 +194,7 @@ uint32_t tlcl_continue_self_test(void)
response, sizeof(response));
}
-uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
+tpm_result_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
{
struct s_tpm_nv_definespace_cmd cmd;
VBDEBUG("TPM: TlclDefineSpace(%#x, %#x, %d)\n", index, perm, size);
@@ -201,7 +205,7 @@ uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
return send(cmd.buffer);
}
-uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length)
+tpm_result_t tlcl_write(uint32_t index, const void *data, uint32_t length)
{
struct s_tpm_nv_write_cmd cmd;
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
@@ -221,12 +225,12 @@ uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length)
return tlcl_send_receive(cmd.buffer, response, sizeof(response));
}
-uint32_t tlcl_read(uint32_t index, void *data, uint32_t length)
+tpm_result_t tlcl_read(uint32_t index, void *data, uint32_t length)
{
struct s_tpm_nv_read_cmd cmd;
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
uint32_t result_length;
- uint32_t rc;
+ tpm_result_t rc;
VBDEBUG("TPM: %s(%#x, %d)\n", __func__, index, length);
memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd));
@@ -246,43 +250,43 @@ uint32_t tlcl_read(uint32_t index, void *data, uint32_t length)
return rc;
}
-uint32_t tlcl_assert_physical_presence(void)
+tpm_result_t tlcl_assert_physical_presence(void)
{
VBDEBUG("TPM: Asserting physical presence\n");
return send(tpm_ppassert_cmd.buffer);
}
-uint32_t tlcl_physical_presence_cmd_enable(void)
+tpm_result_t tlcl_physical_presence_cmd_enable(void)
{
VBDEBUG("TPM: Enable the physical presence command\n");
return send(tpm_ppenable_cmd.buffer);
}
-uint32_t tlcl_finalize_physical_presence(void)
+tpm_result_t tlcl_finalize_physical_presence(void)
{
VBDEBUG("TPM: Enable PP cmd, disable HW pp, and set lifetime lock\n");
return send(tpm_finalizepp_cmd.buffer);
}
-uint32_t tlcl_set_nv_locked(void)
+tpm_result_t tlcl_set_nv_locked(void)
{
VBDEBUG("TPM: Set NV locked\n");
return tlcl_define_space(TPM_NV_INDEX_LOCK, 0, 0);
}
-uint32_t tlcl_force_clear(void)
+tpm_result_t tlcl_force_clear(void)
{
VBDEBUG("TPM: Force clear\n");
return send(tpm_forceclear_cmd.buffer);
}
-uint32_t tlcl_set_enable(void)
+tpm_result_t tlcl_set_enable(void)
{
VBDEBUG("TPM: Enabling TPM\n");
return send(tpm_physicalenable_cmd.buffer);
}
-uint32_t tlcl_set_deactivated(uint8_t flag)
+tpm_result_t tlcl_set_deactivated(uint8_t flag)
{
struct s_tpm_physicalsetdeactivated_cmd cmd;
VBDEBUG("TPM: SetDeactivated(%d)\n", flag);
@@ -291,11 +295,11 @@ uint32_t tlcl_set_deactivated(uint8_t flag)
return send(cmd.buffer);
}
-uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags)
+tpm_result_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags)
{
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
uint32_t size;
- uint32_t rc = tlcl_send_receive(tpm_getflags_cmd.buffer, response,
+ tpm_result_t rc = tlcl_send_receive(tpm_getflags_cmd.buffer, response,
sizeof(response));
if (rc != TPM_SUCCESS)
return rc;
@@ -307,11 +311,11 @@ uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags)
return rc;
}
-uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
+tpm_result_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
uint8_t *nvlocked)
{
TPM_PERMANENT_FLAGS pflags;
- uint32_t rc = tlcl_get_permanent_flags(&pflags);
+ tpm_result_t rc = tlcl_get_permanent_flags(&pflags);
if (rc == TPM_SUCCESS) {
if (disable)
*disable = pflags.disable;
@@ -325,13 +329,13 @@ uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
return rc;
}
-uint32_t tlcl_set_global_lock(void)
+tpm_result_t tlcl_set_global_lock(void)
{
VBDEBUG("TPM: Set global lock\n");
return tlcl_write(TPM_NV_INDEX0, NULL, 0);
}
-uint32_t tlcl_extend(int pcr_num, const uint8_t *digest_data,
+tpm_result_t tlcl_extend(int pcr_num, const uint8_t *digest_data,
enum vb2_hash_algorithm digest_algo)
{
struct s_tpm_extend_cmd cmd;
@@ -347,12 +351,12 @@ uint32_t tlcl_extend(int pcr_num, const uint8_t *digest_data,
return tlcl_send_receive(cmd.buffer, response, sizeof(response));
}
-uint32_t tlcl_get_permissions(uint32_t index, uint32_t *permissions)
+tpm_result_t tlcl_get_permissions(uint32_t index, uint32_t *permissions)
{
struct s_tpm_getpermissions_cmd cmd;
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
uint8_t *nvdata;
- uint32_t rc;
+ tpm_result_t rc;
uint32_t size;
memcpy(&cmd, &tpm_getpermissions_cmd, sizeof(cmd));