]> git.proxmox.com Git - qemu.git/blob - include/backends/tpm.h
QOM-ify the TPM support
[qemu.git] / include / backends / tpm.h
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
13 #ifndef _QEMU_TPM_H
14 #define _QEMU_TPM_H
15
16 #include "qom/object.h"
17 #include "qemu-common.h"
18 #include "qapi/error.h"
19 #include "qapi-types.h"
20 #include "qemu/option.h"
21 #include "tpm/tpm.h"
22
23 #define TYPE_TPM_BACKEND "tpm-backend"
24 #define TPM_BACKEND(obj) \
25 OBJECT_CHECK(TPMBackend, (obj), TYPE_TPM_BACKEND)
26 #define TPM_BACKEND_GET_CLASS(obj) \
27 OBJECT_GET_CLASS(TPMBackendClass, (obj), TYPE_TPM_BACKEND)
28 #define TPM_BACKEND_CLASS(klass) \
29 OBJECT_CLASS_CHECK(TPMBackendClass, (klass), TYPE_TPM_BACKEND)
30
31 typedef struct TPMBackendClass TPMBackendClass;
32 typedef struct TPMBackend TPMBackend;
33
34 typedef struct TPMDriverOps TPMDriverOps;
35
36 struct TPMBackendClass {
37 ObjectClass parent_class;
38
39 const TPMDriverOps *ops;
40
41 void (*opened)(TPMBackend *s, Error **errp);
42 };
43
44 struct TPMBackend {
45 Object parent;
46
47 /*< protected >*/
48 bool opened;
49
50 char *id;
51 enum TpmModel fe_model;
52 char *path;
53 char *cancel_path;
54 const TPMDriverOps *ops;
55
56 QLIST_ENTRY(TPMBackend) list;
57 };
58
59
60 /**
61 * tpm_backend_get_type:
62 * @s: the backend
63 *
64 * Returns the TpmType of the backend.
65 */
66 enum TpmType tpm_backend_get_type(TPMBackend *s);
67
68 /**
69 * tpm_backend_get_desc:
70 * @s: the backend
71 *
72 * Returns a human readable description of the backend.
73 */
74 const char *tpm_backend_get_desc(TPMBackend *s);
75
76 /**
77 * tpm_backend_destroy:
78 * @s: the backend to destroy
79 */
80 void tpm_backend_destroy(TPMBackend *s);
81
82 /**
83 * tpm_backend_init:
84 * @s: the backend to initialized
85 * @state: TPMState
86 * @datacb: callback for sending data to frontend
87 *
88 * Initialize the backend with the given variables.
89 *
90 * Returns 0 on success.
91 */
92 int tpm_backend_init(TPMBackend *s, TPMState *state,
93 TPMRecvDataCB *datacb);
94
95 /**
96 * tpm_backend_startup_tpm:
97 * @s: the backend whose TPM support is to be started
98 *
99 * Returns 0 on success.
100 */
101 int tpm_backend_startup_tpm(TPMBackend *s);
102
103 /**
104 * tpm_backend_had_startup_error:
105 * @s: the backend to query for a statup error
106 *
107 * Check whether the backend had an error during startup. Returns
108 * false if no error occurred and the backend can be used, true
109 * otherwise.
110 */
111 bool tpm_backend_had_startup_error(TPMBackend *s);
112
113 /**
114 * tpm_backend_realloc_buffer:
115 * @s: the backend
116 * @sb: the TPMSizedBuffer to re-allocated to the size suitable for the
117 * backend.
118 *
119 * This function returns the size of the allocated buffer
120 */
121 size_t tpm_backend_realloc_buffer(TPMBackend *s, TPMSizedBuffer *sb);
122
123 /**
124 * tpm_backend_deliver_request:
125 * @s: the backend to send the request to
126 *
127 * Send a request to the backend. The backend will then send the request
128 * to the TPM implementation.
129 */
130 void tpm_backend_deliver_request(TPMBackend *s);
131
132 /**
133 * tpm_backend_reset:
134 * @s: the backend to reset
135 *
136 * Reset the backend into a well defined state with all previous errors
137 * reset.
138 */
139 void tpm_backend_reset(TPMBackend *s);
140
141 /**
142 * tpm_backend_cancel_cmd:
143 * @s: the backend
144 *
145 * Cancel any ongoing command being processed by the TPM implementation
146 * on behalf of the QEMU guest.
147 */
148 void tpm_backend_cancel_cmd(TPMBackend *s);
149
150 /**
151 * tpm_backend_get_tpm_established_flag:
152 * @s: the backend
153 *
154 * Get the TPM establishment flag. This function may be called very
155 * frequently by the frontend since for example in the TIS implementation
156 * this flag is part of a register.
157 */
158 bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
159
160 /**
161 * tpm_backend_open:
162 * @s: the backend to open
163 * @errp: a pointer to return the #Error object if an error occurs.
164 *
165 * This function will open the backend if it is not already open. Calling this
166 * function on an already opened backend will not result in an error.
167 */
168 void tpm_backend_open(TPMBackend *s, Error **errp);
169
170 #endif