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 17 int tpm_config_parse(QemuOptsList *opts_list, const char *optarg); 18 int tpm_init(void); 19 void tpm_cleanup(void); 20 21 typedef enum TPMVersion { 22 TPM_VERSION_UNSPEC = 0, 23 TPM_VERSION_1_2 = 1, 24 TPM_VERSION_2_0 = 2, 25 } TPMVersion; 26 27 #define TYPE_TPM_IF "tpm-if" 28 #define TPM_IF_CLASS(klass) \ 29 OBJECT_CLASS_CHECK(TPMIfClass, (klass), TYPE_TPM_IF) 30 #define TPM_IF_GET_CLASS(obj) \ 31 OBJECT_GET_CLASS(TPMIfClass, (obj), TYPE_TPM_IF) 32 #define TPM_IF(obj) \ 33 INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF) 34 35 typedef struct TPMIf { 36 Object parent_obj; 37 } TPMIf; 38 39 typedef 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 } TPMIfClass; 46 47 #define TYPE_TPM_TIS "tpm-tis" 48 #define TYPE_TPM_CRB "tpm-crb" 49 50 #define TPM_IS_TIS(chr) \ 51 object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS) 52 #define TPM_IS_CRB(chr) \ 53 object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB) 54 55 /* returns NULL unless there is exactly one TPM device */ 56 static inline TPMIf *tpm_find(void) 57 { 58 Object *obj = object_resolve_path_type("", TYPE_TPM_IF, NULL); 59 60 return TPM_IF(obj); 61 } 62 63 static inline TPMVersion tpm_get_version(TPMIf *ti) 64 { 65 if (!ti) { 66 return TPM_VERSION_UNSPEC; 67 } 68 69 return TPM_IF_GET_CLASS(ti)->get_version(ti); 70 } 71 72 #endif /* QEMU_TPM_H */ 73