xref: /rk3399_rockchip-uboot/include/tpm.h (revision d2eae43ba803cff75b44a07d08d718ecdecdee94)
1 /*
2  * Copyright (c) 2013 The Chromium OS Authors.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22 
23 #ifndef __TPM_H
24 #define __TPM_H
25 
26 #include <tis.h>
27 
28 /*
29  * Here is a partial implementation of TPM commands.  Please consult TCG Main
30  * Specification for definitions of TPM commands.
31  */
32 
33 enum tpm_startup_type {
34 	TPM_ST_CLEAR		= 0x0001,
35 	TPM_ST_STATE		= 0x0002,
36 	TPM_ST_DEACTIVATED	= 0x0003,
37 };
38 
39 enum tpm_physical_presence {
40 	TPM_PHYSICAL_PRESENCE_HW_DISABLE	= 0x0200,
41 	TPM_PHYSICAL_PRESENCE_CMD_DISABLE	= 0x0100,
42 	TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK	= 0x0080,
43 	TPM_PHYSICAL_PRESENCE_HW_ENABLE		= 0x0040,
44 	TPM_PHYSICAL_PRESENCE_CMD_ENABLE	= 0x0020,
45 	TPM_PHYSICAL_PRESENCE_NOTPRESENT	= 0x0010,
46 	TPM_PHYSICAL_PRESENCE_PRESENT		= 0x0008,
47 	TPM_PHYSICAL_PRESENCE_LOCK		= 0x0004,
48 };
49 
50 enum tpm_nv_index {
51 	TPM_NV_INDEX_LOCK	= 0xffffffff,
52 	TPM_NV_INDEX_0		= 0x00000000,
53 	TPM_NV_INDEX_DIR	= 0x10000001,
54 };
55 
56 /**
57  * Initialize TPM device.  It must be called before any TPM commands.
58  *
59  * @return 0 on success, non-0 on error.
60  */
61 uint32_t tpm_init(void);
62 
63 /**
64  * Issue a TPM_Startup command.
65  *
66  * @param mode		TPM startup mode
67  * @return return code of the operation
68  */
69 uint32_t tpm_startup(enum tpm_startup_type mode);
70 
71 /**
72  * Issue a TPM_SelfTestFull command.
73  *
74  * @return return code of the operation
75  */
76 uint32_t tpm_self_test_full(void);
77 
78 /**
79  * Issue a TPM_ContinueSelfTest command.
80  *
81  * @return return code of the operation
82  */
83 uint32_t tpm_continue_self_test(void);
84 
85 /**
86  * Issue a TPM_NV_DefineSpace command.  The implementation is limited
87  * to specify TPM_NV_ATTRIBUTES and size of the area.  The area index
88  * could be one of the special value listed in enum tpm_nv_index.
89  *
90  * @param index		index of the area
91  * @param perm		TPM_NV_ATTRIBUTES of the area
92  * @param size		size of the area
93  * @return return code of the operation
94  */
95 uint32_t tpm_nv_define_space(uint32_t index, uint32_t perm, uint32_t size);
96 
97 /**
98  * Issue a TPM_NV_ReadValue command.  This implementation is limited
99  * to read the area from offset 0.  The area index could be one of
100  * the special value listed in enum tpm_nv_index.
101  *
102  * @param index		index of the area
103  * @param data		output buffer of the area contents
104  * @param count		size of output buffer
105  * @return return code of the operation
106  */
107 uint32_t tpm_nv_read_value(uint32_t index, void *data, uint32_t count);
108 
109 /**
110  * Issue a TPM_NV_WriteValue command.  This implementation is limited
111  * to write the area from offset 0.  The area index could be one of
112  * the special value listed in enum tpm_nv_index.
113  *
114  * @param index		index of the area
115  * @param data		input buffer to be wrote to the area
116  * @param length	length of data bytes of input buffer
117  * @return return code of the operation
118  */
119 uint32_t tpm_nv_write_value(uint32_t index, const void *data, uint32_t length);
120 
121 /**
122  * Issue a TPM_Extend command.
123  *
124  * @param index		index of the PCR
125  * @param in_digest	160-bit value representing the event to be
126  *			recorded
127  * @param out_digest	160-bit PCR value after execution of the
128  *			command
129  * @return return code of the operation
130  */
131 uint32_t tpm_extend(uint32_t index, const void *in_digest, void *out_digest);
132 
133 /**
134  * Issue a TPM_PCRRead command.
135  *
136  * @param index		index of the PCR
137  * @param data		output buffer for contents of the named PCR
138  * @param count		size of output buffer
139  * @return return code of the operation
140  */
141 uint32_t tpm_pcr_read(uint32_t index, void *data, size_t count);
142 
143 /**
144  * Issue a TSC_PhysicalPresence command.  TPM physical presence flag
145  * is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
146  *
147  * @param presence	TPM physical presence flag
148  * @return return code of the operation
149  */
150 uint32_t tpm_tsc_physical_presence(uint16_t presence);
151 
152 /**
153  * Issue a TPM_ReadPubek command.
154  *
155  * @param data		output buffer for the public endorsement key
156  * @param count		size of ouput buffer
157  * @return return code of the operation
158  */
159 uint32_t tpm_read_pubek(void *data, size_t count);
160 
161 /**
162  * Issue a TPM_ForceClear command.
163  *
164  * @return return code of the operation
165  */
166 uint32_t tpm_force_clear(void);
167 
168 /**
169  * Issue a TPM_PhysicalEnable command.
170  *
171  * @return return code of the operation
172  */
173 uint32_t tpm_physical_enable(void);
174 
175 /**
176  * Issue a TPM_PhysicalDisable command.
177  *
178  * @return return code of the operation
179  */
180 uint32_t tpm_physical_disable(void);
181 
182 /**
183  * Issue a TPM_PhysicalSetDeactivated command.
184  *
185  * @param state		boolean state of the deactivated flag
186  * @return return code of the operation
187  */
188 uint32_t tpm_physical_set_deactivated(uint8_t state);
189 
190 /**
191  * Issue a TPM_GetCapability command.  This implementation is limited
192  * to query sub_cap index that is 4-byte wide.
193  *
194  * @param cap_area	partition of capabilities
195  * @param sub_cap	further definition of capability, which is
196  *			limited to be 4-byte wide
197  * @param cap		output buffer for capability information
198  * @param count		size of ouput buffer
199  * @return return code of the operation
200  */
201 uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap,
202 		void *cap, size_t count);
203 
204 #endif /* __TPM_H */
205