提交 d31076ba 编写于 作者: M Marc-André Lureau 提交者: Stefan Berger

tpm: remove TPMDriverOps

Use TPMBackendClass to hold class methods/fields.
Signed-off-by: NMarc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: NStefan Berger <stefanb@linux.vnet.ibm.com>
上级 cfab6da8
......@@ -41,7 +41,7 @@ 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,
......@@ -53,7 +53,7 @@ int tpm_backend_init(TPMBackend *s, TPMState *state,
s->recv_data_callback = datacb;
s->had_startup_error = false;
return k->ops->init ? k->ops->init(s) : 0;
return k->init ? k->init(s) : 0;
}
int tpm_backend_startup_tpm(TPMBackend *s)
......@@ -68,7 +68,7 @@ int tpm_backend_startup_tpm(TPMBackend *s)
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);
......@@ -90,8 +90,8 @@ 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 +103,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 +140,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;
}
......
......@@ -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;
......@@ -504,20 +502,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 +549,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;
}
......
......@@ -365,19 +365,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 +389,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;
}
......
......@@ -29,7 +29,7 @@
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 {
......@@ -59,14 +59,6 @@ struct TPMBackend {
struct TPMBackendClass {
ObjectClass parent_class;
const TPMDriverOps *ops;
void (*opened)(TPMBackend *s, Error **errp);
void (*handle_request)(TPMBackend *s, TPMBackendCmd cmd);
};
struct TPMDriverOps {
enum TpmType type;
const QemuOptDesc *opts;
/* get a descriptive text of the backend to display to the user */
......@@ -90,8 +82,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:
......
......@@ -2602,7 +2602,6 @@ sub process {
SCSIBusInfo|
SCSIReqOps|
Spice[A-Z][a-zA-Z0-9]*Interface|
TPMDriverOps|
USBDesc[A-Z][a-zA-Z0-9]*|
VhostOps|
VMStateDescription|
......
......@@ -32,11 +32,10 @@ void tpm_register_model(enum TpmModel model)
#ifdef CONFIG_TPM
static const TPMDriverOps *
tpm_driver_find_by_type(enum TpmType type)
static const TPMBackendClass *
tpm_be_find_by_type(enum TpmType type)
{
ObjectClass *oc;
TPMBackendClass *bc;
char *typename = g_strdup_printf("tpm-%s", TpmType_str(type));
oc = object_class_by_name(typename);
......@@ -46,8 +45,7 @@ tpm_driver_find_by_type(enum TpmType type)
return NULL;
}
bc = TPM_BACKEND_CLASS(oc);
return bc->ops;
return TPM_BACKEND_CLASS(oc);
}
/*
......@@ -61,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++) {
const TPMDriverOps *ops = tpm_driver_find_by_type(i);
if (!ops) {
const TPMBackendClass *bc = tpm_be_find_by_type(i);
if (!bc) {
continue;
}
fprintf(stderr, "%12s %s\n", TpmType_str(i), ops->desc);
fprintf(stderr, "%12s %s\n", TpmType_str(i), bc->desc);
}
fprintf(stderr, "\n");
}
......@@ -92,7 +90,7 @@ static int configure_tpm(QemuOpts *opts)
{
const char *value;
const char *id;
const TPMDriverOps *be;
const TPMBackendClass *be;
TPMBackend *drv;
Error *local_err = NULL;
int i;
......@@ -116,7 +114,7 @@ static int configure_tpm(QemuOpts *opts)
}
i = qapi_enum_parse(&TpmType_lookup, value, -1, NULL);
be = i >= 0 ? tpm_driver_find_by_type(i) : 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");
......@@ -234,7 +232,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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册