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_resume(struct udevice *dev)
41 return tpm1_startup(dev, TPM_ST_STATE);
42 else if (tpm_is_v2(dev))
43 return tpm2_startup(dev, TPM2_SU_STATE);
48 u32 tpm_self_test_full(struct udevice *dev)
51 return tpm1_self_test_full(dev);
52 else if (tpm_is_v2(dev))
53 return tpm2_self_test(dev, TPMI_YES);
58 u32 tpm_continue_self_test(struct udevice *dev)
61 return tpm1_continue_self_test(dev);
62 else if (tpm_is_v2(dev))
63 return tpm2_self_test(dev, TPMI_NO);
68 u32 tpm_clear_and_reenable(struct udevice *dev)
72 log_info("TPM: Clear and re-enable\n");
73 ret = tpm_force_clear(dev);
74 if (ret != TPM_SUCCESS) {
75 log_err("Can't initiate a force clear\n");
80 ret = tpm1_physical_enable(dev);
81 if (ret != TPM_SUCCESS) {
82 log_err("TPM: Can't set enabled state\n");
86 ret = tpm1_physical_set_deactivated(dev, 0);
87 if (ret != TPM_SUCCESS) {
88 log_err("TPM: Can't set deactivated state\n");
96 u32 tpm_nv_enable_locking(struct udevice *dev)
99 return tpm1_nv_define_space(dev, TPM_NV_INDEX_LOCK, 0, 0);
100 else if (tpm_is_v2(dev))
106 u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count)
109 return tpm1_nv_read_value(dev, index, data, count);
110 else if (tpm_is_v2(dev))
111 return tpm2_nv_read_value(dev, index, data, count);
116 u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
120 return tpm1_nv_write_value(dev, index, data, count);
121 else if (tpm_is_v2(dev))
122 return tpm2_nv_write_value(dev, index, data, count);
127 u32 tpm_set_global_lock(struct udevice *dev)
129 return tpm_nv_write_value(dev, TPM_NV_INDEX_0, NULL, 0);
132 u32 tpm_write_lock(struct udevice *dev, u32 index)
136 else if (tpm_is_v2(dev))
137 return tpm2_write_lock(dev, index);
142 u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest,
143 uint size, void *out_digest, const char *name)
145 if (tpm_is_v1(dev)) {
146 return tpm1_extend(dev, index, in_digest, out_digest);
147 } else if (tpm_is_v2(dev)) {
148 return tpm2_pcr_extend(dev, index, TPM2_ALG_SHA256, in_digest,
150 /* @name is ignored as we do not support the TPM log here */
156 u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count)
159 return tpm1_pcr_read(dev, index, data, count);
160 else if (tpm_is_v2(dev))
166 u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence)
169 return tpm1_tsc_physical_presence(dev, presence);
172 * Nothing to do on TPM2 for this; use platform hierarchy availability
175 else if (tpm_is_v2(dev))
181 u32 tpm_finalise_physical_presence(struct udevice *dev)
184 return tpm1_finalise_physical_presence(dev);
186 /* Nothing needs to be done with tpm2 */
187 else if (tpm_is_v2(dev))
193 u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count)
196 return tpm1_read_pubek(dev, data, count);
197 else if (tpm_is_v2(dev))
198 return -ENOSYS; /* not implemented yet */
203 u32 tpm_force_clear(struct udevice *dev)
206 return tpm1_force_clear(dev);
207 else if (tpm_is_v2(dev))
208 return tpm2_clear(dev, TPM2_RH_PLATFORM, NULL, 0);
213 u32 tpm_physical_enable(struct udevice *dev)
216 return tpm1_physical_enable(dev);
218 /* Nothing needs to be done with tpm2 */
219 else if (tpm_is_v2(dev))
225 u32 tpm_physical_disable(struct udevice *dev)
228 return tpm1_physical_disable(dev);
230 /* Nothing needs to be done with tpm2 */
231 else if (tpm_is_v2(dev))
237 u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state)
240 return tpm1_physical_set_deactivated(dev, state);
241 /* Nothing needs to be done with tpm2 */
242 else if (tpm_is_v2(dev))
248 u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap,
249 void *cap, size_t count)
252 return tpm1_get_capability(dev, cap_area, sub_cap, cap, count);
253 else if (tpm_is_v2(dev))
254 return tpm2_get_capability(dev, cap_area, sub_cap, cap, count);
259 u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm)
262 return tpm1_get_permissions(dev, index, perm);
263 else if (tpm_is_v2(dev))
264 return -ENOSYS; /* not implemented yet */
269 u32 tpm_get_random(struct udevice *dev, void *data, u32 count)
272 return tpm1_get_random(dev, data, count);
273 else if (tpm_is_v2(dev))
274 return tpm2_get_random(dev, data, count);