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 <stef...@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 f3ab3b3..fec8234 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 04edf00..19a9bab 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -55,7 +55,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; @@ -253,12 +256,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); @@ -401,12 +404,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 6393411..79703ee 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); /** -- 1.9.3