iotests/129: Do not check @busy
[qemu.git] / include / sysemu / tpm_backend.h
blob6f078f5f4829ff55af09b87aa48ddbe38a1ce2f1
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 #define TYPE_TPM_BACKEND "tpm-backend"
22 OBJECT_DECLARE_TYPE(TPMBackend, TPMBackendClass,
23 TPM_BACKEND)
26 typedef struct TPMBackendCmd {
27 uint8_t locty;
28 const uint8_t *in;
29 uint32_t in_len;
30 uint8_t *out;
31 uint32_t out_len;
32 bool selftest_done;
33 } TPMBackendCmd;
35 struct TPMBackend {
36 Object parent;
38 /*< protected >*/
39 TPMIf *tpmif;
40 bool opened;
41 bool had_startup_error;
42 TPMBackendCmd *cmd;
44 /* <public> */
45 char *id;
47 QLIST_ENTRY(TPMBackend) list;
50 struct TPMBackendClass {
51 ObjectClass parent_class;
53 enum TpmType type;
54 const QemuOptDesc *opts;
55 /* get a descriptive text of the backend to display to the user */
56 const char *desc;
58 TPMBackend *(*create)(QemuOpts *opts);
60 /* start up the TPM on the backend - optional */
61 int (*startup_tpm)(TPMBackend *t, size_t buffersize);
63 /* optional */
64 void (*reset)(TPMBackend *t);
66 void (*cancel_cmd)(TPMBackend *t);
68 /* optional */
69 bool (*get_tpm_established_flag)(TPMBackend *t);
71 /* optional */
72 int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);
74 TPMVersion (*get_tpm_version)(TPMBackend *t);
76 size_t (*get_buffer_size)(TPMBackend *t);
78 TpmTypeOptions *(*get_tpm_options)(TPMBackend *t);
80 void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd, Error **errp);
83 /**
84 * tpm_backend_get_type:
85 * @s: the backend
87 * Returns the TpmType of the backend.
89 enum TpmType tpm_backend_get_type(TPMBackend *s);
91 /**
92 * tpm_backend_init:
93 * @s: the backend to initialized
94 * @tpmif: TPM interface
95 * @datacb: callback for sending data to frontend
96 * @errp: a pointer to return the #Error object if an error occurs.
98 * Initialize the backend with the given variables.
100 * Returns 0 on success.
102 int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp);
105 * tpm_backend_startup_tpm:
106 * @s: the backend whose TPM support is to be started
107 * @buffersize: the buffer size the TPM is supposed to use,
108 * 0 to leave it as-is
110 * Returns 0 on success.
112 int tpm_backend_startup_tpm(TPMBackend *s, size_t buffersize);
115 * tpm_backend_had_startup_error:
116 * @s: the backend to query for a statup error
118 * Check whether the backend had an error during startup. Returns
119 * false if no error occurred and the backend can be used, true
120 * otherwise.
122 bool tpm_backend_had_startup_error(TPMBackend *s);
125 * tpm_backend_deliver_request:
126 * @s: the backend to send the request to
127 * @cmd: the command to deliver
129 * Send a request to the backend. The backend will then send the request
130 * to the TPM implementation.
132 void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd);
135 * tpm_backend_reset:
136 * @s: the backend to reset
138 * Reset the backend into a well defined state with all previous errors
139 * reset.
141 void tpm_backend_reset(TPMBackend *s);
144 * tpm_backend_cancel_cmd:
145 * @s: the backend
147 * Cancel any ongoing command being processed by the TPM implementation
148 * on behalf of the QEMU guest.
150 void tpm_backend_cancel_cmd(TPMBackend *s);
153 * tpm_backend_get_tpm_established_flag:
154 * @s: the backend
156 * Get the TPM establishment flag. This function may be called very
157 * frequently by the frontend since for example in the TIS implementation
158 * this flag is part of a register.
160 bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
163 * tpm_backend_reset_tpm_established_flag:
164 * @s: the backend
165 * @locty: the locality number
167 * Reset the TPM establishment flag.
169 int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty);
172 * tpm_backend_get_tpm_version:
173 * @s: the backend to call into
175 * Get the TPM Version that is emulated at the backend.
177 * Returns TPMVersion.
179 TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
182 * tpm_backend_get_buffer_size:
183 * @s: the backend to call into
185 * Get the TPM's buffer size.
187 * Returns buffer size.
189 size_t tpm_backend_get_buffer_size(TPMBackend *s);
192 * tpm_backend_finish_sync:
193 * @s: the backend to call into
195 * Finish the pending command synchronously (this will call aio_poll()
196 * on qemu main AIOContext until it ends)
198 void tpm_backend_finish_sync(TPMBackend *s);
201 * tpm_backend_query_tpm:
202 * @s: the backend
204 * Query backend tpm info
206 * Returns newly allocated TPMInfo
208 TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
210 TPMBackend *qemu_find_tpm_be(const char *id);
212 #endif