tpm.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. 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. void __iomem *iobase; /* ioremapped address */
  49. unsigned long base; /* TPM base address */
  50. int region_size;
  51. int have_region;
  52. int (*recv) (struct tpm_chip *, u8 *, size_t);
  53. int (*send) (struct tpm_chip *, u8 *, size_t);
  54. void (*cancel) (struct tpm_chip *);
  55. u8 (*status) (struct tpm_chip *);
  56. struct miscdevice miscdev;
  57. struct attribute_group *attr_group;
  58. };
  59. struct tpm_chip {
  60. struct device *dev; /* Device stuff */
  61. int dev_num; /* /dev/tpm# */
  62. int num_opens; /* only one allowed */
  63. int time_expired;
  64. /* Data passed to and from the tpm via the read/write calls */
  65. u8 *data_buffer;
  66. atomic_t data_pending;
  67. struct semaphore buffer_mutex;
  68. struct timer_list user_read_timer; /* user needs to claim result */
  69. struct semaphore tpm_mutex; /* tpm is processing */
  70. struct tpm_vendor_specific *vendor;
  71. struct list_head list;
  72. };
  73. static inline int tpm_read_index(int base, int index)
  74. {
  75. outb(index, base);
  76. return inb(base+1) & 0xFF;
  77. }
  78. static inline void tpm_write_index(int base, int index, int value)
  79. {
  80. outb(index, base);
  81. outb(value & 0xFF, base+1);
  82. }
  83. extern int tpm_register_hardware(struct device *,
  84. struct tpm_vendor_specific *);
  85. extern int tpm_open(struct inode *, struct file *);
  86. extern int tpm_release(struct inode *, struct file *);
  87. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  88. loff_t *);
  89. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  90. extern void tpm_remove_hardware(struct device *);
  91. extern int tpm_pm_suspend(struct device *, pm_message_t);
  92. extern int tpm_pm_resume(struct device *);