From patchwork Wed Oct 5 13:12:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Winkler, Tomas" X-Patchwork-Id: 9362909 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A3C5F6075E for ; Wed, 5 Oct 2016 13:14:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90FF628696 for ; Wed, 5 Oct 2016 13:14:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 845AA286C4; Wed, 5 Oct 2016 13:14:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 633C628696 for ; Wed, 5 Oct 2016 13:14:38 +0000 (UTC) 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 1brm1r-0004Ef-UD; Wed, 05 Oct 2016 13:14:35 +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 1brm1r-0004EZ-3K for tpmdd-devel@lists.sourceforge.net; Wed, 05 Oct 2016 13:14:35 +0000 Received-SPF: fail (sog-mx-3.v43.ch3.sourceforge.com: domain of intel.com does not designate 192.55.52.120 as permitted sender) client-ip=192.55.52.120; envelope-from=tomas.winkler@intel.com; helo=mga04.intel.com; Received: from mga04.intel.com ([192.55.52.120]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1brm1q-00015I-5C for tpmdd-devel@lists.sourceforge.net; Wed, 05 Oct 2016 13:14:35 +0000 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 05 Oct 2016 06:14:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,449,1473145200"; d="scan'208";a="176626665" Received: from twinkler-lnx.jer.intel.com ([10.12.87.167]) by fmsmga004.fm.intel.com with ESMTP; 05 Oct 2016 06:14:01 -0700 From: Tomas Winkler To: tpmdd-devel@lists.sourceforge.net, Jason Gunthorpe , Jarkko Sakkinen Date: Wed, 5 Oct 2016 16:12:08 +0300 Message-Id: <1475673128-32262-1-git-send-email-tomas.winkler@intel.com> X-Mailer: git-send-email 2.7.4 X-Headers-End: 1brm1q-00015I-5C Cc: linux-kernel@vger.kernel.org Subject: [tpmdd-devel] [PATCH] tpm/tpm_crb: revamp starting method setting. 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 X-Virus-Scanned: ClamAV using ClamSMTP Encapsulate the start method parsing in a single function and add needed debug printouts. It eliminates small issue with useless double checking for ACPI_TPM2_MEMORY_MAPPED. Signed-off-by: Tomas Winkler --- drivers/char/tpm/tpm_crb.c | 65 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 15 deletions(-) diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index aa0ef742ac03..aeec313384d7 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c @@ -381,6 +381,52 @@ out: return ret; } +/** + * crb_start_method - parse starting method + * + * @device: acpi device + * @sm: starting method + * + * Return 0 if supported starting method was not found + * CRB_FL_CRB_START or CRB_FL_ACPI_START otherwise + */ +static unsigned int crb_start_method(struct acpi_device *device, u32 sm) +{ + struct device *dev = &device->dev; + u32 flags; + + switch (sm) { + /* Should the FIFO driver handle this? */ + case ACPI_TPM2_MEMORY_MAPPED: + dev_dbg(dev, "starting method[%d]: MM\n", sm); + return 0; + case ACPI_TPM2_COMMAND_BUFFER: + flags = CRB_FL_CRB_START; + dev_dbg(dev, "starting method[%d]: CB\n", sm); + break; + case ACPI_TPM2_START_METHOD: + flags = CRB_FL_ACPI_START; + dev_dbg(dev, "starting method[%d]: SM\n", sm); + break; + case ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD: + flags = CRB_FL_ACPI_START; + dev_dbg(dev, "starting method[%d]: CB w/ SM\n", + sm); + break; + default: + return 0; + } + + /* 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. + */ + if (!strcmp(acpi_device_hid(device), "MSFT0101")) + flags |= CRB_FL_CRB_START; + + return flags; +} + static int crb_acpi_add(struct acpi_device *device) { struct acpi_table_tpm2 *buf; @@ -388,7 +434,7 @@ static int crb_acpi_add(struct acpi_device *device) struct tpm_chip *chip; struct device *dev = &device->dev; acpi_status status; - u32 sm; + unsigned int sm; int rc; status = acpi_get_table(ACPI_SIG_TPM2, 1, @@ -398,26 +444,15 @@ static int crb_acpi_add(struct acpi_device *device) return -EINVAL; } - /* Should the FIFO driver handle this? */ - sm = buf->start_method; - if (sm == ACPI_TPM2_MEMORY_MAPPED) + sm = crb_start_method(device, buf->start_method); + if (!sm) return -ENODEV; priv = devm_kzalloc(dev, sizeof(struct crb_priv), GFP_KERNEL); if (!priv) return -ENOMEM; - /* 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. - */ - if (sm == ACPI_TPM2_COMMAND_BUFFER || sm == ACPI_TPM2_MEMORY_MAPPED || - !strcmp(acpi_device_hid(device), "MSFT0101")) - priv->flags |= CRB_FL_CRB_START; - - if (sm == ACPI_TPM2_START_METHOD || - sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD) - priv->flags |= CRB_FL_ACPI_START; + priv->flags = sm; rc = crb_map_io(device, priv, buf); if (rc)