1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019 Google LLC
14 static bool is_tpm1(struct udevice *dev)
16 return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1;
19 static bool is_tpm2(struct udevice *dev)
21 return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2;
24 u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode)
27 return tpm1_startup(dev, mode);
28 } else if (is_tpm2(dev)) {
29 enum tpm2_startup_types type;
39 case TPM_ST_DEACTIVATED:
42 return tpm2_startup(dev, type);
48 u32 tpm_resume(struct udevice *dev)
51 return tpm1_startup(dev, TPM_ST_STATE);
52 else if (is_tpm2(dev))
53 return tpm2_startup(dev, TPM2_SU_STATE);
58 u32 tpm_self_test_full(struct udevice *dev)
61 return tpm1_self_test_full(dev);
62 else if (is_tpm2(dev))
63 return tpm2_self_test(dev, TPMI_YES);
68 u32 tpm_continue_self_test(struct udevice *dev)
71 return tpm1_continue_self_test(dev);
72 else if (is_tpm2(dev))
73 return tpm2_self_test(dev, TPMI_NO);
78 u32 tpm_clear_and_reenable(struct udevice *dev)
82 log_info("TPM: Clear and re-enable\n");
83 ret = tpm_force_clear(dev);
84 if (ret != TPM_SUCCESS) {
85 log_err("Can't initiate a force clear\n");
90 ret = tpm1_physical_enable(dev);
91 if (ret != TPM_SUCCESS) {
92 log_err("TPM: Can't set enabled state\n");
96 ret = tpm1_physical_set_deactivated(dev, 0);
97 if (ret != TPM_SUCCESS) {
98 log_err("TPM: Can't set deactivated state\n");
106 u32 tpm_nv_enable_locking(struct udevice *dev)
109 return tpm1_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0);
110 else if (is_tpm2(dev))
116 u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count)
119 return tpm1_nv_read_value(dev, index, data, count);
120 else if (is_tpm2(dev))
121 return tpm2_nv_read_value(dev, index, data, count);
126 u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
130 return tpm1_nv_write_value(dev, index, data, count);
131 else if (is_tpm2(dev))
132 return tpm2_nv_write_value(dev, index, data, count);
137 u32 tpm_set_global_lock(struct udevice *dev)
139 return tpm_nv_write_value(dev, TPM_NV_INDEX_0, NULL, 0);
142 u32 tpm_write_lock(struct udevice *dev, u32 index)
146 else if (is_tpm2(dev))
147 return tpm2_write_lock(dev, index);
152 u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest,
156 return tpm1_extend(dev, index, in_digest, out_digest);
157 else if (is_tpm2(dev))
158 return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest,
164 u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count)
167 return tpm1_pcr_read(dev, index, data, count);
168 else if (is_tpm2(dev))
174 u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence)
177 return tpm1_tsc_physical_presence(dev, presence);
180 * Nothing to do on TPM2 for this; use platform hierarchy availability
183 else if (is_tpm2(dev))
189 u32 tpm_finalise_physical_presence(struct udevice *dev)
192 return tpm1_finalise_physical_presence(dev);
194 /* Nothing needs to be done with tpm2 */
195 else if (is_tpm2(dev))
201 u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count)
204 return tpm1_read_pubek(dev, data, count);
205 else if (is_tpm2(dev))
206 return -ENOSYS; /* not implemented yet */
211 u32 tpm_force_clear(struct udevice *dev)
214 return tpm1_force_clear(dev);
215 else if (is_tpm2(dev))
216 return tpm2_clear(dev, TPM2_RH_PLATFORM, NULL, 0);
221 u32 tpm_physical_enable(struct udevice *dev)
224 return tpm1_physical_enable(dev);
226 /* Nothing needs to be done with tpm2 */
227 else if (is_tpm2(dev))
233 u32 tpm_physical_disable(struct udevice *dev)
236 return tpm1_physical_disable(dev);
238 /* Nothing needs to be done with tpm2 */
239 else if (is_tpm2(dev))
245 u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state)
248 return tpm1_physical_set_deactivated(dev, state);
249 /* Nothing needs to be done with tpm2 */
250 else if (is_tpm2(dev))
256 u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap,
257 void *cap, size_t count)
260 return tpm1_get_capability(dev, cap_area, sub_cap, cap, count);
261 else if (is_tpm2(dev))
262 return tpm2_get_capability(dev, cap_area, sub_cap, cap, count);
267 u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm)
270 return tpm1_get_permissions(dev, index, perm);
271 else if (is_tpm2(dev))
272 return -ENOSYS; /* not implemented yet */
277 u32 tpm_get_random(struct udevice *dev, void *data, u32 count)
280 return tpm1_get_random(dev, data, count);
281 else if (is_tpm2(dev))
282 return -ENOSYS; /* not implemented yet */