tpm.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 region_size;
  62. int have_region;
  63. int (*recv) (struct tpm_chip *, u8 *, size_t);
  64. int (*send) (struct tpm_chip *, u8 *, size_t);
  65. void (*cancel) (struct tpm_chip *);
  66. u8 (*status) (struct tpm_chip *);
  67. struct miscdevice miscdev;
  68. struct attribute_group *attr_group;
  69. u32 timeout_a, timeout_b, timeout_c, timeout_d;
  70. u32 duration[3];
  71. };
  72. struct tpm_chip {
  73. struct device *dev; /* Device stuff */
  74. int dev_num; /* /dev/tpm# */
  75. int num_opens; /* only one allowed */
  76. int time_expired;
  77. /* Data passed to and from the tpm via the read/write calls */
  78. u8 *data_buffer;
  79. atomic_t data_pending;
  80. struct semaphore buffer_mutex;
  81. struct timer_list user_read_timer; /* user needs to claim result */
  82. struct work_struct work;
  83. struct semaphore tpm_mutex; /* tpm is processing */
  84. struct tpm_vendor_specific vendor;
  85. struct dentry **bios_dir;
  86. struct list_head list;
  87. };
  88. static inline int tpm_read_index(int base, int index)
  89. {
  90. outb(index, base);
  91. return inb(base+1) & 0xFF;
  92. }
  93. static inline void tpm_write_index(int base, int index, int value)
  94. {
  95. outb(index, base);
  96. outb(value & 0xFF, base+1);
  97. }
  98. extern void tpm_get_timeouts(struct tpm_chip *);
  99. extern void tpm_gen_interrupt(struct tpm_chip *);
  100. extern void tpm_continue_selftest(struct tpm_chip *);
  101. extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
  102. extern struct tpm_chip* tpm_register_hardware(struct device *,
  103. const struct tpm_vendor_specific *);
  104. extern int tpm_open(struct inode *, struct file *);
  105. extern int tpm_release(struct inode *, struct file *);
  106. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  107. loff_t *);
  108. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  109. extern void tpm_remove_hardware(struct device *);
  110. extern int tpm_pm_suspend(struct device *, pm_message_t);
  111. extern int tpm_pm_resume(struct device *);
  112. #ifdef CONFIG_ACPI
  113. extern struct dentry ** tpm_bios_log_setup(char *);
  114. extern void tpm_bios_log_teardown(struct dentry **);
  115. #else
  116. static inline struct dentry* tpm_bios_log_setup(char *name)
  117. {
  118. return NULL;
  119. }
  120. static inline void tpm_bios_log_teardown(struct dentry **dir)
  121. {
  122. }
  123. #endif