tpm.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/pci.h>
  23. #include <linux/delay.h>
  24. #include <linux/fs.h>
  25. #include <linux/miscdevice.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/io.h>
  28. enum tpm_timeout {
  29. TPM_TIMEOUT = 5, /* msecs */
  30. };
  31. /* TPM addresses */
  32. enum tpm_addr {
  33. TPM_SUPERIO_ADDR = 0x2E,
  34. TPM_ADDR = 0x4E,
  35. };
  36. extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr,
  37. char *);
  38. extern ssize_t tpm_show_pcrs(struct device *, struct device_attribute *attr,
  39. char *);
  40. extern ssize_t tpm_show_caps(struct device *, struct device_attribute *attr,
  41. char *);
  42. extern ssize_t tpm_show_caps_1_2(struct device *, struct device_attribute *attr,
  43. char *);
  44. extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
  45. const char *, size_t);
  46. extern ssize_t tpm_show_enabled(struct device *, struct device_attribute *attr,
  47. char *);
  48. extern ssize_t tpm_show_active(struct device *, struct device_attribute *attr,
  49. char *);
  50. extern ssize_t tpm_show_owned(struct device *, struct device_attribute *attr,
  51. char *);
  52. extern ssize_t tpm_show_temp_deactivated(struct device *,
  53. struct device_attribute *attr, char *);
  54. struct tpm_chip;
  55. struct tpm_vendor_specific {
  56. const u8 req_complete_mask;
  57. const u8 req_complete_val;
  58. const u8 req_canceled;
  59. void __iomem *iobase; /* ioremapped address */
  60. unsigned long base; /* TPM base address */
  61. int irq;
  62. int region_size;
  63. int have_region;
  64. int (*recv) (struct tpm_chip *, u8 *, size_t);
  65. int (*send) (struct tpm_chip *, u8 *, size_t);
  66. void (*cancel) (struct tpm_chip *);
  67. u8 (*status) (struct tpm_chip *);
  68. struct miscdevice miscdev;
  69. struct attribute_group *attr_group;
  70. struct list_head list;
  71. int locality;
  72. unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
  73. unsigned long duration[3]; /* jiffies */
  74. wait_queue_head_t read_queue;
  75. wait_queue_head_t int_queue;
  76. };
  77. struct tpm_chip {
  78. struct device *dev; /* Device stuff */
  79. int dev_num; /* /dev/tpm# */
  80. int num_opens; /* only one allowed */
  81. int time_expired;
  82. /* Data passed to and from the tpm via the read/write calls */
  83. u8 *data_buffer;
  84. atomic_t data_pending;
  85. struct semaphore buffer_mutex;
  86. struct timer_list user_read_timer; /* user needs to claim result */
  87. struct work_struct work;
  88. struct semaphore tpm_mutex; /* tpm is processing */
  89. struct tpm_vendor_specific vendor;
  90. struct dentry **bios_dir;
  91. struct list_head list;
  92. };
  93. #define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
  94. static inline int tpm_read_index(int base, int index)
  95. {
  96. outb(index, base);
  97. return inb(base+1) & 0xFF;
  98. }
  99. static inline void tpm_write_index(int base, int index, int value)
  100. {
  101. outb(index, base);
  102. outb(value & 0xFF, base+1);
  103. }
  104. extern void tpm_get_timeouts(struct tpm_chip *);
  105. extern void tpm_gen_interrupt(struct tpm_chip *);
  106. extern void tpm_continue_selftest(struct tpm_chip *);
  107. extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
  108. extern struct tpm_chip* tpm_register_hardware(struct device *,
  109. const struct tpm_vendor_specific *);
  110. extern int tpm_open(struct inode *, struct file *);
  111. extern int tpm_release(struct inode *, struct file *);
  112. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  113. loff_t *);
  114. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  115. extern void tpm_remove_hardware(struct device *);
  116. extern int tpm_pm_suspend(struct device *, pm_message_t);
  117. extern int tpm_pm_resume(struct device *);
  118. #ifdef CONFIG_ACPI
  119. extern struct dentry ** tpm_bios_log_setup(char *);
  120. extern void tpm_bios_log_teardown(struct dentry **);
  121. #else
  122. static inline struct dentry ** tpm_bios_log_setup(char *name)
  123. {
  124. return NULL;
  125. }
  126. static inline void tpm_bios_log_teardown(struct dentry **dir)
  127. {
  128. }
  129. #endif