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
, const char *id
);
68 /* start up the TPM on the backend */
69 int (*startup_tpm
)(TPMBackend
*t
);
71 void (*reset
)(TPMBackend
*t
);
73 void (*cancel_cmd
)(TPMBackend
*t
);
75 bool (*get_tpm_established_flag
)(TPMBackend
*t
);
77 int (*reset_tpm_established_flag
)(TPMBackend
*t
, uint8_t locty
);
79 TPMVersion (*get_tpm_version
)(TPMBackend
*t
);
81 TpmTypeOptions
*(*get_tpm_options
)(TPMBackend
*t
);
83 void (*handle_request
)(TPMBackend
*s
, TPMBackendCmd
*cmd
);
87 * tpm_backend_get_type:
90 * Returns the TpmType of the backend.
92 enum TpmType
tpm_backend_get_type(TPMBackend
*s
);
96 * @s: the backend to initialized
97 * @tpmif: TPM interface
98 * @datacb: callback for sending data to frontend
99 * @errp: a pointer to return the #Error object if an error occurs.
101 * Initialize the backend with the given variables.
103 * Returns 0 on success.
105 int tpm_backend_init(TPMBackend
*s
, TPMIf
*tpmif
, Error
**errp
);
108 * tpm_backend_startup_tpm:
109 * @s: the backend whose TPM support is to be started
111 * Returns 0 on success.
113 int tpm_backend_startup_tpm(TPMBackend
*s
);
116 * tpm_backend_had_startup_error:
117 * @s: the backend to query for a statup error
119 * Check whether the backend had an error during startup. Returns
120 * false if no error occurred and the backend can be used, true
123 bool tpm_backend_had_startup_error(TPMBackend
*s
);
126 * tpm_backend_deliver_request:
127 * @s: the backend to send the request to
128 * @cmd: the command to deliver
130 * Send a request to the backend. The backend will then send the request
131 * to the TPM implementation.
133 void tpm_backend_deliver_request(TPMBackend
*s
, TPMBackendCmd
*cmd
);
137 * @s: the backend to reset
139 * Reset the backend into a well defined state with all previous errors
142 void tpm_backend_reset(TPMBackend
*s
);
145 * tpm_backend_cancel_cmd:
148 * Cancel any ongoing command being processed by the TPM implementation
149 * on behalf of the QEMU guest.
151 void tpm_backend_cancel_cmd(TPMBackend
*s
);
154 * tpm_backend_get_tpm_established_flag:
157 * Get the TPM establishment flag. This function may be called very
158 * frequently by the frontend since for example in the TIS implementation
159 * this flag is part of a register.
161 bool tpm_backend_get_tpm_established_flag(TPMBackend
*s
);
164 * tpm_backend_reset_tpm_established_flag:
166 * @locty: the locality number
168 * Reset the TPM establishment flag.
170 int tpm_backend_reset_tpm_established_flag(TPMBackend
*s
, uint8_t locty
);
173 * tpm_backend_get_tpm_version:
174 * @s: the backend to call into
176 * Get the TPM Version that is emulated at the backend.
178 * Returns TPMVersion.
180 TPMVersion
tpm_backend_get_tpm_version(TPMBackend
*s
);
183 * tpm_backend_query_tpm:
186 * Query backend tpm info
188 * Returns newly allocated TPMInfo
190 TPMInfo
*tpm_backend_query_tpm(TPMBackend
*s
);
192 TPMBackend
*qemu_find_tpm(const char *id
);
194 void tpm_register_model(enum TpmModel model
);