accel: move qtest CpusAccel functions to a common location
[qemu.git] / include / sysemu / tpm.h
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 "qapi/qapi-types-tpm.h"
16 #include "qom/object.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 typedef struct TPMIfClass TPMIfClass;
30 DECLARE_CLASS_CHECKERS(TPMIfClass, TPM_IF,
31 TYPE_TPM_IF)
32 #define TPM_IF(obj) \
33 INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF)
34
35 typedef struct TPMIf TPMIf;
36
37 struct TPMIfClass {
38 InterfaceClass parent_class;
39
40 enum TpmModel model;
41 void (*request_completed)(TPMIf *obj, int ret);
42 enum TPMVersion (*get_version)(TPMIf *obj);
43 };
44
45 #define TYPE_TPM_TIS_ISA "tpm-tis"
46 #define TYPE_TPM_TIS_SYSBUS "tpm-tis-device"
47 #define TYPE_TPM_CRB "tpm-crb"
48 #define TYPE_TPM_SPAPR "tpm-spapr"
49
50 #define TPM_IS_TIS_ISA(chr) \
51 object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
52 #define TPM_IS_TIS_SYSBUS(chr) \
53 object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
54 #define TPM_IS_CRB(chr) \
55 object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
56 #define TPM_IS_SPAPR(chr) \
57 object_dynamic_cast(OBJECT(chr), TYPE_TPM_SPAPR)
58
59 /* returns NULL unless there is exactly one TPM device */
60 static inline TPMIf *tpm_find(void)
61 {
62 Object *obj = object_resolve_path_type("", TYPE_TPM_IF, NULL);
63
64 return TPM_IF(obj);
65 }
66
67 static inline TPMVersion tpm_get_version(TPMIf *ti)
68 {
69 if (!ti) {
70 return TPM_VERSION_UNSPEC;
71 }
72
73 return TPM_IF_GET_CLASS(ti)->get_version(ti);
74 }
75
76 #endif /* QEMU_TPM_H */