tpm.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 work_struct work;
  70. struct semaphore tpm_mutex; /* tpm is processing */
  71. struct tpm_vendor_specific *vendor;
  72. struct dentry **bios_dir;
  73. struct list_head list;
  74. };
  75. static inline int tpm_read_index(int base, int index)
  76. {
  77. outb(index, base);
  78. return inb(base+1) & 0xFF;
  79. }
  80. static inline void tpm_write_index(int base, int index, int value)
  81. {
  82. outb(index, base);
  83. outb(value & 0xFF, base+1);
  84. }
  85. extern int tpm_register_hardware(struct device *,
  86. struct tpm_vendor_specific *);
  87. extern int tpm_open(struct inode *, struct file *);
  88. extern int tpm_release(struct inode *, struct file *);
  89. extern ssize_t tpm_write(struct file *, const char __user *, size_t,
  90. loff_t *);
  91. extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
  92. extern void tpm_remove_hardware(struct device *);
  93. extern int tpm_pm_suspend(struct device *, pm_message_t);
  94. extern int tpm_pm_resume(struct device *);
  95. #ifdef CONFIG_ACPI
  96. extern struct dentry ** tpm_bios_log_setup(char *);
  97. extern void tpm_bios_log_teardown(struct dentry **);
  98. #else
  99. static inline struct dentry* tpm_bios_log_setup(char *name)
  100. {
  101. return NULL;
  102. }
  103. static inline void tpm_bios_log_teardown(struct dentry **dir)
  104. {
  105. }
  106. #endif