2 * Copyright (C) 2004 IBM Corporation
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>
10 * Maintained by: <tpmdd_devel@lists.sourceforge.net>
12 * Device driver for TCG/TCPA TPM (trusted platform module).
13 * Specifications at www.trustedcomputinggroup.org
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
21 #include <linux/module.h>
22 #include <linux/version.h>
23 #include <linux/pci.h>
24 #include <linux/delay.h>
26 #include <linux/miscdevice.h>
28 #define TPM_TIMEOUT 5 /* msecs */
36 struct tpm_vendor_specific {
39 u16 base; /* TPM base address */
41 int (*recv) (struct tpm_chip *, u8 *, size_t);
42 int (*send) (struct tpm_chip *, u8 *, size_t);
43 void (*cancel) (struct tpm_chip *);
44 struct miscdevice miscdev;
48 struct pci_dev *pci_dev; /* PCI device stuff */
50 int dev_num; /* /dev/tpm# */
51 int num_opens; /* only one allowed */
54 /* Data passed to and from the tpm via the read/write calls */
56 atomic_t data_pending;
57 struct semaphore buffer_mutex;
59 struct timer_list user_read_timer; /* user needs to claim result */
60 struct semaphore tpm_mutex; /* tpm is processing */
61 struct timer_list device_timer; /* tpm is processing */
62 struct semaphore timer_manipulation_mutex;
64 struct tpm_vendor_specific *vendor;
66 struct list_head list;
69 static inline int tpm_read_index(int index)
71 outb(index, TPM_ADDR);
72 return inb(TPM_DATA) & 0xFF;
75 static inline void tpm_write_index(int index, int value)
77 outb(index, TPM_ADDR);
78 outb(value & 0xFF, TPM_DATA);
81 extern int tpm_lpc_bus_init(struct pci_dev *, u16);
83 extern int tpm_register_hardware(struct pci_dev *,
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,
89 extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
90 extern void __devexit tpm_remove(struct pci_dev *);
91 extern int tpm_pm_suspend(struct pci_dev *, pm_message_t);
92 extern int tpm_pm_resume(struct pci_dev *);