tpm_tis_i2c.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright (C) 2011 Infineon Technologies
  3. *
  4. * Authors:
  5. * Peter Huewe <huewe.external@infineon.com>
  6. *
  7. * Version: 2.1.1
  8. *
  9. * Description:
  10. * Device driver for TCG/TCPA TPM (trusted platform module).
  11. * Specifications at www.trustedcomputinggroup.org
  12. *
  13. * It is based on the Linux kernel driver tpm.c from Leendert van
  14. * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
  15. *
  16. * SPDX-License-Identifier: GPL-2.0
  17. */
  18. #ifndef _TPM_TIS_I2C_H
  19. #define _TPM_TIS_I2C_H
  20. #include <linux/compiler.h>
  21. #include <linux/types.h>
  22. enum tpm_timeout {
  23. TPM_TIMEOUT_MS = 5,
  24. TIS_SHORT_TIMEOUT_MS = 750,
  25. TIS_LONG_TIMEOUT_MS = 2000,
  26. SLEEP_DURATION_US = 60,
  27. SLEEP_DURATION_LONG_US = 210,
  28. };
  29. /* Size of external transmit buffer (used in tpm_transmit)*/
  30. #define TPM_BUFSIZE 4096
  31. /* Index of Count field in TPM response buffer */
  32. #define TPM_RSP_SIZE_BYTE 2
  33. #define TPM_RSP_RC_BYTE 6
  34. /* Max buffer size supported by our tpm */
  35. #define TPM_DEV_BUFSIZE 1260
  36. enum i2c_chip_type {
  37. SLB9635,
  38. SLB9645,
  39. UNKNOWN,
  40. };
  41. struct tpm_chip {
  42. bool inited;
  43. int is_open;
  44. u8 req_complete_mask;
  45. u8 req_complete_val;
  46. u8 req_canceled;
  47. int irq;
  48. int locality;
  49. unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
  50. unsigned long duration[3]; /* msec */
  51. struct udevice *dev;
  52. u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
  53. enum i2c_chip_type chip_type;
  54. };
  55. struct tpm_input_header {
  56. __be16 tag;
  57. __be32 length;
  58. __be32 ordinal;
  59. } __packed;
  60. struct tpm_output_header {
  61. __be16 tag;
  62. __be32 length;
  63. __be32 return_code;
  64. } __packed;
  65. struct timeout_t {
  66. __be32 a;
  67. __be32 b;
  68. __be32 c;
  69. __be32 d;
  70. } __packed;
  71. struct duration_t {
  72. __be32 tpm_short;
  73. __be32 tpm_medium;
  74. __be32 tpm_long;
  75. } __packed;
  76. union cap_t {
  77. struct timeout_t timeout;
  78. struct duration_t duration;
  79. };
  80. struct tpm_getcap_params_in {
  81. __be32 cap;
  82. __be32 subcap_size;
  83. __be32 subcap;
  84. } __packed;
  85. struct tpm_getcap_params_out {
  86. __be32 cap_size;
  87. union cap_t cap;
  88. } __packed;
  89. union tpm_cmd_header {
  90. struct tpm_input_header in;
  91. struct tpm_output_header out;
  92. };
  93. union tpm_cmd_params {
  94. struct tpm_getcap_params_out getcap_out;
  95. struct tpm_getcap_params_in getcap_in;
  96. };
  97. struct tpm_cmd_t {
  98. union tpm_cmd_header header;
  99. union tpm_cmd_params params;
  100. } __packed;
  101. /* Max number of iterations after i2c NAK */
  102. #define MAX_COUNT 3
  103. /*
  104. * Max number of iterations after i2c NAK for 'long' commands
  105. *
  106. * We need this especially for sending TPM_READY, since the cleanup after the
  107. * transtion to the ready state may take some time, but it is unpredictable
  108. * how long it will take.
  109. */
  110. #define MAX_COUNT_LONG 50
  111. #define TPM_HEADER_SIZE 10
  112. enum tis_access {
  113. TPM_ACCESS_VALID = 0x80,
  114. TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
  115. TPM_ACCESS_REQUEST_PENDING = 0x04,
  116. TPM_ACCESS_REQUEST_USE = 0x02,
  117. };
  118. enum tis_status {
  119. TPM_STS_VALID = 0x80,
  120. TPM_STS_COMMAND_READY = 0x40,
  121. TPM_STS_GO = 0x20,
  122. TPM_STS_DATA_AVAIL = 0x10,
  123. TPM_STS_DATA_EXPECT = 0x08,
  124. };
  125. /* expected value for DIDVID register */
  126. #define TPM_TIS_I2C_DID_VID_9635 0x000b15d1L
  127. #define TPM_TIS_I2C_DID_VID_9645 0x001a15d1L
  128. #define TPM_ACCESS(l) (0x0000 | ((l) << 4))
  129. #define TPM_STS(l) (0x0001 | ((l) << 4))
  130. #define TPM_DATA_FIFO(l) (0x0005 | ((l) << 4))
  131. #define TPM_DID_VID(l) (0x0006 | ((l) << 4))
  132. /* Extended error numbers from linux (see errno.h) */
  133. #define ECANCELED 125 /* Operation Canceled */
  134. /* Timer frequency. Corresponds to msec timer resolution */
  135. #define HZ 1000
  136. #endif