Re: [PATCH v6 4/6] tpm: of: Make of-tree specific function commonly available

2022-07-20 Thread Nageswara R Sastry



> From: Stefan Berger 
> Sent: 07 July 2022 10:50 PM
> To: ke...@lists.infradead.org; devicet...@vger.kernel.org; 
> linux-integr...@vger.kernel.org; linux-ker...@vger.kernel.org; 
> linuxppc-dev@lists.ozlabs.org
> Cc: na...@linux.ibm.com; Nageswara R Sastry; m...@ellerman.id.au; Stefan 
> Berger; Jarkko Sakkinen; Jason Gunthorpe; Rob Herring; Frank Rowand
> Subject: [PATCH v6 4/6] tpm: of: Make of-tree specific function commonly 
> available

> 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 


Tested-by: Nageswara R Sastry 

Re: [PATCH v6 4/6] tpm: of: Make of-tree specific function commonly available

2022-07-12 Thread Stefan Berger




On 7/11/22 18:04, Mimi Zohar wrote:

Hi Stefan,

On Thu, 2022-07-07 at 13:20 -0400, Stefan Berger wrote:

-   /*
-* 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.
-*/


This comment is dropped.  Perhaps not in such detail, but shouldn't a
comment or function description exist in the new function.


I am adding back the comment in v7.



Otherwise,
Reviewed-by: Mimi Zohar 

thanks,

Mimi


___
kexec mailing list
ke...@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec


Re: [PATCH v6 4/6] tpm: of: Make of-tree specific function commonly available

2022-07-11 Thread Mimi Zohar
Hi Stefan,

On Thu, 2022-07-07 at 13:20 -0400, Stefan Berger wrote:
> -   /*
> -* 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.
> -*/

This comment is dropped.  Perhaps not in such detail, but shouldn't a
comment or function description exist in the new function.

Otherwise,
Reviewed-by: Mimi Zohar 

thanks,

Mimi



[PATCH v6 4/6] tpm: of: Make of-tree specific function commonly available

2022-07-07 Thread Stefan Berger
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 = >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, , );
+   if (ret < 0)
+   return ret;
 
if (size == 0) {
dev_warn(>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