4 * Copyright IBM, Corp. 2013
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.
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);
51 enum TpmModel fe_model;
54 const TPMDriverOps *ops;
56 QLIST_ENTRY(TPMBackend) list;
59 typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty);
61 typedef struct TPMSizedBuffer {
68 /* get a descriptive text of the backend to display to the user */
69 const char *(*desc)(void);
71 TPMBackend *(*create)(QemuOpts *opts, const char *id);
72 void (*destroy)(TPMBackend *t);
74 /* initialize the backend */
75 int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb);
76 /* start up the TPM on the backend */
77 int (*startup_tpm)(TPMBackend *t);
78 /* returns true if nothing will ever answer TPM requests */
79 bool (*had_startup_error)(TPMBackend *t);
81 size_t (*realloc_buffer)(TPMSizedBuffer *sb);
83 void (*deliver_request)(TPMBackend *t);
85 void (*reset)(TPMBackend *t);
87 void (*cancel_cmd)(TPMBackend *t);
89 bool (*get_tpm_established_flag)(TPMBackend *t);
94 * tpm_backend_get_type:
97 * Returns the TpmType of the backend.
99 enum TpmType tpm_backend_get_type(TPMBackend *s);
102 * tpm_backend_get_desc:
105 * Returns a human readable description of the backend.
107 const char *tpm_backend_get_desc(TPMBackend *s);
110 * tpm_backend_destroy:
111 * @s: the backend to destroy
113 void tpm_backend_destroy(TPMBackend *s);
117 * @s: the backend to initialized
119 * @datacb: callback for sending data to frontend
121 * Initialize the backend with the given variables.
123 * Returns 0 on success.
125 int tpm_backend_init(TPMBackend *s, TPMState *state,
126 TPMRecvDataCB *datacb);
129 * tpm_backend_startup_tpm:
130 * @s: the backend whose TPM support is to be started
132 * Returns 0 on success.
134 int tpm_backend_startup_tpm(TPMBackend *s);
137 * tpm_backend_had_startup_error:
138 * @s: the backend to query for a statup error
140 * Check whether the backend had an error during startup. Returns
141 * false if no error occurred and the backend can be used, true
144 bool tpm_backend_had_startup_error(TPMBackend *s);
147 * tpm_backend_realloc_buffer:
149 * @sb: the TPMSizedBuffer to re-allocated to the size suitable for the
152 * This function returns the size of the allocated buffer
154 size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb);
157 * tpm_backend_deliver_request:
158 * @s: the backend to send the request to
160 * Send a request to the backend. The backend will then send the request
161 * to the TPM implementation.
163 void tpm_backend_deliver_request(TPMBackend *s);
167 * @s: the backend to reset
169 * Reset the backend into a well defined state with all previous errors
172 void tpm_backend_reset(TPMBackend *s);
175 * tpm_backend_cancel_cmd:
178 * Cancel any ongoing command being processed by the TPM implementation
179 * on behalf of the QEMU guest.
181 void tpm_backend_cancel_cmd(TPMBackend *s);
184 * tpm_backend_get_tpm_established_flag:
187 * Get the TPM establishment flag. This function may be called very
188 * frequently by the frontend since for example in the TIS implementation
189 * this flag is part of a register.
191 bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
195 * @s: the backend to open
196 * @errp: a pointer to return the #Error object if an error occurs.
198 * This function will open the backend if it is not already open. Calling this
199 * function on an already opened backend will not result in an error.
201 void tpm_backend_open(TPMBackend *s, Error **errp);
203 TPMBackend *qemu_find_tpm(const char *id);
205 const TPMDriverOps *tpm_get_backend_driver(const char *type);
206 int tpm_register_model(enum TpmModel model);
207 int tpm_register_driver(const TPMDriverOps *tdo);