hw/arm/allwinner-h3: add EMAC ethernet device
[qemu/ar7.git] / include / sysemu / tpm_backend.h
blob9e7451fb52fc511b16fd6fffef5a2015c7851927
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 #define TPM_BACKEND(obj) \
23 OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND)
24 #define TPM_BACKEND_GET_CLASS(obj) \
25 OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND)
26 #define TPM_BACKEND_CLASS(klass) \
27 OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND)
29 typedef struct TPMBackendClass TPMBackendClass;
30 typedef struct TPMBackend TPMBackend;
32 typedef struct TPMBackendCmd {
33 uint8_t locty;
34 const uint8_t *in;
35 uint32_t in_len;
36 uint8_t *out;
37 uint32_t out_len;
38 bool selftest_done;
39 } TPMBackendCmd;
41 struct TPMBackend {
42 Object parent;
44 /*< protected >*/
45 TPMIf *tpmif;
46 bool opened;
47 bool had_startup_error;
48 TPMBackendCmd *cmd;
50 /* <public> */
51 char *id;
53 QLIST_ENTRY(TPMBackend) list;
56 struct TPMBackendClass {
57 ObjectClass parent_class;
59 enum TpmType type;
60 const QemuOptDesc *opts;
61 /* get a descriptive text of the backend to display to the user */
62 const char *desc;
64 TPMBackend *(*create)(QemuOpts *opts);
66 /* start up the TPM on the backend - optional */
67 int (*startup_tpm)(TPMBackend *t, size_t buffersize);
69 /* optional */
70 void (*reset)(TPMBackend *t);
72 void (*cancel_cmd)(TPMBackend *t);
74 /* optional */
75 bool (*get_tpm_established_flag)(TPMBackend *t);
77 /* optional */
78 int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);
80 TPMVersion (*get_tpm_version)(TPMBackend *t);
82 size_t (*get_buffer_size)(TPMBackend *t);
84 TpmTypeOptions *(*get_tpm_options)(TPMBackend *t);
86 void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd, Error **errp);
89 /**
90 * tpm_backend_get_type:
91 * @s: the backend
93 * Returns the TpmType of the backend.
95 enum TpmType tpm_backend_get_type(TPMBackend *s);
97 /**
98 * tpm_backend_init:
99 * @s: the backend to initialized
100 * @tpmif: TPM interface
101 * @datacb: callback for sending data to frontend
102 * @errp: a pointer to return the #Error object if an error occurs.
104 * Initialize the backend with the given variables.
106 * Returns 0 on success.
108 int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp);
111 * tpm_backend_startup_tpm:
112 * @s: the backend whose TPM support is to be started
113 * @buffersize: the buffer size the TPM is supposed to use,
114 * 0 to leave it as-is
116 * Returns 0 on success.
118 int tpm_backend_startup_tpm(TPMBackend *s, size_t buffersize);
121 * tpm_backend_had_startup_error:
122 * @s: the backend to query for a statup error
124 * Check whether the backend had an error during startup. Returns
125 * false if no error occurred and the backend can be used, true
126 * otherwise.
128 bool tpm_backend_had_startup_error(TPMBackend *s);
131 * tpm_backend_deliver_request:
132 * @s: the backend to send the request to
133 * @cmd: the command to deliver
135 * Send a request to the backend. The backend will then send the request
136 * to the TPM implementation.
138 void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd);
141 * tpm_backend_reset:
142 * @s: the backend to reset
144 * Reset the backend into a well defined state with all previous errors
145 * reset.
147 void tpm_backend_reset(TPMBackend *s);
150 * tpm_backend_cancel_cmd:
151 * @s: the backend
153 * Cancel any ongoing command being processed by the TPM implementation
154 * on behalf of the QEMU guest.
156 void tpm_backend_cancel_cmd(TPMBackend *s);
159 * tpm_backend_get_tpm_established_flag:
160 * @s: the backend
162 * Get the TPM establishment flag. This function may be called very
163 * frequently by the frontend since for example in the TIS implementation
164 * this flag is part of a register.
166 bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
169 * tpm_backend_reset_tpm_established_flag:
170 * @s: the backend
171 * @locty: the locality number
173 * Reset the TPM establishment flag.
175 int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty);
178 * tpm_backend_get_tpm_version:
179 * @s: the backend to call into
181 * Get the TPM Version that is emulated at the backend.
183 * Returns TPMVersion.
185 TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
188 * tpm_backend_get_buffer_size:
189 * @s: the backend to call into
191 * Get the TPM's buffer size.
193 * Returns buffer size.
195 size_t tpm_backend_get_buffer_size(TPMBackend *s);
198 * tpm_backend_finish_sync:
199 * @s: the backend to call into
201 * Finish the pending command synchronously (this will call aio_poll()
202 * on qemu main AIOContext until it ends)
204 void tpm_backend_finish_sync(TPMBackend *s);
207 * tpm_backend_query_tpm:
208 * @s: the backend
210 * Query backend tpm info
212 * Returns newly allocated TPMInfo
214 TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
216 TPMBackend *qemu_find_tpm_be(const char *id);
218 #endif