From patchwork Fri Jun 17 21:10:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9185027 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 8A61E608A2 for ; Fri, 17 Jun 2016 21:12:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D7C527D45 for ; Fri, 17 Jun 2016 21:12:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51C1B27F07; Fri, 17 Jun 2016 21:12:55 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA0D127D45 for ; Fri, 17 Jun 2016 21:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753428AbcFQVLK (ORCPT ); Fri, 17 Jun 2016 17:11:10 -0400 Received: from mga14.intel.com ([192.55.52.115]:3086 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751219AbcFQVLH (ORCPT ); Fri, 17 Jun 2016 17:11:07 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 17 Jun 2016 14:11:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,485,1459839600"; d="scan'208";a="990081096" Received: from unknown (HELO localhost) ([10.252.61.71]) by fmsmga001.fm.intel.com with ESMTP; 17 Jun 2016 14:11:03 -0700 From: Jarkko Sakkinen To: Peter Huewe , Jason Gunthorpe Cc: linux-security-module@vger.kernel.org, Stefan Berger , Jarkko Sakkinen , Marcel Selhorst , tpmdd-devel@lists.sourceforge.net (moderated list:TPM DEVICE DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 1/5] tpm: unify tpm_gen_interrupt() Date: Fri, 17 Jun 2016 23:10:43 +0200 Message-Id: <1466197847-4937-2-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1466197847-4937-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1466197847-4937-1-git-send-email-jarkko.sakkinen@linux.intel.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Migrated into single tpm_gen_interrupt() function and cleaned up the whole construction in general because it was starting to turn into a train wreck. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm-interface.c | 23 ++++++++++++++--------- drivers/char/tpm/tpm.h | 3 +-- drivers/char/tpm/tpm2-cmd.c | 17 ----------------- drivers/char/tpm/tpm_tis_core.c | 5 +---- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index 5e3c1b6..e953618 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c @@ -459,18 +459,23 @@ ssize_t tpm_getcap(struct tpm_chip *chip, __be32 subcap_id, cap_t *cap, return rc; } +/** + * tpm_gen_interrupt -- generate an interrupt by issuing an idempotent command + * @chip: TPM chip to use + * + * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing + * a TPM error code. + */ void tpm_gen_interrupt(struct tpm_chip *chip) { - struct tpm_cmd_t tpm_cmd; - ssize_t rc; + const char *desc = "attempting to generate an interrupt"; + u32 cap2; + cap_t cap; - tpm_cmd.header.in = tpm_getcap_header; - tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; - tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); - tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; - - rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, - "attempting to determine the timeouts"); + if (chip->flags & TPM_CHIP_FLAG_TPM2) + tpm2_get_tpm_pt(chip, 0x100, &cap2, desc); + else + tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, desc); } EXPORT_SYMBOL_GPL(tpm_gen_interrupt); diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 8890df2..276a3c5 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -483,7 +483,7 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, ssize_t tpm_transmit_cmd(struct tpm_chip *chip, void *cmd, int len, const char *desc); extern int tpm_get_timeouts(struct tpm_chip *); -extern void tpm_gen_interrupt(struct tpm_chip *); +void tpm_gen_interrupt(struct tpm_chip *); extern int tpm_do_selftest(struct tpm_chip *); extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32); extern int tpm_pm_suspend(struct device *); @@ -530,6 +530,5 @@ extern int tpm2_startup(struct tpm_chip *chip, u16 startup_type); extern void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); extern unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *, u32); extern int tpm2_do_selftest(struct tpm_chip *chip); -extern int tpm2_gen_interrupt(struct tpm_chip *chip); extern int tpm2_probe(struct tpm_chip *chip); #endif diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index a1673dc..77ef027 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c @@ -897,23 +897,6 @@ int tpm2_do_selftest(struct tpm_chip *chip) EXPORT_SYMBOL_GPL(tpm2_do_selftest); /** - * tpm2_gen_interrupt() - generate an interrupt - * @chip: TPM chip to use - * - * 0 is returned when the operation is successful. If a negative number is - * returned it remarks a POSIX error code. If a positive number is returned - * it remarks a TPM error. - */ -int tpm2_gen_interrupt(struct tpm_chip *chip) -{ - u32 dummy; - - return tpm2_get_tpm_pt(chip, 0x100, &dummy, - "attempting to generate an interrupt"); -} -EXPORT_SYMBOL_GPL(tpm2_gen_interrupt); - -/** * tpm2_probe() - probe TPM 2.0 * @chip: TPM chip to use * diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index 03a06b3..c7dc58d 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -580,10 +580,7 @@ static int tpm_tis_probe_irq_single(struct tpm_chip *chip, u32 intmask, /* Generate an interrupt by having the core call through to * tpm_tis_send */ - if (chip->flags & TPM_CHIP_FLAG_TPM2) - tpm2_gen_interrupt(chip); - else - tpm_gen_interrupt(chip); + tpm_gen_interrupt(chip); /* tpm_tis_send will either confirm the interrupt is working or it * will call disable_irq which undoes all of the above.