2006-04-22 09:38:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005, 2006 IBM Corporation
|
2015-09-28 21:32:19 +00:00
|
|
|
* Copyright (C) 2014, 2015 Intel Corporation
|
2006-04-22 09:38:03 +00:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Leendert van Doorn <leendert@watson.ibm.com>
|
|
|
|
* Kylene Hall <kjhall@us.ibm.com>
|
|
|
|
*
|
2007-08-22 21:01:04 +00:00
|
|
|
* Maintained by: <tpmdd-devel@lists.sourceforge.net>
|
|
|
|
*
|
2006-04-22 09:38:03 +00: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 09:39:44 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2006-04-22 09:38:03 +00: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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2006-04-22 09:38:03 +00:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/wait.h>
|
2010-10-21 21:42:40 +00:00
|
|
|
#include <linux/acpi.h>
|
2011-03-30 16:13:31 +00:00
|
|
|
#include <linux/freezer.h>
|
2016-11-07 22:44:31 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2006-04-22 09:38:03 +00:00
|
|
|
#include "tpm.h"
|
2016-05-18 22:35:48 +00:00
|
|
|
#include "tpm_tis_core.h"
|
2006-04-22 09:38:03 +00:00
|
|
|
|
2015-09-28 21:32:19 +00:00
|
|
|
struct tpm_info {
|
2016-01-08 00:36:23 +00:00
|
|
|
struct resource res;
|
2016-01-08 00:36:21 +00:00
|
|
|
/* irq > 0 means: use irq $irq;
|
|
|
|
* irq = 0 means: autoprobe for an irq;
|
|
|
|
* irq = -1 means: no irq support
|
|
|
|
*/
|
|
|
|
int irq;
|
2015-09-28 21:32:19 +00:00
|
|
|
};
|
|
|
|
|
2016-05-18 22:35:48 +00:00
|
|
|
struct tpm_tis_tcg_phy {
|
|
|
|
struct tpm_tis_data priv;
|
2016-03-31 20:56:55 +00:00
|
|
|
void __iomem *iobase;
|
2014-09-24 22:41:10 +00:00
|
|
|
};
|
|
|
|
|
2016-05-18 22:35:48 +00:00
|
|
|
static inline struct tpm_tis_tcg_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *data)
|
|
|
|
{
|
|
|
|
return container_of(data, struct tpm_tis_tcg_phy, priv);
|
|
|
|
}
|
|
|
|
|
2016-05-18 22:35:52 +00:00
|
|
|
static bool interrupts = true;
|
|
|
|
module_param(interrupts, bool, 0444);
|
|
|
|
MODULE_PARM_DESC(interrupts, "Enable interrupts");
|
|
|
|
|
|
|
|
static bool itpm;
|
|
|
|
module_param(itpm, bool, 0444);
|
|
|
|
MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
|
|
|
|
|
|
|
|
static bool force;
|
|
|
|
#ifdef CONFIG_X86
|
|
|
|
module_param(force, bool, 0444);
|
|
|
|
MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
|
|
|
|
#endif
|
|
|
|
|
2011-08-03 23:21:11 +00:00
|
|
|
#if defined(CONFIG_PNP) && defined(CONFIG_ACPI)
|
2015-09-28 21:32:19 +00:00
|
|
|
static int has_hid(struct acpi_device *dev, const char *hid)
|
2010-10-21 21:42:40 +00:00
|
|
|
{
|
|
|
|
struct acpi_hardware_id *id;
|
|
|
|
|
2015-09-28 21:32:19 +00:00
|
|
|
list_for_each_entry(id, &dev->pnp.ids, list)
|
|
|
|
if (!strcmp(hid, id->id))
|
2010-10-21 21:42:40 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-28 21:32:19 +00:00
|
|
|
|
|
|
|
static inline int is_itpm(struct acpi_device *dev)
|
|
|
|
{
|
2017-05-04 15:53:25 +00:00
|
|
|
if (!dev)
|
|
|
|
return 0;
|
2015-09-28 21:32:19 +00:00
|
|
|
return has_hid(dev, "INTC0102");
|
|
|
|
}
|
2011-08-03 23:21:11 +00:00
|
|
|
#else
|
2015-09-28 21:32:19 +00:00
|
|
|
static inline int is_itpm(struct acpi_device *dev)
|
2011-08-03 23:21:11 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2010-10-21 21:42:40 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-04 15:53:25 +00:00
|
|
|
#if defined(CONFIG_ACPI)
|
|
|
|
#define DEVICE_IS_TPM2 1
|
|
|
|
|
|
|
|
static const struct acpi_device_id tpm_acpi_tbl[] = {
|
|
|
|
{"MSFT0101", DEVICE_IS_TPM2},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(acpi, tpm_acpi_tbl);
|
|
|
|
|
|
|
|
static int check_acpi_tpm2(struct device *dev)
|
|
|
|
{
|
|
|
|
const struct acpi_device_id *aid = acpi_match_device(tpm_acpi_tbl, dev);
|
|
|
|
struct acpi_table_tpm2 *tbl;
|
|
|
|
acpi_status st;
|
|
|
|
|
|
|
|
if (!aid || aid->driver_data != DEVICE_IS_TPM2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* If the ACPI TPM2 signature is matched then a global ACPI_SIG_TPM2
|
|
|
|
* table is mandatory
|
|
|
|
*/
|
|
|
|
st =
|
|
|
|
acpi_get_table(ACPI_SIG_TPM2, 1, (struct acpi_table_header **)&tbl);
|
|
|
|
if (ACPI_FAILURE(st) || tbl->header.length < sizeof(*tbl)) {
|
|
|
|
dev_err(dev, FW_BUG "failed to get TPM2 ACPI table\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The tpm2_crb driver handles this device */
|
|
|
|
if (tbl->start_method != ACPI_TPM2_MEMORY_MAPPED)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int check_acpi_tpm2(struct device *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-19 02:17:59 +00:00
|
|
|
#ifdef CONFIG_X86
|
|
|
|
#define INTEL_LEGACY_BLK_BASE_ADDR 0xFED08000
|
|
|
|
#define ILB_REMAP_SIZE 0x100
|
|
|
|
#define LPC_CNTRL_REG_OFFSET 0x84
|
|
|
|
#define LPC_CLKRUN_EN (1 << 2)
|
|
|
|
|
2017-06-20 10:22:02 +00:00
|
|
|
static void __iomem *ilb_base_addr;
|
2017-06-19 02:17:59 +00:00
|
|
|
|
|
|
|
static inline bool is_bsw(void)
|
|
|
|
{
|
|
|
|
return ((boot_cpu_data.x86_model == INTEL_FAM6_ATOM_AIRMONT) ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tpm_platform_begin_xfer() - clear LPC CLKRUN_EN i.e. clocks will be running
|
|
|
|
*/
|
|
|
|
static void tpm_platform_begin_xfer(void)
|
|
|
|
{
|
|
|
|
u32 clkrun_val;
|
|
|
|
|
|
|
|
if (!is_bsw())
|
|
|
|
return;
|
|
|
|
|
|
|
|
clkrun_val = ioread32(ilb_base_addr + LPC_CNTRL_REG_OFFSET);
|
|
|
|
|
|
|
|
/* Disable LPC CLKRUN# */
|
|
|
|
clkrun_val &= ~LPC_CLKRUN_EN;
|
|
|
|
iowrite32(clkrun_val, ilb_base_addr + LPC_CNTRL_REG_OFFSET);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write any random value on port 0x80 which is on LPC, to make
|
|
|
|
* sure LPC clock is running before sending any TPM command.
|
|
|
|
*/
|
|
|
|
outb(0xCC, 0x80);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tpm_platform_end_xfer() - set LPC CLKRUN_EN i.e. clocks can be turned off
|
|
|
|
*/
|
|
|
|
static void tpm_platform_end_xfer(void)
|
|
|
|
{
|
|
|
|
u32 clkrun_val;
|
|
|
|
|
|
|
|
if (!is_bsw())
|
|
|
|
return;
|
|
|
|
|
|
|
|
clkrun_val = ioread32(ilb_base_addr + LPC_CNTRL_REG_OFFSET);
|
|
|
|
|
|
|
|
/* Enable LPC CLKRUN# */
|
|
|
|
clkrun_val |= LPC_CLKRUN_EN;
|
|
|
|
iowrite32(clkrun_val, ilb_base_addr + LPC_CNTRL_REG_OFFSET);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write any random value on port 0x80 which is on LPC, to make
|
|
|
|
* sure LPC clock is running before sending any TPM command.
|
|
|
|
*/
|
|
|
|
outb(0xCC, 0x80);
|
|
|
|
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline bool is_bsw(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_platform_begin_xfer(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tpm_platform_end_xfer(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
static int tpm_tcg_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
|
|
|
|
u8 *result)
|
|
|
|
{
|
|
|
|
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
|
|
|
|
|
2017-06-19 02:17:59 +00:00
|
|
|
tpm_platform_begin_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
while (len--)
|
|
|
|
*result++ = ioread8(phy->iobase + addr);
|
2017-06-19 02:17:59 +00:00
|
|
|
|
|
|
|
tpm_platform_end_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tpm_tcg_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
|
|
|
|
u8 *value)
|
|
|
|
{
|
|
|
|
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
|
|
|
|
|
2017-06-19 02:17:59 +00:00
|
|
|
tpm_platform_begin_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
while (len--)
|
|
|
|
iowrite8(*value++, phy->iobase + addr);
|
2017-06-19 02:17:59 +00:00
|
|
|
|
|
|
|
tpm_platform_end_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tpm_tcg_read16(struct tpm_tis_data *data, u32 addr, u16 *result)
|
|
|
|
{
|
|
|
|
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
|
|
|
|
|
2017-06-19 02:17:59 +00:00
|
|
|
tpm_platform_begin_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
*result = ioread16(phy->iobase + addr);
|
2017-06-19 02:17:59 +00:00
|
|
|
|
|
|
|
tpm_platform_end_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tpm_tcg_read32(struct tpm_tis_data *data, u32 addr, u32 *result)
|
|
|
|
{
|
|
|
|
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
|
|
|
|
|
2017-06-19 02:17:59 +00:00
|
|
|
tpm_platform_begin_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
*result = ioread32(phy->iobase + addr);
|
2017-06-19 02:17:59 +00:00
|
|
|
|
|
|
|
tpm_platform_end_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tpm_tcg_write32(struct tpm_tis_data *data, u32 addr, u32 value)
|
|
|
|
{
|
|
|
|
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
|
|
|
|
|
2017-06-19 02:17:59 +00:00
|
|
|
tpm_platform_begin_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
iowrite32(value, phy->iobase + addr);
|
2017-06-19 02:17:59 +00:00
|
|
|
|
|
|
|
tpm_platform_end_xfer();
|
|
|
|
|
2016-05-18 22:35:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct tpm_tis_phy_ops tpm_tcg = {
|
|
|
|
.read_bytes = tpm_tcg_read_bytes,
|
|
|
|
.write_bytes = tpm_tcg_write_bytes,
|
|
|
|
.read16 = tpm_tcg_read16,
|
|
|
|
.read32 = tpm_tcg_read32,
|
|
|
|
.write32 = tpm_tcg_write32,
|
|
|
|
};
|
|
|
|
|
2017-05-04 15:53:25 +00:00
|
|
|
static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
|
2006-04-22 09:38:03 +00:00
|
|
|
{
|
2016-05-18 22:35:48 +00:00
|
|
|
struct tpm_tis_tcg_phy *phy;
|
2016-05-18 22:35:52 +00:00
|
|
|
int irq = -1;
|
2017-05-04 15:53:25 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = check_acpi_tpm2(dev);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2006-04-22 09:38:03 +00:00
|
|
|
|
2016-05-18 22:35:48 +00:00
|
|
|
phy = devm_kzalloc(dev, sizeof(struct tpm_tis_tcg_phy), GFP_KERNEL);
|
|
|
|
if (phy == NULL)
|
2014-09-24 22:41:10 +00:00
|
|
|
return -ENOMEM;
|
2014-12-12 19:46:34 +00:00
|
|
|
|
2016-05-18 22:35:48 +00:00
|
|
|
phy->iobase = devm_ioremap_resource(dev, &tpm_info->res);
|
|
|
|
if (IS_ERR(phy->iobase))
|
|
|
|
return PTR_ERR(phy->iobase);
|
2006-04-22 09:38:03 +00:00
|
|
|
|
2016-05-18 22:35:52 +00:00
|
|
|
if (interrupts)
|
|
|
|
irq = tpm_info->irq;
|
2011-03-30 16:13:33 +00:00
|
|
|
|
2017-05-04 15:53:25 +00:00
|
|
|
if (itpm || is_itpm(ACPI_COMPANION(dev)))
|
2017-01-13 21:37:00 +00:00
|
|
|
phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND;
|
2015-11-25 21:05:32 +00:00
|
|
|
|
2016-05-18 22:35:52 +00:00
|
|
|
return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg,
|
2017-05-04 15:53:25 +00:00
|
|
|
ACPI_HANDLE(dev));
|
2006-04-22 09:38:03 +00:00
|
|
|
}
|
2011-07-17 05:04:24 +00:00
|
|
|
|
2013-09-11 21:23:13 +00:00
|
|
|
static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
|
|
|
|
|
2012-11-19 18:22:42 +00:00
|
|
|
static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
|
2016-01-08 00:36:21 +00:00
|
|
|
const struct pnp_device_id *pnp_id)
|
2006-07-14 07:24:31 +00:00
|
|
|
{
|
2016-01-08 00:36:21 +00:00
|
|
|
struct tpm_info tpm_info = {};
|
2016-01-08 00:36:23 +00:00
|
|
|
struct resource *res;
|
2007-10-17 06:26:46 +00:00
|
|
|
|
2016-01-08 00:36:23 +00:00
|
|
|
res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res)
|
|
|
|
return -ENODEV;
|
|
|
|
tpm_info.res = *res;
|
2006-07-14 07:24:31 +00:00
|
|
|
|
2007-10-17 06:26:46 +00:00
|
|
|
if (pnp_irq_valid(pnp_dev, 0))
|
2015-09-28 21:32:19 +00:00
|
|
|
tpm_info.irq = pnp_irq(pnp_dev, 0);
|
2007-10-17 06:26:46 +00:00
|
|
|
else
|
2016-01-08 00:36:21 +00:00
|
|
|
tpm_info.irq = -1;
|
2007-10-17 06:26:46 +00:00
|
|
|
|
2017-05-04 15:53:25 +00:00
|
|
|
return tpm_tis_init(&pnp_dev->dev, &tpm_info);
|
2006-07-14 07:24:31 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:24:36 +00:00
|
|
|
static struct pnp_device_id tpm_pnp_tbl[] = {
|
2006-04-22 09:38:03 +00:00
|
|
|
{"PNP0C31", 0}, /* TPM */
|
2006-04-22 09:39:52 +00:00
|
|
|
{"ATM1200", 0}, /* Atmel */
|
|
|
|
{"IFX0102", 0}, /* Infineon */
|
|
|
|
{"BCM0101", 0}, /* Broadcom */
|
2008-07-26 02:44:56 +00:00
|
|
|
{"BCM0102", 0}, /* Broadcom */
|
2006-04-22 09:39:52 +00:00
|
|
|
{"NSC1200", 0}, /* National */
|
2008-07-11 00:30:42 +00:00
|
|
|
{"ICO0102", 0}, /* Intel */
|
2006-04-22 09:39:52 +00:00
|
|
|
/* Add new here */
|
|
|
|
{"", 0}, /* User Specified */
|
|
|
|
{"", 0} /* Terminator */
|
2006-04-22 09:38:03 +00:00
|
|
|
};
|
2009-11-03 01:05:50 +00:00
|
|
|
MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
|
2006-04-22 09:38:03 +00:00
|
|
|
|
2012-11-19 18:26:26 +00:00
|
|
|
static void tpm_tis_pnp_remove(struct pnp_dev *dev)
|
2008-10-10 22:04:39 +00:00
|
|
|
{
|
|
|
|
struct tpm_chip *chip = pnp_get_drvdata(dev);
|
2015-09-28 21:32:19 +00:00
|
|
|
|
2014-12-12 19:46:34 +00:00
|
|
|
tpm_chip_unregister(chip);
|
|
|
|
tpm_tis_remove(chip);
|
2008-10-10 22:04:39 +00:00
|
|
|
}
|
|
|
|
|
2006-04-22 09:38:03 +00:00
|
|
|
static struct pnp_driver tis_pnp_driver = {
|
|
|
|
.name = "tpm_tis",
|
|
|
|
.id_table = tpm_pnp_tbl,
|
|
|
|
.probe = tpm_tis_pnp_init,
|
2008-10-10 22:04:39 +00:00
|
|
|
.remove = tpm_tis_pnp_remove,
|
2013-09-11 21:23:13 +00:00
|
|
|
.driver = {
|
|
|
|
.pm = &tpm_tis_pm,
|
|
|
|
},
|
2006-04-22 09:38:03 +00:00
|
|
|
};
|
|
|
|
|
2006-04-22 09:39:52 +00: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 15:40:12 +00:00
|
|
|
|
2016-01-08 00:36:24 +00: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;
|
|
|
|
|
2017-05-04 15:53:24 +00:00
|
|
|
tpm_info.irq = platform_get_irq(pdev, 0);
|
|
|
|
if (tpm_info.irq <= 0) {
|
2017-05-04 15:53:23 +00:00
|
|
|
if (pdev != force_pdev)
|
2016-01-08 00:36:24 +00:00
|
|
|
tpm_info.irq = -1;
|
|
|
|
else
|
|
|
|
/* When forcing auto probe the IRQ */
|
|
|
|
tpm_info.irq = 0;
|
|
|
|
}
|
|
|
|
|
2017-05-04 15:53:25 +00:00
|
|
|
return tpm_tis_init(&pdev->dev, &tpm_info);
|
2016-01-08 00:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-11-07 22:44:31 +00:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id tis_of_platform_match[] = {
|
|
|
|
{.compatible = "tcg,tpm-tis-mmio"},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, tis_of_platform_match);
|
|
|
|
#endif
|
|
|
|
|
2009-02-06 15:40:12 +00:00
|
|
|
static struct platform_driver tis_drv = {
|
2016-01-08 00:36:24 +00:00
|
|
|
.probe = tpm_tis_plat_probe,
|
|
|
|
.remove = tpm_tis_plat_remove,
|
2009-02-06 15:40:12 +00:00
|
|
|
.driver = {
|
2014-12-12 19:46:34 +00:00
|
|
|
.name = "tpm_tis",
|
2012-07-06 17:09:20 +00:00
|
|
|
.pm = &tpm_tis_pm,
|
2016-11-07 22:44:31 +00:00
|
|
|
.of_match_table = of_match_ptr(tis_of_platform_match),
|
2017-05-04 15:53:25 +00:00
|
|
|
.acpi_match_table = ACPI_PTR(tpm_acpi_tbl),
|
2009-02-06 15:40:12 +00:00
|
|
|
},
|
2006-07-14 07:24:31 +00:00
|
|
|
};
|
|
|
|
|
2016-01-08 00:36:24 +00:00
|
|
|
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 09:38:03 +00:00
|
|
|
static int __init init_tis(void)
|
|
|
|
{
|
2006-07-14 07:24:31 +00:00
|
|
|
int rc;
|
2016-01-08 00:36:24 +00:00
|
|
|
|
|
|
|
rc = tpm_tis_force_device();
|
|
|
|
if (rc)
|
|
|
|
goto err_force;
|
|
|
|
|
2017-06-19 02:17:59 +00:00
|
|
|
#ifdef CONFIG_X86
|
|
|
|
if (is_bsw())
|
|
|
|
ilb_base_addr = ioremap(INTEL_LEGACY_BLK_BASE_ADDR,
|
|
|
|
ILB_REMAP_SIZE);
|
|
|
|
#endif
|
2016-01-08 00:36:24 +00:00
|
|
|
rc = platform_driver_register(&tis_drv);
|
|
|
|
if (rc)
|
|
|
|
goto err_platform;
|
|
|
|
|
2006-07-14 07:24:31 +00:00
|
|
|
|
2016-01-08 00:36:24 +00:00
|
|
|
if (IS_ENABLED(CONFIG_PNP)) {
|
|
|
|
rc = pnp_register_driver(&tis_pnp_driver);
|
|
|
|
if (rc)
|
|
|
|
goto err_pnp;
|
2006-07-14 07:24:31 +00:00
|
|
|
}
|
2016-01-08 00:36:24 +00:00
|
|
|
|
2013-04-25 07:07:47 +00:00
|
|
|
return 0;
|
2016-01-08 00:36:24 +00:00
|
|
|
|
|
|
|
err_pnp:
|
2017-02-07 15:51:47 +00:00
|
|
|
platform_driver_unregister(&tis_drv);
|
2016-01-08 00:36:24 +00:00
|
|
|
err_platform:
|
|
|
|
if (force_pdev)
|
|
|
|
platform_device_unregister(force_pdev);
|
2017-06-19 02:17:59 +00:00
|
|
|
#ifdef CONFIG_X86
|
|
|
|
if (is_bsw())
|
|
|
|
iounmap(ilb_base_addr);
|
|
|
|
#endif
|
2016-01-08 00:36:24 +00:00
|
|
|
err_force:
|
2010-05-13 20:37:54 +00:00
|
|
|
return rc;
|
2006-04-22 09:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cleanup_tis(void)
|
|
|
|
{
|
2016-01-08 00:36:24 +00:00
|
|
|
pnp_unregister_driver(&tis_pnp_driver);
|
2010-05-13 20:37:54 +00:00
|
|
|
platform_driver_unregister(&tis_drv);
|
2016-01-08 00:36:24 +00:00
|
|
|
|
2017-06-19 02:17:59 +00:00
|
|
|
#ifdef CONFIG_X86
|
|
|
|
if (is_bsw())
|
|
|
|
iounmap(ilb_base_addr);
|
|
|
|
#endif
|
2016-01-08 00:36:24 +00:00
|
|
|
if (force_pdev)
|
|
|
|
platform_device_unregister(force_pdev);
|
2006-04-22 09:38:03 +00: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");
|