]> git.proxmox.com Git - qemu.git/blame - backends/tpm.c
configure: fix TPM logic
[qemu.git] / backends / tpm.c
CommitLineData
8f0605cc
SB
1/*
2 * QEMU TPM Backend
3 *
4 * Copyright IBM, Corp. 2013
5 *
6 * Authors:
7 * Stefan Berger <stefanb@us.ibm.com>
8 *
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.
11 *
12 * Based on backends/rng.c by Anthony Liguori
13 */
14
15#include "backends/tpm.h"
16#include "tpm/tpm_int.h"
17#include "qapi/qmp/qerror.h"
18
19enum TpmType tpm_backend_get_type(TPMBackend *s)
20{
21 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
22
23 return k->ops->type;
24}
25
26const char *tpm_backend_get_desc(TPMBackend *s)
27{
28 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
29
30 return k->ops->desc();
31}
32
33void tpm_backend_destroy(TPMBackend *s)
34{
35 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
36
37 return k->ops->destroy(s);
38}
39
40int tpm_backend_init(TPMBackend *s, TPMState *state,
41 TPMRecvDataCB *datacb)
42{
43 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
44
45 return k->ops->init(s, state, datacb);
46}
47
48int tpm_backend_startup_tpm(TPMBackend *s)
49{
50 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
51
52 return k->ops->startup_tpm(s);
53}
54
55bool tpm_backend_had_startup_error(TPMBackend *s)
56{
57 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
58
59 return k->ops->had_startup_error(s);
60}
61
62size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb)
63{
64 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
65
66 return k->ops->realloc_buffer(sb);
67}
68
69void tpm_backend_deliver_request(TPMBackend *s)
70{
71 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
72
73 k->ops->deliver_request(s);
74}
75
76void tpm_backend_reset(TPMBackend *s)
77{
78 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
79
80 k->ops->reset(s);
81}
82
83void tpm_backend_cancel_cmd(TPMBackend *s)
84{
85 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
86
87 k->ops->cancel_cmd(s);
88}
89
90bool tpm_backend_get_tpm_established_flag(TPMBackend *s)
91{
92 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
93
94 return k->ops->get_tpm_established_flag(s);
95}
96
97static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
98{
99 TPMBackend *s = TPM_BACKEND(obj);
100
101 return s->opened;
102}
103
104void tpm_backend_open(TPMBackend *s, Error **errp)
105{
106 object_property_set_bool(OBJECT(s), true, "opened", errp);
107}
108
109static void tpm_backend_prop_set_opened(Object *obj, bool value, Error **errp)
110{
111 TPMBackend *s = TPM_BACKEND(obj);
112 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
113
114 if (value == s->opened) {
115 return;
116 }
117
118 if (!value && s->opened) {
119 error_set(errp, QERR_PERMISSION_DENIED);
120 return;
121 }
122
123 if (k->opened) {
124 k->opened(s, errp);
125 }
126
127 if (!error_is_set(errp)) {
128 s->opened = value;
129 }
130}
131
132static void tpm_backend_instance_init(Object *obj)
133{
134 object_property_add_bool(obj, "opened",
135 tpm_backend_prop_get_opened,
136 tpm_backend_prop_set_opened,
137 NULL);
138}
139
140static 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,
147};
148
149static void register_types(void)
150{
151 type_register_static(&tpm_backend_info);
152}
153
154type_init(register_types);