[SLOF] [PATCH v4 15/33] tpm: Add TPM firmware API call get-failure-reason
Stefan Berger
stefanb at linux.vnet.ibm.com
Thu Dec 12 07:27:10 AEDT 2019
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 | 13 +++++++++++++
lib/libtpm/tcgbios.h | 1 +
lib/libtpm/tpm.code | 10 ++++++++++
lib/libtpm/tpm.in | 1 +
6 files changed, 40 insertions(+)
diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs b/board-qemu/slof/vio-vtpm-cdriver.fs
index 667f321..c13a063 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?
THEN
;
+\ 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
diff --git a/board-qemu/slof/vtpm-sml.fs b/board-qemu/slof/vtpm-sml.fs
index 5349786..43e4f1e 100644
--- a/board-qemu/slof/vtpm-sml.fs
+++ b/board-qemu/slof/vtpm-sml.fs
@@ -62,6 +62,13 @@ log-base LOG-SIZE tpm-set-log-parameters
THEN
;
+: get-failure-reason ( -- reason )
+ tpm-driver-get-failure-reason ( reason )
+ vtpm-debug? IF
+ ." VTPM: Return value from tpm-driver-get-failure-reason: " dup . cr
+ THEN
+;
+
: 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 05e5e18..66b1cca 100644
--- a/lib/libtpm/tcgbios.c
+++ b/lib/libtpm/tcgbios.c
@@ -901,3 +901,16 @@ uint32_t tpm_driver_get_state(void)
return spapr_vtpm_get_state();
}
+
+/*
+ * tpm_driver_get_failure_reason: Function for interfacing with the firmware
+ * API
+ */
+uint32_t tpm_driver_get_failure_reason(void)
+{
+ /* do not check for a working TPM here */
+ if (!tpm_state.tpm_found)
+ return VTPM_DRV_STATE_INVALID;
+
+ return spapr_vtpm_get_error();
+}
diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h
index 25c7518..0ddd537 100644
--- a/lib/libtpm/tcgbios.h
+++ b/lib/libtpm/tcgbios.h
@@ -37,6 +37,7 @@ uint32_t tpm_process_opcode(uint8_t op, bool verbose);
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 6f1a85c..3f2bd7f 100644
--- a/lib/libtpm/tpm.code
+++ b/lib/libtpm/tpm.code
@@ -87,6 +87,16 @@ PRIM(tpm_X2d_driver_X2d_get_X2d_state)
TOS.n = tpm_driver_get_state();
MIRP
+/*********************************************************/
+/* Firmware API */
+/* SLOF: tpm-driver-get_failure-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 52b4b4f..88d8a14 100644
--- a/lib/libtpm/tpm.in
+++ b/lib/libtpm/tpm.in
@@ -30,3 +30,4 @@ cod(tpm-measure-scrtm)
cod(tpm-get-maximum-cmd-size)
cod(tpm-pass-through-to-tpm)
cod(tpm-driver-get-state)
+cod(tpm-driver-get-failure-reason)
--
2.17.1
More information about the SLOF
mailing list