[Skiboot] [PATCH v2 29/31] libstb/tpm_chip: register firwmare event log

Claudio Carvalho cclaudio at linux.vnet.ibm.com
Wed Sep 28 18:01:28 AEST 2016


This registers the firmware event log defined in the tpm device tree
node.

Signed-off-by: Claudio Carvalho <cclaudio at linux.vnet.ibm.com>
---
 libstb/tpm_chip.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 libstb/tpm_chip.h |  6 ++++++
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/libstb/tpm_chip.c b/libstb/tpm_chip.c
index 945d98e..91efa3a 100644
--- a/libstb/tpm_chip.c
+++ b/libstb/tpm_chip.c
@@ -29,6 +29,8 @@ int tpm_register_chip(struct dt_node *node, struct tpm_dev *dev,
 		       struct tpm_driver *driver)
 {
 	int i, rc;
+	uint64_t sml_base;
+	uint32_t sml_size;
 	struct tpm_chip *tpm;
 
 	i = 0;
@@ -51,6 +53,63 @@ int tpm_register_chip(struct dt_node *node, struct tpm_dev *dev,
 	assert(tpm);
 	tpm->id = i;
 
+	/*
+	 * Read event log info from the tpm device tree node. Both
+	 * linux,sml-base and linux,sml-size properties are documented in
+	 * 'doc/device-tree/tpm.rst'
+	 */
+
+	sml_base = dt_prop_get_u64_def(node, "linux,sml-base", 0);
+
+	/* Check if sml-base is really 0 or it just doesn't exist */
+	if (!sml_base &&
+	    !dt_find_property(node, "linux,sml-base")) {
+		/**
+		 * @fwts-label TPMSmlBaseNotFound
+		 * @fwts-advice linux,sml-base property not found. This
+		 * indicates a Hostboot bug if the property really
+		 * doesn't exist in the tpm node.
+		 */
+		prlog(PR_ERR, "TPM: linux,sml-base property not found "
+		      "tpm node %p\n", node);
+		goto disable;
+	}
+
+	sml_size = dt_prop_get_u32_def(node, "linux,sml-size", 0);
+
+	if (!sml_size) {
+		/**
+		 * @fwts-label TPMSmlSizeNotFound
+		 * @fwts-advice linux,sml-size property not found. This
+		 * indicates a Hostboot bug if the property really
+		 * doesn't exist in the tpm node.
+		 */
+		prlog(PR_ERR, "TPM: linux,sml-size property not found, "
+		      "tpm node %p\n", node);
+		goto disable;
+	}
+
+	/*
+	 * Initialize the event log manager by walking through the log to identify
+	 * what is the next free position in the log
+	 */
+	rc = TpmLogMgr_initializeUsingExistingLog(&tpm->logmgr,
+					 (uint8_t*) sml_base, sml_size);
+
+	if (rc) {
+		/**
+		 * @fwts-label TPMInitEventLogFailed
+		 * @fwts-advice Hostboot creates and adds entries to the
+		 * event log. The failed init function is part of hostboot,
+		 * but the source code is shared with skiboot. If the hostboot
+		 * TpmLogMgr code (or friends) has been updated, the changes
+		 * need to be applied to skiboot as well.
+		 */
+		prlog(PR_ERR, "TPM: eventlog init failed: tpm%d rc=%d",
+		      tpm->id, rc);
+		goto disable;
+	}
+
 	tpm->enabled = true;
 	tpm->node = node;
 	tpm->dev = dev;
@@ -58,8 +117,8 @@ int tpm_register_chip(struct dt_node *node, struct tpm_dev *dev,
 
 	list_add_tail(&tpm_list, &tpm->link);
 
-	prlog(PR_NOTICE, "TPM: tpm%d registered: driver=%s\n",
-	      tpm->id, tpm->driver->name);
+	prlog(PR_NOTICE, "TPM: tpm%d registered: driver=%s felsz=%d\n",
+	      tpm->id, tpm->driver->name, tpm->logmgr.logSize);
 
 	return 0;
 
diff --git a/libstb/tpm_chip.h b/libstb/tpm_chip.h
index ca30e3b..b8f536c 100644
--- a/libstb/tpm_chip.h
+++ b/libstb/tpm_chip.h
@@ -19,6 +19,8 @@
 
 #include <device.h>
 
+#include "tss/tpmLogMgr.H"
+
 struct tpm_dev {
 
 	/* TPM bus id */
@@ -49,6 +51,9 @@ struct tpm_chip {
 	/* TPM device tree node */
 	struct dt_node *node;
 
+	/* Event log handler */
+	struct _TpmLogMgr logmgr;
+
 	/* TPM device handler */
 	struct tpm_dev    *dev;
 
@@ -63,6 +68,7 @@ typedef struct tpm_chip TpmTarget;
 
 /*
  * Register a tpm chip by binding the driver to dev.
+ * Event log is also registered by this function.
  */
 extern int tpm_register_chip(struct dt_node *node, struct tpm_dev *dev,
 			     struct tpm_driver *driver);
-- 
1.9.1



More information about the Skiboot mailing list