2
0

tpm.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * tpm.h - TPM ACPI definitions
  3. *
  4. * Copyright (C) 2014 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. * Implementation of the TIS interface according to specs found at
  13. * http://www.trustedcomputinggroup.org
  14. *
  15. */
  16. #ifndef HW_ACPI_TPM_H
  17. #define HW_ACPI_TPM_H
  18. #include "qemu/units.h"
  19. #include "hw/registerfields.h"
  20. #include "hw/acpi/aml-build.h"
  21. #include "system/tpm.h"
  22. #ifdef CONFIG_TPM
  23. #define TPM_TIS_ADDR_BASE 0xFED40000
  24. #define TPM_TIS_ADDR_SIZE 0x5000
  25. #define TPM_TIS_IRQ 5
  26. #define TPM_TIS_NUM_LOCALITIES 5 /* per spec */
  27. #define TPM_TIS_LOCALITY_SHIFT 12
  28. /* tis registers */
  29. #define TPM_TIS_REG_ACCESS 0x00
  30. #define TPM_TIS_REG_INT_ENABLE 0x08
  31. #define TPM_TIS_REG_INT_VECTOR 0x0c
  32. #define TPM_TIS_REG_INT_STATUS 0x10
  33. #define TPM_TIS_REG_INTF_CAPABILITY 0x14
  34. #define TPM_TIS_REG_STS 0x18
  35. #define TPM_TIS_REG_DATA_FIFO 0x24
  36. #define TPM_TIS_REG_INTERFACE_ID 0x30
  37. #define TPM_TIS_REG_DATA_XFIFO 0x80
  38. #define TPM_TIS_REG_DATA_XFIFO_END 0xbc
  39. #define TPM_TIS_REG_DID_VID 0xf00
  40. #define TPM_TIS_REG_RID 0xf04
  41. /* vendor-specific registers */
  42. #define TPM_TIS_REG_DEBUG 0xf90
  43. #define TPM_TIS_STS_TPM_FAMILY_MASK (0x3 << 26)/* TPM 2.0 */
  44. #define TPM_TIS_STS_TPM_FAMILY1_2 (0 << 26) /* TPM 2.0 */
  45. #define TPM_TIS_STS_TPM_FAMILY2_0 (1 << 26) /* TPM 2.0 */
  46. #define TPM_TIS_STS_RESET_ESTABLISHMENT_BIT (1 << 25) /* TPM 2.0 */
  47. #define TPM_TIS_STS_COMMAND_CANCEL (1 << 24) /* TPM 2.0 */
  48. #define TPM_TIS_STS_VALID (1 << 7)
  49. #define TPM_TIS_STS_COMMAND_READY (1 << 6)
  50. #define TPM_TIS_STS_TPM_GO (1 << 5)
  51. #define TPM_TIS_STS_DATA_AVAILABLE (1 << 4)
  52. #define TPM_TIS_STS_EXPECT (1 << 3)
  53. #define TPM_TIS_STS_SELFTEST_DONE (1 << 2)
  54. #define TPM_TIS_STS_RESPONSE_RETRY (1 << 1)
  55. #define TPM_TIS_BURST_COUNT_SHIFT 8
  56. #define TPM_TIS_BURST_COUNT(X) \
  57. ((X) << TPM_TIS_BURST_COUNT_SHIFT)
  58. #define TPM_TIS_ACCESS_TPM_REG_VALID_STS (1 << 7)
  59. #define TPM_TIS_ACCESS_ACTIVE_LOCALITY (1 << 5)
  60. #define TPM_TIS_ACCESS_BEEN_SEIZED (1 << 4)
  61. #define TPM_TIS_ACCESS_SEIZE (1 << 3)
  62. #define TPM_TIS_ACCESS_PENDING_REQUEST (1 << 2)
  63. #define TPM_TIS_ACCESS_REQUEST_USE (1 << 1)
  64. #define TPM_TIS_ACCESS_TPM_ESTABLISHMENT (1 << 0)
  65. #define TPM_TIS_INT_ENABLED (1 << 31)
  66. #define TPM_TIS_INT_DATA_AVAILABLE (1 << 0)
  67. #define TPM_TIS_INT_STS_VALID (1 << 1)
  68. #define TPM_TIS_INT_LOCALITY_CHANGED (1 << 2)
  69. #define TPM_TIS_INT_COMMAND_READY (1 << 7)
  70. #define TPM_TIS_INT_POLARITY_MASK (3 << 3)
  71. #define TPM_TIS_INT_POLARITY_LOW_LEVEL (1 << 3)
  72. #define TPM_TIS_INTERRUPTS_SUPPORTED (TPM_TIS_INT_LOCALITY_CHANGED | \
  73. TPM_TIS_INT_DATA_AVAILABLE | \
  74. TPM_TIS_INT_STS_VALID | \
  75. TPM_TIS_INT_COMMAND_READY)
  76. #define TPM_TIS_CAP_INTERFACE_VERSION1_3 (2 << 28)
  77. #define TPM_TIS_CAP_INTERFACE_VERSION1_3_FOR_TPM2_0 (3 << 28)
  78. #define TPM_TIS_CAP_DATA_TRANSFER_64B (3 << 9)
  79. #define TPM_TIS_CAP_DATA_TRANSFER_LEGACY (0 << 9)
  80. #define TPM_TIS_CAP_BURST_COUNT_DYNAMIC (0 << 8)
  81. #define TPM_TIS_CAP_BURST_COUNT_STATIC (1 << 8)
  82. #define TPM_TIS_CAP_INTERRUPT_LOW_LEVEL (1 << 4) /* support is mandatory */
  83. #define TPM_TIS_CAPABILITIES_SUPPORTED1_3 \
  84. (TPM_TIS_CAP_INTERRUPT_LOW_LEVEL | \
  85. TPM_TIS_CAP_BURST_COUNT_DYNAMIC | \
  86. TPM_TIS_CAP_DATA_TRANSFER_64B | \
  87. TPM_TIS_CAP_INTERFACE_VERSION1_3 | \
  88. TPM_TIS_INTERRUPTS_SUPPORTED)
  89. #define TPM_TIS_CAPABILITIES_SUPPORTED2_0 \
  90. (TPM_TIS_CAP_INTERRUPT_LOW_LEVEL | \
  91. TPM_TIS_CAP_BURST_COUNT_DYNAMIC | \
  92. TPM_TIS_CAP_DATA_TRANSFER_64B | \
  93. TPM_TIS_CAP_INTERFACE_VERSION1_3_FOR_TPM2_0 | \
  94. TPM_TIS_INTERRUPTS_SUPPORTED)
  95. #define TPM_TIS_IFACE_ID_INTERFACE_TIS1_3 (0xf) /* TPM 2.0 */
  96. #define TPM_TIS_IFACE_ID_INTERFACE_FIFO (0x0) /* TPM 2.0 */
  97. #define TPM_TIS_IFACE_ID_INTERFACE_VER_FIFO (0 << 4) /* TPM 2.0 */
  98. #define TPM_TIS_IFACE_ID_CAP_5_LOCALITIES (1 << 8) /* TPM 2.0 */
  99. #define TPM_TIS_IFACE_ID_CAP_TIS_SUPPORTED (1 << 13) /* TPM 2.0 */
  100. #define TPM_TIS_IFACE_ID_INT_SEL_LOCK (1 << 19) /* TPM 2.0 */
  101. #define TPM_TIS_IFACE_ID_SUPPORTED_FLAGS1_3 \
  102. (TPM_TIS_IFACE_ID_INTERFACE_TIS1_3 | \
  103. (~0u << 4)/* all of it is don't care */)
  104. /* if backend was a TPM 2.0: */
  105. #define TPM_TIS_IFACE_ID_SUPPORTED_FLAGS2_0 \
  106. (TPM_TIS_IFACE_ID_INTERFACE_FIFO | \
  107. TPM_TIS_IFACE_ID_INTERFACE_VER_FIFO | \
  108. TPM_TIS_IFACE_ID_CAP_5_LOCALITIES | \
  109. TPM_TIS_IFACE_ID_CAP_TIS_SUPPORTED)
  110. #define TPM_TIS_TPM_DID 0x0001
  111. #define TPM_TIS_TPM_VID PCI_VENDOR_ID_IBM
  112. #define TPM_TIS_TPM_RID 0x0001
  113. #define TPM_TIS_NO_DATA_BYTE 0xff
  114. REG32(CRB_LOC_STATE, 0x00)
  115. FIELD(CRB_LOC_STATE, tpmEstablished, 0, 1)
  116. FIELD(CRB_LOC_STATE, locAssigned, 1, 1)
  117. FIELD(CRB_LOC_STATE, activeLocality, 2, 3)
  118. FIELD(CRB_LOC_STATE, reserved, 5, 2)
  119. FIELD(CRB_LOC_STATE, tpmRegValidSts, 7, 1)
  120. REG32(CRB_LOC_CTRL, 0x08)
  121. REG32(CRB_LOC_STS, 0x0C)
  122. FIELD(CRB_LOC_STS, Granted, 0, 1)
  123. FIELD(CRB_LOC_STS, beenSeized, 1, 1)
  124. REG32(CRB_INTF_ID, 0x30)
  125. FIELD(CRB_INTF_ID, InterfaceType, 0, 4)
  126. FIELD(CRB_INTF_ID, InterfaceVersion, 4, 4)
  127. FIELD(CRB_INTF_ID, CapLocality, 8, 1)
  128. FIELD(CRB_INTF_ID, CapCRBIdleBypass, 9, 1)
  129. FIELD(CRB_INTF_ID, Reserved1, 10, 1)
  130. FIELD(CRB_INTF_ID, CapDataXferSizeSupport, 11, 2)
  131. FIELD(CRB_INTF_ID, CapFIFO, 13, 1)
  132. FIELD(CRB_INTF_ID, CapCRB, 14, 1)
  133. FIELD(CRB_INTF_ID, CapIFRes, 15, 2)
  134. FIELD(CRB_INTF_ID, InterfaceSelector, 17, 2)
  135. FIELD(CRB_INTF_ID, IntfSelLock, 19, 1)
  136. FIELD(CRB_INTF_ID, Reserved2, 20, 4)
  137. FIELD(CRB_INTF_ID, RID, 24, 8)
  138. REG32(CRB_INTF_ID2, 0x34)
  139. FIELD(CRB_INTF_ID2, VID, 0, 16)
  140. FIELD(CRB_INTF_ID2, DID, 16, 16)
  141. REG32(CRB_CTRL_EXT, 0x38)
  142. REG32(CRB_CTRL_REQ, 0x40)
  143. REG32(CRB_CTRL_STS, 0x44)
  144. FIELD(CRB_CTRL_STS, tpmSts, 0, 1)
  145. FIELD(CRB_CTRL_STS, tpmIdle, 1, 1)
  146. REG32(CRB_CTRL_CANCEL, 0x48)
  147. REG32(CRB_CTRL_START, 0x4C)
  148. REG32(CRB_INT_ENABLED, 0x50)
  149. REG32(CRB_INT_STS, 0x54)
  150. REG32(CRB_CTRL_CMD_SIZE, 0x58)
  151. REG32(CRB_CTRL_CMD_LADDR, 0x5C)
  152. REG32(CRB_CTRL_CMD_HADDR, 0x60)
  153. REG32(CRB_CTRL_RSP_SIZE, 0x64)
  154. REG32(CRB_CTRL_RSP_LADDR, 0x68)
  155. REG32(CRB_CTRL_RSP_HADDR, 0x6C)
  156. REG32(CRB_DATA_BUFFER, 0x80)
  157. #define TPM_CRB_ADDR_BASE 0xFED40000
  158. #define TPM_CRB_ADDR_SIZE 0x1000
  159. #define TPM_CRB_ADDR_CTRL (TPM_CRB_ADDR_BASE + A_CRB_CTRL_REQ)
  160. #define TPM_CRB_R_MAX R_CRB_DATA_BUFFER
  161. #define TPM_LOG_AREA_MINIMUM_SIZE (64 * KiB)
  162. #define TPM_TCPA_ACPI_CLASS_CLIENT 0
  163. #define TPM_TCPA_ACPI_CLASS_SERVER 1
  164. #define TPM2_ACPI_CLASS_CLIENT 0
  165. #define TPM2_ACPI_CLASS_SERVER 1
  166. #define TPM2_START_METHOD_MMIO 6
  167. #define TPM2_START_METHOD_CRB 7
  168. /*
  169. * Physical Presence Interface
  170. */
  171. #define TPM_PPI_ADDR_SIZE 0x400
  172. #define TPM_PPI_ADDR_BASE 0xFED45000
  173. #define TPM_PPI_VERSION_NONE 0
  174. #define TPM_PPI_VERSION_1_30 1
  175. /* whether function is blocked by BIOS settings; bits 0, 1, 2 */
  176. #define TPM_PPI_FUNC_NOT_IMPLEMENTED (0 << 0)
  177. #define TPM_PPI_FUNC_BIOS_ONLY (1 << 0)
  178. #define TPM_PPI_FUNC_BLOCKED (2 << 0)
  179. #define TPM_PPI_FUNC_ALLOWED_USR_REQ (3 << 0)
  180. #define TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ (4 << 0)
  181. #define TPM_PPI_FUNC_MASK (7 << 0)
  182. /* TPM TIS I2C registers */
  183. #define TPM_I2C_REG_LOC_SEL 0x00
  184. #define TPM_I2C_REG_ACCESS 0x04
  185. #define TPM_I2C_REG_INT_ENABLE 0x08
  186. #define TPM_I2C_REG_INT_CAPABILITY 0x14
  187. #define TPM_I2C_REG_STS 0x18
  188. #define TPM_I2C_REG_DATA_FIFO 0x24
  189. #define TPM_I2C_REG_INTF_CAPABILITY 0x30
  190. #define TPM_I2C_REG_I2C_DEV_ADDRESS 0x38
  191. #define TPM_I2C_REG_DATA_CSUM_ENABLE 0x40
  192. #define TPM_I2C_REG_DATA_CSUM_GET 0x44
  193. #define TPM_I2C_REG_DID_VID 0x48
  194. #define TPM_I2C_REG_RID 0x4c
  195. #define TPM_I2C_REG_UNKNOWN 0xff
  196. /* I2C specific interface capabilities */
  197. #define TPM_I2C_CAP_INTERFACE_TYPE (0x2 << 0) /* FIFO interface */
  198. #define TPM_I2C_CAP_INTERFACE_VER (0x0 << 4) /* TCG I2C intf 1.0 */
  199. #define TPM_I2C_CAP_TPM2_FAMILY (0x1 << 7) /* TPM 2.0 family. */
  200. #define TPM_I2C_CAP_DEV_ADDR_CHANGE (0x0 << 27) /* No dev addr chng */
  201. #define TPM_I2C_CAP_BURST_COUNT_STATIC (0x1 << 29) /* Burst count static */
  202. #define TPM_I2C_CAP_LOCALITY_CAP (0x1 << 25) /* 0-5 locality */
  203. #define TPM_I2C_CAP_BUS_SPEED (3 << 21) /* std and fast mode */
  204. /*
  205. * TPM_I2C_STS masks for read/writing bits from/to TIS
  206. * TPM_STS mask for read bits 31:26 must be zero
  207. */
  208. #define TPM_I2C_STS_READ_MASK 0x00ffffdd
  209. #define TPM_I2C_STS_WRITE_MASK 0x03000062
  210. /* Checksum enabled. */
  211. #define TPM_DATA_CSUM_ENABLED 0x1
  212. /*
  213. * TPM_I2C_INT_ENABLE mask. Linux kernel does not support
  214. * interrupts hence setting it to 0.
  215. */
  216. #define TPM_I2C_INT_ENABLE_MASK 0x0
  217. void tpm_build_ppi_acpi(TPMIf *tpm, Aml *dev);
  218. #endif /* CONFIG_TPM */
  219. #endif /* HW_ACPI_TPM_H */