PageRenderTime 37ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/char/tpm/tpm.h

https://bitbucket.org/wisechild/galaxy-nexus
C++ Header | 302 lines | 240 code | 40 blank | 22 comment | 0 complexity | 3f94f90099d56b6c4fc7719b98445254 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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. #include <linux/tpm.h>
  30. enum tpm_timeout {
  31. TPM_TIMEOUT = 5, /* msecs */
  32. };
  33. /* TPM addresses */
  34. enum tpm_addr {
  35. TPM_SUPERIO_ADDR = 0x2E,
  36. TPM_ADDR = 0x4E,
  37. };
  38. extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr,
  39. char *);
  40. extern ssize_t tpm_show_pcrs(struct device *, struct device_attribute *attr,
  41. char *);
  42. extern ssize_t tpm_show_caps(struct device *, struct device_attribute *attr,
  43. char *);
  44. extern ssize_t tpm_show_caps_1_2(struct device *, struct device_attribute *attr,
  45. char *);
  46. extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
  47. const char *, size_t);
  48. extern ssize_t tpm_show_enabled(struct device *, struct device_attribute *attr,
  49. char *);
  50. extern ssize_t tpm_show_active(struct device *, struct device_attribute *attr,
  51. char *);
  52. extern ssize_t tpm_show_owned(struct device *, struct device_attribute *attr,
  53. char *);
  54. extern ssize_t tpm_show_temp_deactivated(struct device *,
  55. struct device_attribute *attr, char *);
  56. struct tpm_chip;
  57. struct tpm_vendor_specific {
  58. const u8 req_complete_mask;
  59. const u8 req_complete_val;
  60. const u8 req_canceled;
  61. void __iomem *iobase; /* ioremapped address */
  62. unsigned long base; /* TPM base address */
  63. int irq;
  64. int region_size;
  65. int have_region;
  66. int (*recv) (struct tpm_chip *, u8 *, size_t);
  67. int (*send) (struct tpm_chip *, u8 *, size_t);
  68. void (*cancel) (struct tpm_chip *);
  69. u8 (*status) (struct tpm_chip *);
  70. void (*release) (struct device *);
  71. struct miscdevice miscdev;
  72. struct attribute_group *attr_group;
  73. struct list_head list;
  74. int locality;
  75. unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
  76. unsigned long duration[3]; /* jiffies */
  77. wait_queue_head_t read_queue;
  78. wait_queue_head_t int_queue;
  79. };
  80. struct tpm_chip {
  81. struct device *dev; /* Device stuff */
  82. int dev_num; /* /dev/tpm# */
  83. unsigned long is_open; /* only one allowed */
  84. int time_expired;
  85. /* Data passed to and from the tpm via the read/write calls */
  86. u8 *data_buffer;
  87. atomic_t data_pending;
  88. struct mutex buffer_mutex;
  89. struct timer_list user_read_timer; /* user needs to claim result */
  90. struct work_struct work;
  91. struct mutex tpm_mutex; /* tpm is processing */
  92. struct tpm_vendor_specific vendor;
  93. struct dentry **bios_dir;
  94. struct list_head list;
  95. void (*release) (struct device *);
  96. };
  97. #define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
  98. static inline void tpm_chip_put(struct tpm_chip *chip)
  99. {
  100. module_put(chip->dev->driver->owner);
  101. }
  102. static inline int tpm_read_index(int base, int index)
  103. {
  104. outb(index, base);
  105. return inb(base+1) & 0xFF;
  106. }
  107. static inline void tpm_write_index(int base, int index, int value)
  108. {
  109. outb(index, base);
  110. outb(value & 0xFF, base+1);
  111. }
  112. struct tpm_input_header {
  113. __be16 tag;
  114. __be32 length;
  115. __be32 ordinal;
  116. }__attribute__((packed));
  117. struct tpm_output_header {
  118. __be16 tag;
  119. __be32 length;
  120. __be32 return_code;
  121. }__attribute__((packed));
  122. struct stclear_flags_t {
  123. __be16 tag;
  124. u8 deactivated;
  125. u8 disableForceClear;
  126. u8 physicalPresence;
  127. u8 physicalPresenceLock;
  128. u8 bGlobalLock;
  129. }__attribute__((packed));
  130. struct tpm_version_t {
  131. u8 Major;
  132. u8 Minor;
  133. u8 revMajor;
  134. u8 revMinor;
  135. }__attribute__((packed));
  136. struct tpm_version_1_2_t {
  137. __be16 tag;
  138. u8 Major;
  139. u8 Minor;
  140. u8 revMajor;
  141. u8 revMinor;
  142. }__attribute__((packed));
  143. struct timeout_t {
  144. __be32 a;
  145. __be32 b;
  146. __be32 c;
  147. __be32 d;
  148. }__attribute__((packed));
  149. struct duration_t {
  150. __be32 tpm_short;
  151. __be32 tpm_medium;
  152. __be32 tpm_long;
  153. }__attribute__((packed));
  154. struct permanent_flags_t {
  155. __be16 tag;
  156. u8 disable;
  157. u8 ownership;
  158. u8 deactivated;
  159. u8 readPubek;
  160. u8 disableOwnerClear;
  161. u8 allowMaintenance;
  162. u8 physicalPresenceLifetimeLock;
  163. u8 physicalPresenceHWEnable;
  164. u8 physicalPresenceCMDEnable;
  165. u8 CEKPUsed;
  166. u8 TPMpost;
  167. u8 TPMpostLock;
  168. u8 FIPS;
  169. u8 operator;
  170. u8 enableRevokeEK;
  171. u8 nvLocked;
  172. u8 readSRKPub;
  173. u8 tpmEstablished;
  174. u8 maintenanceDone;
  175. u8 disableFullDALogicInfo;
  176. }__attribute__((packed));
  177. typedef union {
  178. struct permanent_flags_t perm_flags;
  179. struct stclear_flags_t stclear_flags;
  180. bool owned;
  181. __be32 num_pcrs;
  182. struct tpm_version_t tpm_version;
  183. struct tpm_version_1_2_t tpm_version_1_2;
  184. __be32 manufacturer_id;
  185. struct timeout_t timeout;
  186. struct duration_t duration;
  187. } cap_t;
  188. struct tpm_getcap_params_in {
  189. __be32 cap;
  190. __be32 subcap_size;
  191. __be32 subcap;
  192. }__attribute__((packed));
  193. struct tpm_getcap_params_out {
  194. __be32 cap_size;
  195. cap_t cap;
  196. }__attribute__((packed));
  197. struct tpm_readpubek_params_out {
  198. u8 algorithm[4];
  199. u8 encscheme[2];
  200. u8 sigscheme[2];
  201. __be32 paramsize;
  202. u8 parameters[12]; /*assuming RSA*/
  203. __be32 keysize;
  204. u8 modulus[256];
  205. u8 checksum[20];
  206. }__attribute__((packed));
  207. typedef union {
  208. struct tpm_input_header in;
  209. struct tpm_output_header out;
  210. } tpm_cmd_header;
  211. #define TPM_DIGEST_SIZE 20
  212. struct tpm_pcrread_out {
  213. u8 pcr_result[TPM_DIGEST_SIZE];
  214. }__attribute__((packed));
  215. struct tpm_pcrread_in {
  216. __be32 pcr_idx;
  217. }__attribute__((packed));
  218. struct tpm_pcrextend_in {
  219. __be32 pcr_idx;
  220. u8 hash[TPM_DIGEST_SIZE];
  221. }__attribute__((packed));
  222. typedef union {
  223. struct tpm_getcap_params_out getcap_out;
  224. struct tpm_readpubek_params_out readpubek_out;
  225. u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)];
  226. struct tpm_getcap_params_in getcap_in;
  227. struct tpm_pcrread_in pcrread_in;
  228. struct tpm_pcrread_out pcrread_out;
  229. struct tpm_pcrextend_in pcrextend_in;
  230. } tpm_cmd_params;
  231. struct tpm_cmd_t {
  232. tpm_cmd_header header;
  233. tpm_cmd_params params;
  234. }__attribute__((packed));
  235. ssize_t tpm_getcap(struct device *, __be32, cap_t *, const char *);
  236. extern void tpm_get_timeouts(struct tpm_chip *);
  237. extern void tpm_gen_interrupt(struct tpm_chip *);
  238. extern void tpm_continue_selftest(struct tpm_chip *);
  239. extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
  240. extern struct tpm_chip* tpm_register_hardware(struct device *,
  241. const struct tpm_vendor_specific *);
  242. extern int tpm_open(struct inode *, struct file *);
  243. extern int tpm_release(struct inode *, struct file *);
  244. extern void tpm_dev_vendor_release(struct tpm_chip *);
  245. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  246. loff_t *);
  247. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  248. extern void tpm_remove_hardware(struct device *);
  249. extern int tpm_pm_suspend(struct device *, pm_message_t);
  250. extern int tpm_pm_resume(struct device *);
  251. #ifdef CONFIG_ACPI
  252. extern struct dentry ** tpm_bios_log_setup(char *);
  253. extern void tpm_bios_log_teardown(struct dentry **);
  254. #else
  255. static inline struct dentry ** tpm_bios_log_setup(char *name)
  256. {
  257. return NULL;
  258. }
  259. static inline void tpm_bios_log_teardown(struct dentry **dir)
  260. {
  261. }
  262. #endif