blob: 99a60496ecc65e3fb1e8907213ae00367bc2a423 [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>
Al Virobbc5b212005-11-01 15:14:05 +000027#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Kylene Hall3122a882005-06-23 22:01:48 -070029enum tpm_timeout {
30 TPM_TIMEOUT = 5, /* msecs */
31};
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33/* TPM addresses */
Kylene Hall3122a882005-06-23 22:01:48 -070034enum tpm_addr {
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070035 TPM_SUPERIO_ADDR = 0x2E,
Kylene Hall3122a882005-06-23 22:01:48 -070036 TPM_ADDR = 0x4E,
Kylene Hall3122a882005-06-23 22:01:48 -070037};
38
Kylene Hall6659ca22005-06-23 22:02:00 -070039extern ssize_t tpm_show_pubek(struct device *, struct device_attribute *attr,
40 char *);
41extern ssize_t tpm_show_pcrs(struct device *, struct device_attribute *attr,
42 char *);
43extern ssize_t tpm_show_caps(struct device *, struct device_attribute *attr,
44 char *);
45extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
46 const char *, size_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48struct tpm_chip;
49
50struct tpm_vendor_specific {
51 u8 req_complete_mask;
52 u8 req_complete_val;
Kylene Halld9e5b6b2005-06-23 22:02:02 -070053 u8 req_canceled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 u16 base; /* TPM base address */
55
56 int (*recv) (struct tpm_chip *, u8 *, size_t);
57 int (*send) (struct tpm_chip *, u8 *, size_t);
58 void (*cancel) (struct tpm_chip *);
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -080059 u8 (*status) (struct tpm_chip *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 struct miscdevice miscdev;
Kylene Hall6659ca22005-06-23 22:02:00 -070061 struct attribute_group *attr_group;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
64struct tpm_chip {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -080065 struct device *dev; /* Device stuff */
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 int dev_num; /* /dev/tpm# */
68 int num_opens; /* only one allowed */
69 int time_expired;
70
71 /* Data passed to and from the tpm via the read/write calls */
72 u8 *data_buffer;
73 atomic_t data_pending;
74 struct semaphore buffer_mutex;
75
76 struct timer_list user_read_timer; /* user needs to claim result */
77 struct semaphore tpm_mutex; /* tpm is processing */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 struct tpm_vendor_specific *vendor;
80
81 struct list_head list;
82};
83
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070084static inline int tpm_read_index(int base, int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070086 outb(index, base);
87 return inb(base+1) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088}
89
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070090static inline void tpm_write_index(int base, int index, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070092 outb(index, base);
93 outb(value & 0xFF, base+1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
Kylene Jo Halle659a3f2005-10-30 15:03:24 -080096extern int tpm_register_hardware(struct device *,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 struct tpm_vendor_specific *);
98extern int tpm_open(struct inode *, struct file *);
99extern int tpm_release(struct inode *, struct file *);
100extern ssize_t tpm_write(struct file *, const char __user *, size_t,
101 loff_t *);
102extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800103extern void tpm_remove_hardware(struct device *);
Kylene Jo Hallce2c87d2005-10-30 15:03:25 -0800104extern int tpm_pm_suspend(struct device *, pm_message_t);
105extern int tpm_pm_resume(struct device *);