Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp1480239rwe; Thu, 1 Sep 2022 20:48:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Ta3IgxpGQRBotNXBou5uv6k3dfjVUzpZ9DOYi5qD6h/sXoBFV5qJGm0Yunv02yAZK5Jxy X-Received: by 2002:aa7:8a0b:0:b0:537:f5f1:fd91 with SMTP id m11-20020aa78a0b000000b00537f5f1fd91mr28832435pfa.41.1662090489762; Thu, 01 Sep 2022 20:48:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662090489; cv=none; d=google.com; s=arc-20160816; b=B74ZZshXjJoT4yLfewbW8IZdwT5VhmzDzHlpiB2WNqJKQwuhEyqM1/dnABxJobE7gh 0PGWWJIPbS2iDcPZ3WhDjzbKr2OzrWjR2zNZui4i/nhcYXe/JaKt+piwvFQqxmsrwWnR BFM/jHQB/5NicR22nh+tVb0viWOc2xihlPqhW9ypvhb+NnSSgF58eXQ7xK8e5blDXvg/ QwFaqQYKJMCAFH6Wljt13slCbi50/6ZmuJ1X0+cqXyiYFiNe+ocfVkjvVKUA6EL2qmoV mddXuZvQcsZoiF6Ox3OBWrbAaWbn7wmQpqEUaFxCjRJOr1MzqLfs56GJzmB7YH9wGCfV sZkA== 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=yZOdCGhpmoLi+MgPGM5ScgX4BwVSUkEKY20DFOwjcW0=; b=0ttnpYmfNzRfDA5gtLFZH5Pok8Q86QKm98gg0SoaMjKDcGDqeE4KKyaTcSxh1PHp8X fWB5i3S4o46tE9NTGPcV2uF20DfrnL6TSAlFcw5wttKgyNreD+LVNcspsymTNLlvNHeO UkKRMZ81SKRgDvZIkaA0YdTCRqgmuY1L0Roxxs6oTrEUkUod51avFvXzpelQD+QZ+GtS UAHN8fg2cMwaeVPCIY5PqvU25t+oCaZ2bn0acdcaYjcUwNi4kEKMJPnofC4jafTrh2zr K6QQ3r3Ds1Y+DjjQFXpQKhaaBrmmn6kbw/sg8y5jJpxwyV4Y1iAEbFlp+5s0gjvbmjqd 0TGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=GKaUWEyj; 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 g21-20020a056a0023d500b00537da3fad3bsi1047089pfc.216.2022.09.01.20.47.57; Thu, 01 Sep 2022 20:48:09 -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=GKaUWEyj; 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 S235127AbiIBDUz (ORCPT + 99 others); Thu, 1 Sep 2022 23:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229602AbiIBDUl (ORCPT ); Thu, 1 Sep 2022 23:20:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DD2429A; Thu, 1 Sep 2022 20:20:39 -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 B8DBE61EA7; Fri, 2 Sep 2022 03:20:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD6FEC433D7; Fri, 2 Sep 2022 03:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662088838; bh=BsOHRM4pj/Cx8jQlerkEmWkvN1ZmISnL0o3Je+RC3rw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GKaUWEyjbUEJRtygq8yOuDVsk1O04YnbRJGoh7VvhNd2P1rxWx4bnXqflp21EoP8j buEgk7J+cWUd5w63K33u1gmvuBgvleQoLczdUYEHhIe4b/bHpJk3wpa9oun5xIUUQn EeCzn7anOLNmtAKSVDDC6xGqxiaJwsAWqKnd8bg0koKtrvKoo5/BUx2g8iCvQd2l9R OsHcjQ2UoQlUNW460HYHQRSfenZNJxl2XpHCWCIjP/2mlhVWuKAcwFPKzQsBlnCJ5J Tku/VFuscSdEsr3TD912gdlFXx+DBeNh233eWt1mF7hudLkeKk1xz5AJ5hwz4dfmNU RjmGqaz32M8jg== Date: Fri, 2 Sep 2022 06:20:33 +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 , Mimi Zohar , Nageswara R Sastry , Coiby Xu Subject: Re: [PATCH v8 2/4] tpm: of: Make of-tree specific function commonly available Message-ID: References: <20220901214610.768645-1-stefanb@linux.ibm.com> <20220901214610.768645-3-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220901214610.768645-3-stefanb@linux.ibm.com> X-Spam-Status: No, score=-7.1 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 Thu, Sep 01, 2022 at 05:46:08PM -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 > Reviewed-by: Mimi Zohar > Tested-by: Nageswara R Sastry > Reviewed-by: Jarkko Sakkinen > Tested-by: Coiby Xu > > --- > v7: > - Added original comment back into inlined function > > v4: > - converted to inline function > --- > drivers/char/tpm/eventlog/of.c | 31 +++++------------------------ > include/linux/tpm.h | 36 ++++++++++++++++++++++++++++++++++ > 2 files changed, 41 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..6356baaa1393 100644 > --- a/include/linux/tpm.h > +++ b/include/linux/tpm.h > @@ -460,4 +460,40 @@ 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; > + > + /* > + * 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; > + } > + return 0; > +} > +#endif > + > #endif > -- > 2.35.1 > Acked-by: Jarkko Sakkinen BR, Jarkko