2019-06-01 16:08:55 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
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>
|
|
|
|
*
|
2007-08-23 05:01:04 +08:00
|
|
|
* Maintained by: <tpmdd-devel@lists.sourceforge.net>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Device driver for TCG/TCPA TPM (trusted platform module).
|
|
|
|
* Specifications at www.trustedcomputinggroup.org
|
|
|
|
*/
|
|
|
|
|
2005-11-01 15:44:28 +08:00
|
|
|
#include <linux/platform_device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "tpm.h"
|
|
|
|
|
|
|
|
/* National definitions */
|
2005-06-24 13:02:06 +08:00
|
|
|
enum tpm_nsc_addr{
|
|
|
|
TPM_NSC_IRQ = 0x07,
|
|
|
|
TPM_NSC_BASE0_HI = 0x60,
|
|
|
|
TPM_NSC_BASE0_LO = 0x61,
|
|
|
|
TPM_NSC_BASE1_HI = 0x62,
|
|
|
|
TPM_NSC_BASE1_LO = 0x63
|
2005-06-24 13:01:48 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-24 13:01:48 +08:00
|
|
|
enum tpm_nsc_index {
|
|
|
|
NSC_LDN_INDEX = 0x07,
|
|
|
|
NSC_SID_INDEX = 0x20,
|
|
|
|
NSC_LDC_INDEX = 0x30,
|
|
|
|
NSC_DIO_INDEX = 0x60,
|
|
|
|
NSC_CIO_INDEX = 0x62,
|
|
|
|
NSC_IRQ_INDEX = 0x70,
|
|
|
|
NSC_ITS_INDEX = 0x71
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-06-24 13:01:48 +08:00
|
|
|
enum tpm_nsc_status_loc {
|
|
|
|
NSC_STATUS = 0x01,
|
|
|
|
NSC_COMMAND = 0x01,
|
|
|
|
NSC_DATA = 0x00
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* status bits */
|
2005-06-24 13:02:06 +08:00
|
|
|
enum tpm_nsc_status {
|
2005-06-24 13:01:48 +08:00
|
|
|
NSC_STATUS_OBF = 0x01, /* output buffer full */
|
|
|
|
NSC_STATUS_IBF = 0x02, /* input buffer full */
|
|
|
|
NSC_STATUS_F0 = 0x04, /* F0 */
|
|
|
|
NSC_STATUS_A2 = 0x08, /* A2 */
|
|
|
|
NSC_STATUS_RDY = 0x10, /* ready to receive command */
|
|
|
|
NSC_STATUS_IBR = 0x20 /* ready to receive data */
|
|
|
|
};
|
2005-06-26 05:55:39 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* command bits */
|
2005-06-24 13:01:48 +08:00
|
|
|
enum tpm_nsc_cmd_mode {
|
|
|
|
NSC_COMMAND_NORMAL = 0x01, /* normal mode */
|
|
|
|
NSC_COMMAND_EOC = 0x03,
|
|
|
|
NSC_COMMAND_CANCEL = 0x22
|
|
|
|
};
|
2016-03-23 14:16:09 +08:00
|
|
|
|
|
|
|
struct tpm_nsc_priv {
|
|
|
|
unsigned long base;
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Wait for a certain status to appear
|
|
|
|
*/
|
|
|
|
static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
|
|
|
|
{
|
2016-04-01 04:57:00 +08:00
|
|
|
struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
|
2005-06-24 13:01:47 +08:00
|
|
|
unsigned long stop;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* status immediately available check */
|
2016-04-01 04:57:00 +08:00
|
|
|
*data = inb(priv->base + NSC_STATUS);
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((*data & mask) == val)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* wait for status */
|
2005-06-24 13:01:47 +08:00
|
|
|
stop = jiffies + 10 * HZ;
|
2005-04-17 06:20:36 +08:00
|
|
|
do {
|
2005-06-24 13:01:47 +08:00
|
|
|
msleep(TPM_TIMEOUT);
|
2016-04-01 04:57:00 +08:00
|
|
|
*data = inb(priv->base + 1);
|
2005-06-24 13:01:47 +08:00
|
|
|
if ((*data & mask) == val)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-06-24 13:01:47 +08:00
|
|
|
while (time_before(jiffies, stop));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int nsc_wait_for_ready(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 04:57:00 +08:00
|
|
|
struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
int status;
|
2005-06-24 13:01:47 +08:00
|
|
|
unsigned long stop;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* status immediately available check */
|
2016-04-01 04:57:00 +08:00
|
|
|
status = inb(priv->base + NSC_STATUS);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status & NSC_STATUS_OBF)
|
2016-04-01 04:57:00 +08:00
|
|
|
status = inb(priv->base + NSC_DATA);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status & NSC_STATUS_RDY)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* wait for status */
|
2005-06-24 13:01:47 +08:00
|
|
|
stop = jiffies + 100;
|
2005-04-17 06:20:36 +08:00
|
|
|
do {
|
2005-06-24 13:01:47 +08:00
|
|
|
msleep(TPM_TIMEOUT);
|
2016-04-01 04:57:00 +08:00
|
|
|
status = inb(priv->base + NSC_STATUS);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (status & NSC_STATUS_OBF)
|
2016-04-01 04:57:00 +08:00
|
|
|
status = inb(priv->base + NSC_DATA);
|
2005-06-24 13:01:47 +08:00
|
|
|
if (status & NSC_STATUS_RDY)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-06-24 13:01:47 +08:00
|
|
|
while (time_before(jiffies, stop));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_info(&chip->dev, "wait for ready failed\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
|
|
|
|
{
|
2016-04-01 04:57:00 +08:00
|
|
|
struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
u8 *buffer = buf;
|
|
|
|
u8 data, *p;
|
|
|
|
u32 size;
|
|
|
|
__be32 *native_size;
|
|
|
|
|
|
|
|
if (count < 6)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev, "F0 timeout\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
2016-03-23 14:16:09 +08:00
|
|
|
|
2016-04-01 04:57:00 +08:00
|
|
|
data = inb(priv->base + NSC_DATA);
|
2016-03-23 14:16:09 +08:00
|
|
|
if (data != NSC_COMMAND_NORMAL) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev, "not in normal mode (0x%x)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
data);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the whole packet */
|
|
|
|
for (p = buffer; p < &buffer[count]; p++) {
|
|
|
|
if (wait_for_stat
|
|
|
|
(chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"OBF timeout (while reading data)\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
if (data & NSC_STATUS_F0)
|
|
|
|
break;
|
2016-04-01 04:57:00 +08:00
|
|
|
*p = inb(priv->base + NSC_DATA);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-06-26 05:55:39 +08:00
|
|
|
if ((data & NSC_STATUS_F0) == 0 &&
|
|
|
|
(wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev, "F0 not set\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
2016-03-23 14:16:09 +08:00
|
|
|
|
2016-04-01 04:57:00 +08:00
|
|
|
data = inb(priv->base + NSC_DATA);
|
2016-03-23 14:16:09 +08:00
|
|
|
if (data != NSC_COMMAND_EOC) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"expected end of command(0x%x)\n", data);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
native_size = (__force __be32 *) (buf + 2);
|
|
|
|
size = be32_to_cpu(*native_size);
|
|
|
|
|
|
|
|
if (count < size)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
|
|
|
|
{
|
2016-04-01 04:57:00 +08:00
|
|
|
struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
u8 data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we hit the chip with back to back commands it locks up
|
|
|
|
* and never set IBF. Hitting it with this "hammer" seems to
|
|
|
|
* fix it. Not sure why this is needed, we followed the flow
|
|
|
|
* chart in the manual to the letter.
|
|
|
|
*/
|
2016-04-01 04:57:00 +08:00
|
|
|
outb(NSC_COMMAND_CANCEL, priv->base + NSC_COMMAND);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (nsc_wait_for_ready(chip) != 0)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev, "IBF timeout\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2016-04-01 04:57:00 +08:00
|
|
|
outb(NSC_COMMAND_NORMAL, priv->base + NSC_COMMAND);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev, "IBR timeout\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"IBF timeout (while writing data)\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
2016-04-01 04:57:00 +08:00
|
|
|
outb(buf[i], priv->base + NSC_DATA);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
|
2016-03-01 01:29:47 +08:00
|
|
|
dev_err(&chip->dev, "IBF timeout\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
2016-04-01 04:57:00 +08:00
|
|
|
outb(NSC_COMMAND_EOC, priv->base + NSC_COMMAND);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-02-09 00:30:58 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_nsc_cancel(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 04:57:00 +08:00
|
|
|
struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
|
|
|
|
|
|
|
|
outb(NSC_COMMAND_CANCEL, priv->base + NSC_COMMAND);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-10-31 07:03:23 +08:00
|
|
|
static u8 tpm_nsc_status(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 04:57:00 +08:00
|
|
|
struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
|
|
|
|
|
|
|
|
return inb(priv->base + NSC_STATUS);
|
2005-10-31 07:03:23 +08:00
|
|
|
}
|
|
|
|
|
2013-01-23 03:52:35 +08:00
|
|
|
static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status)
|
|
|
|
{
|
|
|
|
return (status == NSC_STATUS_RDY);
|
|
|
|
}
|
|
|
|
|
2013-11-27 04:30:43 +08:00
|
|
|
static const struct tpm_class_ops tpm_nsc = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.recv = tpm_nsc_recv,
|
|
|
|
.send = tpm_nsc_send,
|
|
|
|
.cancel = tpm_nsc_cancel,
|
2005-10-31 07:03:23 +08:00
|
|
|
.status = tpm_nsc_status,
|
2005-04-17 06:20:36 +08:00
|
|
|
.req_complete_mask = NSC_STATUS_OBF,
|
|
|
|
.req_complete_val = NSC_STATUS_OBF,
|
2013-01-23 03:52:35 +08:00
|
|
|
.req_canceled = tpm_nsc_req_canceled,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2005-10-31 07:03:26 +08:00
|
|
|
static struct platform_device *pdev = NULL;
|
|
|
|
|
2008-04-29 16:03:23 +08:00
|
|
|
static void tpm_nsc_remove(struct device *dev)
|
2005-10-31 07:03:26 +08:00
|
|
|
{
|
|
|
|
struct tpm_chip *chip = dev_get_drvdata(dev);
|
2016-04-01 04:57:00 +08:00
|
|
|
struct tpm_nsc_priv *priv = dev_get_drvdata(&chip->dev);
|
2014-12-13 03:46:34 +08:00
|
|
|
|
|
|
|
tpm_chip_unregister(chip);
|
2016-04-01 04:57:00 +08:00
|
|
|
release_region(priv->base, 2);
|
2005-10-31 07:03:26 +08:00
|
|
|
}
|
|
|
|
|
2012-07-07 01:09:28 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
|
2009-01-08 10:08:57 +08:00
|
|
|
|
|
|
|
static struct platform_driver nsc_drv = {
|
|
|
|
.driver = {
|
|
|
|
.name = "tpm_nsc",
|
2012-07-07 01:09:28 +08:00
|
|
|
.pm = &tpm_nsc_pm,
|
2009-01-08 10:08:57 +08:00
|
|
|
},
|
2005-10-31 07:03:26 +08:00
|
|
|
};
|
|
|
|
|
2017-01-25 22:47:39 +08:00
|
|
|
static inline int tpm_read_index(int base, int index)
|
|
|
|
{
|
|
|
|
outb(index, base);
|
|
|
|
return inb(base+1) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tpm_write_index(int base, int index, int value)
|
|
|
|
{
|
|
|
|
outb(index, base);
|
|
|
|
outb(value & 0xFF, base+1);
|
|
|
|
}
|
|
|
|
|
2005-10-31 07:03:26 +08:00
|
|
|
static int __init init_nsc(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rc = 0;
|
2006-10-11 16:21:51 +08:00
|
|
|
int lo, hi, err;
|
2005-06-26 05:55:39 +08:00
|
|
|
int nscAddrBase = TPM_ADDR;
|
2006-04-22 17:37:26 +08:00
|
|
|
struct tpm_chip *chip;
|
|
|
|
unsigned long base;
|
2016-03-23 14:16:09 +08:00
|
|
|
struct tpm_nsc_priv *priv;
|
2005-06-26 05:55:39 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* verify that it is a National part (SID) */
|
2005-06-26 05:55:39 +08:00
|
|
|
if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
|
|
|
|
nscAddrBase = (tpm_read_index(TPM_SUPERIO_ADDR, 0x2C)<<8)|
|
|
|
|
(tpm_read_index(TPM_SUPERIO_ADDR, 0x2B)&0xFE);
|
2005-10-31 07:03:26 +08:00
|
|
|
if (tpm_read_index(nscAddrBase, NSC_SID_INDEX) != 0xF6)
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-01-08 10:08:57 +08:00
|
|
|
err = platform_driver_register(&nsc_drv);
|
2006-10-11 16:21:51 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2005-11-07 16:59:25 +08:00
|
|
|
|
2005-06-26 05:55:39 +08:00
|
|
|
hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
|
|
|
|
lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
|
2006-04-22 17:37:26 +08:00
|
|
|
base = (hi<<8) | lo;
|
2005-06-26 05:55:39 +08:00
|
|
|
|
2005-10-31 07:03:26 +08:00
|
|
|
/* enable the DPM module */
|
|
|
|
tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
|
|
|
|
|
2009-01-08 10:08:57 +08:00
|
|
|
pdev = platform_device_alloc("tpm_nscl0", -1);
|
2005-11-07 16:59:25 +08:00
|
|
|
if (!pdev) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_unreg_drv;
|
|
|
|
}
|
2005-10-31 07:03:26 +08:00
|
|
|
|
|
|
|
pdev->num_resources = 0;
|
2009-01-08 10:08:57 +08:00
|
|
|
pdev->dev.driver = &nsc_drv.driver;
|
2005-10-31 07:03:26 +08:00
|
|
|
pdev->dev.release = tpm_nsc_remove;
|
|
|
|
|
2011-07-23 05:39:20 +08:00
|
|
|
if ((rc = platform_device_add(pdev)) < 0)
|
|
|
|
goto err_put_dev;
|
2005-10-31 07:03:26 +08:00
|
|
|
|
2016-03-23 14:16:09 +08:00
|
|
|
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
|
|
|
|
if (!priv) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_del_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->base = base;
|
|
|
|
|
2006-04-22 17:37:26 +08:00
|
|
|
if (request_region(base, 2, "tpm_nsc0") == NULL ) {
|
2005-11-07 16:59:25 +08:00
|
|
|
rc = -EBUSY;
|
2011-07-23 05:39:20 +08:00
|
|
|
goto err_del_dev;
|
2005-10-31 07:03:26 +08:00
|
|
|
}
|
|
|
|
|
2014-12-13 03:46:34 +08:00
|
|
|
chip = tpmm_chip_alloc(&pdev->dev, &tpm_nsc);
|
|
|
|
if (IS_ERR(chip)) {
|
2006-04-22 17:37:26 +08:00
|
|
|
rc = -ENODEV;
|
2005-11-07 16:59:25 +08:00
|
|
|
goto err_rel_reg;
|
2006-04-22 17:37:26 +08:00
|
|
|
}
|
2005-10-31 07:03:26 +08:00
|
|
|
|
2016-04-01 04:57:00 +08:00
|
|
|
dev_set_drvdata(&chip->dev, priv);
|
2016-03-23 14:16:09 +08:00
|
|
|
|
2014-12-13 03:46:34 +08:00
|
|
|
rc = tpm_chip_register(chip);
|
|
|
|
if (rc)
|
|
|
|
goto err_rel_reg;
|
|
|
|
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_dbg(&pdev->dev, "NSC TPM detected\n");
|
|
|
|
dev_dbg(&pdev->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
|
2005-06-26 05:55:39 +08:00
|
|
|
tpm_read_index(nscAddrBase,0x07), tpm_read_index(nscAddrBase,0x20),
|
|
|
|
tpm_read_index(nscAddrBase,0x27));
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_dbg(&pdev->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"NSC SIOCF1 0x%x SIOCF5 0x%x SIOCF6 0x%x SIOCF8 0x%x\n",
|
2005-06-26 05:55:39 +08:00
|
|
|
tpm_read_index(nscAddrBase,0x21), tpm_read_index(nscAddrBase,0x25),
|
|
|
|
tpm_read_index(nscAddrBase,0x26), tpm_read_index(nscAddrBase,0x28));
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_dbg(&pdev->dev, "NSC IO Base0 0x%x\n",
|
2005-06-26 05:55:39 +08:00
|
|
|
(tpm_read_index(nscAddrBase,0x60) << 8) | tpm_read_index(nscAddrBase,0x61));
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_dbg(&pdev->dev, "NSC IO Base1 0x%x\n",
|
2005-06-26 05:55:39 +08:00
|
|
|
(tpm_read_index(nscAddrBase,0x62) << 8) | tpm_read_index(nscAddrBase,0x63));
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_dbg(&pdev->dev, "NSC Interrupt number and wakeup 0x%x\n",
|
2005-06-26 05:55:39 +08:00
|
|
|
tpm_read_index(nscAddrBase,0x70));
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_dbg(&pdev->dev, "NSC IRQ type select 0x%x\n",
|
2005-06-26 05:55:39 +08:00
|
|
|
tpm_read_index(nscAddrBase,0x71));
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_dbg(&pdev->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"NSC DMA channel select0 0x%x, select1 0x%x\n",
|
2005-06-26 05:55:39 +08:00
|
|
|
tpm_read_index(nscAddrBase,0x74), tpm_read_index(nscAddrBase,0x75));
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_dbg(&pdev->dev,
|
2005-04-17 06:20:36 +08:00
|
|
|
"NSC Config "
|
|
|
|
"0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
|
2005-06-26 05:55:39 +08:00
|
|
|
tpm_read_index(nscAddrBase,0xF0), tpm_read_index(nscAddrBase,0xF1),
|
|
|
|
tpm_read_index(nscAddrBase,0xF2), tpm_read_index(nscAddrBase,0xF3),
|
|
|
|
tpm_read_index(nscAddrBase,0xF4), tpm_read_index(nscAddrBase,0xF5),
|
|
|
|
tpm_read_index(nscAddrBase,0xF6), tpm_read_index(nscAddrBase,0xF7),
|
|
|
|
tpm_read_index(nscAddrBase,0xF8), tpm_read_index(nscAddrBase,0xF9));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-10-31 07:03:26 +08:00
|
|
|
dev_info(&pdev->dev,
|
2005-06-26 05:55:39 +08:00
|
|
|
"NSC TPM revision %d\n",
|
|
|
|
tpm_read_index(nscAddrBase, 0x27) & 0x1F);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
2005-11-07 16:59:25 +08:00
|
|
|
|
|
|
|
err_rel_reg:
|
2006-04-22 17:37:26 +08:00
|
|
|
release_region(base, 2);
|
2011-07-23 05:39:20 +08:00
|
|
|
err_del_dev:
|
|
|
|
platform_device_del(pdev);
|
|
|
|
err_put_dev:
|
|
|
|
platform_device_put(pdev);
|
2005-11-07 16:59:25 +08:00
|
|
|
err_unreg_drv:
|
2009-01-08 10:08:57 +08:00
|
|
|
platform_driver_unregister(&nsc_drv);
|
2005-11-07 16:59:25 +08:00
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cleanup_nsc(void)
|
|
|
|
{
|
2005-10-31 07:03:26 +08:00
|
|
|
if (pdev) {
|
|
|
|
tpm_nsc_remove(&pdev->dev);
|
|
|
|
platform_device_unregister(pdev);
|
|
|
|
}
|
|
|
|
|
2009-01-08 10:08:57 +08:00
|
|
|
platform_driver_unregister(&nsc_drv);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_nsc);
|
|
|
|
module_exit(cleanup_nsc);
|
|
|
|
|
2024-02-13 22:54:04 +08:00
|
|
|
MODULE_AUTHOR("Leendert van Doorn <leendert@watson.ibm.com>");
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_DESCRIPTION("TPM Driver");
|
|
|
|
MODULE_VERSION("2.0");
|
|
|
|
MODULE_LICENSE("GPL");
|