aboutsummaryrefslogtreecommitdiff
path: root/backends/tpm.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-12-17 15:27:41 +0000
committerPeter Maydell <peter.maydell@linaro.org>2017-12-17 15:27:41 +0000
commit411ad78115ebeb3411cf4b7622784b93dfabe259 (patch)
tree00d85d7c41e5d0eaae7bebb969f0271c627ad517 /backends/tpm.c
parent38d1b31e0501f938db39c5b2e508328530410246 (diff)
parent683c4b775355cc7acd301e8efe7d4c1c9acdafd8 (diff)
Merge remote-tracking branch 'remotes/stefanberger/tags/pull-tpm-2017-12-15-1' into staging
Merge tpm 2017/12/15 v1 # gpg: Signature made Fri 15 Dec 2017 04:44:15 GMT # gpg: using RSA key 0x75AD65802A0B4211 # gpg: Good signature from "Stefan Berger <stefanb@linux.vnet.ibm.com>" # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: B818 B9CA DF90 89C2 D5CE C66B 75AD 6580 2A0B 4211 * remotes/stefanberger/tags/pull-tpm-2017-12-15-1: (32 commits) tpm: tpm_passthrough: Fail startup if FE buffer size < BE buffer size tpm: tpm_emulator: get and set buffer size of device tpm: tpm_passthrough: Read the buffer size from the host device tpm: pull tpm_util_request() out of tpm_util_test() tpm: Move getting TPM buffer size to backends tpm: remove tpm_register_model() tpm-tis: use DEFINE_PROP_TPMBE qdev: add DEFINE_PROP_TPMBE tpm-tis: check that at most one TPM device exists tpm-tis: remove redundant 'tpm_tis:' in error messages tpm-emulator: add a FIXME comment about blocking cancel acpi: change TPM TIS data conditions tpm: add tpm_cmd_get_size() to tpm_util tpm: add TPM interface to lookup TPM version tpm: lookup the the TPM interface instead of TIS device tpm: rename qemu_find_tpm() -> qemu_find_tpm_be() tpm-tis: simplify header inclusion tpm-passthrough: workaround a possible race tpm-passthrough: simplify create() tpm-passthrough: make it safer to destroy after creation ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'backends/tpm.c')
-rw-r--r--backends/tpm.c92
1 files changed, 35 insertions, 57 deletions
diff --git a/backends/tpm.c b/backends/tpm.c
index 5763f6f369..91222c5164 100644
--- a/backends/tpm.c
+++ b/backends/tpm.c
@@ -17,16 +17,25 @@
#include "qapi/error.h"
#include "qapi/qmp/qerror.h"
#include "sysemu/tpm.h"
-#include "hw/tpm/tpm_int.h"
#include "qemu/thread.h"
+#include "qemu/main-loop.h"
+
+static void tpm_backend_request_completed_bh(void *opaque)
+{
+ TPMBackend *s = TPM_BACKEND(opaque);
+ TPMIfClass *tic = TPM_IF_GET_CLASS(s->tpmif);
+
+ tic->request_completed(s->tpmif);
+}
static void tpm_backend_worker_thread(gpointer data, gpointer user_data)
{
TPMBackend *s = TPM_BACKEND(user_data);
- TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
+ TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
- assert(k->handle_request != NULL);
k->handle_request(s, (TPMBackendCmd *)data);
+
+ qemu_bh_schedule(s->bh);
}
static void tpm_backend_thread_end(TPMBackend *s)
@@ -44,15 +53,22 @@ enum TpmType tpm_backend_get_type(TPMBackend *s)
return k->type;
}
-int tpm_backend_init(TPMBackend *s, TPMState *state)
+int tpm_backend_init(TPMBackend *s, TPMIf *tpmif, Error **errp)
{
- s->tpm_state = state;
+ if (s->tpmif) {
+ error_setg(errp, "TPM backend '%s' is already initialized", s->id);
+ return -1;
+ }
+
+ s->tpmif = tpmif;
+ object_ref(OBJECT(tpmif));
+
s->had_startup_error = false;
return 0;
}
-int tpm_backend_startup_tpm(TPMBackend *s)
+int tpm_backend_startup_tpm(TPMBackend *s, size_t buffersize)
{
int res = 0;
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
@@ -63,7 +79,7 @@ int tpm_backend_startup_tpm(TPMBackend *s)
s->thread_pool = g_thread_pool_new(tpm_backend_worker_thread, s, 1, TRUE,
NULL);
- res = k->startup_tpm ? k->startup_tpm(s) : 0;
+ res = k->startup_tpm ? k->startup_tpm(s, buffersize) : 0;
s->had_startup_error = (res != 0);
@@ -97,8 +113,6 @@ void tpm_backend_cancel_cmd(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
- assert(k->cancel_cmd);
-
k->cancel_cmd(s);
}
@@ -122,80 +136,44 @@ TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
- assert(k->get_tpm_version);
-
return k->get_tpm_version(s);
}
-TPMInfo *tpm_backend_query_tpm(TPMBackend *s)
+size_t tpm_backend_get_buffer_size(TPMBackend *s)
{
- TPMInfo *info = g_new0(TPMInfo, 1);
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
- info->id = g_strdup(s->id);
- info->model = s->fe_model;
- if (k->get_tpm_options) {
- info->options = k->get_tpm_options(s);
- }
-
- return info;
+ return k->get_buffer_size(s);
}
-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)
+TPMInfo *tpm_backend_query_tpm(TPMBackend *s)
{
- TPMBackend *s = TPM_BACKEND(obj);
+ TPMInfo *info = g_new0(TPMInfo, 1);
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
- Error *local_err = NULL;
-
- if (value == s->opened) {
- return;
- }
-
- if (!value && s->opened) {
- error_setg(errp, QERR_PERMISSION_DENIED);
- return;
- }
+ TPMIfClass *tic = TPM_IF_GET_CLASS(s->tpmif);
- if (k->opened) {
- k->opened(s, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
- }
+ info->id = g_strdup(s->id);
+ info->model = tic->model;
+ info->options = k->get_tpm_options(s);
- s->opened = true;
+ return info;
}
static void tpm_backend_instance_init(Object *obj)
{
TPMBackend *s = TPM_BACKEND(obj);
- object_property_add_bool(obj, "opened",
- tpm_backend_prop_get_opened,
- tpm_backend_prop_set_opened,
- NULL);
- s->fe_model = -1;
+ s->bh = qemu_bh_new(tpm_backend_request_completed_bh, s);
}
static void tpm_backend_instance_finalize(Object *obj)
{
TPMBackend *s = TPM_BACKEND(obj);
+ object_unref(OBJECT(s->tpmif));
g_free(s->id);
tpm_backend_thread_end(s);
+ qemu_bh_delete(s->bh);
}
static const TypeInfo tpm_backend_info = {