All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: amarnath.valluri@intel.com, stefanb@linux.vnet.ibm.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH 21/42] tpm: move recv_data_callback to TPM interface
Date: Tue, 10 Oct 2017 00:56:02 +0200	[thread overview]
Message-ID: <20171009225623.29232-22-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20171009225623.29232-1-marcandre.lureau@redhat.com>

Simplify the TPM backend setup, move callback to TPM interface.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/tpm/tpm_int.h             |  3 +++
 include/sysemu/tpm_backend.h |  6 +-----
 backends/tpm.c               |  4 +---
 hw/tpm/tpm_emulator.c        |  3 ++-
 hw/tpm/tpm_passthrough.c     |  3 ++-
 hw/tpm/tpm_tis.c             | 11 ++++++-----
 6 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h
index eb02e7760c..9c045b6691 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/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 3bb90be3de..03ea5a3400 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:
diff --git a/backends/tpm.c b/backends/tpm.c
index 87c5c09179..5763f6f369 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 407ac97651..f04f4e0830 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_passthrough.c b/hw/tpm/tpm_passthrough.c
index 4274164a61..c440aff4b2 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 dbb50043ac..8c5cac5fa5 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 = {
-- 
2.14.1.146.gd35faa819

  parent reply	other threads:[~2017-10-09 22:57 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-09 22:55 [Qemu-devel] [PATCH 00/42] TPM: code cleanup & CRB device Marc-André Lureau
2017-10-09 22:55 ` [Qemu-devel] [PATCH 01/42] tpm-tis: remove unused hw_access argument Marc-André Lureau
2017-10-10  2:34   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 02/42] tpm-tis: remove RAISE_STS_IRQ Marc-André Lureau
2017-10-10  2:36   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 03/42] tpm: make tpm_get_backend_driver() static Marc-André Lureau
2017-10-10  2:36   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 04/42] tpm: lookup tpm backend class in tpm_driver_find_by_type() Marc-André Lureau
2017-10-10  2:38   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 05/42] tpm: replace tpm_get_backend_driver() to drop be_drivers Marc-André Lureau
2017-10-10  2:40   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 06/42] tpm: remove tpm_register_driver() Marc-André Lureau
2017-10-10  2:41   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 07/42] tpm: move TPMSizedBuffer to tpm_tis.h Marc-André Lureau
2017-10-10  2:41   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 08/42] tpm: remove TPMDriverOps Marc-André Lureau
2017-10-10  7:12   ` Valluri, Amarnath
2017-10-10  7:29     ` Valluri, Amarnath
2017-10-19 14:43   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 09/42] tpm: remove init() class method Marc-André Lureau
2017-10-10 15:30   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 10/42] tpm: remove configure_tpm() hop Marc-André Lureau
2017-10-10 15:31   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 11/42] tpm: remove unused TPMBackendCmd Marc-André Lureau
2017-10-19 14:39   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 12/42] tpm: remove needless cast Marc-André Lureau
2017-10-10 15:31   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 13/42] tpm: remove locty argument from receive_cb Marc-André Lureau
2017-10-10 15:32   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 14/42] tpm: add TPMBackendCmd to hold the request state Marc-André Lureau
2017-10-10 15:38   ` Stefan Berger
2017-10-10 16:16     ` Marc-André Lureau
2017-10-11  1:27       ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 15/42] tpm-emulator: fix error handling Marc-André Lureau
2017-10-10 15:39   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 16/42] tpm: remove locty_data from TPMState Marc-André Lureau
2017-10-10 15:42   ` Stefan Berger
2017-10-09 22:55 ` [Qemu-devel] [PATCH 17/42] tpm-tis: move TPMState to TIS header Marc-André Lureau
2017-10-10 15:45   ` Stefan Berger
2017-10-10 16:01     ` Marc-André Lureau
2017-10-09 22:55 ` [Qemu-devel] [PATCH 18/42] tpm-tis: remove tpm_tis.h header Marc-André Lureau
2017-10-10 18:03   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 19/42] tpm-tis: fold TPMTISEmuState in TPMState Marc-André Lureau
2017-10-10 18:07   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 20/42] tpm: add a QOM TPM interface Marc-André Lureau
2017-10-10 18:09   ` Stefan Berger
2017-10-09 22:56 ` Marc-André Lureau [this message]
2017-10-10 20:17   ` [Qemu-devel] [PATCH 21/42] tpm: move recv_data_callback to " Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 22/42] tpm-backend: store TPMIf interface, improve backend_init() Marc-André Lureau
2017-10-10  8:18   ` Valluri, Amarnath
2017-10-10 11:02     ` Marc-André Lureau
2017-10-09 22:56 ` [Qemu-devel] [PATCH 23/42] tpm-tis: no longer expose TPMState Marc-André Lureau
2017-10-10 20:17   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 24/42] tpm-be: call request_completed() out of thread Marc-André Lureau
2017-10-19 14:35   ` Stefan Berger
2017-10-19 22:02   ` Stefan Berger
2017-10-19 23:21     ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 25/42] tpm-be: report error instead of front-end Marc-André Lureau
2017-10-10 20:20   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 26/42] tpm-be: ask model to the TPM interface Marc-André Lureau
2017-10-10 20:22   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 27/42] tpm: remove unused opened code Marc-André Lureau
2017-10-10 20:50   ` Stefan Berger
2017-10-10 22:27     ` Marc-André Lureau
2017-10-11  1:30       ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 28/42] tpm-passthrough: don't save guessed cancel_path in options Marc-André Lureau
2017-10-10 20:26   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 29/42] tpm-be: update optional function pointers Marc-André Lureau
2017-10-10 20:28   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 30/42] tpm-passthrough: pass TPMPassthruState to handle_device_opts Marc-André Lureau
2017-10-10 20:29   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 31/42] tpm-backend: move set 'id' to common code Marc-André Lureau
2017-10-10  8:15   ` Valluri, Amarnath
2017-10-10 10:47     ` Marc-André Lureau
2017-10-10 11:39       ` Valluri, Amarnath
2017-10-10 20:31   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 32/42] tpm-passthrough: make it safer to destroy after creation Marc-André Lureau
2017-10-10 18:13   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 33/42] tpm-passthrough: remove error cleanup from handle_device_opts Marc-André Lureau
2017-10-10 20:34   ` Stefan Berger
2017-10-10 22:19     ` Marc-André Lureau
2017-10-11  1:28       ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 34/42] tpm-passthrough: workaround a possible race Marc-André Lureau
2017-10-10 20:37   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 35/42] tpm-tis: simplify header inclusion Marc-André Lureau
2017-10-10 20:38   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 36/42] tpm: rename qemu_find_tpm() -> qemu_find_tpm_be() Marc-André Lureau
2017-10-10 20:38   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 37/42] tpm: lookup the the TPM interface instead of TIS device Marc-André Lureau
2017-10-10 20:21   ` Eduardo Habkost
2017-10-10 20:47     ` Stefan Berger
2017-10-10 22:31       ` Marc-André Lureau
2017-10-10 20:42   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 38/42] tpm: add TPM interface to lookup TPM version Marc-André Lureau
2017-10-10 20:43   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 39/42] tpm: add tpm_cmd_get_size() to tpm_util Marc-André Lureau
2017-10-10 18:23   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 40/42] acpi: change TPM TIS data conditions Marc-André Lureau
2017-10-10 18:22   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 41/42] tpm-emulator: add a FIXME comment about blocking cancel Marc-André Lureau
2017-10-10 18:21   ` Stefan Berger
2017-10-09 22:56 ` [Qemu-devel] [PATCH 42/42] WIP: add TPM CRB device Marc-André Lureau
2017-10-10 18:28   ` Stefan Berger
2017-10-10 20:19     ` Eduardo Habkost
2017-10-20 15:31   ` Stefan Berger
2017-11-06 17:49   ` Stefan Berger
2017-10-09 23:32 ` [Qemu-devel] [PATCH 00/42] TPM: code cleanup & " no-reply
2017-10-10  2:34 ` Stefan Berger
2017-10-10 12:14   ` Marc-André Lureau
2017-10-10 18:20     ` Stefan Berger
2017-10-19 14:26 ` Stefan Berger
2017-10-19 14:33   ` Marc-André Lureau
2017-10-19 14:44     ` Stefan Berger
2017-10-19 16:50       ` Stefan Berger
2017-10-19 17:00         ` Marc-André Lureau
2017-10-19 23:55           ` Stefan Berger

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=20171009225623.29232-22-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=amarnath.valluri@intel.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.