mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/stefanberger/tags/pull-tpm-2017-10-19-1' into staging
Merge tpm 2017/10/19 v1 # gpg: Signature made Thu 19 Oct 2017 16:42:39 BST # gpg: using RSA key 0x75AD65802A0B4211 # gpg: Good signature from "Stefan Berger <stefanb@linux.vnet.ibm.com>" # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: B818 B9CA DF90 89C2 D5CE C66B 75AD 6580 2A0B 4211 * remotes/stefanberger/tags/pull-tpm-2017-10-19-1: (21 commits) tpm: move recv_data_callback to TPM interface tpm: add a QOM TPM interface tpm-tis: fold TPMTISEmuState in TPMState tpm-tis: remove tpm_tis.h header tpm-tis: move TPMState to TIS header tpm: remove locty_data from TPMState tpm-emulator: fix error handling tpm: add TPMBackendCmd to hold the request state tpm: remove locty argument from receive_cb tpm: remove needless cast tpm: remove unused TPMBackendCmd tpm: remove configure_tpm() hop tpm: remove init() class method tpm: remove TPMDriverOps tpm: move TPMSizedBuffer to tpm_tis.h tpm: remove tpm_register_driver() tpm: replace tpm_get_backend_driver() to drop be_drivers tpm: lookup tpm backend class in tpm_driver_find_by_type() tpm: make tpm_get_backend_driver() static tpm-tis: remove RAISE_STS_IRQ ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
+28
-26
@@ -17,6 +17,7 @@
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "sysemu/tpm.h"
|
||||
#include "hw/tpm/tpm_int.h"
|
||||
#include "qemu/thread.h"
|
||||
|
||||
static void tpm_backend_worker_thread(gpointer data, gpointer user_data)
|
||||
@@ -25,13 +26,12 @@ static void tpm_backend_worker_thread(gpointer data, gpointer user_data)
|
||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
||||
|
||||
assert(k->handle_request != NULL);
|
||||
k->handle_request(s, (TPMBackendCmd)data);
|
||||
k->handle_request(s, (TPMBackendCmd *)data);
|
||||
}
|
||||
|
||||
static void tpm_backend_thread_end(TPMBackend *s)
|
||||
{
|
||||
if (s->thread_pool) {
|
||||
g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_END, NULL);
|
||||
g_thread_pool_free(s->thread_pool, FALSE, TRUE);
|
||||
s->thread_pool = NULL;
|
||||
}
|
||||
@@ -41,19 +41,15 @@ enum TpmType tpm_backend_get_type(TPMBackend *s)
|
||||
{
|
||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
||||
|
||||
return k->ops->type;
|
||||
return k->type;
|
||||
}
|
||||
|
||||
int tpm_backend_init(TPMBackend *s, TPMState *state,
|
||||
TPMRecvDataCB *datacb)
|
||||
int tpm_backend_init(TPMBackend *s, TPMState *state)
|
||||
{
|
||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
||||
|
||||
s->tpm_state = state;
|
||||
s->recv_data_callback = datacb;
|
||||
s->had_startup_error = false;
|
||||
|
||||
return k->ops->init ? k->ops->init(s) : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tpm_backend_startup_tpm(TPMBackend *s)
|
||||
@@ -66,9 +62,8 @@ int tpm_backend_startup_tpm(TPMBackend *s)
|
||||
|
||||
s->thread_pool = g_thread_pool_new(tpm_backend_worker_thread, s, 1, TRUE,
|
||||
NULL);
|
||||
g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_INIT, NULL);
|
||||
|
||||
res = k->ops->startup_tpm ? k->ops->startup_tpm(s) : 0;
|
||||
res = k->startup_tpm ? k->startup_tpm(s) : 0;
|
||||
|
||||
s->had_startup_error = (res != 0);
|
||||
|
||||
@@ -80,18 +75,17 @@ bool tpm_backend_had_startup_error(TPMBackend *s)
|
||||
return s->had_startup_error;
|
||||
}
|
||||
|
||||
void tpm_backend_deliver_request(TPMBackend *s)
|
||||
void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd)
|
||||
{
|
||||
g_thread_pool_push(s->thread_pool, (gpointer)TPM_BACKEND_CMD_PROCESS_CMD,
|
||||
NULL);
|
||||
g_thread_pool_push(s->thread_pool, cmd, NULL);
|
||||
}
|
||||
|
||||
void tpm_backend_reset(TPMBackend *s)
|
||||
{
|
||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
||||
|
||||
if (k->ops->reset) {
|
||||
k->ops->reset(s);
|
||||
if (k->reset) {
|
||||
k->reset(s);
|
||||
}
|
||||
|
||||
tpm_backend_thread_end(s);
|
||||
@@ -103,34 +97,34 @@ void tpm_backend_cancel_cmd(TPMBackend *s)
|
||||
{
|
||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
||||
|
||||
assert(k->ops->cancel_cmd);
|
||||
assert(k->cancel_cmd);
|
||||
|
||||
k->ops->cancel_cmd(s);
|
||||
k->cancel_cmd(s);
|
||||
}
|
||||
|
||||
bool tpm_backend_get_tpm_established_flag(TPMBackend *s)
|
||||
{
|
||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
||||
|
||||
return k->ops->get_tpm_established_flag ?
|
||||
k->ops->get_tpm_established_flag(s) : false;
|
||||
return k->get_tpm_established_flag ?
|
||||
k->get_tpm_established_flag(s) : false;
|
||||
}
|
||||
|
||||
int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty)
|
||||
{
|
||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
||||
|
||||
return k->ops->reset_tpm_established_flag ?
|
||||
k->ops->reset_tpm_established_flag(s, locty) : 0;
|
||||
return k->reset_tpm_established_flag ?
|
||||
k->reset_tpm_established_flag(s, locty) : 0;
|
||||
}
|
||||
|
||||
TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)
|
||||
{
|
||||
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
|
||||
|
||||
assert(k->ops->get_tpm_version);
|
||||
assert(k->get_tpm_version);
|
||||
|
||||
return k->ops->get_tpm_version(s);
|
||||
return k->get_tpm_version(s);
|
||||
}
|
||||
|
||||
TPMInfo *tpm_backend_query_tpm(TPMBackend *s)
|
||||
@@ -140,8 +134,9 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s)
|
||||
|
||||
info->id = g_strdup(s->id);
|
||||
info->model = s->fe_model;
|
||||
info->options = k->ops->get_tpm_options ?
|
||||
k->ops->get_tpm_options(s) : NULL;
|
||||
if (k->get_tpm_options) {
|
||||
info->options = k->get_tpm_options(s);
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
@@ -213,9 +208,16 @@ static const TypeInfo tpm_backend_info = {
|
||||
.abstract = true,
|
||||
};
|
||||
|
||||
static const TypeInfo tpm_if_info = {
|
||||
.name = TYPE_TPM_IF,
|
||||
.parent = TYPE_INTERFACE,
|
||||
.class_size = sizeof(TPMIfClass),
|
||||
};
|
||||
|
||||
static void register_types(void)
|
||||
{
|
||||
type_register_static(&tpm_backend_info);
|
||||
type_register_static(&tpm_if_info);
|
||||
}
|
||||
|
||||
type_init(register_types);
|
||||
|
||||
+36
-50
@@ -60,8 +60,6 @@
|
||||
|
||||
#define TPM_EMULATOR_IMPLEMENTS_ALL_CAPS(S, cap) (((S)->caps & (cap)) == (cap))
|
||||
|
||||
static const TPMDriverOps tpm_emulator_driver;
|
||||
|
||||
/* data structures */
|
||||
typedef struct TPMEmulator {
|
||||
TPMBackend parent;
|
||||
@@ -143,7 +141,8 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number)
|
||||
static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number,
|
||||
Error **errp)
|
||||
{
|
||||
ptm_loc loc;
|
||||
|
||||
@@ -157,15 +156,15 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number)
|
||||
loc.u.req.loc = locty_number;
|
||||
if (tpm_emulator_ctrlcmd(&tpm_emu->ctrl_chr, CMD_SET_LOCALITY, &loc,
|
||||
sizeof(loc), sizeof(loc)) < 0) {
|
||||
error_report("tpm-emulator: could not set locality : %s",
|
||||
strerror(errno));
|
||||
error_setg(errp, "tpm-emulator: could not set locality : %s",
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
loc.u.resp.tpm_result = be32_to_cpu(loc.u.resp.tpm_result);
|
||||
if (loc.u.resp.tpm_result != 0) {
|
||||
error_report("tpm-emulator: TPM result for set locality : 0x%x",
|
||||
loc.u.resp.tpm_result);
|
||||
error_setg(errp, "tpm-emulator: TPM result for set locality : 0x%x",
|
||||
loc.u.resp.tpm_result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -174,39 +173,30 @@ static int tpm_emulator_set_locality(TPMEmulator *tpm_emu, uint8_t locty_number)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd cmd)
|
||||
static void tpm_emulator_handle_request(TPMBackend *tb, TPMBackendCmd *cmd)
|
||||
{
|
||||
TPMEmulator *tpm_emu = TPM_EMULATOR(tb);
|
||||
TPMLocality *locty = NULL;
|
||||
bool selftest_done = false;
|
||||
TPMIfClass *tic = TPM_IF_GET_CLASS(tb->tpm_state);
|
||||
Error *err = NULL;
|
||||
|
||||
DPRINTF("processing command type %d", cmd);
|
||||
DPRINTF("processing TPM command");
|
||||
|
||||
switch (cmd) {
|
||||
case TPM_BACKEND_CMD_PROCESS_CMD:
|
||||
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);
|
||||
}
|
||||
|
||||
tb->recv_data_callback(tb->tpm_state, tb->tpm_state->locty_number,
|
||||
selftest_done);
|
||||
|
||||
break;
|
||||
case TPM_BACKEND_CMD_INIT:
|
||||
case TPM_BACKEND_CMD_END:
|
||||
case TPM_BACKEND_CMD_TPM_RESET:
|
||||
/* nothing to do */
|
||||
break;
|
||||
if (tpm_emulator_set_locality(tpm_emu, cmd->locty, &err) < 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;
|
||||
}
|
||||
|
||||
tic->request_completed(TPM_IF(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)
|
||||
@@ -504,20 +494,6 @@ static const QemuOptDesc tpm_emulator_cmdline_opts[] = {
|
||||
{ /* end of list */ },
|
||||
};
|
||||
|
||||
static const TPMDriverOps tpm_emulator_driver = {
|
||||
.type = TPM_TYPE_EMULATOR,
|
||||
.opts = tpm_emulator_cmdline_opts,
|
||||
.desc = "TPM emulator backend driver",
|
||||
|
||||
.create = tpm_emulator_create,
|
||||
.startup_tpm = tpm_emulator_startup_tpm,
|
||||
.cancel_cmd = tpm_emulator_cancel_cmd,
|
||||
.get_tpm_established_flag = tpm_emulator_get_tpm_established_flag,
|
||||
.reset_tpm_established_flag = tpm_emulator_reset_tpm_established_flag,
|
||||
.get_tpm_version = tpm_emulator_get_tpm_version,
|
||||
.get_tpm_options = tpm_emulator_get_tpm_options,
|
||||
};
|
||||
|
||||
static void tpm_emulator_inst_init(Object *obj)
|
||||
{
|
||||
TPMEmulator *tpm_emu = TPM_EMULATOR(obj);
|
||||
@@ -565,7 +541,18 @@ static void tpm_emulator_inst_finalize(Object *obj)
|
||||
static void tpm_emulator_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
TPMBackendClass *tbc = TPM_BACKEND_CLASS(klass);
|
||||
tbc->ops = &tpm_emulator_driver;
|
||||
|
||||
tbc->type = TPM_TYPE_EMULATOR;
|
||||
tbc->opts = tpm_emulator_cmdline_opts;
|
||||
tbc->desc = "TPM emulator backend driver";
|
||||
tbc->create = tpm_emulator_create;
|
||||
tbc->startup_tpm = tpm_emulator_startup_tpm;
|
||||
tbc->cancel_cmd = tpm_emulator_cancel_cmd;
|
||||
tbc->get_tpm_established_flag = tpm_emulator_get_tpm_established_flag;
|
||||
tbc->reset_tpm_established_flag = tpm_emulator_reset_tpm_established_flag;
|
||||
tbc->get_tpm_version = tpm_emulator_get_tpm_version;
|
||||
tbc->get_tpm_options = tpm_emulator_get_tpm_options;
|
||||
|
||||
tbc->handle_request = tpm_emulator_handle_request;
|
||||
}
|
||||
|
||||
@@ -581,7 +568,6 @@ static const TypeInfo tpm_emulator_info = {
|
||||
static void tpm_emulator_register(void)
|
||||
{
|
||||
type_register_static(&tpm_emulator_info);
|
||||
tpm_register_driver(&tpm_emulator_driver);
|
||||
}
|
||||
|
||||
type_init(tpm_emulator_register)
|
||||
|
||||
+18
-18
@@ -12,29 +12,29 @@
|
||||
#ifndef TPM_TPM_INT_H
|
||||
#define TPM_TPM_INT_H
|
||||
|
||||
#include "exec/memory.h"
|
||||
#include "tpm_tis.h"
|
||||
#include "qemu/osdep.h"
|
||||
#include "qom/object.h"
|
||||
|
||||
/* overall state of the TPM interface */
|
||||
struct TPMState {
|
||||
ISADevice busdev;
|
||||
MemoryRegion mmio;
|
||||
#define TYPE_TPM_IF "tpm-if"
|
||||
#define TPM_IF_CLASS(klass) \
|
||||
OBJECT_CLASS_CHECK(TPMIfClass, (klass), TYPE_TPM_IF)
|
||||
#define TPM_IF_GET_CLASS(obj) \
|
||||
OBJECT_GET_CLASS(TPMIfClass, (obj), TYPE_TPM_IF)
|
||||
#define TPM_IF(obj) \
|
||||
INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF)
|
||||
|
||||
union {
|
||||
TPMTISEmuState tis;
|
||||
} s;
|
||||
typedef struct TPMIf {
|
||||
Object parent_obj;
|
||||
} TPMIf;
|
||||
|
||||
uint8_t locty_number;
|
||||
TPMLocality *locty_data;
|
||||
typedef struct TPMIfClass {
|
||||
InterfaceClass parent_class;
|
||||
|
||||
char *backend;
|
||||
TPMBackend *be_driver;
|
||||
TPMVersion be_tpm_version;
|
||||
};
|
||||
/* run in thread pool by backend */
|
||||
void (*request_completed)(TPMIf *obj);
|
||||
} TPMIfClass;
|
||||
|
||||
#define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)
|
||||
|
||||
#define TPM_STANDARD_CMDLINE_OPTS \
|
||||
#define TPM_STANDARD_CMDLINE_OPTS \
|
||||
{ \
|
||||
.name = "type", \
|
||||
.type = QEMU_OPT_STRING, \
|
||||
|
||||
+18
-47
@@ -31,7 +31,6 @@
|
||||
#include "hw/hw.h"
|
||||
#include "hw/i386/pc.h"
|
||||
#include "qapi/clone-visitor.h"
|
||||
#include "tpm_tis.h"
|
||||
#include "tpm_util.h"
|
||||
|
||||
#define DEBUG_TPM 0
|
||||
@@ -96,7 +95,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
|
||||
|
||||
is_selftest = tpm_util_is_selftest(in, in_len);
|
||||
|
||||
ret = qemu_write_full(tpm_pt->tpm_fd, (const void *)in, (size_t)in_len);
|
||||
ret = qemu_write_full(tpm_pt->tpm_fd, in, in_len);
|
||||
if (ret != in_len) {
|
||||
if (!tpm_pt->tpm_op_canceled || errno != ECANCELED) {
|
||||
error_report("tpm_passthrough: error while transmitting data "
|
||||
@@ -137,41 +136,17 @@ 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, TPMBackendCmd cmd)
|
||||
static void tpm_passthrough_handle_request(TPMBackend *tb, TPMBackendCmd *cmd)
|
||||
{
|
||||
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
|
||||
bool selftest_done = false;
|
||||
TPMIfClass *tic = TPM_IF_GET_CLASS(tb->tpm_state);
|
||||
|
||||
DPRINTF("tpm_passthrough: processing command type %d\n", cmd);
|
||||
DPRINTF("tpm_passthrough: processing command %p\n", cmd);
|
||||
|
||||
switch (cmd) {
|
||||
case TPM_BACKEND_CMD_PROCESS_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,
|
||||
tb->tpm_state->locty_number,
|
||||
selftest_done);
|
||||
break;
|
||||
case TPM_BACKEND_CMD_INIT:
|
||||
case TPM_BACKEND_CMD_END:
|
||||
case TPM_BACKEND_CMD_TPM_RESET:
|
||||
/* nothing to do */
|
||||
break;
|
||||
}
|
||||
tic->request_completed(TPM_IF(tb->tpm_state));
|
||||
}
|
||||
|
||||
static void tpm_passthrough_reset(TPMBackend *tb)
|
||||
@@ -365,19 +340,6 @@ static const QemuOptDesc tpm_passthrough_cmdline_opts[] = {
|
||||
{ /* end of list */ },
|
||||
};
|
||||
|
||||
static const TPMDriverOps tpm_passthrough_driver = {
|
||||
.type = TPM_TYPE_PASSTHROUGH,
|
||||
.opts = tpm_passthrough_cmdline_opts,
|
||||
.desc = "Passthrough TPM backend driver",
|
||||
.create = tpm_passthrough_create,
|
||||
.reset = tpm_passthrough_reset,
|
||||
.cancel_cmd = tpm_passthrough_cancel_cmd,
|
||||
.get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag,
|
||||
.reset_tpm_established_flag = tpm_passthrough_reset_tpm_established_flag,
|
||||
.get_tpm_version = tpm_passthrough_get_tpm_version,
|
||||
.get_tpm_options = tpm_passthrough_get_tpm_options,
|
||||
};
|
||||
|
||||
static void tpm_passthrough_inst_init(Object *obj)
|
||||
{
|
||||
TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(obj);
|
||||
@@ -402,7 +364,17 @@ static void tpm_passthrough_class_init(ObjectClass *klass, void *data)
|
||||
{
|
||||
TPMBackendClass *tbc = TPM_BACKEND_CLASS(klass);
|
||||
|
||||
tbc->ops = &tpm_passthrough_driver;
|
||||
tbc->type = TPM_TYPE_PASSTHROUGH;
|
||||
tbc->opts = tpm_passthrough_cmdline_opts;
|
||||
tbc->desc = "Passthrough TPM backend driver";
|
||||
tbc->create = tpm_passthrough_create;
|
||||
tbc->reset = tpm_passthrough_reset;
|
||||
tbc->cancel_cmd = tpm_passthrough_cancel_cmd;
|
||||
tbc->get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag;
|
||||
tbc->reset_tpm_established_flag =
|
||||
tpm_passthrough_reset_tpm_established_flag;
|
||||
tbc->get_tpm_version = tpm_passthrough_get_tpm_version;
|
||||
tbc->get_tpm_options = tpm_passthrough_get_tpm_options;
|
||||
tbc->handle_request = tpm_passthrough_handle_request;
|
||||
}
|
||||
|
||||
@@ -418,7 +390,6 @@ static const TypeInfo tpm_passthrough_info = {
|
||||
static void tpm_passthrough_register(void)
|
||||
{
|
||||
type_register_static(&tpm_passthrough_info);
|
||||
tpm_register_driver(&tpm_passthrough_driver);
|
||||
}
|
||||
|
||||
type_init(tpm_passthrough_register)
|
||||
|
||||
+243
-214
File diff suppressed because it is too large
Load Diff
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* tpm_tis.h - QEMU's TPM TIS interface emulator
|
||||
*
|
||||
* Copyright (C) 2006, 2010-2013 IBM Corporation
|
||||
*
|
||||
* Authors:
|
||||
* Stefan Berger <stefanb@us.ibm.com>
|
||||
* David Safford <safford@us.ibm.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
* Implementation of the TIS interface according to specs found at
|
||||
* http://www.trustedcomputinggroup.org
|
||||
*
|
||||
*/
|
||||
#ifndef TPM_TPM_TIS_H
|
||||
#define TPM_TPM_TIS_H
|
||||
|
||||
#include "hw/isa/isa.h"
|
||||
#include "hw/acpi/tpm.h"
|
||||
#include "qemu-common.h"
|
||||
|
||||
#define TPM_TIS_NUM_LOCALITIES 5 /* per spec */
|
||||
#define TPM_TIS_LOCALITY_SHIFT 12
|
||||
#define TPM_TIS_NO_LOCALITY 0xff
|
||||
|
||||
#define TPM_TIS_IS_VALID_LOCTY(x) ((x) < TPM_TIS_NUM_LOCALITIES)
|
||||
|
||||
#define TPM_TIS_BUFFER_MAX 4096
|
||||
|
||||
typedef enum {
|
||||
TPM_TIS_STATE_IDLE = 0,
|
||||
TPM_TIS_STATE_READY,
|
||||
TPM_TIS_STATE_COMPLETION,
|
||||
TPM_TIS_STATE_EXECUTION,
|
||||
TPM_TIS_STATE_RECEPTION,
|
||||
} TPMTISState;
|
||||
|
||||
/* locality data -- all fields are persisted */
|
||||
typedef struct TPMLocality {
|
||||
TPMTISState state;
|
||||
uint8_t access;
|
||||
uint32_t sts;
|
||||
uint32_t iface_id;
|
||||
uint32_t inte;
|
||||
uint32_t ints;
|
||||
|
||||
uint16_t w_offset;
|
||||
uint16_t r_offset;
|
||||
TPMSizedBuffer w_buffer;
|
||||
TPMSizedBuffer r_buffer;
|
||||
} TPMLocality;
|
||||
|
||||
typedef struct TPMTISEmuState {
|
||||
QEMUBH *bh;
|
||||
uint32_t offset;
|
||||
uint8_t buf[TPM_TIS_BUFFER_MAX];
|
||||
|
||||
uint8_t active_locty;
|
||||
uint8_t aborting_locty;
|
||||
uint8_t next_locty;
|
||||
|
||||
TPMLocality loc[TPM_TIS_NUM_LOCALITIES];
|
||||
|
||||
qemu_irq irq;
|
||||
uint32_t irq_num;
|
||||
} TPMTISEmuState;
|
||||
|
||||
#endif /* TPM_TPM_TIS_H */
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "tpm_util.h"
|
||||
#include "tpm_int.h"
|
||||
#include "exec/memory.h"
|
||||
|
||||
/*
|
||||
* Write an error message in the given output buffer.
|
||||
|
||||
@@ -29,14 +29,14 @@
|
||||
|
||||
typedef struct TPMBackendClass TPMBackendClass;
|
||||
typedef struct TPMBackend TPMBackend;
|
||||
typedef struct TPMDriverOps TPMDriverOps;
|
||||
typedef void (TPMRecvDataCB)(TPMState *, uint8_t locty, bool selftest_done);
|
||||
|
||||
typedef enum TPMBackendCmd {
|
||||
TPM_BACKEND_CMD_INIT = 1,
|
||||
TPM_BACKEND_CMD_PROCESS_CMD,
|
||||
TPM_BACKEND_CMD_END,
|
||||
TPM_BACKEND_CMD_TPM_RESET,
|
||||
typedef struct TPMBackendCmd {
|
||||
uint8_t locty;
|
||||
const uint8_t *in;
|
||||
uint32_t in_len;
|
||||
uint8_t *out;
|
||||
uint32_t out_len;
|
||||
bool selftest_done;
|
||||
} TPMBackendCmd;
|
||||
|
||||
struct TPMBackend {
|
||||
@@ -46,7 +46,6 @@ struct TPMBackend {
|
||||
bool opened;
|
||||
TPMState *tpm_state;
|
||||
GThreadPool *thread_pool;
|
||||
TPMRecvDataCB *recv_data_callback;
|
||||
bool had_startup_error;
|
||||
|
||||
/* <public> */
|
||||
@@ -59,19 +58,6 @@ struct TPMBackend {
|
||||
struct TPMBackendClass {
|
||||
ObjectClass parent_class;
|
||||
|
||||
const TPMDriverOps *ops;
|
||||
|
||||
void (*opened)(TPMBackend *s, Error **errp);
|
||||
|
||||
void (*handle_request)(TPMBackend *s, TPMBackendCmd cmd);
|
||||
};
|
||||
|
||||
typedef struct TPMSizedBuffer {
|
||||
uint32_t size;
|
||||
uint8_t *buffer;
|
||||
} TPMSizedBuffer;
|
||||
|
||||
struct TPMDriverOps {
|
||||
enum TpmType type;
|
||||
const QemuOptDesc *opts;
|
||||
/* get a descriptive text of the backend to display to the user */
|
||||
@@ -79,8 +65,6 @@ struct TPMDriverOps {
|
||||
|
||||
TPMBackend *(*create)(QemuOpts *opts, const char *id);
|
||||
|
||||
/* initialize the backend */
|
||||
int (*init)(TPMBackend *t);
|
||||
/* start up the TPM on the backend */
|
||||
int (*startup_tpm)(TPMBackend *t);
|
||||
|
||||
@@ -95,8 +79,11 @@ struct TPMDriverOps {
|
||||
TPMVersion (*get_tpm_version)(TPMBackend *t);
|
||||
|
||||
TpmTypeOptions *(*get_tpm_options)(TPMBackend *t);
|
||||
};
|
||||
|
||||
void (*opened)(TPMBackend *s, Error **errp);
|
||||
|
||||
void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd);
|
||||
};
|
||||
|
||||
/**
|
||||
* tpm_backend_get_type:
|
||||
@@ -116,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:
|
||||
@@ -140,11 +126,12 @@ bool tpm_backend_had_startup_error(TPMBackend *s);
|
||||
/**
|
||||
* tpm_backend_deliver_request:
|
||||
* @s: the backend to send the request to
|
||||
* @cmd: the command to deliver
|
||||
*
|
||||
* Send a request to the backend. The backend will then send the request
|
||||
* to the TPM implementation.
|
||||
*/
|
||||
void tpm_backend_deliver_request(TPMBackend *s);
|
||||
void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd);
|
||||
|
||||
/**
|
||||
* tpm_backend_reset:
|
||||
@@ -215,8 +202,6 @@ TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
|
||||
|
||||
TPMBackend *qemu_find_tpm(const char *id);
|
||||
|
||||
const TPMDriverOps *tpm_get_backend_driver(const char *type);
|
||||
void tpm_register_model(enum TpmModel model);
|
||||
void tpm_register_driver(const TPMDriverOps *tdo);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2603,7 +2603,6 @@ sub process {
|
||||
SCSIBusInfo|
|
||||
SCSIReqOps|
|
||||
Spice[A-Z][a-zA-Z0-9]*Interface|
|
||||
TPMDriverOps|
|
||||
USBDesc[A-Z][a-zA-Z0-9]*|
|
||||
VhostOps|
|
||||
VMStateDescription|
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
static QLIST_HEAD(, TPMBackend) tpm_backends =
|
||||
QLIST_HEAD_INITIALIZER(tpm_backends);
|
||||
|
||||
static TPMDriverOps const *be_drivers[TPM_TYPE__MAX];
|
||||
static bool tpm_models[TPM_MODEL__MAX];
|
||||
|
||||
void tpm_register_model(enum TpmModel model)
|
||||
@@ -31,20 +30,22 @@ void tpm_register_model(enum TpmModel model)
|
||||
tpm_models[model] = true;
|
||||
}
|
||||
|
||||
const TPMDriverOps *tpm_get_backend_driver(const char *type)
|
||||
{
|
||||
int i = qapi_enum_parse(&TpmType_lookup, type, -1, NULL);
|
||||
|
||||
return i >= 0 ? be_drivers[i] : NULL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_TPM
|
||||
|
||||
void tpm_register_driver(const TPMDriverOps *tdo)
|
||||
static const TPMBackendClass *
|
||||
tpm_be_find_by_type(enum TpmType type)
|
||||
{
|
||||
assert(!be_drivers[tdo->type]);
|
||||
ObjectClass *oc;
|
||||
char *typename = g_strdup_printf("tpm-%s", TpmType_str(type));
|
||||
|
||||
be_drivers[tdo->type] = tdo;
|
||||
oc = object_class_by_name(typename);
|
||||
g_free(typename);
|
||||
|
||||
if (!object_class_dynamic_cast(oc, TYPE_TPM_BACKEND)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return TPM_BACKEND_CLASS(oc);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -58,11 +59,11 @@ static void tpm_display_backend_drivers(void)
|
||||
fprintf(stderr, "Supported TPM types (choose only one):\n");
|
||||
|
||||
for (i = 0; i < TPM_TYPE__MAX; i++) {
|
||||
if (be_drivers[i] == NULL) {
|
||||
const TPMBackendClass *bc = tpm_be_find_by_type(i);
|
||||
if (!bc) {
|
||||
continue;
|
||||
}
|
||||
fprintf(stderr, "%12s %s\n",
|
||||
TpmType_str(i), be_drivers[i]->desc);
|
||||
fprintf(stderr, "%12s %s\n", TpmType_str(i), bc->desc);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
@@ -85,13 +86,14 @@ TPMBackend *qemu_find_tpm(const char *id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int configure_tpm(QemuOpts *opts)
|
||||
static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
|
||||
{
|
||||
const char *value;
|
||||
const char *id;
|
||||
const TPMDriverOps *be;
|
||||
const TPMBackendClass *be;
|
||||
TPMBackend *drv;
|
||||
Error *local_err = NULL;
|
||||
int i;
|
||||
|
||||
if (!QLIST_EMPTY(&tpm_backends)) {
|
||||
error_report("Only one TPM is allowed.");
|
||||
@@ -111,7 +113,8 @@ static int configure_tpm(QemuOpts *opts)
|
||||
return 1;
|
||||
}
|
||||
|
||||
be = tpm_get_backend_driver(value);
|
||||
i = qapi_enum_parse(&TpmType_lookup, value, -1, NULL);
|
||||
be = i >= 0 ? tpm_be_find_by_type(i) : NULL;
|
||||
if (be == NULL) {
|
||||
error_report(QERR_INVALID_PARAMETER_VALUE,
|
||||
"type", "a TPM backend type");
|
||||
@@ -142,11 +145,6 @@ static int configure_tpm(QemuOpts *opts)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tpm_init_tpmdev(void *dummy, QemuOpts *opts, Error **errp)
|
||||
{
|
||||
return configure_tpm(opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* Walk the list of TPM backend drivers that are in use and call their
|
||||
* destroy function to have them cleaned up.
|
||||
@@ -196,11 +194,6 @@ int tpm_config_parse(QemuOptsList *opts_list, const char *optarg)
|
||||
|
||||
#endif /* CONFIG_TPM */
|
||||
|
||||
static const TPMDriverOps *tpm_driver_find_by_type(enum TpmType type)
|
||||
{
|
||||
return be_drivers[type];
|
||||
}
|
||||
|
||||
/*
|
||||
* Walk the list of active TPM backends and collect information about them
|
||||
* following the schema description in qapi-schema.json.
|
||||
@@ -234,7 +227,7 @@ TpmTypeList *qmp_query_tpm_types(Error **errp)
|
||||
TpmTypeList *head = NULL, *prev = NULL, *cur_item;
|
||||
|
||||
for (i = 0; i < TPM_TYPE__MAX; i++) {
|
||||
if (!tpm_driver_find_by_type(i)) {
|
||||
if (!tpm_be_find_by_type(i)) {
|
||||
continue;
|
||||
}
|
||||
cur_item = g_new0(TpmTypeList, 1);
|
||||
|
||||
Reference in New Issue
Block a user