2006-04-22 16:38:03 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005, 2006 IBM Corporation
|
2015-09-29 04:32:19 +07:00
|
|
|
* Copyright (C) 2014, 2015 Intel Corporation
|
2006-04-22 16:38:03 +07:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Leendert van Doorn <leendert@watson.ibm.com>
|
|
|
|
* Kylene Hall <kjhall@us.ibm.com>
|
|
|
|
*
|
2007-08-23 04:01:04 +07:00
|
|
|
* Maintained by: <tpmdd-devel@lists.sourceforge.net>
|
|
|
|
*
|
2006-04-22 16:38:03 +07:00
|
|
|
* Device driver for TCG/TCPA TPM (trusted platform module).
|
|
|
|
* Specifications at www.trustedcomputinggroup.org
|
|
|
|
*
|
|
|
|
* This device driver implements the TPM interface as defined in
|
|
|
|
* the TCG TPM Interface Spec version 1.2, revision 1.0.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2006-04-22 16:39:44 +07:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2006-04-22 16:38:03 +07:00
|
|
|
#include <linux/pnp.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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2006-04-22 16:38:03 +07:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/wait.h>
|
2010-10-22 04:42:40 +07:00
|
|
|
#include <linux/acpi.h>
|
2011-03-30 23:13:31 +07:00
|
|
|
#include <linux/freezer.h>
|
2006-04-22 16:38:03 +07:00
|
|
|
#include "tpm.h"
|
|
|
|
|
|
|
|
enum tis_access {
|
|
|
|
TPM_ACCESS_VALID = 0x80,
|
|
|
|
TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
|
|
|
|
TPM_ACCESS_REQUEST_PENDING = 0x04,
|
|
|
|
TPM_ACCESS_REQUEST_USE = 0x02,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum tis_status {
|
|
|
|
TPM_STS_VALID = 0x80,
|
|
|
|
TPM_STS_COMMAND_READY = 0x40,
|
|
|
|
TPM_STS_GO = 0x20,
|
|
|
|
TPM_STS_DATA_AVAIL = 0x10,
|
|
|
|
TPM_STS_DATA_EXPECT = 0x08,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum tis_int_flags {
|
|
|
|
TPM_GLOBAL_INT_ENABLE = 0x80000000,
|
|
|
|
TPM_INTF_BURST_COUNT_STATIC = 0x100,
|
|
|
|
TPM_INTF_CMD_READY_INT = 0x080,
|
|
|
|
TPM_INTF_INT_EDGE_FALLING = 0x040,
|
|
|
|
TPM_INTF_INT_EDGE_RISING = 0x020,
|
|
|
|
TPM_INTF_INT_LEVEL_LOW = 0x010,
|
|
|
|
TPM_INTF_INT_LEVEL_HIGH = 0x008,
|
|
|
|
TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
|
|
|
|
TPM_INTF_STS_VALID_INT = 0x002,
|
|
|
|
TPM_INTF_DATA_AVAIL_INT = 0x001,
|
|
|
|
};
|
|
|
|
|
2006-04-22 16:38:19 +07:00
|
|
|
enum tis_defaults {
|
2006-04-22 16:38:55 +07:00
|
|
|
TIS_MEM_LEN = 0x5000,
|
2006-04-22 16:39:31 +07:00
|
|
|
TIS_SHORT_TIMEOUT = 750, /* ms */
|
|
|
|
TIS_LONG_TIMEOUT = 2000, /* 2 sec */
|
2006-04-22 16:38:19 +07:00
|
|
|
};
|
|
|
|
|
2015-09-29 04:32:19 +07:00
|
|
|
struct tpm_info {
|
2016-01-08 07:36:23 +07:00
|
|
|
struct resource res;
|
2016-01-08 07:36:21 +07:00
|
|
|
/* irq > 0 means: use irq $irq;
|
|
|
|
* irq = 0 means: autoprobe for an irq;
|
|
|
|
* irq = -1 means: no irq support
|
|
|
|
*/
|
|
|
|
int irq;
|
2015-09-29 04:32:19 +07:00
|
|
|
};
|
|
|
|
|
2014-12-13 02:46:40 +07:00
|
|
|
/* Some timeout values are needed before it is known whether the chip is
|
|
|
|
* TPM 1.0 or TPM 2.0.
|
|
|
|
*/
|
|
|
|
#define TIS_TIMEOUT_A_MAX max(TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_A)
|
|
|
|
#define TIS_TIMEOUT_B_MAX max(TIS_LONG_TIMEOUT, TPM2_TIMEOUT_B)
|
|
|
|
#define TIS_TIMEOUT_C_MAX max(TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_C)
|
|
|
|
#define TIS_TIMEOUT_D_MAX max(TIS_SHORT_TIMEOUT, TPM2_TIMEOUT_D)
|
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
#define TPM_ACCESS(l) (0x0000 | ((l) << 12))
|
|
|
|
#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
|
|
|
|
#define TPM_INT_VECTOR(l) (0x000C | ((l) << 12))
|
|
|
|
#define TPM_INT_STATUS(l) (0x0010 | ((l) << 12))
|
|
|
|
#define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12))
|
|
|
|
#define TPM_STS(l) (0x0018 | ((l) << 12))
|
2014-12-13 02:46:40 +07:00
|
|
|
#define TPM_STS3(l) (0x001b | ((l) << 12))
|
2006-04-22 16:38:03 +07:00
|
|
|
#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12))
|
|
|
|
|
|
|
|
#define TPM_DID_VID(l) (0x0F00 | ((l) << 12))
|
|
|
|
#define TPM_RID(l) (0x0F04 | ((l) << 12))
|
|
|
|
|
2014-09-25 05:41:10 +07:00
|
|
|
struct priv_data {
|
2016-04-01 03:56:55 +07:00
|
|
|
void __iomem *iobase;
|
2016-03-23 12:31:56 +07:00
|
|
|
u16 manufacturer_id;
|
2016-04-01 03:56:58 +07:00
|
|
|
int locality;
|
2016-04-01 03:56:56 +07:00
|
|
|
int irq;
|
2014-09-25 05:41:10 +07:00
|
|
|
bool irq_tested;
|
2016-03-22 11:20:09 +07:00
|
|
|
wait_queue_head_t int_queue;
|
2016-04-01 03:56:57 +07:00
|
|
|
wait_queue_head_t read_queue;
|
2014-09-25 05:41:10 +07:00
|
|
|
};
|
|
|
|
|
2011-08-04 06:21:11 +07:00
|
|
|
#if defined(CONFIG_PNP) && defined(CONFIG_ACPI)
|
2015-09-29 04:32:19 +07:00
|
|
|
static int has_hid(struct acpi_device *dev, const char *hid)
|
2010-10-22 04:42:40 +07:00
|
|
|
{
|
|
|
|
struct acpi_hardware_id *id;
|
|
|
|
|
2015-09-29 04:32:19 +07:00
|
|
|
list_for_each_entry(id, &dev->pnp.ids, list)
|
|
|
|
if (!strcmp(hid, id->id))
|
2010-10-22 04:42:40 +07:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-29 04:32:19 +07:00
|
|
|
|
|
|
|
static inline int is_itpm(struct acpi_device *dev)
|
|
|
|
{
|
|
|
|
return has_hid(dev, "INTC0102");
|
|
|
|
}
|
2011-08-04 06:21:11 +07:00
|
|
|
#else
|
2015-09-29 04:32:19 +07:00
|
|
|
static inline int is_itpm(struct acpi_device *dev)
|
2011-08-04 06:21:11 +07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2010-10-22 04:42:40 +07:00
|
|
|
#endif
|
|
|
|
|
2012-12-07 05:44:54 +07:00
|
|
|
/* Before we attempt to access the TPM we must see that the valid bit is set.
|
|
|
|
* The specification says that this bit is 0 at reset and remains 0 until the
|
|
|
|
* 'TPM has gone through its self test and initialization and has established
|
|
|
|
* correct values in the other bits.' */
|
|
|
|
static int wait_startup(struct tpm_chip *chip, int l)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2016-04-01 03:56:59 +07:00
|
|
|
unsigned long stop = jiffies + chip->timeout_a;
|
2012-12-07 05:44:54 +07:00
|
|
|
do {
|
2016-04-01 03:56:55 +07:00
|
|
|
if (ioread8(priv->iobase + TPM_ACCESS(l)) &
|
2012-12-07 05:44:54 +07:00
|
|
|
TPM_ACCESS_VALID)
|
|
|
|
return 0;
|
|
|
|
msleep(TPM_TIMEOUT);
|
|
|
|
} while (time_before(jiffies, stop));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
static int check_locality(struct tpm_chip *chip, int l)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2016-04-01 03:56:55 +07:00
|
|
|
|
|
|
|
if ((ioread8(priv->iobase + TPM_ACCESS(l)) &
|
2006-04-22 16:38:03 +07:00
|
|
|
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID)) ==
|
|
|
|
(TPM_ACCESS_ACTIVE_LOCALITY | TPM_ACCESS_VALID))
|
2016-04-01 03:56:58 +07:00
|
|
|
return priv->locality = l;
|
2006-04-22 16:38:03 +07:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void release_locality(struct tpm_chip *chip, int l, int force)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2016-04-01 03:56:55 +07:00
|
|
|
|
|
|
|
if (force || (ioread8(priv->iobase + TPM_ACCESS(l)) &
|
2006-04-22 16:38:03 +07:00
|
|
|
(TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID)) ==
|
|
|
|
(TPM_ACCESS_REQUEST_PENDING | TPM_ACCESS_VALID))
|
|
|
|
iowrite8(TPM_ACCESS_ACTIVE_LOCALITY,
|
2016-04-01 03:56:55 +07:00
|
|
|
priv->iobase + TPM_ACCESS(l));
|
2006-04-22 16:38:03 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int request_locality(struct tpm_chip *chip, int l)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2011-03-30 23:13:31 +07:00
|
|
|
unsigned long stop, timeout;
|
2006-04-22 16:38:03 +07:00
|
|
|
long rc;
|
|
|
|
|
|
|
|
if (check_locality(chip, l) >= 0)
|
|
|
|
return l;
|
|
|
|
|
|
|
|
iowrite8(TPM_ACCESS_REQUEST_USE,
|
2016-04-01 03:56:55 +07:00
|
|
|
priv->iobase + TPM_ACCESS(l));
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2016-04-01 03:56:59 +07:00
|
|
|
stop = jiffies + chip->timeout_a;
|
2011-03-30 23:13:31 +07:00
|
|
|
|
2016-04-01 03:56:56 +07:00
|
|
|
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
|
2011-03-30 23:13:31 +07:00
|
|
|
again:
|
|
|
|
timeout = stop - jiffies;
|
|
|
|
if ((long)timeout <= 0)
|
|
|
|
return -1;
|
2016-03-22 11:20:09 +07:00
|
|
|
rc = wait_event_interruptible_timeout(priv->int_queue,
|
2006-04-22 16:38:03 +07:00
|
|
|
(check_locality
|
|
|
|
(chip, l) >= 0),
|
2011-03-30 23:13:31 +07:00
|
|
|
timeout);
|
2006-04-22 16:38:03 +07:00
|
|
|
if (rc > 0)
|
|
|
|
return l;
|
2011-03-30 23:13:31 +07:00
|
|
|
if (rc == -ERESTARTSYS && freezing(current)) {
|
|
|
|
clear_thread_flag(TIF_SIGPENDING);
|
|
|
|
goto again;
|
|
|
|
}
|
2006-04-22 16:38:03 +07:00
|
|
|
} else {
|
|
|
|
/* wait for burstcount */
|
|
|
|
do {
|
|
|
|
if (check_locality(chip, l) >= 0)
|
|
|
|
return l;
|
|
|
|
msleep(TPM_TIMEOUT);
|
|
|
|
}
|
|
|
|
while (time_before(jiffies, stop));
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 tpm_tis_status(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2016-04-01 03:56:55 +07:00
|
|
|
|
|
|
|
return ioread8(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_STS(priv->locality));
|
2006-04-22 16:38:03 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_tis_ready(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2016-04-01 03:56:55 +07:00
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
/* this causes the current command to be aborted */
|
|
|
|
iowrite8(TPM_STS_COMMAND_READY,
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_STS(priv->locality));
|
2006-04-22 16:38:03 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int get_burstcount(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2006-04-22 16:38:03 +07:00
|
|
|
unsigned long stop;
|
|
|
|
int burstcnt;
|
|
|
|
|
|
|
|
/* wait for burstcount */
|
|
|
|
/* which timeout value, spec has 2 answers (c & d) */
|
2016-04-01 03:56:59 +07:00
|
|
|
stop = jiffies + chip->timeout_d;
|
2006-04-22 16:38:03 +07:00
|
|
|
do {
|
2016-04-01 03:56:55 +07:00
|
|
|
burstcnt = ioread8(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_STS(priv->locality) + 1);
|
2016-04-01 03:56:55 +07:00
|
|
|
burstcnt += ioread8(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_STS(priv->locality) +
|
2006-04-22 16:38:03 +07:00
|
|
|
2) << 8;
|
|
|
|
if (burstcnt)
|
|
|
|
return burstcnt;
|
|
|
|
msleep(TPM_TIMEOUT);
|
|
|
|
} while (time_before(jiffies, stop));
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2006-04-22 16:39:31 +07:00
|
|
|
static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)
|
2006-04-22 16:38:03 +07:00
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2006-04-22 16:38:03 +07:00
|
|
|
int size = 0, burstcnt;
|
|
|
|
while (size < count &&
|
2011-09-17 00:39:40 +07:00
|
|
|
wait_for_tpm_stat(chip,
|
|
|
|
TPM_STS_DATA_AVAIL | TPM_STS_VALID,
|
2016-04-01 03:56:59 +07:00
|
|
|
chip->timeout_c,
|
2016-04-01 03:56:57 +07:00
|
|
|
&priv->read_queue, true)
|
2006-04-22 16:38:03 +07:00
|
|
|
== 0) {
|
|
|
|
burstcnt = get_burstcount(chip);
|
|
|
|
for (; burstcnt > 0 && size < count; burstcnt--)
|
2016-04-01 03:56:55 +07:00
|
|
|
buf[size++] = ioread8(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_DATA_FIFO(priv->locality));
|
2006-04-22 16:38:03 +07:00
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2006-04-22 16:39:31 +07:00
|
|
|
static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
|
2006-04-22 16:38:03 +07:00
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2006-04-22 16:38:03 +07:00
|
|
|
int size = 0;
|
|
|
|
int expected, status;
|
|
|
|
|
|
|
|
if (count < TPM_HEADER_SIZE) {
|
|
|
|
size = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read first 10 bytes, including tag, paramsize, and result */
|
|
|
|
if ((size =
|
|
|
|
recv_data(chip, buf, TPM_HEADER_SIZE)) < TPM_HEADER_SIZE) {
|
2016-03-01 00:29:47 +07:00
|
|
|
dev_err(&chip->dev, "Unable to read header\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
expected = be32_to_cpu(*(__be32 *) (buf + 2));
|
|
|
|
if (expected > count) {
|
|
|
|
size = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((size +=
|
|
|
|
recv_data(chip, &buf[TPM_HEADER_SIZE],
|
|
|
|
expected - TPM_HEADER_SIZE)) < expected) {
|
2016-03-01 00:29:47 +07:00
|
|
|
dev_err(&chip->dev, "Unable to read remainder of result\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
size = -ETIME;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-04-01 03:56:59 +07:00
|
|
|
wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
|
2016-03-22 11:20:09 +07:00
|
|
|
&priv->int_queue, false);
|
2006-04-22 16:38:03 +07:00
|
|
|
status = tpm_tis_status(chip);
|
|
|
|
if (status & TPM_STS_DATA_AVAIL) { /* retry? */
|
2016-03-01 00:29:47 +07:00
|
|
|
dev_err(&chip->dev, "Error left over data\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
size = -EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
tpm_tis_ready(chip);
|
2016-04-01 03:56:58 +07:00
|
|
|
release_locality(chip, priv->locality, 0);
|
2006-04-22 16:38:03 +07:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2012-01-13 06:02:20 +07:00
|
|
|
static bool itpm;
|
2009-09-11 03:09:35 +07:00
|
|
|
module_param(itpm, bool, 0444);
|
|
|
|
MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
|
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
/*
|
|
|
|
* If interrupts are used (signaled by an irq set in the vendor structure)
|
|
|
|
* tpm.c can skip polling for the data to be available as the interrupt is
|
|
|
|
* waited for here
|
|
|
|
*/
|
2011-03-30 23:13:33 +07:00
|
|
|
static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len)
|
2006-04-22 16:38:03 +07:00
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2006-04-22 16:38:03 +07:00
|
|
|
int rc, status, burstcnt;
|
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
if (request_locality(chip, 0) < 0)
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
status = tpm_tis_status(chip);
|
|
|
|
if ((status & TPM_STS_COMMAND_READY) == 0) {
|
|
|
|
tpm_tis_ready(chip);
|
2011-09-17 00:39:40 +07:00
|
|
|
if (wait_for_tpm_stat
|
2016-04-01 03:56:59 +07:00
|
|
|
(chip, TPM_STS_COMMAND_READY, chip->timeout_b,
|
2016-03-22 11:20:09 +07:00
|
|
|
&priv->int_queue, false) < 0) {
|
2006-04-22 16:38:03 +07:00
|
|
|
rc = -ETIME;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (count < len - 1) {
|
|
|
|
burstcnt = get_burstcount(chip);
|
|
|
|
for (; burstcnt > 0 && count < len - 1; burstcnt--) {
|
2016-04-01 03:56:55 +07:00
|
|
|
iowrite8(buf[count], priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_DATA_FIFO(priv->locality));
|
2006-04-22 16:38:03 +07:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
2016-04-01 03:56:59 +07:00
|
|
|
wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
|
2016-03-22 11:20:09 +07:00
|
|
|
&priv->int_queue, false);
|
2006-04-22 16:38:03 +07:00
|
|
|
status = tpm_tis_status(chip);
|
2009-09-11 03:09:35 +07:00
|
|
|
if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
|
2006-04-22 16:38:03 +07:00
|
|
|
rc = -EIO;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write last byte */
|
|
|
|
iowrite8(buf[count],
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_DATA_FIFO(priv->locality));
|
2016-04-01 03:56:59 +07:00
|
|
|
wait_for_tpm_stat(chip, TPM_STS_VALID, chip->timeout_c,
|
2016-03-22 11:20:09 +07:00
|
|
|
&priv->int_queue, false);
|
2006-04-22 16:38:03 +07:00
|
|
|
status = tpm_tis_status(chip);
|
|
|
|
if ((status & TPM_STS_DATA_EXPECT) != 0) {
|
|
|
|
rc = -EIO;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2011-03-30 23:13:33 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_err:
|
|
|
|
tpm_tis_ready(chip);
|
2016-04-01 03:56:58 +07:00
|
|
|
release_locality(chip, priv->locality, 0);
|
2011-03-30 23:13:33 +07:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-09-25 05:41:10 +07:00
|
|
|
static void disable_interrupts(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2014-09-25 05:41:10 +07:00
|
|
|
u32 intmask;
|
|
|
|
|
|
|
|
intmask =
|
2016-04-01 03:56:55 +07:00
|
|
|
ioread32(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INT_ENABLE(priv->locality));
|
2014-09-25 05:41:10 +07:00
|
|
|
intmask &= ~TPM_GLOBAL_INT_ENABLE;
|
|
|
|
iowrite32(intmask,
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_INT_ENABLE(priv->locality));
|
2016-04-27 23:58:46 +07:00
|
|
|
devm_free_irq(chip->dev.parent, priv->irq, chip);
|
2016-04-01 03:56:56 +07:00
|
|
|
priv->irq = 0;
|
|
|
|
chip->flags &= ~TPM_CHIP_FLAG_IRQ;
|
2014-09-25 05:41:10 +07:00
|
|
|
}
|
|
|
|
|
2011-03-30 23:13:33 +07:00
|
|
|
/*
|
|
|
|
* If interrupts are used (signaled by an irq set in the vendor structure)
|
|
|
|
* tpm.c can skip polling for the data to be available as the interrupt is
|
|
|
|
* waited for here
|
|
|
|
*/
|
2014-09-25 05:41:10 +07:00
|
|
|
static int tpm_tis_send_main(struct tpm_chip *chip, u8 *buf, size_t len)
|
2011-03-30 23:13:33 +07:00
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2011-03-30 23:13:33 +07:00
|
|
|
int rc;
|
|
|
|
u32 ordinal;
|
2014-12-13 02:46:40 +07:00
|
|
|
unsigned long dur;
|
2011-03-30 23:13:33 +07:00
|
|
|
|
|
|
|
rc = tpm_tis_send_data(chip, buf, len);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
/* go and do it */
|
|
|
|
iowrite8(TPM_STS_GO,
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_STS(priv->locality));
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2016-04-01 03:56:56 +07:00
|
|
|
if (chip->flags & TPM_CHIP_FLAG_IRQ) {
|
2006-04-22 16:38:03 +07:00
|
|
|
ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
|
2014-12-13 02:46:40 +07:00
|
|
|
|
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2)
|
|
|
|
dur = tpm2_calc_ordinal_duration(chip, ordinal);
|
|
|
|
else
|
|
|
|
dur = tpm_calc_ordinal_duration(chip, ordinal);
|
|
|
|
|
2011-09-17 00:39:40 +07:00
|
|
|
if (wait_for_tpm_stat
|
2014-12-13 02:46:40 +07:00
|
|
|
(chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, dur,
|
2016-04-01 03:56:57 +07:00
|
|
|
&priv->read_queue, false) < 0) {
|
2006-04-22 16:38:03 +07:00
|
|
|
rc = -ETIME;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
out_err:
|
|
|
|
tpm_tis_ready(chip);
|
2016-04-01 03:56:58 +07:00
|
|
|
release_locality(chip, priv->locality, 0);
|
2006-04-22 16:38:03 +07:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-09-25 05:41:10 +07:00
|
|
|
static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
|
|
|
|
{
|
|
|
|
int rc, irq;
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2014-09-25 05:41:10 +07:00
|
|
|
|
2016-04-01 03:56:56 +07:00
|
|
|
if (!(chip->flags & TPM_CHIP_FLAG_IRQ) || priv->irq_tested)
|
2014-09-25 05:41:10 +07:00
|
|
|
return tpm_tis_send_main(chip, buf, len);
|
|
|
|
|
|
|
|
/* Verify receipt of the expected IRQ */
|
2016-04-01 03:56:56 +07:00
|
|
|
irq = priv->irq;
|
|
|
|
priv->irq = 0;
|
|
|
|
chip->flags &= ~TPM_CHIP_FLAG_IRQ;
|
2014-09-25 05:41:10 +07:00
|
|
|
rc = tpm_tis_send_main(chip, buf, len);
|
2016-04-01 03:56:56 +07:00
|
|
|
priv->irq = irq;
|
|
|
|
chip->flags |= TPM_CHIP_FLAG_IRQ;
|
2014-09-25 05:41:10 +07:00
|
|
|
if (!priv->irq_tested)
|
|
|
|
msleep(1);
|
2015-11-26 04:05:35 +07:00
|
|
|
if (!priv->irq_tested)
|
2014-09-25 05:41:10 +07:00
|
|
|
disable_interrupts(chip);
|
|
|
|
priv->irq_tested = true;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-05-22 07:26:44 +07:00
|
|
|
struct tis_vendor_timeout_override {
|
|
|
|
u32 did_vid;
|
|
|
|
unsigned long timeout_us[4];
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tis_vendor_timeout_override vendor_timeout_overrides[] = {
|
|
|
|
/* Atmel 3204 */
|
|
|
|
{ 0x32041114, { (TIS_SHORT_TIMEOUT*1000), (TIS_LONG_TIMEOUT*1000),
|
|
|
|
(TIS_SHORT_TIMEOUT*1000), (TIS_SHORT_TIMEOUT*1000) } },
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool tpm_tis_update_timeouts(struct tpm_chip *chip,
|
|
|
|
unsigned long *timeout_cap)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2014-05-22 07:26:44 +07:00
|
|
|
int i;
|
|
|
|
u32 did_vid;
|
|
|
|
|
2016-04-01 03:56:55 +07:00
|
|
|
did_vid = ioread32(priv->iobase + TPM_DID_VID(0));
|
2014-05-22 07:26:44 +07:00
|
|
|
|
|
|
|
for (i = 0; i != ARRAY_SIZE(vendor_timeout_overrides); i++) {
|
|
|
|
if (vendor_timeout_overrides[i].did_vid != did_vid)
|
|
|
|
continue;
|
|
|
|
memcpy(timeout_cap, vendor_timeout_overrides[i].timeout_us,
|
|
|
|
sizeof(vendor_timeout_overrides[i].timeout_us));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-30 23:13:33 +07:00
|
|
|
/*
|
|
|
|
* Early probing for iTPM with STS_DATA_EXPECT flaw.
|
|
|
|
* Try sending command without itpm flag set and if that
|
|
|
|
* fails, repeat with itpm flag set.
|
|
|
|
*/
|
|
|
|
static int probe_itpm(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2011-03-30 23:13:33 +07:00
|
|
|
int rc = 0;
|
|
|
|
u8 cmd_getticks[] = {
|
|
|
|
0x00, 0xc1, 0x00, 0x00, 0x00, 0x0a,
|
|
|
|
0x00, 0x00, 0x00, 0xf1
|
|
|
|
};
|
|
|
|
size_t len = sizeof(cmd_getticks);
|
2012-01-21 00:58:50 +07:00
|
|
|
bool rem_itpm = itpm;
|
2016-04-01 03:56:55 +07:00
|
|
|
u16 vendor = ioread16(priv->iobase + TPM_DID_VID(0));
|
2012-01-21 00:58:49 +07:00
|
|
|
|
|
|
|
/* probe only iTPMS */
|
|
|
|
if (vendor != TPM_VID_INTEL)
|
|
|
|
return 0;
|
2011-03-30 23:13:33 +07:00
|
|
|
|
2012-11-30 04:08:41 +07:00
|
|
|
itpm = false;
|
2011-03-30 23:13:33 +07:00
|
|
|
|
|
|
|
rc = tpm_tis_send_data(chip, cmd_getticks, len);
|
|
|
|
if (rc == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
tpm_tis_ready(chip);
|
2016-04-01 03:56:58 +07:00
|
|
|
release_locality(chip, priv->locality, 0);
|
2011-03-30 23:13:33 +07:00
|
|
|
|
2012-11-30 04:08:41 +07:00
|
|
|
itpm = true;
|
2011-03-30 23:13:33 +07:00
|
|
|
|
|
|
|
rc = tpm_tis_send_data(chip, cmd_getticks, len);
|
|
|
|
if (rc == 0) {
|
2016-03-01 00:29:47 +07:00
|
|
|
dev_info(&chip->dev, "Detected an iTPM.\n");
|
2011-03-30 23:13:33 +07:00
|
|
|
rc = 1;
|
|
|
|
} else
|
|
|
|
rc = -EFAULT;
|
|
|
|
|
|
|
|
out:
|
|
|
|
itpm = rem_itpm;
|
|
|
|
tpm_tis_ready(chip);
|
2016-04-01 03:56:58 +07:00
|
|
|
release_locality(chip, priv->locality, 0);
|
2011-03-30 23:13:33 +07:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-01-23 02:52:35 +07:00
|
|
|
static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2016-03-23 12:31:56 +07:00
|
|
|
|
|
|
|
switch (priv->manufacturer_id) {
|
2013-01-23 02:52:35 +07:00
|
|
|
case TPM_VID_WINBOND:
|
|
|
|
return ((status == TPM_STS_VALID) ||
|
|
|
|
(status == (TPM_STS_VALID | TPM_STS_COMMAND_READY)));
|
|
|
|
case TPM_VID_STM:
|
|
|
|
return (status == (TPM_STS_VALID | TPM_STS_COMMAND_READY));
|
|
|
|
default:
|
|
|
|
return (status == TPM_STS_COMMAND_READY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 03:30:43 +07:00
|
|
|
static const struct tpm_class_ops tpm_tis = {
|
2006-04-22 16:38:03 +07:00
|
|
|
.status = tpm_tis_status,
|
|
|
|
.recv = tpm_tis_recv,
|
|
|
|
.send = tpm_tis_send,
|
|
|
|
.cancel = tpm_tis_ready,
|
2014-05-22 07:26:44 +07:00
|
|
|
.update_timeouts = tpm_tis_update_timeouts,
|
2006-04-22 16:38:03 +07:00
|
|
|
.req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
|
|
|
|
.req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
|
2013-01-23 02:52:35 +07:00
|
|
|
.req_canceled = tpm_tis_req_canceled,
|
2006-04-22 16:38:03 +07:00
|
|
|
};
|
|
|
|
|
2007-10-31 16:20:49 +07:00
|
|
|
static irqreturn_t tis_int_handler(int dummy, void *dev_id)
|
2006-04-22 16:38:03 +07:00
|
|
|
{
|
2007-10-19 14:10:11 +07:00
|
|
|
struct tpm_chip *chip = dev_id;
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2006-04-22 16:38:03 +07:00
|
|
|
u32 interrupt;
|
|
|
|
int i;
|
|
|
|
|
2016-04-01 03:56:55 +07:00
|
|
|
interrupt = ioread32(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INT_STATUS(priv->locality));
|
2006-04-22 16:38:03 +07:00
|
|
|
|
|
|
|
if (interrupt == 0)
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
2016-04-01 03:57:00 +07:00
|
|
|
priv->irq_tested = true;
|
2006-04-22 16:38:03 +07:00
|
|
|
if (interrupt & TPM_INTF_DATA_AVAIL_INT)
|
2016-04-01 03:56:57 +07:00
|
|
|
wake_up_interruptible(&priv->read_queue);
|
2006-04-22 16:38:03 +07:00
|
|
|
if (interrupt & TPM_INTF_LOCALITY_CHANGE_INT)
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
if (check_locality(chip, i) >= 0)
|
|
|
|
break;
|
|
|
|
if (interrupt &
|
|
|
|
(TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_STS_VALID_INT |
|
|
|
|
TPM_INTF_CMD_READY_INT))
|
2016-03-22 11:20:09 +07:00
|
|
|
wake_up_interruptible(&priv->int_queue);
|
2006-04-22 16:38:03 +07:00
|
|
|
|
|
|
|
/* Clear interrupts handled with TPM_EOI */
|
|
|
|
iowrite32(interrupt,
|
2016-04-01 03:56:55 +07:00
|
|
|
priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INT_STATUS(priv->locality));
|
|
|
|
ioread32(priv->iobase + TPM_INT_STATUS(priv->locality));
|
2006-04-22 16:38:03 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2015-11-26 04:05:35 +07:00
|
|
|
/* Register the IRQ and issue a command that will cause an interrupt. If an
|
|
|
|
* irq is seen then leave the chip setup for IRQ operation, otherwise reverse
|
|
|
|
* everything and leave in polling mode. Returns 0 on success.
|
|
|
|
*/
|
2015-11-26 04:05:36 +07:00
|
|
|
static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask,
|
|
|
|
int flags, int irq)
|
2015-11-26 04:05:35 +07:00
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2015-11-26 04:05:35 +07:00
|
|
|
u8 original_int_vec;
|
|
|
|
|
2016-04-27 23:58:46 +07:00
|
|
|
if (devm_request_irq(chip->dev.parent, irq, tis_int_handler, flags,
|
2016-03-01 00:29:48 +07:00
|
|
|
dev_name(&chip->dev), chip) != 0) {
|
2016-03-01 00:29:47 +07:00
|
|
|
dev_info(&chip->dev, "Unable to request irq: %d for probe\n",
|
2015-11-26 04:05:35 +07:00
|
|
|
irq);
|
|
|
|
return -1;
|
|
|
|
}
|
2016-04-01 03:56:56 +07:00
|
|
|
priv->irq = irq;
|
2015-11-26 04:05:35 +07:00
|
|
|
|
2016-04-01 03:56:55 +07:00
|
|
|
original_int_vec = ioread8(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INT_VECTOR(priv->locality));
|
2015-11-26 04:05:35 +07:00
|
|
|
iowrite8(irq,
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_INT_VECTOR(priv->locality));
|
2015-11-26 04:05:35 +07:00
|
|
|
|
|
|
|
/* Clear all existing */
|
2016-04-01 03:56:55 +07:00
|
|
|
iowrite32(ioread32(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INT_STATUS(priv->locality)),
|
|
|
|
priv->iobase + TPM_INT_STATUS(priv->locality));
|
2015-11-26 04:05:35 +07:00
|
|
|
|
|
|
|
/* Turn on */
|
|
|
|
iowrite32(intmask | TPM_GLOBAL_INT_ENABLE,
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_INT_ENABLE(priv->locality));
|
2015-11-26 04:05:35 +07:00
|
|
|
|
|
|
|
priv->irq_tested = false;
|
|
|
|
|
|
|
|
/* Generate an interrupt by having the core call through to
|
|
|
|
* tpm_tis_send
|
|
|
|
*/
|
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2)
|
|
|
|
tpm2_gen_interrupt(chip);
|
|
|
|
else
|
|
|
|
tpm_gen_interrupt(chip);
|
|
|
|
|
|
|
|
/* tpm_tis_send will either confirm the interrupt is working or it
|
|
|
|
* will call disable_irq which undoes all of the above.
|
|
|
|
*/
|
2016-04-01 03:56:56 +07:00
|
|
|
if (!(chip->flags & TPM_CHIP_FLAG_IRQ)) {
|
2015-11-26 04:05:35 +07:00
|
|
|
iowrite8(original_int_vec,
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_INT_VECTOR(priv->locality));
|
2015-11-26 04:05:35 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to find the IRQ the TPM is using. This is for legacy x86 systems that
|
|
|
|
* do not have ACPI/etc. We typically expect the interrupt to be declared if
|
|
|
|
* present.
|
|
|
|
*/
|
|
|
|
static void tpm_tis_probe_irq(struct tpm_chip *chip, u32 intmask)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2015-11-26 04:05:35 +07:00
|
|
|
u8 original_int_vec;
|
|
|
|
int i;
|
|
|
|
|
2016-04-01 03:56:55 +07:00
|
|
|
original_int_vec = ioread8(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INT_VECTOR(priv->locality));
|
2015-11-26 04:05:35 +07:00
|
|
|
|
|
|
|
if (!original_int_vec) {
|
2015-11-26 04:05:36 +07:00
|
|
|
if (IS_ENABLED(CONFIG_X86))
|
|
|
|
for (i = 3; i <= 15; i++)
|
|
|
|
if (!tpm_tis_probe_irq_single(chip, intmask, 0,
|
|
|
|
i))
|
|
|
|
return;
|
|
|
|
} else if (!tpm_tis_probe_irq_single(chip, intmask, 0,
|
|
|
|
original_int_vec))
|
2015-11-26 04:05:35 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-30 04:08:41 +07:00
|
|
|
static bool interrupts = true;
|
2006-04-22 16:39:44 +07:00
|
|
|
module_param(interrupts, bool, 0444);
|
|
|
|
MODULE_PARM_DESC(interrupts, "Enable interrupts");
|
|
|
|
|
2014-12-13 02:46:34 +07:00
|
|
|
static void tpm_tis_remove(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2016-04-01 03:56:58 +07:00
|
|
|
void __iomem *reg = priv->iobase + TPM_INT_ENABLE(priv->locality);
|
2016-03-31 17:05:36 +07:00
|
|
|
|
|
|
|
iowrite32(~TPM_GLOBAL_INT_ENABLE & ioread32(reg), reg);
|
2016-04-01 03:56:58 +07:00
|
|
|
release_locality(chip, priv->locality, 1);
|
2014-12-13 02:46:34 +07:00
|
|
|
}
|
|
|
|
|
2015-09-29 04:32:19 +07:00
|
|
|
static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info,
|
|
|
|
acpi_handle acpi_dev_handle)
|
2006-04-22 16:38:03 +07:00
|
|
|
{
|
|
|
|
u32 vendor, intfcaps, intmask;
|
2015-11-26 04:05:35 +07:00
|
|
|
int rc, probe;
|
2006-04-22 16:38:03 +07:00
|
|
|
struct tpm_chip *chip;
|
2014-09-25 05:41:10 +07:00
|
|
|
struct priv_data *priv;
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2014-09-25 05:41:10 +07:00
|
|
|
priv = devm_kzalloc(dev, sizeof(struct priv_data), GFP_KERNEL);
|
|
|
|
if (priv == NULL)
|
|
|
|
return -ENOMEM;
|
2014-12-13 02:46:34 +07:00
|
|
|
|
|
|
|
chip = tpmm_chip_alloc(dev, &tpm_tis);
|
|
|
|
if (IS_ERR(chip))
|
|
|
|
return PTR_ERR(chip);
|
|
|
|
|
2014-12-13 02:46:40 +07:00
|
|
|
#ifdef CONFIG_ACPI
|
2014-12-13 02:46:35 +07:00
|
|
|
chip->acpi_dev_handle = acpi_dev_handle;
|
2014-12-13 02:46:40 +07:00
|
|
|
#endif
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2016-04-01 03:56:55 +07:00
|
|
|
priv->iobase = devm_ioremap_resource(dev, &tpm_info->res);
|
|
|
|
if (IS_ERR(priv->iobase))
|
|
|
|
return PTR_ERR(priv->iobase);
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2014-12-13 02:46:40 +07:00
|
|
|
/* Maximum timeouts */
|
2016-04-01 03:56:59 +07:00
|
|
|
chip->timeout_a = TIS_TIMEOUT_A_MAX;
|
|
|
|
chip->timeout_b = TIS_TIMEOUT_B_MAX;
|
|
|
|
chip->timeout_c = TIS_TIMEOUT_C_MAX;
|
|
|
|
chip->timeout_d = TIS_TIMEOUT_D_MAX;
|
2009-09-10 06:22:18 +07:00
|
|
|
|
2016-04-01 03:57:00 +07:00
|
|
|
dev_set_drvdata(&chip->dev, priv);
|
|
|
|
|
2012-12-07 05:44:54 +07:00
|
|
|
if (wait_startup(chip, 0) != 0) {
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2015-11-26 04:05:31 +07:00
|
|
|
/* Take control of the TPM's interrupt hardware and shut it off */
|
2016-04-01 03:56:55 +07:00
|
|
|
intmask = ioread32(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INT_ENABLE(priv->locality));
|
2015-11-26 04:05:31 +07:00
|
|
|
intmask |= TPM_INTF_CMD_READY_INT | TPM_INTF_LOCALITY_CHANGE_INT |
|
|
|
|
TPM_INTF_DATA_AVAIL_INT | TPM_INTF_STS_VALID_INT;
|
|
|
|
intmask &= ~TPM_GLOBAL_INT_ENABLE;
|
|
|
|
iowrite32(intmask,
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_INT_ENABLE(priv->locality));
|
2015-11-26 04:05:31 +07:00
|
|
|
|
2007-11-29 07:21:27 +07:00
|
|
|
if (request_locality(chip, 0) != 0) {
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2015-02-04 21:21:09 +07:00
|
|
|
rc = tpm2_probe(chip);
|
|
|
|
if (rc)
|
|
|
|
goto out_err;
|
2014-12-13 02:46:40 +07:00
|
|
|
|
2016-04-01 03:56:55 +07:00
|
|
|
vendor = ioread32(priv->iobase + TPM_DID_VID(0));
|
2016-03-23 12:31:56 +07:00
|
|
|
priv->manufacturer_id = vendor;
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2014-12-13 02:46:40 +07:00
|
|
|
dev_info(dev, "%s TPM (device-id 0x%X, rev-id %d)\n",
|
|
|
|
(chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2",
|
2016-04-01 03:56:55 +07:00
|
|
|
vendor >> 16, ioread8(priv->iobase + TPM_RID(0)));
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2011-03-30 23:13:33 +07:00
|
|
|
if (!itpm) {
|
2012-01-21 00:58:50 +07:00
|
|
|
probe = probe_itpm(chip);
|
|
|
|
if (probe < 0) {
|
2011-03-30 23:13:33 +07:00
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2012-11-30 04:08:41 +07:00
|
|
|
itpm = !!probe;
|
2011-03-30 23:13:33 +07:00
|
|
|
}
|
|
|
|
|
2009-09-11 03:09:35 +07:00
|
|
|
if (itpm)
|
|
|
|
dev_info(dev, "Intel iTPM workaround enabled\n");
|
|
|
|
|
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
/* Figure out the capabilities */
|
|
|
|
intfcaps =
|
2016-04-01 03:56:55 +07:00
|
|
|
ioread32(priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INTF_CAPS(priv->locality));
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
|
2006-04-22 16:38:03 +07:00
|
|
|
intfcaps);
|
|
|
|
if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tBurst Count Static\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
if (intfcaps & TPM_INTF_CMD_READY_INT)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tCommand Ready Int Support\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tInterrupt Edge Falling\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
if (intfcaps & TPM_INTF_INT_EDGE_RISING)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tInterrupt Edge Rising\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tInterrupt Level Low\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tInterrupt Level High\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tLocality Change Int Support\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
if (intfcaps & TPM_INTF_STS_VALID_INT)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tSts Valid Int Support\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
|
2006-07-14 14:24:31 +07:00
|
|
|
dev_dbg(dev, "\tData Avail Int Support\n");
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2015-11-26 04:05:32 +07:00
|
|
|
/* Very early on issue a command to the TPM in polling mode to make
|
|
|
|
* sure it works. May as well use that command to set the proper
|
|
|
|
* timeouts for the driver.
|
|
|
|
*/
|
|
|
|
if (tpm_get_timeouts(chip)) {
|
|
|
|
dev_err(dev, "Could not get TPM timeouts and durations\n");
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
/* INTERRUPT Setup */
|
2016-04-01 03:56:57 +07:00
|
|
|
init_waitqueue_head(&priv->read_queue);
|
2016-03-22 11:20:09 +07:00
|
|
|
init_waitqueue_head(&priv->int_queue);
|
2016-01-08 07:36:21 +07:00
|
|
|
if (interrupts && tpm_info->irq != -1) {
|
2015-11-26 04:05:35 +07:00
|
|
|
if (tpm_info->irq) {
|
2015-11-26 04:05:36 +07:00
|
|
|
tpm_tis_probe_irq_single(chip, intmask, IRQF_SHARED,
|
|
|
|
tpm_info->irq);
|
2016-04-01 03:56:56 +07:00
|
|
|
if (!(chip->flags & TPM_CHIP_FLAG_IRQ))
|
2016-03-01 00:29:47 +07:00
|
|
|
dev_err(&chip->dev, FW_BUG
|
2015-11-26 04:05:35 +07:00
|
|
|
"TPM interrupt not working, polling instead\n");
|
|
|
|
} else
|
|
|
|
tpm_tis_probe_irq(chip, intmask);
|
2015-11-26 04:05:32 +07:00
|
|
|
}
|
2014-12-13 02:46:40 +07:00
|
|
|
|
2015-11-26 04:05:32 +07:00
|
|
|
if (chip->flags & TPM_CHIP_FLAG_TPM2) {
|
2014-12-13 02:46:40 +07:00
|
|
|
rc = tpm2_do_selftest(chip);
|
|
|
|
if (rc == TPM2_RC_INITIALIZE) {
|
|
|
|
dev_warn(dev, "Firmware has not started TPM\n");
|
|
|
|
rc = tpm2_startup(chip, TPM2_SU_CLEAR);
|
|
|
|
if (!rc)
|
|
|
|
rc = tpm2_do_selftest(chip);
|
|
|
|
}
|
2014-09-25 05:41:10 +07:00
|
|
|
|
2014-12-13 02:46:40 +07:00
|
|
|
if (rc) {
|
|
|
|
dev_err(dev, "TPM self test failed\n");
|
|
|
|
if (rc > 0)
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (tpm_do_selftest(chip)) {
|
|
|
|
dev_err(dev, "TPM self test failed\n");
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto out_err;
|
|
|
|
}
|
2014-09-25 05:41:10 +07:00
|
|
|
}
|
|
|
|
|
2014-12-13 02:46:34 +07:00
|
|
|
return tpm_chip_register(chip);
|
2006-04-22 16:38:03 +07:00
|
|
|
out_err:
|
2014-12-13 02:46:34 +07:00
|
|
|
tpm_tis_remove(chip);
|
2006-04-22 16:38:03 +07:00
|
|
|
return rc;
|
|
|
|
}
|
2011-07-17 12:04:24 +07:00
|
|
|
|
2016-02-22 21:09:12 +07:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2011-07-17 12:04:24 +07:00
|
|
|
static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
|
|
|
|
{
|
2016-04-01 03:57:00 +07:00
|
|
|
struct priv_data *priv = dev_get_drvdata(&chip->dev);
|
2011-07-17 12:04:24 +07:00
|
|
|
u32 intmask;
|
|
|
|
|
|
|
|
/* reenable interrupts that device may have lost or
|
|
|
|
BIOS/firmware may have disabled */
|
2016-04-01 03:56:56 +07:00
|
|
|
iowrite8(priv->irq, priv->iobase +
|
2016-04-01 03:56:58 +07:00
|
|
|
TPM_INT_VECTOR(priv->locality));
|
2011-07-17 12:04:24 +07:00
|
|
|
|
|
|
|
intmask =
|
2016-04-01 03:56:58 +07:00
|
|
|
ioread32(priv->iobase + TPM_INT_ENABLE(priv->locality));
|
2011-07-17 12:04:24 +07:00
|
|
|
|
|
|
|
intmask |= TPM_INTF_CMD_READY_INT
|
|
|
|
| TPM_INTF_LOCALITY_CHANGE_INT | TPM_INTF_DATA_AVAIL_INT
|
|
|
|
| TPM_INTF_STS_VALID_INT | TPM_GLOBAL_INT_ENABLE;
|
|
|
|
|
|
|
|
iowrite32(intmask,
|
2016-04-01 03:56:58 +07:00
|
|
|
priv->iobase + TPM_INT_ENABLE(priv->locality));
|
2011-07-17 12:04:24 +07:00
|
|
|
}
|
|
|
|
|
2013-09-12 04:23:13 +07:00
|
|
|
static int tpm_tis_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct tpm_chip *chip = dev_get_drvdata(dev);
|
2015-01-29 12:43:47 +07:00
|
|
|
int ret;
|
2013-09-12 04:23:13 +07:00
|
|
|
|
2016-04-01 03:56:56 +07:00
|
|
|
if (chip->flags & TPM_CHIP_FLAG_IRQ)
|
2013-09-12 04:23:13 +07:00
|
|
|
tpm_tis_reenable_interrupts(chip);
|
|
|
|
|
2015-01-29 12:43:47 +07:00
|
|
|
ret = tpm_pm_resume(dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-12-13 02:46:40 +07:00
|
|
|
|
2015-01-29 12:43:47 +07:00
|
|
|
/* TPM 1.2 requires self-test on resume. This function actually returns
|
|
|
|
* an error code but for unknown reason it isn't handled.
|
|
|
|
*/
|
|
|
|
if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
|
|
|
|
tpm_do_selftest(chip);
|
2013-09-12 04:23:13 +07:00
|
|
|
|
2015-01-29 12:43:47 +07:00
|
|
|
return 0;
|
2013-09-12 04:23:13 +07:00
|
|
|
}
|
2016-02-22 21:09:12 +07:00
|
|
|
#endif
|
2013-09-12 04:23:13 +07:00
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
|
|
|
|
|
2012-11-20 01:22:42 +07:00
|
|
|
static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
|
2016-01-08 07:36:21 +07:00
|
|
|
const struct pnp_device_id *pnp_id)
|
2006-07-14 14:24:31 +07:00
|
|
|
{
|
2016-01-08 07:36:21 +07:00
|
|
|
struct tpm_info tpm_info = {};
|
2014-12-13 02:46:35 +07:00
|
|
|
acpi_handle acpi_dev_handle = NULL;
|
2016-01-08 07:36:23 +07:00
|
|
|
struct resource *res;
|
2007-10-17 13:26:46 +07:00
|
|
|
|
2016-01-08 07:36:23 +07:00
|
|
|
res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res)
|
|
|
|
return -ENODEV;
|
|
|
|
tpm_info.res = *res;
|
2006-07-14 14:24:31 +07:00
|
|
|
|
2007-10-17 13:26:46 +07:00
|
|
|
if (pnp_irq_valid(pnp_dev, 0))
|
2015-09-29 04:32:19 +07:00
|
|
|
tpm_info.irq = pnp_irq(pnp_dev, 0);
|
2007-10-17 13:26:46 +07:00
|
|
|
else
|
2016-01-08 07:36:21 +07:00
|
|
|
tpm_info.irq = -1;
|
2007-10-17 13:26:46 +07:00
|
|
|
|
2015-09-29 04:32:19 +07:00
|
|
|
if (pnp_acpi_device(pnp_dev)) {
|
|
|
|
if (is_itpm(pnp_acpi_device(pnp_dev)))
|
|
|
|
itpm = true;
|
|
|
|
|
2016-01-08 07:36:24 +07:00
|
|
|
acpi_dev_handle = ACPI_HANDLE(&pnp_dev->dev);
|
2015-09-29 04:32:19 +07:00
|
|
|
}
|
2014-12-13 02:46:35 +07:00
|
|
|
|
2015-09-29 04:32:19 +07:00
|
|
|
return tpm_tis_init(&pnp_dev->dev, &tpm_info, acpi_dev_handle);
|
2006-07-14 14:24:31 +07:00
|
|
|
}
|
|
|
|
|
2012-11-20 01:24:36 +07:00
|
|
|
static struct pnp_device_id tpm_pnp_tbl[] = {
|
2006-04-22 16:38:03 +07:00
|
|
|
{"PNP0C31", 0}, /* TPM */
|
2006-04-22 16:39:52 +07:00
|
|
|
{"ATM1200", 0}, /* Atmel */
|
|
|
|
{"IFX0102", 0}, /* Infineon */
|
|
|
|
{"BCM0101", 0}, /* Broadcom */
|
2008-07-26 09:44:56 +07:00
|
|
|
{"BCM0102", 0}, /* Broadcom */
|
2006-04-22 16:39:52 +07:00
|
|
|
{"NSC1200", 0}, /* National */
|
2008-07-11 07:30:42 +07:00
|
|
|
{"ICO0102", 0}, /* Intel */
|
2006-04-22 16:39:52 +07:00
|
|
|
/* Add new here */
|
|
|
|
{"", 0}, /* User Specified */
|
|
|
|
{"", 0} /* Terminator */
|
2006-04-22 16:38:03 +07:00
|
|
|
};
|
2009-11-03 08:05:50 +07:00
|
|
|
MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
|
2006-04-22 16:38:03 +07:00
|
|
|
|
2012-11-20 01:26:26 +07:00
|
|
|
static void tpm_tis_pnp_remove(struct pnp_dev *dev)
|
2008-10-11 05:04:39 +07:00
|
|
|
{
|
|
|
|
struct tpm_chip *chip = pnp_get_drvdata(dev);
|
2015-09-29 04:32:19 +07:00
|
|
|
|
2014-12-13 02:46:34 +07:00
|
|
|
tpm_chip_unregister(chip);
|
|
|
|
tpm_tis_remove(chip);
|
2008-10-11 05:04:39 +07:00
|
|
|
}
|
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
static struct pnp_driver tis_pnp_driver = {
|
|
|
|
.name = "tpm_tis",
|
|
|
|
.id_table = tpm_pnp_tbl,
|
|
|
|
.probe = tpm_tis_pnp_init,
|
2008-10-11 05:04:39 +07:00
|
|
|
.remove = tpm_tis_pnp_remove,
|
2013-09-12 04:23:13 +07:00
|
|
|
.driver = {
|
|
|
|
.pm = &tpm_tis_pm,
|
|
|
|
},
|
2006-04-22 16:38:03 +07:00
|
|
|
};
|
|
|
|
|
2006-04-22 16:39:52 +07:00
|
|
|
#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
|
|
|
|
module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
|
|
|
|
sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
|
|
|
|
MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
|
2009-02-06 22:40:12 +07:00
|
|
|
|
2015-09-29 04:32:19 +07:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
static int tpm_check_resource(struct acpi_resource *ares, void *data)
|
|
|
|
{
|
|
|
|
struct tpm_info *tpm_info = (struct tpm_info *) data;
|
|
|
|
struct resource res;
|
|
|
|
|
2016-01-08 07:36:23 +07:00
|
|
|
if (acpi_dev_resource_interrupt(ares, 0, &res))
|
2015-09-29 04:32:19 +07:00
|
|
|
tpm_info->irq = res.start;
|
2016-02-17 07:10:52 +07:00
|
|
|
else if (acpi_dev_resource_memory(ares, &res)) {
|
2016-01-08 07:36:23 +07:00
|
|
|
tpm_info->res = res;
|
2016-02-17 07:10:52 +07:00
|
|
|
tpm_info->res.name = NULL;
|
|
|
|
}
|
2015-09-29 04:32:19 +07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tpm_tis_acpi_init(struct acpi_device *acpi_dev)
|
|
|
|
{
|
2016-01-08 07:36:22 +07:00
|
|
|
struct acpi_table_tpm2 *tbl;
|
|
|
|
acpi_status st;
|
2015-09-29 04:32:19 +07:00
|
|
|
struct list_head resources;
|
2016-01-08 07:36:22 +07:00
|
|
|
struct tpm_info tpm_info = {};
|
2015-09-29 04:32:19 +07:00
|
|
|
int ret;
|
|
|
|
|
2016-01-08 07:36:22 +07:00
|
|
|
st = acpi_get_table(ACPI_SIG_TPM2, 1,
|
|
|
|
(struct acpi_table_header **) &tbl);
|
|
|
|
if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) {
|
|
|
|
dev_err(&acpi_dev->dev,
|
|
|
|
FW_BUG "failed to get TPM2 ACPI table\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tbl->start_method != ACPI_TPM2_MEMORY_MAPPED)
|
2015-09-29 04:32:19 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&resources);
|
2016-01-08 07:36:21 +07:00
|
|
|
tpm_info.irq = -1;
|
2015-09-29 04:32:19 +07:00
|
|
|
ret = acpi_dev_get_resources(acpi_dev, &resources, tpm_check_resource,
|
|
|
|
&tpm_info);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
acpi_dev_free_resource_list(&resources);
|
|
|
|
|
2016-01-08 07:36:23 +07:00
|
|
|
if (resource_type(&tpm_info.res) != IORESOURCE_MEM) {
|
2016-01-08 07:36:22 +07:00
|
|
|
dev_err(&acpi_dev->dev,
|
|
|
|
FW_BUG "TPM2 ACPI table does not define a memory resource\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-09-29 04:32:19 +07:00
|
|
|
if (is_itpm(acpi_dev))
|
|
|
|
itpm = true;
|
|
|
|
|
|
|
|
return tpm_tis_init(&acpi_dev->dev, &tpm_info, acpi_dev->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tpm_tis_acpi_remove(struct acpi_device *dev)
|
|
|
|
{
|
|
|
|
struct tpm_chip *chip = dev_get_drvdata(&dev->dev);
|
|
|
|
|
|
|
|
tpm_chip_unregister(chip);
|
|
|
|
tpm_tis_remove(chip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct acpi_device_id tpm_acpi_tbl[] = {
|
|
|
|
{"MSFT0101", 0}, /* TPM 2.0 */
|
|
|
|
/* Add new here */
|
|
|
|
{"", 0}, /* User Specified */
|
|
|
|
{"", 0} /* Terminator */
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, tpm_acpi_tbl);
|
|
|
|
|
|
|
|
static struct acpi_driver tis_acpi_driver = {
|
|
|
|
.name = "tpm_tis",
|
|
|
|
.ids = tpm_acpi_tbl,
|
|
|
|
.ops = {
|
|
|
|
.add = tpm_tis_acpi_init,
|
|
|
|
.remove = tpm_tis_acpi_remove,
|
|
|
|
},
|
|
|
|
.drv = {
|
|
|
|
.pm = &tpm_tis_pm,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-01-08 07:36:24 +07:00
|
|
|
static struct platform_device *force_pdev;
|
|
|
|
|
|
|
|
static int tpm_tis_plat_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct tpm_info tpm_info = {};
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (res == NULL) {
|
|
|
|
dev_err(&pdev->dev, "no memory resource defined\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
tpm_info.res = *res;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
|
|
|
|
if (res) {
|
|
|
|
tpm_info.irq = res->start;
|
|
|
|
} else {
|
|
|
|
if (pdev == force_pdev)
|
|
|
|
tpm_info.irq = -1;
|
|
|
|
else
|
|
|
|
/* When forcing auto probe the IRQ */
|
|
|
|
tpm_info.irq = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tpm_tis_init(&pdev->dev, &tpm_info, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tpm_tis_plat_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
|
|
|
|
|
|
|
|
tpm_chip_unregister(chip);
|
|
|
|
tpm_tis_remove(chip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-06 22:40:12 +07:00
|
|
|
static struct platform_driver tis_drv = {
|
2016-01-08 07:36:24 +07:00
|
|
|
.probe = tpm_tis_plat_probe,
|
|
|
|
.remove = tpm_tis_plat_remove,
|
2009-02-06 22:40:12 +07:00
|
|
|
.driver = {
|
2014-12-13 02:46:34 +07:00
|
|
|
.name = "tpm_tis",
|
2012-07-07 00:09:20 +07:00
|
|
|
.pm = &tpm_tis_pm,
|
2009-02-06 22:40:12 +07:00
|
|
|
},
|
2006-07-14 14:24:31 +07:00
|
|
|
};
|
|
|
|
|
2012-01-13 06:02:20 +07:00
|
|
|
static bool force;
|
2016-01-08 07:36:24 +07:00
|
|
|
#ifdef CONFIG_X86
|
2006-07-14 14:24:31 +07:00
|
|
|
module_param(force, bool, 0444);
|
|
|
|
MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
|
2016-01-08 07:36:24 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int tpm_tis_force_device(void)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev;
|
|
|
|
static const struct resource x86_resources[] = {
|
|
|
|
{
|
|
|
|
.start = 0xFED40000,
|
|
|
|
.end = 0xFED40000 + TIS_MEM_LEN - 1,
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!force)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* The driver core will match the name tpm_tis of the device to
|
|
|
|
* the tpm_tis platform driver and complete the setup via
|
|
|
|
* tpm_tis_plat_probe
|
|
|
|
*/
|
|
|
|
pdev = platform_device_register_simple("tpm_tis", -1, x86_resources,
|
|
|
|
ARRAY_SIZE(x86_resources));
|
|
|
|
if (IS_ERR(pdev))
|
|
|
|
return PTR_ERR(pdev);
|
|
|
|
force_pdev = pdev;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-04-22 16:38:03 +07:00
|
|
|
static int __init init_tis(void)
|
|
|
|
{
|
2006-07-14 14:24:31 +07:00
|
|
|
int rc;
|
2016-01-08 07:36:24 +07:00
|
|
|
|
|
|
|
rc = tpm_tis_force_device();
|
|
|
|
if (rc)
|
|
|
|
goto err_force;
|
|
|
|
|
|
|
|
rc = platform_driver_register(&tis_drv);
|
|
|
|
if (rc)
|
|
|
|
goto err_platform;
|
|
|
|
|
2015-09-29 04:32:19 +07:00
|
|
|
#ifdef CONFIG_ACPI
|
2016-01-08 07:36:24 +07:00
|
|
|
rc = acpi_bus_register_driver(&tis_acpi_driver);
|
|
|
|
if (rc)
|
|
|
|
goto err_acpi;
|
2015-09-29 04:32:19 +07:00
|
|
|
#endif
|
2006-07-14 14:24:31 +07:00
|
|
|
|
2016-01-08 07:36:24 +07:00
|
|
|
if (IS_ENABLED(CONFIG_PNP)) {
|
|
|
|
rc = pnp_register_driver(&tis_pnp_driver);
|
|
|
|
if (rc)
|
|
|
|
goto err_pnp;
|
2006-07-14 14:24:31 +07:00
|
|
|
}
|
2016-01-08 07:36:24 +07:00
|
|
|
|
2013-04-25 14:07:47 +07:00
|
|
|
return 0;
|
2016-01-08 07:36:24 +07:00
|
|
|
|
|
|
|
err_pnp:
|
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
acpi_bus_unregister_driver(&tis_acpi_driver);
|
|
|
|
err_acpi:
|
|
|
|
#endif
|
|
|
|
platform_device_unregister(force_pdev);
|
|
|
|
err_platform:
|
|
|
|
if (force_pdev)
|
|
|
|
platform_device_unregister(force_pdev);
|
|
|
|
err_force:
|
2010-05-14 03:37:54 +07:00
|
|
|
return rc;
|
2006-04-22 16:38:03 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cleanup_tis(void)
|
|
|
|
{
|
2016-01-08 07:36:24 +07:00
|
|
|
pnp_unregister_driver(&tis_pnp_driver);
|
2015-09-29 04:32:19 +07:00
|
|
|
#ifdef CONFIG_ACPI
|
2016-01-08 07:36:24 +07:00
|
|
|
acpi_bus_unregister_driver(&tis_acpi_driver);
|
2010-05-14 03:37:54 +07:00
|
|
|
#endif
|
|
|
|
platform_driver_unregister(&tis_drv);
|
2016-01-08 07:36:24 +07:00
|
|
|
|
|
|
|
if (force_pdev)
|
|
|
|
platform_device_unregister(force_pdev);
|
2006-04-22 16:38:03 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_tis);
|
|
|
|
module_exit(cleanup_tis);
|
|
|
|
MODULE_AUTHOR("Leendert van Doorn (leendert@watson.ibm.com)");
|
|
|
|
MODULE_DESCRIPTION("TPM Driver");
|
|
|
|
MODULE_VERSION("2.0");
|
|
|
|
MODULE_LICENSE("GPL");
|