tpm.h 2.4 KB

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