[Skiboot] [PATCH v2 18/31] libstb/drivers/tpm_i2c_nuvoton.c: add probe function

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


This adds the probe function to the TPM Nuvoton driver and also updates
the tpm_init() in tpm_chip.c to call the probe function.

Signed-off-by: Claudio Carvalho <cclaudio at linux.vnet.ibm.com>
---
 libstb/drivers/tpm_i2c_nuvoton.c | 61 ++++++++++++++++++++++++++++++++++++++++
 libstb/drivers/tpm_i2c_nuvoton.h | 22 +++++++++++++++
 libstb/tpm_chip.c                |  2 ++
 3 files changed, 85 insertions(+)
 create mode 100644 libstb/drivers/tpm_i2c_nuvoton.h

diff --git a/libstb/drivers/tpm_i2c_nuvoton.c b/libstb/drivers/tpm_i2c_nuvoton.c
index 0f9ec24..a4dfb23 100644
--- a/libstb/drivers/tpm_i2c_nuvoton.c
+++ b/libstb/drivers/tpm_i2c_nuvoton.c
@@ -21,14 +21,18 @@
 
 #include <timebase.h>
 #include <skiboot.h>
+#include <device.h>
 #include <i2c.h>
 #include "../status_codes.h"
 #include "../tpm_chip.h"
 #include "tpm_i2c_interface.h"
+#include "tpm_i2c_nuvoton.h"
 
 //#define DBG(fmt, ...) prlog(PR_DEBUG, fmt, ##__VA_ARGS__)
 #define DBG(fmt, ...)
 
+#define DRIVER_NAME "i2c_tpm_nuvoton"
+
 /*
  * Timings between various states or transitions within the interface protocol
  * as defined in the TCG PC Client Platform TPM Profile specification, Revision
@@ -441,3 +445,60 @@ out:
 	    (rc) ? "ERROR" : "SUCCESS", rc);
 	return rc;
 }
+
+static struct tpm_driver tpm_i2c_nuvoton_driver = {
+	.name     = DRIVER_NAME,
+	.transmit = tpm_transmit,
+};
+
+void tpm_i2c_nuvoton_probe(void)
+{
+	struct tpm_dev *tpm_device = NULL;
+	struct dt_node *node = NULL;
+
+	dt_for_each_compatible(dt_root, node, "nuvoton,npct650") {
+		if (!dt_node_is_enabled(node))
+			continue;
+		tpm_device = (struct tpm_dev*) malloc(sizeof(struct tpm_dev));
+		assert(tpm_device);
+		/*
+		 * Read TPM device address and bus id. Make sure the properties
+		 * really exist if the default value is returned.
+		 */
+		tpm_device->xscom_base = dt_prop_get_u32_def(node, "reg", 0);
+		if (!tpm_device->xscom_base &&
+		    !dt_find_property(node, "reg")) {
+			/*
+			 * @fwts-label NuvotonRegNotFound
+			 * @fwts-advice reg property not found. This indicates
+			 * a Hostboot bug if the property really doesn't exist
+			 * in the tpm node.
+			 */
+			prlog(PR_ERR, "NUVOTON: reg property not found, "
+			      "tpm node %p\n", node);
+			goto disable;
+		}
+		tpm_device->bus_id = dt_prop_get_u32_def(node->parent,
+							 "ibm,opal-id", 0);
+		if (!tpm_device->bus_id &&
+		    !dt_find_property(node->parent, "ibm,opal-id")) {
+			/*
+			 * @fwts-label NuvotonIbmOpalIdNotFound
+			 * @fwts-advice ibm,opal-id property not found. This
+			 * indicates a Hostboot bug if the property really
+			 * doesn't exist in the tpm node.
+			 */
+			prlog(PR_ERR, "NUVOTON: ibm,opal-id property not "
+			      "found, tpm node parent %p\n", node->parent);
+			goto disable;
+		}
+		if (tpm_register_chip(node, tpm_device,
+				      &tpm_i2c_nuvoton_driver))
+			free(tpm_device);
+	}
+	return;
+disable:
+	dt_add_property_string(node, "status", "disabled");
+	prlog(PR_NOTICE, "TPM: tpm node %p disabled\n", node);
+	free(tpm_device);
+}
diff --git a/libstb/drivers/tpm_i2c_nuvoton.h b/libstb/drivers/tpm_i2c_nuvoton.h
new file mode 100644
index 0000000..4d8a0b2
--- /dev/null
+++ b/libstb/drivers/tpm_i2c_nuvoton.h
@@ -0,0 +1,22 @@
+/* Copyright 2013-2016 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TPM_I2C_NUVOTON_H
+#define __TPM_I2C_NUVOTON_H
+
+extern void tpm_i2c_nuvoton_probe(void);
+
+#endif /* __TPM_I2C_NUVOTON_H */
diff --git a/libstb/tpm_chip.c b/libstb/tpm_chip.c
index 72d15b5..945d98e 100644
--- a/libstb/tpm_chip.c
+++ b/libstb/tpm_chip.c
@@ -21,6 +21,7 @@
 #include "status_codes.h"
 #include "container.h"
 #include "tpm_chip.h"
+#include "drivers/tpm_i2c_nuvoton.h"
 
 static struct list_head tpm_list = LIST_HEAD_INIT(tpm_list);
 
@@ -84,6 +85,7 @@ void tpm_init(void)
 	list_head_init(&tpm_list);
 
 	/* tpm drivers supported */
+	tpm_i2c_nuvoton_probe();
 
 	if (list_empty(&tpm_list))
 		/**
-- 
1.9.1



More information about the Skiboot mailing list