]>
Commit | Line | Data |
---|---|---|
8f0605cc SB |
1 | /* |
2 | * QEMU TPM Backend | |
3 | * | |
4 | * Copyright IBM, Corp. 2013 | |
5 | * | |
6 | * Authors: | |
7 | * Stefan Berger <stefanb@us.ibm.com> | |
8 | * | |
9 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
10 | * See the COPYING file in the top-level directory. | |
11 | */ | |
12 | ||
121d0712 MA |
13 | #ifndef TPM_BACKEND_H |
14 | #define TPM_BACKEND_H | |
8f0605cc SB |
15 | |
16 | #include "qom/object.h" | |
17 | #include "qemu-common.h" | |
8f0605cc SB |
18 | #include "qapi-types.h" |
19 | #include "qemu/option.h" | |
bdee56f5 | 20 | #include "sysemu/tpm.h" |
8f0605cc SB |
21 | |
22 | #define TYPE_TPM_BACKEND "tpm-backend" | |
23 | #define TPM_BACKEND(obj) \ | |
24 | OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND) | |
25 | #define TPM_BACKEND_GET_CLASS(obj) \ | |
26 | OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND) | |
27 | #define TPM_BACKEND_CLASS(klass) \ | |
28 | OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND) | |
29 | ||
30 | typedef struct TPMBackendClass TPMBackendClass; | |
31 | typedef struct TPMBackend TPMBackend; | |
d31076ba | 32 | |
0e43b7e6 MAL |
33 | typedef struct TPMBackendCmd { |
34 | uint8_t locty; | |
35 | const uint8_t *in; | |
36 | uint32_t in_len; | |
37 | uint8_t *out; | |
38 | uint32_t out_len; | |
39 | bool selftest_done; | |
40 | } TPMBackendCmd; | |
8f0605cc | 41 | |
8f0605cc SB |
42 | struct TPMBackend { |
43 | Object parent; | |
44 | ||
45 | /*< protected >*/ | |
8a89c9ac | 46 | TPMIf *tpmif; |
8f0605cc | 47 | bool opened; |
93330cf5 | 48 | bool had_startup_error; |
c4fb8561 | 49 | TPMBackendCmd *cmd; |
8f0605cc | 50 | |
f59864ba | 51 | /* <public> */ |
8f0605cc | 52 | char *id; |
8f0605cc SB |
53 | |
54 | QLIST_ENTRY(TPMBackend) list; | |
55 | }; | |
56 | ||
b19a5eea AV |
57 | struct TPMBackendClass { |
58 | ObjectClass parent_class; | |
59 | ||
bdee56f5 | 60 | enum TpmType type; |
bb716238 | 61 | const QemuOptDesc *opts; |
bdee56f5 | 62 | /* get a descriptive text of the backend to display to the user */ |
93330cf5 | 63 | const char *desc; |
bdee56f5 | 64 | |
9f7c0ef2 | 65 | TPMBackend *(*create)(QemuOpts *opts); |
bdee56f5 | 66 | |
ebca2df7 | 67 | /* start up the TPM on the backend - optional */ |
9375c44f | 68 | int (*startup_tpm)(TPMBackend *t, size_t buffersize); |
bdee56f5 | 69 | |
ebca2df7 | 70 | /* optional */ |
bdee56f5 PB |
71 | void (*reset)(TPMBackend *t); |
72 | ||
73 | void (*cancel_cmd)(TPMBackend *t); | |
74 | ||
ebca2df7 | 75 | /* optional */ |
bdee56f5 | 76 | bool (*get_tpm_established_flag)(TPMBackend *t); |
116694c3 | 77 | |
ebca2df7 | 78 | /* optional */ |
116694c3 SB |
79 | int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty); |
80 | ||
81 | TPMVersion (*get_tpm_version)(TPMBackend *t); | |
f59864ba | 82 | |
b21e6aaf SB |
83 | size_t (*get_buffer_size)(TPMBackend *t); |
84 | ||
f59864ba | 85 | TpmTypeOptions *(*get_tpm_options)(TPMBackend *t); |
bdee56f5 | 86 | |
0e43b7e6 | 87 | void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd); |
d31076ba | 88 | }; |
8f0605cc SB |
89 | |
90 | /** | |
91 | * tpm_backend_get_type: | |
92 | * @s: the backend | |
93 | * | |
94 | * Returns the TpmType of the backend. | |
95 | */ | |
96 | enum TpmType tpm_backend_get_type(TPMBackend *s); | |
97 | ||
8f0605cc SB |
98 | /** |
99 | * tpm_backend_init: | |
100 | * @s: the backend to initialized | |
8a89c9ac | 101 | * @tpmif: TPM interface |
8f0605cc | 102 | * @datacb: callback for sending data to frontend |
0bd6c8a9 | 103 | * @errp: a pointer to return the #Error object if an error occurs. |
8f0605cc SB |
104 | * |
105 | * Initialize the backend with the given variables. | |
106 | * | |
107 | * Returns 0 on success. | |
108 | */ | |
0bd6c8a9 | 109 | int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp); |
8f0605cc SB |
110 | |
111 | /** | |
112 | * tpm_backend_startup_tpm: | |
113 | * @s: the backend whose TPM support is to be started | |
9375c44f SB |
114 | * @buffersize: the buffer size the TPM is supposed to use, |
115 | * 0 to leave it as-is | |
8f0605cc SB |
116 | * |
117 | * Returns 0 on success. | |
118 | */ | |
9375c44f | 119 | int tpm_backend_startup_tpm(TPMBackend *s, size_t buffersize); |
8f0605cc SB |
120 | |
121 | /** | |
122 | * tpm_backend_had_startup_error: | |
123 | * @s: the backend to query for a statup error | |
124 | * | |
125 | * Check whether the backend had an error during startup. Returns | |
126 | * false if no error occurred and the backend can be used, true | |
127 | * otherwise. | |
128 | */ | |
129 | bool tpm_backend_had_startup_error(TPMBackend *s); | |
130 | ||
8f0605cc SB |
131 | /** |
132 | * tpm_backend_deliver_request: | |
133 | * @s: the backend to send the request to | |
0e43b7e6 | 134 | * @cmd: the command to deliver |
8f0605cc SB |
135 | * |
136 | * Send a request to the backend. The backend will then send the request | |
137 | * to the TPM implementation. | |
138 | */ | |
0e43b7e6 | 139 | void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd); |
8f0605cc SB |
140 | |
141 | /** | |
142 | * tpm_backend_reset: | |
143 | * @s: the backend to reset | |
144 | * | |
145 | * Reset the backend into a well defined state with all previous errors | |
146 | * reset. | |
147 | */ | |
148 | void tpm_backend_reset(TPMBackend *s); | |
149 | ||
150 | /** | |
151 | * tpm_backend_cancel_cmd: | |
152 | * @s: the backend | |
153 | * | |
154 | * Cancel any ongoing command being processed by the TPM implementation | |
155 | * on behalf of the QEMU guest. | |
156 | */ | |
157 | void tpm_backend_cancel_cmd(TPMBackend *s); | |
158 | ||
159 | /** | |
160 | * tpm_backend_get_tpm_established_flag: | |
161 | * @s: the backend | |
162 | * | |
163 | * Get the TPM establishment flag. This function may be called very | |
164 | * frequently by the frontend since for example in the TIS implementation | |
165 | * this flag is part of a register. | |
166 | */ | |
167 | bool tpm_backend_get_tpm_established_flag(TPMBackend *s); | |
168 | ||
116694c3 SB |
169 | /** |
170 | * tpm_backend_reset_tpm_established_flag: | |
171 | * @s: the backend | |
172 | * @locty: the locality number | |
173 | * | |
174 | * Reset the TPM establishment flag. | |
175 | */ | |
176 | int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty); | |
177 | ||
116694c3 SB |
178 | /** |
179 | * tpm_backend_get_tpm_version: | |
180 | * @s: the backend to call into | |
181 | * | |
182 | * Get the TPM Version that is emulated at the backend. | |
183 | * | |
184 | * Returns TPMVersion. | |
185 | */ | |
186 | TPMVersion tpm_backend_get_tpm_version(TPMBackend *s); | |
187 | ||
b21e6aaf SB |
188 | /** |
189 | * tpm_backend_get_buffer_size: | |
190 | * @s: the backend to call into | |
191 | * | |
192 | * Get the TPM's buffer size. | |
193 | * | |
194 | * Returns buffer size. | |
195 | */ | |
196 | size_t tpm_backend_get_buffer_size(TPMBackend *s); | |
197 | ||
c4fb8561 MAL |
198 | /** |
199 | * tpm_backend_finish_sync: | |
200 | * @s: the backend to call into | |
201 | * | |
202 | * Finish the pending command synchronously (this will call aio_poll() | |
203 | * on qemu main AIOContext until it ends) | |
204 | */ | |
205 | void tpm_backend_finish_sync(TPMBackend *s); | |
206 | ||
f59864ba AV |
207 | /** |
208 | * tpm_backend_query_tpm: | |
209 | * @s: the backend | |
210 | * | |
211 | * Query backend tpm info | |
212 | * | |
213 | * Returns newly allocated TPMInfo | |
214 | */ | |
215 | TPMInfo *tpm_backend_query_tpm(TPMBackend *s); | |
216 | ||
d36e7db1 | 217 | TPMBackend *qemu_find_tpm_be(const char *id); |
bdee56f5 | 218 | |
8f0605cc | 219 | #endif |