tpm.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/version.h>
  23. #include <linux/pci.h>
  24. #include <linux/delay.h>
  25. #include <linux/fs.h>
  26. #include <linux/miscdevice.h>
  27. enum tpm_timeout {
  28. TPM_TIMEOUT = 5, /* msecs */
  29. };
  30. /* TPM addresses */
  31. enum tpm_addr {
  32. TPM_SUPERIO_ADDR = 0x2E,
  33. TPM_ADDR = 0x4E,
  34. };
  35. extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr,
  36. char *);
  37. extern ssize_t tpm_show_pcrs(struct device *, struct device_attribute *attr,
  38. char *);
  39. extern ssize_t tpm_show_caps(struct device *, struct device_attribute *attr,
  40. char *);
  41. extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
  42. const char *, size_t);
  43. struct tpm_chip;
  44. struct tpm_vendor_specific {
  45. u8 req_complete_mask;
  46. u8 req_complete_val;
  47. u8 req_canceled;
  48. u16 base; /* TPM base address */
  49. int (*recv) (struct tpm_chip *, u8 *, size_t);
  50. int (*send) (struct tpm_chip *, u8 *, size_t);
  51. void (*cancel) (struct tpm_chip *);
  52. struct miscdevice miscdev;
  53. struct attribute_group *attr_group;
  54. };
  55. struct tpm_chip {
  56. struct pci_dev *pci_dev; /* PCI device stuff */
  57. int dev_num; /* /dev/tpm# */
  58. int num_opens; /* only one allowed */
  59. int time_expired;
  60. /* Data passed to and from the tpm via the read/write calls */
  61. u8 *data_buffer;
  62. atomic_t data_pending;
  63. struct semaphore buffer_mutex;
  64. struct timer_list user_read_timer; /* user needs to claim result */
  65. struct semaphore tpm_mutex; /* tpm is processing */
  66. struct tpm_vendor_specific *vendor;
  67. struct list_head list;
  68. };
  69. static inline int tpm_read_index(int base, int index)
  70. {
  71. outb(index, base);
  72. return inb(base+1) & 0xFF;
  73. }
  74. static inline void tpm_write_index(int base, int index, int value)
  75. {
  76. outb(index, base);
  77. outb(value & 0xFF, base+1);
  78. }
  79. extern int tpm_register_hardware(struct pci_dev *,
  80. struct tpm_vendor_specific *);
  81. extern int tpm_open(struct inode *, struct file *);
  82. extern int tpm_release(struct inode *, struct file *);
  83. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  84. loff_t *);
  85. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  86. extern void __devexit tpm_remove(struct pci_dev *);
  87. extern int tpm_pm_suspend(struct pci_dev *, pm_message_t);
  88. extern int tpm_pm_resume(struct pci_dev *);