aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-10-10 00:55:49 +0200
committerStefan Berger <stefanb@linux.vnet.ibm.com>2017-10-19 11:42:23 -0400
commitd31076ba75d4239928282143efd30d08730c8845 (patch)
treef92f2182a095cd749861b0858689346abacb26c9
parentcfab6da8a7d3e9d825ea284a0ebbf6579e204f74 (diff)
tpm: remove TPMDriverOps
Use TPMBackendClass to hold class methods/fields. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com> Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
-rw-r--r--backends/tpm.c31
-rw-r--r--hw/tpm/tpm_emulator.c29
-rw-r--r--hw/tpm/tpm_passthrough.c25
-rw-r--r--include/sysemu/tpm_backend.h15
-rwxr-xr-xscripts/checkpatch.pl1
-rw-r--r--tpm.c20
6 files changed, 53 insertions, 68 deletions
diff --git a/backends/tpm.c b/backends/tpm.c
index 37c84b7c66..ca3a78eea8 100644
--- a/backends/tpm.c
+++ b/backends/tpm.c
@@ -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;
}
diff --git a/hw/tpm/tpm_emulator.c b/hw/tpm/tpm_emulator.c
index 187a69e442..03ea5845db 100644
--- a/hw/tpm/tpm_emulator.c
+++ b/hw/tpm/tpm_emulator.c
@@ -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;
}
diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
index f04eab3e63..d9da99bc8e 100644
--- a/hw/tpm/tpm_passthrough.c
+++ b/hw/tpm/tpm_passthrough.c
@@ -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;
}
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 63093551a1..a4288df038 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -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:
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 0c41f1212f..c9529df67f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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|
diff --git a/tpm.c b/tpm.c
index 75a589b837..4882501bd7 100644
--- a/tpm.c
+++ b/tpm.c
@@ -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);