4 * Copyright IBM, Corp. 2013
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
);
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
);
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
);
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
) {
118 if (!value
&& s
->opened
) {
119 error_set(errp
, QERR_PERMISSION_DENIED
);
127 if (!error_is_set(errp
)) {
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
,
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
),
149 static void register_types(void)
151 type_register_static(&tpm_backend_info
);
154 type_init(register_types
);