1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2019 Google LLC
14 u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode)
17 return tpm1_startup(dev, mode);
18 } else if (tpm_is_v2(dev)) {
19 enum tpm2_startup_types type;
29 case TPM_ST_DEACTIVATED:
32 return tpm2_startup(dev, type);
38 u32 tpm_auto_start(struct udevice *dev)
43 * the tpm_init() will return -EBUSY if the init has already happened
44 * The selftest and startup code can run multiple times with no side
48 if (rc && rc != -EBUSY)
52 return tpm1_auto_start(dev);
53 else if (tpm_is_v2(dev))
54 return tpm2_auto_start(dev);
59 u32 tpm_resume(struct udevice *dev)
62 return tpm1_startup(dev, TPM_ST_STATE);
63 else if (tpm_is_v2(dev))
64 return tpm2_startup(dev, TPM2_SU_STATE);
69 u32 tpm_self_test_full(struct udevice *dev)
72 return tpm1_self_test_full(dev);
73 else if (tpm_is_v2(dev))
74 return tpm2_self_test(dev, TPMI_YES);
79 u32 tpm_continue_self_test(struct udevice *dev)
82 return tpm1_continue_self_test(dev);
83 else if (tpm_is_v2(dev))
84 return tpm2_self_test(dev, TPMI_NO);
89 u32 tpm_clear_and_reenable(struct udevice *dev)
93 log_info("TPM: Clear and re-enable\n");
94 ret = tpm_force_clear(dev);
95 if (ret != TPM_SUCCESS) {
96 log_err("Can't initiate a force clear\n");
100 if (tpm_is_v1(dev)) {
101 ret = tpm1_physical_enable(dev);
102 if (ret != TPM_SUCCESS) {
103 log_err("TPM: Can't set enabled state\n");
107 ret = tpm1_physical_set_deactivated(dev, 0);
108 if (ret != TPM_SUCCESS) {
109 log_err("TPM: Can't set deactivated state\n");
117 u32 tpm_nv_enable_locking(struct udevice *dev)
120 return tpm1_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0);
121 else if (tpm_is_v2(dev))
127 u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count)
130 return tpm1_nv_read_value(dev, index, data, count);
131 else if (tpm_is_v2(dev))
132 return tpm2_nv_read_value(dev, index, data, count);
137 u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
141 return tpm1_nv_write_value(dev, index, data, count);
142 else if (tpm_is_v2(dev))
143 return tpm2_nv_write_value(dev, index, data, count);
148 u32 tpm_set_global_lock(struct udevice *dev)
150 return tpm_nv_write_value(dev, TPM_NV_INDEX_0, NULL, 0);
153 u32 tpm_write_lock(struct udevice *dev, u32 index)
157 else if (tpm_is_v2(dev))
158 return tpm2_write_lock(dev, index);
163 u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest,
164 uint size, void *out_digest, const char *name)
166 if (tpm_is_v1(dev)) {
167 return tpm1_extend(dev, index, in_digest, out_digest);
168 } else if (tpm_is_v2(dev)) {
169 return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest,
171 /* @name is ignored as we do not support the TPM log here */
177 u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count)
180 return tpm1_pcr_read(dev, index, data, count);
181 else if (tpm_is_v2(dev))
187 u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence)
190 return tpm1_tsc_physical_presence(dev, presence);
193 * Nothing to do on TPM2 for this; use platform hierarchy availability
196 else if (tpm_is_v2(dev))
202 u32 tpm_finalise_physical_presence(struct udevice *dev)
205 return tpm1_finalise_physical_presence(dev);
207 /* Nothing needs to be done with tpm2 */
208 else if (tpm_is_v2(dev))
214 u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count)
217 return tpm1_read_pubek(dev, data, count);
218 else if (tpm_is_v2(dev))
219 return -ENOSYS; /* not implemented yet */
224 u32 tpm_force_clear(struct udevice *dev)
227 return tpm1_force_clear(dev);
228 else if (tpm_is_v2(dev))
229 return tpm2_clear(dev, TPM2_RH_PLATFORM, NULL, 0);
234 u32 tpm_physical_enable(struct udevice *dev)
237 return tpm1_physical_enable(dev);
239 /* Nothing needs to be done with tpm2 */
240 else if (tpm_is_v2(dev))
246 u32 tpm_physical_disable(struct udevice *dev)
249 return tpm1_physical_disable(dev);
251 /* Nothing needs to be done with tpm2 */
252 else if (tpm_is_v2(dev))
258 u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state)
261 return tpm1_physical_set_deactivated(dev, state);
262 /* Nothing needs to be done with tpm2 */
263 else if (tpm_is_v2(dev))
269 u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap,
270 void *cap, size_t count)
273 return tpm1_get_capability(dev, cap_area, sub_cap, cap, count);
274 else if (tpm_is_v2(dev))
275 return tpm2_get_capability(dev, cap_area, sub_cap, cap, count);
280 u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm)
283 return tpm1_get_permissions(dev, index, perm);
284 else if (tpm_is_v2(dev))
285 return -ENOSYS; /* not implemented yet */
290 u32 tpm_get_random(struct udevice *dev, void *data, u32 count)
293 return tpm1_get_random(dev, data, count);
294 else if (tpm_is_v2(dev))
295 return tpm2_get_random(dev, data, count);