xref: /openbmc/qemu/include/sysemu/tpm.h (revision 191adc94)
1 /*
2  * Public TPM functions
3  *
4  * Copyright (C) 2011-2013 IBM Corporation
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 #ifndef QEMU_TPM_H
13 #define QEMU_TPM_H
14 
15 #include "qom/object.h"
16 #include "qapi-types.h"
17 
18 int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
19 int tpm_init(void);
20 void tpm_cleanup(void);
21 
22 typedef enum  TPMVersion {
23     TPM_VERSION_UNSPEC = 0,
24     TPM_VERSION_1_2 = 1,
25     TPM_VERSION_2_0 = 2,
26 } TPMVersion;
27 
28 #define TYPE_TPM_IF "tpm-if"
29 #define TPM_IF_CLASS(klass)                                 \
30     OBJECT_CLASS_CHECK(TPMIfClass, (klass), TYPE_TPM_IF)
31 #define TPM_IF_GET_CLASS(obj)                           \
32     OBJECT_GET_CLASS(TPMIfClass, (obj), TYPE_TPM_IF)
33 #define TPM_IF(obj)                             \
34     INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF)
35 
36 typedef struct TPMIf {
37     Object parent_obj;
38 } TPMIf;
39 
40 typedef struct TPMIfClass {
41     InterfaceClass parent_class;
42 
43     enum TpmModel model;
44     void (*request_completed)(TPMIf *obj);
45 } TPMIfClass;
46 
47 TPMVersion tpm_tis_get_tpm_version(Object *obj);
48 
49 #define TYPE_TPM_TIS                "tpm-tis"
50 
51 static inline TPMVersion tpm_get_version(void)
52 {
53 #ifdef CONFIG_TPM
54     Object *obj = object_resolve_path_type("", TYPE_TPM_TIS, NULL);
55 
56     if (obj) {
57         return tpm_tis_get_tpm_version(obj);
58     }
59 #endif
60     return TPM_VERSION_UNSPEC;
61 }
62 
63 #endif /* QEMU_TPM_H */
64