diff options
Diffstat (limited to 'hw')
-rw-r--r-- | hw/tpm/tpm_emulator.c | 29 | ||||
-rw-r--r-- | hw/tpm/tpm_int.h | 1 | ||||
-rw-r--r-- | hw/tpm/tpm_passthrough.c | 24 | ||||
-rw-r--r-- | hw/tpm/tpm_tis.c | 18 |
4 files changed, 34 insertions, 38 deletions
diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c index 8fbe9ad74a..0b1a99fcc5 100644 --- a/hw/tpm/tpm_emulator.c +++ b/hw/tpm/tpm_emulator.c @@ -172,28 +172,29 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number) return 0; } -static void tpm_emulator_handle_request(TPMBackend *tb) +static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd) { TPMEmulator *tpm_emu = TPM_EMULATOR(tb); - TPMLocality *locty = NULL; - bool selftest_done = false; Error *err = NULL; DPRINTF("processing TPM command"); - locty = tb->tpm_state->locty_data; - if (tpm_emulator_set_locality(tpm_emu, - tb->tpm_state->locty_number) < 0 || - tpm_emulator_unix_tx_bufs(tpm_emu, locty->w_buffer.buffer, - locty->w_offset, locty->r_buffer.buffer, - locty->r_buffer.size, &selftest_done, - &err) < 0) { - tpm_util_write_fatal_error_response(locty->r_buffer.buffer, - locty->r_buffer.size); - error_report_err(err); + if (tpm_emulator_set_locality(tpm_emu, tb->tpm_state->locty_number) < 0) { + goto error; + } + + if (tpm_emulator_unix_tx_bufs(tpm_emu, cmd->in, cmd->in_len, + cmd->out, cmd->out_len, + &cmd->selftest_done, &err) < 0) { + goto error; } - tb->recv_data_callback(tb->tpm_state, selftest_done); + tb->recv_data_callback(tb->tpm_state); + return; + +error: + tpm_util_write_fatal_error_response(cmd->out, cmd->out_len); + error_report_err(err); } static int tpm_emulator_probe_caps(TPMEmulator *tpm_emu) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index f2f285b3cc..6d7b3dc850 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -26,6 +26,7 @@ struct TPMState { uint8_t locty_number; TPMLocality *locty_data; + TPMBackendCmd cmd; char *backend; TPMBackend *be_driver; diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 0ae4596932..93d72b8e9e 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -137,30 +137,16 @@ err_exit: return ret; } -static int tpm_passthrough_unix_transfer(TPMPassthruState *tpm_pt, - const TPMLocality *locty_data, - bool *selftest_done) -{ - return tpm_passthrough_unix_tx_bufs(tpm_pt, - locty_data->w_buffer.buffer, - locty_data->w_offset, - locty_data->r_buffer.buffer, - locty_data->r_buffer.size, - selftest_done); -} - -static void tpm_passthrough_handle_request(TPMBackend *tb) +static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *cmd) { TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb); - bool selftest_done = false; - DPRINTF("tpm_passthrough: processing command\n"); + DPRINTF("tpm_passthrough: processing command %p\n", cmd); - tpm_passthrough_unix_transfer(tpm_pt, - tb->tpm_state->locty_data, - &selftest_done); + 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, selftest_done); + tb->recv_data_callback(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 345a4fbee5..ffed7bfaf9 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -215,7 +215,15 @@ static void tpm_tis_tpm_send(TPMState *s, uint8_t locty) */ tis->loc[locty].state = TPM_TIS_STATE_EXECUTION; - tpm_backend_deliver_request(s->be_driver); + s->cmd = (TPMBackendCmd) { + .locty = locty, + .in = s->locty_data->w_buffer.buffer, + .in_len = s->locty_data->w_offset, + .out = s->locty_data->r_buffer.buffer, + .out_len = s->locty_data->r_buffer.size + }; + + tpm_backend_deliver_request(s->be_driver, &s->cmd); } /* raise an interrupt if allowed */ @@ -352,7 +360,7 @@ static void tpm_tis_receive_bh(void *opaque) { TPMState *s = opaque; TPMTISEmuState *tis = &s->s.tis; - uint8_t locty = s->locty_number; + uint8_t locty = s->cmd.locty; tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); @@ -371,11 +379,11 @@ 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, - bool is_selftest_done) +static void tpm_tis_receive_cb(TPMState *s) { TPMTISEmuState *tis = &s->s.tis; - uint8_t locty = s->locty_number; + bool is_selftest_done = s->cmd.selftest_done; + uint8_t locty = s->cmd.locty; uint8_t l; if (is_selftest_done) { |