tpm.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright (C) 2004 IBM Corporation
  3. *
  4. * Authors:
  5. * Leendert van Doorn <leendert@watson.ibm.com>
  6. * Dave Safford <safford@watson.ibm.com>
  7. * Reiner Sailer <sailer@watson.ibm.com>
  8. * Kylene Hall <kjhall@us.ibm.com>
  9. *
  10. * Maintained by: <tpmdd-devel@lists.sourceforge.net>
  11. *
  12. * Device driver for TCG/TCPA TPM (trusted platform module).
  13. * Specifications at www.trustedcomputinggroup.org
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation, version 2 of the
  18. * License.
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/delay.h>
  23. #include <linux/fs.h>
  24. #include <linux/mutex.h>
  25. #include <linux/sched.h>
  26. #include <linux/miscdevice.h>
  27. #include <linux/platform_device.h>
  28. #include <linux/io.h>
  29. enum tpm_timeout {
  30. TPM_TIMEOUT = 5, /* msecs */
  31. };
  32. /* TPM addresses */
  33. enum tpm_addr {
  34. TPM_SUPERIO_ADDR = 0x2E,
  35. TPM_ADDR = 0x4E,
  36. };
  37. extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr,
  38. char *);
  39. extern ssize_t tpm_show_pcrs(struct device *, struct device_attribute *attr,
  40. char *);
  41. extern ssize_t tpm_show_caps(struct device *, struct device_attribute *attr,
  42. char *);
  43. extern ssize_t tpm_show_caps_1_2(struct device *, struct device_attribute *attr,
  44. char *);
  45. extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
  46. const char *, size_t);
  47. extern ssize_t tpm_show_enabled(struct device *, struct device_attribute *attr,
  48. char *);
  49. extern ssize_t tpm_show_active(struct device *, struct device_attribute *attr,
  50. char *);
  51. extern ssize_t tpm_show_owned(struct device *, struct device_attribute *attr,
  52. char *);
  53. extern ssize_t tpm_show_temp_deactivated(struct device *,
  54. struct device_attribute *attr, char *);
  55. struct tpm_chip;
  56. struct tpm_vendor_specific {
  57. const u8 req_complete_mask;
  58. const u8 req_complete_val;
  59. const u8 req_canceled;
  60. void __iomem *iobase; /* ioremapped address */
  61. unsigned long base; /* TPM base address */
  62. int irq;
  63. int region_size;
  64. int have_region;
  65. int (*recv) (struct tpm_chip *, u8 *, size_t);
  66. int (*send) (struct tpm_chip *, u8 *, size_t);
  67. void (*cancel) (struct tpm_chip *);
  68. u8 (*status) (struct tpm_chip *);
  69. void (*release) (struct device *);
  70. struct miscdevice miscdev;
  71. struct attribute_group *attr_group;
  72. struct list_head list;
  73. int locality;
  74. unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
  75. unsigned long duration[3]; /* jiffies */
  76. wait_queue_head_t read_queue;
  77. wait_queue_head_t int_queue;
  78. };
  79. struct tpm_chip {
  80. struct device *dev; /* Device stuff */
  81. int dev_num; /* /dev/tpm# */
  82. unsigned long is_open; /* only one allowed */
  83. int time_expired;
  84. /* Data passed to and from the tpm via the read/write calls */
  85. u8 *data_buffer;
  86. atomic_t data_pending;
  87. struct mutex buffer_mutex;
  88. struct timer_list user_read_timer; /* user needs to claim result */
  89. struct work_struct work;
  90. struct mutex tpm_mutex; /* tpm is processing */
  91. struct tpm_vendor_specific vendor;
  92. struct dentry **bios_dir;
  93. struct list_head list;
  94. void (*release) (struct device *);
  95. };
  96. #define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
  97. static inline int tpm_read_index(int base, int index)
  98. {
  99. outb(index, base);
  100. return inb(base+1) & 0xFF;
  101. }
  102. static inline void tpm_write_index(int base, int index, int value)
  103. {
  104. outb(index, base);
  105. outb(value & 0xFF, base+1);
  106. }
  107. struct tpm_input_header {
  108. __be16 tag;
  109. __be32 length;
  110. __be32 ordinal;
  111. }__attribute__((packed));
  112. struct tpm_output_header {
  113. __be16 tag;
  114. __be32 length;
  115. __be32 return_code;
  116. }__attribute__((packed));
  117. struct stclear_flags_t {
  118. __be16 tag;
  119. u8 deactivated;
  120. u8 disableForceClear;
  121. u8 physicalPresence;
  122. u8 physicalPresenceLock;
  123. u8 bGlobalLock;
  124. }__attribute__((packed));
  125. struct tpm_version_t {
  126. u8 Major;
  127. u8 Minor;
  128. u8 revMajor;
  129. u8 revMinor;
  130. }__attribute__((packed));
  131. struct tpm_version_1_2_t {
  132. __be16 tag;
  133. u8 Major;
  134. u8 Minor;
  135. u8 revMajor;
  136. u8 revMinor;
  137. }__attribute__((packed));
  138. struct timeout_t {
  139. __be32 a;
  140. __be32 b;
  141. __be32 c;
  142. __be32 d;
  143. }__attribute__((packed));
  144. struct duration_t {
  145. __be32 tpm_short;
  146. __be32 tpm_medium;
  147. __be32 tpm_long;
  148. }__attribute__((packed));
  149. struct permanent_flags_t {
  150. __be16 tag;
  151. u8 disable;
  152. u8 ownership;
  153. u8 deactivated;
  154. u8 readPubek;
  155. u8 disableOwnerClear;
  156. u8 allowMaintenance;
  157. u8 physicalPresenceLifetimeLock;
  158. u8 physicalPresenceHWEnable;
  159. u8 physicalPresenceCMDEnable;
  160. u8 CEKPUsed;
  161. u8 TPMpost;
  162. u8 TPMpostLock;
  163. u8 FIPS;
  164. u8 operator;
  165. u8 enableRevokeEK;
  166. u8 nvLocked;
  167. u8 readSRKPub;
  168. u8 tpmEstablished;
  169. u8 maintenanceDone;
  170. u8 disableFullDALogicInfo;
  171. }__attribute__((packed));
  172. typedef union {
  173. struct permanent_flags_t perm_flags;
  174. struct stclear_flags_t stclear_flags;
  175. bool owned;
  176. __be32 num_pcrs;
  177. struct tpm_version_t tpm_version;
  178. struct tpm_version_1_2_t tpm_version_1_2;
  179. __be32 manufacturer_id;
  180. struct timeout_t timeout;
  181. struct duration_t duration;
  182. } cap_t;
  183. struct tpm_getcap_params_in {
  184. __be32 cap;
  185. __be32 subcap_size;
  186. __be32 subcap;
  187. }__attribute__((packed));
  188. struct tpm_getcap_params_out {
  189. __be32 cap_size;
  190. cap_t cap;
  191. }__attribute__((packed));
  192. struct tpm_readpubek_params_out {
  193. u8 algorithm[4];
  194. u8 encscheme[2];
  195. u8 sigscheme[2];
  196. u8 parameters[12]; /*assuming RSA*/
  197. __be32 keysize;
  198. u8 modulus[256];
  199. u8 checksum[20];
  200. }__attribute__((packed));
  201. typedef union {
  202. struct tpm_input_header in;
  203. struct tpm_output_header out;
  204. } tpm_cmd_header;
  205. typedef union {
  206. struct tpm_getcap_params_out getcap_out;
  207. struct tpm_readpubek_params_out readpubek_out;
  208. u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)];
  209. struct tpm_getcap_params_in getcap_in;
  210. } tpm_cmd_params;
  211. struct tpm_cmd_t {
  212. tpm_cmd_header header;
  213. tpm_cmd_params params;
  214. }__attribute__((packed));
  215. ssize_t tpm_getcap(struct device *, __be32, cap_t *, const char *);
  216. extern void tpm_get_timeouts(struct tpm_chip *);
  217. extern void tpm_gen_interrupt(struct tpm_chip *);
  218. extern void tpm_continue_selftest(struct tpm_chip *);
  219. extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
  220. extern struct tpm_chip* tpm_register_hardware(struct device *,
  221. const struct tpm_vendor_specific *);
  222. extern int tpm_open(struct inode *, struct file *);
  223. extern int tpm_release(struct inode *, struct file *);
  224. extern void tpm_dev_vendor_release(struct tpm_chip *);
  225. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  226. loff_t *);
  227. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  228. extern void tpm_remove_hardware(struct device *);
  229. extern int tpm_pm_suspend(struct device *, pm_message_t);
  230. extern int tpm_pm_resume(struct device *);
  231. #ifdef CONFIG_ACPI
  232. extern struct dentry ** tpm_bios_log_setup(char *);
  233. extern void tpm_bios_log_teardown(struct dentry **);
  234. #else
  235. static inline struct dentry ** tpm_bios_log_setup(char *name)
  236. {
  237. return NULL;
  238. }
  239. static inline void tpm_bios_log_teardown(struct dentry **dir)
  240. {
  241. }
  242. #endif