aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorAmarnath Valluri <amarnath.valluri@intel.com>2017-09-29 14:10:16 +0300
committerStefan Berger <stefanb@linux.vnet.ibm.com>2017-10-13 07:34:33 -0400
commit93330cf542b920b6ea5fea8120a08b76bb353113 (patch)
tree8450f62f15427f279ea4257877d6ce91a062fcab /backends
parentf35fe5cb97bbdaa6a6967f2fefc3fc1f79680601 (diff)
downloadqemu-93330cf542b920b6ea5fea8120a08b76bb353113.zip
qemu-93330cf542b920b6ea5fea8120a08b76bb353113.tar.gz
qemu-93330cf542b920b6ea5fea8120a08b76bb353113.tar.bz2
tpm-backend: Made few interface methods optional
This allows backend implementations left optional interface methods. For mandatory methods assertion checks added. Took the opportunity to remove unused methods: - tpm_backend_get_desc() - TPMDriverOps->handle_startup_error Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Stefan Berger<stefanb@linux.vnet.ibm.com> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Diffstat (limited to 'backends')
-rw-r--r--backends/tpm.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/backends/tpm.c b/backends/tpm.c
index cf5abf1..8911597 100644
--- a/backends/tpm.c
+++ b/backends/tpm.c
@@ -44,13 +44,6 @@ enum TpmType tpm_backend_get_type(TPMBackend *s)
return k->ops->type;
}
-const char *tpm_backend_get_desc(TPMBackend *s)
-{
- TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
-
- return k->ops->desc();
-}
-
int tpm_backend_init(TPMBackend *s, TPMState *state,
TPMRecvDataCB *datacb)
{
@@ -58,12 +51,14 @@ int tpm_backend_init(TPMBackend *s, TPMState *state,
s->tpm_state = state;
s->recv_data_callback = datacb;
+ s->had_startup_error = false;
- return k->ops->init(s);
+ return k->ops->init ? k->ops->init(s) : 0;
}
int tpm_backend_startup_tpm(TPMBackend *s)
{
+ int res = 0;
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
/* terminate a running TPM */
@@ -73,20 +68,24 @@ int tpm_backend_startup_tpm(TPMBackend *s)
NULL);
g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL);
- return k->ops->startup_tpm(s);
+ res = k->ops->startup_tpm ? k->ops->startup_tpm(s) : 0;
+
+ s->had_startup_error = (res != 0);
+
+ return res;
}
bool tpm_backend_had_startup_error(TPMBackend *s)
{
- TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
-
- return k->ops->had_startup_error(s);
+ return s->had_startup_error;
}
size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
+ assert(k->ops->realloc_buffer);
+
return k->ops->realloc_buffer(sb);
}
@@ -100,15 +99,21 @@ void tpm_backend_reset(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
- k->ops->reset(s);
+ if (k->ops->reset) {
+ k->ops->reset(s);
+ }
tpm_backend_thread_end(s);
+
+ s->had_startup_error = false;
}
void tpm_backend_cancel_cmd(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
+ assert(k->ops->cancel_cmd);
+
k->ops->cancel_cmd(s);
}
@@ -116,20 +121,24 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
- return k->ops->get_tpm_established_flag(s);
+ return k->ops->get_tpm_established_flag ?
+ k->ops->get_tpm_established_flag(s) : false;
}
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);
+ return k->ops->reset_tpm_established_flag ?
+ k->ops->reset_tpm_established_flag(s, locty) : 0;
}
TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
+ assert(k->ops->get_tpm_version);
+
return k->ops->get_tpm_version(s);
}