From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 935C4C433EF for ; Mon, 11 Jul 2022 00:01:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=0h1OZrmBJ5GLbkgHIFwWP/PLB9ts24wwtQ9hn47BXgE=; b=keZqcKMslW6k+k AYRzTEQRVmwzeWZmodI269SgMP+ZVrOKhp/0ccznOtEA7vrr3dlly8eoyXcTohQ6J+4aTIOTfLAkm ogPWarryMkrprnhCoC65DJa2epdZso61OrzuJXBqlk9xOqxIirfXv1nrhR5xTAQeRDZHlp2w3MG7o fobZpijuR06Fp6zWnmwlwmfAkPK8DdjA5aUIIl9JxZ6sbBK+Dsf/85RH23mqeCIQZaBnwXxIQKqSo c5lB9r7s9PGArqbV11jv5A3ygZ5dxHUuFaIxnc4kHvWr9+QnQH8ZBBEqiV8dORkV9Mai7Wl0UuB6k tc6BdZ/R/NSMk4oeUQ/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAgrr-00EVKs-D3; Mon, 11 Jul 2022 00:01:39 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAgro-00EVGK-0f for kexec@lists.infradead.org; Mon, 11 Jul 2022 00:01:37 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 67CFDB80C6A; Mon, 11 Jul 2022 00:01:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C12FC3411E; Mon, 11 Jul 2022 00:01:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657497691; bh=TlKLPcBbz3RbDuAHDfDGZpSXrFAFDL26YjdPaucaCzw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TM0tqX+WVO1YhtmTQj6f3/iwtJ9vXQmF/+f23nkkdRjQm/qtjCTQE5K0/ykfIyDWz m462R4ubh/OY87QYnG0uWBV/1gTLLlqsQtRg2gd+80nU5nyvYYGMc1dFoahy1XtsDv GomSv43YdZTK/luiQlUzKeAYIC14VaQGNT14BMhNDwDSM6dVEIFBxbXhqsZhcDFXJW d+LWMuuPK7ZvTaUwyYREKLvPsN93GRqjaLwJ0q622KKFzCMTVJNHyBLc2ZpH2Sns0J QGe4GQeA3z6pVIBMoavuGt9IG2lvU9YKLXCYa82ESk3AsXkbPyH87XFvs6wYXWU5yK VEw30aJNXttSQ== Date: Mon, 11 Jul 2022 03:01:25 +0300 From: Jarkko Sakkinen To: Stefan Berger Cc: kexec@lists.infradead.org, devicetree@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, nayna@linux.ibm.com, nasastry@in.ibm.com, mpe@ellerman.id.au, Jason Gunthorpe , Rob Herring , Frank Rowand Subject: Re: [PATCH v4 3/5] tpm: of: Make of-tree specific function commonly available Message-ID: References: <20220701022603.31076-1-stefanb@linux.ibm.com> <20220701022603.31076-4-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220701022603.31076-4-stefanb@linux.ibm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220710_170136_399858_7FC114CF X-CRM114-Status: GOOD ( 26.83 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org On Thu, Jun 30, 2022 at 10:26:01PM -0400, Stefan Berger wrote: > Simplify tpm_read_log_of() by moving reusable parts of the code into > an inline function that makes it commonly available so it can be > used also for kexec support. Call the new of_tpm_get_sml_parameters() > function from the TPM Open Firmware driver. > > Signed-off-by: Stefan Berger > Cc: Jarkko Sakkinen > Cc: Jason Gunthorpe > Cc: Rob Herring > Cc: Frank Rowand > > --- > v4: > - converted to inline function > --- > drivers/char/tpm/eventlog/of.c | 31 +++++-------------------------- > include/linux/tpm.h | 27 +++++++++++++++++++++++++++ > 2 files changed, 32 insertions(+), 26 deletions(-) > > diff --git a/drivers/char/tpm/eventlog/of.c b/drivers/char/tpm/eventlog/of.c > index a9ce66d09a75..f9462d19632e 100644 > --- a/drivers/char/tpm/eventlog/of.c > +++ b/drivers/char/tpm/eventlog/of.c > @@ -12,6 +12,7 @@ > > #include > #include > +#include > #include > > #include "../tpm.h" > @@ -20,11 +21,10 @@ > int tpm_read_log_of(struct tpm_chip *chip) > { > struct device_node *np; > - const u32 *sizep; > - const u64 *basep; > struct tpm_bios_log *log; > u32 size; > u64 base; > + int ret; > > log = &chip->log; > if (chip->dev.parent && chip->dev.parent->of_node) > @@ -35,30 +35,9 @@ int tpm_read_log_of(struct tpm_chip *chip) > if (of_property_read_bool(np, "powered-while-suspended")) > chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED; > > - sizep = of_get_property(np, "linux,sml-size", NULL); > - basep = of_get_property(np, "linux,sml-base", NULL); > - if (sizep == NULL && basep == NULL) > - return -ENODEV; > - if (sizep == NULL || basep == NULL) > - return -EIO; > - > - /* > - * For both vtpm/tpm, firmware has log addr and log size in big > - * endian format. But in case of vtpm, there is a method called > - * sml-handover which is run during kernel init even before > - * device tree is setup. This sml-handover function takes care > - * of endianness and writes to sml-base and sml-size in little > - * endian format. For this reason, vtpm doesn't need conversion > - * but physical tpm needs the conversion. > - */ > - if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 && > - of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) { > - size = be32_to_cpup((__force __be32 *)sizep); > - base = be64_to_cpup((__force __be64 *)basep); > - } else { > - size = *sizep; > - base = *basep; > - } > + ret = of_tpm_get_sml_parameters(np, &base, &size); > + if (ret < 0) > + return ret; > > if (size == 0) { > dev_warn(&chip->dev, "%s: Event log area empty\n", __func__); > diff --git a/include/linux/tpm.h b/include/linux/tpm.h > index dfeb25a0362d..b3dff255bc58 100644 > --- a/include/linux/tpm.h > +++ b/include/linux/tpm.h > @@ -460,4 +460,31 @@ static inline struct tpm_chip *tpm_default_chip(void) > return NULL; > } > #endif > + > +#ifdef CONFIG_OF > +static inline int of_tpm_get_sml_parameters(struct device_node *np, > + u64 *base, u32 *size) > +{ > + const u32 *sizep; > + const u64 *basep; > + > + sizep = of_get_property(np, "linux,sml-size", NULL); > + basep = of_get_property(np, "linux,sml-base", NULL); > + if (sizep == NULL && basep == NULL) > + return -ENODEV; > + if (sizep == NULL || basep == NULL) > + return -EIO; > + > + if (of_property_match_string(np, "compatible", "IBM,vtpm") < 0 && > + of_property_match_string(np, "compatible", "IBM,vtpm20") < 0) { > + *size = be32_to_cpup((__force __be32 *)sizep); > + *base = be64_to_cpup((__force __be64 *)basep); > + } else { > + *size = *sizep; > + *base = *basep; > + } > + return 0; > +} > +#endif > + > #endif > -- > 2.35.1 > Reviewed-by: Jarkko Sakkinen BR, Jarkko _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec