blob: 4f005345bf3794f3d293f080e11118b3d20dd518 [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>
Andrew Morton276ad0c2006-03-25 03:07:35 -080027#include <linux/io.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 {
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -070051 const u8 req_complete_mask;
52 const u8 req_complete_val;
53 const u8 req_canceled;
Kylene Jo Hallad5ea3c2005-11-13 16:07:41 -080054 void __iomem *iobase; /* ioremapped address */
55 unsigned long base; /* TPM base address */
56
57 int region_size;
58 int have_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 int (*recv) (struct tpm_chip *, u8 *, size_t);
61 int (*send) (struct tpm_chip *, u8 *, size_t);
62 void (*cancel) (struct tpm_chip *);
Kylene Jo Hallb4ed3e32005-10-30 15:03:23 -080063 u8 (*status) (struct tpm_chip *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 struct miscdevice miscdev;
Kylene Hall6659ca22005-06-23 22:02:00 -070065 struct attribute_group *attr_group;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066};
67
68struct tpm_chip {
Kylene Jo Halle659a3f2005-10-30 15:03:24 -080069 struct device *dev; /* Device stuff */
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71 int dev_num; /* /dev/tpm# */
72 int num_opens; /* only one allowed */
73 int time_expired;
74
75 /* Data passed to and from the tpm via the read/write calls */
76 u8 *data_buffer;
77 atomic_t data_pending;
78 struct semaphore buffer_mutex;
79
80 struct timer_list user_read_timer; /* user needs to claim result */
Kylene Jo Hall09e12f92005-11-13 16:07:43 -080081 struct work_struct work;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 struct semaphore tpm_mutex; /* tpm is processing */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Kylene Jo Hall90dda522006-04-22 02:37:15 -070084 struct tpm_vendor_specific vendor;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -080086 struct dentry **bios_dir;
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 struct list_head list;
89};
90
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070091static inline int tpm_read_index(int base, int index)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070093 outb(index, base);
94 return inb(base+1) & 0xFF;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
96
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070097static inline void tpm_write_index(int base, int index, int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
Kylene Jo Halldaacdfa2005-06-25 14:55:39 -070099 outb(index, base);
100 outb(value & 0xFF, base+1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
Kylene Jo Halle0dd03c2006-04-22 02:37:26 -0700103extern struct tpm_chip* tpm_register_hardware(struct device *,
104 const struct tpm_vendor_specific *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern int tpm_open(struct inode *, struct file *);
106extern int tpm_release(struct inode *, struct file *);
107extern ssize_t tpm_write(struct file *, const char __user *, size_t,
108 loff_t *);
109extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
Kylene Jo Halle659a3f2005-10-30 15:03:24 -0800110extern void tpm_remove_hardware(struct device *);
Kylene Jo Hallce2c87d2005-10-30 15:03:25 -0800111extern int tpm_pm_suspend(struct device *, pm_message_t);
112extern int tpm_pm_resume(struct device *);
Kylene Jo Hall55a82ab2006-01-08 01:03:15 -0800113
114#ifdef CONFIG_ACPI
115extern struct dentry ** tpm_bios_log_setup(char *);
116extern void tpm_bios_log_teardown(struct dentry **);
117#else
118static inline struct dentry* tpm_bios_log_setup(char *name)
119{
120 return NULL;
121}
122static inline void tpm_bios_log_teardown(struct dentry **dir)
123{
124}
125#endif