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