blob: 575cf5aed41a572286bbc96f942356c72567edac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
28#define TPM_TIMEOUT msecs_to_jiffies(5)
29
30/* TPM addresses */
31#define TPM_ADDR 0x4E
32#define TPM_DATA 0x4F
33
34struct tpm_chip;
35
36struct tpm_vendor_specific {
37 u8 req_complete_mask;
38 u8 req_complete_val;
39 u16 base; /* TPM base address */
40
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;
45};
46
47struct tpm_chip {
48 struct pci_dev *pci_dev; /* PCI device stuff */
49
50 int dev_num; /* /dev/tpm# */
51 int num_opens; /* only one allowed */
52 int time_expired;
53
54 /* Data passed to and from the tpm via the read/write calls */
55 u8 *data_buffer;
56 atomic_t data_pending;
57 struct semaphore buffer_mutex;
58
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;
63
64 struct tpm_vendor_specific *vendor;
65
66 struct list_head list;
67};
68
69static inline int tpm_read_index(int index)
70{
71 outb(index, TPM_ADDR);
72 return inb(TPM_DATA) & 0xFF;
73}
74
75static inline void tpm_write_index(int index, int value)
76{
77 outb(index, TPM_ADDR);
78 outb(value & 0xFF, TPM_DATA);
79}
80
81extern void tpm_time_expired(unsigned long);
82extern int tpm_lpc_bus_init(struct pci_dev *, u16);
83
84extern int tpm_register_hardware(struct pci_dev *,
85 struct tpm_vendor_specific *);
86extern int tpm_open(struct inode *, struct file *);
87extern int tpm_release(struct inode *, struct file *);
88extern ssize_t tpm_write(struct file *, const char __user *, size_t,
89 loff_t *);
90extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
91extern void __devexit tpm_remove(struct pci_dev *);
92extern int tpm_pm_suspend(struct pci_dev *, u32);
93extern int tpm_pm_resume(struct pci_dev *);