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-types.h"
19 #include "qemu/option.h"
20 #include "sysemu/tpm.h"
22 #define TYPE_TPM_BACKEND "tpm-backend"
23 #define TPM_BACKEND(obj) \
24 OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND)
25 #define TPM_BACKEND_GET_CLASS(obj) \
26 OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND)
27 #define TPM_BACKEND_CLASS(klass) \
28 OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND)
30 typedef struct TPMBackendClass TPMBackendClass
;
31 typedef struct TPMBackend TPMBackend
;
32 typedef struct TPMDriverOps TPMDriverOps
;
33 typedef void (TPMRecvDataCB
)(TPMState
*, uint8_t locty
, bool selftest_done
);
35 typedef enum TPMBackendCmd
{
36 TPM_BACKEND_CMD_INIT
= 1,
37 TPM_BACKEND_CMD_PROCESS_CMD
,
39 TPM_BACKEND_CMD_TPM_RESET
,
48 GThreadPool
*thread_pool
;
49 TPMRecvDataCB
*recv_data_callback
;
50 bool had_startup_error
;
54 enum TpmModel fe_model
;
56 QLIST_ENTRY(TPMBackend
) list
;
59 struct TPMBackendClass
{
60 ObjectClass parent_class
;
62 const TPMDriverOps
*ops
;
64 void (*opened
)(TPMBackend
*s
, Error
**errp
);
66 void (*handle_request
)(TPMBackend
*s
, TPMBackendCmd cmd
);
69 typedef struct TPMSizedBuffer
{
76 const QemuOptDesc
*opts
;
77 /* get a descriptive text of the backend to display to the user */
80 TPMBackend
*(*create
)(QemuOpts
*opts
, const char *id
);
82 /* initialize the backend */
83 int (*init
)(TPMBackend
*t
);
84 /* start up the TPM on the backend */
85 int (*startup_tpm
)(TPMBackend
*t
);
87 void (*reset
)(TPMBackend
*t
);
89 void (*cancel_cmd
)(TPMBackend
*t
);
91 bool (*get_tpm_established_flag
)(TPMBackend
*t
);
93 int (*reset_tpm_established_flag
)(TPMBackend
*t
, uint8_t locty
);
95 TPMVersion (*get_tpm_version
)(TPMBackend
*t
);
97 TpmTypeOptions
*(*get_tpm_options
)(TPMBackend
*t
);
102 * tpm_backend_get_type:
105 * Returns the TpmType of the backend.
107 enum TpmType
tpm_backend_get_type(TPMBackend
*s
);
111 * @s: the backend to initialized
113 * @datacb: callback for sending data to frontend
115 * Initialize the backend with the given variables.
117 * Returns 0 on success.
119 int tpm_backend_init(TPMBackend
*s
, TPMState
*state
,
120 TPMRecvDataCB
*datacb
);
123 * tpm_backend_startup_tpm:
124 * @s: the backend whose TPM support is to be started
126 * Returns 0 on success.
128 int tpm_backend_startup_tpm(TPMBackend
*s
);
131 * tpm_backend_had_startup_error:
132 * @s: the backend to query for a statup error
134 * Check whether the backend had an error during startup. Returns
135 * false if no error occurred and the backend can be used, true
138 bool tpm_backend_had_startup_error(TPMBackend
*s
);
141 * tpm_backend_deliver_request:
142 * @s: the backend to send the request to
144 * Send a request to the backend. The backend will then send the request
145 * to the TPM implementation.
147 void tpm_backend_deliver_request(TPMBackend
*s
);
151 * @s: the backend to reset
153 * Reset the backend into a well defined state with all previous errors
156 void tpm_backend_reset(TPMBackend
*s
);
159 * tpm_backend_cancel_cmd:
162 * Cancel any ongoing command being processed by the TPM implementation
163 * on behalf of the QEMU guest.
165 void tpm_backend_cancel_cmd(TPMBackend
*s
);
168 * tpm_backend_get_tpm_established_flag:
171 * Get the TPM establishment flag. This function may be called very
172 * frequently by the frontend since for example in the TIS implementation
173 * this flag is part of a register.
175 bool tpm_backend_get_tpm_established_flag(TPMBackend
*s
);
178 * tpm_backend_reset_tpm_established_flag:
180 * @locty: the locality number
182 * Reset the TPM establishment flag.
184 int tpm_backend_reset_tpm_established_flag(TPMBackend
*s
, uint8_t locty
);
188 * @s: the backend to open
189 * @errp: a pointer to return the #Error object if an error occurs.
191 * This function will open the backend if it is not already open. Calling this
192 * function on an already opened backend will not result in an error.
194 void tpm_backend_open(TPMBackend
*s
, Error
**errp
);
197 * tpm_backend_get_tpm_version:
198 * @s: the backend to call into
200 * Get the TPM Version that is emulated at the backend.
202 * Returns TPMVersion.
204 TPMVersion
tpm_backend_get_tpm_version(TPMBackend
*s
);
207 * tpm_backend_query_tpm:
210 * Query backend tpm info
212 * Returns newly allocated TPMInfo
214 TPMInfo
*tpm_backend_query_tpm(TPMBackend
*s
);
216 TPMBackend
*qemu_find_tpm(const char *id
);
218 const TPMDriverOps
*tpm_get_backend_driver(const char *type
);
219 void tpm_register_model(enum TpmModel model
);
220 void tpm_register_driver(const TPMDriverOps
*tdo
);