tpm.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. *
  17. * See file CREDITS for list of people who contributed to this
  18. * project.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation, version 2 of the
  23. * License.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33. * MA 02111-1307 USA
  34. */
  35. #ifndef _TPM_H_
  36. #define _TPM_H_
  37. #include <linux/compiler.h>
  38. #include "compatibility.h"
  39. enum tpm_timeout {
  40. TPM_TIMEOUT = 5, /* msecs */
  41. };
  42. /* Size of external transmit buffer (used in tpm_transmit)*/
  43. #define TPM_BUFSIZE 4096
  44. /* Index of fields in TPM command buffer */
  45. #define TPM_CMD_SIZE_BYTE 2
  46. #define TPM_CMD_ORDINAL_BYTE 6
  47. /* Index of Count field in TPM response buffer */
  48. #define TPM_RSP_SIZE_BYTE 2
  49. #define TPM_RSP_RC_BYTE 6
  50. struct tpm_chip;
  51. struct tpm_vendor_specific {
  52. const u8 req_complete_mask;
  53. const u8 req_complete_val;
  54. const u8 req_canceled;
  55. int irq;
  56. int (*recv) (struct tpm_chip *, u8 *, size_t);
  57. int (*send) (struct tpm_chip *, u8 *, size_t);
  58. void (*cancel) (struct tpm_chip *);
  59. u8(*status) (struct tpm_chip *);
  60. int locality;
  61. unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
  62. unsigned long duration[3]; /* msec */
  63. };
  64. struct tpm_chip {
  65. int is_open;
  66. struct tpm_vendor_specific vendor;
  67. };
  68. struct tpm_input_header {
  69. __be16 tag;
  70. __be32 length;
  71. __be32 ordinal;
  72. } __packed;
  73. struct tpm_output_header {
  74. __be16 tag;
  75. __be32 length;
  76. __be32 return_code;
  77. } __packed;
  78. struct timeout_t {
  79. __be32 a;
  80. __be32 b;
  81. __be32 c;
  82. __be32 d;
  83. } __packed;
  84. struct duration_t {
  85. __be32 tpm_short;
  86. __be32 tpm_medium;
  87. __be32 tpm_long;
  88. } __packed;
  89. union cap_t {
  90. struct timeout_t timeout;
  91. struct duration_t duration;
  92. };
  93. struct tpm_getcap_params_in {
  94. __be32 cap;
  95. __be32 subcap_size;
  96. __be32 subcap;
  97. } __packed;
  98. struct tpm_getcap_params_out {
  99. __be32 cap_size;
  100. union cap_t cap;
  101. } __packed;
  102. union tpm_cmd_header {
  103. struct tpm_input_header in;
  104. struct tpm_output_header out;
  105. };
  106. union tpm_cmd_params {
  107. struct tpm_getcap_params_out getcap_out;
  108. struct tpm_getcap_params_in getcap_in;
  109. };
  110. struct tpm_cmd_t {
  111. union tpm_cmd_header header;
  112. union tpm_cmd_params params;
  113. } __packed;
  114. /* ---------- Interface for TPM vendor ------------ */
  115. extern struct tpm_chip *tpm_register_hardware(
  116. const struct tpm_vendor_specific *);
  117. extern int tpm_vendor_init(uint32_t dev_addr);
  118. extern void tpm_vendor_cleanup(struct tpm_chip *chip);
  119. /* ---------- Interface for TDDL ------------------- */
  120. /*
  121. * if dev_addr != 0 - redefines TPM device address
  122. * Returns < 0 on error, 0 on success.
  123. */
  124. extern int tpm_open(uint32_t dev_addr);
  125. extern void tpm_close(void);
  126. /*
  127. * Transmit bufsiz bytes out of buf to TPM and get results back in buf, too.
  128. * Returns < 0 on error, 0 on success.
  129. */
  130. extern ssize_t tpm_transmit(const unsigned char *buf, size_t bufsiz);
  131. #endif