[SLOF] [PATCH v2 17/20] Add TPM firmware API call get-failure-reason

Stefan Berger stefanb at us.ibm.com
Wed Nov 18 04:02:33 AEDT 2015


From: Stefan Berger <stefanb at linux.vnet.ibm.com>

This patch adds support for the TPM firmware API call get-failure-reason.

Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
Reviewed-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
---
 board-qemu/slof/vio-vtpm-cdriver.fs |  8 ++++++++
 board-qemu/slof/vtpm-sml.fs         |  7 +++++++
 lib/libtpm/tcgbios.c                | 16 ++++++++++++++++
 lib/libtpm/tcgbios.h                |  1 +
 lib/libtpm/tpm.code                 | 10 ++++++++++
 lib/libtpm/tpm.in                   |  1 +
 slof/fs/tpm/tpm-static.fs           | 12 ++++++++++++
 7 files changed, 55 insertions(+)

diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs b/board-qemu/slof/vio-vtpm-cdriver.fs
index 64e0e1a..3f0cb73 100644
--- a/board-qemu/slof/vio-vtpm-cdriver.fs
+++ b/board-qemu/slof/vio-vtpm-cdriver.fs
@@ -106,6 +106,14 @@ false VALUE vtpm-debug?
 ;
 
 \ firmware API call
+: get-failure-reason ( -- reason )
+    " get-failure-reason" vtpm-call-forward IF
+        \ vtpm-call-forward failed; return a value
+        0 \ invalid
+    THEN
+;
+
+\ firmware API call
 : hash-all ( data-ptr data-len hash-ptr -- )
     " hash-all" vtpm-call-forward IF
         \ vtpm-call-forward failed; clean up stack
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 5e19dd6..b8afed8 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -59,6 +59,13 @@ log-base LOG-SIZE tpm-set-log-parameters
     vtpm-driver-get-state
 ;
 
+: get-failure-reason ( -- reason )
+    vtpm-debug? IF
+        ." Call to get-failure-reason" cr
+    THEN
+    vtpm-driver-get-failure-reason
+;
+
 : hash-all ( data-ptr data-len hash-ptr -- )
     vtpm-debug? IF
         ." Call to hash-all" cr
diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c
index b83a78d..c404410 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -1594,3 +1594,19 @@ uint32_t tpm_driver_get_state(void)
 
 	return td->getstate();
 }
+
+/*
+ * tpm_driver_get_failure_reason: Function for interfacing with the firmware
+ *                                API
+ */
+uint32_t tpm_driver_get_failure_reason(void)
+{
+	struct tpm_driver *td = tpm_state.tpm_drv;
+
+	/* do not check for a working TPM here */
+
+	if (!td)
+		return VTPM_DRV_ERROR_NO_FAILURE;
+
+	return td->geterror();
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 2914e8f..5bd8ab4 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -44,6 +44,7 @@ uint32_t tpm_hash_all(const void *data, uint32_t datalen, void *hashptr);
 uint32_t tpm_get_maximum_cmd_size(void);
 uint32_t tpm_pass_through_to_tpm(unsigned char *buf, uint32_t cmdlen);
 uint32_t tpm_driver_get_state(void);
+uint32_t tpm_driver_get_failure_reason(void);
 
 /* flags returned by tpm_get_state */
 #define TPM_STATE_ENABLED        1
diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code
index 4d18222..ee6e81c 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -163,6 +163,16 @@ PRIM(tpm_X2d_driver_X2d_get_X2d_state)
 	TOS.n = tpm_driver_get_state();
 MIRP
 
+/*********************************************************/
+/* Firmware API                                          */
+/* SLOF:   tpm-driver-get_failuer-reason ( -- errcode)   */
+/* LIBTPM: errcode = tpm_driver_get_failure_reason(void) */
+/*********************************************************/
+PRIM(tpm_X2d_driver_X2d_get_X2d_failure_X2d_reason)
+	PUSH;
+	TOS.n = tpm_driver_get_failure_reason();
+MIRP
+
 /*****************************************************************/
 /* Firmware API                                                  */
 /* SLOF:   tpm-hash-all ( data-ptr data-len hash-ptr -- errcode) */
diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in
index 81eeab7..797a49e 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -30,3 +30,4 @@ cod(tpm-hash-all)
 cod(tpm-get-maximum-cmd-size)
 cod(tpm-pass-through-to-tpm)
 cod(tpm-driver-get-state)
+cod(tpm-driver-get-failure-reason)
diff --git a/slof/fs/tpm/tpm-static.fs b/slof/fs/tpm/tpm-static.fs
index dce6393..0dfea19 100644
--- a/slof/fs/tpm/tpm-static.fs
+++ b/slof/fs/tpm/tpm-static.fs
@@ -85,6 +85,18 @@ false VALUE vtpm-debug?
 ;
 
 \ firmware API function
+: vtpm-driver-get-failure-reason ( -- reason )
+    vtpm-available? IF
+        tpm-driver-get-failure-reason
+        vtpm-debug? IF
+            ." VTPM: Return value from tpm-driver-get-failure-reason: " dup . cr
+        THEN
+    ELSE
+        -1 \ no failure
+    THEN
+;
+
+\ firmware API function
 : vtpm-log-event ( event-ptr -- ok? )
     vtpm-available? IF
         tpm-log-event
-- 
2.4.3



More information about the SLOF mailing list