| 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 | #ifdef CONFIG_TPM |
| 19 | |
| 20 | int tpm_config_parse(QemuOptsList *opts_list, const char *optstr); |
| 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 | typedef struct TPMIfClass TPMIfClass; |
| 32 | DECLARE_CLASS_CHECKERS(TPMIfClass, TPM_IF, |
| 33 | TYPE_TPM_IF) |
| 34 | #define TPM_IF(obj) \ |
| 35 | INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF) |
| 36 | |
| 37 | typedef struct TPMIf TPMIf; |
| 38 | |
| 39 | struct TPMIfClass { |
| 40 | InterfaceClass parent_class; |
| 41 | |
| 42 | enum TpmModel model; |
| 43 | void (*request_completed)(TPMIf *obj, int ret); |
| 44 | enum TPMVersion (*get_version)(TPMIf *obj); |
| 45 | bool ppi_enabled; |
| 46 | }; |
| 47 | |
| 48 | #define TYPE_TPM_TIS_ISA "tpm-tis" |
| 49 | #define TYPE_TPM_TIS_SYSBUS "tpm-tis-device" |
| 50 | #define TYPE_TPM_CRB "tpm-crb" |
| 51 | #define TYPE_TPM_SPAPR "tpm-spapr" |
| 52 | #define TYPE_TPM_TIS_I2C "tpm-tis-i2c" |
| 53 | |
| 54 | #define TPM_IS_TIS_ISA(chr) \ |
| 55 | object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA) |
| 56 | #define TPM_IS_TIS_SYSBUS(chr) \ |
| 57 | object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS) |
| 58 | #define TPM_IS_CRB(chr) \ |
| 59 | object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB) |
| 60 | #define TPM_IS_SPAPR(chr) \ |
| 61 | object_dynamic_cast(OBJECT(chr), TYPE_TPM_SPAPR) |
| 62 | #define TPM_IS_TIS_I2C(chr) \ |
| 63 | object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_I2C) |
| 64 | |
| 65 | /* returns NULL unless there is exactly one TPM device */ |
| 66 | static inline TPMIf *tpm_find(void) |
| 67 | { |
| 68 | Object *obj = object_resolve_path_type("", TYPE_TPM_IF, NULL); |
| 69 | |
| 70 | return TPM_IF(obj); |
| 71 | } |
| 72 | |
| 73 | static inline TPMVersion tpm_get_version(TPMIf *ti) |
| 74 | { |
| 75 | if (!ti) { |
| 76 | return TPM_VERSION_UNSPEC; |
| 77 | } |
| 78 | |
| 79 | return TPM_IF_GET_CLASS(ti)->get_version(ti); |
| 80 | } |
| 81 | |
| 82 | static inline bool tpm_ppi_enabled(TPMIf *ti) |
| 83 | { |
| 84 | if (!ti) { |
| 85 | return false; |
| 86 | } |
| 87 | return TPM_IF_GET_CLASS(ti)->ppi_enabled; |
| 88 | } |
| 89 | |
| 90 | #else /* CONFIG_TPM */ |
| 91 | |
| 92 | #define tpm_init() (0) |
| 93 | #define tpm_cleanup() |
| 94 | |
| 95 | /* needed for an alignment check in non-tpm code */ |
| 96 | static inline Object *TPM_IS_CRB(Object *obj) |
| 97 | { |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | #endif /* CONFIG_TPM */ |
| 102 | |
| 103 | #endif /* QEMU_TPM_H */ |