Release 4.15 drivers/char/tpm/tpm_tis.c
/*
* Copyright (C) 2005, 2006 IBM Corporation
* Copyright (C) 2014, 2015 Intel Corporation
*
* Authors:
* Leendert van Doorn <leendert@watson.ibm.com>
* Kylene Hall <kjhall@us.ibm.com>
*
* Maintained by: <tpmdd-devel@lists.sourceforge.net>
*
* Device driver for TCG/TCPA TPM (trusted platform module).
* Specifications at www.trustedcomputinggroup.org
*
* This 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.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/pnp.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/wait.h>
#include <linux/acpi.h>
#include <linux/freezer.h>
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/kernel.h>
#include "tpm.h"
#include "tpm_tis_core.h"
struct tpm_info {
struct resource res;
/* irq > 0 means: use irq $irq;
* irq = 0 means: autoprobe for an irq;
* irq = -1 means: no irq support
*/
int irq;
};
struct tpm_tis_tcg_phy {
struct tpm_tis_data priv;
void __iomem *iobase;
};
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);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christophe Ricard | 25 | 100.00% | 1 | 100.00% |
Total | 25 | 100.00% | 1 | 100.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
#if defined(CONFIG_PNP) && defined(CONFIG_ACPI)
static int has_hid(struct acpi_device *dev, const char *hid)
{
struct acpi_hardware_id *id;
list_for_each_entry(id, &dev->pnp.ids, list)
if (!strcmp(hid, id->id))
return 1;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Matthew Garrett | 34 | 72.34% | 1 | 50.00% |
Jarkko Sakkinen | 13 | 27.66% | 1 | 50.00% |
Total | 47 | 100.00% | 2 | 100.00% |
static inline int is_itpm(struct acpi_device *dev)
{
if (!dev)
return 0;
return has_hid(dev, "INTC0102");
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jarkko Sakkinen | 20 | 71.43% | 1 | 50.00% |
Jason Gunthorpe | 8 | 28.57% | 1 | 50.00% |
Total | 28 | 100.00% | 2 | 100.00% |
#else
static inline int is_itpm(struct acpi_device *dev)
{
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Randy Dunlap | 14 | 93.33% | 1 | 50.00% |
Jarkko Sakkinen | 1 | 6.67% | 1 | 50.00% |
Total | 15 | 100.00% | 2 | 100.00% |
#endif
#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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jason Gunthorpe | 114 | 100.00% | 1 | 100.00% |
Total | 114 | 100.00% | 1 | 100.00% |
#else
static int check_acpi_tpm2(struct device *dev)
{
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jason Gunthorpe | 14 | 100.00% | 1 | 100.00% |
Total | 14 | 100.00% | 1 | 100.00% |
#endif
#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)
static void __iomem *ilb_base_addr;
static inline bool is_bsw(void)
{
return ((boot_cpu_data.x86_model == INTEL_FAM6_ATOM_AIRMONT) ? 1 : 0);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Azhar Shaikh | 24 | 100.00% | 1 | 100.00% |
Total | 24 | 100.00% | 1 | 100.00% |
/**
* 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);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Azhar Shaikh | 50 | 100.00% | 1 | 100.00% |
Total | 50 | 100.00% | 1 | 100.00% |
/**
* 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);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Azhar Shaikh | 49 | 100.00% | 1 | 100.00% |
Total | 49 | 100.00% | 1 | 100.00% |
#else
static inline bool is_bsw(void)
{
return false;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Azhar Shaikh | 12 | 100.00% | 1 | 100.00% |
Total | 12 | 100.00% | 1 | 100.00% |
static void tpm_platform_begin_xfer(void)
{
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Azhar Shaikh | 7 | 100.00% | 1 | 100.00% |
Total | 7 | 100.00% | 1 | 100.00% |
static void tpm_platform_end_xfer(void)
{
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Azhar Shaikh | 7 | 100.00% | 1 | 100.00% |
Total | 7 | 100.00% | 1 | 100.00% |
#endif
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);
tpm_platform_begin_xfer();
while (len--)
*result++ = ioread8(phy->iobase + addr);
tpm_platform_end_xfer();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christophe Ricard | 37 | 63.79% | 4 | 66.67% |
Jason Gunthorpe | 15 | 25.86% | 1 | 16.67% |
Azhar Shaikh | 6 | 10.34% | 1 | 16.67% |
Total | 58 | 100.00% | 6 | 100.00% |
static int tpm_tcg_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
const u8 *value)
{
struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
tpm_platform_begin_xfer();
while (len--)
iowrite8(*value++, phy->iobase + addr);
tpm_platform_end_xfer();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christophe Ricard | 39 | 66.10% | 4 | 57.14% |
Leendert van Doorn | 13 | 22.03% | 1 | 14.29% |
Azhar Shaikh | 6 | 10.17% | 1 | 14.29% |
Arnd Bergmann | 1 | 1.69% | 1 | 14.29% |
Total | 59 | 100.00% | 7 | 100.00% |
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);
tpm_platform_begin_xfer();
*result = ioread16(phy->iobase + addr);
tpm_platform_end_xfer();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christophe Ricard | 34 | 69.39% | 4 | 66.67% |
Leendert van Doorn | 9 | 18.37% | 1 | 16.67% |
Azhar Shaikh | 6 | 12.24% | 1 | 16.67% |
Total | 49 | 100.00% | 6 | 100.00% |
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);
tpm_platform_begin_xfer();
*result = ioread32(phy->iobase + addr);
tpm_platform_end_xfer();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christophe Ricard | 22 | 44.90% | 2 | 40.00% |
Leendert van Doorn | 17 | 34.69% | 1 | 20.00% |
Azhar Shaikh | 6 | 12.24% | 1 | 20.00% |
Jarkko Sakkinen | 4 | 8.16% | 1 | 20.00% |
Total | 49 | 100.00% | 5 | 100.00% |
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);
tpm_platform_begin_xfer();
iowrite32(value, phy->iobase + addr);
tpm_platform_end_xfer();
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christophe Ricard | 28 | 59.57% | 5 | 62.50% |
Leendert van Doorn | 12 | 25.53% | 1 | 12.50% |
Azhar Shaikh | 6 | 12.77% | 1 | 12.50% |
Jarkko Sakkinen | 1 | 2.13% | 1 | 12.50% |
Total | 47 | 100.00% | 8 | 100.00% |
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,
};
static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
{
struct tpm_tis_tcg_phy *phy;
int irq = -1;
int rc;
rc = check_acpi_tpm2(dev);
if (rc)
return rc;
phy = devm_kzalloc(dev, sizeof(struct tpm_tis_tcg_phy), GFP_KERNEL);
if (phy == NULL)
return -ENOMEM;
phy->iobase = devm_ioremap_resource(dev, &tpm_info->res);
if (IS_ERR(phy->iobase))
return PTR_ERR(phy->iobase);
if (interrupts)
irq = tpm_info->irq;
if (itpm || is_itpm(ACPI_COMPANION(dev)))
phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND;
return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg,
ACPI_HANDLE(dev));
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Christophe Ricard | 85 | 56.29% | 3 | 33.33% |
Jason Gunthorpe | 29 | 19.21% | 1 | 11.11% |
Stefan Berger | 20 | 13.25% | 1 | 11.11% |
Shuah Khan | 9 | 5.96% | 1 | 11.11% |
Jarkko Sakkinen | 7 | 4.64% | 2 | 22.22% |
Maciej S. Szmigiero | 1 | 0.66% | 1 | 11.11% |
Total | 151 | 100.00% | 9 | 100.00% |
static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
const struct pnp_device_id *pnp_id)
{
struct tpm_info tpm_info = {};
struct resource *res;
res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
if (!res)
return -ENODEV;
tpm_info.res = *res;
if (pnp_irq_valid(pnp_dev, 0))
tpm_info.irq = pnp_irq(pnp_dev, 0);
else
tpm_info.irq = -1;
return tpm_tis_init(&pnp_dev->dev, &tpm_info);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kylene Jo Hall | 36 | 37.89% | 1 | 20.00% |
Jason Gunthorpe | 27 | 28.42% | 2 | 40.00% |
Björn Helgaas | 23 | 24.21% | 1 | 20.00% |
Jarkko Sakkinen | 9 | 9.47% | 1 | 20.00% |
Total | 95 | 100.00% | 5 | 100.00% |
static struct pnp_device_id tpm_pnp_tbl[] = {
{"PNP0C31", 0}, /* TPM */
{"ATM1200", 0}, /* Atmel */
{"IFX0102", 0}, /* Infineon */
{"BCM0101", 0}, /* Broadcom */
{"BCM0102", 0}, /* Broadcom */
{"NSC1200", 0}, /* National */
{"ICO0102", 0}, /* Intel */
/* Add new here */
{"", 0}, /* User Specified */
{"", 0} /* Terminator */
};
MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
static void tpm_tis_pnp_remove(struct pnp_dev *dev)
{
struct tpm_chip *chip = pnp_get_drvdata(dev);
tpm_chip_unregister(chip);
tpm_tis_remove(chip);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Rajiv Andrade | 29 | 93.55% | 1 | 50.00% |
Jarkko Sakkinen | 2 | 6.45% | 1 | 50.00% |
Total | 31 | 100.00% | 2 | 100.00% |
static struct pnp_driver tis_pnp_driver = {
.name = "tpm_tis",
.id_table = tpm_pnp_tbl,
.probe = tpm_tis_pnp_init,
.remove = tpm_tis_pnp_remove,
.driver = {
.pm = &tpm_tis_pm,
},
};
#define TIS_HID_USR_IDX (ARRAY_SIZE(tpm_pnp_tbl) - 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");
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;
tpm_info.irq = platform_get_irq(pdev, 0);
if (tpm_info.irq <= 0) {
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);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jason Gunthorpe | 81 | 69.83% | 3 | 50.00% |
Kylene Jo Hall | 18 | 15.52% | 1 | 16.67% |
Jarkko Sakkinen | 14 | 12.07% | 1 | 16.67% |
Rajiv Andrade | 3 | 2.59% | 1 | 16.67% |
Total | 116 | 100.00% | 6 | 100.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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jason Gunthorpe | 37 | 100.00% | 1 | 100.00% |
Total | 37 | 100.00% | 1 | 100.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
static struct platform_driver tis_drv = {
.probe = tpm_tis_plat_probe,
.remove = tpm_tis_plat_remove,
.driver = {
.name = "tpm_tis",
.pm = &tpm_tis_pm,
.of_match_table = of_match_ptr(tis_of_platform_match),
.acpi_match_table = ACPI_PTR(tpm_acpi_tbl),
},
};
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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jason Gunthorpe | 65 | 73.03% | 1 | 33.33% |
Kylene Jo Hall | 18 | 20.22% | 1 | 33.33% |
Wei Yongjun | 6 | 6.74% | 1 | 33.33% |
Total | 89 | 100.00% | 3 | 100.00% |
static int __init init_tis(void)
{
int rc;
rc = tpm_tis_force_device();
if (rc)
goto err_force;
#ifdef CONFIG_X86
if (is_bsw())
ilb_base_addr = ioremap(INTEL_LEGACY_BLK_BASE_ADDR,
ILB_REMAP_SIZE);
#endif
rc = platform_driver_register(&tis_drv);
if (rc)
goto err_platform;
if (IS_ENABLED(CONFIG_PNP)) {
rc = pnp_register_driver(&tis_pnp_driver);
if (rc)
goto err_pnp;
}
return 0;
err_pnp:
platform_driver_unregister(&tis_drv);
err_platform:
if (force_pdev)
platform_device_unregister(force_pdev);
#ifdef CONFIG_X86
if (is_bsw())
iounmap(ilb_base_addr);
#endif
err_force:
return rc;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jason Gunthorpe | 55 | 44.35% | 1 | 16.67% |
Azhar Shaikh | 34 | 27.42% | 1 | 16.67% |
Wei Yongjun | 20 | 16.13% | 2 | 33.33% |
Kylene Jo Hall | 14 | 11.29% | 1 | 16.67% |
Jarkko Sakkinen | 1 | 0.81% | 1 | 16.67% |
Total | 124 | 100.00% | 6 | 100.00% |
static void __exit cleanup_tis(void)
{
pnp_unregister_driver(&tis_pnp_driver);
platform_driver_unregister(&tis_drv);
#ifdef CONFIG_X86
if (is_bsw())
iounmap(ilb_base_addr);
#endif
if (force_pdev)
platform_device_unregister(force_pdev);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Azhar Shaikh | 15 | 33.33% | 1 | 16.67% |
Jason Gunthorpe | 11 | 24.44% | 1 | 16.67% |
Leendert van Doorn | 8 | 17.78% | 1 | 16.67% |
Jarkko Sakkinen | 6 | 13.33% | 2 | 33.33% |
Kylene Jo Hall | 5 | 11.11% | 1 | 16.67% |
Total | 45 | 100.00% | 6 | 100.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");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jason Gunthorpe | 586 | 31.29% | 9 | 20.45% |
Christophe Ricard | 383 | 20.45% | 5 | 11.36% |
Azhar Shaikh | 258 | 13.77% | 1 | 2.27% |
Kylene Jo Hall | 173 | 9.24% | 3 | 6.82% |
Leendert van Doorn | 149 | 7.96% | 1 | 2.27% |
Jarkko Sakkinen | 90 | 4.81% | 5 | 11.36% |
Matthew Garrett | 39 | 2.08% | 1 | 2.27% |
Rajiv Andrade | 34 | 1.82% | 2 | 4.55% |
Shuah Khan | 27 | 1.44% | 1 | 2.27% |
Randy Dunlap | 26 | 1.39% | 1 | 2.27% |
Wei Yongjun | 26 | 1.39% | 2 | 4.55% |
Stefan Berger | 24 | 1.28% | 3 | 6.82% |
Björn Helgaas | 23 | 1.23% | 1 | 2.27% |
Marcin Obara | 7 | 0.37% | 1 | 2.27% |
Matt Domsch | 7 | 0.37% | 1 | 2.27% |
LE DISEZ Erwan | 7 | 0.37% | 1 | 2.27% |
Jérémy Lefaure | 4 | 0.21% | 1 | 2.27% |
Scot Doyle | 4 | 0.21% | 1 | 2.27% |
Tejun Heo | 3 | 0.16% | 1 | 2.27% |
Maciej S. Szmigiero | 1 | 0.05% | 1 | 2.27% |
Arnd Bergmann | 1 | 0.05% | 1 | 2.27% |
Colin Ian King | 1 | 0.05% | 1 | 2.27% |
Bill Pemberton | | 0.00% | 0 | 0.00% |
Total | 1873 | 100.00% | 44 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.