diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tpm-common.c | 16 | ||||
-rw-r--r-- | lib/tpm-utils.h | 21 | ||||
-rw-r--r-- | lib/tpm-v1.c | 142 | ||||
-rw-r--r-- | lib/tpm-v2.c | 60 |
4 files changed, 112 insertions, 127 deletions
diff --git a/lib/tpm-common.c b/lib/tpm-common.c index a440639cec..6afe59b1fe 100644 --- a/lib/tpm-common.c +++ b/lib/tpm-common.c @@ -151,9 +151,9 @@ u32 tpm_return_code(const void *response) return get_unaligned_be32(response + return_code_offset); } -u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr) +u32 tpm_sendrecv_command(struct udevice *dev, const void *command, + void *response, size_t *size_ptr) { - struct udevice *dev; int err, ret; u8 response_buffer[COMMAND_BUFFER_SIZE]; size_t response_length; @@ -166,9 +166,6 @@ u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr) response_length = sizeof(response_buffer); } - ret = uclass_first_device_err(UCLASS_TPM, &dev); - if (ret) - return ret; err = tpm_xfer(dev, command, tpm_command_size(command), response, &response_length); @@ -188,14 +185,7 @@ u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr) return ret; } -int tpm_init(void) +int tpm_init(struct udevice *dev) { - struct udevice *dev; - int err; - - err = uclass_first_device_err(UCLASS_TPM, &dev); - if (err) - return err; - return tpm_open(dev); } diff --git a/lib/tpm-utils.h b/lib/tpm-utils.h index a9cb7dc7ee..d680d14088 100644 --- a/lib/tpm-utils.h +++ b/lib/tpm-utils.h @@ -19,24 +19,6 @@ #define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF) /** - * tpm_open() - Request access to locality 0 for the caller - * - * After all commands have been completed the caller is supposed to - * call tpm_close(). - * - * Returns 0 on success, -ve on failure. - */ -int tpm_open(struct udevice *dev); - -/** - * tpm_close() - Close the current session - * - * Releasing the locked locality. Returns 0 on success, -ve 1 on - * failure (in case lock removal did not succeed). - */ -int tpm_close(struct udevice *dev); - -/** * Pack data into a byte string. The data types are specified in * the format string: 'b' means unsigned byte, 'w' unsigned word, * 'd' unsigned double word, and 's' byte string. The data are a @@ -96,6 +78,7 @@ u32 tpm_return_code(const void *response); * is a bidirectional * @return return code of the TPM response */ -u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr); +u32 tpm_sendrecv_command(struct udevice *dev, const void *command, + void *response, size_t *size_ptr); #endif /* __TPM_UTILS_H */ diff --git a/lib/tpm-v1.c b/lib/tpm-v1.c index 9d45c3d3bf..f29e62ff7b 100644 --- a/lib/tpm-v1.c +++ b/lib/tpm-v1.c @@ -31,7 +31,7 @@ static struct session_data oiap_session = {0, }; #endif /* CONFIG_TPM_AUTH_SESSIONS */ -u32 tpm_startup(enum tpm_startup_type mode) +u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) { const u8 command[12] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x0, 0x0, 0x0, 0x99, 0x0, 0x0, @@ -44,49 +44,49 @@ u32 tpm_startup(enum tpm_startup_type mode) mode_offset, mode)) return TPM_LIB_ERROR; - return tpm_sendrecv_command(buf, NULL, NULL); + return tpm_sendrecv_command(dev, buf, NULL, NULL); } -u32 tpm_resume(void) +u32 tpm_resume(struct udevice *dev) { - return tpm_startup(TPM_ST_STATE); + return tpm_startup(dev, TPM_ST_STATE); } -u32 tpm_self_test_full(void) +u32 tpm_self_test_full(struct udevice *dev) { const u8 command[10] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x50, }; - return tpm_sendrecv_command(command, NULL, NULL); + return tpm_sendrecv_command(dev, command, NULL, NULL); } -u32 tpm_continue_self_test(void) +u32 tpm_continue_self_test(struct udevice *dev) { const u8 command[10] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x53, }; - return tpm_sendrecv_command(command, NULL, NULL); + return tpm_sendrecv_command(dev, command, NULL, NULL); } -u32 tpm_clear_and_reenable(void) +u32 tpm_clear_and_reenable(struct udevice *dev) { u32 ret; log_info("TPM: Clear and re-enable\n"); - ret = tpm_force_clear(); + ret = tpm_force_clear(dev); if (ret != TPM_SUCCESS) { log_err("Can't initiate a force clear\n"); return ret; } #if IS_ENABLED(CONFIG_TPM_V1) - ret = tpm_physical_enable(); + ret = tpm_physical_enable(dev); if (ret != TPM_SUCCESS) { log_err("TPM: Can't set enabled state\n"); return ret; } - ret = tpm_physical_set_deactivated(0); + ret = tpm_physical_set_deactivated(dev, 0); if (ret != TPM_SUCCESS) { log_err("TPM: Can't set deactivated state\n"); return ret; @@ -96,7 +96,7 @@ u32 tpm_clear_and_reenable(void) return TPM_SUCCESS; } -u32 tpm_nv_define_space(u32 index, u32 perm, u32 size) +u32 tpm_nv_define_space(struct udevice *dev, u32 index, u32 perm, u32 size) { const u8 command[101] = { 0x0, 0xc1, /* TPM_TAG */ @@ -136,15 +136,15 @@ u32 tpm_nv_define_space(u32 index, u32 perm, u32 size) size_offset, size)) return TPM_LIB_ERROR; - return tpm_sendrecv_command(buf, NULL, NULL); + return tpm_sendrecv_command(dev, buf, NULL, NULL); } -u32 tpm_nv_set_locked(void) +u32 tpm_nv_set_locked(struct udevice *dev) { - return tpm_nv_define_space(TPM_NV_INDEX_LOCK, 0, 0); + return tpm_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0); } -u32 tpm_nv_read_value(u32 index, void *data, u32 count) +u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count) { const u8 command[22] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0x16, 0x0, 0x0, 0x0, 0xcf, @@ -163,7 +163,7 @@ u32 tpm_nv_read_value(u32 index, void *data, u32 count) index_offset, index, length_offset, count)) return TPM_LIB_ERROR; - err = tpm_sendrecv_command(buf, response, &response_length); + err = tpm_sendrecv_command(dev, buf, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "d", @@ -178,7 +178,8 @@ u32 tpm_nv_read_value(u32 index, void *data, u32 count) return 0; } -u32 tpm_nv_write_value(u32 index, const void *data, u32 length) +u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data, + u32 length) { const u8 command[256] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xcd, @@ -201,21 +202,22 @@ u32 tpm_nv_write_value(u32 index, const void *data, u32 length) length_offset, length, data_offset, data, length)) return TPM_LIB_ERROR; - err = tpm_sendrecv_command(buf, response, &response_length); + err = tpm_sendrecv_command(dev, buf, response, &response_length); if (err) return err; return 0; } -uint32_t tpm_set_global_lock(void) +uint32_t tpm_set_global_lock(struct udevice *dev) { u32 x; - return tpm_nv_write_value(TPM_NV_INDEX_0, (uint8_t *)&x, 0); + return tpm_nv_write_value(dev, TPM_NV_INDEX_0, (uint8_t *)&x, 0); } -u32 tpm_extend(u32 index, const void *in_digest, void *out_digest) +u32 tpm_extend(struct udevice *dev, u32 index, const void *in_digest, + void *out_digest) { const u8 command[34] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0x22, 0x0, 0x0, 0x0, 0x14, @@ -234,7 +236,7 @@ u32 tpm_extend(u32 index, const void *in_digest, void *out_digest) in_digest_offset, in_digest, PCR_DIGEST_LENGTH)) return TPM_LIB_ERROR; - err = tpm_sendrecv_command(buf, response, &response_length); + err = tpm_sendrecv_command(dev, buf, response, &response_length); if (err) return err; @@ -246,7 +248,7 @@ u32 tpm_extend(u32 index, const void *in_digest, void *out_digest) return 0; } -u32 tpm_pcr_read(u32 index, void *data, size_t count) +u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count) { const u8 command[14] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xe, 0x0, 0x0, 0x0, 0x15, @@ -264,7 +266,7 @@ u32 tpm_pcr_read(u32 index, void *data, size_t count) 0, command, sizeof(command), index_offset, index)) return TPM_LIB_ERROR; - err = tpm_sendrecv_command(buf, response, &response_length); + err = tpm_sendrecv_command(dev, buf, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "s", @@ -274,7 +276,7 @@ u32 tpm_pcr_read(u32 index, void *data, size_t count) return 0; } -u32 tpm_tsc_physical_presence(u16 presence) +u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence) { const u8 command[12] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x0, 0x0, @@ -287,19 +289,19 @@ u32 tpm_tsc_physical_presence(u16 presence) presence_offset, presence)) return TPM_LIB_ERROR; - return tpm_sendrecv_command(buf, NULL, NULL); + return tpm_sendrecv_command(dev, buf, NULL, NULL); } -u32 tpm_finalise_physical_presence(void) +u32 tpm_finalise_physical_presence(struct udevice *dev) { const u8 command[12] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xc, 0x40, 0x0, 0x0, 0xa, 0x2, 0xa0, }; - return tpm_sendrecv_command(command, NULL, NULL); + return tpm_sendrecv_command(dev, command, NULL, NULL); } -u32 tpm_read_pubek(void *data, size_t count) +u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count) { const u8 command[30] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0x1e, 0x0, 0x0, 0x0, 0x7c, @@ -312,7 +314,7 @@ u32 tpm_read_pubek(void *data, size_t count) u32 data_size; u32 err; - err = tpm_sendrecv_command(command, response, &response_length); + err = tpm_sendrecv_command(dev, command, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "d", @@ -330,34 +332,34 @@ u32 tpm_read_pubek(void *data, size_t count) return 0; } -u32 tpm_force_clear(void) +u32 tpm_force_clear(struct udevice *dev) { const u8 command[10] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x5d, }; - return tpm_sendrecv_command(command, NULL, NULL); + return tpm_sendrecv_command(dev, command, NULL, NULL); } -u32 tpm_physical_enable(void) +u32 tpm_physical_enable(struct udevice *dev) { const u8 command[10] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x6f, }; - return tpm_sendrecv_command(command, NULL, NULL); + return tpm_sendrecv_command(dev, command, NULL, NULL); } -u32 tpm_physical_disable(void) +u32 tpm_physical_disable(struct udevice *dev) { const u8 command[10] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xa, 0x0, 0x0, 0x0, 0x70, }; - return tpm_sendrecv_command(command, NULL, NULL); + return tpm_sendrecv_command(dev, command, NULL, NULL); } -u32 tpm_physical_set_deactivated(u8 state) +u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state) { const u8 command[11] = { 0x0, 0xc1, 0x0, 0x0, 0x0, 0xb, 0x0, 0x0, 0x0, 0x72, @@ -370,10 +372,11 @@ u32 tpm_physical_set_deactivated(u8 state) state_offset, state)) return TPM_LIB_ERROR; - return tpm_sendrecv_command(buf, NULL, NULL); + return tpm_sendrecv_command(dev, buf, NULL, NULL); } -u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count) +u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap, + void *cap, size_t count) { const u8 command[22] = { 0x0, 0xc1, /* TPM_TAG */ @@ -397,7 +400,7 @@ u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count) cap_area_offset, cap_area, sub_cap_offset, sub_cap)) return TPM_LIB_ERROR; - err = tpm_sendrecv_command(buf, response, &response_length); + err = tpm_sendrecv_command(dev, buf, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "d", @@ -412,7 +415,8 @@ u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count) return 0; } -u32 tpm_get_permanent_flags(struct tpm_permanent_flags *pflags) +u32 tpm_get_permanent_flags(struct udevice *dev, + struct tpm_permanent_flags *pflags) { const u8 command[22] = { 0x0, 0xc1, /* TPM_TAG */ @@ -429,7 +433,7 @@ u32 tpm_get_permanent_flags(struct tpm_permanent_flags *pflags) u32 err; u32 data_size; - err = tpm_sendrecv_command(command, response, &response_length); + err = tpm_sendrecv_command(dev, command, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "d", @@ -450,7 +454,7 @@ u32 tpm_get_permanent_flags(struct tpm_permanent_flags *pflags) return 0; } -u32 tpm_get_permissions(u32 index, u32 *perm) +u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm) { const u8 command[22] = { 0x0, 0xc1, /* TPM_TAG */ @@ -468,7 +472,7 @@ u32 tpm_get_permissions(u32 index, u32 *perm) if (pack_byte_string(buf, sizeof(buf), "d", 0, command, sizeof(command), index_offset, index)) return TPM_LIB_ERROR; - err = tpm_sendrecv_command(buf, response, &response_length); + err = tpm_sendrecv_command(dev, buf, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "d", @@ -479,7 +483,7 @@ u32 tpm_get_permissions(u32 index, u32 *perm) } #ifdef CONFIG_TPM_FLUSH_RESOURCES -u32 tpm_flush_specific(u32 key_handle, u32 resource_type) +u32 tpm_flush_specific(struct udevice *dev, u32 key_handle, u32 resource_type) { const u8 command[18] = { 0x00, 0xc1, /* TPM_TAG */ @@ -500,7 +504,7 @@ u32 tpm_flush_specific(u32 key_handle, u32 resource_type) resource_type_offset, resource_type)) return TPM_LIB_ERROR; - err = tpm_sendrecv_command(buf, response, &response_length); + err = tpm_sendrecv_command(dev, buf, response, &response_length); if (err) return err; return 0; @@ -638,7 +642,7 @@ static u32 verify_response_auth(u32 command_code, const void *response, return TPM_SUCCESS; } -u32 tpm_terminate_auth_session(u32 auth_handle) +u32 tpm_terminate_auth_session(struct udevice *dev, u32 auth_handle) { const u8 command[18] = { 0x00, 0xc1, /* TPM_TAG */ @@ -657,19 +661,19 @@ u32 tpm_terminate_auth_session(u32 auth_handle) if (oiap_session.valid && oiap_session.handle == auth_handle) oiap_session.valid = 0; - return tpm_sendrecv_command(request, NULL, NULL); + return tpm_sendrecv_command(dev, request, NULL, NULL); } -u32 tpm_end_oiap(void) +u32 tpm_end_oiap(struct udevice *dev) { u32 err = TPM_SUCCESS; if (oiap_session.valid) - err = tpm_terminate_auth_session(oiap_session.handle); + err = tpm_terminate_auth_session(dev, oiap_session.handle); return err; } -u32 tpm_oiap(u32 *auth_handle) +u32 tpm_oiap(struct udevice *dev, u32 *auth_handle) { const u8 command[10] = { 0x00, 0xc1, /* TPM_TAG */ @@ -683,9 +687,9 @@ u32 tpm_oiap(u32 *auth_handle) u32 err; if (oiap_session.valid) - tpm_terminate_auth_session(oiap_session.handle); + tpm_terminate_auth_session(dev, oiap_session.handle); - err = tpm_sendrecv_command(command, response, &response_length); + err = tpm_sendrecv_command(dev, command, response, &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "ds", @@ -699,8 +703,9 @@ u32 tpm_oiap(u32 *auth_handle) return 0; } -u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length, - const void *parent_key_usage_auth, u32 *key_handle) +u32 tpm_load_key2_oiap(struct udevice *dev, u32 parent_handle, const void *key, + size_t key_length, const void *parent_key_usage_auth, + u32 *key_handle) { const u8 command[14] = { 0x00, 0xc2, /* TPM_TAG */ @@ -719,7 +724,7 @@ u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length, u32 err; if (!oiap_session.valid) { - err = tpm_oiap(NULL); + err = tpm_oiap(dev, NULL); if (err) return err; } @@ -739,7 +744,7 @@ u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length, parent_key_usage_auth); if (err) return err; - err = tpm_sendrecv_command(request, response, &response_length); + err = tpm_sendrecv_command(dev, request, response, &response_length); if (err) { if (err == TPM_AUTHFAIL) oiap_session.valid = 0; @@ -764,7 +769,8 @@ u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length, return 0; } -u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey, +u32 tpm_get_pub_key_oiap(struct udevice *dev, u32 key_handle, + const void *usage_auth, void *pubkey, size_t *pubkey_len) { const u8 command[14] = { @@ -783,7 +789,7 @@ u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey, u32 err; if (!oiap_session.valid) { - err = tpm_oiap(NULL); + err = tpm_oiap(dev, NULL); if (err) return err; } @@ -799,7 +805,7 @@ u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey, request + sizeof(command), usage_auth); if (err) return err; - err = tpm_sendrecv_command(request, response, &response_length); + err = tpm_sendrecv_command(dev, request, response, &response_length); if (err) { if (err == TPM_AUTHFAIL) oiap_session.valid = 0; @@ -829,8 +835,8 @@ u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey, } #ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1 -u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20], - u32 *handle) +u32 tpm_find_key_sha1(struct udevice *dev, const u8 auth[20], + const u8 pubkey_digest[20], u32 *handle) { u16 key_count; u32 key_handles[10]; @@ -842,7 +848,8 @@ u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20], unsigned int i; /* fetch list of already loaded keys in the TPM */ - err = tpm_get_capability(TPM_CAP_HANDLE, TPM_RT_KEY, buf, sizeof(buf)); + err = tpm_get_capability(dev, TPM_CAP_HANDLE, TPM_RT_KEY, buf, + sizeof(buf)); if (err) return -1; key_count = get_unaligned_be16(buf); @@ -870,7 +877,7 @@ u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20], #endif /* CONFIG_TPM_AUTH_SESSIONS */ -u32 tpm_get_random(void *data, u32 count) +u32 tpm_get_random(struct udevice *dev, void *data, u32 count) { const u8 command[14] = { 0x0, 0xc1, /* TPM_TAG */ @@ -894,7 +901,8 @@ u32 tpm_get_random(void *data, u32 count) 0, command, sizeof(command), length_offset, this_bytes)) return TPM_LIB_ERROR; - err = tpm_sendrecv_command(buf, response, &response_length); + err = tpm_sendrecv_command(dev, buf, response, + &response_length); if (err) return err; if (unpack_byte_string(response, response_length, "d", diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index f1bbca8e7a..f89592d6e2 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -10,7 +10,7 @@ #include <tpm-v2.h> #include "tpm-utils.h" -u32 tpm2_startup(enum tpm2_startup_types mode) +u32 tpm2_startup(struct udevice *dev, enum tpm2_startup_types mode) { const u8 command_v2[12] = { tpm_u16(TPM2_ST_NO_SESSIONS), @@ -24,14 +24,14 @@ u32 tpm2_startup(enum tpm2_startup_types mode) * Note TPM2_Startup command will return RC_SUCCESS the first time, * but will return RC_INITIALIZE otherwise. */ - ret = tpm_sendrecv_command(command_v2, NULL, NULL); + ret = tpm_sendrecv_command(dev, command_v2, NULL, NULL); if (ret && ret != TPM2_RC_INITIALIZE) return ret; return 0; } -u32 tpm2_self_test(enum tpm2_yes_no full_test) +u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test) { const u8 command_v2[12] = { tpm_u16(TPM2_ST_NO_SESSIONS), @@ -40,10 +40,11 @@ u32 tpm2_self_test(enum tpm2_yes_no full_test) full_test, }; - return tpm_sendrecv_command(command_v2, NULL, NULL); + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz) +u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, + const ssize_t pw_sz) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_SESSIONS), /* TAG */ @@ -75,10 +76,10 @@ u32 tpm2_clear(u32 handle, const char *pw, const ssize_t pw_sz) if (ret) return TPM_LIB_ERROR; - return tpm_sendrecv_command(command_v2, NULL, NULL); + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_pcr_extend(u32 index, const uint8_t *digest) +u32 tpm2_pcr_extend(struct udevice *dev, u32 index, const uint8_t *digest) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_SESSIONS), /* TAG */ @@ -113,11 +114,11 @@ u32 tpm2_pcr_extend(u32 index, const uint8_t *digest) if (ret) return TPM_LIB_ERROR; - return tpm_sendrecv_command(command_v2, NULL, NULL); + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data, - unsigned int *updates) +u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, + void *data, unsigned int *updates) { u8 idx_array_sz = max(idx_min_sz, DIV_ROUND_UP(idx, 8)); u8 command_v2[COMMAND_BUFFER_SIZE] = { @@ -142,7 +143,7 @@ u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data, 17 + pcr_sel_idx, pcr_sel_bit)) return TPM_LIB_ERROR; - ret = tpm_sendrecv_command(command_v2, response, &response_len); + ret = tpm_sendrecv_command(dev, command_v2, response, &response_len); if (ret) return ret; @@ -158,8 +159,8 @@ u32 tpm2_pcr_read(u32 idx, unsigned int idx_min_sz, void *data, return 0; } -u32 tpm2_get_capability(u32 capability, u32 property, void *buf, - size_t prop_count) +u32 tpm2_get_capability(struct udevice *dev, u32 capability, u32 property, + void *buf, size_t prop_count) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_NO_SESSIONS), /* TAG */ @@ -175,7 +176,7 @@ u32 tpm2_get_capability(u32 capability, u32 property, void *buf, unsigned int properties_off; int ret; - ret = tpm_sendrecv_command(command_v2, response, &response_len); + ret = tpm_sendrecv_command(dev, command_v2, response, &response_len); if (ret) return ret; @@ -191,7 +192,7 @@ u32 tpm2_get_capability(u32 capability, u32 property, void *buf, return 0; } -u32 tpm2_dam_reset(const char *pw, const ssize_t pw_sz) +u32 tpm2_dam_reset(struct udevice *dev, const char *pw, const ssize_t pw_sz) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_SESSIONS), /* TAG */ @@ -223,11 +224,12 @@ u32 tpm2_dam_reset(const char *pw, const ssize_t pw_sz) if (ret) return TPM_LIB_ERROR; - return tpm_sendrecv_command(command_v2, NULL, NULL); + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz, - unsigned int max_tries, unsigned int recovery_time, +u32 tpm2_dam_parameters(struct udevice *dev, const char *pw, + const ssize_t pw_sz, unsigned int max_tries, + unsigned int recovery_time, unsigned int lockout_recovery) { u8 command_v2[COMMAND_BUFFER_SIZE] = { @@ -271,11 +273,12 @@ u32 tpm2_dam_parameters(const char *pw, const ssize_t pw_sz, if (ret) return TPM_LIB_ERROR; - return tpm_sendrecv_command(command_v2, NULL, NULL); + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -int tpm2_change_auth(u32 handle, const char *newpw, const ssize_t newpw_sz, - const char *oldpw, const ssize_t oldpw_sz) +int tpm2_change_auth(struct udevice *dev, u32 handle, const char *newpw, + const ssize_t newpw_sz, const char *oldpw, + const ssize_t oldpw_sz) { unsigned int offset = 27; u8 command_v2[COMMAND_BUFFER_SIZE] = { @@ -315,11 +318,11 @@ int tpm2_change_auth(u32 handle, const char *newpw, const ssize_t newpw_sz, if (ret) return TPM_LIB_ERROR; - return tpm_sendrecv_command(command_v2, NULL, NULL); + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_pcr_setauthpolicy(const char *pw, const ssize_t pw_sz, u32 index, - const char *key) +u32 tpm2_pcr_setauthpolicy(struct udevice *dev, const char *pw, + const ssize_t pw_sz, u32 index, const char *key) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_SESSIONS), /* TAG */ @@ -370,11 +373,12 @@ u32 tpm2_pcr_setauthpolicy(const char *pw, const ssize_t pw_sz, u32 index, if (ret) return TPM_LIB_ERROR; - return tpm_sendrecv_command(command_v2, NULL, NULL); + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } -u32 tpm2_pcr_setauthvalue(const char *pw, const ssize_t pw_sz, u32 index, - const char *key, const ssize_t key_sz) +u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw, + const ssize_t pw_sz, u32 index, const char *key, + const ssize_t key_sz) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_SESSIONS), /* TAG */ @@ -415,5 +419,5 @@ u32 tpm2_pcr_setauthvalue(const char *pw, const ssize_t pw_sz, u32 index, if (ret) return TPM_LIB_ERROR; - return tpm_sendrecv_command(command_v2, NULL, NULL); + return tpm_sendrecv_command(dev, command_v2, NULL, NULL); } |