coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
tss.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 /*
4  * TPM Lightweight Command Library.
5  *
6  * A low-level library for interfacing to TPM hardware or an emulator.
7  */
8 
9 #ifndef TSS_H_
10 #define TSS_H_
11 
12 #include <types.h>
13 
17 
18 #if CONFIG(TPM1)
19 
21 
22 /**
23  * Define a space with permission [perm]. [index] is the index for the space,
24  * [size] the usable data size. The TPM error code is returned.
25  */
27 
28 /**
29  * Issue a PhysicalEnable. The TPM error code is returned.
30  */
32 
33 /**
34  * Issue a SetDeactivated. Pass 0 to activate. Returns result code.
35  */
37 
38 /**
39  * Get flags of interest. Pointers for flags you aren't interested in may
40  * be NULL. The TPM error code is returned.
41  */
42 uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
43  uint8_t *nvlocked);
44 
45 /**
46  * Get the entire set of permanent flags.
47  */
49 
50 #endif
51 
52 #if CONFIG(TPM2)
53 
55 
56 /*
57  * Define a TPM2 space. The define space command TPM command used by the tlcl
58  * layer offers the ability to use custom nv attributes and policies.
59  */
60 uint32_t tlcl_define_space(uint32_t space_index, size_t space_size,
61  const TPMA_NV nv_attributes,
62  const uint8_t *nv_policy, size_t nv_policy_size);
63 
64 /*
65  * Issue TPM2_GetCapability command
66  */
67 uint32_t tlcl_get_capability(TPM_CAP capability, uint32_t property,
68  uint32_t property_count,
69  TPMS_CAPABILITY_DATA *capability_data);
70 
71 /* Issue TPM2_NV_SetBits command */
73 
74 /*
75  * Makes tpm_process_command available for on top implementations of
76  * custom tpm standards like cr50
77  */
78 void *tpm_process_command(TPM_CC command, void *command_body);
79 
80 /* Return digest size of hash algorithm */
82 
83 #endif
84 
85 /*****************************************************************************/
86 /* Generic Functions implemented in tlcl.c */
87 
88 /**
89  * Call this first. Returns 0 if success, nonzero if error.
90  */
92 
93 /**
94  * Perform a raw TPM request/response transaction.
95  */
96 uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
97  int max_length);
98 
99 /* Commands */
100 
101 /**
102  * Send a TPM_Startup(ST_CLEAR). The TPM error code is returned (0 for
103  * success).
104  */
105 uint32_t tlcl_startup(void);
106 
107 /**
108  * Resume by sending a TPM_Startup(ST_STATE). The TPM error code is returned
109  * (0 for success).
110  */
111 uint32_t tlcl_resume(void);
112 
113 /**
114  * Save TPM state by sending either TPM_SaveState() (TPM1.2) or
115  * TPM_Shutdown(ST_STATE) (TPM2.0). The TPM error code is returned (0 for
116  * success).
117  */
119 
120 /**
121  * Run the self test.
122  *
123  * Note---this is synchronous. To run this in parallel with other firmware,
124  * use ContinueSelfTest(). The TPM error code is returned.
125  */
127 
128 /**
129  * Run the self test in the background.
130  */
132 
133 /**
134  * Write [length] bytes of [data] to space at [index]. The TPM error code is
135  * returned.
136  */
137 uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length);
138 
139 /**
140  * Read [length] bytes from space at [index] into [data]. The TPM error code
141  * is returned.
142  */
143 uint32_t tlcl_read(uint32_t index, void *data, uint32_t length);
144 
145 /**
146  * Assert physical presence in software. The TPM error code is returned.
147  */
149 
150 /**
151  * Enable the physical presence command. The TPM error code is returned.
152  */
154 
155 /**
156  * Finalize the physical presence settings: software PP is enabled, hardware PP
157  * is disabled, and the lifetime lock is set. The TPM error code is returned.
158  */
160 
161 /**
162  * Set the nvLocked bit. The TPM error code is returned.
163  */
165 
166 /**
167  * Issue a ForceClear. The TPM error code is returned.
168  */
170 
171 /**
172  * Set Clear Control. The TPM error code is returned.
173  */
174 uint32_t tlcl_clear_control(bool disable);
175 
176 /**
177  * Set the bGlobalLock flag, which only a reboot can clear. The TPM error
178  * code is returned.
179  */
181 
182 /**
183  * Make an NV Ram location read_only. The TPM error code is returned.
184  */
186 
187 /**
188  * Perform a TPM_Extend.
189  */
190 uint32_t tlcl_extend(int pcr_num, const uint8_t *in_digest,
191  uint8_t *out_digest);
192 
193 /**
194  * Disable platform hierarchy. Specific to TPM2. The TPM error code is returned.
195  */
197 
198 /**
199  * Get the permission bits for the NVRAM space with |index|.
200  */
201 uint32_t tlcl_get_permissions(uint32_t index, uint32_t *permissions);
202 
203 #endif /* TSS_H_ */
uint64_t length
Definition: fw_cfg_if.h:1
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
unsigned char uint8_t
Definition: stdint.h:8
uint32_t tlcl_set_deactivated(uint8_t flag)
Definition: tss.c:285
uint32_t tlcl_set_enable(void)
Definition: tss.c:279
uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
Definition: tss.c:193
uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated, uint8_t *nvlocked)
Definition: tss.c:310
uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags)
Definition: tss.c:294
void * tpm_process_command(TPM_CC command, void *command_body)
Definition: tss.c:19
uint32_t tlcl_set_bits(uint32_t index, uint64_t bits)
Definition: tss.c:323
uint16_t tlcl_get_hash_size_from_algo(TPMI_ALG_HASH hash_algo)
Definition: tss.c:389
uint32_t tlcl_get_capability(TPM_CAP capability, uint32_t property, uint32_t property_count, TPMS_CAPABILITY_DATA *capability_data)
Definition: tss.c:437
TPM_ALG_ID TPMI_ALG_HASH
uint32_t TPM_CAP
uint32_t TPM_CC
uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response, int max_length)
Perform a raw TPM request/response transaction.
Definition: tss.c:104
uint32_t tlcl_set_global_lock(void)
Set the bGlobalLock flag, which only a reboot can clear.
Definition: tss.c:328
uint32_t tlcl_save_state(void)
Save TPM state by sending either TPM_SaveState() (TPM1.2) or TPM_Shutdown(ST_STATE) (TPM2....
Definition: tss.c:172
uint32_t tlcl_assert_physical_presence(void)
Assert physical presence in software.
Definition: tss.c:249
uint32_t tlcl_get_permissions(uint32_t index, uint32_t *permissions)
Get the permission bits for the NVRAM space with |index|.
Definition: tss.c:355
uint32_t tlcl_continue_self_test(void)
Run the self test in the background.
Definition: tss.c:184
uint32_t tlcl_disable_platform_hierarchy(void)
Disable platform hierarchy.
Definition: tss.c:421
uint32_t tlcl_force_clear(void)
Issue a ForceClear.
Definition: tss.c:273
uint32_t tlcl_lock_nv_write(uint32_t index)
Make an NV Ram location read_only.
Definition: tss.c:276
uint32_t tlcl_self_test_full(void)
Run the self test.
Definition: tss.c:178
uint32_t tlcl_finalize_physical_presence(void)
Finalize the physical presence settings: software PP is enabled, hardware PP is disabled,...
Definition: tss.c:261
uint32_t tlcl_clear_control(bool disable)
Set Clear Control.
Definition: tss.c:168
uint32_t tlcl_lib_init(void)
Call this first.
Definition: tss.c:145
uint32_t tlcl_set_nv_locked(void)
Set the nvLocked bit.
Definition: tss.c:267
uint32_t tlcl_startup(void)
Send a TPM_Startup(ST_CLEAR).
Definition: tss.c:160
uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length)
Write [length] bytes of [data] to space at [index].
Definition: tss.c:204
uint32_t tlcl_extend(int pcr_num, const uint8_t *in_digest, uint8_t *out_digest)
Perform a TPM_Extend.
Definition: tss.c:334
uint32_t tlcl_physical_presence_cmd_enable(void)
Enable the physical presence command.
Definition: tss.c:255
uint32_t tlcl_read(uint32_t index, void *data, uint32_t length)
Read [length] bytes from space at [index] into [data].
Definition: tss.c:224
uint32_t tlcl_resume(void)
Resume by sending a TPM_Startup(ST_STATE).
Definition: tss.c:166