tpm_tis.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. struct tpm_chip {
  35. int is_open;
  36. int locality;
  37. u32 vend_dev;
  38. unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
  39. ulong chip_type;
  40. };
  41. struct tpm_input_header {
  42. __be16 tag;
  43. __be32 length;
  44. __be32 ordinal;
  45. } __packed;
  46. struct tpm_output_header {
  47. __be16 tag;
  48. __be32 length;
  49. __be32 return_code;
  50. } __packed;
  51. struct timeout_t {
  52. __be32 a;
  53. __be32 b;
  54. __be32 c;
  55. __be32 d;
  56. } __packed;
  57. struct duration_t {
  58. __be32 tpm_short;
  59. __be32 tpm_medium;
  60. __be32 tpm_long;
  61. } __packed;
  62. union cap_t {
  63. struct timeout_t timeout;
  64. struct duration_t duration;
  65. };
  66. struct tpm_getcap_params_in {
  67. __be32 cap;
  68. __be32 subcap_size;
  69. __be32 subcap;
  70. } __packed;
  71. struct tpm_getcap_params_out {
  72. __be32 cap_size;
  73. union cap_t cap;
  74. } __packed;
  75. union tpm_cmd_header {
  76. struct tpm_input_header in;
  77. struct tpm_output_header out;
  78. };
  79. union tpm_cmd_params {
  80. struct tpm_getcap_params_out getcap_out;
  81. struct tpm_getcap_params_in getcap_in;
  82. };
  83. struct tpm_cmd_t {
  84. union tpm_cmd_header header;
  85. union tpm_cmd_params params;
  86. } __packed;
  87. /* Max number of iterations after i2c NAK */
  88. #define MAX_COUNT 3
  89. /*
  90. * Max number of iterations after i2c NAK for 'long' commands
  91. *
  92. * We need this especially for sending TPM_READY, since the cleanup after the
  93. * transtion to the ready state may take some time, but it is unpredictable
  94. * how long it will take.
  95. */
  96. #define MAX_COUNT_LONG 50
  97. enum tis_access {
  98. TPM_ACCESS_VALID = 0x80,
  99. TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
  100. TPM_ACCESS_REQUEST_PENDING = 0x04,
  101. TPM_ACCESS_REQUEST_USE = 0x02,
  102. };
  103. enum tis_status {
  104. TPM_STS_VALID = 0x80,
  105. TPM_STS_COMMAND_READY = 0x40,
  106. TPM_STS_GO = 0x20,
  107. TPM_STS_DATA_AVAIL = 0x10,
  108. TPM_STS_DATA_EXPECT = 0x08,
  109. };
  110. #endif