Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
700d8bdc | 28 | #define TPM_TIMEOUT 5 /* msecs */ |
1da177e4 LT |
29 | |
30 | /* TPM addresses */ | |
31 | #define TPM_ADDR 0x4E | |
32 | #define TPM_DATA 0x4F | |
33 | ||
34 | struct tpm_chip; | |
35 | ||
36 | struct 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 | ||
47 | struct 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 | ||
69 | static inline int tpm_read_index(int index) | |
70 | { | |
71 | outb(index, TPM_ADDR); | |
72 | return inb(TPM_DATA) & 0xFF; | |
73 | } | |
74 | ||
75 | static inline void tpm_write_index(int index, int value) | |
76 | { | |
77 | outb(index, TPM_ADDR); | |
78 | outb(value & 0xFF, TPM_DATA); | |
79 | } | |
80 | ||
1da177e4 LT |
81 | extern int tpm_lpc_bus_init(struct pci_dev *, u16); |
82 | ||
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, | |
88 | loff_t *); | |
89 | extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *); | |
90 | extern void __devexit tpm_remove(struct pci_dev *); | |
4fd416c1 | 91 | extern int tpm_pm_suspend(struct pci_dev *, pm_message_t); |
1da177e4 | 92 | extern int tpm_pm_resume(struct pci_dev *); |