From patchwork Thu Apr 7 11:18:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lino Sanfilippo X-Patchwork-Id: 12805082 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26059C433F5 for ; Thu, 7 Apr 2022 11:19:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235405AbiDGLVb (ORCPT ); Thu, 7 Apr 2022 07:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229821AbiDGLVa (ORCPT ); Thu, 7 Apr 2022 07:21:30 -0400 Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD95C19533A; Thu, 7 Apr 2022 04:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1649330355; bh=+8FAwpjcDILWSNDx21CKUAniktty0diX3BBBPxBxwd4=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=HQ7EXUW0mimX7QIrI44zFyjDh1CIh0dfexOujOd9tC4nKczWDM7KLVMS1i8p6jjsL n5MGBhKbaC36g95F/K4g/ttes1M4KPgbXK913YLQdOBfb//D6IvP8COwOO2RnB6m7Q 3pszwSvSQ7hDnM3J1JR7Kq0Z8gxaWMsDjpJlKcDc= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from Venus.fritz.box ([46.223.2.23]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Mn2W5-1oIwmS1vaJ-00k9ZU; Thu, 07 Apr 2022 13:19:15 +0200 From: Lino Sanfilippo To: peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, =robh+dt@kernel.org Cc: devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, stefanb@linux.ibm.com, p.rosenberger@kunbus.com, lukas@wunner.de, Lino Sanfilippo Subject: [PATCH 1/5] tpm: add functions to set and unset the tpm chips reset state Date: Thu, 7 Apr 2022 13:18:45 +0200 Message-Id: <20220407111849.5676-2-LinoSanfilippo@gmx.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407111849.5676-1-LinoSanfilippo@gmx.de> References: <20220407111849.5676-1-LinoSanfilippo@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:vsXneH/Z/sGRwRqqSWBf86QGc9y88g1044oI/ue+S4oOjAaxNqb CZDLh+ocCxBVvKtNTa8zcPm3jvF9NTUQLid2fGsZ5JhttpSBPCAMBaJHtKkeh2/ff1GcHsh ZO/65USFf5MPdLOAEVmhmFCVLs7vwC8ujUn5iCqXZJWyisu7QthBih+rtrhgH23WBVqWYws EzsD9GVfGv8Qn2v3gA2pQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:pNlkzPablvw=:/QgYjB7n+D6+tavd5UU/LT F/d8/GAxkJ5hYiBBQlPdml3OKDzUcWGrgydsqndoVFb8NUu7jrvL2NWkl9TUrIwcQAYLlUdlq UW/pvwERv47aNxozlZe6NOa1+eTr2O79+w3p8OcOIkkrRtwScRVqwyW23ZssOrN7ar93kfTjT LcNvVc9yzVYswD4y/YPpJFzbiQ9pHLxpp5cT0XBQqSxsGWlYxTzlpekx4A0jCToaLmBG2ucX+ LEJecDdvbHE+nTrXi4F5c9CnPO51VrqYVDk49bSY5S+YizkU/Ox9E/+GH8Zc08RNqXsHPjenK /nDrK/cVEzda36HEVbGA3uIuZewzCBYyxtGZh8n37/qPxeHDBRr/V7DFgDL2pbVVMOhBM/Lj7 z0vdFdtXDGadXfa6wHZMLXtmXeXRaQv0mmJinYOmpyHRCQXW1j25WF05TpJv0iVMiiZSnWZ44 TlSL5HPJsTyIdkq2CVFo2t8hGwp/ga0c/PQz4XM81W0Al3udM8nSude3cN6m28Ry5MQyThEBs nl9wHfkx78xStox1eQk3sq6LUO+/ZdsaWaPLOh+2mmklQnXfGn/Oohi8hKYosJy7JvUf/cqqI SNaSDioYjzEl7sl47eEp3rwr8Y7DH1Pp9k2iJ6mdztpvfqwxGJJhKE2orrWd9RCJVG08VmjyA DZwsMRqHiyqtIFapu3azOpeNCgbE6paFlTJ3sj6idSs2KvUgg2rjGFZ3IFgH9vjlq6lAFtbLh iMqMscVlGfQPz7ImS5kOv+etImzn8TmUzPfAfeEq3PHTDdp6V4rmQKbW3SA69YxA27h9dOtXY 7dx3bSeEJZfqXXYRTX4mDl1hxuqB0P8xAKDjmJHV1X8TC0rHE9hCEQvGDELE/J/jli7Gf8zav lp2K7M7xoSsdqTUUymKPrJSg7bso17x7USnn8KWpTrBUiHKSyhAce77Z2E5gQrn0y2r1lzuCE Y1tH9w9s4Tew1Vj4i0tz38bqH85oimDXf4Hs/dQlMKoB6V8C3aWuwb1ljZigroZdIqotBu4f4 JBXttiQVTW3CO6zJBw/gDRBHfgMDfpuu/FppuiH+uAR58ig1CR9y+dk4oRvF2PT/cMP34JJ9C sc5OlLBhbAYMGk= Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Currently it is not possible to set the tpm chips reset state from within the driver. This is problematic if the chip is still in reset after the system comes up. This may e.g. happen if the reset line is pulled into reset state by a pin configuration in the device tree. To handle this case extend tpm_tis_phy_ops by the two functions "set_reset" and "unset_reset" which may optionally be defined by a tpm driver. If defined call "unset_reset" at chip startup before the first tpm command is issued. Also if defined call "set_reset" at chip shutdown after the tpm2 shutdown command has been sent. Signed-off-by: Lino Sanfilippo --- drivers/char/tpm/tpm-chip.c | 5 +++++ drivers/char/tpm/tpm_tis_core.c | 3 +++ drivers/char/tpm/tpm_tis_core.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 783d65fc71f0..c1b79ba9159d 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -24,6 +24,7 @@ #include #include #include "tpm.h" +#include "tpm_tis_core.h" DEFINE_IDR(dev_nums_idr); static DEFINE_MUTEX(idr_lock); @@ -286,6 +287,7 @@ static void tpm_dev_release(struct device *dev) static int tpm_class_shutdown(struct device *dev) { struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev); + struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev); down_write(&chip->ops_sem); if (chip->flags & TPM_CHIP_FLAG_TPM2) { @@ -297,6 +299,9 @@ static int tpm_class_shutdown(struct device *dev) chip->ops = NULL; up_write(&chip->ops_sem); + if (priv->phy_ops->set_reset) + priv->phy_ops->set_reset(priv); + return 0; } diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index dc56b976d816..11e5e045f3a7 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -952,6 +952,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, dev_set_drvdata(&chip->dev, priv); + if (priv->phy_ops->unset_reset) + priv->phy_ops->unset_reset(priv); + rc = tpm_tis_read32(priv, TPM_DID_VID(0), &vendor); if (rc < 0) return rc; diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h index 3be24f221e32..f1a67445a5c5 100644 --- a/drivers/char/tpm/tpm_tis_core.h +++ b/drivers/char/tpm/tpm_tis_core.h @@ -105,6 +105,8 @@ struct tpm_tis_data { }; struct tpm_tis_phy_ops { + int (*set_reset)(struct tpm_tis_data *data); + int (*unset_reset)(struct tpm_tis_data *data); int (*read_bytes)(struct tpm_tis_data *data, u32 addr, u16 len, u8 *result); int (*write_bytes)(struct tpm_tis_data *data, u32 addr, u16 len,