tpm.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include "qemu/osdep.h"
  15. #include "exec/hwaddr.h"
  16. #include "qapi/qapi-types-tpm.h"
  17. #include "qom/object.h"
  18. #ifdef CONFIG_TPM
  19. int tpm_config_parse(QemuOptsList *opts_list, const char *optstr);
  20. int tpm_init(void);
  21. void tpm_cleanup(void);
  22. typedef enum TPMVersion {
  23. TPM_VERSION_UNSPEC = 0,
  24. TPM_VERSION_1_2 = 1,
  25. TPM_VERSION_2_0 = 2,
  26. } TPMVersion;
  27. #define TYPE_TPM_IF "tpm-if"
  28. typedef struct TPMIfClass TPMIfClass;
  29. DECLARE_CLASS_CHECKERS(TPMIfClass, TPM_IF,
  30. TYPE_TPM_IF)
  31. #define TPM_IF(obj) \
  32. INTERFACE_CHECK(TPMIf, (obj), TYPE_TPM_IF)
  33. typedef struct TPMIf TPMIf;
  34. struct TPMIfClass {
  35. InterfaceClass parent_class;
  36. enum TpmModel model;
  37. void (*request_completed)(TPMIf *obj, int ret);
  38. enum TPMVersion (*get_version)(TPMIf *obj);
  39. };
  40. #define TYPE_TPM_TIS_ISA "tpm-tis"
  41. #define TYPE_TPM_TIS_SYSBUS "tpm-tis-device"
  42. #define TYPE_TPM_CRB "tpm-crb"
  43. #define TYPE_TPM_CRB_SYSBUS "tpm-crb-device"
  44. #define TYPE_TPM_SPAPR "tpm-spapr"
  45. #define TYPE_TPM_TIS_I2C "tpm-tis-i2c"
  46. #define TPM_IS_TIS_ISA(chr) \
  47. object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
  48. #define TPM_IS_TIS_SYSBUS(chr) \
  49. object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
  50. #define TPM_IS_CRB(chr) \
  51. object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
  52. #define TPM_IS_CRB_SYSBUS(chr) \
  53. object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB_SYSBUS)
  54. #define TPM_IS_SPAPR(chr) \
  55. object_dynamic_cast(OBJECT(chr), TYPE_TPM_SPAPR)
  56. #define TPM_IS_TIS_I2C(chr) \
  57. object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_I2C)
  58. /* returns NULL unless there is exactly one TPM device */
  59. static inline TPMIf *tpm_find(void)
  60. {
  61. Object *obj = object_resolve_path_type("", TYPE_TPM_IF, NULL);
  62. return TPM_IF(obj);
  63. }
  64. static inline TPMVersion tpm_get_version(TPMIf *ti)
  65. {
  66. if (!ti) {
  67. return TPM_VERSION_UNSPEC;
  68. }
  69. return TPM_IF_GET_CLASS(ti)->get_version(ti);
  70. }
  71. void tpm_sysbus_plug(TPMIf *tpmif, Object *pbus, hwaddr pbus_base);
  72. #else /* CONFIG_TPM */
  73. #define tpm_init() (0)
  74. #define tpm_cleanup()
  75. /* needed for an alignment check in non-tpm code */
  76. static inline Object *TPM_IS_CRB(Object *obj)
  77. {
  78. return NULL;
  79. }
  80. #endif /* CONFIG_TPM */
  81. #endif /* QEMU_TPM_H */