]> git.proxmox.com Git - mirror_qemu.git/blame - include/sysemu/tpm.h
Merge tag 'pull-target-arm-20230518' of https://git.linaro.org/people/pmaydell/qemu...
[mirror_qemu.git] / include / sysemu / tpm.h
CommitLineData
d1a0cf73
SB
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
9af23989 15#include "qapi/qapi-types-tpm.h"
6b287efe 16#include "qom/object.h"
d1a0cf73 17
e542b718
SB
18#ifdef CONFIG_TPM
19
d1a0cf73 20int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
d64072c0 21int tpm_init(void);
d1a0cf73
SB
22void tpm_cleanup(void);
23
3dfd5a2a 24typedef enum TPMVersion {
116694c3
SB
25 TPM_VERSION_UNSPEC = 0,
26 TPM_VERSION_1_2 = 1,
27 TPM_VERSION_2_0 = 2,
28} TPMVersion;
29
67af320c 30#define TYPE_TPM_IF "tpm-if"
db1015e9 31typedef struct TPMIfClass TPMIfClass;
8110fa1d
EH
32DECLARE_CLASS_CHECKERS(TPMIfClass, TPM_IF,
33 TYPE_TPM_IF)
67af320c
MAL
34#define TPM_IF(obj) \
35 INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF)
36
aa1b35b9 37typedef struct TPMIf TPMIf;
67af320c 38
db1015e9 39struct TPMIfClass {
67af320c
MAL
40 InterfaceClass parent_class;
41
191adc94 42 enum TpmModel model;
6a8a2354 43 void (*request_completed)(TPMIf *obj, int ret);
9af7a721 44 enum TPMVersion (*get_version)(TPMIf *obj);
db1015e9 45};
67af320c 46
43bc7f84 47#define TYPE_TPM_TIS_ISA "tpm-tis"
229de57a 48#define TYPE_TPM_TIS_SYSBUS "tpm-tis-device"
4ab6cb4c 49#define TYPE_TPM_CRB "tpm-crb"
3676bc69 50#define TYPE_TPM_SPAPR "tpm-spapr"
139fdb3e 51#define TYPE_TPM_TIS_I2C "tpm-tis-i2c"
711b20b4 52
43bc7f84
EA
53#define TPM_IS_TIS_ISA(chr) \
54 object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
80bde693
EA
55#define TPM_IS_TIS_SYSBUS(chr) \
56 object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
4ab6cb4c
MAL
57#define TPM_IS_CRB(chr) \
58 object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
3676bc69
SB
59#define TPM_IS_SPAPR(chr) \
60 object_dynamic_cast(OBJECT(chr), TYPE_TPM_SPAPR)
139fdb3e
NP
61#define TPM_IS_TIS_I2C(chr) \
62 object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_I2C)
ff5ce21e 63
3dfd5a2a
MAL
64/* returns NULL unless there is exactly one TPM device */
65static inline TPMIf *tpm_find(void)
711b20b4 66{
3dfd5a2a
MAL
67 Object *obj = object_resolve_path_type("", TYPE_TPM_IF, NULL);
68
69 return TPM_IF(obj);
70}
5cb18b3d 71
3dfd5a2a
MAL
72static inline TPMVersion tpm_get_version(TPMIf *ti)
73{
74 if (!ti) {
75 return TPM_VERSION_UNSPEC;
5cb18b3d 76 }
3dfd5a2a 77
9af7a721 78 return TPM_IF_GET_CLASS(ti)->get_version(ti);
711b20b4
SB
79}
80
e542b718
SB
81#else /* CONFIG_TPM */
82
83#define tpm_init() (0)
84#define tpm_cleanup()
85
4168cdad
EA
86/* needed for an alignment check in non-tpm code */
87static inline Object *TPM_IS_CRB(Object *obj)
88{
89 return NULL;
90}
91
e542b718
SB
92#endif /* CONFIG_TPM */
93
d1a0cf73 94#endif /* QEMU_TPM_H */