From patchwork Wed Oct 15 11:35:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 399954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BDC661400B6 for ; Wed, 15 Oct 2014 22:36:12 +1100 (EST) Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XeMsE-00012k-Rd; Wed, 15 Oct 2014 11:36:10 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1XeMsD-00012c-GP for tpmdd-devel@lists.sourceforge.net; Wed, 15 Oct 2014 11:36:09 +0000 X-ACL-Warn: Received: from mga01.intel.com ([192.55.52.88]) by sog-mx-1.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1XeMsC-0002IQ-Af for tpmdd-devel@lists.sourceforge.net; Wed, 15 Oct 2014 11:36:09 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP; 15 Oct 2014 04:36:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,862,1389772800"; d="scan'208";a="400584427" Received: from sleopold-mobl.ger.corp.intel.com (HELO localhost) ([10.252.121.87]) by FMSMGA003.fm.intel.com with ESMTP; 15 Oct 2014 04:28:45 -0700 From: Jarkko Sakkinen To: Peter Huewe , Ashley Lai , Marcel Selhorst Date: Wed, 15 Oct 2014 13:35:16 +0200 Message-Id: <1413372916-12091-7-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1413372916-12091-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1413372916-12091-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Spam-Score: -0.0 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1XeMsC-0002IQ-Af Cc: christophe.ricard@gmail.com, josh.triplett@intel.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, will.c.arthur@intel.com, tpmdd-devel@lists.sourceforge.net, monty.wiseman@intel.com Subject: [tpmdd-devel] [PATCH v3 6/6] tpm: TPM 2.0 FIFO Interface X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net From: Will Arthur Detect TPM 2.0 by using the extended STS (STS3) register. For TPM 2.0, instead of calling tpm_get_timeouts(), assign duration and timeout values defined in the TPM 2.0 PTP specification. Signed-off-by: Will Arthur Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis.c | 75 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index e2cb04d..ec89c61d 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2005, 2006 IBM Corporation + * Copyright (C) 2014 Intel Corporation * * Authors: * Leendert van Doorn @@ -44,6 +45,10 @@ enum tis_status { TPM_STS_DATA_EXPECT = 0x08, }; +enum tis_status3 { + TPM_STS3_TPM2_FAM = 0x04, +}; + enum tis_int_flags { TPM_GLOBAL_INT_ENABLE = 0x80000000, TPM_INTF_BURST_COUNT_STATIC = 0x100, @@ -70,6 +75,7 @@ enum tis_defaults { #define TPM_INT_STATUS(l) (0x0010 | ((l) << 12)) #define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12)) #define TPM_STS(l) (0x0018 | ((l) << 12)) +#define TPM_STS3(l) (0x001b | ((l) << 12)) #define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12)) #define TPM_DID_VID(l) (0x0F00 | ((l) << 12)) @@ -344,6 +350,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) { int rc; u32 ordinal; + unsigned long dur; rc = tpm_tis_send_data(chip, buf, len); if (rc < 0) @@ -355,9 +362,14 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) if (chip->vendor.irq) { ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); + + if (chip->flags & TPM_CHIP_FLAG_TPM2) + dur = tpm_calc_ordinal_duration(chip, ordinal); + else + dur = tpm_calc_ordinal_duration(chip, ordinal); + if (wait_for_tpm_stat - (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, - tpm_calc_ordinal_duration(chip, ordinal), + (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, dur, &chip->vendor.read_queue, false) < 0) { rc = -ETIME; goto out_err; @@ -542,6 +554,8 @@ static int tpm_tis_init(struct device *dev, resource_size_t start, u32 vendor, intfcaps, intmask; int rc, i, irq_s, irq_e, probe; struct tpm_chip *chip; + u8 sts3; + u32 dummy; chip = tpmm_chip_alloc(dev, &tpm_tis); if (IS_ERR(chip)) @@ -551,11 +565,28 @@ static int tpm_tis_init(struct device *dev, resource_size_t start, if (!chip->vendor.iobase) return -EIO; - /* Default timeouts */ - chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); - chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); - chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); - chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); + sts3 = ioread8(chip->vendor.iobase + TPM_STS3(1)); + if (sts3 & TPM_STS3_TPM2_FAM) + chip->flags = TPM_CHIP_FLAG_TPM2; + + /* Default timeouts */ + if (chip->flags & TPM_CHIP_FLAG_TPM2) { + chip->vendor.timeout_a = usecs_to_jiffies(TPM2_TIMEOUT_A); + chip->vendor.timeout_b = usecs_to_jiffies(TPM2_TIMEOUT_B); + chip->vendor.timeout_c = usecs_to_jiffies(TPM2_TIMEOUT_C); + chip->vendor.timeout_d = usecs_to_jiffies(TPM2_TIMEOUT_D); + chip->vendor.duration[TPM_SHORT] = + usecs_to_jiffies(TPM2_DURATION_SHORT); + chip->vendor.duration[TPM_MEDIUM] = + usecs_to_jiffies(TPM2_DURATION_MEDIUM); + chip->vendor.duration[TPM_LONG] = + usecs_to_jiffies(TPM2_DURATION_LONG); + } else { + chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT); + chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT); + chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT); + chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT); + } if (wait_startup(chip, 0) != 0) { rc = -ENODEV; @@ -570,9 +601,9 @@ static int tpm_tis_init(struct device *dev, resource_size_t start, vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0)); chip->vendor.manufacturer_id = vendor; - dev_info(dev, - "1.2 TPM (device-id 0x%X, rev-id %d)\n", - vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0))); + dev_info(dev, "%s TPM (device-id 0x%X, rev-id %d)\n", + (chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2", + vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0))); if (!itpm) { probe = probe_itpm(chip); @@ -619,7 +650,11 @@ static int tpm_tis_init(struct device *dev, resource_size_t start, goto out_err; } - if (tpm_do_selftest(chip)) { + if (chip->flags & TPM_CHIP_FLAG_TPM2) + rc = tpm2_do_selftest(chip); + else + rc = tpm_do_selftest(chip); + if (rc) { dev_err(dev, "TPM self test failed\n"); rc = -ENODEV; goto out_err; @@ -680,7 +715,11 @@ static int tpm_tis_init(struct device *dev, resource_size_t start, chip->vendor.probed_irq = 0; /* Generate Interrupts */ - tpm_gen_interrupt(chip); + if (chip->flags & TPM_CHIP_FLAG_TPM2) + rc = tpm2_get_tpm_pt(chip, TPM2_CAP_TPM_PROPERTIES, &dummy, + "attempting to generate an interrupt"); + else + tpm_gen_interrupt(chip); chip->vendor.irq = chip->vendor.probed_irq; @@ -756,14 +795,18 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip) static int tpm_tis_resume(struct device *dev) { struct tpm_chip *chip = dev_get_drvdata(dev); - int ret; + int ret = 0; if (chip->vendor.irq) tpm_tis_reenable_interrupts(chip); - ret = tpm_pm_resume(dev); - if (!ret) - tpm_do_selftest(chip); + if (chip->flags & TPM_CHIP_FLAG_TPM2) + tpm2_do_selftest(chip); + else { + ret = tpm_pm_resume(dev); + if (!ret) + tpm_do_selftest(chip); + } return ret; }