Merge tag 'v9.0.0-rc3'
[qemu/ar7.git] / include / sysemu / tpm_backend.h
blob7fabafefee164f2f307a0f879f3510d650ac96e1
1 /*
2 * QEMU TPM Backend
4 * Copyright IBM, Corp. 2013
6 * Authors:
7 * Stefan Berger <stefanb@us.ibm.com>
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.
13 #ifndef TPM_BACKEND_H
14 #define TPM_BACKEND_H
16 #include "qom/object.h"
17 #include "qemu/option.h"
18 #include "sysemu/tpm.h"
19 #include "qapi/error.h"
21 #ifdef CONFIG_TPM
23 #define TYPE_TPM_BACKEND "tpm-backend"
24 OBJECT_DECLARE_TYPE(TPMBackend, TPMBackendClass,
25 TPM_BACKEND)
28 typedef struct TPMBackendCmd {
29 uint8_t locty;
30 const uint8_t *in;
31 uint32_t in_len;
32 uint8_t *out;
33 uint32_t out_len;
34 bool selftest_done;
35 } TPMBackendCmd;
37 struct TPMBackend {
38 Object parent;
40 /*< protected >*/
41 TPMIf *tpmif;
42 bool opened;
43 bool had_startup_error;
44 TPMBackendCmd *cmd;
46 /* <public> */
47 char *id;
49 QLIST_ENTRY(TPMBackend) list;
52 struct TPMBackendClass {
53 ObjectClass parent_class;
55 enum TpmType type;
56 const QemuOptDesc *opts;
57 /* get a descriptive text of the backend to display to the user */
58 const char *desc;
60 TPMBackend *(*create)(QemuOpts *opts);
62 /* start up the TPM on the backend - optional */
63 int (*startup_tpm)(TPMBackend *t, size_t buffersize);
65 /* optional */
66 void (*reset)(TPMBackend *t);
68 void (*cancel_cmd)(TPMBackend *t);
70 /* optional */
71 bool (*get_tpm_established_flag)(TPMBackend *t);
73 /* optional */
74 int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);
76 TPMVersion (*get_tpm_version)(TPMBackend *t);
78 size_t (*get_buffer_size)(TPMBackend *t);
80 TpmTypeOptions *(*get_tpm_options)(TPMBackend *t);
82 void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd, Error **errp);
85 /**
86 * tpm_backend_get_type:
87 * @s: the backend
89 * Returns the TpmType of the backend.
91 enum TpmType tpm_backend_get_type(TPMBackend *s);
93 /**
94 * tpm_backend_init:
95 * @s: the backend to initialized
96 * @tpmif: TPM interface
97 * @datacb: callback for sending data to frontend
98 * @errp: a pointer to return the #Error object if an error occurs.
100 * Initialize the backend with the given variables.
102 * Returns 0 on success.
104 int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp);
107 * tpm_backend_startup_tpm:
108 * @s: the backend whose TPM support is to be started
109 * @buffersize: the buffer size the TPM is supposed to use,
110 * 0 to leave it as-is
112 * Returns 0 on success.
114 int tpm_backend_startup_tpm(TPMBackend *s, size_t buffersize);
117 * tpm_backend_had_startup_error:
118 * @s: the backend to query for a startup error
120 * Check whether the backend had an error during startup. Returns
121 * false if no error occurred and the backend can be used, true
122 * otherwise.
124 bool tpm_backend_had_startup_error(TPMBackend *s);
127 * tpm_backend_deliver_request:
128 * @s: the backend to send the request to
129 * @cmd: the command to deliver
131 * Send a request to the backend. The backend will then send the request
132 * to the TPM implementation.
134 void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd);
137 * tpm_backend_reset:
138 * @s: the backend to reset
140 * Reset the backend into a well defined state with all previous errors
141 * reset.
143 void tpm_backend_reset(TPMBackend *s);
146 * tpm_backend_cancel_cmd:
147 * @s: the backend
149 * Cancel any ongoing command being processed by the TPM implementation
150 * on behalf of the QEMU guest.
152 void tpm_backend_cancel_cmd(TPMBackend *s);
155 * tpm_backend_get_tpm_established_flag:
156 * @s: the backend
158 * Get the TPM establishment flag. This function may be called very
159 * frequently by the frontend since for example in the TIS implementation
160 * this flag is part of a register.
162 bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
165 * tpm_backend_reset_tpm_established_flag:
166 * @s: the backend
167 * @locty: the locality number
169 * Reset the TPM establishment flag.
171 int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty);
174 * tpm_backend_get_tpm_version:
175 * @s: the backend to call into
177 * Get the TPM Version that is emulated at the backend.
179 * Returns TPMVersion.
181 TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
184 * tpm_backend_get_buffer_size:
185 * @s: the backend to call into
187 * Get the TPM's buffer size.
189 * Returns buffer size.
191 size_t tpm_backend_get_buffer_size(TPMBackend *s);
194 * tpm_backend_finish_sync:
195 * @s: the backend to call into
197 * Finish the pending command synchronously (this will call aio_poll()
198 * on qemu main AIOContext until it ends)
200 void tpm_backend_finish_sync(TPMBackend *s);
203 * tpm_backend_query_tpm:
204 * @s: the backend
206 * Query backend tpm info
208 * Returns newly allocated TPMInfo
210 TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
212 TPMBackend *qemu_find_tpm_be(const char *id);
214 #endif /* CONFIG_TPM */
216 #endif /* TPM_BACKEND_H */