2013-03-28 12:26:21 +01:00
|
|
|
/*
|
|
|
|
* QEMU TPM Backend
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2013
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Stefan Berger <stefanb@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
* Based on backends/rng.c by Anthony Liguori
|
|
|
|
*/
|
|
|
|
|
2016-01-29 18:49:54 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-04-08 16:55:25 +02:00
|
|
|
#include "sysemu/tpm_backend.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2013-03-28 12:26:21 +01:00
|
|
|
#include "qapi/qmp/qerror.h"
|
2013-04-02 18:28:41 +02:00
|
|
|
#include "sysemu/tpm.h"
|
|
|
|
#include "qemu/thread.h"
|
|
|
|
#include "sysemu/tpm_backend_int.h"
|
2013-03-28 12:26:21 +01:00
|
|
|
|
|
|
|
enum TpmType tpm_backend_get_type(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *tpm_backend_get_desc(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->desc();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tpm_backend_destroy(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
2015-03-08 19:14:47 +01:00
|
|
|
k->ops->destroy(s);
|
2013-03-28 12:26:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int tpm_backend_init(TPMBackend *s, TPMState *state,
|
|
|
|
TPMRecvDataCB *datacb)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->init(s, state, datacb);
|
|
|
|
}
|
|
|
|
|
|
|
|
int tpm_backend_startup_tpm(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->startup_tpm(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tpm_backend_had_startup_error(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->had_startup_error(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->realloc_buffer(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tpm_backend_deliver_request(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
k->ops->deliver_request(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tpm_backend_reset(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
k->ops->reset(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tpm_backend_cancel_cmd(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
k->ops->cancel_cmd(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool tpm_backend_get_tpm_established_flag(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->get_tpm_established_flag(s);
|
|
|
|
}
|
|
|
|
|
2015-05-26 22:51:05 +02:00
|
|
|
int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->reset_tpm_established_flag(s, locty);
|
|
|
|
}
|
|
|
|
|
|
|
|
TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)
|
|
|
|
{
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
|
|
|
|
|
|
|
return k->ops->get_tpm_version(s);
|
|
|
|
}
|
|
|
|
|
2013-03-28 12:26:21 +01:00
|
|
|
static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
TPMBackend *s = TPM_BACKEND(obj);
|
|
|
|
|
|
|
|
return s->opened;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tpm_backend_open(TPMBackend *s, Error **errp)
|
|
|
|
{
|
|
|
|
object_property_set_bool(OBJECT(s), true, "opened", errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **errp)
|
|
|
|
{
|
|
|
|
TPMBackend *s = TPM_BACKEND(obj);
|
|
|
|
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
2014-04-25 12:44:22 +02:00
|
|
|
Error *local_err = NULL;
|
2013-03-28 12:26:21 +01:00
|
|
|
|
|
|
|
if (value == s->opened) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!value && s->opened) {
|
2015-03-17 11:54:50 +01:00
|
|
|
error_setg(errp, QERR_PERMISSION_DENIED);
|
2013-03-28 12:26:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k->opened) {
|
2014-04-25 12:44:22 +02:00
|
|
|
k->opened(s, &local_err);
|
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2013-03-28 12:26:21 +01:00
|
|
|
}
|
|
|
|
|
2014-04-25 12:44:22 +02:00
|
|
|
s->opened = true;
|
2013-03-28 12:26:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_backend_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
object_property_add_bool(obj, "opened",
|
|
|
|
tpm_backend_prop_get_opened,
|
|
|
|
tpm_backend_prop_set_opened,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2013-04-02 18:28:41 +02:00
|
|
|
void tpm_backend_thread_deliver_request(TPMBackendThread *tbt)
|
|
|
|
{
|
|
|
|
g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tpm_backend_thread_create(TPMBackendThread *tbt,
|
|
|
|
GFunc func, gpointer user_data)
|
|
|
|
{
|
|
|
|
if (!tbt->pool) {
|
|
|
|
tbt->pool = g_thread_pool_new(func, user_data, 1, TRUE, NULL);
|
|
|
|
g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void tpm_backend_thread_end(TPMBackendThread *tbt)
|
|
|
|
{
|
|
|
|
if (tbt->pool) {
|
|
|
|
g_thread_pool_push(tbt->pool, (gpointer)TPM_BACKEND_CMD_END, NULL);
|
|
|
|
g_thread_pool_free(tbt->pool, FALSE, TRUE);
|
|
|
|
tbt->pool = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-28 12:26:21 +01:00
|
|
|
static const TypeInfo tpm_backend_info = {
|
|
|
|
.name = TYPE_TPM_BACKEND,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.instance_size = sizeof(TPMBackend),
|
|
|
|
.instance_init = tpm_backend_instance_init,
|
|
|
|
.class_size = sizeof(TPMBackendClass),
|
|
|
|
.abstract = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&tpm_backend_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types);
|