hw/vfio/platform: irqfd setup sequence update
[qemu.git] / include / sysemu / tpm_backend.h
blob0a366be0f2a2429a55f333f94a89e075e889c93f
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 _QEMU_TPM_H
14 #define _QEMU_TPM_H
16 #include "qom/object.h"
17 #include "qemu-common.h"
18 #include "qapi/error.h"
19 #include "qapi-types.h"
20 #include "qemu/option.h"
21 #include "sysemu/tpm.h"
23 #define TYPE_TPM_BACKEND "tpm-backend"
24 #define TPM_BACKEND(obj) \
25 OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND)
26 #define TPM_BACKEND_GET_CLASS(obj) \
27 OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND)
28 #define TPM_BACKEND_CLASS(klass) \
29 OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND)
31 typedef struct TPMBackendClass TPMBackendClass;
32 typedef struct TPMBackend TPMBackend;
34 typedef struct TPMDriverOps TPMDriverOps;
36 struct TPMBackendClass {
37 ObjectClass parent_class;
39 const TPMDriverOps *ops;
41 void (*opened)(TPMBackend *s, Error **errp);
44 struct TPMBackend {
45 Object parent;
47 /*< protected >*/
48 bool opened;
50 char *id;
51 enum TpmModel fe_model;
52 char *path;
53 char *cancel_path;
54 const TPMDriverOps *ops;
56 QLIST_ENTRY(TPMBackend) list;
59 typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done);
61 typedef struct TPMSizedBuffer {
62 uint32_t size;
63 uint8_t *buffer;
64 } TPMSizedBuffer;
66 struct TPMDriverOps {
67 enum TpmType type;
68 const QemuOptDesc *opts;
69 /* get a descriptive text of the backend to display to the user */
70 const char *(*desc)(void);
72 TPMBackend *(*create)(QemuOpts *opts, const char *id);
73 void (*destroy)(TPMBackend *t);
75 /* initialize the backend */
76 int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb);
77 /* start up the TPM on the backend */
78 int (*startup_tpm)(TPMBackend *t);
79 /* returns true if nothing will ever answer TPM requests */
80 bool (*had_startup_error)(TPMBackend *t);
82 size_t (*realloc_buffer)(TPMSizedBuffer *sb);
84 void (*deliver_request)(TPMBackend *t);
86 void (*reset)(TPMBackend *t);
88 void (*cancel_cmd)(TPMBackend *t);
90 bool (*get_tpm_established_flag)(TPMBackend *t);
92 int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);
94 TPMVersion (*get_tpm_version)(TPMBackend *t);
98 /**
99 * tpm_backend_get_type:
100 * @s: the backend
102 * Returns the TpmType of the backend.
104 enum TpmType tpm_backend_get_type(TPMBackend *s);
107 * tpm_backend_get_desc:
108 * @s: the backend
110 * Returns a human readable description of the backend.
112 const char *tpm_backend_get_desc(TPMBackend *s);
115 * tpm_backend_destroy:
116 * @s: the backend to destroy
118 void tpm_backend_destroy(TPMBackend *s);
121 * tpm_backend_init:
122 * @s: the backend to initialized
123 * @state: TPMState
124 * @datacb: callback for sending data to frontend
126 * Initialize the backend with the given variables.
128 * Returns 0 on success.
130 int tpm_backend_init(TPMBackend *s, TPMState *state,
131 TPMRecvDataCB *datacb);
134 * tpm_backend_startup_tpm:
135 * @s: the backend whose TPM support is to be started
137 * Returns 0 on success.
139 int tpm_backend_startup_tpm(TPMBackend *s);
142 * tpm_backend_had_startup_error:
143 * @s: the backend to query for a statup error
145 * Check whether the backend had an error during startup. Returns
146 * false if no error occurred and the backend can be used, true
147 * otherwise.
149 bool tpm_backend_had_startup_error(TPMBackend *s);
152 * tpm_backend_realloc_buffer:
153 * @s: the backend
154 * @sb: the TPMSizedBuffer to re-allocated to the size suitable for the
155 * backend.
157 * This function returns the size of the allocated buffer
159 size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb);
162 * tpm_backend_deliver_request:
163 * @s: the backend to send the request to
165 * Send a request to the backend. The backend will then send the request
166 * to the TPM implementation.
168 void tpm_backend_deliver_request(TPMBackend *s);
171 * tpm_backend_reset:
172 * @s: the backend to reset
174 * Reset the backend into a well defined state with all previous errors
175 * reset.
177 void tpm_backend_reset(TPMBackend *s);
180 * tpm_backend_cancel_cmd:
181 * @s: the backend
183 * Cancel any ongoing command being processed by the TPM implementation
184 * on behalf of the QEMU guest.
186 void tpm_backend_cancel_cmd(TPMBackend *s);
189 * tpm_backend_get_tpm_established_flag:
190 * @s: the backend
192 * Get the TPM establishment flag. This function may be called very
193 * frequently by the frontend since for example in the TIS implementation
194 * this flag is part of a register.
196 bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
199 * tpm_backend_reset_tpm_established_flag:
200 * @s: the backend
201 * @locty: the locality number
203 * Reset the TPM establishment flag.
205 int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty);
208 * tpm_backend_open:
209 * @s: the backend to open
210 * @errp: a pointer to return the #Error object if an error occurs.
212 * This function will open the backend if it is not already open. Calling this
213 * function on an already opened backend will not result in an error.
215 void tpm_backend_open(TPMBackend *s, Error **errp);
218 * tpm_backend_get_tpm_version:
219 * @s: the backend to call into
221 * Get the TPM Version that is emulated at the backend.
223 * Returns TPMVersion.
225 TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
227 TPMBackend *qemu_find_tpm(const char *id);
229 const TPMDriverOps *tpm_get_backend_driver(const char *type);
230 int tpm_register_model(enum TpmModel model);
231 int tpm_register_driver(const TPMDriverOps *tdo);
233 #endif