tpm_tis.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2011 Infineon Technologies
  4. *
  5. * Authors:
  6. * Peter Huewe <huewe.external@infineon.com>
  7. *
  8. * Version: 2.1.1
  9. *
  10. * Description:
  11. * Device driver for TCG/TCPA TPM (trusted platform module).
  12. * Specifications at www.trustedcomputinggroup.org
  13. *
  14. * It is based on the Linux kernel driver tpm.c from Leendert van
  15. * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
  16. */
  17. #ifndef _TPM_TIS_I2C_H
  18. #define _TPM_TIS_I2C_H
  19. #include <linux/compiler.h>
  20. #include <linux/types.h>
  21. enum tpm_timeout {
  22. TPM_TIMEOUT_MS = 5,
  23. TIS_SHORT_TIMEOUT_MS = 750,
  24. TIS_LONG_TIMEOUT_MS = 2000,
  25. SLEEP_DURATION_US = 60,
  26. SLEEP_DURATION_LONG_US = 210,
  27. };
  28. /* Size of external transmit buffer (used in tpm_transmit)*/
  29. #define TPM_BUFSIZE 4096
  30. /* Index of Count field in TPM response buffer */
  31. #define TPM_RSP_SIZE_BYTE 2
  32. #define TPM_RSP_RC_BYTE 6
  33. struct tpm_chip {
  34. int is_open;
  35. int locality;
  36. u32 vend_dev;
  37. u8 rid;
  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. #ifndef __TPM_V2_H
  90. /*
  91. * Max number of iterations after i2c NAK for 'long' commands
  92. *
  93. * We need this especially for sending TPM_READY, since the cleanup after the
  94. * transtion to the ready state may take some time, but it is unpredictable
  95. * how long it will take.
  96. */
  97. #define MAX_COUNT_LONG 50
  98. enum tis_access {
  99. TPM_ACCESS_VALID = 0x80,
  100. TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
  101. TPM_ACCESS_REQUEST_PENDING = 0x04,
  102. TPM_ACCESS_REQUEST_USE = 0x02,
  103. };
  104. enum tis_status {
  105. TPM_STS_VALID = 0x80,
  106. TPM_STS_COMMAND_READY = 0x40,
  107. TPM_STS_GO = 0x20,
  108. TPM_STS_DATA_AVAIL = 0x10,
  109. TPM_STS_DATA_EXPECT = 0x08,
  110. };
  111. #endif
  112. #endif