Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2939150imw; Sun, 10 Jul 2022 20:17:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tR3Sur9NwQdmerl7nytRLRxUcF6E9GXzM6cV0xvTfWOKtf8zTmnvkdmbAs+5xH0rDHOo3C X-Received: by 2002:a17:902:9004:b0:16a:6808:e602 with SMTP id a4-20020a170902900400b0016a6808e602mr16632086plp.94.1657509438352; Sun, 10 Jul 2022 20:17:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657509438; cv=none; d=google.com; s=arc-20160816; b=lkLxja8Y83/k9xAYNrfO+PzSE8kyJd8c0YfRC0K4XmcEYW5/d9PSwwix9VkJK/rsgk GUs4GfxFk8fVQCwBSOWu2IapB+djmFQIlBmksXYCdPe7dwgRa5Hd9KypI1CtCK/v7t/G P37rLFFdA9aifQD4h7TM94JyAOXJmD7qOyaBqDbmpPIX4TV1vWzVyy5JnYtktk44UhqQ 1cv+tqeGP9s32nJzLFj96pc81yXJvNgjRj/Or42MSNPDzgKgCas8ZeOsgbsArXAaBi8O rkpNytCjE2dy7hzry+qbL7t1txq0F4k6qltY8BTsVq76aykXuVwWryOcU8Yood3z6gVu GQCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3ecYyXTrN+diimZVnGvPsRjSAAHM7PiSg/o+T0+Gbwc=; b=RCEDYhaB0rcc5ym50bXRReWyug3xfn77a7591OV9vdcCGZNNg0x2Ogf85AYr+dsjIx z9y/rEmJZeu3J67i/GDhw3E90RqjgtQuqaErs6/gvAKopQfB0jhWsBq5yXNMvyv5qIjg UJMAnp3Eoa9z2/5ee5ZGNZ2UFcAVQHeb3l11HT6ZiuNl2bFo8Cbv79/u6tUmOpDhDPB9 JQlFBHqschPgrcu31GKLPxranX3UeBmKp7WsfGX5jx67x3WS2cj5xHh8Vb6mKivMxN23 RCLWduei4dcyXI1+kv+hHkzjZ/yGRsxzw4zME0AAPxAqNEh07A3dAxtzCJroM+L9eq7n iHdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mbkI4rxE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j12-20020a17090276cc00b00163a65d92desi8028811plt.267.2022.07.10.20.17.04; Sun, 10 Jul 2022 20:17:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mbkI4rxE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbiGKDEq (ORCPT + 99 others); Sun, 10 Jul 2022 23:04:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiGKDEp (ORCPT ); Sun, 10 Jul 2022 23:04:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A9BE186D7; Sun, 10 Jul 2022 20:04:44 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 06ECA6111B; Mon, 11 Jul 2022 03:04:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D022CC3411E; Mon, 11 Jul 2022 03:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657508683; bh=2qgfVdj8tvTCH2jYcKrpZ5Snk3LhfgSEv3T6kIahGWI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mbkI4rxEMLL92W1bpiBd/cttlQzNlLGKIfErZJYzed5mizc3O4JeX3w7OwxR0Hi3g vYKvR32OoSTzsZOBqt2zxcyULxu1tX0SlEAKBloPJP/8PUaTbKZQcqwQTAtEZLXaRj 7xdUWBHYfOXyUCf2JWtVh3QK+fRvCgvzpiwgoMfDHV8/HtPhwIzuBes3xTJZmjLCb3 qx6Ni85gFvI1A0C4PS1kgqnp2EhXEvRhWRn4Xjm+/PBMo5YRq5eAOFIzXA5u88iziA MevgLPsvMtTO3Ii6wg+K+fA1zj1lEibb837/esD2mtKfyuvFr0IUIsft5bGNXBma3c LuTG/JPhAFoGQ== Date: Mon, 11 Jul 2022 06:04:38 +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 v5 4/6] tpm: of: Make of-tree specific function commonly available Message-ID: References: <20220706152329.665636-1-stefanb@linux.ibm.com> <20220706152329.665636-5-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220706152329.665636-5-stefanb@linux.ibm.com> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 06, 2022 at 11:23:27AM -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