blob: ad51c6538034ed73c8c8575cc5864215ea460956 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/pci.h>
23#include <linux/delay.h>
24#include <linux/fs.h>
25#include <linux/miscdevice.h>
Al Virobbc5b212005-11-01 15:14:05 +000026#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Kylene Hall3122a882005-06-23 22:01:48 -070028enum tpm_timeout {
29 TPM_TIMEOUT = 5, /* msecs */
30};
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32/* TPM addresses */
Kylene Hall3122a882005-06-23 22:01:48 -070033enum tpm_addr {
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070034 TPM_SUPERIO_ADDR = 0x2E,
Kylene Hall3122a882005-06-23 22:01:48 -070035 TPM_ADDR = 0x4E,
Kylene Hall3122a882005-06-23 22:01:48 -070036};
37
Kylene Hall6659ca22005-06-23 22:02:00 -070038extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr,
39 char *);
40extern ssize_t tpm_show_pcrs(struct device *, struct device_attribute *attr,
41 char *);
42extern ssize_t tpm_show_caps(struct device *, struct device_attribute *attr,
43 char *);
44extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
45 const char *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
47struct tpm_chip;
48
49struct tpm_vendor_specific {
50 u8 req_complete_mask;
51 u8 req_complete_val;
Kylene Halld9e5b6b2005-06-23 22:02:02 -070052 u8 req_canceled;
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -080053 void __iomem *iobase; /* ioremapped address */
54 unsigned long base; /* TPM base address */
55
56 int region_size;
57 int have_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 int (*recv) (struct tpm_chip *, u8 *, size_t);
60 int (*send) (struct tpm_chip *, u8 *, size_t);
61 void (*cancel) (struct tpm_chip *);
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -080062 u8 (*status) (struct tpm_chip *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 struct miscdevice miscdev;
Kylene Hall6659ca22005-06-23 22:02:00 -070064 struct attribute_group *attr_group;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
67struct tpm_chip {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -080068 struct device *dev; /* Device stuff */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 int dev_num; /* /dev/tpm# */
71 int num_opens; /* only one allowed */
72 int time_expired;
73
74 /* Data passed to and from the tpm via the read/write calls */
75 u8 *data_buffer;
76 atomic_t data_pending;
77 struct semaphore buffer_mutex;
78
79 struct timer_list user_read_timer; /* user needs to claim result */
80 struct semaphore tpm_mutex; /* tpm is processing */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82 struct tpm_vendor_specific *vendor;
83
84 struct list_head list;
85};
86
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070087static inline int tpm_read_index(int base, int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070089 outb(index, base);
90 return inb(base+1) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091}
92
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070093static inline void tpm_write_index(int base, int index, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070095 outb(index, base);
96 outb(value & 0xFF, base+1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Kylene Jo Halle659a3f2005-10-30 15:03:24 -080099extern int tpm_register_hardware(struct device *,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 struct tpm_vendor_specific *);
101extern int tpm_open(struct inode *, struct file *);
102extern int tpm_release(struct inode *, struct file *);
103extern ssize_t tpm_write(struct file *, const char __user *, size_t,
104 loff_t *);
105extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800106extern void tpm_remove_hardware(struct device *);
Kylene Jo Hallce2c87d2005-10-30 15:03:25 -0800107extern int tpm_pm_suspend(struct device *, pm_message_t);
108extern int tpm_pm_resume(struct device *);