2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 IBM Corporation
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Leendert van Doorn <leendert@watson.ibm.com>
|
|
|
|
* Dave Safford <safford@watson.ibm.com>
|
|
|
|
* Reiner Sailer <sailer@watson.ibm.com>
|
|
|
|
* Kylene Hall <kjhall@us.ibm.com>
|
|
|
|
*
|
|
|
|
* Maintained by: <tpmdd_devel@lists.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Device driver for TCG/TCPA TPM (trusted platform module).
|
|
|
|
* Specifications at www.trustedcomputinggroup.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation, version 2 of the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-11-01 15:44:28 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "tpm.h"
|
|
|
|
|
|
|
|
/* Atmel definitions */
|
2005-06-24 13:02:06 +08:00
|
|
|
enum tpm_atmel_addr {
|
|
|
|
TPM_ATMEL_BASE_ADDR_LO = 0x08,
|
|
|
|
TPM_ATMEL_BASE_ADDR_HI = 0x09
|
2005-06-24 13:01:48 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* write status bits */
|
2005-06-24 13:01:48 +08:00
|
|
|
enum tpm_atmel_write_status {
|
|
|
|
ATML_STATUS_ABORT = 0x01,
|
|
|
|
ATML_STATUS_LASTBYTE = 0x04
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
/* read status bits */
|
2005-06-24 13:01:48 +08:00
|
|
|
enum tpm_atmel_read_status {
|
|
|
|
ATML_STATUS_BUSY = 0x01,
|
|
|
|
ATML_STATUS_DATA_AVAIL = 0x02,
|
|
|
|
ATML_STATUS_REWRITE = 0x04,
|
|
|
|
ATML_STATUS_READY = 0x08
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:28 +08:00
|
|
|
static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
u8 status, *hdr = buf;
|
|
|
|
u32 size;
|
|
|
|
int i;
|
|
|
|
__be32 *native_size;
|
|
|
|
|
|
|
|
/* start reading header */
|
|
|
|
if (count < 6)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
status = inb(chip->vendor->base + 1);
|
|
|
|
if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
|
2005-10-31 07:03:24 +08:00
|
|
|
dev_err(chip->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"error reading header\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
*buf++ = inb(chip->vendor->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* size of the data received */
|
|
|
|
native_size = (__force __be32 *) (hdr + 2);
|
|
|
|
size = be32_to_cpu(*native_size);
|
|
|
|
|
|
|
|
if (count < size) {
|
2005-10-31 07:03:24 +08:00
|
|
|
dev_err(chip->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"Recv size(%d) less than available space\n", size);
|
|
|
|
for (; i < size; i++) { /* clear the waiting data anyway */
|
|
|
|
status = inb(chip->vendor->base + 1);
|
|
|
|
if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
|
2005-10-31 07:03:24 +08:00
|
|
|
dev_err(chip->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"error reading data\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read all the data available */
|
|
|
|
for (; i < size; i++) {
|
|
|
|
status = inb(chip->vendor->base + 1);
|
|
|
|
if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
|
2005-10-31 07:03:24 +08:00
|
|
|
dev_err(chip->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"error reading data\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
*buf++ = inb(chip->vendor->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure data available is gone */
|
|
|
|
status = inb(chip->vendor->base + 1);
|
|
|
|
if (status & ATML_STATUS_DATA_AVAIL) {
|
2005-10-31 07:03:24 +08:00
|
|
|
dev_err(chip->dev, "data available is stuck\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2005-10-31 07:03:28 +08:00
|
|
|
static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2005-10-31 07:03:24 +08:00
|
|
|
dev_dbg(chip->dev, "tpm_atml_send:\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < count; i++) {
|
2005-10-31 07:03:24 +08:00
|
|
|
dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
outb(buf[i], chip->vendor->base);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_atml_cancel(struct tpm_chip *chip)
|
|
|
|
{
|
|
|
|
outb(ATML_STATUS_ABORT, chip->vendor->base + 1);
|
|
|
|
}
|
|
|
|
|
2005-10-31 07:03:23 +08:00
|
|
|
static u8 tpm_atml_status(struct tpm_chip *chip)
|
|
|
|
{
|
|
|
|
return inb(chip->vendor->base + 1);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct file_operations atmel_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.open = tpm_open,
|
|
|
|
.read = tpm_read,
|
|
|
|
.write = tpm_write,
|
|
|
|
.release = tpm_release,
|
|
|
|
};
|
|
|
|
|
2005-06-24 13:02:00 +08:00
|
|
|
static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
|
|
|
|
static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
|
|
|
|
static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
|
|
|
|
static DEVICE_ATTR(cancel, S_IWUSR |S_IWGRP, NULL, tpm_store_cancel);
|
|
|
|
|
|
|
|
static struct attribute* atmel_attrs[] = {
|
|
|
|
&dev_attr_pubek.attr,
|
|
|
|
&dev_attr_pcrs.attr,
|
|
|
|
&dev_attr_caps.attr,
|
|
|
|
&dev_attr_cancel.attr,
|
2005-10-31 07:03:29 +08:00
|
|
|
NULL,
|
2005-06-24 13:02:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs };
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct tpm_vendor_specific tpm_atmel = {
|
|
|
|
.recv = tpm_atml_recv,
|
|
|
|
.send = tpm_atml_send,
|
|
|
|
.cancel = tpm_atml_cancel,
|
2005-10-31 07:03:23 +08:00
|
|
|
.status = tpm_atml_status,
|
2005-04-17 06:20:36 +08:00
|
|
|
.req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
|
|
|
|
.req_complete_val = ATML_STATUS_DATA_AVAIL,
|
2005-06-24 13:02:02 +08:00
|
|
|
.req_canceled = ATML_STATUS_READY,
|
2005-06-24 13:02:00 +08:00
|
|
|
.attr_group = &atmel_attr_grp,
|
2005-04-17 06:20:36 +08:00
|
|
|
.miscdev = { .fops = &atmel_ops, },
|
|
|
|
};
|
|
|
|
|
2005-10-31 07:03:28 +08:00
|
|
|
static struct platform_device *pdev;
|
2005-10-31 07:03:25 +08:00
|
|
|
|
|
|
|
static void __devexit tpm_atml_remove(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tpm_chip *chip = dev_get_drvdata(dev);
|
2005-10-31 07:03:28 +08:00
|
|
|
if (chip) {
|
2005-10-31 07:03:25 +08:00
|
|
|
release_region(chip->vendor->base, 2);
|
|
|
|
tpm_remove_hardware(chip->dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct device_driver atml_drv = {
|
|
|
|
.name = "tpm_atmel",
|
|
|
|
.bus = &platform_bus_type,
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.suspend = tpm_pm_suspend,
|
|
|
|
.resume = tpm_pm_resume,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init init_atmel(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rc = 0;
|
2005-06-24 13:02:06 +08:00
|
|
|
int lo, hi;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:25 +08:00
|
|
|
driver_register(&atml_drv);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-26 05:55:39 +08:00
|
|
|
lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
|
|
|
|
hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
|
2005-06-24 13:02:06 +08:00
|
|
|
|
|
|
|
tpm_atmel.base = (hi<<8)|lo;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* verify that it is an Atmel part */
|
2005-06-26 05:55:39 +08:00
|
|
|
if (tpm_read_index(TPM_ADDR, 4) != 'A' || tpm_read_index(TPM_ADDR, 5) != 'T'
|
|
|
|
|| tpm_read_index(TPM_ADDR, 6) != 'M' || tpm_read_index(TPM_ADDR, 7) != 'L') {
|
2005-10-31 07:03:25 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-10-31 07:03:25 +08:00
|
|
|
/* verify chip version number is 1.1 */
|
|
|
|
if ( (tpm_read_index(TPM_ADDR, 0x00) != 0x01) ||
|
|
|
|
(tpm_read_index(TPM_ADDR, 0x01) != 0x01 ))
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:28 +08:00
|
|
|
pdev = kzalloc(sizeof(struct platform_device), GFP_KERNEL);
|
2005-10-31 07:03:25 +08:00
|
|
|
if ( !pdev )
|
|
|
|
return -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:25 +08:00
|
|
|
pdev->name = "tpm_atmel0";
|
|
|
|
pdev->id = -1;
|
|
|
|
pdev->num_resources = 0;
|
|
|
|
pdev->dev.release = tpm_atml_remove;
|
|
|
|
pdev->dev.driver = &atml_drv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:28 +08:00
|
|
|
if ((rc = platform_device_register(pdev)) < 0) {
|
2005-10-31 07:03:25 +08:00
|
|
|
kfree(pdev);
|
|
|
|
pdev = NULL;
|
|
|
|
return rc;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:25 +08:00
|
|
|
if (request_region(tpm_atmel.base, 2, "tpm_atmel0") == NULL ) {
|
|
|
|
platform_device_unregister(pdev);
|
|
|
|
kfree(pdev);
|
|
|
|
pdev = NULL;
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:25 +08:00
|
|
|
if ((rc = tpm_register_hardware(&pdev->dev, &tpm_atmel)) < 0) {
|
|
|
|
release_region(tpm_atmel.base, 2);
|
|
|
|
platform_device_unregister(pdev);
|
|
|
|
kfree(pdev);
|
|
|
|
pdev = NULL;
|
|
|
|
return rc;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:28 +08:00
|
|
|
dev_info(&pdev->dev, "Atmel TPM 1.1, Base Address: 0x%x\n",
|
|
|
|
tpm_atmel.base);
|
2005-10-31 07:03:25 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cleanup_atmel(void)
|
|
|
|
{
|
2005-10-31 07:03:25 +08:00
|
|
|
if (pdev) {
|
|
|
|
tpm_atml_remove(&pdev->dev);
|
|
|
|
platform_device_unregister(pdev);
|
|
|
|
kfree(pdev);
|
|
|
|
pdev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
driver_unregister(&atml_drv);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_atmel);
|
|
|
|
module_exit(cleanup_atmel);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
|
|
|
|
MODULE_DESCRIPTION("TPM Driver");
|
|
|
|
MODULE_VERSION("2.0");
|
|
|
|
MODULE_LICENSE("GPL");
|