]> git.proxmox.com Git - qemu.git/blob - backends/tpm.c
acpi: initialize s4_val used in s4 shutdown
[qemu.git] / backends / tpm.c
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
19 enum TpmType tpm_backend_get_type(TPMBackend *s)
20 {
21 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
22
23 return k->ops->type;
24 }
25
26 const char *tpm_backend_get_desc(TPMBackend *s)
27 {
28 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
29
30 return k->ops->desc();
31 }
32
33 void tpm_backend_destroy(TPMBackend *s)
34 {
35 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
36
37 return k->ops->destroy(s);
38 }
39
40 int 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
48 int 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
55 bool 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
62 size_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
69 void tpm_backend_deliver_request(TPMBackend *s)
70 {
71 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
72
73 k->ops->deliver_request(s);
74 }
75
76 void tpm_backend_reset(TPMBackend *s)
77 {
78 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
79
80 k->ops->reset(s);
81 }
82
83 void tpm_backend_cancel_cmd(TPMBackend *s)
84 {
85 TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
86
87 k->ops->cancel_cmd(s);
88 }
89
90 bool 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
97 static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
98 {
99 TPMBackend *s = TPM_BACKEND(obj);
100
101 return s->opened;
102 }
103
104 void tpm_backend_open(TPMBackend *s, Error **errp)
105 {
106 object_property_set_bool(OBJECT(s), true, "opened", errp);
107 }
108
109 static 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
132 static 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
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,
147 };
148
149 static void register_types(void)
150 {
151 type_register_static(&tpm_backend_info);
152 }
153
154 type_init(register_types);