1 /* SPDX-License-Identifier: BSD-3-Clause */
4 * TPM Lightweight Command Library.
6 * A low-level library for interfacing to TPM hardware or an emulator.
15 #include <security/tpm/tis.h>
16 #include <security/tpm/tss_errors.h>
17 #include <security/tpm/tss/vendor/cr50/cr50.h>
18 #include <security/tpm/tss/tcg-1.2/tss_structures.h>
19 #include <security/tpm/tss/tcg-2.0/tss_structures.h>
20 #include <security/tpm/tss1.h>
21 #include <security/tpm/tss2.h>
24 * Operations that are applicable to both TPM versions have wrappers which
25 * pick the implementation based on version determined during initialization via
28 * Other operations are defined in tss1.h and tss2.h.
32 * Call this first. Returns 0 if success, nonzero if error.
34 tpm_result_t
tlcl_lib_init(void);
37 * Query active TPM family. Returns TPM_UNKNOWN if uninitialized and TPM_1 or TPM_2 otherwise.
39 static inline enum tpm_family
tlcl_get_family(void)
41 /* Defined in tss/tss.c */
42 extern enum tpm_family tlcl_tpm_family
;
44 if (CONFIG(TPM1
) && CONFIG(TPM2
))
45 return tlcl_tpm_family
;
55 #define TLCL_CALL(name, ...) do { \
56 if (tlcl_get_family() == TPM_1) \
57 return tlcl1_##name(__VA_ARGS__); \
58 if (tlcl_get_family() == TPM_2) \
59 return tlcl2_##name(__VA_ARGS__); \
60 return TPM_CB_INTERNAL_INCONSISTENCY; \
64 * Send a TPM_Startup(ST_CLEAR). The TPM error code is returned (0 for
67 static inline tpm_result_t
tlcl_startup(void)
73 * Resume by sending a TPM_Startup(ST_STATE). The TPM error code is returned
76 static inline tpm_result_t
tlcl_resume(void)
82 * Save TPM state by sending either TPM_SaveState() (TPM1.2) or
83 * TPM_Shutdown(ST_STATE) (TPM2.0). The TPM error code is returned (0 for
86 static inline tpm_result_t
tlcl_save_state(void)
88 TLCL_CALL(save_state
);
94 * Note---this is synchronous. To run this in parallel with other firmware,
95 * use ContinueSelfTest(). The TPM error code is returned.
97 static inline tpm_result_t
tlcl_self_test_full(void)
99 TLCL_CALL(self_test_full
);
103 * Write [length] bytes of [data] to space at [index]. The TPM error code is
106 static inline tpm_result_t
tlcl_write(uint32_t index
, const void *data
, uint32_t length
)
108 TLCL_CALL(write
, index
, data
, length
);
112 * Read [length] bytes from space at [index] into [data]. The TPM error code
115 static inline tpm_result_t
tlcl_read(uint32_t index
, void *data
, uint32_t length
)
117 TLCL_CALL(read
, index
, data
, length
);
121 * Assert physical presence in software. The TPM error code is returned.
123 static inline tpm_result_t
tlcl_assert_physical_presence(void)
125 TLCL_CALL(assert_physical_presence
);
129 * Enable the physical presence command. The TPM error code is returned.
131 static inline tpm_result_t
tlcl_physical_presence_cmd_enable(void)
133 TLCL_CALL(physical_presence_cmd_enable
);
137 * Finalize the physical presence settings: software PP is enabled, hardware PP
138 * is disabled, and the lifetime lock is set. The TPM error code is returned.
140 static inline tpm_result_t
tlcl_finalize_physical_presence(void)
142 TLCL_CALL(finalize_physical_presence
);
146 * Issue a ForceClear. The TPM error code is returned.
148 static inline tpm_result_t
tlcl_force_clear(void)
150 TLCL_CALL(force_clear
);
154 * Perform a TPM_Extend.
156 static inline tpm_result_t
tlcl_extend(int pcr_num
, const uint8_t *digest_data
,
157 enum vb2_hash_algorithm digest_algo
)
159 TLCL_CALL(extend
, pcr_num
, digest_data
, digest_algo
);
162 extern tis_sendrecv_fn tlcl_tis_sendrecv
;