From: Stefan Berger <stefanb@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
marcandre.lureau@gmail.com,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Stefan Berger" <stefanb@linux.vnet.ibm.com>
Subject: [Qemu-devel] [PULL v1 21/21] tpm: move recv_data_callback to TPM interface
Date: Thu, 19 Oct 2017 14:02:55 -0400 [thread overview]
Message-ID: <1508436175-1596-22-git-send-email-stefanb@linux.vnet.ibm.com> (raw)
In-Reply-To: <1508436175-1596-1-git-send-email-stefanb@linux.vnet.ibm.com>
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Simplify the TPM backend setup, move callback to TPM interface.
Signed-off-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>
---
backends/tpm.c | 4 +---
hw/tpm/tpm_emulator.c | 3 ++-
hw/tpm/tpm_int.h | 3 +++
hw/tpm/tpm_passthrough.c | 3 ++-
hw/tpm/tpm_tis.c | 11 ++++++-----
include/sysemu/tpm_backend.h | 6 +-----
6 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/backends/tpm.c b/backends/tpm.c
index 87c5c09..5763f6f 100644
--- a/backends/tpm.c
+++ b/backends/tpm.c
@@ -44,11 +44,9 @@ enum TpmType tpm_backend_get_type(TPMBackend *s)
return k->type;
}
-int tpm_backend_init(TPMBackend *s, TPMState *state,
- TPMRecvDataCB *datacb)
+int tpm_backend_init(TPMBackend *s, TPMState *state)
{
s->tpm_state = state;
- s->recv_data_callback = datacb;
s->had_startup_error = false;
return 0;
diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c
index 6500b86..9aaec8e 100644
--- a/hw/tpm/tpm_emulator.c
+++ b/hw/tpm/tpm_emulator.c
@@ -176,6 +176,7 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number,
static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd)
{
TPMEmulator *tpm_emu = TPM_EMULATOR(tb);
+ TPMIfClass *tic = TPM_IF_GET_CLASS(tb->tpm_state);
Error *err = NULL;
DPRINTF("processing TPM command");
@@ -190,7 +191,7 @@ static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd)
goto error;
}
- tb->recv_data_callback(tb->tpm_state);
+ tic->request_completed(TPM_IF(tb->tpm_state));
return;
error:
diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h
index eb02e77..9c045b6 100644
--- a/hw/tpm/tpm_int.h
+++ b/hw/tpm/tpm_int.h
@@ -29,6 +29,9 @@ typedef struct TPMIf {
typedef struct TPMIfClass {
InterfaceClass parent_class;
+
+ /* run in thread pool by backend */
+ void (*request_completed)(TPMIf *obj);
} TPMIfClass;
#define TPM_STANDARD_CMDLINE_OPTS \
diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
index 4274164..c440aff 100644
--- a/hw/tpm/tpm_passthrough.c
+++ b/hw/tpm/tpm_passthrough.c
@@ -139,13 +139,14 @@ err_exit:
static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *cmd)
{
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
+ TPMIfClass *tic = TPM_IF_GET_CLASS(tb->tpm_state);
DPRINTF("tpm_passthrough: processing command %p\n", cmd);
tpm_passthrough_unix_tx_bufs(tpm_pt, cmd->in, cmd->in_len,
cmd->out, cmd->out_len, &cmd->selftest_done);
- tb->recv_data_callback(tb->tpm_state);
+ tic->request_completed(TPM_IF(tb->tpm_state));
}
static void tpm_passthrough_reset(TPMBackend *tb)
diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index dbb5004..8c5cac5 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -430,11 +430,10 @@ static void tpm_tis_receive_bh(void *opaque)
TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID);
}
-/*
- * Callback from the TPM to indicate that the response was received.
- */
-static void tpm_tis_receive_cb(TPMState *s)
+static void tpm_tis_request_completed(TPMIf *ti)
{
+ TPMState *s = TPM(ti);
+
bool is_selftest_done = s->cmd.selftest_done;
uint8_t locty = s->cmd.locty;
uint8_t l;
@@ -1078,7 +1077,7 @@ static void tpm_tis_realizefn(DeviceState *dev, Error **errp)
s->be_driver->fe_model = TPM_MODEL_TPM_TIS;
- if (tpm_backend_init(s->be_driver, s, tpm_tis_receive_cb)) {
+ if (tpm_backend_init(s->be_driver, s)) {
error_setg(errp, "tpm_tis: backend driver with id %s could not be "
"initialized", s->backend);
return;
@@ -1110,11 +1109,13 @@ static void tpm_tis_initfn(Object *obj)
static void tpm_tis_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ TPMIfClass *tc = TPM_IF_CLASS(klass);
dc->realize = tpm_tis_realizefn;
dc->props = tpm_tis_properties;
dc->reset = tpm_tis_reset;
dc->vmsd = &vmstate_tpm_tis;
+ tc->request_completed = tpm_tis_request_completed;
}
static const TypeInfo tpm_tis_info = {
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 3bb90be..03ea5a3 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -30,8 +30,6 @@
typedef struct TPMBackendClass TPMBackendClass;
typedef struct TPMBackend TPMBackend;
-typedef void (TPMRecvDataCB)(TPMState *);
-
typedef struct TPMBackendCmd {
uint8_t locty;
const uint8_t *in;
@@ -48,7 +46,6 @@ struct TPMBackend {
bool opened;
TPMState *tpm_state;
GThreadPool *thread_pool;
- TPMRecvDataCB *recv_data_callback;
bool had_startup_error;
/* <public> */
@@ -106,8 +103,7 @@ enum TpmType tpm_backend_get_type(TPMBackend *s);
*
* Returns 0 on success.
*/
-int tpm_backend_init(TPMBackend *s, TPMState *state,
- TPMRecvDataCB *datacb);
+int tpm_backend_init(TPMBackend *s, TPMState *state);
/**
* tpm_backend_startup_tpm:
--
2.5.5
next prev parent reply other threads:[~2017-10-19 18:03 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-19 18:02 [Qemu-devel] [PULL v1 00/21] Merge tpm 2017/10/19 Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 01/21] tpm-tis: remove unused hw_access argument Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 02/21] tpm-tis: remove RAISE_STS_IRQ Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 03/21] tpm: make tpm_get_backend_driver() static Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 04/21] tpm: lookup tpm backend class in tpm_driver_find_by_type() Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 05/21] tpm: replace tpm_get_backend_driver() to drop be_drivers Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 06/21] tpm: remove tpm_register_driver() Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 07/21] tpm: move TPMSizedBuffer to tpm_tis.h Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 08/21] tpm: remove TPMDriverOps Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 09/21] tpm: remove init() class method Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 10/21] tpm: remove configure_tpm() hop Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 11/21] tpm: remove unused TPMBackendCmd Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 12/21] tpm: remove needless cast Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 13/21] tpm: remove locty argument from receive_cb Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 14/21] tpm: add TPMBackendCmd to hold the request state Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 15/21] tpm-emulator: fix error handling Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 16/21] tpm: remove locty_data from TPMState Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 17/21] tpm-tis: move TPMState to TIS header Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 18/21] tpm-tis: remove tpm_tis.h header Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 19/21] tpm-tis: fold TPMTISEmuState in TPMState Stefan Berger
2017-10-19 18:02 ` [Qemu-devel] [PULL v1 20/21] tpm: add a QOM TPM interface Stefan Berger
2017-10-19 18:02 ` Stefan Berger [this message]
2017-10-20 11:33 ` [Qemu-devel] [PULL v1 00/21] Merge tpm 2017/10/19 Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1508436175-1596-22-git-send-email-stefanb@linux.vnet.ibm.com \
--to=stefanb@linux.vnet.ibm.com \
--cc=marcandre.lureau@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).