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"
21 #define TYPE_TPM_BACKEND "tpm-backend"
22 OBJECT_DECLARE_TYPE(TPMBackend
, TPMBackendClass
,
26 typedef struct TPMBackendCmd
{
41 bool had_startup_error
;
47 QLIST_ENTRY(TPMBackend
) list
;
50 struct TPMBackendClass
{
51 ObjectClass parent_class
;
54 const QemuOptDesc
*opts
;
55 /* get a descriptive text of the backend to display to the user */
58 TPMBackend
*(*create
)(QemuOpts
*opts
);
60 /* start up the TPM on the backend - optional */
61 int (*startup_tpm
)(TPMBackend
*t
, size_t buffersize
);
64 void (*reset
)(TPMBackend
*t
);
66 void (*cancel_cmd
)(TPMBackend
*t
);
69 bool (*get_tpm_established_flag
)(TPMBackend
*t
);
72 int (*reset_tpm_established_flag
)(TPMBackend
*t
, uint8_t locty
);
74 TPMVersion (*get_tpm_version
)(TPMBackend
*t
);
76 size_t (*get_buffer_size
)(TPMBackend
*t
);
78 TpmTypeOptions
*(*get_tpm_options
)(TPMBackend
*t
);
80 void (*handle_request
)(TPMBackend
*s
, TPMBackendCmd
*cmd
, Error
**errp
);
84 * tpm_backend_get_type:
87 * Returns the TpmType of the backend.
89 enum TpmType
tpm_backend_get_type(TPMBackend
*s
);
93 * @s: the backend to initialized
94 * @tpmif: TPM interface
95 * @datacb: callback for sending data to frontend
96 * @errp: a pointer to return the #Error object if an error occurs.
98 * Initialize the backend with the given variables.
100 * Returns 0 on success.
102 int tpm_backend_init(TPMBackend
*s
, TPMIf
*tpmif
, Error
**errp
);
105 * tpm_backend_startup_tpm:
106 * @s: the backend whose TPM support is to be started
107 * @buffersize: the buffer size the TPM is supposed to use,
108 * 0 to leave it as-is
110 * Returns 0 on success.
112 int tpm_backend_startup_tpm(TPMBackend
*s
, size_t buffersize
);
115 * tpm_backend_had_startup_error:
116 * @s: the backend to query for a statup error
118 * Check whether the backend had an error during startup. Returns
119 * false if no error occurred and the backend can be used, true
122 bool tpm_backend_had_startup_error(TPMBackend
*s
);
125 * tpm_backend_deliver_request:
126 * @s: the backend to send the request to
127 * @cmd: the command to deliver
129 * Send a request to the backend. The backend will then send the request
130 * to the TPM implementation.
132 void tpm_backend_deliver_request(TPMBackend
*s
, TPMBackendCmd
*cmd
);
136 * @s: the backend to reset
138 * Reset the backend into a well defined state with all previous errors
141 void tpm_backend_reset(TPMBackend
*s
);
144 * tpm_backend_cancel_cmd:
147 * Cancel any ongoing command being processed by the TPM implementation
148 * on behalf of the QEMU guest.
150 void tpm_backend_cancel_cmd(TPMBackend
*s
);
153 * tpm_backend_get_tpm_established_flag:
156 * Get the TPM establishment flag. This function may be called very
157 * frequently by the frontend since for example in the TIS implementation
158 * this flag is part of a register.
160 bool tpm_backend_get_tpm_established_flag(TPMBackend
*s
);
163 * tpm_backend_reset_tpm_established_flag:
165 * @locty: the locality number
167 * Reset the TPM establishment flag.
169 int tpm_backend_reset_tpm_established_flag(TPMBackend
*s
, uint8_t locty
);
172 * tpm_backend_get_tpm_version:
173 * @s: the backend to call into
175 * Get the TPM Version that is emulated at the backend.
177 * Returns TPMVersion.
179 TPMVersion
tpm_backend_get_tpm_version(TPMBackend
*s
);
182 * tpm_backend_get_buffer_size:
183 * @s: the backend to call into
185 * Get the TPM's buffer size.
187 * Returns buffer size.
189 size_t tpm_backend_get_buffer_size(TPMBackend
*s
);
192 * tpm_backend_finish_sync:
193 * @s: the backend to call into
195 * Finish the pending command synchronously (this will call aio_poll()
196 * on qemu main AIOContext until it ends)
198 void tpm_backend_finish_sync(TPMBackend
*s
);
201 * tpm_backend_query_tpm:
204 * Query backend tpm info
206 * Returns newly allocated TPMInfo
208 TPMInfo
*tpm_backend_query_tpm(TPMBackend
*s
);
210 TPMBackend
*qemu_find_tpm_be(const char *id
);