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/option.h"
18 #include "sysemu/tpm.h"
19 #include "qapi/error.h"
23 #define TYPE_TPM_BACKEND "tpm-backend"
24 OBJECT_DECLARE_TYPE(TPMBackend
, TPMBackendClass
,
28 typedef struct TPMBackendCmd
{
43 bool had_startup_error
;
49 QLIST_ENTRY(TPMBackend
) list
;
52 struct TPMBackendClass
{
53 ObjectClass parent_class
;
56 const QemuOptDesc
*opts
;
57 /* get a descriptive text of the backend to display to the user */
60 TPMBackend
*(*create
)(QemuOpts
*opts
);
62 /* start up the TPM on the backend - optional */
63 int (*startup_tpm
)(TPMBackend
*t
, size_t buffersize
);
66 void (*reset
)(TPMBackend
*t
);
68 void (*cancel_cmd
)(TPMBackend
*t
);
71 bool (*get_tpm_established_flag
)(TPMBackend
*t
);
74 int (*reset_tpm_established_flag
)(TPMBackend
*t
, uint8_t locty
);
76 TPMVersion (*get_tpm_version
)(TPMBackend
*t
);
78 size_t (*get_buffer_size
)(TPMBackend
*t
);
80 TpmTypeOptions
*(*get_tpm_options
)(TPMBackend
*t
);
82 void (*handle_request
)(TPMBackend
*s
, TPMBackendCmd
*cmd
, Error
**errp
);
86 * tpm_backend_get_type:
89 * Returns the TpmType of the backend.
91 enum TpmType
tpm_backend_get_type(TPMBackend
*s
);
95 * @s: the backend to initialized
96 * @tpmif: TPM interface
97 * @datacb: callback for sending data to frontend
98 * @errp: a pointer to return the #Error object if an error occurs.
100 * Initialize the backend with the given variables.
102 * Returns 0 on success.
104 int tpm_backend_init(TPMBackend
*s
, TPMIf
*tpmif
, Error
**errp
);
107 * tpm_backend_startup_tpm:
108 * @s: the backend whose TPM support is to be started
109 * @buffersize: the buffer size the TPM is supposed to use,
110 * 0 to leave it as-is
112 * Returns 0 on success.
114 int tpm_backend_startup_tpm(TPMBackend
*s
, size_t buffersize
);
117 * tpm_backend_had_startup_error:
118 * @s: the backend to query for a startup error
120 * Check whether the backend had an error during startup. Returns
121 * false if no error occurred and the backend can be used, true
124 bool tpm_backend_had_startup_error(TPMBackend
*s
);
127 * tpm_backend_deliver_request:
128 * @s: the backend to send the request to
129 * @cmd: the command to deliver
131 * Send a request to the backend. The backend will then send the request
132 * to the TPM implementation.
134 void tpm_backend_deliver_request(TPMBackend
*s
, TPMBackendCmd
*cmd
);
138 * @s: the backend to reset
140 * Reset the backend into a well defined state with all previous errors
143 void tpm_backend_reset(TPMBackend
*s
);
146 * tpm_backend_cancel_cmd:
149 * Cancel any ongoing command being processed by the TPM implementation
150 * on behalf of the QEMU guest.
152 void tpm_backend_cancel_cmd(TPMBackend
*s
);
155 * tpm_backend_get_tpm_established_flag:
158 * Get the TPM establishment flag. This function may be called very
159 * frequently by the frontend since for example in the TIS implementation
160 * this flag is part of a register.
162 bool tpm_backend_get_tpm_established_flag(TPMBackend
*s
);
165 * tpm_backend_reset_tpm_established_flag:
167 * @locty: the locality number
169 * Reset the TPM establishment flag.
171 int tpm_backend_reset_tpm_established_flag(TPMBackend
*s
, uint8_t locty
);
174 * tpm_backend_get_tpm_version:
175 * @s: the backend to call into
177 * Get the TPM Version that is emulated at the backend.
179 * Returns TPMVersion.
181 TPMVersion
tpm_backend_get_tpm_version(TPMBackend
*s
);
184 * tpm_backend_get_buffer_size:
185 * @s: the backend to call into
187 * Get the TPM's buffer size.
189 * Returns buffer size.
191 size_t tpm_backend_get_buffer_size(TPMBackend
*s
);
194 * tpm_backend_finish_sync:
195 * @s: the backend to call into
197 * Finish the pending command synchronously (this will call aio_poll()
198 * on qemu main AIOContext until it ends)
200 void tpm_backend_finish_sync(TPMBackend
*s
);
203 * tpm_backend_query_tpm:
206 * Query backend tpm info
208 * Returns newly allocated TPMInfo
210 TPMInfo
*tpm_backend_query_tpm(TPMBackend
*s
);
212 TPMBackend
*qemu_find_tpm_be(const char *id
);
214 #endif /* CONFIG_TPM */
216 #endif /* TPM_BACKEND_H */