From patchwork Wed Feb 17 11:23:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 584061 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 1691A1400A0 for ; Wed, 17 Feb 2016 22:23:58 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aW0Cv-0004yl-AY; Wed, 17 Feb 2016 11:23:45 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1aW0Ct-0004yf-Op for tpmdd-devel@lists.sourceforge.net; Wed, 17 Feb 2016 11:23:43 +0000 X-ACL-Warn: Received: from mga02.intel.com ([134.134.136.20]) by sog-mx-3.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1aW0Cr-0005U9-06 for tpmdd-devel@lists.sourceforge.net; Wed, 17 Feb 2016 11:23:43 +0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP; 17 Feb 2016 03:23:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,460,1449561600"; d="scan'208";a="49386246" Received: from mpouesse-mobl.ger.corp.intel.com (HELO localhost) ([10.252.29.20]) by fmsmga004.fm.intel.com with ESMTP; 17 Feb 2016 03:23:33 -0800 From: Jarkko Sakkinen To: Peter Huewe Date: Wed, 17 Feb 2016 13:23:31 +0200 Message-Id: <1455708211-9653-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.7.0 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 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1aW0Cr-0005U9-06 Cc: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Subject: [tpmdd-devel] [PATCH] tpm_crb: fix: associate to the correct device 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 At the moment for tpm_crb /proc/iomem shows the HW interface and not the device using the memory range. This patch fixes the issue by associating memory mappings to the TPM character device. The end result is this: $ cat /proc/iomem|grep MSFT -A2 dbfff000-dbffffff : MSFT0101:00 dbfff000-dbffffff : tpm0 Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_crb.c | 93 ++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index 151689d..e0d9fbe 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c @@ -198,30 +198,6 @@ static const struct tpm_class_ops tpm_crb = { .req_complete_val = CRB_STS_COMPLETE, }; -static int crb_init(struct acpi_device *device, struct crb_priv *priv) -{ - struct tpm_chip *chip; - int rc; - - chip = tpmm_chip_alloc(&device->dev, &tpm_crb); - if (IS_ERR(chip)) - return PTR_ERR(chip); - - chip->vendor.priv = priv; - chip->acpi_dev_handle = device->handle; - chip->flags = TPM_CHIP_FLAG_TPM2; - - rc = tpm_get_timeouts(chip); - if (rc) - return rc; - - rc = tpm2_do_selftest(chip); - if (rc) - return rc; - - return tpm_chip_register(chip); -} - static int crb_check_resource(struct acpi_resource *ares, void *data) { struct crb_priv *priv = data; @@ -256,32 +232,15 @@ static void __iomem *crb_map_res(struct device *dev, struct crb_priv *priv, return priv->iobase + (new_res.start - priv->res.start); } -static int crb_map_io(struct acpi_device *device, struct crb_priv *priv, - struct acpi_table_tpm2 *buf) +static int crb_map_io(struct device *dev, u64 cca_pa, struct crb_priv *priv) { - struct list_head resources; - struct device *dev = &device->dev; u64 pa; - int ret; - - INIT_LIST_HEAD(&resources); - ret = acpi_dev_get_resources(device, &resources, crb_check_resource, - priv); - if (ret < 0) - return ret; - acpi_dev_free_resource_list(&resources); - - if (resource_type(&priv->res) != IORESOURCE_MEM) { - dev_err(dev, - FW_BUG "TPM2 ACPI table does not define a memory resource\n"); - return -EINVAL; - } priv->iobase = devm_ioremap_resource(dev, &priv->res); if (IS_ERR(priv->iobase)) return PTR_ERR(priv->iobase); - priv->cca = crb_map_res(dev, priv, buf->control_address, 0x1000); + priv->cca = crb_map_res(dev, priv, cca_pa, 0x1000); if (IS_ERR(priv->cca)) return PTR_ERR(priv->cca); @@ -297,11 +256,41 @@ static int crb_map_io(struct acpi_device *device, struct crb_priv *priv, return PTR_ERR_OR_ZERO(priv->rsp); } +static int crb_init(struct acpi_device *device, u64 cca_pa, + struct crb_priv *priv) +{ + struct tpm_chip *chip; + int rc; + + chip = tpmm_chip_alloc(&device->dev, &tpm_crb); + if (IS_ERR(chip)) + return PTR_ERR(chip); + + chip->vendor.priv = priv; + chip->acpi_dev_handle = device->handle; + chip->flags = TPM_CHIP_FLAG_TPM2; + + rc = crb_map_io(&chip->dev, cca_pa, priv); + if (rc) + return rc; + + rc = tpm_get_timeouts(chip); + if (rc) + return rc; + + rc = tpm2_do_selftest(chip); + if (rc) + return rc; + + return tpm_chip_register(chip); +} + static int crb_acpi_add(struct acpi_device *device) { struct acpi_table_tpm2 *buf; struct crb_priv *priv; struct device *dev = &device->dev; + struct list_head resources; acpi_status status; u32 sm; int rc; @@ -322,6 +311,18 @@ static int crb_acpi_add(struct acpi_device *device) if (!priv) return -ENOMEM; + INIT_LIST_HEAD(&resources); + rc = acpi_dev_get_resources(device, &resources, crb_check_resource, + priv); + if (rc < 0) + return rc; + acpi_dev_free_resource_list(&resources); + + if (resource_type(&priv->res) != IORESOURCE_MEM) { + dev_err(dev, FW_BUG "The ACPI device does not have a memory resource\n"); + return -EINVAL; + } + /* The reason for the extra quirk is that the PTT in 4th Gen Core CPUs * report only ACPI start but in practice seems to require both * ACPI start and CRB start. @@ -334,11 +335,7 @@ static int crb_acpi_add(struct acpi_device *device) sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD) priv->flags |= CRB_FL_ACPI_START; - rc = crb_map_io(device, priv, buf); - if (rc) - return rc; - - return crb_init(device, priv); + return crb_init(device, buf->control_address, priv); } static int crb_acpi_remove(struct acpi_device *device)