1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef TPM_BACKEND_H
14#define TPM_BACKEND_H
15
16#include "qom/object.h"
17#include "qemu-common.h"
18#include "qapi-types.h"
19#include "qemu/option.h"
20#include "sysemu/tpm.h"
21
22#define TYPE_TPM_BACKEND "tpm-backend"
23#define TPM_BACKEND(obj) \
24 OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND)
25#define TPM_BACKEND_GET_CLASS(obj) \
26 OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND)
27#define TPM_BACKEND_CLASS(klass) \
28 OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND)
29
30typedef struct TPMBackendClass TPMBackendClass;
31typedef struct TPMBackend TPMBackend;
32
33typedef struct TPMBackendCmd {
34 uint8_t locty;
35 const uint8_t *in;
36 uint32_t in_len;
37 uint8_t *out;
38 uint32_t out_len;
39 bool selftest_done;
40} TPMBackendCmd;
41
42struct TPMBackend {
43 Object parent;
44
45
46 bool opened;
47 TPMState *tpm_state;
48 GThreadPool *thread_pool;
49 bool had_startup_error;
50
51
52 char *id;
53 enum TpmModel fe_model;
54
55 QLIST_ENTRY(TPMBackend) list;
56};
57
58struct TPMBackendClass {
59 ObjectClass parent_class;
60
61 enum TpmType type;
62 const QemuOptDesc *opts;
63
64 const char *desc;
65
66 TPMBackend *(*create)(QemuOpts *opts, const char *id);
67
68
69 int (*startup_tpm)(TPMBackend *t);
70
71 void (*reset)(TPMBackend *t);
72
73 void (*cancel_cmd)(TPMBackend *t);
74
75 bool (*get_tpm_established_flag)(TPMBackend *t);
76
77 int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);
78
79 TPMVersion (*get_tpm_version)(TPMBackend *t);
80
81 TpmTypeOptions *(*get_tpm_options)(TPMBackend *t);
82
83 void (*opened)(TPMBackend *s, Error **errp);
84
85 void (*handle_request)(TPMBackend *s, TPMBackendCmd *cmd);
86};
87
88
89
90
91
92
93
94enum TpmType tpm_backend_get_type(TPMBackend *s);
95
96
97
98
99
100
101
102
103
104
105
106int tpm_backend_init(TPMBackend *s, TPMState *state);
107
108
109
110
111
112
113
114int tpm_backend_startup_tpm(TPMBackend *s);
115
116
117
118
119
120
121
122
123
124bool tpm_backend_had_startup_error(TPMBackend *s);
125
126
127
128
129
130
131
132
133
134void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd);
135
136
137
138
139
140
141
142
143void tpm_backend_reset(TPMBackend *s);
144
145
146
147
148
149
150
151
152void tpm_backend_cancel_cmd(TPMBackend *s);
153
154
155
156
157
158
159
160
161
162bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
163
164
165
166
167
168
169
170
171int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty);
172
173
174
175
176
177
178
179
180
181void tpm_backend_open(TPMBackend *s, Error **errp);
182
183
184
185
186
187
188
189
190
191TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
192
193
194
195
196
197
198
199
200
201TPMInfo *tpm_backend_query_tpm(TPMBackend *s);
202
203TPMBackend *qemu_find_tpm(const char *id);
204
205void tpm_register_model(enum TpmModel model);
206
207#endif
208