tpm.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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_store_cancel(struct device *, struct device_attribute *attr,
  43. const char *, size_t);
  44. struct tpm_chip;
  45. struct tpm_vendor_specific {
  46. u8 req_complete_mask;
  47. u8 req_complete_val;
  48. u8 req_canceled;
  49. void __iomem *iobase; /* ioremapped address */
  50. unsigned long base; /* TPM base address */
  51. int region_size;
  52. int have_region;
  53. int (*recv) (struct tpm_chip *, u8 *, size_t);
  54. int (*send) (struct tpm_chip *, u8 *, size_t);
  55. void (*cancel) (struct tpm_chip *);
  56. u8 (*status) (struct tpm_chip *);
  57. struct miscdevice miscdev;
  58. struct attribute_group *attr_group;
  59. };
  60. struct tpm_chip {
  61. struct device *dev; /* Device stuff */
  62. int dev_num; /* /dev/tpm# */
  63. int num_opens; /* only one allowed */
  64. int time_expired;
  65. /* Data passed to and from the tpm via the read/write calls */
  66. u8 *data_buffer;
  67. atomic_t data_pending;
  68. struct semaphore buffer_mutex;
  69. struct timer_list user_read_timer; /* user needs to claim result */
  70. struct work_struct work;
  71. struct semaphore tpm_mutex; /* tpm is processing */
  72. struct tpm_vendor_specific *vendor;
  73. struct dentry **bios_dir;
  74. struct list_head list;
  75. };
  76. static inline int tpm_read_index(int base, int index)
  77. {
  78. outb(index, base);
  79. return inb(base+1) & 0xFF;
  80. }
  81. static inline void tpm_write_index(int base, int index, int value)
  82. {
  83. outb(index, base);
  84. outb(value & 0xFF, base+1);
  85. }
  86. extern int tpm_register_hardware(struct device *,
  87. struct tpm_vendor_specific *);
  88. extern int tpm_open(struct inode *, struct file *);
  89. extern int tpm_release(struct inode *, struct file *);
  90. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  91. loff_t *);
  92. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  93. extern void tpm_remove_hardware(struct device *);
  94. extern int tpm_pm_suspend(struct device *, pm_message_t);
  95. extern int tpm_pm_resume(struct device *);
  96. #ifdef CONFIG_ACPI
  97. extern struct dentry ** tpm_bios_log_setup(char *);
  98. extern void tpm_bios_log_teardown(struct dentry **);
  99. #else
  100. static inline struct dentry* tpm_bios_log_setup(char *name)
  101. {
  102. return NULL;
  103. }
  104. static inline void tpm_bios_log_teardown(struct dentry **dir)
  105. {
  106. }
  107. #endif