ipoctal232: Convert to use chardev properties directly
[qemu/ar7.git] / backends / tpm.c
blob28148c23cfd51902a4281b518d00ac8aaa4205a3
1 /*
2 * QEMU TPM Backend
4 * Copyright IBM, Corp. 2013
6 * Authors:
7 * Stefan Berger <stefanb@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
12 * Based on backends/rng.c by Anthony Liguori
15 #include "backends/tpm.h"
16 #include "tpm/tpm_int.h"
17 #include "qapi/qmp/qerror.h"
19 enum TpmType tpm_backend_get_type(TPMBackend *s)
21 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
23 return k->ops->type;
26 const char *tpm_backend_get_desc(TPMBackend *s)
28 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
30 return k->ops->desc();
33 void tpm_backend_destroy(TPMBackend *s)
35 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
37 return k->ops->destroy(s);
40 int tpm_backend_init(TPMBackend *s, TPMState *state,
41 TPMRecvDataCB *datacb)
43 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
45 return k->ops->init(s, state, datacb);
48 int tpm_backend_startup_tpm(TPMBackend *s)
50 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
52 return k->ops->startup_tpm(s);
55 bool tpm_backend_had_startup_error(TPMBackend *s)
57 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
59 return k->ops->had_startup_error(s);
62 size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb)
64 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
66 return k->ops->realloc_buffer(sb);
69 void tpm_backend_deliver_request(TPMBackend *s)
71 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
73 k->ops->deliver_request(s);
76 void tpm_backend_reset(TPMBackend *s)
78 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
80 k->ops->reset(s);
83 void tpm_backend_cancel_cmd(TPMBackend *s)
85 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
87 k->ops->cancel_cmd(s);
90 bool tpm_backend_get_tpm_established_flag(TPMBackend *s)
92 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
94 return k->ops->get_tpm_established_flag(s);
97 static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
99 TPMBackend *s = TPM_BACKEND(obj);
101 return s->opened;
104 void tpm_backend_open(TPMBackend *s, Error **errp)
106 object_property_set_bool(OBJECT(s), true, "opened", errp);
109 static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **errp)
111 TPMBackend *s = TPM_BACKEND(obj);
112 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
114 if (value == s->opened) {
115 return;
118 if (!value && s->opened) {
119 error_set(errp, QERR_PERMISSION_DENIED);
120 return;
123 if (k->opened) {
124 k->opened(s, errp);
127 if (!error_is_set(errp)) {
128 s->opened = value;
132 static void tpm_backend_instance_init(Object *obj)
134 object_property_add_bool(obj, "opened",
135 tpm_backend_prop_get_opened,
136 tpm_backend_prop_set_opened,
137 NULL);
140 static const TypeInfo tpm_backend_info = {
141 .name = TYPE_TPM_BACKEND,
142 .parent = TYPE_OBJECT,
143 .instance_size = sizeof(TPMBackend),
144 .instance_init = tpm_backend_instance_init,
145 .class_size = sizeof(TPMBackendClass),
146 .abstract = true,
149 static void register_types(void)
151 type_register_static(&tpm_backend_info);
154 type_init(register_types);