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
;
33 typedef struct TPMBackendCmd
{
48 GThreadPool
*thread_pool
;
49 bool had_startup_error
;
55 QLIST_ENTRY(TPMBackend
) list
;
58 struct TPMBackendClass
{
59 ObjectClass parent_class
;
62 const QemuOptDesc
*opts
;
63 /* get a descriptive text of the backend to display to the user */
66 TPMBackend
*(*create
)(QemuOpts
*opts
);
68 /* start up the TPM on the backend - optional */
69 int (*startup_tpm
)(TPMBackend
*t
);
72 void (*reset
)(TPMBackend
*t
);
74 void (*cancel_cmd
)(TPMBackend
*t
);
77 bool (*get_tpm_established_flag
)(TPMBackend
*t
);
80 int (*reset_tpm_established_flag
)(TPMBackend
*t
, uint8_t locty
);
82 TPMVersion (*get_tpm_version
)(TPMBackend
*t
);
84 TpmTypeOptions
*(*get_tpm_options
)(TPMBackend
*t
);
86 void (*handle_request
)(TPMBackend
*s
, TPMBackendCmd
*cmd
);
90 * tpm_backend_get_type:
93 * Returns the TpmType of the backend.
95 enum TpmType
tpm_backend_get_type(TPMBackend
*s
);
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
114 * Returns 0 on success.
116 int tpm_backend_startup_tpm(TPMBackend
*s
);
119 * tpm_backend_had_startup_error:
120 * @s: the backend to query for a statup error
122 * Check whether the backend had an error during startup. Returns
123 * false if no error occurred and the backend can be used, true
126 bool tpm_backend_had_startup_error(TPMBackend
*s
);
129 * tpm_backend_deliver_request:
130 * @s: the backend to send the request to
131 * @cmd: the command to deliver
133 * Send a request to the backend. The backend will then send the request
134 * to the TPM implementation.
136 void tpm_backend_deliver_request(TPMBackend
*s
, TPMBackendCmd
*cmd
);
140 * @s: the backend to reset
142 * Reset the backend into a well defined state with all previous errors
145 void tpm_backend_reset(TPMBackend
*s
);
148 * tpm_backend_cancel_cmd:
151 * Cancel any ongoing command being processed by the TPM implementation
152 * on behalf of the QEMU guest.
154 void tpm_backend_cancel_cmd(TPMBackend
*s
);
157 * tpm_backend_get_tpm_established_flag:
160 * Get the TPM establishment flag. This function may be called very
161 * frequently by the frontend since for example in the TIS implementation
162 * this flag is part of a register.
164 bool tpm_backend_get_tpm_established_flag(TPMBackend
*s
);
167 * tpm_backend_reset_tpm_established_flag:
169 * @locty: the locality number
171 * Reset the TPM establishment flag.
173 int tpm_backend_reset_tpm_established_flag(TPMBackend
*s
, uint8_t locty
);
176 * tpm_backend_get_tpm_version:
177 * @s: the backend to call into
179 * Get the TPM Version that is emulated at the backend.
181 * Returns TPMVersion.
183 TPMVersion
tpm_backend_get_tpm_version(TPMBackend
*s
);
186 * tpm_backend_query_tpm:
189 * Query backend tpm info
191 * Returns newly allocated TPMInfo
193 TPMInfo
*tpm_backend_query_tpm(TPMBackend
*s
);
195 TPMBackend
*qemu_find_tpm_be(const char *id
);