tpm.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #define TPM_TIMEOUT msecs_to_jiffies(5)
  28. /* TPM addresses */
  29. #define TPM_ADDR 0x4E
  30. #define TPM_DATA 0x4F
  31. struct tpm_chip;
  32. struct tpm_vendor_specific {
  33. u8 req_complete_mask;
  34. u8 req_complete_val;
  35. u16 base; /* TPM base address */
  36. int (*recv) (struct tpm_chip *, u8 *, size_t);
  37. int (*send) (struct tpm_chip *, u8 *, size_t);
  38. void (*cancel) (struct tpm_chip *);
  39. struct miscdevice miscdev;
  40. };
  41. struct tpm_chip {
  42. struct pci_dev *pci_dev; /* PCI device stuff */
  43. int dev_num; /* /dev/tpm# */
  44. int num_opens; /* only one allowed */
  45. int time_expired;
  46. /* Data passed to and from the tpm via the read/write calls */
  47. u8 *data_buffer;
  48. atomic_t data_pending;
  49. struct semaphore buffer_mutex;
  50. struct timer_list user_read_timer; /* user needs to claim result */
  51. struct semaphore tpm_mutex; /* tpm is processing */
  52. struct timer_list device_timer; /* tpm is processing */
  53. struct semaphore timer_manipulation_mutex;
  54. struct tpm_vendor_specific *vendor;
  55. struct list_head list;
  56. };
  57. static inline int tpm_read_index(int index)
  58. {
  59. outb(index, TPM_ADDR);
  60. return inb(TPM_DATA) & 0xFF;
  61. }
  62. static inline void tpm_write_index(int index, int value)
  63. {
  64. outb(index, TPM_ADDR);
  65. outb(value & 0xFF, TPM_DATA);
  66. }
  67. extern void tpm_time_expired(unsigned long);
  68. extern int tpm_lpc_bus_init(struct pci_dev *, u16);
  69. extern int tpm_register_hardware(struct pci_dev *,
  70. struct tpm_vendor_specific *);
  71. extern int tpm_open(struct inode *, struct file *);
  72. extern int tpm_release(struct inode *, struct file *);
  73. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  74. loff_t *);
  75. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  76. extern void __devexit tpm_remove(struct pci_dev *);
  77. extern int tpm_pm_suspend(struct pci_dev *, pm_message_t);
  78. extern int tpm_pm_resume(struct pci_dev *);