blob: 8979d9d6df7ef8caec8b9dd6287c7b23c1d805f7 [file] [log] [blame]
Simon Glassbfe8fa22021-02-06 14:23:35 -07001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (c) 2013 The Chromium OS Authors.
4 * Coypright (c) 2013 Guntermann & Drunck GmbH
5 */
6
7#ifndef __TPM_API_H
8#define __TPM_API_H
9
10#include <tpm-common.h>
11#include <tpm-v1.h>
12#include <tpm-v2.h>
13
14/**
15 * Issue a TPM_Startup command.
16 *
17 * @param dev TPM device
18 * @param mode TPM startup mode
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010019 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -070020 */
21u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode);
22
23/**
24 * Issue a TPM_SelfTestFull command.
25 *
26 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010027 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -070028 */
29u32 tpm_self_test_full(struct udevice *dev);
30
31/**
32 * Issue a TPM_ContinueSelfTest command.
33 *
34 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010035 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -070036 */
37u32 tpm_continue_self_test(struct udevice *dev);
38
39/**
40 * Issue a TPM_NV_DefineSpace command. The implementation is limited
41 * to specify TPM_NV_ATTRIBUTES and size of the area. The area index
42 * could be one of the special value listed in enum tpm_nv_index.
43 *
44 * @param dev TPM device
45 * @param index index of the area
46 * @param perm TPM_NV_ATTRIBUTES of the area
47 * @param size size of the area
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010048 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -070049 */
50u32 tpm_nv_define_space(struct udevice *dev, u32 index, u32 perm, u32 size);
51
52/**
53 * Issue a TPM_NV_ReadValue command. This implementation is limited
54 * to read the area from offset 0. The area index could be one of
55 * the special value listed in enum tpm_nv_index.
56 *
57 * @param dev TPM device
58 * @param index index of the area
59 * @param data output buffer of the area contents
60 * @param count size of output buffer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010061 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -070062 */
63u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count);
64
65/**
66 * Issue a TPM_NV_WriteValue command. This implementation is limited
67 * to write the area from offset 0. The area index could be one of
68 * the special value listed in enum tpm_nv_index.
69 *
70 * @param dev TPM device
71 * @param index index of the area
72 * @param data input buffer to be wrote to the area
73 * @param length length of data bytes of input buffer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010074 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -070075 */
76u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
77 u32 length);
78
79/**
80 * Issue a TPM_Extend command.
81 *
82 * @param dev TPM device
83 * @param index index of the PCR
Simon Glassa557d252022-08-30 21:05:32 -060084 * @param in_digest 160/256-bit value representing the event to be
Simon Glassbfe8fa22021-02-06 14:23:35 -070085 * recorded
Simon Glassa557d252022-08-30 21:05:32 -060086 * @param size size of digest in bytes
87 * @param out_digest 160/256-bit PCR value after execution of the
Simon Glassbfe8fa22021-02-06 14:23:35 -070088 * command
Simon Glassa557d252022-08-30 21:05:32 -060089 * @param name digest source, used for log output
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010090 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -070091 */
92u32 tpm_pcr_extend(struct udevice *dev, u32 index, const void *in_digest,
Simon Glassa557d252022-08-30 21:05:32 -060093 uint size, void *out_digest, const char *name);
Simon Glassbfe8fa22021-02-06 14:23:35 -070094
95/**
96 * Issue a TPM_PCRRead command.
97 *
98 * @param dev TPM device
99 * @param index index of the PCR
100 * @param data output buffer for contents of the named PCR
101 * @param count size of output buffer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100102 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700103 */
104u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count);
105
106/**
107 * Issue a TSC_PhysicalPresence command. TPM physical presence flag
108 * is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
109 *
110 * @param dev TPM device
111 * @param presence TPM physical presence flag
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100112 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700113 */
114u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence);
115
116/**
117 * Issue a TPM_ReadPubek command.
118 *
119 * @param dev TPM device
120 * @param data output buffer for the public endorsement key
121 * @param count size of output buffer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100122 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700123 */
124u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count);
125
126/**
127 * Issue a TPM_ForceClear command.
128 *
129 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100130 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700131 */
132u32 tpm_force_clear(struct udevice *dev);
133
134/**
135 * Issue a TPM_PhysicalEnable command.
136 *
137 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100138 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700139 */
140u32 tpm_physical_enable(struct udevice *dev);
141
142/**
143 * Issue a TPM_PhysicalDisable command.
144 *
145 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100146 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700147 */
148u32 tpm_physical_disable(struct udevice *dev);
149
150/**
151 * Issue a TPM_PhysicalSetDeactivated command.
152 *
153 * @param dev TPM device
154 * @param state boolean state of the deactivated flag
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100155 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700156 */
157u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state);
158
159/**
160 * Issue a TPM_GetCapability command. This implementation is limited
161 * to query sub_cap index that is 4-byte wide.
162 *
163 * @param dev TPM device
164 * @param cap_area partition of capabilities
165 * @param sub_cap further definition of capability, which is
166 * limited to be 4-byte wide
167 * @param cap output buffer for capability information
168 * @param count size of output buffer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100169 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700170 */
171u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap,
172 void *cap, size_t count);
173
174/**
175 * Issue a TPM_FlushSpecific command for a AUTH resource.
176 *
177 * @param dev TPM device
178 * @param auth_handle handle of the auth session
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100179 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700180 */
181u32 tpm_terminate_auth_session(struct udevice *dev, u32 auth_handle);
182
183/**
184 * Issue a TPM_OIAP command to setup an object independent authorization
185 * session.
186 * Information about the session is stored internally.
187 * If there was already an OIAP session active it is terminated and a new
188 * session is set up.
189 *
190 * @param dev TPM device
191 * @param auth_handle pointer to the (new) auth handle or NULL.
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100192 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700193 */
194u32 tpm_oiap(struct udevice *dev, u32 *auth_handle);
195
196/**
197 * Ends an active OIAP session.
198 *
199 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100200 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700201 */
202u32 tpm_end_oiap(struct udevice *dev);
203
204/**
205 * Issue a TPM_LoadKey2 (Auth1) command using an OIAP session for authenticating
206 * the usage of the parent key.
207 *
208 * @param dev TPM device
209 * @param parent_handle handle of the parent key.
210 * @param key pointer to the key structure (TPM_KEY or TPM_KEY12).
211 * @param key_length size of the key structure
212 * @param parent_key_usage_auth usage auth for the parent key
213 * @param key_handle pointer to the key handle
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100214 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700215 */
216u32 tpm_load_key2_oiap(struct udevice *dev, u32 parent_handle, const void *key,
217 size_t key_length, const void *parent_key_usage_auth,
218 u32 *key_handle);
219
220/**
221 * Issue a TPM_GetPubKey (Auth1) command using an OIAP session for
222 * authenticating the usage of the key.
223 *
224 * @param dev TPM device
225 * @param key_handle handle of the key
226 * @param usage_auth usage auth for the key
227 * @param pubkey pointer to the pub key buffer; may be NULL if the pubkey
228 * should not be stored.
229 * @param pubkey_len pointer to the pub key buffer len. On entry: the size of
230 * the provided pubkey buffer. On successful exit: the size
231 * of the stored TPM_PUBKEY structure (iff pubkey != NULL).
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100232 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700233 */
234u32 tpm_get_pub_key_oiap(struct udevice *dev, u32 key_handle,
235 const void *usage_auth, void *pubkey,
236 size_t *pubkey_len);
237
238/**
239 * Get the TPM permissions
240 *
241 * @param dev TPM device
242 * @param perm Returns permissions value
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100243 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700244 */
245u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm);
246
247/**
248 * Flush a resource with a given handle and type from the TPM
249 *
250 * @param dev TPM device
251 * @param key_handle handle of the resource
252 * @param resource_type type of the resource
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100253 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700254 */
255u32 tpm_flush_specific(struct udevice *dev, u32 key_handle, u32 resource_type);
256
257#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
258/**
259 * Search for a key by usage AuthData and the hash of the parent's pub key.
260 *
261 * @param dev TPM device
262 * @param auth Usage auth of the key to search for
263 * @param pubkey_digest SHA1 hash of the pub key structure of the key
264 * @param[out] handle The handle of the key (Non-null iff found)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100265 * Return: 0 if key was found in TPM; != 0 if not.
Simon Glassbfe8fa22021-02-06 14:23:35 -0700266 */
267u32 tpm_find_key_sha1(struct udevice *dev, const u8 auth[20],
268 const u8 pubkey_digest[20], u32 *handle);
269#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
270
271/**
272 * Read random bytes from the TPM RNG. The implementation deals with the fact
273 * that the TPM may legally return fewer bytes than requested by retrying
274 * until @p count bytes have been received.
275 *
276 * @param dev TPM device
277 * @param data output buffer for the random bytes
278 * @param count size of output buffer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100279 * Return: return code of the operation
Simon Glassbfe8fa22021-02-06 14:23:35 -0700280 */
281u32 tpm_get_random(struct udevice *dev, void *data, u32 count);
282
283/**
284 * tpm_finalise_physical_presence() - Finalise physical presence
285 *
286 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100287 * Return: return code of the operation (0 = success)
Simon Glassbfe8fa22021-02-06 14:23:35 -0700288 */
289u32 tpm_finalise_physical_presence(struct udevice *dev);
290
291/**
292 * tpm_nv_enable_locking() - lock the non-volatile space
293 *
294 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100295 * Return: return code of the operation (0 = success)
Simon Glassbfe8fa22021-02-06 14:23:35 -0700296 */
297u32 tpm_nv_enable_locking(struct udevice *dev);
298
299/**
300 * tpm_set_global_lock() - set the global lock
301 *
302 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100303 * Return: return code of the operation (0 = success)
Simon Glassbfe8fa22021-02-06 14:23:35 -0700304 */
305u32 tpm_set_global_lock(struct udevice *dev);
306
307/**
308 * tpm_write_lock() - lock the non-volatile space
309 *
310 * @param dev TPM device
311 * @param index Index of space to lock
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100312 * Return: return code of the operation (0 = success)
Simon Glassbfe8fa22021-02-06 14:23:35 -0700313 */
314u32 tpm_write_lock(struct udevice *dev, u32 index);
315
316/**
317 * tpm_resume() - start up the TPM from resume (after suspend)
318 *
319 * @param dev TPM device
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100320 * Return: return code of the operation (0 = success)
Simon Glassbfe8fa22021-02-06 14:23:35 -0700321 */
322u32 tpm_resume(struct udevice *dev);
323
Simon Glass5e593782022-07-22 21:32:02 +0530324static inline bool tpm_is_v1(struct udevice *dev)
325{
326 return IS_ENABLED(CONFIG_TPM_V1) && tpm_get_version(dev) == TPM_V1;
327}
328
329static inline bool tpm_is_v2(struct udevice *dev)
330{
331 return IS_ENABLED(CONFIG_TPM_V2) && tpm_get_version(dev) == TPM_V2;
332}
333
Simon Glassbfe8fa22021-02-06 14:23:35 -0700334#endif /* __TPM_API_H */