tpm.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. extern void tpm_get_timeouts(struct tpm_chip *);
  108. extern void tpm_gen_interrupt(struct tpm_chip *);
  109. extern void tpm_continue_selftest(struct tpm_chip *);
  110. extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
  111. extern struct tpm_chip* tpm_register_hardware(struct device *,
  112. const struct tpm_vendor_specific *);
  113. extern int tpm_open(struct inode *, struct file *);
  114. extern int tpm_release(struct inode *, struct file *);
  115. extern void tpm_dev_vendor_release(struct tpm_chip *);
  116. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  117. loff_t *);
  118. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  119. extern void tpm_remove_hardware(struct device *);
  120. extern int tpm_pm_suspend(struct device *, pm_message_t);
  121. extern int tpm_pm_resume(struct device *);
  122. #ifdef CONFIG_ACPI
  123. extern struct dentry ** tpm_bios_log_setup(char *);
  124. extern void tpm_bios_log_teardown(struct dentry **);
  125. #else
  126. static inline struct dentry ** tpm_bios_log_setup(char *name)
  127. {
  128. return NULL;
  129. }
  130. static inline void tpm_bios_log_teardown(struct dentry **dir)
  131. {
  132. }
  133. #endif