qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@us.ibm.com>
To: qemu-ppc@nongnu.org
Cc: thuth@redhat.com, aik@au1.ibm.com, nikunj@linux.vnet.ibm.com,
	Stefan Berger <stefanb@linux.vnet.ibm.com>,
	agraf@suse.de, qemu-devel@nongnu.org, jb613w@att.com
Subject: [Qemu-devel] [PATCH v2 2/3] tpm: remove TPMState usage from backend
Date: Mon,  4 Jan 2016 11:14:23 -0500	[thread overview]
Message-ID: <1451924064-8625-3-git-send-email-stefanb@us.ibm.com> (raw)
In-Reply-To: <1451924064-8625-1-git-send-email-stefanb@us.ibm.com>

From: Stefan Berger <stefanb@linux.vnet.ibm.com>

Remove the direct TPMState usage from the TPM backend. This allows different
frontends to use the backend. A few more parameters now need to be passed to the
backend.

Other frontends may need different TPMState structures if for example
the device types they are using are not always visible during compilation.
An example is the usage of the PPC64 specific VIOsPAPRDevice whose
include files are not all visible to x86 target for example. Therefore,
we now pass void * where previously TPMState * was passed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
 backends/tpm.c               |  5 +++--
 hw/tpm/tpm_passthrough.c     | 18 ++++++++++++------
 hw/tpm/tpm_tis.c             |  7 +++++--
 include/sysemu/tpm_backend.h | 15 +++++++++++----
 4 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/backends/tpm.c b/backends/tpm.c
index a512693..33af8a1 100644
--- a/backends/tpm.c
+++ b/backends/tpm.c
@@ -39,12 +39,13 @@ void tpm_backend_destroy(TPMBackend *s)
     k->ops->destroy(s);
 }
 
-int tpm_backend_init(TPMBackend *s, TPMState *state,
+int tpm_backend_init(TPMBackend *s, void *state,
+                     uint8_t *locty_number, TPMLocality **locty_data,
                      TPMRecvDataCB *datacb)
 {
     TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
 
-    return k->ops->init(s, state, datacb);
+    return k->ops->init(s, state, locty_number, locty_data, datacb);
 }
 
 int tpm_backend_startup_tpm(TPMBackend *s)
diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
index cef3696..50ef15c 100644
--- a/hw/tpm/tpm_passthrough.c
+++ b/hw/tpm/tpm_passthrough.c
@@ -54,7 +54,10 @@ static const VMStateDescription vmstate_tpm_cuse;
 
 /* data structures */
 typedef struct TPMPassthruThreadParams {
-    TPMState *tpm_state;
+    void *tpm_state;
+
+    uint8_t *locty_number;
+    TPMLocality **locty_data;
 
     TPMRecvDataCB *recv_data_callback;
     TPMBackend *tb;
@@ -252,12 +255,12 @@ static void tpm_passthrough_worker_thread(gpointer data,
     switch (cmd) {
     case TPM_BACKEND_CMD_PROCESS_CMD:
         tpm_passthrough_unix_transfer(tpm_pt,
-                                      thr_parms->tpm_state->locty_number,
-                                      thr_parms->tpm_state->locty_data,
+                                      *thr_parms->locty_number,
+                                      *thr_parms->locty_data,
                                       &selftest_done);
 
         thr_parms->recv_data_callback(thr_parms->tpm_state,
-                                      thr_parms->tpm_state->locty_number,
+                                      *thr_parms->locty_number,
                                       selftest_done);
         /* result delivered */
         qemu_mutex_lock(&tpm_pt->state_lock);
@@ -400,12 +403,15 @@ static void tpm_passthrough_reset(TPMBackend *tb)
     tpm_pt->tpm_busy = false;
 }
 
-static int tpm_passthrough_init(TPMBackend *tb, TPMState *s,
+static int tpm_passthrough_init(TPMBackend *tb, void *tpm_state,
+                                uint8_t *locty_number, TPMLocality **locty_data,
                                 TPMRecvDataCB *recv_data_cb)
 {
     TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
 
-    tpm_pt->tpm_thread_params.tpm_state = s;
+    tpm_pt->tpm_thread_params.tpm_state = tpm_state;
+    tpm_pt->tpm_thread_params.locty_number = locty_number;
+    tpm_pt->tpm_thread_params.locty_data = locty_data;
     tpm_pt->tpm_thread_params.recv_data_callback = recv_data_cb;
     tpm_pt->tpm_thread_params.tb = tb;
 
diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index 61b26d1..3b69af4 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -395,9 +395,10 @@ static void tpm_tis_receive_bh(void *opaque)
 /*
  * Callback from the TPM to indicate that the response was received.
  */
-static void tpm_tis_receive_cb(TPMState *s, uint8_t locty,
+static void tpm_tis_receive_cb(void *opaque, uint8_t locty,
                                bool is_selftest_done)
 {
+    TPMState *s = opaque;
     TPMTISEmuState *tis = &s->s.tis;
     uint8_t l;
 
@@ -1189,7 +1190,9 @@ 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,
+                         &s->locty_number, &s->locty_data,
+                         tpm_tis_receive_cb)) {
         error_setg(errp, "tpm_tis: backend driver with id %s could not be "
                    "initialized", s->backend);
         return;
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 92bc3e4..927254a 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -33,6 +33,8 @@ typedef struct TPMBackend TPMBackend;
 
 typedef struct TPMDriverOps TPMDriverOps;
 
+typedef struct TPMLocality TPMLocality;
+
 struct TPMBackendClass {
     ObjectClass parent_class;
 
@@ -56,7 +58,7 @@ struct TPMBackend {
     QLIST_ENTRY(TPMBackend) list;
 };
 
-typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done);
+typedef void (TPMRecvDataCB)(void *, uint8_t locty, bool selftest_done);
 
 typedef struct TPMSizedBuffer {
     uint32_t size;
@@ -85,7 +87,9 @@ struct TPMDriverOps {
     void (*destroy)(TPMBackend *t);
 
     /* initialize the backend */
-    int (*init)(TPMBackend *t, TPMState *s, TPMRecvDataCB *datacb);
+    int (*init)(TPMBackend *t, void *tpm_state,
+                uint8_t *locty_number, TPMLocality **locty_data,
+                TPMRecvDataCB *datacb);
     /* start up the TPM on the backend */
     int (*startup_tpm)(TPMBackend *t);
     /* returns true if nothing will ever answer TPM requests */
@@ -132,14 +136,17 @@ void tpm_backend_destroy(TPMBackend *s);
 /**
  * tpm_backend_init:
  * @s: the backend to initialized
- * @state: TPMState
+ * @state: opaque pointer to TPM state
+ * @locty_number: pointer to locality_number
+ * @locty_data: pointer to locality_data pointer
  * @datacb: callback for sending data to frontend
  *
  * Initialize the backend with the given variables.
  *
  * Returns 0 on success.
  */
-int tpm_backend_init(TPMBackend *s, TPMState *state,
+int tpm_backend_init(TPMBackend *s, void *state,
+                     uint8_t *locty_number, TPMLocality **locty_data,
                      TPMRecvDataCB *datacb);
 
 /**
-- 
2.4.3

  parent reply	other threads:[~2016-01-04 16:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-04 16:14 [Qemu-devel] [PATCH v2 0/3] Add TPM support to ppc64 Stefan Berger
2016-01-04 16:14 ` [Qemu-devel] [PATCH v2 1/3] Enable PPC64 with TPM support Stefan Berger
2016-01-04 16:14 ` Stefan Berger [this message]
2016-01-04 16:14 ` [Qemu-devel] [PATCH v2 3/3] tpm: Support TPM for ppc64 using CRQ based interface 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=1451924064-8625-3-git-send-email-stefanb@us.ibm.com \
    --to=stefanb@us.ibm.com \
    --cc=agraf@suse.de \
    --cc=aik@au1.ibm.com \
    --cc=jb613w@att.com \
    --cc=nikunj@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    --cc=thuth@redhat.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 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).