Skip to contentSkip to conversation

tpm: Add new vTPM device driver for PPC64

PATCH Superseded Ashley Lai 2 participants 6 messages Aug 9, 2012 – Aug 13, 2012

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ashley Lai

author Applied
#0 lore raw

v2 cover tpm: Add new vTPM device driver for PPC64

Change log V2:
- Removed unnecessary tpm_bios_log_setup and tpm_bios_log_teardown functions in tpm_eventlog.h (patch 3/3).
- Added more descriptions on vTPM (patch 1/3).

These patches add support for IBM vTPM for PPC64. This new device driver works on firmware that supports vTPM (firmware release 740 or higher).

Tested on Power7+ system with firmware level ZM770_001.

Applied to Kent Yoder patch to modularize event log located at:
https://github.com/shpedoikal/linux/tree/tpmdd-next

Ashley Lai (3):
drivers/char/tpm: Add new device driver to support IBM vTPM
PPC64: Add support for instantiating SML from Open Firmware drivers/char/tpm: Add securityfs support for event log

 arch/powerpc/kernel/prom_init.c   |   64 ++++
 drivers/char/tpm/Kconfig          |    8 +
 drivers/char/tpm/Makefile         |    9 +-
 drivers/char/tpm/tpm.h            |   13 +-
 drivers/char/tpm/tpm_eventlog.c   |    7 +
 drivers/char/tpm/tpm_eventlog.h   |   14 +
 drivers/char/tpm/tpm_ibmvtpm.c    |  750 +++++++++++++++++++++++++++++++++++++
 drivers/char/tpm/tpm_ibmvtpm.h    |   83 ++++
 drivers/char/tpm/tpm_noeventlog.c |   21 +
 drivers/char/tpm/tpm_of.c         |   68 ++++
 10 files changed, 1024 insertions(+), 13 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_ibmvtpm.c
 create mode 100644 drivers/char/tpm/tpm_ibmvtpm.h
 create mode 100644 drivers/char/tpm/tpm_noeventlog.c
 create mode 100644 drivers/char/tpm/tpm_of.c
author
#1 lore raw

PATCH v2 1/3 drivers/char/tpm: Add new device driver to support IBM vTPM

This patch adds a new device driver to support IBM virtual TPM (vTPM) for PPC64. IBM vTPM is supported through the adjunct partition with firmware release 740 or higher. With vTPM support, each lpar is able to have its own vTPM without the physical TPM hardware.

This driver provides TPM functionalities by communicating with the vTPM adjunct partition through Hypervisor calls (Hcalls) and Command/Response Queue (CRQ) commands.

---
 drivers/char/tpm/Kconfig       |    8 +
 drivers/char/tpm/Makefile      |    1 +
 drivers/char/tpm/tpm.h         |    1 +
 drivers/char/tpm/tpm_ibmvtpm.c |  750 ++++++++++++++++++++++++++++++++++++++++
 drivers/char/tpm/tpm_ibmvtpm.h |   83 +++++
 5 files changed, 843 insertions(+), 0 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_ibmvtpm.c
 create mode 100644 drivers/char/tpm/tpm_ibmvtpm.h
drivers/char/tpm/Kconfig +8 -0
index c4aac48..915875e 100644
@@ -73,4 +73,12 @@ config TCG_INFINEON
 	  Further information on this driver and the supported hardware
 	  can be found at http://www.trust.rub.de/projects/linux-device-driver-infineon-tpm/ 
 
+config TCG_IBMVTPM
+	tristate "IBM VTPM Interface"
+	depends on PPC64
+	---help---
+	  If you have IBM virtual TPM (VTPM) support say Yes and it
+	  will be accessible from within Linux.  To compile this driver
+	  as a module, choose M here; the module will be called tpm_ibmvtpm.
+
 endif # TCG_TPM
drivers/char/tpm/Makefile +1 -0
index beac52f..547509d 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
 obj-$(CONFIG_TCG_NSC) += tpm_nsc.o
 obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o
 obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o
+obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o
drivers/char/tpm/tpm.h +1 -0
index b1c5280..aece857 100644
@@ -94,6 +94,7 @@ struct tpm_vendor_specific {
 	bool timeout_adjusted;
 	unsigned long duration[3]; /* jiffies */
 	bool duration_adjusted;
+	void *data;
 
 	wait_queue_head_t read_queue;
 	wait_queue_head_t int_queue;
drivers/char/tpm/tpm_ibmvtpm.c new file +750 -0

750 lines not on this page · raw message

drivers/char/tpm/tpm_ibmvtpm.h new file +83 -0

83 lines not on this page · raw message

Signature · 1 line
1.7.1
author
#2 lore raw

PATCH v2 2/3 PPC64: Add support for instantiating SML from Open Firmware

In reply to Ashley Lai

This patch instantiate Stored Measurement Log (SML) and put the log address and size in the device tree.

---
 arch/powerpc/kernel/prom_init.c |   64 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)
arch/powerpc/kernel/prom_init.c +64 -0
index 1b488e5..3f54bd4 100644
@@ -1624,6 +1624,65 @@ static void __init prom_instantiate_rtas(void)
 
 #ifdef CONFIG_PPC64
 /*
+ * Allocate room for and instantiate Stored Measurement Log (SML)
+ */
+static void __init prom_instantiate_sml(void)
+{
+	phandle ibmvtpm_node;
+	ihandle ibmvtpm_inst;
+	u32 entry = 0, size = 0;
+	u64 base;
+
+	prom_debug("prom_instantiate_sml: start...\n");
+
+	ibmvtpm_node = call_prom("finddevice", 1, 1, ADDR("/ibm,vtpm"));
+	prom_debug("ibmvtpm_node: %x\n", ibmvtpm_node);
+	if (!PHANDLE_VALID(ibmvtpm_node))
+		return;
+
+	ibmvtpm_inst = call_prom("open", 1, 1, ADDR("/ibm,vtpm"));
+	if (!IHANDLE_VALID(ibmvtpm_inst)) {
+		prom_printf("opening vtpm package failed (%x)\n", ibmvtpm_inst);
+		return;
+	}
+
+	if (call_prom_ret("call-method", 2, 2, &size,
+			  ADDR("sml-get-handover-size"),
+			  ibmvtpm_inst) != 0) {
+		prom_printf("SML get handover size failed\n");
+		return;
+	}
+	if (size == 0)
+		return;
+
+	base = alloc_down(size, PAGE_SIZE, 0);
+	if (base == 0)
+		prom_panic("Could not allocate memory for sml\n");
+
+	prom_printf("instantiating sml at 0x%x...", base);
+
+	if (call_prom_ret("call-method", 4, 2, &entry,
+			  ADDR("sml-handover"),
+			  ibmvtpm_inst, size, base) != 0 || entry == 0) {
+		prom_printf("SML handover failed\n");
+		return;
+	}
+	prom_printf(" done\n");
+
+	reserve_mem(base, size);
+
+	prom_setprop(ibmvtpm_node, "/ibm,vtpm", "linux,sml-base",
+		     &base, sizeof(base));
+	prom_setprop(ibmvtpm_node, "/ibm,vtpm", "linux,sml-size",
+		     &size, sizeof(size));
+
+	prom_debug("sml base     = 0x%x\n", base);
+	prom_debug("sml size     = 0x%x\n", (long)size);
+
+	prom_debug("prom_instantiate_sml: end...\n");
+}
+
+/*
  * Allocate room for and initialize TCE tables
  */
 static void __init prom_initialize_tce_table(void)
@@ -2916,6 +2975,11 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
 		prom_instantiate_opal();
 #endif
 
+#ifdef CONFIG_PPC64
+	/* instantiate sml */
+	prom_instantiate_sml();
+#endif
+
 	/*
 	 * On non-powermacs, put all CPUs in spin-loops.
 	 *
Signature · 1 line
1.7.1
author
#3 lore raw

PATCH v2 3/3 drivers/char/tpm: Add securityfs support for event log

In reply to Ashley Lai

This patch retrieves the event log data from the device tree during file open. The event log data will then displayed through securityfs.

---
 drivers/char/tpm/Makefile         |    8 ++++-
 drivers/char/tpm/tpm.h            |   12 ------
 drivers/char/tpm/tpm_eventlog.c   |    7 ++++
 drivers/char/tpm/tpm_eventlog.h   |   14 +++++++
 drivers/char/tpm/tpm_noeventlog.c |   21 +++++++++++
 drivers/char/tpm/tpm_of.c         |   68 +++++++++++++++++++++++++++++++++++++
 6 files changed, 117 insertions(+), 13 deletions(-)
 create mode 100644 drivers/char/tpm/tpm_noeventlog.c
 create mode 100644 drivers/char/tpm/tpm_of.c
drivers/char/tpm/Makefile +7 -1
index 547509d..b53da57 100644
@@ -2,9 +2,15 @@
 # Makefile for the kernel tpm device drivers.
 #
 obj-$(CONFIG_TCG_TPM) += tpm.o
+obj-$(CONFIG_TCG_TPM) += tpm_bios.o
 ifdef CONFIG_ACPI
-	obj-$(CONFIG_TCG_TPM) += tpm_bios.o
 	tpm_bios-objs += tpm_eventlog.o tpm_acpi.o
+else
+ifdef CONFIG_TCG_IBMVTPM
+	tpm_bios-objs += tpm_eventlog.o tpm_of.o
+else
+	tpm_bios-objs += tpm_eventlog.o tpm_noeventlog.o
+endif
 endif
 obj-$(CONFIG_TCG_TIS) += tpm_tis.o
 obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o
drivers/char/tpm/tpm.h +0 -12
index aece857..08f6a07 100644
@@ -304,15 +304,3 @@ extern int tpm_pm_suspend(struct device *, pm_message_t);
 extern int tpm_pm_resume(struct device *);
 extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long,
 			     wait_queue_head_t *);
-#ifdef CONFIG_ACPI
-extern struct dentry ** tpm_bios_log_setup(char *);
-extern void tpm_bios_log_teardown(struct dentry **);
-#else
-static inline struct dentry ** tpm_bios_log_setup(char *name)
-{
-	return NULL;
-}
-static inline void tpm_bios_log_teardown(struct dentry **dir)
-{
-}
-#endif
drivers/char/tpm/tpm_eventlog.c +7 -0
index 84ddc55..814b202 100644
@@ -24,6 +24,7 @@
 #include <linux/security.h>
 #include <linux/module.h>
 #include <linux/slab.h>
+#include <linux/of.h>
 
 #include "tpm.h"
 #include "tpm_eventlog.h"
@@ -369,6 +370,9 @@ struct dentry **tpm_bios_log_setup(char *name)
 {
 	struct dentry **ret = NULL, *tpm_dir, *bin_file, *ascii_file;
 
+	if (TPM_NO_EVENT_LOG)
+		return NULL;
+
 	tpm_dir = securityfs_create_dir(name, NULL);
 	if (is_bad(tpm_dir))
 		goto out;
@@ -412,6 +416,9 @@ void tpm_bios_log_teardown(struct dentry **lst)
 {
 	int i;
 
+	if (TPM_NO_EVENT_LOG)
+		return;
+
 	for (i = 0; i < 3; i++)
 		securityfs_remove(lst[i]);
 }
drivers/char/tpm/tpm_eventlog.h +14 -0
index 8e23ccd..21ac6af 100644
@@ -68,4 +68,18 @@ enum tcpa_pc_event_ids {
 };
 
 int read_log(struct tpm_bios_log *log);
+
+extern struct dentry **tpm_bios_log_setup(char *);
+extern void tpm_bios_log_teardown(struct dentry **);
+
+#ifdef CONFIG_PPC64
+#define TPM_NO_EVENT_LOG !of_find_node_by_name(NULL, "ibm,vtpm")
+#else
+#ifdef CONFIG_ACPI
+#define TPM_NO_EVENT_LOG 0
+#else
+#define TPM_NO_EVENT_LOG 1
+#endif
+#endif
+
 #endif
drivers/char/tpm/tpm_noeventlog.c new file +21 -0
new file mode 100644
index 0000000..f30a2bf
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 IBM Corporation
+ *
+ * Author: Ashley Lai <[email protected]>
+ *
+ * Maintained by: <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <linux/slab.h>
+#include "tpm_eventlog.h"
+
+int read_log(struct tpm_bios_log *log)
+{
+	return -EINVAL;
+}
drivers/char/tpm/tpm_of.c new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
1.7.1
#4 lore raw

Re: [PATCH V2 3/3] drivers/char/tpm: Add securityfs support for event log

Quoted 3 lines · Ashley Lai

This patch retrieves the event log data from the device tree during file open. The event log data will then displayed through securityfs.

Hi Ashley,

Comments inline ..

Quoted 7 lines
drivers/char/tpm/Makefile +0 -0
index 547509d..b53da57 100644
@@ -2,9 +2,15 @@
 # Makefile for the kernel tpm device drivers.
 #

drivers/char/tpm/Makefile line 12

Quoted 10 lines
drivers/char/tpm/Makefile +6 -1
 obj-$(CONFIG_TCG_TPM) += tpm.o
+obj-$(CONFIG_TCG_TPM) += tpm_bios.o
 ifdef CONFIG_ACPI
-	obj-$(CONFIG_TCG_TPM) += tpm_bios.o
 	tpm_bios-objs += tpm_eventlog.o tpm_acpi.o
+else
+ifdef CONFIG_TCG_IBMVTPM
+	tpm_bios-objs += tpm_eventlog.o tpm_of.o
+else
+	tpm_bios-objs += tpm_eventlog.o tpm_noeventlog.o

What does it mean to build tpm_eventlog and tpm_noeventlog ?

Quoted 11 lines
drivers/char/tpm/tpm_eventlog.h +3 -0
index 8e23ccd..21ac6af 100644
@@ -68,4 +68,18 @@ enum tcpa_pc_event_ids {
 };
 
 int read_log(struct tpm_bios_log *log);
+
+extern struct dentry **tpm_bios_log_setup(char *);
+extern void tpm_bios_log_teardown(struct dentry **);

drivers/char/tpm/tpm_eventlog.h enum tcpa_pc_event_ids { · line 83

Quoted 10 lines
drivers/char/tpm/tpm_eventlog.h +10 -0
+
+#ifdef CONFIG_PPC64
+#define TPM_NO_EVENT_LOG !of_find_node_by_name(NULL, "ibm,vtpm")
+#else
+#ifdef CONFIG_ACPI
+#define TPM_NO_EVENT_LOG 0
+#else
+#define TPM_NO_EVENT_LOG 1
+#endif
+#endif

This should be a static inline, with the ifdefs inside.

How often is this called? of_find_node_by_name() is not particularly efficient. It might be better to search once and save a flag indicating whether you found it.

Also you must call of_node_put() on the result of of_find_node_by_name(), so at the least you must do:

struct device_node *np;
np = of_find_node_by_name(NULL, "ibm,vtpm");
of_node_put(np);
return (np != NULL);

drivers/char/tpm/tpm_noeventlog.c line 2

Quoted 9 lines
drivers/char/tpm/tpm_eventlog.h +0 -0
 #endif
drivers/char/tpm/tpm_noeventlog.c new file +2 -0
new file mode 100644
index 0000000..f30a2bf
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 IBM Corporation
                ^^

Don't use (C)

Quoted 9 lines
drivers/char/tpm/tpm_noeventlog.c new file +9 -0
+ *
+ * Author: Ashley Lai <[email protected]>
+ *
+ * Maintained by: <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.

drivers/char/tpm/tpm_noeventlog.c line 21

Quoted 10 lines
drivers/char/tpm/tpm_noeventlog.c new file +10 -0
+ *
+ */
+
+#include <linux/slab.h>
+#include "tpm_eventlog.h"
+
+int read_log(struct tpm_bios_log *log)
+{
+	return -EINVAL;
+}

Wouldn't it be simpler to put this in a header with the appropriate ifdefs, and then you'd need less logic in the Makefile?

Quoted 34 lines
drivers/char/tpm/tpm_of.c new file +28 -0
new file mode 100644
index 0000000..6d44adb
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2012 IBM Corporation
+ *
+ * Author: Ashley Lai <[email protected]>
+ *
+ * Maintained by: <[email protected]>
+ *
+ * Read the event log created by the firmware on PPC64
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/of.h>
+
+#include "tpm.h"
+#include "tpm_eventlog.h"
+
+int read_log(struct tpm_bios_log *log)
+{
+	struct device_node *np;
+	const u32 *sizep;
+	const __be64 *basep;
+

drivers/char/tpm/tpm_of.c line 38

Quoted 10 lines
drivers/char/tpm/tpm_of.c new file +10 -0
+	if (log->bios_event_log != NULL) {
+		pr_err("%s: ERROR - Eventlog already initialized\n", __func__);
+		return -EFAULT;
+	}
+
+	np = of_find_node_by_name(NULL, "ibm,vtpm");
+	if (!np) {
+		pr_err("%s: ERROR - IBMVTPM not supported\n", __func__);
+		return -ENODEV;
+	}

All your return paths below here must call of_node_put(np).

Quoted 19 lines
drivers/char/tpm/tpm_of.c new file +19 -0
+	sizep = of_get_property(np, "linux,sml-size", NULL);
+	if (sizep == NULL) {
+		pr_err("%s: ERROR - SML size not found\n", __func__);
+		return -EIO;
+	}
+	if (*sizep == 0) {
+		pr_err("%s: ERROR - event log area empty\n", __func__);
+		return -EIO;
+	}
+
+	basep = of_get_property(np, "linux,sml-base", NULL);
+	if (basep == NULL) {
+		pr_err(KERN_ERR "%s: ERROR - SML not found\n", __func__);
+		return -EIO;
+	}
+
+	log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
+	if (!log->bios_event_log) {
+		pr_err("%s: ERROR - Not enough memory for BIOS measurements\n",

drivers/char/tpm/tpm_of.c line 68

Quoted 10 lines
drivers/char/tpm/tpm_of.c new file +10 -0
+		       __func__);
+		return -ENOMEM;
+	}
+
+	log->bios_event_log_end = log->bios_event_log + *sizep;
+
+	memcpy(log->bios_event_log, __va(be64_to_cpup(basep)), *sizep);
+
+	return 0;
+}

cheers

author
#5 lore raw

Re: [PATCH V2 3/3] drivers/char/tpm: Add securityfs support for event log

Thank you so much for reviewing the code. Please see my reply below.

Quoted 20 lines · Michael Ellerman
Quoted 3 lines · Ashley Lai

This patch retrieves the event log data from the device tree during file open. The event log data will then displayed through securityfs.

Hi Ashley,

Comments inline ..

Quoted 11 lines
drivers/char/tpm/Makefile +1 -1
index 547509d..b53da57 100644
@@ -2,9 +2,15 @@
 # Makefile for the kernel tpm device drivers.
 #
 obj-$(CONFIG_TCG_TPM) += tpm.o
+obj-$(CONFIG_TCG_TPM) += tpm_bios.o
 ifdef CONFIG_ACPI
-	obj-$(CONFIG_TCG_TPM) += tpm_bios.o
Quoted 8 lines

drivers/char/tpm/Makefile line 12

Quoted 6 lines
drivers/char/tpm/Makefile +5 -0
 	tpm_bios-objs += tpm_eventlog.o tpm_acpi.o
+else
+ifdef CONFIG_TCG_IBMVTPM
+	tpm_bios-objs += tpm_eventlog.o tpm_of.o
+else
+	tpm_bios-objs += tpm_eventlog.o tpm_noeventlog.o

What does it mean to build tpm_eventlog and tpm_noeventlog ?

This is the case where the event log is not available. I agree it does not look clean. I'm thinking of moving tpm_noeventlog into header file to eliminate this file.

Quoted 10 lines
Quoted 10 lines
drivers/char/tpm/tpm_eventlog.h +0 -0
index 8e23ccd..21ac6af 100644
@@ -68,4 +68,18 @@ enum tcpa_pc_event_ids {
 };
 
Quoted 16 lines
Quoted 4 lines
drivers/char/tpm/tpm_eventlog.h +3 -0
 int read_log(struct tpm_bios_log *log);
+
+extern struct dentry **tpm_bios_log_setup(char *);
+extern void tpm_bios_log_teardown(struct dentry **);

drivers/char/tpm/tpm_eventlog.h enum tcpa_pc_event_ids { · line 83

Quoted 10 lines
drivers/char/tpm/tpm_eventlog.h +10 -0
+
+#ifdef CONFIG_PPC64
+#define TPM_NO_EVENT_LOG !of_find_node_by_name(NULL, "ibm,vtpm")
+#else
+#ifdef CONFIG_ACPI
+#define TPM_NO_EVENT_LOG 0
+#else
+#define TPM_NO_EVENT_LOG 1
+#endif
+#endif

This should be a static inline, with the ifdefs inside.

I just realized that it does not need to call of_find_node_by_name() here because if ibm,vtpm is not there it does not go to probe. Thanks for pointing this out.

Quoted 4 lines

How often is this called? of_find_node_by_name() is not particularly efficient. It might be better to search once and save a flag indicating whether you found it.

This is called during load and unload of the driver. I'll remove the call to of_find_node_by_name() in next version. See above.

Quoted 3 lines

Also you must call of_node_put() on the result of of_find_node_by_name(), so at the least you must do:

Nice catch!!! I will fix other places in the code in the next version.

Quoted 16 lines

struct device_node *np;
np = of_find_node_by_name(NULL, "ibm,vtpm");
of_node_put(np);
return (np != NULL);

drivers/char/tpm/tpm_noeventlog.c line 2

Quoted 9 lines
drivers/char/tpm/tpm_eventlog.h +0 -0
 #endif
drivers/char/tpm/tpm_noeventlog.c new file +2 -0
new file mode 100644
index 0000000..f30a2bf
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2012 IBM Corporation
                ^^
Quoted 1 line

Don't use (C)

Will remove it.

Quoted 15 lines
Quoted 15 lines
drivers/char/tpm/tpm_noeventlog.c new file +14 -0
+ *
+ * Author: Ashley Lai <[email protected]>
+ *
+ * Maintained by: <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <linux/slab.h>
+#include "tpm_eventlog.h"
Quoted 8 lines

drivers/char/tpm/tpm_noeventlog.c line 21

Quoted 5 lines
drivers/char/tpm/tpm_noeventlog.c new file +5 -0
+
+int read_log(struct tpm_bios_log *log)
+{
+	return -EINVAL;
+}

Wouldn't it be simpler to put this in a header with the appropriate ifdefs, and then you'd need less logic in the Makefile?

Will move this to header file. Thanks.

Quoted 40 lines
Quoted 40 lines
drivers/char/tpm/tpm_of.c new file +32 -0
new file mode 100644
index 0000000..6d44adb
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2012 IBM Corporation
+ *
+ * Author: Ashley Lai <[email protected]>
+ *
+ * Maintained by: <[email protected]>
+ *
+ * Read the event log created by the firmware on PPC64
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/of.h>
+
+#include "tpm.h"
+#include "tpm_eventlog.h"
+
+int read_log(struct tpm_bios_log *log)
+{
+	struct device_node *np;
+	const u32 *sizep;
+	const __be64 *basep;
+
+	if (log->bios_event_log != NULL) {
+		pr_err("%s: ERROR - Eventlog already initialized\n", __func__);
+		return -EFAULT;
+	}
Quoted 8 lines

drivers/char/tpm/tpm_of.c line 38

Quoted 6 lines
drivers/char/tpm/tpm_of.c new file +6 -0
+
+	np = of_find_node_by_name(NULL, "ibm,vtpm");
+	if (!np) {
+		pr_err("%s: ERROR - IBMVTPM not supported\n", __func__);
+		return -ENODEV;
+	}

All your return paths below here must call of_node_put(np).

I'll fix it in next version. Thanks.

Quoted 34 lines
Quoted 20 lines
drivers/char/tpm/tpm_of.c new file +19 -0
+	sizep = of_get_property(np, "linux,sml-size", NULL);
+	if (sizep == NULL) {
+		pr_err("%s: ERROR - SML size not found\n", __func__);
+		return -EIO;
+	}
+	if (*sizep == 0) {
+		pr_err("%s: ERROR - event log area empty\n", __func__);
+		return -EIO;
+	}
+
+	basep = of_get_property(np, "linux,sml-base", NULL);
+	if (basep == NULL) {
+		pr_err(KERN_ERR "%s: ERROR - SML not found\n", __func__);
+		return -EIO;
+	}
+
+	log->bios_event_log = kmalloc(*sizep, GFP_KERNEL);
+	if (!log->bios_event_log) {
+		pr_err("%s: ERROR - Not enough memory for BIOS measurements\n",

drivers/char/tpm/tpm_of.c line 68

Quoted 10 lines
drivers/char/tpm/tpm_of.c new file +10 -0
+		       __func__);
+		return -ENOMEM;
+	}
+
+	log->bios_event_log_end = log->bios_event_log + *sizep;
+
+	memcpy(log->bios_event_log, __va(be64_to_cpup(basep)), *sizep);
+
+	return 0;
+}

cheers